commit 4d96cbd1fb577d79dcd23cc2641715972f38812a
parent a8d287644af5f00508ba8ec858b44b3151731872
Author: dsp56300 <dsp56300@users.noreply.github.com>
Date: Thu, 23 Sep 2021 18:36:02 +0200
do not send midi events to the plugin output that are meant for the editor
Diffstat:
8 files changed, 34 insertions(+), 19 deletions(-)
diff --git a/source/jucePlugin/PluginProcessor.cpp b/source/jucePlugin/PluginProcessor.cpp
@@ -199,20 +199,20 @@ void AudioPluginAudioProcessor::processBlock (juce::AudioBuffer<float>& buffer,
m_midiOut.clear();
m_plugin.getMidiOut(m_midiOut);
- if (m_midiOut.size() > 0)
+ if (!m_midiOut.empty())
m_controller->dispatchVirusOut(m_midiOut);
for (size_t i = 0; i < m_midiOut.size(); ++i)
{
const auto& e = m_midiOut[i];
- if(e.sysex.empty())
- {
+
+ if (e.source == synthLib::MidiEventSourceEditor)
+ continue;
+
+ if(e.sysex.empty())
midiMessages.addEvent(juce::MidiMessage (e.a, e.b, e.c, 0.0), 0);
- }
else
- {
midiMessages.addEvent(juce::MidiMessage (&e.sysex[0], static_cast<int>(e.sysex.size()), 0.0), 0);
- }
}
}
diff --git a/source/jucePlugin/VirusController.cpp b/source/jucePlugin/VirusController.cpp
@@ -1327,6 +1327,7 @@ namespace Virus
{
synthLib::SMidiEvent ev;
ev.sysex = msg;
+ ev.source = synthLib::MidiEventSourceEditor;
m_processor.addMidiEvent(ev);
}
diff --git a/source/synthLib/midiTypes.h b/source/synthLib/midiTypes.h
@@ -191,12 +191,22 @@ namespace synthLib
Note_C8, Note_Cis8, Note_D8, Note_Dis8, Note_E8, Note_F8, Note_Fis8, Note_G8
};
+ enum MidiEventSource
+ {
+ MidiEventSourcePlugin,
+ MidiEventSourceEditor,
+ };
+
struct SMidiEvent
{
uint8_t a, b, c;
std::vector<uint8_t> sysex;
uint32_t offset;
+ MidiEventSource source;
- SMidiEvent(const uint8_t _a = 0, const uint8_t _b = 0, const uint8_t _c = 0, const uint32_t _offset = 0) : a(_a), b(_b), c(_c), offset(_offset) {}
+ SMidiEvent(const uint8_t _a = 0, const uint8_t _b = 0, const uint8_t _c = 0, const uint32_t _offset = 0, const MidiEventSource _source = MidiEventSourcePlugin)
+ : a(_a), b(_b), c(_c), offset(_offset), source(_source)
+ {
+ }
};
}
diff --git a/source/synthLib/plugin.cpp b/source/synthLib/plugin.cpp
@@ -78,7 +78,7 @@ namespace synthLib
return m_device->isValid();
}
- bool Plugin::getState(std::vector<uint8_t>& _state, StateType _type)
+ bool Plugin::getState(std::vector<uint8_t>& _state, StateType _type) const
{
if(!m_device)
return false;
diff --git a/source/synthLib/plugin.h b/source/synthLib/plugin.h
@@ -30,7 +30,7 @@ namespace synthLib
bool isValid() const;
- bool getState(std::vector<uint8_t>& _state, StateType _type);
+ bool getState(std::vector<uint8_t>& _state, StateType _type) const;
bool setState(const std::vector<uint8_t>& _state);
private:
diff --git a/source/virusLib/device.cpp b/source/virusLib/device.cpp
@@ -75,7 +75,7 @@ namespace virusLib
std::vector<synthLib::SMidiEvent> responses;
- if(!m_syx.sendSysex(_ev.sysex, true, responses))
+ if(!m_syx.sendSysex(_ev.sysex, true, responses, _ev.source))
return false;
for (const auto& response : responses)
diff --git a/source/virusLib/microcontroller.cpp b/source/virusLib/microcontroller.cpp
@@ -227,7 +227,7 @@ bool Microcontroller::sendMIDI(const SMidiEvent& _ev, bool cancelIfFull/* = fals
return true;
}
-bool Microcontroller::sendSysex(const std::vector<uint8_t>& _data, bool _cancelIfFull, std::vector<SMidiEvent>& _responses)
+bool Microcontroller::sendSysex(const std::vector<uint8_t>& _data, bool _cancelIfFull, std::vector<SMidiEvent>& _responses, const MidiEventSource _source)
{
const auto manufacturerA = _data[1];
const auto manufacturerB = _data[2];
@@ -259,6 +259,8 @@ bool Microcontroller::sendSysex(const std::vector<uint8_t>& _data, bool _cancelI
auto buildPresetResponse = [&](const uint8_t _type, const uint8_t _bank, const uint8_t _program, const TPreset& _dump)
{
SMidiEvent ev;
+ ev.source = _source;
+
auto& response = ev.sysex;
buildResponseHeader(ev);
@@ -332,6 +334,7 @@ bool Microcontroller::sendSysex(const std::vector<uint8_t>& _data, bool _cancelI
auto buildGlobalResponse = [&](const uint8_t _param)
{
SMidiEvent ev;
+ ev.source = _source;
auto& response = ev.sysex;
buildResponseHeader(ev);
@@ -342,7 +345,7 @@ bool Microcontroller::sendSysex(const std::vector<uint8_t>& _data, bool _cancelI
response.push_back(m_globalSettings[_param]);
response.push_back(M_ENDOFSYSEX);
- _responses.push_back(ev);
+ _responses.emplace_back(std::move(ev));
};
auto buildGlobalResponses = [&]()
@@ -382,11 +385,11 @@ bool Microcontroller::sendSysex(const std::vector<uint8_t>& _data, bool _cancelI
TPreset _dump, _multi;
const auto res = requestSingle(0, _part, _dump);
const auto resm = requestMulti(0, 0, _multi);
- const uint8_t channel = _part == SINGLE ? m_globalSettings[GLOBAL_CHANNEL] : _multi[(size_t)MD_PART_MIDI_CHANNEL + _part];
+ const uint8_t channel = _part == SINGLE ? m_globalSettings[GLOBAL_CHANNEL] : _multi[static_cast<size_t>(MD_PART_MIDI_CHANNEL) + _part];
for (const auto cc : g_pageA)
{
SMidiEvent ev;
-
+ ev.source = _source;
ev.a = M_CONTROLCHANGE + channel;
ev.b = cc;
ev.c = _dump[cc];
@@ -395,9 +398,10 @@ bool Microcontroller::sendSysex(const std::vector<uint8_t>& _data, bool _cancelI
for (const auto cc : g_pageB)
{
SMidiEvent ev;
+ ev.source = _source;
ev.a = M_POLYPRESSURE + channel;
ev.b = cc;
- ev.c = _dump[(size_t)cc+128];
+ ev.c = _dump[static_cast<size_t>(cc)+128];
_responses.emplace_back(std::move(ev));
}
@@ -750,9 +754,9 @@ bool Microcontroller::getState(std::vector<unsigned char>& _state, const StateTy
std::vector<SMidiEvent> responses;
if(_type == StateTypeGlobal)
- sendSysex({M_STARTOFSYSEX, 0x00, 0x20, 0x33, 0x01, deviceId, REQUEST_TOTAL, M_ENDOFSYSEX}, false, responses);
+ sendSysex({M_STARTOFSYSEX, 0x00, 0x20, 0x33, 0x01, deviceId, REQUEST_TOTAL, M_ENDOFSYSEX}, false, responses, MidiEventSourcePlugin);
- sendSysex({M_STARTOFSYSEX, 0x00, 0x20, 0x33, 0x01, deviceId, REQUEST_ARRANGEMENT, M_ENDOFSYSEX}, false, responses);
+ sendSysex({M_STARTOFSYSEX, 0x00, 0x20, 0x33, 0x01, deviceId, REQUEST_ARRANGEMENT, M_ENDOFSYSEX}, false, responses, MidiEventSourcePlugin);
if(responses.empty())
return false;
@@ -797,7 +801,7 @@ bool Microcontroller::setState(const std::vector<unsigned char>& _state, const S
for (const auto& event : events)
{
- sendSysex(event.sysex, false, unusedResponses);
+ sendSysex(event.sysex, false, unusedResponses, MidiEventSourcePlugin);
unusedResponses.clear();
}
diff --git a/source/virusLib/microcontroller.h b/source/virusLib/microcontroller.h
@@ -178,7 +178,7 @@ public:
explicit Microcontroller(dsp56k::HDI08& hdi08, ROMFile& romFile);
bool sendMIDI(const synthLib::SMidiEvent& _ev, bool cancelIfFull = false);
- bool sendSysex(const std::vector<uint8_t>& _data, bool _cancelIfFull, std::vector<synthLib::SMidiEvent>& _responses);
+ bool sendSysex(const std::vector<uint8_t>& _data, bool _cancelIfFull, std::vector<synthLib::SMidiEvent>& _responses, synthLib::MidiEventSource _source);
bool writeSingle(uint8_t _bank, uint8_t _program, const TPreset& _data);
bool writeMulti(uint8_t _bank, uint8_t _program, const TPreset& _data);