commit 82ce141edddcbea214d069a135d467eeea8d175a
parent bbb47b1d6d29820e7e4aa135a05d46c1734291a2
Author: dsp56300 <dsp56300@users.noreply.github.com>
Date: Mon, 19 Jul 2021 22:19:40 +0200
use midi event struct in sendMIDI instead of single bytes
Diffstat:
5 files changed, 29 insertions(+), 22 deletions(-)
diff --git a/source/synthLib/midiTypes.h b/source/synthLib/midiTypes.h
@@ -197,6 +197,6 @@ namespace synthLib
std::vector<uint8_t> sysex;
int offset;
- SMidiEvent() : a(0), b(0), c(0), offset(0) {}
+ SMidiEvent(const uint8_t _a = 0, const uint8_t _b = 0, const uint8_t _c = 0, const int _offset = 0) : a(_a), b(_b), c(_c), offset(_offset) {}
};
}
diff --git a/source/virusLib/device.cpp b/source/virusLib/device.cpp
@@ -60,8 +60,8 @@ namespace virusLib
{
if(_ev.sysex.empty())
{
-// LOG("MIDI: " << std::hex << (int)me.a << " " << (int)me.b << " " << (int)me.c);
- return m_syx.sendMIDI(_ev.a, _ev.b, _ev.c, true);
+// LOG("MIDI: " << std::hex << (int)_ev.a << " " << (int)_ev.b << " " << (int)_ev.c);
+ return m_syx.sendMIDI(_ev, true);
}
std::vector<synthLib::SMidiEvent> responses;
diff --git a/source/virusLib/microcontroller.cpp b/source/virusLib/microcontroller.cpp
@@ -155,10 +155,10 @@ bool Microcontroller::send(const Page _page, const uint8_t _part, const uint8_t
return true;
}
-bool Microcontroller::sendMIDI(uint8_t a, uint8_t b, uint8_t c, bool cancelIfFull/* = false*/)
+bool Microcontroller::sendMIDI(const SMidiEvent& _ev, bool cancelIfFull/* = false*/)
{
- const uint8_t channel = a & 0x0f;
- const uint8_t status = a & 0xf0;
+ const uint8_t channel = _ev.a & 0x0f;
+ const uint8_t status = _ev.a & 0xf0;
const auto singleMode = m_globalSettings[PLAY_MODE] == PlayModeSingle;
@@ -173,45 +173,40 @@ bool Microcontroller::sendMIDI(uint8_t a, uint8_t b, uint8_t c, bool cancelIfFul
if(singleMode)
{
- if(getSingle(m_currentBank, b, single))
+ if(getSingle(m_currentBank, _ev.b, single))
{
- m_currentSingle = b;
+ m_currentSingle = _ev.b;
return writeSingle(0, SINGLE, single);
}
}
else
{
- return partProgramChange(channel, b);
+ return partProgramChange(channel, _ev.b);
}
}
break;
case M_CONTROLCHANGE:
- switch(b)
+ switch(_ev.b)
{
case MC_BANKSELECTLSB:
if(singleMode)
- m_currentBank = c % m_singles.size();
+ m_currentBank = _ev.c % m_singles.size();
else
- partBankSelect(channel, c, false);
+ partBankSelect(channel, _ev.c, false);
return true;
default:
- applyToSingleEditBuffer(PAGE_A, singleMode ? SINGLE : channel, b, c);
+ applyToSingleEditBuffer(PAGE_A, singleMode ? SINGLE : channel, _ev.b, _ev.c);
break;
}
break;
case M_POLYPRESSURE:
- applyToSingleEditBuffer(PAGE_B, singleMode ? SINGLE : channel, b, c);
+ applyToSingleEditBuffer(PAGE_B, singleMode ? SINGLE : channel, _ev.b, _ev.c);
break;
default:
break;
}
- if(cancelIfFull && (needsToWaitForHostBits(1,1) || m_hdi08.dataRXFull()))
- return false;
- writeHostBitsWithWait(1,1);
- TWord buf[3] = {static_cast<TWord>(a)<<16, static_cast<TWord>(b)<<16, static_cast<TWord>(c)<<16};
- m_hdi08.writeRX(buf,3);
- return true;
+ return sendMIDItoDSP(_ev.a,_ev.b,_ev.c, cancelIfFull);
}
bool Microcontroller::sendSysex(const std::vector<uint8_t>& _data, bool _cancelIfFull, std::vector<SMidiEvent>& _responses)
@@ -782,6 +777,16 @@ bool Microcontroller::setState(const std::vector<unsigned char>& _state, const S
return true;
}
+bool Microcontroller::sendMIDItoDSP(uint8_t _a, uint8_t _b, uint8_t _c, bool cancelIfFull)
+{
+ if(cancelIfFull && (needsToWaitForHostBits(1,1) || m_hdi08.dataRXFull()))
+ return false;
+ writeHostBitsWithWait(1,1);
+ TWord buf[3] = {static_cast<TWord>(_a)<<16, static_cast<TWord>(_b)<<16, static_cast<TWord>(_c)<<16};
+ m_hdi08.writeRX(buf,3);
+ return true;
+}
+
void Microcontroller::applyToSingleEditBuffer(const Page _page, const uint8_t _part, const uint8_t _param, const uint8_t _value)
{
if(_part == SINGLE)
diff --git a/source/virusLib/microcontroller.h b/source/virusLib/microcontroller.h
@@ -182,7 +182,7 @@ public:
bool sendPreset(uint8_t program, const std::vector<dsp56k::TWord>& preset, bool isMulti = false);
void sendControlCommand(ControlCommand command, uint8_t value);
- bool sendMIDI(uint8_t a, uint8_t b, uint8_t c, bool cancelIfFull = false);
+ bool sendMIDI(const synthLib::SMidiEvent& _ev, bool cancelIfFull = false);
bool send(Page page, uint8_t part, uint8_t param, uint8_t value, bool cancelIfFull = false);
bool sendSysex(const std::vector<uint8_t>& _data, bool _cancelIfFull, std::vector<synthLib::SMidiEvent>& _responses);
@@ -200,6 +200,8 @@ public:
bool getState(std::vector<unsigned char>& _state, synthLib::StateType _type);
bool setState(const std::vector<unsigned char>& _state, synthLib::StateType _type);
+ bool sendMIDItoDSP(uint8_t _a, uint8_t _b, uint8_t _c, bool cancelIfFull);
+
private:
void writeHostBitsWithWait(char flag1,char flag2) const;
void waitUntilReady() const;
diff --git a/source/virusTestConsole/virusTestConsole.cpp b/source/virusTestConsole/virusTestConsole.cpp
@@ -155,7 +155,7 @@ void midiNoteOn(void *data,DSP *dsp)
{
auto* uc = static_cast<Microcontroller*>(data);
LOG("Sending Note On!");
- uc->sendMIDI(0x90,60,0x7f); // Note On
+ uc->sendMIDI(SMidiEvent(0x90,60,0x7f)); // Note On
}
void midiCallback(void *data,DSP *dsp)