From: <sag...@us...> - 2011-03-19 13:26:44
|
Revision: 816 http://modplug.svn.sourceforge.net/modplug/?rev=816&view=rev Author: saga-games Date: 2011-03-19 13:26:38 +0000 (Sat, 19 Mar 2011) Log Message: ----------- [Fix] VST: Fixed garbage characters in preset fields of plugins that don't return program names. [Fix] Comments Tab: When changing font size, the editor is now resized instantly. Modified Paths: -------------- trunk/OpenMPT/mptrack/AbstractVstEditor.cpp trunk/OpenMPT/mptrack/Ctrl_com.cpp trunk/OpenMPT/mptrack/View_gen.cpp trunk/OpenMPT/mptrack/Vstplug.cpp trunk/OpenMPT/mptrack/Vstplug.h Modified: trunk/OpenMPT/mptrack/AbstractVstEditor.cpp =================================================================== --- trunk/OpenMPT/mptrack/AbstractVstEditor.cpp 2011-03-09 12:35:25 UTC (rev 815) +++ trunk/OpenMPT/mptrack/AbstractVstEditor.cpp 2011-03-19 13:26:38 UTC (rev 816) @@ -139,6 +139,7 @@ //TODO: exception handling if (!(m_pVstPlugin->SaveProgram(files.first_file.c_str()))) ::AfxMessageBox("Error saving preset."); + } VOID CAbstractVstEditor::OnRandomizePreset() @@ -172,25 +173,29 @@ void CAbstractVstEditor::UpdatePresetField() //------------------------------------------ { - - if(m_pVstPlugin->GetNumPrograms() > 0 && m_pMenu->GetMenuItemCount() < 5) + if(m_pVstPlugin->GetNumPrograms() > 0) { - m_pMenu->AppendMenu(MF_BYPOSITION, ID_VSTPRESETBACKWARDJUMP, TEXT("<<")); - m_pMenu->AppendMenu(MF_BYPOSITION, ID_PREVIOUSVSTPRESET, TEXT("<")); - m_pMenu->AppendMenu(MF_BYPOSITION, ID_NEXTVSTPRESET, TEXT(">")); - m_pMenu->AppendMenu(MF_BYPOSITION, ID_VSTPRESETFORWARDJUMP, TEXT(">>")); - m_pMenu->AppendMenu(MF_BYPOSITION|MF_DISABLED, 0, TEXT("")); + if(m_pMenu->GetMenuItemCount() < 5) + { + m_pMenu->AppendMenu(MF_BYPOSITION, ID_VSTPRESETBACKWARDJUMP, TEXT("<<")); + m_pMenu->AppendMenu(MF_BYPOSITION, ID_PREVIOUSVSTPRESET, TEXT("<")); + m_pMenu->AppendMenu(MF_BYPOSITION, ID_NEXTVSTPRESET, TEXT(">")); + m_pMenu->AppendMenu(MF_BYPOSITION, ID_VSTPRESETFORWARDJUMP, TEXT(">>")); + m_pMenu->AppendMenu(MF_BYPOSITION|MF_DISABLED, 0, TEXT("")); + } + long index = m_pVstPlugin->GetCurrentProgram(); + char name[266]; + char rawname[256]; + if(!m_pVstPlugin->GetProgramNameIndexed(index, -1, rawname)) + { + strcpy(rawname, ""); + } + SetNullTerminator(rawname); + CreateVerifiedProgramName(rawname, sizeof(rawname), name, sizeof(name), index); + + m_pMenu->ModifyMenu(8, MF_BYPOSITION, 0, name); } - long index = m_pVstPlugin->GetCurrentProgram(); - char name[266]; - char rawname[256]; - m_pVstPlugin->GetProgramNameIndexed(index, -1, rawname); - rawname[sizeof(rawname)-1] = 0; - CreateVerifiedProgramName(rawname, sizeof(rawname), name, sizeof(name), index); - - m_pMenu->ModifyMenu(8, MF_BYPOSITION, 0, name); - DrawMenuBar(); } @@ -255,7 +260,8 @@ //We handle keypresses before Windows has a chance to handle them (for alt etc..) if ( (!m_pVstPlugin->m_bPassKeypressesToPlug) && ((pMsg->message == WM_SYSKEYUP) || (pMsg->message == WM_KEYUP) || - (pMsg->message == WM_SYSKEYDOWN) || (pMsg->message == WM_KEYDOWN)) ) { + (pMsg->message == WM_SYSKEYDOWN) || (pMsg->message == WM_KEYDOWN)) ) + { CInputHandler* ih = (CMainFrame::GetMainFrame())->GetInputHandler(); @@ -267,13 +273,15 @@ InputTargetContext ctx = (InputTargetContext)(kCtxVSTGUI); // If we successfully mapped to a command and plug does not listen for keypresses, no need to pass message on. - if (ih->KeyEvent(ctx, nChar, nRepCnt, nFlags, kT, (CWnd*)this) != kcNull) { + if (ih->KeyEvent(ctx, nChar, nRepCnt, nFlags, kT, (CWnd*)this) != kcNull) + { return true; } // Don't forward key repeats if plug does not listen for keypresses // (avoids system beeps on note hold) - if (kT == kKeyEventRepeat) { + if (kT == kKeyEventRepeat) + { return true; } } @@ -361,7 +369,7 @@ if(!pModDoc || !pSndFile) return false; - if(pModDoc->GetSoundFile()->GetModSpecifications().instrumentsMax == 0 || + if(!m_pVstPlugin->isInstrument() || pModDoc->GetSoundFile()->GetModSpecifications().instrumentsMax == 0 || AfxMessageBox(_T("You need to assign an instrument to this plugin before you can play notes from here.\nCreate a new instrument and assign this plugin to the instrument?"), MB_YESNO | MB_ICONQUESTION) == IDNO) { return false; @@ -376,8 +384,8 @@ MODINSTRUMENT *pIns = pSndFile->Instruments[nIns]; m_nInstrument = nIns; - _snprintf(pIns->name, ARRAYELEMCOUNT(pIns->name) - 1, _T("%d: %s"), m_pVstPlugin->GetSlot() + 1, pSndFile->m_MixPlugins[m_pVstPlugin->GetSlot()].Info.szName); - strncpy(pIns->filename, pSndFile->m_MixPlugins[m_pVstPlugin->GetSlot()].Info.szLibraryName, ARRAYELEMCOUNT(pIns->filename) - 1); + _snprintf(pIns->name, CountOf(pIns->name) - 1, _T("%d: %s"), m_pVstPlugin->GetSlot() + 1, pSndFile->m_MixPlugins[m_pVstPlugin->GetSlot()].Info.szName); + strncpy(pIns->filename, pSndFile->m_MixPlugins[m_pVstPlugin->GetSlot()].Info.szLibraryName, CountOf(pIns->filename) - 1); pIns->nMixPlug = (PLUGINDEX)m_pVstPlugin->GetSlot() + 1; pIns->nMidiChannel = 1; // People will forget to change this anyway, so the following lines can lead to some bad surprises after re-opening the module. @@ -432,9 +440,12 @@ } for (long p=0; p<numProgs; p++) { - m_pVstPlugin->GetProgramNameIndexed(p, -1, sname); + if(!m_pVstPlugin->GetProgramNameIndexed(p, -1, sname)) + { + strcpy(sname, ""); + } + SetNullTerminator(sname); - sname[sizeof(sname)-1] = 0; CreateVerifiedProgramName(sname, sizeof(sname), s, sizeof(s), p); // Get menu item properties Modified: trunk/OpenMPT/mptrack/Ctrl_com.cpp =================================================================== --- trunk/OpenMPT/mptrack/Ctrl_com.cpp 2011-03-09 12:35:25 UTC (rev 815) +++ trunk/OpenMPT/mptrack/Ctrl_com.cpp 2011-03-19 13:26:38 UTC (rev 816) @@ -96,7 +96,6 @@ if ((pHint == this) || (!m_pSndFile) || (!(dwHint & (HINT_MODCOMMENTS|HINT_MPTOPTIONS|HINT_MODTYPE)))) return; if (m_nLockCount) return; m_nLockCount++; - m_EditComments.SetRedraw(FALSE); HFONT newfont; if (CMainFrame::m_dwPatternSetup & PATTERN_LARGECOMMENTS) newfont = CMainFrame::GetLargeFixedFont(); @@ -106,7 +105,9 @@ { m_hFont = newfont; m_EditComments.SendMessage(WM_SETFONT, (WPARAM)newfont); + RecalcLayout(); } + m_EditComments.SetRedraw(FALSE); m_EditComments.SetSel(0, -1, TRUE); m_EditComments.ReplaceSel(""); if (m_pSndFile->m_lpszSongComments) Modified: trunk/OpenMPT/mptrack/View_gen.cpp =================================================================== --- trunk/OpenMPT/mptrack/View_gen.cpp 2011-03-09 12:35:25 UTC (rev 815) +++ trunk/OpenMPT/mptrack/View_gen.cpp 2011-03-19 13:26:38 UTC (rev 816) @@ -1507,7 +1507,11 @@ m_CbnPreset.SetItemData(m_CbnPreset.AddString(s2), 0); for (UINT i = 0; i < nProg; i++) { - pVstPlugin->GetProgramNameIndexed(i, 0, sname); + if(!pVstPlugin->GetProgramNameIndexed(i, 0, sname)) + { + strcpy(sname, ""); + } + SetNullTerminator(sname); if(sname[0] < ' ') { Modified: trunk/OpenMPT/mptrack/Vstplug.cpp =================================================================== --- trunk/OpenMPT/mptrack/Vstplug.cpp 2011-03-09 12:35:25 UTC (rev 815) +++ trunk/OpenMPT/mptrack/Vstplug.cpp 2011-03-19 13:26:38 UTC (rev 816) @@ -2093,32 +2093,38 @@ bool success; //Collect required data - PlugParamIndex numParams = GetNumParameters(); long ID = GetUID(); long plugVersion = GetVersion(); - float *params = new float[numParams]; - GetParams(params, 0, numParams); - Cfxp* fxp = NULL; + Cfxp* fxp = nullptr; //Construct & save fxp + + // try chunk-based preset: if(m_pEffect->flags & effFlagsProgramChunks) - { // try chunk-based preset: + { void *chunk = NULL; long chunkSize = Dispatch(effGetChunk, 1,0, &chunk, 0); - if ((chunkSize > 8) && (chunk)) //If chunk is less that 8 bytes, the plug must be kidding. :) (e.g.: imageline sytrus) + if ((chunkSize > 8) && (chunk)) //If chunk is less than 8 bytes, the plug must be kidding. :) (e.g.: imageline sytrus) fxp = new Cfxp(ID, plugVersion, 1, chunkSize, chunk); } - if (fxp == NULL) - { // fall back on parameter based preset: + // fall back on parameter based preset: + if (fxp == nullptr) + { + //Collect required data + PlugParamIndex numParams = GetNumParameters(); + float *params = new float[numParams]; + GetParams(params, 0, numParams); + fxp = new Cfxp(ID, plugVersion, numParams, params); + + delete[] params; } success = fxp->Save(fileName); if (fxp) delete fxp; - delete[] params; return success; } @@ -2182,14 +2188,14 @@ return 0; } -long CVstPlugin::GetProgramNameIndexed(long index, long category, char *text) +bool CVstPlugin::GetProgramNameIndexed(long index, long category, char *text) //--------------------------------------------------------------------------- { if ((m_pEffect) && (m_pEffect->numPrograms > 0)) { - return Dispatch(effGetProgramNameIndexed, index, category, text, 0); + return (Dispatch(effGetProgramNameIndexed, index, category, text, 0) == 1); } - return 0; + return false; } @@ -2251,10 +2257,10 @@ pszName[0] = 0; if ((m_pEffect) && (m_pEffect->numParams > 0) && (nIndex < (UINT)m_pEffect->numParams)) { - CHAR s[64]; //Increased to 64 bytes since 32 bytes doesn't seem to suffice for all plugs. + CHAR s[64]; // Increased to 64 bytes since 32 bytes doesn't seem to suffice for all plugs. Kind of ridiculous if you consider that kVstMaxParamStrLen = 8... s[0] = 0; Dispatch(effGetParamName, nIndex, 0, s, 0); - s[min(sizeof(s)-1, cbSize-1)] = 0; + s[min(CountOf(s) - 1, cbSize - 1)] = 0; lstrcpyn(pszName, s, min(cbSize, sizeof(s))); } } @@ -2295,7 +2301,7 @@ } void CVstPlugin::Init(unsigned long /*nFreq*/, int /*bReset*/) -//---------------------------------------------------- +//------------------------------------------------------------ { } Modified: trunk/OpenMPT/mptrack/Vstplug.h =================================================================== --- trunk/OpenMPT/mptrack/Vstplug.h 2011-03-09 12:35:25 UTC (rev 815) +++ trunk/OpenMPT/mptrack/Vstplug.h 2011-03-19 13:26:38 UTC (rev 816) @@ -109,7 +109,7 @@ PlugParamIndex GetNumParameters(); long GetCurrentProgram(); long GetNumProgramCategories(); //rewbs.VSTpresets - long GetProgramNameIndexed(long index, long category, char *text); //rewbs.VSTpresets + bool GetProgramNameIndexed(long index, long category, char *text); //rewbs.VSTpresets bool LoadProgram(CString fileName); bool SaveProgram(CString fileName); VstInt32 GetUID(); //rewbs.VSTpresets @@ -205,7 +205,7 @@ UINT GetNumCommands() {return 0;} VOID GetPluginType(LPSTR) {} PlugParamIndex GetNumPrograms() {return 0;} - long GetProgramNameIndexed(long, long, char*) {return 0;} + bool GetProgramNameIndexed(long, long, char*) {return 0;} VOID SetParameter(PlugParamIndex nIndex, PlugParamValue fValue) {} VOID GetParamLabel(UINT, LPSTR) {} VOID GetParamDisplay(UINT, LPSTR) {} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |