// // C++ Implementation: simpledrums // // Description: // // // Author: Mathias Lundgren , (C) 2004 // Contributer: (C) Copyright 2011 Tim E. Real (terminator356 at users.sourceforge.net) // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; version 2 of // the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // // #include "muse/midictrl.h" #include "muse/midi.h" //#include "libsynti/mpevent.h" #include "muse/mpevent.h" //#include "common_defs.h" #include "simpledrums.h" #include "globals.h" #include #include const char* SimpleSynth::synth_state_descr[] = { "SS_INITIALIZING", "SS_LOADING_SAMPLE", "SS_CLEARING_SAMPLE", "SS_RUNNING" }; const char* SimpleSynth::channel_state_descr[] = { "SS_CHANNEL_INACTIVE", "SS_SAMPLE_PLAYING" }; #define SWITCH_SYNTH_STATE(state)\ synth_state = state; \ if (SS_DEBUG_STATE) \ fprintf (stderr, "SS STATE: %s\n", SimpleSynth::synth_state_descr[state]); #define SWITCH_CHAN_STATE(ch, s)\ channels[ch].state = s; \ if (SS_DEBUG_STATE) \ fprintf (stderr, "SS CHAN %d STATE: %s\n", ch, SimpleSynth::channel_state_descr[s]); #define SS_CHANNEL_VOLUME_QUOT 100.0 #define SS_MASTER_VOLUME_QUOT 100.0 int SS_samplerate; #define SS_LOG_MAX 0 #define SS_LOG_MIN -10 #define SS_LOG_OFFSET SS_LOG_MIN // // Map plugin parameter on domain [SS_PLUGIN_PARAM_MIN, SS_PLUGIN_PARAM_MAX] to domain [SS_LOG_MIN, SS_LOG_MAX] (log domain) // float SS_map_pluginparam2logdomain(int pluginparam_val) { float scale = (float) (SS_LOG_MAX - SS_LOG_MIN)/ (float) SS_PLUGIN_PARAM_MAX; float scaled = (float) pluginparam_val * scale; float mapped = scaled + SS_LOG_OFFSET; return mapped; } // // Map plugin parameter on domain to domain [SS_LOG_MIN, SS_LOG_MAX] to [SS_PLUGIN_PARAM_MIN, SS_PLUGIN_PARAM_MAX] (from log-> [0,127]) // (inverse func to the above) int SS_map_logdomain2pluginparam(float pluginparam_log) { float mapped = pluginparam_log - SS_LOG_OFFSET; float scale = (float) SS_PLUGIN_PARAM_MAX / (float) (SS_LOG_MAX - SS_LOG_MIN); int scaled = (int) round(mapped * scale); return scaled; } double rangeToPitch(int value) { // inrange 0 .. 127 // outrange 0.5 .. 2 double outValue; if (value == 64) outValue = 1.0; else if (value > 64) { outValue = double(value) / 64.0; } else { // value < 63 outValue = double(value) / 127.0 + 0.5; } //printf("rangeToPitch(%d) %f\n", value, outValue); return outValue; } /*int pitchToRange(double pitch) { // inrange 0.5 .. 2 // outrange 0 .. 127 int outValue; if (fabs(pitch -1.0) < 0.0001) outValue = 64; else if ( pitch < 1.0){ outValue = (pitch -0.5) * 127; } else if ( pitch > 1.0) { outValue = (pitch -1.0) * 127 + 32; } if (outValue < 0) outValue = 0; if (outValue > 127) outValue = 127; printf("pitchToRange(%f) %d\n", pitch, outValue); return outValue; }*/ //--------------------------------------------------------- // SimpleSynth //--------------------------------------------------------- SimpleSynth::SimpleSynth(int sr) : Mess(SS_AUDIO_CHANNELS) { SS_TRACE_IN SS_samplerate = sr; SS_initPlugins(); initBuffer = 0; initLen = 0; simplesynth_ptr = this; master_vol = 100.0 / SS_MASTER_VOLUME_QUOT; master_vol_ctrlval = 100; //initialize for (int i=0; idata; delete channels[i].sample; } } simplesynth_ptr = NULL; SS_DBG("Deleting pluginlist"); //Cleanup plugins: for (iPlugin i = plugins.begin(); i != plugins.end(); ++i) { delete (*i); } plugins.clear(); SS_DBG("Deleting sendfx buffers"); //Delete sendfx buffers: for (int i=0; i