From 02941424387a064301372c12bda3e8c3ab3fee45 Mon Sep 17 00:00:00 2001 From: "Tim E. Real" Date: Sun, 19 Jun 2011 01:26:26 +0000 Subject: Major work, all synthesizers. Other fixes. Please see ChangeLog. --- muse2/synti/simpledrums2/simpledrums.cpp | 319 +++++++++++++++++++++++-------- 1 file changed, 243 insertions(+), 76 deletions(-) (limited to 'muse2/synti/simpledrums2/simpledrums.cpp') diff --git a/muse2/synti/simpledrums2/simpledrums.cpp b/muse2/synti/simpledrums2/simpledrums.cpp index f14a0627..80f61102 100644 --- a/muse2/synti/simpledrums2/simpledrums.cpp +++ b/muse2/synti/simpledrums2/simpledrums.cpp @@ -5,6 +5,7 @@ // // // Author: Mathias Lundgren , (C) 2004 +// Contributer: (C) Copyright 2011 Tim E. Real (terminator356 at users.sourceforge.net) // // Copyright: See COPYING file that comes with this distribution // @@ -14,6 +15,7 @@ #include "muse/midi.h" //#include "libsynti/mpevent.h" #include "muse/mpevent.h" +//#include "common_defs.h" #include "simpledrums.h" #include @@ -82,6 +84,9 @@ SimpleSynth::SimpleSynth(int sr) SS_samplerate = sr; SS_initPlugins(); + initBuffer = 0; + initLen = 0; + simplesynth_ptr = this; master_vol = 100.0 / SS_MASTER_VOLUME_QUOT; master_vol_ctrlval = 100; @@ -203,6 +208,9 @@ SimpleSynth::~SimpleSynth() { SS_TRACE_IN + if(gui) + delete gui; // p4.0.27 + // Cleanup channels and samples: SS_DBG("Cleaning up sample data"); for (int i=0; iwriteEvent(ev); - delete[] event_data; + ///delete[] event_data; break; } @@ -639,7 +672,7 @@ const MidiPatch* SimpleSynth::getPatchInfo(int index, const MidiPatch* patch) co \return 0 when done, otherwise return next desired controller index */ //--------------------------------------------------------- -int SimpleSynth::getControllerInfo(int index, const char** name, int* controller, int* min, int* max) +int SimpleSynth::getControllerInfo(int index, const char** name, int* controller, int* min, int* max, int* initval) const { SS_TRACE_IN if (index >= SS_NR_OF_CONTROLLERS) { @@ -652,13 +685,40 @@ int SimpleSynth::getControllerInfo(int index, const char** name, int* controller *min = controllers[index].min; *max = controllers[index].max; - if (SS_DEBUG_MIDI) { + *initval = 0; // p4.0.27 FIXME NOTE TODO + + if (SS_DEBUG_MIDI) { printf("setting controller info: index %d name %s controller %d min %d max %d\n", index, *name, *controller, *min, *max); } SS_TRACE_OUT return (index +1); } +//--------------------------------------------------------- +// processMessages +// Called from host always, even if output path is unconnected. +//--------------------------------------------------------- + +void SimpleSynth::processMessages() +{ + //Process messages from the gui + while (gui->fifoSize()) { + MidiPlayEvent ev = gui->readEvent(); + if (ev.type() == ME_SYSEX) { + sysex(ev.len(), ev.data()); + sendEvent(ev); + } + else if (ev.type() == ME_CONTROLLER) { + setController(ev.channel(), ev.dataA(), ev.dataB(), true); + sendEvent(ev); + } + else { + if (SS_DEBUG) + printf("SimpleSynth::process(): unknown event, type: %d\n", ev.type()); + } + } +} + //--------------------------------------------------------- // process /*! @@ -671,6 +731,7 @@ int SimpleSynth::getControllerInfo(int index, const char** name, int* controller //--------------------------------------------------------- void SimpleSynth::process(float** out, int offset, int len) { + /* //Process messages from the gui while (gui->fifoSize()) { MidiPlayEvent ev = gui->readEvent(); @@ -687,7 +748,8 @@ void SimpleSynth::process(float** out, int offset, int len) printf("SimpleSynth::process(): unknown event, type: %d\n", ev.type()); } } - + */ + if (synth_state == SS_RUNNING) { //Temporary mix-doubles @@ -842,6 +904,19 @@ bool SimpleSynth::init(const char* name) return true; } +//--------------------------------------------------------- +// getInitBuffer +//--------------------------------------------------------- +void SimpleSynth::setupInitBuffer(int len) +{ + if (len > initLen) { + if (initBuffer) + delete [] initBuffer; + initBuffer = new byte[len]; + initLen = len; + } +} + //--------------------------------------------------------- /*! \fn SimpleSynth::getInitData @@ -850,7 +925,8 @@ bool SimpleSynth::init(const char* name) \param data - data that is sent as a sysex to the synth on reload of project */ //--------------------------------------------------------- -void SimpleSynth::getInitData(int* n, const unsigned char** data) +//void SimpleSynth::getInitData(int* n, const unsigned char** data) const +void SimpleSynth::getInitData(int* n, const unsigned char** data) { SS_TRACE_IN // Calculate length of data @@ -877,7 +953,10 @@ void SimpleSynth::getInitData(int* n, const unsigned char** data) int labelnamelen = plugin->label().size() + 2; len+=(namelen + labelnamelen); - len+=3; //1 byte for nr of parameters, 1 byte for return gain, 1 byte for effect on/off + ///len+=3; //1 byte for nr of parameters, 1 byte for return gain, 1 byte for effect on/off + // p4.0.27 Tim. + len+=6; //4 bytes for nr of parameters, 1 byte for return gain, 1 byte for effect on/off + len+=sendEffects[i].nrofparameters; // 1 byte for each parameter value } else { @@ -885,17 +964,29 @@ void SimpleSynth::getInitData(int* n, const unsigned char** data) } } + len += 2; // For header. + // First, SS_SYSEX_INIT_DATA - byte* buffer = new byte[len]; - memset(buffer, 0, len); - buffer[0] = SS_SYSEX_INIT_DATA; - buffer[1] = SS_SYSEX_INIT_DATA_VERSION; + + ///byte* buffer = new byte[len]; + setupInitBuffer(len); + + memset(initBuffer, 0, len); + //initBuffer[0] = SS_SYSEX_INIT_DATA; + //initBuffer[1] = SS_SYSEX_INIT_DATA_VERSION; + initBuffer[0] = MUSE_SYNTH_SYSEX_MFG_ID; + initBuffer[1] = SIMPLEDRUMS_UNIQUE_ID; + initBuffer[2] = SS_SYSEX_INIT_DATA; + initBuffer[3] = SS_SYSEX_INIT_DATA_VERSION; if (SS_DEBUG_INIT) { printf("Length of init data: %d\n", len); - printf("buffer[0] - SS_SYSEX_INIT_DATA: %d\n", SS_SYSEX_INIT_DATA); - printf("buffer[1] - SS_SYSEX_INIT_DATA_VERSION: %d\n", SS_SYSEX_INIT_DATA_VERSION); + //printf("initBuffer[0] - SS_SYSEX_INIT_DATA: %d\n", SS_SYSEX_INIT_DATA); + //printf("initBuffer[1] - SS_SYSEX_INIT_DATA_VERSION: %d\n", SS_SYSEX_INIT_DATA_VERSION); + printf("initBuffer[2] - SS_SYSEX_INIT_DATA: %d\n", SS_SYSEX_INIT_DATA); + printf("initBuffer[3] - SS_SYSEX_INIT_DATA_VERSION: %d\n", SS_SYSEX_INIT_DATA_VERSION); } - int i = 2; + //int i = 2; + int i = 4; // All channels: // 0 - volume ctrlval (0-127) // 1 - pan (0-127) @@ -905,71 +996,75 @@ void SimpleSynth::getInitData(int* n, const unsigned char** data) // 8 - len of filename, n // 9 - 9+n - filename for (int ch=0; chfilename.c_str()) + 1; - buffer[i+8] = (byte) filenamelen; - memcpy((buffer+(i+9)), channels[ch].sample->filename.c_str(), filenamelen); + initBuffer[i+8] = (byte) filenamelen; + memcpy((initBuffer+(i+9)), channels[ch].sample->filename.c_str(), filenamelen); if (SS_DEBUG_INIT) { - printf("buffer[%d] - filenamelen: %d\n", i+8, filenamelen); - printf("buffer[%d] - buffer[%d] - filename: ", (i+9), (i+9) + filenamelen - 1); + printf("initBuffer[%d] - filenamelen: %d\n", i+8, filenamelen); + printf("initBuffer[%d] - initBuffer[%d] - filename: ", (i+9), (i+9) + filenamelen - 1); for (int j = i+9; j< i+9+filenamelen; j++) { - printf("%c",buffer[j]); + printf("%c",initBuffer[j]); } printf("\n"); } i+= (SS_NR_OF_CHANNEL_CONTROLLERS + 1 + filenamelen); } else { - buffer[i+8] = SS_NO_SAMPLE; + initBuffer[i+8] = SS_NO_SAMPLE; if (SS_DEBUG_INIT) { - printf("buffer[%d]: SS_NO_SAMPLE: - %d\n", i+8, SS_NO_SAMPLE); + printf("initBuffer[%d]: SS_NO_SAMPLE: - %d\n", i+8, SS_NO_SAMPLE); } i+= (SS_NR_OF_CHANNEL_CONTROLLERS + 1); } } if (SS_DEBUG_INIT) { - printf("buffer[%d]: Master vol: - %d\n", i, master_vol_ctrlval); + printf("initBuffer[%d]: Master vol: - %d\n", i, master_vol_ctrlval); } - buffer[i] = master_vol_ctrlval; - *(data) = buffer; *n = len; + initBuffer[i] = master_vol_ctrlval; + *(data) = initBuffer; *n = len; i++; //Send effects: - buffer[i] = SS_SYSEX_INIT_DATA_VERSION; //Just for check + + ///initBuffer[i] = SS_SYSEX_INIT_DATA_VERSION; //Just for check + // Jun 10 2011. Bumped version up from 1 (with its own ID). p4.0.27 Tim + initBuffer[i] = SS_SYSEX_EFFECT_INIT_DATA_VERSION; //Just for check + if (SS_DEBUG_INIT) { - printf("buffer[%d]: Control value, SS_SYSEX_INIT_DATA_VERSION\n", i); + printf("initBuffer[%d]: Control value, SS_SYSEX_EFFECT_INIT_DATA_VERSION = %d\n", i, SS_SYSEX_EFFECT_INIT_DATA_VERSION); } i++; for (int j=0; jlabel().size() + 1; - buffer[i] = labelnamelen; - memcpy((buffer+i+1), sendEffects[j].plugin->label().toLatin1().constData(), labelnamelen); + initBuffer[i] = labelnamelen; + memcpy((initBuffer+i+1), sendEffects[j].plugin->label().toLatin1().constData(), labelnamelen); if (SS_DEBUG_INIT) { - printf("buffer[%d] - labelnamelen: %d\n", i, labelnamelen); - printf("buffer[%d] - buffer[%d] - filename: ", (i+1), (i+1) + labelnamelen - 1); + printf("initBuffer[%d] - labelnamelen: %d\n", i, labelnamelen); + printf("initBuffer[%d] - initBuffer[%d] - filename: ", (i+1), (i+1) + labelnamelen - 1); for (int k = i+1; k < i+1+labelnamelen; k++) { - printf("%c",buffer[k]); + printf("%c",initBuffer[k]); } printf("\n"); } @@ -977,45 +1072,55 @@ void SimpleSynth::getInitData(int* n, const unsigned char** data) i+=(labelnamelen + 1); int namelen = sendEffects[j].plugin->lib().size() + 1; - buffer[i] = namelen; - memcpy((buffer+i+1), sendEffects[j].plugin->lib().toLatin1().constData(), namelen); + initBuffer[i] = namelen; + memcpy((initBuffer+i+1), sendEffects[j].plugin->lib().toLatin1().constData(), namelen); if (SS_DEBUG_INIT) { - printf("buffer[%d] - libnamelen : %d\n", i, namelen); - printf("buffer[%d] - buffer[%d] - filename: ", (i+1), (i+1) + namelen - 1); + printf("initBuffer[%d] - libnamelen : %d\n", i, namelen); + printf("initBuffer[%d] - initBuffer[%d] - filename: ", (i+1), (i+1) + namelen - 1); for (int k = i+1; k < i+1+namelen; k++) { - printf("%c",buffer[k]); + printf("%c",initBuffer[k]); } printf("\n"); } i+=(namelen + 1); - buffer[i]=sendEffects[j].nrofparameters; + ///initBuffer[i]=sendEffects[j].nrofparameters; + // Jun 10 2011. Changed to 32 bit. p4.0.27 Tim. + *((unsigned*)&initBuffer[i]) = sendEffects[j].nrofparameters; if (SS_DEBUG_INIT) { - printf("buffer[%d]: sendEffects[%d].nrofparameters=%d\n", i, j, buffer[i]); + printf("initBuffer[%d]: sendEffects[%d].nrofparameters=%d\n", i, j, *((unsigned*)&initBuffer[i])); + } + ///i++; + i+=4; + + initBuffer[i]=sendEffects[j].retgain_ctrlval; + if (SS_DEBUG_INIT) { + printf("initBuffer[%d]: sendEffects[%d].retgain_ctrlval=%d\n", i, j, initBuffer[i]); } i++; - buffer[i]=sendEffects[j].retgain_ctrlval; + // Jun 10 2011. This one was missing. p4.0.27 Tim. + initBuffer[i] = sendEffects[j].state; if (SS_DEBUG_INIT) { - printf("buffer[%d]: sendEffects[%d].retgain_ctrlval=%d\n", i, j, buffer[i]); + printf("initBuffer[%d]: sendEffects[%d].state=%d\n", i, j, initBuffer[i]); } i++; for (int k=0; kgetGuiControlValue(k); + initBuffer[i] = sendEffects[j].plugin->getGuiControlValue(k); if (SS_DEBUG_INIT) { - printf("buffer[%d]: sendEffects[%d].parameterval[%d]=%d\n", i, j, k, buffer[i]); + printf("initBuffer[%d]: sendEffects[%d].parameterval[%d]=%d\n", i, j, k, initBuffer[i]); } i++; } } // No plugin loaded: else { - buffer[i] = SS_NO_PLUGIN; + initBuffer[i] = SS_NO_PLUGIN; if (SS_DEBUG_INIT) { - printf("buffer[%d]: SS_NO_PLUGIN\n", i); + printf("initBuffer[%d]: SS_NO_PLUGIN\n", i); } i++; } @@ -1118,11 +1223,15 @@ void SimpleSynth::parseInitData(const unsigned char* data) ptr++; // Effects: - if (*(ptr) != SS_SYSEX_INIT_DATA_VERSION) { - fprintf(stderr, "Error loading init data - control byte not found. Skipping...\n"); + ///if (*(ptr) != SS_SYSEX_INIT_DATA_VERSION) { + int effver = *(ptr); + if (effver < 1 || effver > SS_SYSEX_EFFECT_INIT_DATA_VERSION) { + //if (SS_DEBUG_INIT) + fprintf(stderr, "Error loading init data - effect init version is from future or too old. Skipping...\n"); SS_TRACE_OUT return; } + ptr++; for (int i=0; iwriteEvent(ev); - for (int j=0; j= 2) + { + if (SS_DEBUG_INIT) + printf("buffer[%ld] - sendeffect[%d] state=%d\n", long(ptr-data), i, *(ptr)); + sendEffects[i].state = (SS_SendFXState) *(ptr); + MidiPlayEvent ev(0, 0, 0, ME_CONTROLLER, SS_PLUGIN_ONOFF_CONTROLLER(i), sendEffects[i].state); + gui->writeEvent(ev); + ptr++; + } + + ///for (int j=0; jwriteEvent(ev); SS_TRACE_OUT @@ -1504,8 +1637,13 @@ void SimpleSynth::guiSendError(const char* errorstring) { SS_TRACE_IN byte out[strlen(errorstring)+2]; + //byte out[strlen(errorstring)+4]; + //out[0] = MUSE_SYNTH_SYSEX_MFG_ID; + //out[1] = SIMPLEDRUMS_UNIQUE_ID; out[0] = SS_SYSEX_ERRORMSG; + //out[2] = SS_SYSEX_ERRORMSG; memcpy(out+1, errorstring, strlen(errorstring) +1); + //memcpy(out+3, errorstring, strlen(errorstring) +1); SS_TRACE_OUT } @@ -1590,15 +1728,24 @@ bool SimpleSynth::initSendEffect(int id, QString lib, QString name) //TODO: cleanup if failed } } + //Notify gui - int len = 3; + ///int len = 3; + int len = 2 + 4; // Char is not enough for many plugins. Was causing crash. Changed to 32 bits. p4.0.27 Tim. + //int len = 5; byte out[len]; out[0] = SS_SYSEX_LOAD_SENDEFFECT_OK; out[1] = id; + //out[0] = MUSE_SYNTH_SYSEX_MFG_ID; + //out[1] = SIMPLEDRUMS_UNIQUE_ID; + //out[2] = SS_SYSEX_LOAD_SENDEFFECT_OK; + //out[3] = id; int j=0; for (iPlugin i = plugins.begin(); i!=plugins.end(); i++, j++) { if ((*i)->lib() == plugin->lib() && (*i)->label() == plugin->label()) { - out[2] = j; + ///out[2] = j; + //out[4] = j; + *((unsigned*)(out + 2)) = j; MidiPlayEvent ev(0, 0, ME_SYSEX, out, len); gui->writeEvent(ev); } @@ -1638,9 +1785,15 @@ void SimpleSynth::cleanupPlugin(int id) sendEffects[id].plugin = 0; byte d[2]; + //byte d[4]; d[0] = SS_SYSEX_CLEAR_SENDEFFECT_OK; d[1] = id; + //d[0] = MUSE_SYNTH_SYSEX_MFG_ID; + //d[1] = SIMPLEDRUMS_UNIQUE_ID; + //d[2] = SS_SYSEX_CLEAR_SENDEFFECT_OK; + //d[3] = id; MidiPlayEvent ev(0, 0, ME_SYSEX, d, 2); + //MidiPlayEvent ev(0, 0, ME_SYSEX, d, 4); gui->writeEvent(ev); SS_TRACE_OUT } @@ -1694,11 +1847,19 @@ void SimpleSynth::guiUpdateFxParameter(int fxid, int param, float val) } byte d[4]; + //byte d[6]; d[0] = SS_SYSEX_SET_PLUGIN_PARAMETER_OK; d[1] = fxid; d[2] = param; d[3] = intval; + //d[0] = MUSE_SYNTH_SYSEX_MFG_ID; + //d[1] = SIMPLEDRUMS_UNIQUE_ID; + //d[2] = SS_SYSEX_SET_PLUGIN_PARAMETER_OK; + //d[3] = fxid; + //d[4] = param; + //d[5] = intval; MidiPlayEvent ev(0, 0, ME_SYSEX, d, 4); + //MidiPlayEvent ev(0, 0, ME_SYSEX, d, 6); gui->writeEvent(ev); SS_TRACE_OUT } @@ -1742,9 +1903,15 @@ void SimpleSynth::guiNotifySampleCleared(int ch) { SS_TRACE_IN byte d[2]; + //byte d[4]; d[0] = SS_SYSEX_CLEAR_SAMPLE_OK; d[1] = (byte) ch; + //d[0] = MUSE_SYNTH_SYSEX_MFG_ID; + //d[1] = SIMPLEDRUMS_UNIQUE_ID; + //d[2] = SS_SYSEX_CLEAR_SAMPLE_OK; + //d[3] = (byte) ch; MidiPlayEvent ev(0, 0, ME_SYSEX, d, 2); + //MidiPlayEvent ev(0, 0, ME_SYSEX, d, 4); gui->writeEvent(ev); SS_TRACE_OUT } -- cgit v1.2.3