From: <sag...@us...> - 2012-04-01 19:25:09
|
Revision: 1238 http://modplug.svn.sourceforge.net/modplug/?rev=1238&view=rev Author: saga-games Date: 2012-04-01 19:25:00 +0000 (Sun, 01 Apr 2012) Log Message: ----------- [New] Experimental built-in support for JBridge. Still has some small issues when switching plugins, but apart from that it seems to work (with admin privileges enabled). [Ref] Removed unused buzz machines support and general cleanup. Modified Paths: -------------- trunk/OpenMPT/mptrack/Moddoc.cpp trunk/OpenMPT/mptrack/Mptrack.cpp trunk/OpenMPT/mptrack/SelectPluginDialog.cpp trunk/OpenMPT/mptrack/SelectPluginDialog.h trunk/OpenMPT/mptrack/View_gen.cpp trunk/OpenMPT/mptrack/View_gen.h trunk/OpenMPT/mptrack/Vstplug.cpp trunk/OpenMPT/mptrack/Vstplug.h trunk/OpenMPT/mptrack/mptrack_08.vcproj trunk/OpenMPT/mptrack/mptrack_10.vcxproj trunk/OpenMPT/mptrack/mptrack_10.vcxproj.filters trunk/OpenMPT/mptrack/resource.h trunk/OpenMPT/soundlib/MIDIMacros.h trunk/OpenMPT/soundlib/Sndfile.h Added Paths: ----------- trunk/OpenMPT/soundlib/plugins/ trunk/OpenMPT/soundlib/plugins/JBridge.cpp trunk/OpenMPT/soundlib/plugins/JBridge.h trunk/OpenMPT/soundlib/plugins/PlugInterface.h trunk/OpenMPT/soundlib/plugins/PluginEventQueue.h trunk/OpenMPT/soundlib/plugins/PluginMixBuffer.h Removed Paths: ------------- trunk/OpenMPT/soundlib/PlugInterface.h trunk/OpenMPT/soundlib/PluginEventQueue.h trunk/OpenMPT/soundlib/PluginMixBuffer.h Modified: trunk/OpenMPT/mptrack/Moddoc.cpp =================================================================== --- trunk/OpenMPT/mptrack/Moddoc.cpp 2012-03-31 23:47:31 UTC (rev 1237) +++ trunk/OpenMPT/mptrack/Moddoc.cpp 2012-04-01 19:25:00 UTC (rev 1238) @@ -2509,15 +2509,15 @@ void CModDoc::TogglePluginEditor(UINT m_nCurrentPlugin) //----------------------------------------------------- { - SNDMIXPLUGIN &plugin = m_SndFile.m_MixPlugins[m_nCurrentPlugin]; - - if (m_nCurrentPlugin < MAX_MIXPLUGINS && plugin.pMixPlugin) + if(m_nCurrentPlugin < MAX_MIXPLUGINS) { + SNDMIXPLUGIN &plugin = m_SndFile.m_MixPlugins[m_nCurrentPlugin]; CVstPlugin *pVstPlugin = dynamic_cast<CVstPlugin *>(plugin.pMixPlugin); - pVstPlugin->ToggleEditor(); + if(pVstPlugin != nullptr) + { + pVstPlugin->ToggleEditor(); + } } - - return; } void CModDoc::ChangeFileExtension(MODTYPE nNewType) Modified: trunk/OpenMPT/mptrack/Mptrack.cpp =================================================================== --- trunk/OpenMPT/mptrack/Mptrack.cpp 2012-03-31 23:47:31 UTC (rev 1237) +++ trunk/OpenMPT/mptrack/Mptrack.cpp 2012-04-01 19:25:00 UTC (rev 1238) @@ -2242,14 +2242,13 @@ BOOL CTrackApp::UninitializeDXPlugins() //------------------------------------- { - TCHAR s[_MAX_PATH], tmp[32]; - PVSTPLUGINLIB pPlug; - UINT iPlug; - if (!m_pPluginManager) return FALSE; #ifndef NO_VST - pPlug = m_pPluginManager->GetFirstPlugin(); + TCHAR s[_MAX_PATH], tmp[32]; + VSTPluginLib *pPlug; + + PLUGINDEX pPlug = m_pPluginManager->GetFirstPlugin(); iPlug = 0; while (pPlug) { Modified: trunk/OpenMPT/mptrack/SelectPluginDialog.cpp =================================================================== --- trunk/OpenMPT/mptrack/SelectPluginDialog.cpp 2012-03-31 23:47:31 UTC (rev 1237) +++ trunk/OpenMPT/mptrack/SelectPluginDialog.cpp 2012-04-01 19:25:00 UTC (rev 1238) @@ -107,30 +107,38 @@ { // -> CODE#0002 // -> DESC="list box to choose VST plugin presets (programs)" - if(m_pPlugin==NULL) { CDialog::OnOK(); return; } + if(m_pPlugin==nullptr) { CDialog::OnOK(); return; } // -! NEW_FEATURE#0002 - BOOL bChanged = FALSE; + bool changed = false; CVstPluginManager *pManager = theApp.GetPluginManager(); - PVSTPLUGINLIB pNewPlug = (PVSTPLUGINLIB)m_treePlugins.GetItemData(m_treePlugins.GetSelectedItem()); - PVSTPLUGINLIB pFactory = NULL; - CVstPlugin *pCurrentPlugin = NULL; - if (m_pPlugin) pCurrentPlugin = (CVstPlugin *)m_pPlugin->pMixPlugin; + VSTPluginLib *pNewPlug = (VSTPluginLib *)m_treePlugins.GetItemData(m_treePlugins.GetSelectedItem()); + VSTPluginLib *pFactory = nullptr; + CVstPlugin *pCurrentPlugin = nullptr; + if (m_pPlugin) pCurrentPlugin = dynamic_cast<CVstPlugin *>(m_pPlugin->pMixPlugin); if ((pManager) && (pManager->IsValidPlugin(pNewPlug))) pFactory = pNewPlug; - // Plugin selected + if (pFactory) { + // Plugin selected if ((!pCurrentPlugin) || (pCurrentPlugin->GetPluginFactory() != pFactory)) { CriticalSection cs; - if (pCurrentPlugin) pCurrentPlugin->Release(); + + if (pCurrentPlugin != nullptr) + { + pCurrentPlugin->Release(); + } + // Just in case... - m_pPlugin->pMixPlugin = NULL; - m_pPlugin->pMixState = NULL; + m_pPlugin->pMixPlugin = nullptr; + m_pPlugin->pMixState = nullptr; + // Remove old state m_pPlugin->nPluginDataSize = 0; if (m_pPlugin->pPluginData) delete[] m_pPlugin->pPluginData; - m_pPlugin->pPluginData = NULL; + m_pPlugin->pPluginData = nullptr; + // Initialize plugin info MemsetZero(m_pPlugin->Info); m_pPlugin->Info.dwPluginId1 = pFactory->dwPluginId1; @@ -167,24 +175,27 @@ } } } - bChanged = TRUE; + changed = true; } } else + { // No effect - { CriticalSection cs; if (pCurrentPlugin) { pCurrentPlugin->Release(); - bChanged = TRUE; + changed = true; } + // Just in case... - m_pPlugin->pMixPlugin = NULL; - m_pPlugin->pMixState = NULL; + m_pPlugin->pMixPlugin = nullptr; + m_pPlugin->pMixState = nullptr; + // Remove old state m_pPlugin->nPluginDataSize = 0; if (m_pPlugin->pPluginData) delete[] m_pPlugin->pPluginData; - m_pPlugin->pPluginData = NULL; + m_pPlugin->pPluginData = nullptr; + // Clear plugin info MemsetZero(m_pPlugin->Info); } @@ -197,7 +208,7 @@ CMainFrame::GetSettings().gnPlugWindowWidth = rect.right - rect.left; CMainFrame::GetSettings().gnPlugWindowHeight = rect.bottom - rect.top; - if (bChanged) + if (changed) { CMainFrame::GetSettings().gnPlugWindowLast = m_pPlugin->Info.dwPluginId2; CDialog::OnOK(); @@ -249,8 +260,8 @@ if (pManager) { - PVSTPLUGINLIB pCurrent = NULL; - PVSTPLUGINLIB p = pManager->GetFirstPlugin(); + VSTPluginLib *pCurrent = NULL; + VSTPluginLib *p = pManager->GetFirstPlugin(); while (p) { // Apply name filter @@ -270,10 +281,10 @@ hParent = hDmo; } else { - hParent = (p->bIsInstrument) ? hSynth : hVst; + hParent = (p->isInstrument) ? hSynth : hVst; } - HTREEITEM h = AddTreeItem(p->szLibraryName, p->bIsInstrument ? IMAGE_PLUGININSTRUMENT : IMAGE_EFFECTPLUGIN, true, hParent, (LPARAM)p); + HTREEITEM h = AddTreeItem(p->szLibraryName, p->isInstrument ? IMAGE_PLUGININSTRUMENT : IMAGE_EFFECTPLUGIN, true, hParent, (LPARAM)p); //If filter is active, expand nodes. if (m_sNameFilter != "") m_treePlugins.EnsureVisible(h); @@ -367,7 +378,7 @@ //----------------------------------------------------------- { CVstPluginManager *pManager = theApp.GetPluginManager(); - PVSTPLUGINLIB pPlug = (PVSTPLUGINLIB)m_treePlugins.GetItemData(m_treePlugins.GetSelectedItem()); + VSTPluginLib *pPlug = (VSTPluginLib *)m_treePlugins.GetItemData(m_treePlugins.GetSelectedItem()); if ((pManager) && (pManager->IsValidPlugin(pPlug))) { SetDlgItemText(IDC_TEXT_CURRENT_VSTPLUG, pPlug->szDllPath); @@ -397,7 +408,7 @@ { kEffectMagic, CCONST('f', 'r', 'V', '2'), 1, "Farbrausch V2", "* This plugin can cause OpenMPT to freeze if being used in a combination with various other plugins.\nIt is recommended to not use V2 in combination with any other plugins. *" }, }; -bool CSelectPluginDlg::VerifyPlug(PVSTPLUGINLIB plug) +bool CSelectPluginDlg::VerifyPlug(VSTPluginLib *plug) //--------------------------------------------------- { CString s; @@ -429,7 +440,7 @@ CVstPluginManager *pManager = theApp.GetPluginManager(); bool bOk = false; - PVSTPLUGINLIB plugLib = nullptr; + VSTPluginLib *plugLib = nullptr; for(size_t counter = 0; counter < files.filenames.size(); counter++) { @@ -463,7 +474,7 @@ //------------------------------------- { const HTREEITEM pluginToDelete = m_treePlugins.GetSelectedItem(); - PVSTPLUGINLIB pPlug = (PVSTPLUGINLIB)m_treePlugins.GetItemData(pluginToDelete); + VSTPluginLib *pPlug = (VSTPluginLib *)m_treePlugins.GetItemData(pluginToDelete); CVstPluginManager *pManager = theApp.GetPluginManager(); if ((pManager) && (pPlug)) Modified: trunk/OpenMPT/mptrack/SelectPluginDialog.h =================================================================== --- trunk/OpenMPT/mptrack/SelectPluginDialog.h 2012-03-31 23:47:31 UTC (rev 1237) +++ trunk/OpenMPT/mptrack/SelectPluginDialog.h 2012-04-01 19:25:00 UTC (rev 1238) @@ -33,7 +33,7 @@ ~CSelectPluginDlg(); void DoClose(); void UpdatePluginsList(DWORD forceSelect = 0); - bool VerifyPlug(PVSTPLUGINLIB plug); + bool VerifyPlug(VSTPluginLib *plug); virtual void DoDataExchange(CDataExchange* pDX); virtual BOOL OnInitDialog(); virtual void OnOK(); Modified: trunk/OpenMPT/mptrack/View_gen.cpp =================================================================== --- trunk/OpenMPT/mptrack/View_gen.cpp 2012-03-31 23:47:31 UTC (rev 1237) +++ trunk/OpenMPT/mptrack/View_gen.cpp 2012-04-01 19:25:00 UTC (rev 1238) @@ -106,7 +106,6 @@ ON_CBN_SELCHANGE(IDC_COMBO9, OnSpecialMixProcessingChanged) // -! BEHAVIOUR_CHANGE#0028 - ON_COMMAND_RANGE(ID_FXCOMMANDS_BASE, ID_FXCOMMANDS_BASE+10, OnFxCommands) ON_NOTIFY(TCN_SELCHANGE, IDC_TABCTRL1, OnTabSelchange) ON_MESSAGE(WM_MOD_UNLOCKCONTROLS, OnUnlockControls) ON_MESSAGE(WM_MOD_VIEWMSG, OnModViewMsg) @@ -439,7 +438,7 @@ CheckDlgButton(IDC_CHECK10, pPlugin->IsBypassed() ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(IDC_CHECK11, pPlugin->IsWetMix() ? BST_CHECKED : BST_UNCHECKED); CVstPlugin *pVstPlugin = (pPlugin->pMixPlugin) ? (CVstPlugin *)pPlugin->pMixPlugin : NULL; - m_BtnEdit.EnableWindow((pVstPlugin != nullptr && (pVstPlugin->HasEditor() || pVstPlugin->GetNumCommands())) ? TRUE : FALSE); + m_BtnEdit.EnableWindow((pVstPlugin != nullptr && (pVstPlugin->HasEditor() || pVstPlugin->GetNumParameters())) ? TRUE : FALSE); ::EnableWindow(::GetDlgItem(m_hWnd, IDC_MOVEFXSLOT), (pVstPlugin) ? TRUE : FALSE); ::EnableWindow(::GetDlgItem(m_hWnd, IDC_INSERTFXSLOT), (pVstPlugin) ? TRUE : FALSE); ::EnableWindow(::GetDlgItem(m_hWnd, IDC_CLONEPLUG), (pVstPlugin) ? TRUE : FALSE); @@ -1226,27 +1225,6 @@ } -void CViewGlobals::OnFxCommands(UINT id) -//-------------------------------------- -{ - CModDoc *pModDoc = GetDocument(); - CSoundFile *pSndFile; - UINT nIndex = id - ID_FXCOMMANDS_BASE; - - if ((m_nCurrentPlugin >= MAX_MIXPLUGINS) || (!pModDoc)) return; - pSndFile = pModDoc->GetSoundFile(); - SNDMIXPLUGIN &plugin = pSndFile->m_MixPlugins[m_nCurrentPlugin]; - - if (plugin.pMixPlugin != nullptr) - { - CVstPlugin *pVstPlugin = dynamic_cast<CVstPlugin *>(plugin.pMixPlugin); - pVstPlugin->ExecuteCommand(nIndex); - if(pSndFile->GetModSpecifications().supportsPlugins) - pModDoc->SetModified(); - } -} - - void CViewGlobals::OnOutputRoutingChanged() //----------------------------------------- { Modified: trunk/OpenMPT/mptrack/View_gen.h =================================================================== --- trunk/OpenMPT/mptrack/View_gen.h 2012-03-31 23:47:31 UTC (rev 1237) +++ trunk/OpenMPT/mptrack/View_gen.h 2012-04-01 19:25:00 UTC (rev 1238) @@ -156,7 +156,6 @@ afx_msg void OnPrevPlugin(); afx_msg void OnNextPlugin(); afx_msg void OnDestroy(); - afx_msg void OnFxCommands(UINT id); afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar); afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar); afx_msg void OnSize(UINT nType, int cx, int cy); Modified: trunk/OpenMPT/mptrack/Vstplug.cpp =================================================================== --- trunk/OpenMPT/mptrack/Vstplug.cpp 2012-03-31 23:47:31 UTC (rev 1237) +++ trunk/OpenMPT/mptrack/Vstplug.cpp 2012-04-01 19:25:00 UTC (rev 1238) @@ -26,6 +26,7 @@ #include "version.h" #include "midimappingdialog.h" #include "../common/StringFixer.h" +#include "../soundlib/plugins/JBridge.h" #ifdef VST_USE_ALTERNATIVE_MAGIC //Pelya's plugin ID fix. Breaks fx presets, so let's avoid it for now. #define ZLIB_WINAPI #include "../zlib/zlib.h" //For CRC32 calculation (to detect plugins with same UID) @@ -40,17 +41,10 @@ VstIntPtr CVstPluginManager::s_nHostVendorVersion = MptVersion::num; //#define VST_LOG -//#define ENABLE_BUZZ #define DMO_LOG -#ifdef ENABLE_BUZZ -#define STATIC_BUILD -#include <machineinterface.h> // Buzz -AEffect *Buzz2Vst(CMachineInterface *pBuzzMachine, const CMachineInfo *pBuzzInfo); -#endif // ENABLE_BUZZ +AEffect *DmoToVst(VSTPluginLib *pLib); -AEffect *DmoToVst(PVSTPLUGINLIB pLib); - #ifdef VST_USE_ALTERNATIVE_MAGIC UINT32 CalculateCRC32fromFilename(const char *s) //---------------------------------------------- @@ -105,7 +99,7 @@ CSoundFile::gpMixPluginCreateProc = nullptr; while (m_pVstHead) { - PVSTPLUGINLIB p = m_pVstHead; + VSTPluginLib *p = m_pVstHead; m_pVstHead = m_pVstHead->pNext; if (m_pVstHead) m_pVstHead->pPrev = nullptr; p->pPrev = p->pNext = nullptr; @@ -118,10 +112,10 @@ } -BOOL CVstPluginManager::IsValidPlugin(const VSTPLUGINLIB *pLib) +BOOL CVstPluginManager::IsValidPlugin(const VSTPluginLib *pLib) //------------------------------------------------------------- { - PVSTPLUGINLIB p = m_pVstHead; + VSTPluginLib *p = m_pVstHead; while (p) { if (p == pLib) return TRUE; @@ -163,14 +157,14 @@ if (ERROR_SUCCESS == RegQueryValueEx(hksub, nullptr, 0, &datatype, (LPBYTE)s, &datasize)) { - PVSTPLUGINLIB p = new VSTPLUGINLIB; + VSTPluginLib *p = new VSTPluginLib(); p->pPrev = nullptr; p->pNext = m_pVstHead; p->dwPluginId1 = kDmoMagic; p->dwPluginId2 = clsid.Data1; p->pPluginsList = nullptr; - p->bIsInstrument = FALSE; + p->isInstrument = false; lstrcpyn(p->szLibraryName, s, sizeof(p->szLibraryName)); StringFromGUID2(clsid, w, 100); WideCharToMultiByte(CP_ACP, 0, w, -1, p->szDllPath, sizeof(p->szDllPath), nullptr, nullptr); @@ -189,15 +183,63 @@ if (hkEnum) RegCloseKey(hkEnum); } + +void CVstPluginManager::LoadPlugin(const char *pluginPath, AEffect *&effect, HINSTANCE &library) +//---------------------------------------------------------------------------------------------- +{ + library = nullptr; + effect = nullptr; + + try + { + library = LoadLibrary(pluginPath); + +#ifdef _DEBUG + DWORD dw = GetLastError(); + if(library == nullptr && dw != ERROR_MOD_NOT_FOUND) // "File not found errors" are annoying. + { + TCHAR szBuf[256]; + wsprintf(szBuf, "Warning: encountered problem when loading plugin dll. Error %d: %s", dw, (LPCTSTR)GetErrorMessage(dw)); + Reporting::Error(szBuf, "DEBUG: Error when loading plugin dll"); + } +#endif //_DEBUG + } catch(...) + { + CVstPluginManager::ReportPlugException("Exception caught in LoadLibrary (%s)", pluginPath); + } + + if(library != nullptr && library != INVALID_HANDLE_VALUE) + { + // Try loading the VST plugin. + PVSTPLUGENTRY pMainProc = (PVSTPLUGENTRY)GetProcAddress(library, "VSTPluginMain"); + if(pMainProc == nullptr) + { + pMainProc = (PVSTPLUGENTRY)GetProcAddress(library, "main"); + } + + if(pMainProc != nullptr) + { + effect = pMainProc(MasterCallBack); + } else + { +#ifdef VST_LOG + Log("Entry point not found! (handle=%08X)\n", library); +#endif // VST_LOG + } + } else + { + // Try loading the plugin using JBridge instead. + effect = JBridge::LoadBridgedPlugin(MasterCallBack, pluginPath); + } +} + // // PluginCache format: // LibraryName = ID100000ID200000 // ID100000ID200000 = FullDllPath // ID100000ID200000.Flags = Plugin Flags (for now, just isInstrument). - - - -PVSTPLUGINLIB CVstPluginManager::AddPlugin(LPCSTR pszDllPath, BOOL bCache, const bool checkFileExistence, CString* const errStr) + +VSTPluginLib *CVstPluginManager::AddPlugin(LPCSTR pszDllPath, BOOL bCache, const bool checkFileExistence, CString* const errStr) //------------------------------------------------------------------------------------------------------------------------------ { TCHAR szPath[_MAX_PATH]; @@ -211,8 +253,8 @@ } } - PVSTPLUGINLIB pDup = m_pVstHead; - while (pDup) + VSTPluginLib *pDup = m_pVstHead; + while(pDup != nullptr) { if (!lstrcmpi(pszDllPath, pDup->szDllPath)) return pDup; pDup = pDup->pNext; @@ -236,21 +278,17 @@ if ((szPath[0]) && (!lstrcmpi(szPath, pszDllPath))) { - PVSTPLUGINLIB p; + VSTPluginLib *p; try { - p = new VSTPLUGINLIB; + p = new VSTPluginLib(); } catch(MPTMemoryException) { return nullptr; } - p->dwPluginId1 = 0; - p->dwPluginId2 = 0; - p->bIsInstrument = FALSE; - p->pPluginsList = nullptr; lstrcpyn(p->szDllPath, pszDllPath, sizeof(p->szDllPath)); _splitpath(pszDllPath, nullptr, nullptr, p->szLibraryName, nullptr); - p->szLibraryName[63] = 0; + p->szLibraryName[63] = '\0'; p->pNext = m_pVstHead; p->pPrev = nullptr; if (m_pVstHead) m_pVstHead->pPrev = p; @@ -272,7 +310,7 @@ CString flagKey; flagKey.Format("%s.Flags", IDs); int infoex = CMainFrame::GetPrivateProfileLong(cacheSection, flagKey, 0, cacheFile); - if (infoex&1) p->bIsInstrument = TRUE; + if (infoex & 1) p->isInstrument = true; #ifdef VST_USE_ALTERNATIVE_MAGIC if( p->dwPluginId1 == kEffectMagic ) { @@ -292,187 +330,101 @@ } } - HINSTANCE hLib = nullptr; - - // If this key contains a file name on program launch, a plugin previously crashed OpenMPT. WritePrivateProfileString("VST Plugins", "FailedPlugin", pszDllPath, theApp.GetConfigFileName()); + AEffect *pEffect; + HINSTANCE hLib; + bool validPlug = false; + + VSTPluginLib *p = nullptr; try { - hLib = LoadLibrary(pszDllPath); - -#ifdef _DEBUG - DWORD dw = GetLastError(); - if (!hLib && dw != ERROR_MOD_NOT_FOUND) // "File not found errors" are annoying. - { - TCHAR szBuf[256]; - wsprintf(szBuf, "Warning: encountered problem when loading plugin dll. Error %d: %s", dw, (LPCTSTR)GetErrorMessage(dw)); - Reporting::Error(szBuf, "DEBUG: Error when loading plugin dll"); - } -#endif //_DEBUG - - } catch(...) + p = new VSTPluginLib(); + } catch(MPTMemoryException) { - CVstPluginManager::ReportPlugException("Exception caught in LoadLibrary (%s)", pszDllPath); + return nullptr; } - if ((hLib) && (hLib != INVALID_HANDLE_VALUE)) + p->pPluginsList = nullptr; + lstrcpyn(p->szDllPath, pszDllPath, CountOf(p->szDllPath)); + _splitpath(pszDllPath, nullptr, nullptr, p->szLibraryName, nullptr); + p->szLibraryName[63] = 0; + p->pNext = m_pVstHead; + p->pPrev = nullptr; + + try { - bool validPlug = false; - PVSTPLUGENTRY pMainProc = (PVSTPLUGENTRY)GetProcAddress(hLib, "VSTPluginMain"); - if(pMainProc == nullptr) + LoadPlugin(pszDllPath, pEffect, hLib); + + if(pEffect != nullptr && pEffect->magic == kEffectMagic && pEffect->dispatcher != nullptr) { - pMainProc = (PVSTPLUGENTRY)GetProcAddress(hLib, "main"); - } - #ifdef ENABLE_BUZZ - GET_INFO pBuzzGetInfo = (GET_INFO)GetProcAddress(hLib, "GetInfo"); - #endif // ENABLE_BUZZ - if (pMainProc) - { - PVSTPLUGINLIB p; - try - { - p = new VSTPLUGINLIB; - } catch(MPTMemoryException) - { - return nullptr; - } - p->dwPluginId1 = 0; - p->dwPluginId2 = 0; - p->bIsInstrument = FALSE; - p->pPluginsList = nullptr; - lstrcpyn(p->szDllPath, pszDllPath, CountOf(p->szDllPath)); - _splitpath(pszDllPath, nullptr, nullptr, p->szLibraryName, nullptr); - p->szLibraryName[63] = 0; - p->pNext = m_pVstHead; - p->pPrev = nullptr; + pEffect->dispatcher(pEffect, effOpen, 0, 0, 0, 0); + if (m_pVstHead) m_pVstHead->pPrev = p; m_pVstHead = p; - try - { - AEffect *pEffect = pMainProc(MasterCallBack); - if(pEffect != nullptr && pEffect->magic == kEffectMagic && pEffect->dispatcher != nullptr) - { - pEffect->dispatcher(pEffect, effOpen, 0, 0, 0, 0); +#ifdef VST_USE_ALTERNATIVE_MAGIC + p->dwPluginId1 = CalculateCRC32fromFilename(p->szLibraryName); // Make Plugin ID unique for sure +#else + p->dwPluginId1 = pEffect->magic; +#endif // VST_USE_ALTERNATIVE_MAGIC + p->dwPluginId2 = pEffect->uniqueID; + p->isInstrument = ((pEffect->flags & effFlagsIsSynth) || !pEffect->numInputs); - #ifdef VST_USE_ALTERNATIVE_MAGIC - p->dwPluginId1 = CalculateCRC32fromFilename(p->szLibraryName); // Make Plugin ID unique for sure - #else - p->dwPluginId1 = pEffect->magic; - #endif // VST_USE_ALTERNATIVE_MAGIC - p->dwPluginId2 = pEffect->uniqueID; - if ((pEffect->flags & effFlagsIsSynth) || (!pEffect->numInputs)) p->bIsInstrument = TRUE; +#ifdef VST_LOG + int nver = pEffect->dispatcher(pEffect, effGetVstVersion, 0,0, nullptr, 0); + if (!nver) nver = pEffect->version; + Log("%-20s: v%d.0, %d in, %d out, %2d programs, %2d params, flags=0x%04X realQ=%d offQ=%d\n", + p->szLibraryName, nver, + pEffect->numInputs, pEffect->numOutputs, + pEffect->numPrograms, pEffect->numParams, + pEffect->flags, pEffect->realQualities, pEffect->offQualities); +#endif // VST_LOG - #ifdef VST_LOG - int nver = pEffect->dispatcher(pEffect, effGetVstVersion, 0,0, nullptr, 0); - if (!nver) nver = pEffect->version; - Log("%-20s: v%d.0, %d in, %d out, %2d programs, %2d params, flags=0x%04X realQ=%d offQ=%d\n", - p->szLibraryName, nver, - pEffect->numInputs, pEffect->numOutputs, - pEffect->numPrograms, pEffect->numParams, - pEffect->flags, pEffect->realQualities, pEffect->offQualities); - #endif // VST_LOG + pEffect->dispatcher(pEffect, effClose, 0, 0, 0, 0); - pEffect->dispatcher(pEffect, effClose, 0, 0, 0, 0); - - validPlug = true; - } - } catch(...) - { - CVstPluginManager::ReportPlugException("Exception while trying to load plugin \"%s\"!\n", p->szLibraryName); - } - - // If OK, write the information in PluginCache - if(validPlug) - { - const CString cacheSection = "PluginCache"; - const CString cacheFile = theApp.GetPluginCacheFileName(); - CString IDs, flagsKey; - IDs.Format("%08X%08X", p->dwPluginId1, p->dwPluginId2); - flagsKey.Format("%s.Flags", IDs); - - _tcsncpy(szPath, pszDllPath, CountOf(szPath) - 1); - if(theApp.IsPortableMode()) - { - theApp.AbsolutePathToRelative(szPath); - } - StringFixer::SetNullTerminator(szPath); - - WritePrivateProfileString(cacheSection, IDs, szPath, cacheFile); - CMainFrame::WritePrivateProfileCString(cacheSection, IDs, pszDllPath, cacheFile); - CMainFrame::WritePrivateProfileCString(cacheSection, p->szLibraryName, IDs, cacheFile); - CMainFrame::WritePrivateProfileLong(cacheSection, flagsKey, p->bIsInstrument, cacheFile); - } - } else - #ifdef ENABLE_BUZZ - if (pBuzzGetInfo) - { - PVSTPLUGINLIB p - try - { - p = new VSTPLUGINLIB; - } catch(MPTMemoryException) - { - return nullptr; - } - - p->dwPluginId1 = kBuzzMagic; - p->dwPluginId2 = 0; - p->pPluginsList = nullptr; - lstrcpyn(p->szDllPath, pszDllPath, CountOf(p->szDllPath)); - _splitpath(pszDllPath, nullptr, nullptr, p->szLibraryName, nullptr); - p->szLibraryName[63] = 0; - p->pNext = m_pVstHead; - p->pPrev = nullptr; - if (m_pVstHead) m_pVstHead->pPrev = p; - m_pVstHead = p; - try - { - const CMachineInfo *pInfo = pBuzzGetInfo(); - if (pInfo) - { - p->dwPluginId2 = pInfo->Version; - if (pInfo->Name) - { - lstrcpyn(p->szLibraryName, pInfo->Name, CountOf(p->szLibraryName)); - } - validPlug = true; - } - } catch (...) - { - CVstPluginManager::ReportPlugException("Exception while trying to load buzz plugin \"%s\"!\n", p->szLibraryName); - } - } else - #endif // ENABLE_BUZZ - { - #ifdef VST_LOG - Log("Entry point not found!\n"); - #endif // VST_LOG + validPlug = true; } FreeLibrary(hLib); + } catch(...) + { + CVstPluginManager::ReportPlugException("Exception while trying to load plugin \"%s\"!\n", p->szLibraryName); + } - // Now it should be safe to assume that this plugin loaded properly. :) - WritePrivateProfileString("VST Plugins", "FailedPlugin", nullptr, theApp.GetConfigFileName()); + // Now it should be safe to assume that this plugin loaded properly. :) + WritePrivateProfileString("VST Plugins", "FailedPlugin", nullptr, theApp.GetConfigFileName()); - return (validPlug ? m_pVstHead : nullptr); - } else + // If OK, write the information in PluginCache + if(validPlug) { - #ifdef VST_LOG - Log("LoadLibrary(%s) failed!\n", pszDllPath); - #endif // VST_LOG + const CString cacheSection = "PluginCache"; + const CString cacheFile = theApp.GetPluginCacheFileName(); + CString IDs, flagsKey; + IDs.Format("%08X%08X", p->dwPluginId1, p->dwPluginId2); + flagsKey.Format("%s.Flags", IDs); - WritePrivateProfileString("VST Plugins", "FailedPlugin", nullptr, theApp.GetConfigFileName()); + _tcsncpy(szPath, pszDllPath, CountOf(szPath) - 1); + if(theApp.IsPortableMode()) + { + theApp.AbsolutePathToRelative(szPath); + } + StringFixer::SetNullTerminator(szPath); + + WritePrivateProfileString(cacheSection, IDs, szPath, cacheFile); + CMainFrame::WritePrivateProfileCString(cacheSection, IDs, pszDllPath, cacheFile); + CMainFrame::WritePrivateProfileCString(cacheSection, p->szLibraryName, IDs, cacheFile); + CMainFrame::WritePrivateProfileLong(cacheSection, flagsKey, p->isInstrument, cacheFile); } - return nullptr; + + return (validPlug ? m_pVstHead : nullptr); } -bool CVstPluginManager::RemovePlugin(PVSTPLUGINLIB pFactory) +bool CVstPluginManager::RemovePlugin(VSTPluginLib *pFactory) //---------------------------------------------------------- { - PVSTPLUGINLIB p = m_pVstHead; + VSTPluginLib *p = m_pVstHead; while (p) { @@ -509,11 +461,11 @@ //------------------------------------------------------------------------------------- { UINT nMatch = 0; - PVSTPLUGINLIB pFound = nullptr; + VSTPluginLib *pFound = nullptr; if (pMixPlugin) { - PVSTPLUGINLIB p = m_pVstHead; + VSTPluginLib *p = m_pVstHead; while (p) { @@ -567,6 +519,7 @@ return bOk; } } + if ((!pFound) && strcmp(pMixPlugin->GetLibraryName(), "")) { CHAR s[_MAX_PATH], dir[_MAX_PATH]; @@ -590,81 +543,52 @@ } } } + if (pFound) { - HINSTANCE hLibrary = NULL; - BOOL bOk = FALSE; + AEffect *pEffect = nullptr; + HINSTANCE hLibrary = nullptr; + bool validPlugin = false; + try { CriticalSection cs; - hLibrary = LoadLibrary(pFound->szDllPath); - if (hLibrary != NULL) + LoadPlugin(pFound->szDllPath, pEffect, hLibrary); + + if(pEffect != nullptr && pEffect->dispatcher != nullptr && pEffect->magic == kEffectMagic) { - AEffect *pEffect = NULL; - PVSTPLUGENTRY pEntryPoint = (PVSTPLUGENTRY)GetProcAddress(hLibrary, "main"); - if(pEntryPoint == NULL) + validPlugin = true; + + if(pEffect->flags & effFlagsIsSynth || !pEffect->numInputs) { - pEntryPoint = (PVSTPLUGENTRY)GetProcAddress(hLibrary, "VSTPluginMain"); - } - #ifdef ENABLE_BUZZ - GET_INFO pBuzzGetInfo = (GET_INFO)GetProcAddress(hLibrary, "GetInfo"); - CREATE_MACHINE pBuzzCreateMachine = (CREATE_MACHINE)GetProcAddress(hLibrary, "CreateMachine"); - #endif - if (pEntryPoint) - { - pEffect = pEntryPoint(MasterCallBack); - } else - #ifdef ENABLE_BUZZ - if ((pBuzzCreateMachine) && (pBuzzGetInfo)) - { - CMachineInterface *pBuzzMachine = pBuzzCreateMachine(); - const CMachineInfo *pBuzzInfo = pBuzzGetInfo(); - if ((pBuzzMachine) && (pBuzzInfo) && (pBuzzInfo->Type == MT_EFFECT)) + // Flag as instrument plugin + if (!pFound->isInstrument) { - pEffect = Buzz2Vst(pBuzzMachine, pBuzzInfo); + CString cacheSection = "PluginCache"; + CString cacheFile = theApp.GetPluginCacheFileName(); + //LPCSTR pszSection = "PluginCache"; + pFound->isInstrument = true; + CString flagsKey; + flagsKey.Format("%08X%08X.Flags", pFound->dwPluginId1, pFound->dwPluginId2); + CMainFrame::WritePrivateProfileLong(cacheSection, flagsKey, 1, cacheFile); } - } else - #endif - { - #ifdef VST_LOG - Log("Entry point not found! (handle=%08X)\n", hLibrary); - #endif } - if ((pEffect) && (pEffect->dispatcher) - && ((pEffect->magic == kEffectMagic) || (pEffect->magic == kBuzzMagic))) - { - bOk = TRUE; - if ((pEffect->flags & effFlagsIsSynth) || (!pEffect->numInputs)) - { - if (!pFound->bIsInstrument) - { - CString cacheSection = "PluginCache"; - CString cacheFile = theApp.GetPluginCacheFileName(); - //LPCSTR pszSection = "PluginCache"; - pFound->bIsInstrument = TRUE; - CString flagsKey; - flagsKey.Format("%08X%08X.Flags", pFound->dwPluginId1, pFound->dwPluginId2); - CMainFrame::WritePrivateProfileLong(cacheSection, flagsKey, 1, cacheFile); - } - } - CVstPlugin *pVstPlug = new CVstPlugin(hLibrary, pFound, pMixPlugin, pEffect); - if (pVstPlug) pVstPlug->Initialize(pSndFile); - } - } else + CVstPlugin *pVstPlug = new CVstPlugin(hLibrary, pFound, pMixPlugin, pEffect); + if (pVstPlug) pVstPlug->Initialize(pSndFile); + } + + if(!validPlugin) { - #ifdef VST_LOG - Log("LoadLibrary(\"%s\") failed!\n", pFound->szDllPath); - #endif + FreeLibrary(hLibrary); } - if ((!bOk) && (hLibrary)) FreeLibrary(hLibrary); } catch(...) { CVstPluginManager::ReportPlugException("Exception while trying to create plugin \"%s\"!\n", pFound->szLibraryName); } - return bOk; + return validPlugin; } else { // "plug not found" notification code MOVED to CSoundFile::Create @@ -679,7 +603,7 @@ void CVstPluginManager::OnIdle() //------------------------------ { - PVSTPLUGINLIB pFactory = m_pVstHead; + VSTPluginLib *pFactory = m_pVstHead; while (pFactory) { @@ -1335,7 +1259,7 @@ // CVstPlugin // -CVstPlugin::CVstPlugin(HMODULE hLibrary, VSTPLUGINLIB *pFactory, SNDMIXPLUGIN *pMixStruct, AEffect *pEffect) +CVstPlugin::CVstPlugin(HMODULE hLibrary, VSTPluginLib *pFactory, SNDMIXPLUGIN *pMixStruct, AEffect *pEffect) //---------------------------------------------------------------------------------------------------------- { m_hLibrary = hLibrary; @@ -1538,7 +1462,7 @@ Dispatch(effConnectOutput, 0, 0, nullptr, 0); if (m_pEffect->numOutputs > 1) Dispatch(effConnectOutput, 1, 0, nullptr, 0); } - CVstPlugin::Dispatch(effMainsChanged, 0,0, nullptr, 0); + Suspend(); CVstPlugin::Dispatch(effClose, 0, 0, nullptr, 0); m_pFactory = nullptr; if (m_hLibrary) @@ -1593,8 +1517,8 @@ } //rewbs.VSTcompliance: changed from BOOL to long -long CVstPlugin::GetNumPrograms() -//------------------------------- +VstInt32 CVstPlugin::GetNumPrograms() +//----------------------------------- { if ((m_pEffect) && (m_pEffect->numPrograms > 0)) { @@ -1759,7 +1683,7 @@ VstIntPtr CVstPlugin::Dispatch(VstInt32 opCode, VstInt32 index, VstIntPtr value, void *ptr, float opt) //---------------------------------------------------------------------------------------------------- { - long lresult = 0; + VstIntPtr lresult = 0; try { @@ -1990,17 +1914,17 @@ void CVstPlugin::Suspend() //------------------------ { - try + if(m_bPlugResumed) { - if(m_bPlugResumed) + try { Dispatch(effStopProcess, 0, 0, nullptr, 0.0f); Dispatch(effMainsChanged, 0, 0, nullptr, 0.0f); // calls plugin's suspend (theoretically, plugins should clean their buffers here, but oh well, the number of plugins which don't do this is surprisingly high.) m_bPlugResumed = false; + } catch (...) + { + CVstPluginManager::ReportPlugException("Exception in Suspend() (Plugin=%s)\n", m_pFactory->szLibraryName); } - } catch (...) - { - CVstPluginManager::ReportPlugException("Exception in Suspend() (Plugin=%s)\n", m_pFactory->szLibraryName); } } @@ -2342,21 +2266,21 @@ for (int mc=0; mc<16; mc++) //all midi chans { DWORD dwMidiCode = 0x80 | (mc & 0x0f); //command|channel|velocity - PVSTINSTCH pCh = &m_MidiCh[mc]; + VSTInstrChannel &channel = m_MidiCh[mc]; MidiPitchBend(mc, MIDI_PitchBend_Centre); // centre pitch bend MidiSend(0xB0|mc|(0x79<<8)); // reset all controllers MidiSend(0xB0|mc|(0x7b<<8)); // all notes off MidiSend(0xB0|mc|(0x78<<8)); // all sounds off - for (size_t i = 0; i < CountOf(pCh->uNoteOnMap); i++) //all notes + for (size_t i = 0; i < CountOf(channel.uNoteOnMap); i++) //all notes { - for (CHANNELINDEX c = 0; c < CountOf(pCh->uNoteOnMap[i]); c++) + for (CHANNELINDEX c = 0; c < CountOf(channel.uNoteOnMap[i]); c++) { - while (pCh->uNoteOnMap[i][c] && !overflow) + while (channel.uNoteOnMap[i][c] && !overflow) { overflow=!(MidiSend(dwMidiCode | (i << 8))); - pCh->uNoteOnMap[i][c]--; + channel.uNoteOnMap[i][c]--; } if (overflow) break; //yuck } @@ -2436,10 +2360,10 @@ void CVstPlugin::MidiCommand(UINT nMidiCh, UINT nMidiProg, WORD wMidiBank, UINT note, UINT vol, UINT trackChannel) //---------------------------------------------------------------------------------------------------------------- { - PVSTINSTCH pCh = &m_MidiCh[nMidiCh]; + VSTInstrChannel &channel = m_MidiCh[nMidiCh]; DWORD dwMidiCode = 0; - bool bankChanged = (pCh->wMidiBank != --wMidiBank) && (wMidiBank < 0x80); - bool progChanged = (pCh->nProgram != --nMidiProg) && (nMidiProg < 0x80); + bool bankChanged = (channel.wMidiBank != --wMidiBank) && (wMidiBank < 0x80); + bool progChanged = (channel.nProgram != --nMidiProg) && (nMidiProg < 0x80); //bool chanChanged = nCh != m_nPreviousMidiChan; //get vol in [0,128[ vol = min(vol / 2, 127); @@ -2452,7 +2376,7 @@ // Bank change if ((wMidiBank < 0x80) && ( bankChanged /*|| chanChanged */)) { - pCh->wMidiBank = wMidiBank; + channel.wMidiBank = wMidiBank; MidiSend(((wMidiBank<<16)|(0x20<<8))|(0xB0|nMidiCh)); } // Program change @@ -2460,7 +2384,7 @@ // need to force it by sending prog change too. if ((nMidiProg < 0x80) && (progChanged || bankChanged /*|| chanChanged */ )) { - pCh->nProgram = nMidiProg; + channel.nProgram = nMidiProg; //GetSoundFile()->ProcessMIDIMacro(trackChannel, false, GetSoundFile()->m_MidiCfg.szMidiGlb[MIDIOUT_PROGRAM], 0); MidiSend((nMidiProg<<8)|(0xC0|nMidiCh)); } @@ -2473,9 +2397,9 @@ note--; UINT i = note - NOTE_KEYOFF; - if (pCh->uNoteOnMap[i][trackChannel]) + if (channel.uNoteOnMap[i][trackChannel]) { - pCh->uNoteOnMap[i][trackChannel]--; + channel.uNoteOnMap[i][trackChannel]--; MidiSend(dwMidiCode|(i<<8)); } } @@ -2492,7 +2416,7 @@ dwMidiCode = 0x80|nMidiCh|(vol<<16); //note off, on chan nCh; vol is note off velocity. for (UINT i=0; i<128; i++) //all notes { - pCh->uNoteOnMap[i][trackChannel]=0; + channel.uNoteOnMap[i][trackChannel]=0; MidiSend(dwMidiCode|(i<<8)); } @@ -2508,11 +2432,11 @@ { // Some VSTis need a note off for each instance of a note on, e.g. fabfilter. // But this can cause a VST event overflow if we have many active notes... - while (pCh->uNoteOnMap[i][trackChannel]) + while (channel.uNoteOnMap[i][trackChannel]) { if (MidiSend(dwMidiCode|(i<<8))) { - pCh->uNoteOnMap[i][trackChannel]--; + channel.uNoteOnMap[i][trackChannel]--; } else { // VST event queue overflow, no point in submitting more note offs. @@ -2541,8 +2465,8 @@ // Problem: if a note dies out naturally and we never send a note off, this counter // will block at max until note off. Is this a problem? // Safe to assume we won't need more than 16 note offs max on a given note? - if (pCh->uNoteOnMap[note][trackChannel]<17) - pCh->uNoteOnMap[note][trackChannel]++; + if (channel.uNoteOnMap[note][trackChannel] < 17) + channel.uNoteOnMap[note][trackChannel]++; @@ -2558,8 +2482,7 @@ //------------------------------------------------------------------ { note--; - PVSTINSTCH pMidiCh = &m_MidiCh[midiChn]; - return (pMidiCh->uNoteOnMap[note][trackerChn] != 0); + return (m_MidiCh[midiChn].uNoteOnMap[note][trackerChn] != 0); } @@ -2567,7 +2490,7 @@ //--------------------------------------------------------------------------------------------- { note--; - PVSTINSTCH pMidiCh = &m_MidiCh[midiChn & 0x0f]; + VSTInstrChannel *pMidiCh = &m_MidiCh[midiChn & 0x0f]; if (!(pMidiCh->uNoteOnMap[note][sourceTrackerChn])) return false; @@ -2806,47 +2729,17 @@ } -UINT CVstPlugin::GetNumCommands() -//------------------------------- -{ - if ((m_pEffect) && (m_pEffect->magic == kBuzzMagic)) - { - return Dispatch(effBuzzGetNumCommands, 0, nullptr, nullptr, 0.0f); - } - else if (m_pEffect) - { - return m_pEffect->numParams; - } - return 0; -} - - BOOL CVstPlugin::GetCommandName(UINT nIndex, LPSTR pszName) //--------------------------------------------------------- { - if ((m_pEffect) && (m_pEffect->magic == kBuzzMagic)) + if (m_pEffect) { - return Dispatch(effBuzzGetCommandName, nIndex, nullptr, pszName, 0.0f); - } - else if (m_pEffect) - { return Dispatch(effGetParamName, nIndex, nullptr, pszName, 0.0f); } return 0; } -BOOL CVstPlugin::ExecuteCommand(UINT nIndex) -//------------------------------------------ -{ - if ((m_pEffect) && (m_pEffect->magic == kBuzzMagic)) - { - return Dispatch(effBuzzExecuteCommand, nIndex, nullptr, nullptr, 0.0f); - } - return 0; -} - - //rewbs.defaultPlugGui CAbstractVstEditor* CVstPlugin::GetEditor() //----------------------------------------- @@ -3038,412 +2931,6 @@ } -////////////////////////////////////////////////////////////////////////////////////// -// -// BUZZ -> VST converter -// - -#ifdef ENABLE_BUZZ - -class CBuzz2Vst; - -//=========================================== -class CVSTDataInput: public CMachineDataInput -//=========================================== -{ -protected: - CBuzz2Vst *m_pParent; - -public: - CVSTDataInput(CBuzz2Vst *p) { m_pParent = p; } - virtual void Read(void *pbuf, int const numbytes) { Log("Read(%08X, %d)\n", pbuf, numbytes);} -}; - - -//================================== -class CBuzz2Vst: public CMICallbacks -//================================== -{ -protected: - AEffect m_Effect; - const CMachineInfo *m_pMachineInfo; - CMachineInterface *m_pMachineInterface; - CVSTDataInput *m_pDataInput; - CMasterInfo m_MasterInfo; - CWaveLevel m_WaveLevel; - short m_Waveform[32]; - -public: - CBuzz2Vst(CMachineInterface *, const CMachineInfo *); - ~CBuzz2Vst(); - AEffect *GetEffect() { return &m_Effect; } - VstIntPtr Dispatcher(VstInt32 opCode, VstInt32 index, VstIntPtr value, void *ptr, float opt); - void SetParameter(VstInt32 index, float parameter); - float GetParameter(VstInt32 index); - void Process(float **inputs, float **outputs, long sampleframes); - -public: - static VstIntPtr VSTCALLBACK BuzzDispatcher(AEffect *effect, VstInt32 opCode, VstInt32 index, VstIntPtr value, void *ptr, float opt); - static void VSTCALLBACK BuzzSetParameter(AEffect *effect, VstInt32 index, float parameter); - static float VSTCALLBACK BuzzGetParameter(AEffect *effect, VstInt32 index); - static void VSTCALLBACK BuzzProcess(AEffect *effect, float **inputs, float **outputs, VstInt32 sampleframes); - - // CMICallbacks interface -public: - virtual CWaveInfo const *GetWave(int const) { Log("GetWave\n"); return nullptr; } - virtual CWaveLevel const *GetWaveLevel(int const i, int const level) { Log("GetWaveLevel\n"); return nullptr; } - virtual void MessageBox(char const *txt) { Reporting::Notification(txt, m_pMachineInfo->Name); } - virtual void Lock() { Log("Lock\n"); } - virtual void Unlock() { Log("Unlock\n"); } - virtual int GetWritePos() { Log("GetWritePos\n"); return 0; } - virtual int GetPlayPos() { Log("GetPlayPos\n"); return 0; } - virtual float *GetAuxBuffer() { Log("GetAuxBuffer\n"); return nullptr; } - virtual void ClearAuxBuffer() { Log("ClearAuxBuffer\n"); } - virtual int GetFreeWave() { Log("GetFreeWave\n"); return 0; } - virtual bool AllocateWave(int const i, int const size, char const *name) { Log("AllocateWave\n"); return false; } - virtual void ScheduleEvent(int const time, dword const data) { Log("ScheduleEvent\n"); } - virtual void MidiOut(int const dev, dword const data) { Log("MidiOut\n"); } - virtual short const *GetOscillatorTable(int const waveform) { Log("GetOscillatorTable\n"); return nullptr; } - - // envelopes - virtual int GetEnvSize(int const wave, int const env) { Log("GetEnvSize\n"); return 0; } - virtual bool GetEnvPoint(int const wave, int const env, int const i, word &x, word &y, int &flags) { Log("GetEnvPoint\n"); return false; } - virtual CWaveLevel const *GetNearestWaveLevel(int const i, int const note) { Log("GetNearestWaveLevel(%d, %d)\n", i, note); return &m_WaveLevel; } - - // pattern editing - virtual void SetNumberOfTracks(int const n) { Log("SetNumberOfTracks\n"); } - virtual CPattern *CreatePattern(char const *name, int const length) { Log("CreatePattern\n"); return nullptr; } - virtual CPattern *GetPattern(int const index) { Log("GetPattern\n"); return nullptr; } - virtual char const *GetPatternName(CPattern *ppat) { Log("GetPatternName\n"); return ""; } - virtual void RenamePattern(char const *oldname, char const *newname) { Log("RenamePattern\n"); } - virtual void DeletePattern(CPattern *ppat) { Log("DeletePattern\n"); } - virtual int GetPatternData(CPattern *ppat, int const row, int const group, int const track, int const field) { Log("GetPatternData\n"); return 0; } - virtual void SetPatternData(CPattern *ppat, int const row, int const group, int const track, int const field, int const value) { Log("SetPatternData\n"); } - - // sequence editing - virtual CSequence *CreateSequence() { Log("CreateSequence\n"); return nullptr; } - virtual void DeleteSequence(CSequence *pseq) { Log("DeleteSequence\n"); } - - // special ppat values for GetSequenceData and SetSequenceData - // empty = nullptr - // <break> = (CPattern *)1 - // <mute> = (CPattern *)2 - // <thru> = (CPattern *)3 - virtual CPattern *GetSequenceData(int const row) { Log("GetSequenceData\n"); return nullptr; } - virtual void SetSequenceData(int const row, CPattern *ppat) { Log("SetSequenceData\n"); } - - // buzz v1.2 (MI_VERSION 15) additions start here - virtual void SetMachineInterfaceEx(CMachineInterfaceEx *pex) { Log("SetMachineInterfaceEx\n"); } - // group 1=global, 2=track - virtual void ControlChange__obsolete__(int group, int track, int param, int value) { Log("ControlChange__obsolete__\n"); } - - // direct calls to audiodriver, used by WaveInput and WaveOutput - // shouldn't be used for anything else - virtual int ADGetnumChannels(bool input) { Log("ADGetNumChannels\n"); return 2; } - virtual void ADWrite(int channel, float *psamples, int numsamples) { Log("ADWrite\n"); } - virtual void ADRead(int channel, float *psamples, int numsamples) { Log("ADRead\n"); } - - virtual CMachine *GetThisMachine() { Log("GetThisMachine\n"); return nullptr; } - virtual void ControlChange(CMachine *pmac, int group, int track, int param, int value) { Log("ControlChange\n"); } // set value of parameter (group & 16 == don't record) - - // returns pointer to the sequence if there is a pattern playing - virtual CSequence *GetPlayingSequence(CMachine *pmac) { Log("GetPlayingSequence\n"); return nullptr; } - - // gets ptr to raw pattern data for row of a track of a currently playing pattern (or something like that) - virtual void *GetPlayingRow(CSequence *pseq, int group, int track) { Log("GetPlayingRow\n"); return nullptr; } - virtual int GetStateFlags() { Log("GetStateFlags\n"); return 0; } - virtual void SetnumOutputChannels(CMachine *pmac, int n) { Log("SetNumOutputChannels\n"); } // if n=1 Work(), n=2 WorkMonoToStereo() - virtual void SetEventHandler(CMachine *pmac, BEventType et, EVENT_HANDLER_PTR p, void *param) { Log("SetEventHandler\n"); } - virtual char const *GetWaveName(int const i) { Log("GetWavename\n"); return ""; } - virtual void SetInternalWaveName(CMachine *pmac, int const i, char const *name) { Log("SetInternalWaveName\n"); } // i >= 1, nullptr name to clear - virtual void GetMachineNames(CMachineDataOutput *pout) { Log("GetMachineNames\n"); } // *pout will get one name per Write() - virtual CMachine *GetMachine(char const *name) { Log("GetMachine\n"); return nullptr; } - virtual CMachineInfo const *GetMachineInfo(CMachine *pmac) { Log("GetMachineInfo\n"); return nullptr; } - virtual char const *GetMachineName(CMachine *pmac) { Log("GetMachineName\n"); return ""; } - virtual bool GetInput(int index, float *psamples, int numsamples, bool stereo, float *extrabuffer) { Log("GetInput\n"); return false; } -}; - - -CBuzz2Vst::CBuzz2Vst(CMachineInterface *pBuzzMachine, const CMachineInfo *pBuzzInfo) -//---------------------------------------------------------------------------------- -{ - m_pMachineInfo = pBuzzInfo; - m_pMachineInterface = pBuzzMachine; - m_pDataInput = new CVSTDataInput(this); - - MemsetZero(m_Effect); - m_Effect.magic = kBuzzMagic; - m_Effect.numPrograms = 1; - m_Effect.numParams = pBuzzInfo->numGlobalParameters; - m_Effect.numInputs = 2; - m_Effect.numOutputs = 2; - m_Effect.flags = 0; // see constants - m_Effect.ioRatio = 1.0f; - m_Effect.object = this; - m_Effect.uniqueID = pBuzzInfo->Version; - m_Effect.version = 2; - // Callbacks - m_Effect.dispatcher = BuzzDispatcher; - m_Effect.setParameter = BuzzSetParameter; - m_Effect.getParameter = BuzzGetParameter; - m_Effect.process = BuzzProcess; - m_Effect.processReplacing = nullptr; - // Buzz Info - m_pMachineInterface->pMasterInfo = &m_MasterInfo; - m_pMachineInterface->pCB = this; - m_MasterInfo.BeatsPerMin = 125; - m_MasterInfo.TicksPerBeat = 6; - m_MasterInfo.SamplesPerSec = CSoundFile::gdwMixingFreq; - m_MasterInfo.SamplesPerTick = (int)((60*m_MasterInfo.SamplesPerSec) / (125*6)); - m_MasterInfo.PosInTick = 0; - m_MasterInfo.TicksPerSec = (float)m_MasterInfo.SamplesPerSec / (float)m_MasterInfo.SamplesPerTick; - // Dummy Wave Level - MemsetZero(m_Waveform); - m_WaveLevel.numSamples = 16; - m_WaveLevel.pSamples = m_Waveform; - m_WaveLevel.RootNote = 60; - m_WaveLevel.SamplesPerSec = 44100; - m_WaveLevel.LoopStart = 0; - m_WaveLevel.LoopEnd = 0; -} - - -CBuzz2Vst::~CBuzz2Vst() -//--------------------- -{ - m_Effect.object = nullptr; - if (m_pMachineInfo) - { - m_pMachineInfo = nullptr; - } - if (m_pMachineInterface) - { - delete m_pMachineInterface; - m_pMachineInterface = nullptr; - } - if (m_pDataInput) - { - delete m_pDataInput; - m_pDataInput = nullptr; - } -} - - -VstIntPtr CBuzz2Vst::BuzzDispatcher(AEffect *effect, VstInt32 opCode, VstInt32 index, VstIntPtr value, void *ptr, float opt) -//-------------------------------------------------------------------------------------------------------------------------- -{ - CBuzz2Vst *pBuzz2Vst = (CBuzz2Vst *)effect->object; - if (pBuzz2Vst) return pBuzz2Vst->Dispatcher(opCode, index, value, ptr, opt); - return 0; -} - - -void CBuzz2Vst::BuzzSetParameter(AEffect *effect, VstInt32 index, float parameter) -//-------------------------------------------------------------------------------- -{ - CBuzz2Vst *pBuzz2Vst = (CBuzz2Vst *)effect->object; - if (pBuzz2Vst) pBuzz2Vst->SetParameter(index, parameter); -} - - -float CBuzz2Vst::BuzzGetParameter(AEffect *effect, VstInt32 index) -//---------------------------------------------------------------- -{ - CBuzz2Vst *pBuzz2Vst = (CBuzz2Vst *)effect->object; - if (pBuzz2Vst) return pBuzz2Vst->GetParameter(index); - return 0; -} - - -void CBuzz2Vst::BuzzProcess(AEffect *effect, float **inputs, float **outputs, VstInt32 sampleframes) -//-------------------------------------------------------------------------------------------------- -{ - CBuzz2Vst *pBuzz2Vst = (CBuzz2Vst *)effect->object; - if (pBuzz2Vst) pBuzz2Vst->Process(inputs, outputs, sampleframes); -} - - -VstIntPtr CBuzz2Vst::Dispatcher(VstInt32 opCode, VstInt32 index, VstIntPtr value, void *ptr, float opt) -//----------------------------------------------------------------------------------------------------- -{ - if (!m_pMachineInterface) return 0; - switch(opCode) - { - case effOpen: - Log("Initializing machine...\n"); - m_pMachineInterface->Init(m_pDataInput); - Log("Done.\n"); - break; - - case effClose: - m_Effect.object = nullptr; - delete this; - return 0; - - case effIdentify: - return 'NvEf'; - - case effGetParamName: - if (index < m_pMachineInfo->numGlobalParameters) - { - const CMachineParameter *p = m_pMachineInfo->Parameters[index]; - if ((p) && (ptr) && (p->Name)) - { - lstrcpyn((char *)ptr, p->Name, 9); - } - } - break; - - case effGetParamDisplay: - if (index < m_pMachineInfo->numGlobalParameters) - { - const CMachineParameter *p = m_pMachineInfo->Parameters[index]; - if (p) - { - int value = p->DefValue; - const char *s = m_pMachineInterface->DescribeValue(index, value); - if ((s) && (ptr)) - { - lstrcpyn((char *)ptr, s, 9); - } - } - } - break; - - case effCanBeAutomated: - return (index < m_pMachineInfo->numGlobalParameters); - - // Buzz extensions - case effBuzzGetNumCommands: - { - const char *p = m_pMachineInfo->Commands; - UINT n = 0; - while (p) - { - if (!*p) - { - n++; - break; - } - if (*p == '\n') n++; - p++; - } - return n; - } - - case effBuzzGetCommandName: - if (ptr) - { - const char *p = m_pMachineInfo->Commands; - char *s = (char *)ptr; - UINT n = 0, len = 0; - while ((p) && (n <= (UINT)index)) - { - if (!*p) - { - n++; - break; - } - if (*p == '\n') n++; - if ((n == (UINT)index) && (len < 10)) - { - *s++ = *p; - len++; - } - p++; - } - *s = 0; - return 0; - } - - case effBuzzExecuteCommand: - { - m_pMachineInterface->Command(index); - } - } - return 0; -} - - -void CBuzz2Vst::SetParameter(VstInt32 index, float parameter) -//----------------------------------------------------------- -{ - -} - - -float CBuzz2Vst::GetParameter(VstInt32 index) -//------------------------------------------- -{ - if (index < m_pMachineInfo->numGlobalParameters) - { - const CMachineParameter *p = m_pMachineInfo->Parameters[index]; - if (p) - { - float fmin = (float)p->MinValue; - float fmax = (float)p->MaxValue; - float f = (float)p->DefValue; - if (p->MinValue < p->MaxValue) - { - return (f - fmin) / (fmax - fmin); - } - } - } - return 0; -} - - -void X86_Interleave(const float *pinL, const float *pinR, float *pout, int nsamples) -//---------------------------------------------------------------------------------- -{ - for (int i=0; i<nsamples; i++) - { - pout[i*2] = pinL[i]; - pout[i*2+1] = pinR[i]; - } -} - - -void X86_AddAndDeinterleave(const float *pin, float *poutL, float *poutR, int nsamples) -//------------------------------------------------------------------------------------- -{ - for (int i=0; i<nsamples; i++) - { - poutL[i] += pin[i*2]; - poutR[i] += pin[i*2+1]; - } -} - - -void CBuzz2Vst::Process(float **inputs, float **outputs, long sampleframes) -//------------------------------------------------------------------------- -{ - float *pinL = inputs[0], *pinR = inputs[1]; - float *poutL = outputs[0], *poutR = outputs[1]; - float Buffer[MIXBUFFERSIZE * 2]; // Stereo interleaved - - // Re-interleave the stereo mix - X86_Interleave(pinL, pinR, Buffer, sampleframes); - // Process - m_pMachineInterface->Work(Buffer, sampleframes, WM_READWRITE); - // De-interleave and add the result - X86_AddAndDeinterleave(Buffer, poutL, poutR, sampleframes); -} - - -AEffect *Buzz2Vst(CMachineInterface *pBuzzMachine, const CMachineInfo *pBuzzInfo) -//------------------------------------------------------------------------------- -{ - CBuzz2Vst *p; - - if ((!pBuzzMachine) || (!pBuzzInfo)) return nullptr; - p = new CBuzz2Vst(pBuzzMachine, pBuzzInfo); - return (p) ? p->GetEffect() : nullptr; -} - -#endif // ENABLE_BUZZ - - ////////////////////////////////////////////////////////////////////////////////////////////////// // // DirectX Media Object support @@ -3933,7 +3420,7 @@ } -AEffect *DmoToVst(PVSTPLUGINLIB pLib) +AEffect *DmoToVst(VSTPluginLib *pLib) //----------------------------------- { WCHAR w[100]; Modified: trunk/OpenMPT/mptrack/Vstplug.h =================================================================== --- trunk/OpenMPT/mptrack/Vstplug.h 2012-03-31 23:47:31 UTC (rev 1237) +++ trunk/OpenMPT/mptrack/Vstplug.h 2012-04-01 19:25:00 UTC (rev 1238) @@ -16,9 +16,9 @@ #endif #include "../soundlib/Snd_defs.h" -#include "../soundlib/PluginMixBuffer.h" +#include "../soundlib/plugins/PluginMixBuffer.h" -#define kBuzzMagic 'Buzz' +//#define kBuzzMagic 'Buzz' #define kDmoMagic 'DXMO' @@ -29,42 +29,35 @@ class CModDoc; class CSoundFile; -enum -{ - effBuzzGetNumCommands=0x1000, - effBuzzGetCommandName, - effBuzzExecuteCommand, -}; - #ifndef NO_VST typedef AEffect * (VSTCALLBACK * PVSTPLUGENTRY)(audioMasterCallback); -#endif +#endif // NO_VST -typedef struct _VSTPLUGINLIB +struct VSTPluginLib { - struct _VSTPLUGINLIB *pPrev, *pNext; - DWORD dwPluginId1; - DWORD dwPluginId2; - BOOL bIsInstrument; + VSTPluginLib *pPrev, *pNext; + VstInt32 dwPluginId1; + VstInt32 dwPluginId2; + bool isInstrument; CVstPlugin *pPluginsList; CHAR szLibraryName[_MAX_FNAME]; CHAR szDllPath[_MAX_PATH]; -} VSTPLUGINLIB, *PVSTPLUGINLIB; +}; -typedef struct _VSTINSTCH +struct VSTInstrChannel { //BYTE uNoteOnMap[128/8]; rewbs.deMystifyMidiNoteMap - BYTE uNoteOnMap[128][MAX_CHANNELS]; - UINT nProgram; - WORD wMidiBank; //rewbs.MidiBank -} VSTINSTCH, *PVSTINSTCH; + uint8 uNoteOnMap[128][MAX_CHANNELS]; + uint32 nProgram; + uint16 wMidiBank; //rewbs.MidiBank +}; #ifndef NO_VST -#include "../soundlib/PluginEventQueue.h" +#include "../soundlib/plugins/PluginEventQueue.h" #endif // NO_VST @@ -86,7 +79,7 @@ ULONG m_nRefCount; CVstPlugin *m_pNext, *m_pPrev; HINSTANCE m_hLibrary; - VSTPLUGINLIB *m_pFactory; + VSTPluginLib *m_pFactory; SNDMIXPLUGIN *m_pMixStruct; AEffect *m_pEffect; void (*m_pProcessFP)(AEffect*, float**, float**, VstInt32); //Function pointer to AEffect processReplacing if supported, else process. @@ -96,7 +89,7 @@ bool m_bIsVst2; SNDMIXPLUGINSTATE m_MixState; UINT m_nInputs, m_nOutputs; - VSTINSTCH m_MidiCh[16]; + VSTInstrChannel m_MidiCh[16]; short m_nMidiPitchBendPos[16]; CModDoc* m_pModDoc; //rewbs.plugDocAware @@ -118,17 +111,17 @@ PluginEventQueue<vstNumProcessEvents> vstEvents; // MIDI events that should be sent to the plugin public: - CVstPlugin(HINSTANCE hLibrary, VSTPLUGINLIB *pFactory, SNDMIXPLUGIN *pMixPlugin, AEffect *pEffect); + CVstPlugin(HINSTANCE hLibrary, VSTPluginLib *pFactory, SNDMIXPLUGIN *pMixPlugin, AEffect *pEffect); virtual ~CVstPlugin(); void Initialize(CSoundFile* pSndFile); public: - PVSTPLUGINLIB GetPluginFactory() const { return m_pFactory; } + VSTPluginLib *GetPluginFactory() const { return m_pFactory; } bool HasEditor(); - long GetNumPrograms(); + VstInt32 GetNumPrograms(); PlugParamIndex GetNumParameters(); - long GetCurrentProgram(); - long GetNumProgramCategories(); //rewbs.VSTpresets + VstInt32 GetCurrentProgram(); + VstInt32 GetNumProgramCategories(); //rewbs.VSTpresets CString GetFormattedProgramName(VstInt32 index, bool allowFallback = false); bool LoadProgram(CString fileName); bool SaveProgram(CString fileName); @@ -161,9 +154,7 @@ void ToggleEditor(); void GetPluginType(LPSTR pszType); BOOL GetDefaultEffectName(LPSTR pszName); - UINT GetNumCommands(); BOOL GetCommandName(UINT index, LPSTR pszName); - BOOL ExecuteCommand(UINT nIndex); CAbstractVstEditor* GetEditor(); //rewbs.defaultPlugGUI bool GetSpeakerArrangement(); //rewbs.VSTCompliance @@ -235,9 +226,9 @@ PlugParamIndex GetNumParameters() { return 0; } void ToggleEditor() {} bool HasEditor() { return false; } - UINT GetNumCommands() { return 0; } void GetPluginType(LPSTR) {} - PlugParamIndex GetNumPrograms() { return 0; } + VstInt32 GetNumPrograms() { return 0; } + VstInt32 GetCurrentProgram() { return 0; } bool GetProgramNameIndexed(long, long, char*) { return false; } CString GetFormattedProgramName(VstInt32, bool = false) { return ""; } void SetParameter(PlugParamIndex, PlugParamValue) {} @@ -254,7 +245,6 @@ bool LoadProgram(CString) {return false;} bool SaveProgram(CString) {return false;} void SetCurrentProgram(UINT) {} - BOOL ExecuteCommand(UINT) {return FALSE;} void SetSlot(UINT) {} void UpdateMixStructPtr(void*) {} void Bypass(bool = true) { } @@ -270,23 +260,24 @@ { #ifndef NO_VST protected: - PVSTPLUGINLIB m_pVstHead; + VSTPluginLib *m_pVstHead; public: CVstPluginManager(); ~CVstPluginManager(); public: - PVSTPLUGINLIB GetFirstPlugin() const { return m_pVstHead; } - BOOL IsValidPlugin(const VSTPLUGINLIB *pLib); - PVSTPLUGINLIB AddPlugin(LPCSTR pszDllPath, BOOL bCache=TRUE, const bool checkFileExistence = false, CString* const errStr = 0); - bool RemovePlugin(PVSTPLUGINLIB); + VSTPluginLib *GetFirstPlugin() const { return m_pVstHead; } + BOOL IsValidPlugin(const VSTPluginLib *pLib); + VSTPluginLib *AddPlugin(LPCSTR pszDllPath, BOOL bCache=TRUE, const bool checkFileExistence = false, CString* const errStr = 0); + bool RemovePlugin(VSTPluginLib *); BOOL CreateMixPlugin(SNDMIXPLUGIN *, CSoundFile *); void OnIdle(); static void ReportPlugException(LPCSTR format,...); protected: void EnumerateDirectXDMOs(); + void LoadPlugin(const char *pluginPath, AEffect *&effect, HINSTANCE &library); protected: VstIntPtr VstCallback(AEffect *effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void *ptr, float opt); @@ -302,8 +293,8 @@ #else // NO_VST public: - PVSTPLUGINLIB AddPlugin(LPCSTR, BOOL =TRUE, const bool = false, CString* const = 0) {return 0;} - PVSTPLUGINLIB GetFirstPlugin() const { return 0; } + VSTPluginLib *AddPlugin(LPCSTR, BOOL =TRUE, const bool = false, CString* const = 0) {return 0;} + VSTPluginLib *GetFirstPlugin() const { return 0; } void OnIdle() {} #endif // NO_VST }; Modified: trunk/OpenMPT/mptrack/mptrack_08.vcproj =================================================================== --- trunk/OpenMPT/mptrack/mptrack_08.vcproj 2012-03-31 23:47:31 UTC (rev 1237) +++ trunk/OpenMPT/mptrack/mptrack_08.vcproj 2012-04-01 19:25:00 UTC (rev 1238) @@ -521,6 +521,10 @@ > </File> <File + RelativePath="..\soundlib\plugins\JBridge.cpp" + > + </File> + <File RelativePath=".\SampleEditorDialogs.cpp" > </File> @@ -1139,18 +1143,22 @@ > </File> <File - RelativePath=".\soundlib\PluginEventQueue.h" + RelativePath=".\soundlib\plugins\PluginEventQueue.h" > </File> <File - RelativePath=".\soundlib\PluginMixBuffer.h" + RelativePath=".\soundlib\plugins\PluginMixBuffer.h" > </File> <File - RelativePath=".\soundlib\PlugInterface.h" + RelativePath=".\soundlib\plugins\PlugInterface.h" > </File> <File + RelativePath=".\soundlib\plugins\JBridge.h" + > + </File> + <File RelativePath=".\soundlib\RowVisitor.h" > </File> Modified: trunk/OpenMPT/mptrack/mptrack_10.vcxproj =================================================================== --- trunk/OpenMPT/mptrack/mptrack_10.vcxproj 2012-03-31 23:47:31 UTC (rev 1237) +++ trunk/OpenMPT/mptrack/mptrack_10.vcxproj 2012-04-01 19:25:00 UTC (rev 1238) @@ -174,6 +174,7 @@ <ClCompile Include="..\soundlib\ModChannel.cpp" /> <ClCompile Include="..\soundlib\ModInstrument.cpp" /> <ClCompile Include="..\soundlib\ModSample.cpp" /> + <ClCompile Include="..\soundlib\plugins\JBridge.cpp" /> <ClCompile Include="..\soundlib\RowVisitor.cpp" /> <ClCompile Include="..\soundlib\XMTools.cpp" /> <ClCompile Include="AbstractVstEditor.cpp" /> @@ -336,9 +337,10 @@ <ClInclude Include="..\soundlib\ModChannel.h" /> <ClInclude Include="..\soundlib\ModInstrument.h" /> <ClInclude Include="..\soundlib\ModSample.h" /> - <ClInclude Include="..\soundlib\PluginEventQueue.h" /> - <ClInclude Include="..\soundlib\PluginMixBuffer.h" /> - <ClInclude Include="..\soundlib\PlugInterface.h" /> + <ClInclude Include="..\soundlib\plugins\JBridge.h" /> + <ClInclude Include="..\soundlib\plugins\PluginEventQueue.h" /> + <ClInclude Include="..\soundlib\plugins\PluginMixBuffer.h" /> + <ClInclude Include="..\soundlib\plugins\PlugInterface.h" /> <ClInclude Include="..\soundlib\RowVisitor.h" /> <ClInclude Include="..\soundlib\XMTools.h" /> <ClInclude Include="ACMConvert.h" /> Modified: trunk/OpenMPT/mptrack/mptrack... [truncated message content] |