From: <sag...@us...> - 2013-11-27 01:05:02
|
Revision: 3322 http://sourceforge.net/p/modplug/code/3322 Author: saga-games Date: 2013-11-27 01:04:51 +0000 (Wed, 27 Nov 2013) Log Message: ----------- [Fix] Export: Don't fail if song starts with ignore patterns. [Fix] Memory leak in plugin manager Modified Paths: -------------- trunk/OpenMPT/mptrack/Vstplug.h trunk/OpenMPT/soundlib/Snd_fx.cpp trunk/OpenMPT/soundlib/plugins/PluginManager.cpp Modified: trunk/OpenMPT/mptrack/Vstplug.h =================================================================== --- trunk/OpenMPT/mptrack/Vstplug.h 2013-11-27 00:54:12 UTC (rev 3321) +++ trunk/OpenMPT/mptrack/Vstplug.h 2013-11-27 01:04:51 UTC (rev 3322) @@ -25,17 +25,12 @@ class CVstPluginManager; class CVstPlugin; -class CVstEditor; -class Cfxp; //rewbs.VSTpresets +#ifdef MODPLUG_TRACKER class CModDoc; +#endif // MODPLUG_TRACKER class CSoundFile; -#ifndef NO_VST - typedef AEffect * (VSTCALLBACK * PVSTPLUGENTRY)(audioMasterCallback); -#endif // NO_VST - - struct VSTPluginLib { enum PluginCategory @@ -62,8 +57,8 @@ CVstPlugin *pPluginsList; // Pointer to first plugin instance (this instance carries pointers to other instances) mpt::PathString libraryName; // Display name mpt::PathString dllPath; // Full path name - VstInt32 pluginId1; - VstInt32 pluginId2; + VstInt32 pluginId1; // Plugin type (kEffectMagic, kDmoMagic) + VstInt32 pluginId2; // Plugin unique ID PluginCategory category; bool isInstrument; @@ -76,7 +71,7 @@ { } - uint32 EncodeCacheFlags() + uint32 EncodeCacheFlags() const { return (isInstrument ? 1 : 0) | (category << 1); } @@ -97,15 +92,6 @@ }; -struct VSTInstrChannel -{ - int32 midiPitchBendPos; // Current Pitch Wheel position, in 16.11 fixed point format. Lowest bit is used for indicating that vibrato was applied. Vibrato offset itself is not stored in this value. - uint16 currentProgram; - uint16 currentBank; - uint8 noteOnMap[128][MAX_CHANNELS]; -}; - - #ifndef NO_VST #include "../soundlib/plugins/PluginEventQueue.h" #endif // NO_VST @@ -131,6 +117,14 @@ vstVibratoFlag = 1, }; + struct VSTInstrChannel + { + int32 midiPitchBendPos; // Current Pitch Wheel position, in 16.11 fixed point format. Lowest bit is used for indicating that vibrato was applied. Vibrato offset itself is not stored in this value. + uint16 currentProgram; + uint16 currentBank; + uint8 noteOnMap[128][MAX_CHANNELS]; + }; + CVstPlugin *m_pNext, *m_pPrev; HINSTANCE m_hLibrary; VSTPluginLib &m_Factory; @@ -148,8 +142,8 @@ float m_fGain; PLUGINDEX m_nSlot; - bool m_bSongPlaying; //rewbs.VSTCompliance - bool m_bPlugResumed; //rewbs.VSTCompliance + bool m_bSongPlaying; + bool m_bPlugResumed; bool m_bIsVst2; bool m_bIsInstrument; @@ -327,7 +321,6 @@ CVstPluginManager(); ~CVstPluginManager(); -public: typedef std::vector<VSTPluginLib *>::iterator iterator; typedef std::vector<VSTPluginLib *>::const_iterator const_iterator; @@ -337,7 +330,7 @@ const_iterator end() const { return pluginList.end(); } void reserve(size_t num) { pluginList.reserve(num); } - bool IsValidPlugin(const VSTPluginLib *pLib); + bool IsValidPlugin(const VSTPluginLib *pLib) const; VSTPluginLib *AddPlugin(const mpt::PathString &dllPath, bool fromCache = true, const bool checkFileExistence = false, std::wstring* const errStr = nullptr); bool RemovePlugin(VSTPluginLib *); bool CreateMixPlugin(SNDMIXPLUGIN &, CSoundFile &); Modified: trunk/OpenMPT/soundlib/Snd_fx.cpp =================================================================== --- trunk/OpenMPT/soundlib/Snd_fx.cpp 2013-11-27 00:54:12 UTC (rev 3321) +++ trunk/OpenMPT/soundlib/Snd_fx.cpp 2013-11-27 01:04:51 UTC (rev 3322) @@ -143,6 +143,13 @@ bool patternBreakOnThisRow = false; bool patternLoopEndedOnThisRow = false; + if(nPattern == Order.GetIgnoreIndex() && target.mode == GetLengthTarget::SeekPosition && nCurrentOrder == target.pos.order) + { + // Early test: Target is inside +++ pattern + retval.targetReached = true; + break; + } + while(nPattern >= Patterns.Size()) { // End of song? @@ -4075,7 +4082,7 @@ { // Not an internal device. Pass on to appropriate plugin. const CHANNELINDEX plugChannel = (nChn < GetNumChannels()) ? nChn + 1 : pChn->nMasterChn; - if(plugChannel > 0 && plugChannel <= GetNumChannels()) // XXX do we need this? + if(plugChannel > 0 && plugChannel <= GetNumChannels()) // XXX do we need this? I guess it might be relevant for previewing notes in the pattern... { PLUGINDEX nPlug = 0; if(!pChn->dwFlags[CHN_NOFX]) Modified: trunk/OpenMPT/soundlib/plugins/PluginManager.cpp =================================================================== --- trunk/OpenMPT/soundlib/plugins/PluginManager.cpp 2013-11-27 00:54:12 UTC (rev 3321) +++ trunk/OpenMPT/soundlib/plugins/PluginManager.cpp 2013-11-27 01:04:51 UTC (rev 3322) @@ -17,24 +17,26 @@ #include "../../mptrack/TrackerSettings.h" #include "../../mptrack/AbstractVstEditor.h" #include "../../common/AudioCriticalSection.h" +#include "../../common/StringFixer.h" #include "../Sndfile.h" #include "JBridge.h" - -#ifdef VST_USE_ALTERNATIVE_MAGIC // Pelya's plugin ID fix. Breaks fx presets, so let's avoid it for now. -#include "../../include/zlib/zlib.h" // For CRC32 calculation (to detect plugins with same UID) -#endif // VST_USE_ALTERNATIVE_MAGIC - char CVstPluginManager::s_szHostProductString[64] = "OpenMPT"; char CVstPluginManager::s_szHostVendorString[64] = "OpenMPT project"; VstIntPtr CVstPluginManager::s_nHostVendorVersion = MptVersion::num; +typedef AEffect * (VSTCALLBACK * PVSTPLUGENTRY)(audioMasterCallback); + //#define VST_LOG #define DMO_LOG AEffect *DmoToVst(VSTPluginLib &lib); #ifdef VST_USE_ALTERNATIVE_MAGIC +// Pelya's plugin ID fix. Breaks fx presets, so let's avoid it for now. +// A better solution would be to change the plugin.cache format so that the ID1+ID2 strings are combined with a CRC, +// Or maybe we should just switch to a proper database format. +#include "../../include/zlib/zlib.h" // For CRC32 calculation (to detect plugins with same UID) uint32 CalculateCRC32fromFilename(const char *s) //---------------------------------------------- { @@ -43,7 +45,6 @@ int f; for(f = 0; fn[f] != 0; f++) fn[f] = toupper(fn[f]); return LittleEndian(crc32(0, (uint8 *)fn, f)); - } #endif // VST_USE_ALTERNATIVE_MAGIC @@ -52,7 +53,7 @@ //---------------------------------------------------------------------------------------------------------------------------------------------- { CVstPluginManager *that = theApp.GetPluginManager(); - if (that) + if(that) { return that->VstCallback(effect, opcode, index, value, ptr, opt); } @@ -95,8 +96,8 @@ } -bool CVstPluginManager::IsValidPlugin(const VSTPluginLib *pLib) -//------------------------------------------------------------- +bool CVstPluginManager::IsValidPlugin(const VSTPluginLib *pLib) const +//------------------------------------------------------------------- { for(const_iterator p = begin(); p != end(); p++) { @@ -112,7 +113,7 @@ HKEY hkEnum; WCHAR keyname[128]; - LONG cr = RegOpenKey(HKEY_LOCAL_MACHINE, "software\\classes\\DirectShow\\MediaObjects\\Categories\\f3602b3f-0592-48df-a4cd-674721e7ebeb", &hkEnum); + LONG cr = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "software\\classes\\DirectShow\\MediaObjects\\Categories\\f3602b3f-0592-48df-a4cd-674721e7ebeb", 0, KEY_READ, &hkEnum); DWORD index = 0; while (cr == ERROR_SUCCESS) { @@ -132,9 +133,10 @@ if(ERROR_SUCCESS == RegQueryValueExW(hksub, nullptr, 0, &datatype, (LPBYTE)name, &datasize)) { + mpt::String::SetNullTerminator(name); StringFromGUID2(clsid, keyname, 100); - VSTPluginLib *plug = new (std::nothrow) VSTPluginLib(mpt::PathString::FromNative(keyname), mpt::PathString::FromWide(name)); + VSTPluginLib *plug = new (std::nothrow) VSTPluginLib(mpt::PathString::FromNative(keyname), mpt::PathString::FromNative(name)); if(plug != nullptr) { pluginList.push_back(plug); @@ -142,7 +144,7 @@ plug->pluginId2 = clsid.Data1; plug->category = VSTPluginLib::catDMO; #ifdef DMO_LOG - Log("Found \"%s\" clsid=%s\n", plug->libraryName.AsNative().c_str(), plug->dllPath.AsNative().c_str()); + Log(mpt::String::PrintW(L"Found \"%1\" clsid=%2\n", plug->libraryName, plug->dllPath)); #endif } } @@ -238,12 +240,12 @@ } -// // PluginCache format: // LibraryName = ID100000ID200000 // ID100000ID200000 = FullDllPath -// ID100000ID200000.Flags = Plugin Flags (isInstrument + category). +// ID100000ID200000.Flags = Plugin Flags (set VSTPluginLib::DecodeCacheFlags). +// Add a plugin to the list of known plugins. VSTPluginLib *CVstPluginManager::AddPlugin(const mpt::PathString &dllPath, bool fromCache, const bool checkFileExistence, std::wstring *const errStr) //--------------------------------------------------------------------------------------------------------------------------------------------------- { @@ -287,8 +289,8 @@ } pluginList.push_back(plug); - // Extract plugin Ids - for (UINT i=0; i<16; i++) + // Extract plugin IDs + for (int i = 0; i < 16; i++) { UINT n = IDs[i] - '0'; if (n > 9) n = IDs[i] + 10 - 'A'; @@ -302,7 +304,7 @@ } } - std::string flagKey = mpt::String::Format("%s.Flags", IDs.c_str()); + const std::string flagKey = mpt::String::Format("%s.Flags", IDs.c_str()); plug->DecodeCacheFlags(cacheFile.Read<int32>(cacheSection, flagKey, 0)); #ifdef VST_USE_ALTERNATIVE_MAGIC @@ -376,7 +378,7 @@ } // Now it should be safe to assume that this plugin loaded properly. :) - theApp.GetSettings().Write<std::string>("VST Plugins", "FailedPlugin", ""); + theApp.GetSettings().Remove("VST Plugins", "FailedPlugin"); // If OK, write the information in PluginCache if(validPlug) @@ -397,12 +399,16 @@ cacheFile.Write<mpt::PathString>(cacheSection, IDs, dllPath); cacheFile.Write<std::string>(cacheSectionW, plug->libraryName.ToWide(), IDs); cacheFile.Write<int32>(cacheSection, flagsKey, plug->EncodeCacheFlags()); + } else + { + delete plug; } return (validPlug ? plug : nullptr); } +// Remove a plugin from the list of known plugins and release any remaining instances of it. bool CVstPluginManager::RemovePlugin(VSTPluginLib *pFactory) //---------------------------------------------------------- { @@ -411,6 +417,7 @@ VSTPluginLib *plug = *p; if(plug == pFactory) { + // Kill all instances of this plugin try { CriticalSection cs; @@ -433,6 +440,7 @@ } +// Create an instance of a plugin. bool CVstPluginManager::CreateMixPlugin(SNDMIXPLUGIN &mixPlugin, CSoundFile &sndFile) //----------------------------------------------------------------------------------- { @@ -477,9 +485,8 @@ if(!pFound && strcmp(mixPlugin.GetLibraryName(), "")) { - // Try finding the plugin DLL in the plugin directory instead. - mpt::PathString fullPath; - fullPath = TrackerDirectories::Instance().GetDefaultDirectory(DIR_PLUGINS); + // Try finding the plugin DLL in the plugin directory or plugin cache instead. + mpt::PathString fullPath = TrackerDirectories::Instance().GetDefaultDirectory(DIR_PLUGINS); if(fullPath.empty()) { fullPath = theApp.GetAppDirPath() + MPT_PATHSTRING("Plugins\\"); @@ -493,6 +500,7 @@ pFound = AddPlugin(fullPath); if(!pFound) { + // Try plugin cache (search for library name) SettingsContainer &cacheFile = theApp.GetPluginCache(); std::string IDs = cacheFile.Read<std::string>(cacheSectionW, mpt::ToWide(mpt::CharsetUTF8, mixPlugin.GetLibraryName()), ""); if(IDs.length() >= 16) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |