From: <sag...@us...> - 2015-05-24 22:28:29
|
Revision: 5159 http://sourceforge.net/p/modplug/code/5159 Author: saga-games Date: 2015-05-24 22:28:22 +0000 (Sun, 24 May 2015) Log Message: ----------- [New] Experimental support for 14-bit MIDI controllers: When recording parameter automation through MIDI mapping, combinations of CC 0...31 and CC 32...63 now act as double-precision MIDI messages (I have no devices which send such CC combinations, hence it's untested) Modified Paths: -------------- trunk/OpenMPT/mptrack/MIDIMapping.cpp trunk/OpenMPT/mptrack/MIDIMapping.h trunk/OpenMPT/mptrack/Moddoc.cpp trunk/OpenMPT/mptrack/View_pat.cpp trunk/OpenMPT/mptrack/View_pat.h trunk/OpenMPT/mptrack/Vstplug.cpp trunk/OpenMPT/soundlib/Snd_fx.cpp Modified: trunk/OpenMPT/mptrack/MIDIMapping.cpp =================================================================== --- trunk/OpenMPT/mptrack/MIDIMapping.cpp 2015-05-24 22:25:01 UTC (rev 5158) +++ trunk/OpenMPT/mptrack/MIDIMapping.cpp 2015-05-24 22:28:22 UTC (rev 5159) @@ -108,14 +108,15 @@ } -bool CMIDIMapper::OnMIDImsg(const DWORD midimsg, PLUGINDEX &mappedIndex, PlugParamIndex ¶mindex, uint8 ¶mval) -//------------------------------------------------------------------------------------------------------------------- +bool CMIDIMapper::OnMIDImsg(const DWORD midimsg, PLUGINDEX &mappedIndex, PlugParamIndex ¶mindex, uint16 ¶mval) +//-------------------------------------------------------------------------------------------------------------------- { bool captured = false; const MIDIEvents::EventType eventType = MIDIEvents::GetTypeFromEvent(midimsg); const uint8 controller = MIDIEvents::GetDataByte1FromEvent(midimsg); - const uint8 channel = MIDIEvents::GetChannelFromEvent(midimsg); + const uint8 channel = MIDIEvents::GetChannelFromEvent(midimsg) & 0x7F; + const uint8 controllerVal = MIDIEvents::GetDataByte2FromEvent(midimsg) & 0x7F; for(const_iterator citer = Begin(); citer != End() && !captured; citer++) { @@ -126,8 +127,19 @@ const PLUGINDEX plugindex = citer->GetPlugIndex(); const uint32 param = citer->GetParamIndex(); - const uint8 val = (citer->GetEvent() == MIDIEvents::evChannelAftertouch ? controller : MIDIEvents::GetDataByte2FromEvent(midimsg)) & 0x7F; + uint16 val = (citer->GetEvent() == MIDIEvents::evChannelAftertouch ? controller : controllerVal) << 7; + if(eventType == MIDIEvents::evControllerChange) + { + // Coarse (0...31) / Fine (32...63) controller pairs - coarse should be sent first. + if(controller == lastCC + 32 && lastCC < 32) + { + val = (val >> 7) | lastCCvalue; + } + lastCC = controller; + lastCCvalue = val; + } + if(citer->GetAllowPatternEdit()) { mappedIndex = plugindex; Modified: trunk/OpenMPT/mptrack/MIDIMapping.h =================================================================== --- trunk/OpenMPT/mptrack/MIDIMapping.h 2015-05-24 22:25:01 UTC (rev 5158) +++ trunk/OpenMPT/mptrack/MIDIMapping.h 2015-05-24 22:28:22 UTC (rev 5159) @@ -83,7 +83,7 @@ { public: typedef std::vector<CMIDIMappingDirective>::const_iterator const_iterator; - CMIDIMapper(CSoundFile& sndfile) : m_rSndFile(sndfile) {} + CMIDIMapper(CSoundFile& sndfile) : m_rSndFile(sndfile), lastCC(uint8_max), lastCCvalue(0) {} //If mapping found: // -mappedIndex is set to mapped value(plug index) @@ -91,7 +91,7 @@ // -paramvalue to parameter value. //In case of multiple mappings, these get the values from the last mapping found. //Returns true if MIDI was 'captured' by some directive, false otherwise. - bool OnMIDImsg(const DWORD midimsg, PLUGINDEX &mappedIndex, PlugParamIndex ¶mindex, uint8 ¶mvalue); + bool OnMIDImsg(const DWORD midimsg, PLUGINDEX &mappedIndex, PlugParamIndex ¶mindex, uint16 ¶mvalue); //Swaps the positions of two elements. Returns true if swap was not done. bool Swap(const size_t a, const size_t b); @@ -122,6 +122,8 @@ private: CSoundFile& m_rSndFile; std::vector<CMIDIMappingDirective> m_Directives; + uint8 lastCC; + uint16 lastCCvalue; }; Modified: trunk/OpenMPT/mptrack/Moddoc.cpp =================================================================== --- trunk/OpenMPT/mptrack/Moddoc.cpp 2015-05-24 22:25:01 UTC (rev 5158) +++ trunk/OpenMPT/mptrack/Moddoc.cpp 2015-05-24 22:28:22 UTC (rev 5159) @@ -981,7 +981,7 @@ PLUGINDEX mappedIndex = 0; PlugParamIndex paramIndex = 0; - uint8 paramValue = 0; + uint16 paramValue = 0; bool captured = m_SndFile.GetMIDIMapper().OnMIDImsg(midiData, mappedIndex, paramIndex, paramValue); // Handle MIDI messages assigned to shortcuts Modified: trunk/OpenMPT/mptrack/View_pat.cpp =================================================================== --- trunk/OpenMPT/mptrack/View_pat.cpp 2015-05-24 22:25:01 UTC (rev 5158) +++ trunk/OpenMPT/mptrack/View_pat.cpp 2015-05-24 22:28:22 UTC (rev 5159) @@ -162,8 +162,6 @@ m_Dib.Init(CMainFrame::bmpNotes); UpdateColors(); m_PCNoteEditMemory = ModCommand::Empty(); - - octaveKeyMemory.resize(10, NOTE_NONE); } @@ -1449,7 +1447,7 @@ } else { if (BuildSoloMuteCtxMenu(hMenu, ih, nChn, pSndFile)) - AppendMenu(hMenu, MF_SEPARATOR, 0, ""); + AppendMenu(hMenu, MF_SEPARATOR, 0, _T("")); BuildRecordCtxMenu(hMenu, ih, nChn, pModDoc); BuildChannelControlCtxMenu(hMenu, ih); } @@ -1460,34 +1458,35 @@ { // When combining menus, use bitwise ORs to avoid shortcuts if(BuildSelectionCtxMenu(hMenu, ih)) - AppendMenu(hMenu, MF_SEPARATOR, 0, ""); + AppendMenu(hMenu, MF_SEPARATOR, 0, _T("")); if(BuildEditCtxMenu(hMenu, ih, pModDoc)) - AppendMenu(hMenu, MF_SEPARATOR, 0, ""); + AppendMenu(hMenu, MF_SEPARATOR, 0, _T("")); if(BuildInterpolationCtxMenu(hMenu, ih) | BuildTransposeCtxMenu(hMenu, ih)) - AppendMenu(hMenu, MF_SEPARATOR, 0, ""); + AppendMenu(hMenu, MF_SEPARATOR, 0, _T("")); if(BuildVisFXCtxMenu(hMenu, ih) | BuildAmplifyCtxMenu(hMenu, ih) | BuildSetInstCtxMenu(hMenu, ih)) - AppendMenu(hMenu, MF_SEPARATOR, 0, ""); + AppendMenu(hMenu, MF_SEPARATOR, 0, _T("")); if(BuildPCNoteCtxMenu(hMenu, ih)) - AppendMenu(hMenu, MF_SEPARATOR, 0, ""); + AppendMenu(hMenu, MF_SEPARATOR, 0, _T("")); if(BuildGrowShrinkCtxMenu(hMenu, ih)) - AppendMenu(hMenu, MF_SEPARATOR, 0, ""); + AppendMenu(hMenu, MF_SEPARATOR, 0, _T("")); if(BuildMiscCtxMenu(hMenu, ih)) - AppendMenu(hMenu, MF_SEPARATOR, 0, ""); + AppendMenu(hMenu, MF_SEPARATOR, 0, _T("")); if(BuildRowInsDelCtxMenu(hMenu, ih)) - AppendMenu(hMenu, MF_SEPARATOR, 0, ""); + AppendMenu(hMenu, MF_SEPARATOR, 0, _T("")); - CString s = "&Quantize "; + CString s = _T("&Quantize "); if(TrackerSettings::Instance().recordQuantizeRows != 0) { - s.AppendFormat("(Currently: %d Rows)", TrackerSettings::Instance().recordQuantizeRows.Get()); + uint32 rows = TrackerSettings::Instance().recordQuantizeRows.Get(); + s.AppendFormat(_T("(Currently: %d Row%s)"), rows, rows == 1 ? _T("") : _T("s")); } else { - s.Append("Settings..."); + s.Append(_T("Settings...")); } - s.Append("\t" + ih->GetKeyTextFromCommand(kcQuantizeSettings)); + s.Append(_T("\t") + ih->GetKeyTextFromCommand(kcQuantizeSettings)); AppendMenu(hMenu, MF_STRING | (TrackerSettings::Instance().recordQuantizeRows != 0 ? MF_CHECKED : 0), ID_SETQUANTIZE, s); } @@ -3994,7 +3993,7 @@ // Handle MIDI mapping. PLUGINDEX mappedIndex = uint8_max; PlugParamIndex paramIndex = 0; - uint8 paramValue = uint8_max; + uint16 paramValue = uint16_max; bool captured = sndFile.GetMIDIMapper().OnMIDImsg(dwMidiData, mappedIndex, paramIndex, paramValue); @@ -4008,14 +4007,14 @@ } // Write parameter control commands if needed. - if(paramValue != uint8_max && IsEditingEnabled() && sndFile.GetType() == MOD_TYPE_MPT) + if(paramValue != uint16_max && IsEditingEnabled() && sndFile.GetType() == MOD_TYPE_MPT) { const bool liveRecord = IsLiveRecord(); ModCommandPos editpos = GetEditPos(sndFile, liveRecord); ModCommand &m = GetModCommand(sndFile, editpos); pModDoc->GetPatternUndo().PrepareUndo(editpos.pattern, editpos.channel, editpos.row, 1, 1, "MIDI Mapping Record"); - m.Set(NOTE_PCS, mappedIndex, static_cast<uint16>(paramIndex), static_cast<uint16>((paramValue * ModCommand::maxColumnValue) / 127)); + m.Set(NOTE_PCS, mappedIndex, static_cast<uint16>(paramIndex), static_cast<uint16>((paramValue * ModCommand::maxColumnValue) / 16383)); if(!liveRecord) InvalidateRow(editpos.row); pMainFrm->ThreadSafeSetModified(pModDoc); @@ -5134,7 +5133,7 @@ // custom tunings always has octave 5, no matter how many octaves the tuning actually has. TempEnterNote(((target.note - NOTE_MIN) % groupSize) + (val - 5) * groupSize + NOTE_MIDDLEC); // Memorize note for key-up - ASSERT(size_t(val) < octaveKeyMemory.size()); + ASSERT(size_t(val) < CountOf(octaveKeyMemory)); octaveKeyMemory[val] = target.note; } } @@ -5144,7 +5143,7 @@ void CViewPattern::TempStopOctave(int val) //---------------------------------------- { - ASSERT(size_t(val) < octaveKeyMemory.size()); + ASSERT(size_t(val) < CountOf(octaveKeyMemory)); if(octaveKeyMemory[val] != NOTE_NONE) { TempStopNote(octaveKeyMemory[val]); @@ -6416,7 +6415,7 @@ bool CViewPattern::BuildChannelControlCtxMenu(HMENU hMenu, CInputHandler *ih) const //--------------------------------------------------------------------------------- { - AppendMenu(hMenu, MF_SEPARATOR, 0, ""); + AppendMenu(hMenu, MF_SEPARATOR, 0, _T("")); AppendMenu(hMenu, MF_STRING, ID_PATTERN_TRANSPOSECHANNEL, "&Transpose Channel\t" + ih->GetKeyTextFromCommand(kcChannelTranspose)); AppendMenu(hMenu, MF_STRING, ID_PATTERN_DUPLICATECHANNEL, "&Duplicate Channel\t" + ih->GetKeyTextFromCommand(kcChannelDuplicate)); Modified: trunk/OpenMPT/mptrack/View_pat.h =================================================================== --- trunk/OpenMPT/mptrack/View_pat.h 2015-05-24 22:25:01 UTC (rev 5158) +++ trunk/OpenMPT/mptrack/View_pat.h 2015-05-24 22:28:22 UTC (rev 5159) @@ -193,8 +193,6 @@ QuickChannelProperties quickChannelProperties; - std::vector<ModCommand::NOTE> octaveKeyMemory; - // Chord preview CHANNELINDEX chordPatternChannels[MPTChord::notesPerChord]; ModCommand::NOTE prevChordNote, prevChordBaseNote; @@ -202,6 +200,7 @@ WORD ChnVUMeters[MAX_BASECHANNELS]; WORD OldVUMeters[MAX_BASECHANNELS]; + ModCommand::NOTE octaveKeyMemory[10]; ModCommand::NOTE previousNote[MAX_BASECHANNELS]; BYTE activeNoteChannel[NOTE_MAX + NOTE_MIN]; BYTE splitActiveNoteChannel[NOTE_MAX + NOTE_MIN]; Modified: trunk/OpenMPT/mptrack/Vstplug.cpp =================================================================== --- trunk/OpenMPT/mptrack/Vstplug.cpp 2015-05-24 22:25:01 UTC (rev 5158) +++ trunk/OpenMPT/mptrack/Vstplug.cpp 2015-05-24 22:28:22 UTC (rev 5159) @@ -1987,14 +1987,14 @@ void CVstPlugin::SetZxxParameter(UINT nParam, UINT nValue) //-------------------------------------------------------- { - PlugParamValue fValue = (PlugParamValue)nValue / 127.0f; + PlugParamValue fValue = (PlugParamValue)nValue / 16383.0f; SetParameter(nParam, fValue); } UINT CVstPlugin::GetZxxParameter(UINT nParam) //------------------------------------------- { - return (UINT) (GetParameter(nParam) * 127.0f + 0.5f); + return (UINT) (GetParameter(nParam) * 16383.0f + 0.5f); } Modified: trunk/OpenMPT/soundlib/Snd_fx.cpp =================================================================== --- trunk/OpenMPT/soundlib/Snd_fx.cpp 2015-05-24 22:25:01 UTC (rev 5158) +++ trunk/OpenMPT/soundlib/Snd_fx.cpp 2015-05-24 22:28:22 UTC (rev 5159) @@ -4608,10 +4608,10 @@ { if(!isSmooth) { - pPlugin->SetZxxParameter(plugParam, param & 0x7F); + pPlugin->SetZxxParameter(plugParam, (param & 0x7F) << 7); } else { - pPlugin->SetZxxParameter(plugParam, (uint32)CalculateSmoothParamChange((float)pPlugin->GetZxxParameter(plugParam), (float)(param & 0x7F))); + pPlugin->SetZxxParameter(plugParam, (uint32)CalculateSmoothParamChange((float)pPlugin->GetZxxParameter(plugParam), (float)((param & 0x7F) << 7))); } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |