diff --git a/src/mididevice.cpp b/src/mididevice.cpp index 1b39083..bc69fa2 100644 --- a/src/mididevice.cpp +++ b/src/mididevice.cpp @@ -34,18 +34,6 @@ LOGMODULE ("mididevice"); #define MIDI_NOTE_ON 0b1001 #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_PAN_POSITION 10 - #define MIDI_CC_BANK_SELECT_LSB 32 - #define MIDI_CC_BANK_SUSTAIN 64 - #define MIDI_CC_RESONANCE 71 - #define MIDI_CC_FREQUENCY_CUTOFF 74 - #define MIDI_CC_REVERB_LEVEL 91 - #define MIDI_CC_DETUNE_LEVEL 94 - #define MIDI_CC_ALL_SOUND_OFF 120 - #define MIDI_CC_ALL_NOTES_OFF 123 #define MIDI_PROGRAM_CHANGE 0b1100 #define MIDI_PITCH_BEND 0b1110 @@ -268,7 +256,7 @@ void CMIDIDevice::MIDIMessageHandler (const u8 *pMessage, size_t nLength, unsign m_pSynthesizer->SetReverbSend (maplong (pMessage[2], 0, 127, 0, 99), nTG); break; - case MIDI_CC_DETUNE_LEVEL: + case MIDI_CC_DETUNE_LEVEL+32: if (pMessage[2] == 0) { // "0 to 127, with 0 being no celeste (detune) effect applied at all." @@ -342,7 +330,7 @@ void CMIDIDevice::HandleSystemExclusive(const uint8_t* pMessage, const size_t nL if ( instanceID != nTG ) { printf("WARNING instanceID and nTG do not match!!!!!\n"); } LOGDBG("SYSEX handler return value: %d", sysex_return); - //printf("SYSEX handler return value: %d for TG %i", sysex_return, instanceID); + //printf("SYSEX handler return value: %d for TG %i\n", sysex_return, instanceID); switch (sysex_return) { @@ -501,10 +489,10 @@ void CMIDIDevice::HandleSystemExclusive(const uint8_t* pMessage, const size_t nL LOGDBG("Config request received\n"); SendSystemExclusiveConfig(); break; -// case 601: -// printf("Get Bank Name\n"); -// std::string Value = pUIMenu->m_pMiniDexed->GetSysExFileLoader ()->GetBankName (nValue); -// break; + case 601: + LOGDBG("Get Bank Name request received\n"); + SendBankName(instanceID); + break; /* End of BeZo patches */ case 100: // load sysex-data into voice memory @@ -593,12 +581,6 @@ void CMIDIDevice::SendSystemExclusiveConfig() } configdump[count++] = 0xF7; -// for ( size_t i=0 ; i< count; i++) -// { -// printf("%02X, ", configdump[i]); -// if ( (i+1) % 16 == 0 ) printf ("\n"); -// } - TDeviceMap::const_iterator Iterator; // send voice dump to all MIDI interfaces @@ -611,7 +593,7 @@ void CMIDIDevice::SendSystemExclusiveConfig() void CMIDIDevice::SendProgramChange(uint8_t pgm, uint8_t nTG) { - uint8_t PgmChange[2] = { 0xC0|(nTG & 0x0F), (pgm & 0x7f) }; + uint8_t PgmChange[2] = { (uint8_t)(0xC0|(nTG & 0x0F)), (uint8_t)(pgm & 0x7f) }; TDeviceMap::const_iterator Iterator; // send voice dump to all MIDI interfaces @@ -624,12 +606,12 @@ void CMIDIDevice::SendProgramChange(uint8_t pgm, uint8_t nTG) void CMIDIDevice::SendBankChange(uint8_t bank, uint8_t nTG) { - SendCtrlChange(0xB0,32, (bank&0x7f)); + SendCtrlChange14Bit(0, bank, nTG); } void CMIDIDevice::SendCtrlChange(uint8_t ctrl, uint8_t val, uint8_t nTG) { - uint8_t CtrlMsg[3] = { 0xB0|(nTG & 0x0F), ctrl&0x7f, val&0x7f }; + uint8_t CtrlMsg[3] = { (uint8_t)(0xB0|(nTG & 0x0F)), (uint8_t)(ctrl&0x7f), (uint8_t)(val&0x7f) }; TDeviceMap::const_iterator Iterator; @@ -640,3 +622,30 @@ void CMIDIDevice::SendCtrlChange(uint8_t ctrl, uint8_t val, uint8_t nTG) LOGDBG("Send Ctrl change %02X = %i to \"%s\"",ctrl&0x7f, val&0x7f,Iterator->first.c_str()); } } + +void CMIDIDevice::SendCtrlChange14Bit(uint8_t ctrl, int16_t val, uint8_t nTG) +{ + uint8_t lsb = (val & 0x7f); + uint8_t msb = (val >> 9)&0x7f; + SendCtrlChange(ctrl,msb,nTG); + SendCtrlChange(ctrl+32, lsb, nTG); +} + +void CMIDIDevice::SendBankName(uint8_t nTG) +{ + char *bankname = (char*)calloc(32,sizeof(char)); + snprintf(bankname,sizeof(bankname), "%s", m_pSynthesizer->GetSysExFileLoader()->GetBankName(m_pSynthesizer->GetTGParameter(CMiniDexed::TGParameterVoiceBank,nTG)).c_str()); + uint8_t banksysex[40] = { 0xF0, 0x43, (uint8_t)(0x50|nTG), 0,0,32 }; + memcpy(banksysex+6,bankname,32); + banksysex[38] = 00; + banksysex[39] = 0xF7; + TDeviceMap::const_iterator Iterator; + + // send voice dump to all MIDI interfaces + for(Iterator = s_DeviceMap.begin(); Iterator != s_DeviceMap.end(); ++Iterator) + { + Iterator->second->Send (banksysex, sizeof(banksysex)*sizeof(uint8_t)); + LOGDBG("Send Bank Name Sysex to \"%s\"",Iterator->first.c_str()); + } +} + diff --git a/src/mididevice.h b/src/mididevice.h index a72b88c..38002b7 100644 --- a/src/mididevice.h +++ b/src/mididevice.h @@ -29,6 +29,19 @@ #include #include +#define MIDI_CC_BANK_SELECT_MSB 0 // TODO +#define MIDI_CC_MODULATION 1 +#define MIDI_CC_VOLUME 7 +#define MIDI_CC_PAN_POSITION 10 +#define MIDI_CC_BANK_SELECT_LSB 32 +#define MIDI_CC_BANK_SUSTAIN 64 +#define MIDI_CC_RESONANCE 71 +#define MIDI_CC_FREQUENCY_CUTOFF 74 +#define MIDI_CC_REVERB_LEVEL 91 +#define MIDI_CC_DETUNE_LEVEL 94 +#define MIDI_CC_ALL_SOUND_OFF 120 +#define MIDI_CC_ALL_NOTES_OFF 123 + class CMiniDexed; class CMIDIDevice @@ -54,7 +67,9 @@ public: virtual void SendSystemExclusiveConfig(); virtual void SendProgramChange(uint8_t pgm, uint8_t nTG); virtual void SendBankChange(uint8_t bank, uint8_t nTG); + virtual void SendBankName( uint8_t nTG); virtual void SendCtrlChange(uint8_t ctrl, uint8_t val, uint8_t nTG); + virtual void SendCtrlChange14Bit(uint8_t ctrl, int16_t val, uint8_t nTG); protected: void MIDIMessageHandler (const u8 *pMessage, size_t nLength, unsigned nCable = 0); void AddDevice (const char *pDeviceName); diff --git a/src/minidexed.cpp b/src/minidexed.cpp index 02c30f5..357a51e 100644 --- a/src/minidexed.cpp +++ b/src/minidexed.cpp @@ -346,7 +346,7 @@ void CMiniDexed::BankSelectLSB (unsigned nBankLSB, unsigned nTG) assert (nTG < CConfig::ToneGenerators); m_nVoiceBankID[nTG] = nBankLSB; - m_SerialMIDI.SendBankChange(nBankLSB,nTG); + m_SerialMIDI.SendBankChange(m_nVoiceBankID[nTG],nTG); m_UI.ParameterChanged (); } @@ -363,7 +363,7 @@ void CMiniDexed::ProgramChange (unsigned nProgram, unsigned nTG) assert (m_pTG[nTG]); m_pTG[nTG]->loadVoiceParameters (Buffer); - m_SerialMIDI.SendProgramChange(nProgram,nTG); + m_SerialMIDI.SendProgramChange(m_nProgram[nTG],nTG); m_UI.ParameterChanged (); } @@ -377,7 +377,7 @@ void CMiniDexed::SetVolume (unsigned nVolume, unsigned nTG) assert (m_pTG[nTG]); m_pTG[nTG]->setGain (nVolume / 127.0f); - + m_SerialMIDI.SendCtrlChange(MIDI_CC_VOLUME, m_nVolume[nTG], nTG); m_UI.ParameterChanged (); } @@ -391,6 +391,7 @@ void CMiniDexed::SetPan (unsigned nPan, unsigned nTG) tg_mixer->pan(nTG,mapfloat(nPan,0,127,0.0f,1.0f)); reverb_send_mixer->pan(nTG,mapfloat(nPan,0,127,0.0f,1.0f)); + m_SerialMIDI.SendCtrlChange(MIDI_CC_PAN_POSITION, nPan, nTG); m_UI.ParameterChanged (); } @@ -403,6 +404,8 @@ void CMiniDexed::SetReverbSend (unsigned nReverbSend, unsigned nTG) reverb_send_mixer->gain(nTG,mapfloat(nReverbSend,0,99,0.0f,1.0f)); + m_SerialMIDI.SendCtrlChange(MIDI_CC_REVERB_LEVEL, m_nReverbSend[nTG], nTG); + m_UI.ParameterChanged (); } @@ -416,6 +419,8 @@ void CMiniDexed::SetMasterTune (int nMasterTune, unsigned nTG) assert (m_pTG[nTG]); m_pTG[nTG]->setMasterTune ((int8_t) nMasterTune); + m_SerialMIDI.SendCtrlChange14Bit(MIDI_CC_DETUNE_LEVEL, m_nMasterTune[nTG], nTG); + m_UI.ParameterChanged (); } @@ -429,6 +434,8 @@ void CMiniDexed::SetCutoff (int nCutoff, unsigned nTG) assert (m_pTG[nTG]); m_pTG[nTG]->setFilterCutoff (mapfloat (nCutoff, 0, 99, 0.0f, 1.0f)); + m_SerialMIDI.SendCtrlChange(MIDI_CC_FREQUENCY_CUTOFF, m_nCutoff[nTG], nTG); + m_UI.ParameterChanged (); } @@ -442,6 +449,8 @@ void CMiniDexed::SetResonance (int nResonance, unsigned nTG) assert (m_pTG[nTG]); m_pTG[nTG]->setFilterResonance (mapfloat (nResonance, 0, 99, 0.0f, 1.0f)); + m_SerialMIDI.SendCtrlChange(MIDI_CC_RESONANCE, m_nResonance[nTG], nTG); + m_UI.ParameterChanged (); }