diff options
Diffstat (limited to 'src/drumgizmo.cc')
-rw-r--r-- | src/drumgizmo.cc | 196 |
1 files changed, 68 insertions, 128 deletions
diff --git a/src/drumgizmo.cc b/src/drumgizmo.cc index 853e93d..aa6be23 100644 --- a/src/drumgizmo.cc +++ b/src/drumgizmo.cc @@ -38,26 +38,27 @@ #include <hugin.hpp> #include <config.h> +#include <memory> #include "drumkitparser.h" #include "audioinputenginemidi.h" -#include "configuration.h" #include "configparser.h" #include "nolocale.h" -DrumGizmo::DrumGizmo(AudioOutputEngine *o, AudioInputEngine *i) - : MessageReceiver(MSGRCV_ENGINE) - , loader() +DrumGizmo::DrumGizmo(Settings& settings, + AudioOutputEngine *o, AudioInputEngine *i) + : loader(settings) , oe(o) , ie(i) , framesize(0) , freewheel(false) , events{} + , settings(settings) { is_stopping = false; audioCache.init(10000); // start thread - + events.reserve(1000); } @@ -68,9 +69,12 @@ DrumGizmo::~DrumGizmo() bool DrumGizmo::loadkit(std::string file) { + settings.drumkit_load_status.store(LoadStatus::Idle); + if(file == "") { - return 1; + settings.drumkit_load_status.store(LoadStatus::Error); + return false; } DEBUG(drumgizmo, "loadkit(%s)\n", file.c_str()); @@ -81,27 +85,31 @@ bool DrumGizmo::loadkit(std::string file) // Delete all Channels, Instruments, Samples and AudioFiles. kit.clear(); - DrumKitParser parser(kit); + settings.drumkit_load_status.store(LoadStatus::Loading); + + DrumKitParser parser(settings, kit); if(parser.parseFile(file)) { ERR(drumgizmo, "Drumkit parser failed: %s\n", file.c_str()); + settings.drumkit_load_status.store(LoadStatus::Error); return false; } - // Check if there is enough free RAM to load the drumkit. - if(!memchecker.enoughFreeMemory(kit)) - { - printf("WARNING: " - "There doesn't seem to be enough RAM available to load the kit.\n" - "Trying to load it anyway...\n"); - } + // TODO: Re-introduce when the code has been moved to the loader thread. + //// Check if there is enough free RAM to load the drumkit. + //if(!memchecker.enoughFreeMemory(kit)) + //{ + // printf("WARNING: " + // "There doesn't seem to be enough RAM available to load the kit.\n" + // "Trying to load it anyway...\n"); + //} loader.loadKit(&kit); #ifdef WITH_RESAMPLER for(int i = 0; i < MAX_NUM_CHANNELS; ++i) { - resampler[i].setup(kit.getSamplerate(), Conf::samplerate); + resampler[i].setup(kit.getSamplerate(), settings.samplerate.load()); } #endif/*WITH_RESAMPLER*/ @@ -125,79 +133,6 @@ bool DrumGizmo::init() return true; } -void DrumGizmo::handleMessage(Message *msg) -{ - DEBUG(msg, "got message."); - switch(msg->type()) { - case Message::LoadDrumKit: - { - DEBUG(msg, "got LoadDrumKitMessage message."); - LoadDrumKitMessage *m = (LoadDrumKitMessage*)msg; - loadkit(m->drumkitfile); - //init(true); - } - break; - case Message::LoadMidimap: - DEBUG(msg, "got LoadMidimapMessage message."); - if(!ie->isMidiEngine()) - { - break; - } - { - AudioInputEngineMidi *aim = (AudioInputEngineMidi*)ie; - LoadMidimapMessage *m = (LoadMidimapMessage*)msg; - bool ret = aim->loadMidiMap(m->midimapfile, kit.instruments); - - LoadStatusMessageMidimap *ls = new LoadStatusMessageMidimap(); - ls->success = ret; - msghandler.sendMessage(MSGRCV_UI, ls); - } - break; - case Message::EngineSettingsMessage: - { - bool mmap_loaded = false; - std::string mmapfile; - if(ie->isMidiEngine()) - { - AudioInputEngineMidi *aim = (AudioInputEngineMidi*)ie; - mmapfile = aim->getMidimapFile(); - mmap_loaded = aim->isValid(); - } - - EngineSettingsMessage *msg = new EngineSettingsMessage(); - msg->midimapfile = mmapfile; - msg->midimap_loaded = mmap_loaded; - msg->drumkitfile = kit.getFile(); - msg->drumkit_loaded = loader.isDone(); - msg->enable_velocity_modifier = Conf::enable_velocity_modifier; - msg->velocity_modifier_falloff = Conf::velocity_modifier_falloff; - msg->velocity_modifier_weight = Conf::velocity_modifier_weight; - msg->enable_velocity_randomiser = Conf::enable_velocity_randomiser; - msg->velocity_randomiser_weight = Conf::velocity_randomiser_weight; - msghandler.sendMessage(MSGRCV_UI, msg); - } - break; - case Message::ChangeSettingMessage: - { - ChangeSettingMessage *ch = (ChangeSettingMessage*)msg; - switch(ch->name) { - case ChangeSettingMessage::enable_velocity_modifier: - Conf::enable_velocity_modifier = ch->value; - break; - case ChangeSettingMessage::velocity_modifier_weight: - Conf::velocity_modifier_weight = ch->value; - break; - case ChangeSettingMessage::velocity_modifier_falloff: - Conf::velocity_modifier_falloff = ch->value; - break; - } - } - break; - default: - break; - } -} - void DrumGizmo::setFrameSize(size_t framesize) { // If we are resampling override the frame size. @@ -259,8 +194,31 @@ bool DrumGizmo::run(size_t pos, sample_t *samples, size_t nsamples) { setFrameSize(nsamples); - // Handle engine messages, at most one in each iteration: - handleMessages(1); + // TODO: Move this to DrumKitLoader thread. + if(getter.drumkit_file.hasChanged()) + { + loadkit(getter.drumkit_file.getValue()); + } + + // TODO: Move this to DrumKitLoader thread. + if(getter.midimap_file.hasChanged()) + { + auto ie_midi = dynamic_cast<AudioInputEngineMidi*>(ie); + if(ie_midi) + { + settings.midimap_load_status.store(LoadStatus::Loading); + bool ret = ie_midi->loadMidiMap(getter.midimap_file.getValue(), + kit.instruments); + if(ret) + { + settings.midimap_load_status.store(LoadStatus::Done); + } + else + { + settings.midimap_load_status.store(LoadStatus::Error); + } + } + } ie->pre(); oe->pre(nsamples); @@ -398,7 +356,7 @@ bool DrumGizmo::run(size_t pos, sample_t *samples, size_t nsamples) // Write audio // #ifdef WITH_RESAMPLER - if((Conf::enable_resampling == false) || + if((settings.enable_resampling.load() == false) || (resampler[0].getRatio() == 1.0)) // No resampling needed { #endif @@ -636,17 +594,17 @@ void DrumGizmo::stop() int DrumGizmo::samplerate() { - return Conf::samplerate; + return settings.samplerate.load(); } void DrumGizmo::setSamplerate(int samplerate) { DEBUG(dgeditor, "%s samplerate: %d\n", __PRETTY_FUNCTION__, samplerate); - Conf::samplerate = samplerate; + settings.samplerate.store(samplerate); #ifdef WITH_RESAMPLER for(int i = 0; i < MAX_NUM_CHANNELS; ++i) { - resampler[i].setup(kit.getSamplerate(), Conf::samplerate); + resampler[i].setup(kit.getSamplerate(), settings.samplerate.load()); } if(resampler[0].getRatio() != 1) { @@ -691,15 +649,15 @@ std::string DrumGizmo::configString() " <value name=\"drumkitfile\">" + kit.getFile() + "</value>\n" " <value name=\"midimapfile\">" + mmapfile + "</value>\n" " <value name=\"enable_velocity_modifier\">" + - bool2str(Conf::enable_velocity_modifier) + "</value>\n" + bool2str(settings.enable_velocity_modifier.load()) + "</value>\n" " <value name=\"velocity_modifier_falloff\">" + - float2str(Conf::velocity_modifier_falloff) + "</value>\n" + float2str(settings.velocity_modifier_falloff.load()) + "</value>\n" " <value name=\"velocity_modifier_weight\">" + - float2str(Conf::velocity_modifier_weight) + "</value>\n" + float2str(settings.velocity_modifier_weight.load()) + "</value>\n" " <value name=\"enable_velocity_randomiser\">" + - bool2str(Conf::enable_velocity_randomiser) + "</value>\n" + bool2str(settings.enable_velocity_randomiser.load()) + "</value>\n" " <value name=\"velocity_randomiser_weight\">" + - float2str(Conf::velocity_randomiser_weight) + "</value>\n" + float2str(settings.velocity_randomiser_weight.load()) + "</value>\n" "</config>"; } @@ -711,68 +669,50 @@ bool DrumGizmo::setConfigString(std::string cfg) ConfigParser p; if(p.parseString(cfg)) { - ERR(drumgizmo, "Config parse error.\n"); - return false; + ERR(drumgizmo, "Config parse error.\n"); + return false; } if(p.value("enable_velocity_modifier") != "") { - Conf::enable_velocity_modifier = - p.value("enable_velocity_modifier") == "true"; + settings.enable_velocity_modifier.store(p.value("enable_velocity_modifier") == "true"); } if(p.value("velocity_modifier_falloff") != "") { - Conf::velocity_modifier_falloff = - str2float(p.value("velocity_modifier_falloff")); + settings.velocity_modifier_falloff.store(str2float(p.value("velocity_modifier_falloff"))); } if(p.value("velocity_modifier_weight") != "") { - Conf::velocity_modifier_weight = - str2float(p.value("velocity_modifier_weight")); + settings.velocity_modifier_weight.store(str2float(p.value("velocity_modifier_weight"))); } if(p.value("enable_velocity_randomiser") != "") { - Conf::enable_velocity_randomiser = - p.value("enable_velocity_randomiser") == "true"; + settings.enable_velocity_randomiser.store(p.value("enable_velocity_randomiser") == "true"); } if(p.value("velocity_randomiser_weight") != "") { - Conf::velocity_randomiser_weight = - str2float(p.value("velocity_randomiser_weight")); + settings.velocity_randomiser_weight.store(str2float(p.value("velocity_randomiser_weight"))); } if(p.value("enable_resampling") != "") { - Conf::enable_resampling = - p.value("enable_resampling") == "true"; + settings.enable_resampling.store(p.value("enable_resampling") == "true"); } std::string newkit = p.value("drumkitfile"); - if(newkit != "" && kit.getFile() != newkit) + if(newkit != "") { - /* - if(!loadkit(p.values["drumkitfile"])) - { - return false; - } - init(true); - */ - LoadDrumKitMessage *msg = new LoadDrumKitMessage(); - msg->drumkitfile = newkit; - msghandler.sendMessage(MSGRCV_ENGINE, msg); + settings.drumkit_file.store(newkit); } std::string newmidimap = p.value("midimapfile"); if(newmidimap != "") { - //midimapfile = newmidimap; - LoadMidimapMessage *msg = new LoadMidimapMessage(); - msg->midimapfile = newmidimap; - msghandler.sendMessage(MSGRCV_ENGINE, msg); + settings.midimap_file.store(newmidimap); } return true; |