From: <sv...@op...> - 2024-12-02 21:48:17
|
Author: sagamusix Date: Mon Dec 2 22:48:10 2024 New Revision: 22461 URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=22461 Log: [Mod/Reg] MIDI I/O Plugin: Remove the possibility to automate the MIDI input or output port. The resolution of automation parameters was nowhere nearly enough to be able to actually select devices in a meaningful way. It was only really useful for restoring plugin parameters from early module files using the plugin, which we can do by adding a dedicated code path for this situation. [Imp] MIDI I/O Plugin: Also use plugin parameters 0-99 for macro automation. Modified: trunk/OpenMPT/mptrack/mptrack.rc trunk/OpenMPT/mptrack/plugins/MidiInOut.cpp trunk/OpenMPT/mptrack/plugins/MidiInOut.h trunk/OpenMPT/mptrack/plugins/MidiInOutEditor.cpp Modified: trunk/OpenMPT/mptrack/mptrack.rc ============================================================================== --- trunk/OpenMPT/mptrack/mptrack.rc Mon Dec 2 21:58:48 2024 (r22460) +++ trunk/OpenMPT/mptrack/mptrack.rc Mon Dec 2 22:48:10 2024 (r22461) @@ -501,7 +501,7 @@ PUSHBUTTON "Send &Now",IDC_BUTTON2,102,156,66,14 PUSHBUTTON "&Import Dump...",IDC_BUTTON1,174,156,66,14 GROUPBOX "Parameter Macros",IDC_STATIC,6,180,240,30 - COMBOBOX IDC_COMBO3,12,192,72,12,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP + COMBOBOX IDC_COMBO3,12,192,72,12,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP EDITTEXT IDC_EDIT3,90,192,150,12,ES_AUTOHSCROLL END Modified: trunk/OpenMPT/mptrack/plugins/MidiInOut.cpp ============================================================================== --- trunk/OpenMPT/mptrack/plugins/MidiInOut.cpp Mon Dec 2 21:58:48 2024 (r22460) +++ trunk/OpenMPT/mptrack/plugins/MidiInOut.cpp Mon Dec 2 22:48:10 2024 (r22461) @@ -74,10 +74,32 @@ } -void MidiInOut::RestoreAllParameters(int32 program) +void MidiInOut::RestoreAllParameters(int32 /*program*/) { - IMixPlugin::RestoreAllParameters(program); // First plugin version didn't use chunks. - SetChunk(mpt::as_span(m_pMixStruct->pluginData), false); + if(!m_pMixStruct) + return; + if(m_pMixStruct->pluginData.size() == sizeof(uint32) * 3) + { + // Very old plugin versions + FileReader memFile(mpt::as_span(m_pMixStruct->pluginData)); + uint32 type = memFile.ReadUint32LE(); + if(type != 0) + return; + m_inputDevice.index = ParameterToDeviceID(memFile.ReadFloatLE()); + m_outputDevice.index = ParameterToDeviceID(memFile.ReadFloatLE()); + } else + { + SetChunk(mpt::as_span(m_pMixStruct->pluginData), false); + } + OpenDevice(m_inputDevice.index, true); + OpenDevice(m_outputDevice.index, false); + // Update selection in editor + MidiInOutEditor *editor = dynamic_cast<MidiInOutEditor *>(GetEditor()); + if(editor != nullptr) + { + editor->SetCurrentDevice(true, m_inputDevice.index); + editor->SetCurrentDevice(false, m_outputDevice.index); + } } @@ -175,7 +197,7 @@ // Try to match a port name against stored name or friendly name (preferred) -static void FindPort(MidiDevice::ID &id, unsigned int numPorts, const std::string &name, const mpt::ustring &friendlyName, MidiDevice &midiDevice, bool isInput) +static MidiDevice::ID FindPort(MidiDevice::ID id, unsigned int numPorts, const std::string &name, const mpt::ustring &friendlyName, MidiDevice &midiDevice, bool isInput) { bool foundFriendly = false; for(unsigned int i = 0; i < numPorts; i++) @@ -192,7 +214,7 @@ foundFriendly = true; if(deviceNameMatches) { - return; + return id; } } #else @@ -206,6 +228,7 @@ { } } + return id; } @@ -275,11 +298,8 @@ // Try to match an input port name against stored name or friendly name (preferred) m_inputDevice.friendlyName = mpt::ToUnicode(mpt::Charset::UTF8, inFriendlyName); m_outputDevice.friendlyName = mpt::ToUnicode(mpt::Charset::UTF8, outFriendlyName); - FindPort(inID, m_midiIn.getPortCount(), inName, m_inputDevice.friendlyName, m_inputDevice, true); - FindPort(outID, m_midiOut.getPortCount(), outName, m_outputDevice.friendlyName, m_outputDevice, false); - - SetParameter(MidiInOut::kInputParameter, DeviceIDToParameter(inID)); - SetParameter(MidiInOut::kOutputParameter, DeviceIDToParameter(outID)); + m_inputDevice.index = FindPort(inID, m_midiIn.getPortCount(), inName, m_inputDevice.friendlyName, m_inputDevice, true); + m_outputDevice.index = FindPort(outID, m_midiOut.getPortCount(), outName, m_outputDevice.friendlyName, m_outputDevice, false); } @@ -315,17 +335,7 @@ void MidiInOut::SetParameter(PlugParamIndex index, PlugParamValue value, PlayState *playState, CHANNELINDEX chn) { - value = mpt::safe_clamp(value, 0.0f, 1.0f); - if(index < kNumVisibleParams) - { - MidiDevice::ID newDevice = ParameterToDeviceID(value); - OpenDevice(newDevice, (index == kInputParameter)); - - // Update selection in editor - MidiInOutEditor *editor = dynamic_cast<MidiInOutEditor *>(GetEditor()); - if(editor != nullptr) - editor->SetCurrentDevice((index == kInputParameter), newDevice); - } else if(index >= kMacroParamMin && (index - kMacroParamMin) < m_parameterMacros.size()) + if(index >= kMacroParamMin && (index - kMacroParamMin) < m_parameterMacros.size()) { // Enough memory should have already been allocated when the macro string was set m_parameterMacroScratchSpace.resize(m_parameterMacros[index - kMacroParamMin].first.size() + 1); @@ -342,14 +352,8 @@ float MidiInOut::GetParameter(PlugParamIndex index) { - if(index < kNumVisibleParams) - { - const MidiDevice &device = (index == kInputParameter) ? m_inputDevice : m_outputDevice; - return DeviceIDToParameter(device.index); - } else if(index >= kMacroParamMin && (index - kMacroParamMin) < m_parameterMacros.size()) - { + if(index >= kMacroParamMin && (index - kMacroParamMin) < m_parameterMacros.size()) return m_parameterMacros[index - kMacroParamMin].second; - } return 0.0f; } @@ -358,11 +362,7 @@ CString MidiInOut::GetParamName(PlugParamIndex param) { - if(param == kInputParameter) - return _T("MIDI In"); - else if(param == kOutputParameter) - return _T("MIDI Out"); - else if(param >= kMacroParamMin && (param - kMacroParamMin) < m_parameterMacros.size()) + if(param >= kMacroParamMin && (param - kMacroParamMin) < m_parameterMacros.size()) return mpt::ToCString(mpt::Charset::ASCII, m_parameterMacros[param - kMacroParamMin].first); return {}; } @@ -371,8 +371,9 @@ // Parameter value as text CString MidiInOut::GetParamDisplay(PlugParamIndex param) { - const MidiDevice &device = (param == kInputParameter) ? m_inputDevice : m_outputDevice; - return mpt::ToCString(mpt::Charset::UTF8, device.name); + if(param >= kMacroParamMin && (param - kMacroParamMin) < m_parameterMacros.size()) + return mpt::cfmt::dec(mpt::saturate_round<uint8>(m_parameterMacros[param - kMacroParamMin].second * 127.0f)); + return {}; } @@ -627,7 +628,7 @@ // Open a device for input or output. void MidiInOut::OpenDevice(MidiDevice newDevice, bool asInputDevice) { - FindPort(newDevice.index, asInputDevice ? m_midiIn.getPortCount() : m_midiOut.getPortCount(), newDevice.name, newDevice.friendlyName, newDevice, asInputDevice); + newDevice.index = FindPort(newDevice.index, asInputDevice ? m_midiIn.getPortCount() : m_midiOut.getPortCount(), newDevice.name, newDevice.friendlyName, newDevice, asInputDevice); OpenDevice(newDevice.index, asInputDevice, false); } Modified: trunk/OpenMPT/mptrack/plugins/MidiInOut.h ============================================================================== --- trunk/OpenMPT/mptrack/plugins/MidiInOut.h Mon Dec 2 21:58:48 2024 (r22460) +++ trunk/OpenMPT/mptrack/plugins/MidiInOut.h Mon Dec 2 22:48:10 2024 (r22461) @@ -51,16 +51,15 @@ protected: enum : unsigned int { - kInputParameter = 0, - kOutputParameter = 1, - kMacroParamMin = 100, + kMacroParamMin = 0, kMacroParamMax = 999, kNumPrograms = 1, kNumParams = kMacroParamMax + 1, - kNumVisibleParams = 2, + kNumVisibleParams = 0, kNoDevice = MidiDevice::NO_MIDI_DEVICE, + //kDeviceInternal, kMaxDevices = 65536, // Should be a power of 2 to avoid rounding errors. }; @@ -154,18 +153,12 @@ MidiInOut(VSTPluginLib &factory, CSoundFile &sndFile, SNDMIXPLUGIN &mixStruct); ~MidiInOut(); - // Translate a VST parameter to an RtMidi device ID + // Translate a VST parameter to an RtMidi device ID (for restoring old plugin version chunks) static MidiDevice::ID ParameterToDeviceID(float value) { return static_cast<MidiDevice::ID>(value * static_cast<float>(kMaxDevices)) - 1; } - // Translate a RtMidi device ID to a VST parameter - static float DeviceIDToParameter(MidiDevice::ID index) - { - return static_cast<float>(index + 1) / static_cast<float>(kMaxDevices); - } - ///////////////////////////////////////////////// // Destroy the plugin int32 GetUID() const final { return 'MMID'; } Modified: trunk/OpenMPT/mptrack/plugins/MidiInOutEditor.cpp ============================================================================== --- trunk/OpenMPT/mptrack/plugins/MidiInOutEditor.cpp Mon Dec 2 21:58:48 2024 (r22460) +++ trunk/OpenMPT/mptrack/plugins/MidiInOutEditor.cpp Mon Dec 2 22:48:10 2024 (r22461) @@ -161,24 +161,17 @@ } -static void IOChanged(MidiInOut &plugin, CComboBox &combo, PlugParamIndex param) -{ - // Update device ID and notify plugin. - MidiDevice::ID newDevice = static_cast<MidiDevice::ID>(combo.GetItemData(combo.GetCurSel())); - plugin.SetParameter(param, MidiInOut::DeviceIDToParameter(newDevice)); - plugin.AutomateParameter(param); -} - - void MidiInOutEditor::OnInputChanged() { - IOChanged(static_cast<MidiInOut &>(m_VstPlugin), m_inputCombo, MidiInOut::kInputParameter); + MidiDevice::ID newDevice = static_cast<MidiDevice::ID>(m_inputCombo.GetItemData(m_inputCombo.GetCurSel())); + static_cast<MidiInOut &>(m_VstPlugin).OpenDevice(newDevice, true); } void MidiInOutEditor::OnOutputChanged() { - IOChanged(static_cast<MidiInOut &>(m_VstPlugin), m_outputCombo, MidiInOut::kOutputParameter); + MidiDevice::ID newDevice = static_cast<MidiDevice::ID>(m_outputCombo.GetItemData(m_outputCombo.GetCurSel())); + static_cast<MidiInOut &>(m_VstPlugin).OpenDevice(newDevice, false); } |