From: <sag...@us...> - 2010-05-07 18:23:25
|
Revision: 586 http://modplug.svn.sourceforge.net/modplug/?rev=586&view=rev Author: saga-games Date: 2010-05-07 18:23:18 +0000 (Fri, 07 May 2010) Log Message: ----------- [Imp] Sample Editor: When enabling a sample loop and only parts of the sample are selected [Imp] VST Editor: Instead of just saying the user that the plugin has to be assigned to an instrument to play notes, they are queried now whether they want to automatically add an instrument. [Ref] Related code refactoring Modified Paths: -------------- trunk/OpenMPT/mptrack/AbstractVstEditor.cpp trunk/OpenMPT/mptrack/AbstractVstEditor.h trunk/OpenMPT/mptrack/Ctrl_smp.cpp trunk/OpenMPT/mptrack/Moddoc.h trunk/OpenMPT/mptrack/Modedit.cpp Modified: trunk/OpenMPT/mptrack/AbstractVstEditor.cpp =================================================================== --- trunk/OpenMPT/mptrack/AbstractVstEditor.cpp 2010-05-06 22:39:17 UTC (rev 585) +++ trunk/OpenMPT/mptrack/AbstractVstEditor.cpp 2010-05-07 18:23:18 UTC (rev 586) @@ -326,9 +326,8 @@ m_nInstrument = GetBestInstrumentCandidate(); } - if (m_nInstrument<0 && m_pVstPlugin->CanRecieveMidiEvents()) { //only send warning if plug is able to process notes. - AfxMessageBox("You need to assign an instrument to this plugin before you can play notes from here."); - } else { + if(QueryAddInstrumentIfNeeded()) + { CModDoc* pModDoc = m_pVstPlugin->GetModDoc(); CMainFrame* pMainFrm = CMainFrame::GetMainFrame(); pModDoc->PlayNote(wParam-kcVSTGUIStartNotes+1+pMainFrm->GetBaseOctave()*12, m_nInstrument, 0, FALSE); @@ -337,12 +336,13 @@ } if (wParam>=kcVSTGUIStartNoteStops && wParam<=kcVSTGUIEndNoteStops) { - if (!CheckInstrument(m_nInstrument)) { + if (!CheckInstrument(m_nInstrument)) + { m_nInstrument = GetBestInstrumentCandidate(); } - if (m_nInstrument<0 && m_pVstPlugin->CanRecieveMidiEvents()) { //only send warning if plug is able to process notes. - AfxMessageBox("You need to assign an instrument to this plugin before you can play notes from here."); - } else { + + if(QueryAddInstrumentIfNeeded()) + { CModDoc* pModDoc = m_pVstPlugin->GetModDoc(); CMainFrame* pMainFrm = CMainFrame::GetMainFrame(); pModDoc->NoteOff(wParam-kcVSTGUIStartNoteStops+1+pMainFrm->GetBaseOctave()*12, FALSE, m_nInstrument); @@ -353,6 +353,50 @@ return NULL; } + +// Weird name! :-P +// When trying to play a note using this plugin, but no instrument is assigned to it, +// the user is asked whether a new instrument should be added. +bool CAbstractVstEditor::QueryAddInstrumentIfNeeded() +//--------------------------------------------------- +{ + //only send warning if plug is able to process notes. + if(m_nInstrument < 0 && m_pVstPlugin->CanRecieveMidiEvents()) + { + CModDoc *pModDoc = m_pVstPlugin->GetModDoc(); + if(!pModDoc || !pModDoc->GetSoundFile()) + return false; + + if(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; + } else + { + // try to set up a new instrument + INSTRUMENTINDEX nIns = pModDoc->InsertInstrument(0); + if(nIns == INSTRUMENTINDEX_INVALID) + return false; + + MODINSTRUMENT *pIns = pModDoc->GetSoundFile()->Instruments[nIns]; + m_nInstrument = nIns; + + _snprintf(pIns->name, ARRAYELEMCOUNT(pIns->name) - 1, _T("%d: %s"), m_pVstPlugin->GetSlot() + 1, pModDoc->GetSoundFile()->m_MixPlugins[m_pVstPlugin->GetSlot()].Info.szName); + _snprintf(pIns->filename, ARRAYELEMCOUNT(pIns->filename) - 1, _T("FX %d"), m_pVstPlugin->GetSlot() + 1); + pIns->nMixPlug = m_pVstPlugin->GetSlot() + 1; + pIns->nMidiChannel = 1; + pIns->wMidiBank = (m_pVstPlugin->GetCurrentProgram() >> 7) + 1; + pIns->nMidiProgram = (m_pVstPlugin->GetCurrentProgram() & 0x7F) + 1; + + return true; + } + } else + { + return true; + } + +} + #define PRESETS_PER_COLUMN 32 #define PRESETS_PER_GROUP 128 Modified: trunk/OpenMPT/mptrack/AbstractVstEditor.h =================================================================== --- trunk/OpenMPT/mptrack/AbstractVstEditor.h 2010-05-06 22:39:17 UTC (rev 585) +++ trunk/OpenMPT/mptrack/AbstractVstEditor.h 2010-05-07 18:23:18 UTC (rev 586) @@ -64,6 +64,7 @@ void UpdateOptionsMenu(); int GetBestInstrumentCandidate(); bool CheckInstrument(int instrument); + bool QueryAddInstrumentIfNeeded(); int m_nInstrument; int m_nLearnMacro; @@ -71,6 +72,7 @@ void OnSetInputInstrument(UINT nID); afx_msg void OnInitMenu(CMenu* pMenu); void PrepareToLearnMacro(UINT nID); + }; //end rewbs.defaultPlugGUI Modified: trunk/OpenMPT/mptrack/Ctrl_smp.cpp =================================================================== --- trunk/OpenMPT/mptrack/Ctrl_smp.cpp 2010-05-06 22:39:17 UTC (rev 585) +++ trunk/OpenMPT/mptrack/Ctrl_smp.cpp 2010-05-07 18:23:18 UTC (rev 586) @@ -2562,7 +2562,15 @@ // set loop points if theren't any if(wasDisabled && ((pSmp->uFlags & CHN_LOOP) != 0) && (pSmp->nLoopStart == pSmp->nLoopEnd) && (pSmp->nLoopStart == 0)) { - pSmp->nLoopEnd = pSmp->nLength; + SELECTIONPOINTS selection = GetSelectionPoints(); + if(selection.bSelected) + { + pSmp->nLoopStart = selection.nStart; + pSmp->nLoopEnd = selection.nEnd; + } else + { + pSmp->nLoopEnd = pSmp->nLength; + } m_pModDoc->UpdateAllViews(NULL, (m_nSample << HINT_SHIFT_SMP) | HINT_SAMPLEDATA | HINT_SAMPLEINFO, NULL); } m_pModDoc->AdjustEndOfSample(m_nSample); @@ -2635,7 +2643,15 @@ // set sustain loop points if theren't any if(wasDisabled && ((pSmp->uFlags & CHN_SUSTAINLOOP) != 0) && (pSmp->nSustainStart == pSmp->nSustainEnd) && (pSmp->nSustainStart == 0)) { - pSmp->nSustainEnd = pSmp->nLength; + SELECTIONPOINTS selection = GetSelectionPoints(); + if(selection.bSelected) + { + pSmp->nSustainStart = selection.nStart; + pSmp->nSustainEnd = selection.nEnd; + } else + { + pSmp->nSustainEnd = pSmp->nLength; + } m_pModDoc->UpdateAllViews(NULL, (m_nSample << HINT_SHIFT_SMP) | HINT_SAMPLEDATA | HINT_SAMPLEINFO, NULL); } m_pModDoc->SetModified(); Modified: trunk/OpenMPT/mptrack/Moddoc.h =================================================================== --- trunk/OpenMPT/mptrack/Moddoc.h 2010-05-06 22:39:17 UTC (rev 585) +++ trunk/OpenMPT/mptrack/Moddoc.h 2010-05-07 18:23:18 UTC (rev 586) @@ -226,7 +226,7 @@ PATTERNINDEX InsertPattern(ORDERINDEX nOrd = ORDERINDEX_INVALID, ROWINDEX nRows = 64); SAMPLEINDEX InsertSample(bool bLimit = false); - INSTRUMENTINDEX InsertInstrument(LONG lSample = 0, LONG lDuplicate = 0); + INSTRUMENTINDEX InsertInstrument(SAMPLEINDEX lSample = SAMPLEINDEX_INVALID, INSTRUMENTINDEX lDuplicate = INSTRUMENTINDEX_INVALID); void InitializeInstrument(MODINSTRUMENT *pIns, UINT nsample=0); bool RemoveOrder(SEQUENCEINDEX nSeq, ORDERINDEX nOrd); bool RemovePattern(PATTERNINDEX nPat); Modified: trunk/OpenMPT/mptrack/Modedit.cpp =================================================================== --- trunk/OpenMPT/mptrack/Modedit.cpp 2010-05-06 22:39:17 UTC (rev 585) +++ trunk/OpenMPT/mptrack/Modedit.cpp 2010-05-07 18:23:18 UTC (rev 586) @@ -732,15 +732,17 @@ } -INSTRUMENTINDEX CModDoc::InsertInstrument(LONG lSample, LONG lDuplicate) -//---------------------------------------------------------------------- +// Insert a new instrument assigned to sample nSample or duplicate instrument nDuplicate. +// If nSample is invalid, an approriate sample slot is selected. 0 means "no sample". +INSTRUMENTINDEX CModDoc::InsertInstrument(SAMPLEINDEX nSample, INSTRUMENTINDEX nDuplicate) +//---------------------------------------------------------------------------------------- { - MODINSTRUMENT *pDup = NULL; - INSTRUMENTINDEX nInstrumentMax = m_SndFile.GetModSpecifications().instrumentsMax - 1; + MODINSTRUMENT *pDup = nullptr; + const INSTRUMENTINDEX nInstrumentMax = m_SndFile.GetModSpecifications().instrumentsMax - 1; if ((m_SndFile.m_nType != MOD_TYPE_XM) && !(m_SndFile.m_nType & (MOD_TYPE_IT | MOD_TYPE_MPT))) return INSTRUMENTINDEX_INVALID; - if ((lDuplicate > 0) && (lDuplicate <= (LONG)m_SndFile.m_nInstruments)) + if ((nDuplicate > 0) && (nDuplicate <= m_SndFile.m_nInstruments)) { - pDup = m_SndFile.Instruments[lDuplicate]; + pDup = m_SndFile.Instruments[nDuplicate]; } if ((!m_SndFile.m_nInstruments) && ((m_SndFile.m_nSamples > 1) || (m_SndFile.Samples[1].pSample))) { @@ -748,9 +750,9 @@ UINT n = CMainFrame::GetMainFrame()->MessageBox("Convert existing samples to instruments first?", NULL, MB_YESNOCANCEL|MB_ICONQUESTION); if (n == IDYES) { - UINT nInstruments = m_SndFile.m_nSamples; + SAMPLEINDEX nInstruments = m_SndFile.m_nSamples; if (nInstruments > nInstrumentMax) nInstruments = nInstrumentMax; - for (UINT smp=1; smp<=nInstruments; smp++) + for (SAMPLEINDEX smp = 1; smp <= nInstruments; smp++) { m_SndFile.Samples[smp].uFlags &= ~CHN_MUTE; if (!m_SndFile.Instruments[smp]) @@ -771,7 +773,7 @@ if (n != IDNO) return INSTRUMENTINDEX_INVALID; } UINT newins = 0; - for (UINT i=1; i<=m_SndFile.m_nInstruments; i++) + for (INSTRUMENTINDEX i = 1; i <= m_SndFile.m_nInstruments; i++) { if (!m_SndFile.Instruments[i]) { @@ -791,10 +793,10 @@ MODINSTRUMENT *pIns = new MODINSTRUMENT; if (pIns) { - UINT newsmp = 0; - if ((lSample > 0) && (lSample < m_SndFile.GetModSpecifications().samplesMax)) + SAMPLEINDEX newsmp = 0; + if (nSample < m_SndFile.GetModSpecifications().samplesMax) { - newsmp = lSample; + newsmp = nSample; } else if (!pDup) { @@ -818,7 +820,7 @@ *pIns = *pDup; // -> CODE#0023 // -> DESC="IT project files (.itp)" - strcpy(m_SndFile.m_szInstrumentPath[newins-1],m_SndFile.m_szInstrumentPath[lDuplicate-1]); + strcpy(m_SndFile.m_szInstrumentPath[newins - 1], m_SndFile.m_szInstrumentPath[nDuplicate - 1]); m_SndFile.instrumentModified[newins-1] = FALSE; // -! NEW_FEATURE#0023 } else This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |