Skip to content

Commit

Permalink
Implement Pitch Bend, Modulation, and Sustain
Browse files Browse the repository at this point in the history
#9 and #10
Thanks @rsta2
  • Loading branch information
probonopd committed Mar 17, 2022
1 parent 87513f4 commit a08604d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/dexedadapter.h
Expand Up @@ -63,6 +63,13 @@ class CDexedAdapter : public Dexed
m_SpinLock.Release ();
}

void ControllersRefresh (void)
{
m_SpinLock.Acquire ();
Dexed::ControllersRefresh ();
m_SpinLock.Release ();
}

private:
CSpinLock m_SpinLock;
};
Expand Down
26 changes: 23 additions & 3 deletions src/mididevice.cpp
Expand Up @@ -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

Expand Down Expand Up @@ -131,23 +133,41 @@ 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;

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;

case MIDI_PROGRAM_CHANGE:
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;
Expand Down
3 changes: 3 additions & 0 deletions src/minidexed.cpp
Expand Up @@ -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 ()))
{
Expand Down

0 comments on commit a08604d

Please sign in to comment.