From: <sag...@us...> - 2015-06-27 17:07:30
|
Revision: 5371 http://sourceforge.net/p/modplug/code/5371 Author: saga-games Date: 2015-06-27 17:07:24 +0000 (Sat, 27 Jun 2015) Log Message: ----------- [Imp] Directly assign instruments to newly added instrument plugins without asking. It's very unlikely that the user doesn't want the instrument to be created. Modified Paths: -------------- trunk/OpenMPT/mptrack/AbstractVstEditor.cpp trunk/OpenMPT/mptrack/AbstractVstEditor.h trunk/OpenMPT/mptrack/Ctrl_ins.cpp trunk/OpenMPT/mptrack/Moddoc.h trunk/OpenMPT/mptrack/Modedit.cpp trunk/OpenMPT/mptrack/SelectPluginDialog.cpp Modified: trunk/OpenMPT/mptrack/AbstractVstEditor.cpp =================================================================== --- trunk/OpenMPT/mptrack/AbstractVstEditor.cpp 2015-06-27 16:14:27 UTC (rev 5370) +++ trunk/OpenMPT/mptrack/AbstractVstEditor.cpp 2015-06-27 17:07:24 UTC (rev 5371) @@ -527,7 +527,7 @@ return false; } else { - CreateInstrument(); + OnCreateInstrument(); // Return true since we don't want to trigger the note for which the instrument has been validated yet. // Otherwise, the note might hang forever because the key-up event will go missing. return false; @@ -926,48 +926,11 @@ void CAbstractVstEditor::OnCreateInstrument() //------------------------------------------- { - CreateInstrument(); -} - - -// Try to set up a new instrument that is linked to the current plugin. -bool CAbstractVstEditor::CreateInstrument() -//----------------------------------------- -{ - CModDoc *pModDoc = m_VstPlugin.GetModDoc(); - CSoundFile &sndFile = m_VstPlugin.GetSoundFile(); - if(pModDoc == nullptr) + if(m_VstPlugin.GetModDoc() != nullptr) { - return false; + INSTRUMENTINDEX instr = m_VstPlugin.GetModDoc()->InsertInstrumentForPlugin(m_VstPlugin.GetSlot()); + if(instr != INSTRUMENTINDEX_INVALID) m_nInstrument = instr; } - - const bool first = (sndFile.GetNumInstruments() == 0); - INSTRUMENTINDEX nIns = pModDoc->InsertInstrument(0); - if(nIns == INSTRUMENTINDEX_INVALID) - { - return false; - } - - ModInstrument *pIns = sndFile.Instruments[nIns]; - m_nInstrument = nIns; - - _snprintf(pIns->name, CountOf(pIns->name) - 1, _T("%d: %s"), m_VstPlugin.GetSlot() + 1, sndFile.m_MixPlugins[m_VstPlugin.GetSlot()].GetName()); - mpt::String::Copy(pIns->filename, mpt::ToCharset(mpt::CharsetLocale, mpt::CharsetUTF8, sndFile.m_MixPlugins[m_VstPlugin.GetSlot()].GetLibraryName())); - pIns->nMixPlug = (PLUGINDEX)m_VstPlugin.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. - //pIns->wMidiBank = (WORD)((m_pVstPlugin->GetCurrentProgram() >> 7) + 1); - //pIns->nMidiProgram = (BYTE)((m_pVstPlugin->GetCurrentProgram() & 0x7F) + 1); - - InstrumentHint hint = InstrumentHint(nIns).Info().Envelope().Names(); - if(first) hint.ModType(); - pModDoc->UpdateAllViews(nullptr, hint); - if(sndFile.GetModSpecifications().supportsPlugins) - { - pModDoc->SetModified(); - } - - return true; } Modified: trunk/OpenMPT/mptrack/AbstractVstEditor.h =================================================================== --- trunk/OpenMPT/mptrack/AbstractVstEditor.h 2015-06-27 16:14:27 UTC (rev 5370) +++ trunk/OpenMPT/mptrack/AbstractVstEditor.h 2015-06-27 17:07:24 UTC (rev 5371) @@ -47,7 +47,6 @@ void SetPreset(int32 preset); void UpdatePresetField(); - bool CreateInstrument(); afx_msg void OnSysCommand(UINT nID, LPARAM lParam); afx_msg void OnLoadPreset(); Modified: trunk/OpenMPT/mptrack/Ctrl_ins.cpp =================================================================== --- trunk/OpenMPT/mptrack/Ctrl_ins.cpp 2015-06-27 16:14:27 UTC (rev 5370) +++ trunk/OpenMPT/mptrack/Ctrl_ins.cpp 2015-06-27 17:07:24 UTC (rev 5371) @@ -1218,8 +1218,6 @@ m_CheckResonance.EnableWindow(bITandMPT); m_SliderCutOff.EnableWindow(bITandMPT); m_SliderResonance.EnableWindow(bITandMPT); - m_SpinInstrument.SetRange(1, m_sndFile.m_nInstruments); - m_SpinInstrument.EnableWindow((m_sndFile.m_nInstruments) ? TRUE : FALSE); m_ComboTuning.EnableWindow(bMPTOnly); m_EditPitchTempoLock.EnableWindow(bMPTOnly); m_CheckPitchTempoLock.EnableWindow(bMPTOnly); @@ -1239,8 +1237,11 @@ m_CbnMidiCh.SetItemData(m_CbnMidiCh.AddString(s), ich); } } - if (hintType[HINT_MODTYPE | HINT_INSTRUMENT | HINT_MODTYPE]) + if (hintType[HINT_MODTYPE | HINT_INSTRUMENT]) { + m_SpinInstrument.SetRange(1, m_sndFile.m_nInstruments); + m_SpinInstrument.EnableWindow((m_sndFile.m_nInstruments) ? TRUE : FALSE); + // Backwards compatibility with IT modules that use now deprecated hack features. m_SliderCutSwing.EnableWindow((pIns != nullptr && (m_sndFile.GetType() == MOD_TYPE_MPT || pIns->nCutSwing != 0)) ? TRUE : FALSE); m_SliderResSwing.EnableWindow((pIns != nullptr && (m_sndFile.GetType() == MOD_TYPE_MPT || pIns->nResSwing != 0)) ? TRUE : FALSE); Modified: trunk/OpenMPT/mptrack/Moddoc.h =================================================================== --- trunk/OpenMPT/mptrack/Moddoc.h 2015-06-27 16:14:27 UTC (rev 5370) +++ trunk/OpenMPT/mptrack/Moddoc.h 2015-06-27 17:07:24 UTC (rev 5371) @@ -201,6 +201,7 @@ PATTERNINDEX InsertPattern(ORDERINDEX nOrd = ORDERINDEX_INVALID, ROWINDEX nRows = 64); SAMPLEINDEX InsertSample(bool bLimit = false); INSTRUMENTINDEX InsertInstrument(SAMPLEINDEX lSample = SAMPLEINDEX_INVALID, INSTRUMENTINDEX lDuplicate = INSTRUMENTINDEX_INVALID); + INSTRUMENTINDEX InsertInstrumentForPlugin(PLUGINDEX plug); void InitializeInstrument(ModInstrument *pIns); bool RemoveOrder(SEQUENCEINDEX nSeq, ORDERINDEX nOrd); bool RemovePattern(PATTERNINDEX nPat); Modified: trunk/OpenMPT/mptrack/Modedit.cpp =================================================================== --- trunk/OpenMPT/mptrack/Modedit.cpp 2015-06-27 16:14:27 UTC (rev 5370) +++ trunk/OpenMPT/mptrack/Modedit.cpp 2015-06-27 17:07:24 UTC (rev 5371) @@ -249,7 +249,6 @@ for(CHANNELINDEX nChn = GetNumChannels(); nChn < MAX_BASECHANNELS; nChn++) { m_SndFile.InitChannel(nChn); - m_SndFile.m_PlayState.Chn[nChn].dwFlags.set(CHN_MUTE); } return GetNumChannels(); @@ -538,10 +537,7 @@ bool CModDoc::ConvertInstrumentsToSamples() //----------------------------------------- { - if (!m_SndFile.GetNumInstruments()) - { - return false; - } + if (!m_SndFile.GetNumInstruments()) return false; m_SndFile.Patterns.ForEachModCommand(ConvertInstrumentsToSamplesInPatterns(&m_SndFile)); return true; } @@ -550,15 +546,11 @@ bool CModDoc::ConvertSamplesToInstruments() //----------------------------------------- { - if(GetNumInstruments() > 0) - { - return false; - } + const INSTRUMENTINDEX instrumentMax = m_SndFile.GetModSpecifications().instrumentsMax; + if(GetNumInstruments() > 0 || instrumentMax == 0) return false; - const INSTRUMENTINDEX nInstrumentMax = m_SndFile.GetModSpecifications().instrumentsMax; - const SAMPLEINDEX nInstruments = MIN(m_SndFile.GetNumSamples(), nInstrumentMax); - - for(SAMPLEINDEX smp = 1; smp <= nInstruments; smp++) + m_SndFile.m_nInstruments = std::min(m_SndFile.GetNumSamples(), instrumentMax); + for(SAMPLEINDEX smp = 1; smp <= m_SndFile.m_nInstruments; smp++) { const bool muted = IsSampleMuted(smp); MuteSample(smp, false); @@ -575,8 +567,6 @@ MuteInstrument(smp, muted); } - m_SndFile.m_nInstruments = nInstruments; - return true; } @@ -809,6 +799,46 @@ } +// Try to set up a new instrument that is linked to a given plugin +INSTRUMENTINDEX CModDoc::InsertInstrumentForPlugin(PLUGINDEX plug) +//---------------------------------------------------------------- +{ +#ifndef NO_VST + const bool first = (GetNumInstruments() == 0); + if(first && !ConvertSamplesToInstruments()) return INSTRUMENTINDEX_INVALID; + + INSTRUMENTINDEX instr = m_SndFile.GetNextFreeInstrument(); + if(instr == INSTRUMENTINDEX_INVALID) return INSTRUMENTINDEX_INVALID; + + ModInstrument *ins = m_SndFile.AllocateInstrument(instr, 0); + if(ins == nullptr) return INSTRUMENTINDEX_INVALID; + InitializeInstrument(ins); + + _snprintf(ins->name, CountOf(ins->name) - 1, _T("%u: %s"), plug + 1, m_SndFile.m_MixPlugins[plug].GetName()); + mpt::String::Copy(ins->filename, mpt::ToCharset(mpt::CharsetLocale, mpt::CharsetUTF8, m_SndFile.m_MixPlugins[plug].GetLibraryName())); + ins->nMixPlug = plug + 1; + ins->nMidiChannel = 1; + // People will forget to change this anyway, so the following lines can lead to some bad surprises after re-opening the module. + //pIns->wMidiBank = (WORD)((m_pVstPlugin->GetCurrentProgram() >> 7) + 1); + //pIns->nMidiProgram = (BYTE)((m_pVstPlugin->GetCurrentProgram() & 0x7F) + 1); + + if(instr > m_SndFile.m_nInstruments) m_SndFile.m_nInstruments = instr; + + InstrumentHint hint = InstrumentHint(instr).Info().Envelope().Names(); + if(first) hint.ModType(); + UpdateAllViews(nullptr, hint); + if(m_SndFile.GetModSpecifications().supportsPlugins) + { + SetModified(); + } + + return instr; +#else + return INSTRUMENTINDEX_INVALID; +#endif +} + + bool CModDoc::RemoveOrder(SEQUENCEINDEX nSeq, ORDERINDEX nOrd) //------------------------------------------------------------ { Modified: trunk/OpenMPT/mptrack/SelectPluginDialog.cpp =================================================================== --- trunk/OpenMPT/mptrack/SelectPluginDialog.cpp 2015-06-27 16:14:27 UTC (rev 5370) +++ trunk/OpenMPT/mptrack/SelectPluginDialog.cpp 2015-06-27 17:07:24 UTC (rev 5371) @@ -173,6 +173,21 @@ { mpt::String::Copy(m_pPlugin->Info.szName, s); } + // Check if plugin slot is already assigned to any instrument, and if not, create one. + if(p->isInstrument()) + { + const CSoundFile &sndFile = m_pModDoc->GetrSoundFile(); + INSTRUMENTINDEX instr = 0; + for(INSTRUMENTINDEX i = 1; i < sndFile.GetNumInstruments(); i++) + { + if(sndFile.Instruments[i] != nullptr && sndFile.Instruments[i]->nMixPlug == m_nPlugSlot + 1) + { + instr = i; + break; + } + } + if(instr == 0) m_pModDoc->InsertInstrumentForPlugin(m_nPlugSlot); + } } else { MemsetZero(m_pPlugin->Info); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |