From a08604df8d9c916e0c34c452a4d4398cb981ad7a Mon Sep 17 00:00:00 2001 From: probonopd Date: Thu, 17 Mar 2022 19:08:25 +0100 Subject: [PATCH] Implement Pitch Bend, Modulation, and Sustain #9 and #10 Thanks @rsta2 --- src/dexedadapter.h | 7 +++++++ src/mididevice.cpp | 26 +++++++++++++++++++++++--- src/minidexed.cpp | 3 +++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/dexedadapter.h b/src/dexedadapter.h index 0322dd4..3e85c1b 100644 --- a/src/dexedadapter.h +++ b/src/dexedadapter.h @@ -63,6 +63,13 @@ public: m_SpinLock.Release (); } + void ControllersRefresh (void) + { + m_SpinLock.Acquire (); + Dexed::ControllersRefresh (); + m_SpinLock.Release (); + } + private: CSpinLock m_SpinLock; }; diff --git a/src/mididevice.cpp b/src/mididevice.cpp index 4f92e61..d5559dd 100644 --- a/src/mididevice.cpp +++ b/src/mididevice.cpp @@ -31,8 +31,10 @@ #define MIDI_AFTERTOUCH 0b1010 // TODO #define MIDI_CONTROL_CHANGE 0b1011 #define MIDI_CC_BANK_SELECT_MSB 0 // TODO + #define MIDI_CC_MODULATION 1 #define MIDI_CC_VOLUME 7 #define MIDI_CC_BANK_SELECT_LSB 32 + #define MIDI_CC_BANK_SUSTAIN 64 #define MIDI_PROGRAM_CHANGE 0b1100 #define MIDI_PITCH_BEND 0b1110 @@ -131,6 +133,11 @@ void CMIDIDevice::MIDIMessageHandler (const u8 *pMessage, size_t nLength, unsign switch (pMessage[1]) { + case MIDI_CC_MODULATION: + m_pSynthesizer->setModWheel (pMessage[2]); + m_pSynthesizer->ControllersRefresh (); + break; + case MIDI_CC_VOLUME: m_pSynthesizer->SetVolume (pMessage[2]); break; @@ -138,6 +145,10 @@ void CMIDIDevice::MIDIMessageHandler (const u8 *pMessage, size_t nLength, unsign case MIDI_CC_BANK_SELECT_LSB: m_pSynthesizer->BankSelectLSB (pMessage[2]); break; + + case MIDI_CC_BANK_SUSTAIN: + m_pSynthesizer->setSustain (pMessage[2] >= 64); + break; } break; @@ -145,9 +156,18 @@ void CMIDIDevice::MIDIMessageHandler (const u8 *pMessage, size_t nLength, unsign m_pSynthesizer->ProgramChange (pMessage[1]); break; - case MIDI_PITCH_BEND: - m_pSynthesizer->setPitchbend (pMessage[1]); - break; + case MIDI_PITCH_BEND: { + if (nLength < 3) + { + break; + } + + s16 nValue = pMessage[1]; + nValue |= (s16) pMessage[2] << 7; + nValue -= 0x2000; + + m_pSynthesizer->setPitchbend (nValue); + } break; default: break; diff --git a/src/minidexed.cpp b/src/minidexed.cpp index 4217c35..4e4d8cf 100644 --- a/src/minidexed.cpp +++ b/src/minidexed.cpp @@ -102,6 +102,9 @@ bool CMiniDexed::Initialize (void) ProgramChange (0); setTranspose (24); + setPBController (12, 1); + setMWController (99, 7, 0); + // setup and start the sound device if (!m_pSoundDevice->AllocateQueueFrames (m_pConfig->GetChunkSize ())) {