@@ -576,7 +576,7 @@ public: | |||
* \param sendCallback Send message change to registered callback | |||
* \param block Block the audio callback | |||
*/ | |||
virtual void setProgram(int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback); | |||
virtual void setProgram(const int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback); | |||
/*! | |||
* Change the current MIDI plugin program to \a index. | |||
@@ -590,7 +590,7 @@ public: | |||
* \param sendCallback Send message change to registered callback | |||
* \param block Block the audio callback | |||
*/ | |||
virtual void setMidiProgram(int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback); | |||
virtual void setMidiProgram(const int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback); | |||
/*! | |||
* This is an overloaded call to setMidiProgram().\n | |||
@@ -1267,37 +1267,31 @@ void CarlaPlugin::setChunkData(const char* const stringData) | |||
(void)stringData; | |||
} | |||
void CarlaPlugin::setProgram(int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback) | |||
void CarlaPlugin::setProgram(const int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback) | |||
{ | |||
CARLA_ASSERT(index >= -1 && index < static_cast<int32_t>(pData->prog.count)); | |||
CARLA_SAFE_ASSERT_RETURN(index >= -1 && index < static_cast<int32_t>(pData->prog.count),); | |||
#ifdef BUILD_BRIDGE | |||
if (! gIsLoadingProject) | |||
{ | |||
if (! gIsLoadingProject) { | |||
CARLA_ASSERT(! sendGui); // this should never happen | |||
} | |||
#endif | |||
if (index > static_cast<int32_t>(pData->prog.count)) | |||
return; | |||
const int32_t fixedIndex(carla_fixValue<int32_t>(-1, pData->prog.count, index)); | |||
pData->prog.current = fixedIndex; | |||
pData->prog.current = index; | |||
#ifndef BUILD_BRIDGE | |||
if (sendOsc) | |||
pData->engine->oscSend_control_set_current_program(pData->id, fixedIndex); | |||
pData->engine->oscSend_control_set_current_program(pData->id, index); | |||
#endif | |||
if (sendCallback) | |||
pData->engine->callback(ENGINE_CALLBACK_PROGRAM_CHANGED, pData->id, fixedIndex, 0, 0.0f, nullptr); | |||
pData->engine->callback(ENGINE_CALLBACK_PROGRAM_CHANGED, pData->id, index, 0, 0.0f, nullptr); | |||
// Change default parameter values | |||
if (fixedIndex >= 0) | |||
if (index >= 0) | |||
{ | |||
#ifndef BUILD_BRIDGE | |||
if (sendGui) | |||
uiProgramChange(fixedIndex); | |||
uiProgramChange(index); | |||
#endif | |||
if (getType() == PLUGIN_GIG || getType() == PLUGIN_SF2 || getType() == PLUGIN_SFZ) | |||
@@ -1330,36 +1324,30 @@ void CarlaPlugin::setProgram(int32_t index, const bool sendGui, const bool sendO | |||
#endif | |||
} | |||
void CarlaPlugin::setMidiProgram(int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback) | |||
void CarlaPlugin::setMidiProgram(const int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback) | |||
{ | |||
CARLA_ASSERT(index >= -1 && index < static_cast<int32_t>(pData->midiprog.count)); | |||
CARLA_SAFE_ASSERT_RETURN(index >= -1 && index < static_cast<int32_t>(pData->midiprog.count),); | |||
#ifdef BUILD_BRIDGE | |||
if (! gIsLoadingProject) | |||
{ | |||
if (! gIsLoadingProject) { | |||
CARLA_ASSERT(! sendGui); // this should never happen | |||
} | |||
#endif | |||
if (index > static_cast<int32_t>(pData->midiprog.count)) | |||
return; | |||
const int32_t fixedIndex(carla_fixValue<int32_t>(-1, pData->midiprog.count, index)); | |||
pData->midiprog.current = fixedIndex; | |||
pData->midiprog.current = index; | |||
#ifndef BUILD_BRIDGE | |||
if (sendOsc) | |||
pData->engine->oscSend_control_set_current_midi_program(pData->id, fixedIndex); | |||
pData->engine->oscSend_control_set_current_midi_program(pData->id, index); | |||
#endif | |||
if (sendCallback) | |||
pData->engine->callback(ENGINE_CALLBACK_MIDI_PROGRAM_CHANGED, pData->id, fixedIndex, 0, 0.0f, nullptr); | |||
pData->engine->callback(ENGINE_CALLBACK_MIDI_PROGRAM_CHANGED, pData->id, index, 0, 0.0f, nullptr); | |||
if (fixedIndex >= 0) | |||
if (index >= 0) | |||
{ | |||
#ifndef BUILD_BRIDGE | |||
if (sendGui) | |||
uiMidiProgramChange(fixedIndex); | |||
uiMidiProgramChange(index); | |||
#endif | |||
if (getType() == PLUGIN_GIG || getType() == PLUGIN_SF2 || getType() == PLUGIN_SFZ) | |||
@@ -445,57 +445,51 @@ public: | |||
if (std::strcmp(key, "midiPrograms") != 0) | |||
return carla_stderr2("FluidSynthPlugin::setCustomData(\"%s\", \"%s\", \"%s\", %s) - type is not string", type, key, value, bool2str(sendGui)); | |||
if (! fUses16Outs) | |||
return CarlaPlugin::setCustomData(type, key, value, sendGui); | |||
QStringList midiProgramList(QString(value).split(":", QString::SkipEmptyParts)); | |||
if (midiProgramList.count() == MAX_MIDI_CHANNELS) | |||
if (fUses16Outs) | |||
{ | |||
uint i = 0; | |||
foreach (const QString& midiProg, midiProgramList) | |||
{ | |||
CARLA_SAFE_ASSERT_BREAK(i < MAX_MIDI_CHANNELS); | |||
QStringList midiProgramList(QString(value).split(":", QString::SkipEmptyParts)); | |||
bool ok; | |||
uint index = midiProg.toUInt(&ok); | |||
if (ok && index < pData->midiprog.count) | |||
if (midiProgramList.count() == MAX_MIDI_CHANNELS) | |||
{ | |||
uint i = 0; | |||
foreach (const QString& midiProg, midiProgramList) | |||
{ | |||
const uint32_t bank = pData->midiprog.data[index].bank; | |||
const uint32_t program = pData->midiprog.data[index].program; | |||
CARLA_SAFE_ASSERT_BREAK(i < MAX_MIDI_CHANNELS); | |||
fluid_synth_program_select(fSynth, i, fSynthId, bank, program); | |||
fCurMidiProgs[i] = index; | |||
bool ok; | |||
uint index = midiProg.toUInt(&ok); | |||
if (pData->ctrlChannel == static_cast<int32_t>(i)) | |||
if (ok && index < pData->midiprog.count) | |||
{ | |||
pData->midiprog.current = index; | |||
pData->engine->callback(ENGINE_CALLBACK_MIDI_PROGRAM_CHANGED, pData->id, index, 0, 0.0f, nullptr); | |||
const uint32_t bank = pData->midiprog.data[index].bank; | |||
const uint32_t program = pData->midiprog.data[index].program; | |||
fluid_synth_program_select(fSynth, i, fSynthId, bank, program); | |||
fCurMidiProgs[i] = index; | |||
if (pData->ctrlChannel == static_cast<int32_t>(i)) | |||
{ | |||
pData->midiprog.current = index; | |||
pData->engine->callback(ENGINE_CALLBACK_MIDI_PROGRAM_CHANGED, pData->id, index, 0, 0.0f, nullptr); | |||
} | |||
} | |||
++i; | |||
} | |||
++i; | |||
CARLA_SAFE_ASSERT(i == MAX_MIDI_CHANNELS); | |||
} | |||
} | |||
CarlaPlugin::setCustomData(type, key, value, sendGui); | |||
} | |||
void setMidiProgram(int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback) override | |||
void setMidiProgram(const int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback) override | |||
{ | |||
CARLA_ASSERT(fSynth != nullptr); | |||
CARLA_ASSERT(index >= -1 && index < static_cast<int32_t>(pData->midiprog.count)); | |||
if (index < -1) | |||
index = -1; | |||
else if (index > static_cast<int32_t>(pData->midiprog.count)) | |||
return; | |||
if (pData->ctrlChannel < 0 || pData->ctrlChannel >= MAX_MIDI_CHANNELS) | |||
return; | |||
CARLA_SAFE_ASSERT_RETURN(fSynth != nullptr,); | |||
CARLA_SAFE_ASSERT_RETURN(index >= -1 && index < static_cast<int32_t>(pData->midiprog.count),); | |||
if (index >= 0) | |||
if (index >= 0 && pData->ctrlChannel >= 0 && pData->ctrlChannel < MAX_MIDI_CHANNELS) | |||
{ | |||
const uint32_t bank = pData->midiprog.data[index].bank; | |||
const uint32_t program = pData->midiprog.data[index].program; | |||
@@ -394,66 +394,60 @@ public: | |||
if (std::strcmp(key, "midiPrograms") != 0) | |||
return carla_stderr2("LinuxSamplerPlugin::setCustomData(\"%s\", \"%s\", \"%s\", %s) - type is not string", type, key, value, bool2str(sendGui)); | |||
if (! fUses16Outs) | |||
return CarlaPlugin::setCustomData(type, key, value, sendGui); | |||
QStringList midiProgramList(QString(value).split(":", QString::SkipEmptyParts)); | |||
if (midiProgramList.count() == MAX_MIDI_CHANNELS) | |||
if (fUses16Outs) | |||
{ | |||
uint i = 0; | |||
foreach (const QString& midiProg, midiProgramList) | |||
{ | |||
CARLA_SAFE_ASSERT_BREAK(i < MAX_MIDI_CHANNELS); | |||
bool ok; | |||
uint index = midiProg.toUInt(&ok); | |||
QStringList midiProgramList(QString(value).split(":", QString::SkipEmptyParts)); | |||
if (ok && index < pData->midiprog.count) | |||
if (midiProgramList.count() == MAX_MIDI_CHANNELS) | |||
{ | |||
uint i = 0; | |||
foreach (const QString& midiProg, midiProgramList) | |||
{ | |||
const uint32_t bank = pData->midiprog.data[index].bank; | |||
const uint32_t program = pData->midiprog.data[index].program; | |||
const uint32_t rIndex = bank*128 + program; | |||
CARLA_SAFE_ASSERT_BREAK(i < MAX_MIDI_CHANNELS); | |||
if (pData->engine->isOffline()) | |||
{ | |||
fEngineChannels[i]->PrepareLoadInstrument(pData->filename, rIndex); | |||
fEngineChannels[i]->LoadInstrument(); | |||
} | |||
else | |||
bool ok; | |||
uint index = midiProg.toUInt(&ok); | |||
if (ok && index < pData->midiprog.count) | |||
{ | |||
fInstrument->LoadInstrumentInBackground(fInstrumentIds[rIndex], fEngineChannels[i]); | |||
} | |||
const uint32_t bank = pData->midiprog.data[index].bank; | |||
const uint32_t program = pData->midiprog.data[index].program; | |||
const uint32_t rIndex = bank*128 + program; | |||
if (pData->engine->isOffline()) | |||
{ | |||
fEngineChannels[i]->PrepareLoadInstrument(pData->filename, rIndex); | |||
fEngineChannels[i]->LoadInstrument(); | |||
} | |||
else | |||
{ | |||
fInstrument->LoadInstrumentInBackground(fInstrumentIds[rIndex], fEngineChannels[i]); | |||
} | |||
fCurMidiProgs[i] = index; | |||
fCurMidiProgs[i] = index; | |||
if (pData->ctrlChannel == static_cast<int32_t>(i)) | |||
{ | |||
pData->midiprog.current = index; | |||
pData->engine->callback(ENGINE_CALLBACK_MIDI_PROGRAM_CHANGED, pData->id, index, 0, 0.0f, nullptr); | |||
if (pData->ctrlChannel == static_cast<int32_t>(i)) | |||
{ | |||
pData->midiprog.current = index; | |||
pData->engine->callback(ENGINE_CALLBACK_MIDI_PROGRAM_CHANGED, pData->id, index, 0, 0.0f, nullptr); | |||
} | |||
} | |||
++i; | |||
} | |||
++i; | |||
CARLA_SAFE_ASSERT(i == MAX_MIDI_CHANNELS); | |||
} | |||
} | |||
CarlaPlugin::setCustomData(type, key, value, sendGui); | |||
} | |||
void setMidiProgram(int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback) override | |||
void setMidiProgram(const int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback) override | |||
{ | |||
CARLA_ASSERT(index >= -1 && index < static_cast<int32_t>(pData->midiprog.count)); | |||
if (index < -1) | |||
index = -1; | |||
else if (index > static_cast<int32_t>(pData->midiprog.count)) | |||
return; | |||
if (pData->ctrlChannel < 0 || pData->ctrlChannel >= MAX_MIDI_CHANNELS) | |||
return; | |||
CARLA_SAFE_ASSERT_RETURN(index >= -1 && index < static_cast<int32_t>(pData->midiprog.count),); | |||
if (index >= 0) | |||
if (index >= 0 && pData->ctrlChannel >= 0 && pData->ctrlChannel < MAX_MIDI_CHANNELS) | |||
{ | |||
const uint32_t bank = pData->midiprog.data[index].bank; | |||
const uint32_t program = pData->midiprog.data[index].program; | |||