diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2013-04-20 22:06:08 +0200 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2013-04-20 22:06:08 +0200 |
commit | 3f33469b7237240a2be708ca29087773a4b7e228 (patch) | |
tree | 9ee0a87039d8c45e746c5162ef70de90bafb8f49 | |
parent | c9200c25e02b2ab5c1fc4461a4621d109e798350 (diff) |
Added messages for 'get engine seetings' and 'set engine setting', thereby removing the last 'direct call' in the engine code from the gui code.
-rw-r--r-- | plugingui/plugingui.cc | 42 | ||||
-rw-r--r-- | src/drumgizmo.cc | 60 | ||||
-rw-r--r-- | src/message.h | 37 |
3 files changed, 103 insertions, 36 deletions
diff --git a/plugingui/plugingui.cc b/plugingui/plugingui.cc index 7144140..9403939 100644 --- a/plugingui/plugingui.cc +++ b/plugingui/plugingui.cc @@ -60,13 +60,22 @@ namespace Conf { static void checkClick(void *ptr) { PluginGUI *gui = (PluginGUI*)ptr; - Conf::enable_velocity_modifier = gui->check->checked(); + + ChangeSettingMessage *msg = + new ChangeSettingMessage(ChangeSettingMessage::enable_velocity_modifier, + gui->check->checked()); + gui->drumgizmo->sendEngineMessage(msg); } static void knobChange(void *ptr) { PluginGUI *gui = (PluginGUI*)ptr; - Conf::velocity_modifier_weight = gui->knob->value(); + + ChangeSettingMessage *msg = + new ChangeSettingMessage(ChangeSettingMessage::velocity_modifier_weight, + gui->knob->value()); + gui->drumgizmo->sendEngineMessage(msg); + #ifdef STANDALONE int i = gui->knob->value() * 4; switch(i) { @@ -82,7 +91,12 @@ static void knobChange(void *ptr) static void knobChange2(void *ptr) { PluginGUI *gui = (PluginGUI*)ptr; - Conf::velocity_modifier_falloff = gui->knob2->value(); + + ChangeSettingMessage *msg = + new ChangeSettingMessage(ChangeSettingMessage::velocity_modifier_falloff, + gui->knob2->value()); + gui->drumgizmo->sendEngineMessage(msg); + #ifdef STANDALONE gui->progress->setProgress(gui->knob2->value()); #endif @@ -201,6 +215,11 @@ void PluginGUI::thread_main() { init(); + { // Request all engine settings + EngineSettingsMessage *msg = new EngineSettingsMessage(); + drumgizmo->sendEngineMessage(msg); + } + while(running) { eventhandler->processEvents(window); #ifdef WIN32 @@ -231,6 +250,16 @@ void PluginGUI::thread_main() } } break; + case Message::EngineSettingsMessage: + { + EngineSettingsMessage *settings = (EngineSettingsMessage *)msg; + lineedit->setText(settings->drumkitfile); + lineedit2->setText(settings->midimapfile); + check->setChecked(settings->enable_velocity_modifier); + knob->setValue(settings->velocity_modifier_weight); + knob2->setValue(settings->velocity_modifier_falloff); + + } default: break; } @@ -274,9 +303,6 @@ void PluginGUI::init() y += OFFSET1; lineedit = new GUI::LineEdit(window); - if(drumgizmo) lineedit->setText(drumgizmo->drumkitfile()); - else lineedit->setText("/home/deva/aasimonster/aasimonster.xml"); - //else lineedit->setText("Missing DrumGizmo*"); lineedit->move(XOFFSET, y); lineedit->resize(243, 29); @@ -307,7 +333,6 @@ void PluginGUI::init() y += OFFSET1; lineedit2 = new GUI::LineEdit(window); - if(drumgizmo) lineedit2->setText(drumgizmo->midimapfile); lineedit2->move(XOFFSET, y); lineedit2->resize(243, 29); @@ -342,7 +367,6 @@ void PluginGUI::init() //check->setText("Enable Velocity Modifier"); check->move(26, y + OFFSET4); check->resize(59,38); - check->setChecked(Conf::enable_velocity_modifier); check->registerClickHandler(checkClick, this); // Velocity Weight Modifier: @@ -355,7 +379,6 @@ void PluginGUI::init() knob = new GUI::Knob(window); knob->move(109, y + OFFSET4 - 4); knob->resize(57, 57); - knob->setValue(Conf::velocity_modifier_weight); knob->registerClickHandler(knobChange, this); } @@ -369,7 +392,6 @@ void PluginGUI::init() knob2 = new GUI::Knob(window); knob2->move(202 - 13 - 5, y + OFFSET4 - 4); knob2->resize(57, 57); - knob2->setValue(Conf::velocity_modifier_falloff); knob2->registerClickHandler(knobChange2, this); } } diff --git a/src/drumgizmo.cc b/src/drumgizmo.cc index 77d9b89..49ea787 100644 --- a/src/drumgizmo.cc +++ b/src/drumgizmo.cc @@ -38,6 +38,7 @@ #include "drumkitparser.h" #include "audioinputenginemidi.h" +#include "configuration.h" DrumGizmo::DrumGizmo(AudioOutputEngine *o, AudioInputEngine *i) : loader(this), oe(o), ie(i) @@ -179,8 +180,6 @@ bool DrumGizmo::init(bool preload) void DrumGizmo::handleEngineEvents() { - // DEBUG(msg, "handle?"); - Message *msg = receiveEngineMessage(); if(msg) { DEBUG(msg, "got message."); @@ -202,36 +201,47 @@ void DrumGizmo::handleEngineEvents() aim->loadMidiMap(m->midimapfile, kit.instruments); } break; + case Message::EngineSettingsMessage: + { + DEBUG(msg, "got EngineSettingsMessage message."); + EngineSettingsMessage *msg = new EngineSettingsMessage(); + msg->midimapfile = midimapfile; + msg->midimap_loaded = true; + msg->drumkitfile = drumkitfile(); + msg->drumkit_loaded = true; + 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; + sendGUIMessage(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; } - // delete msg; + delete msg; } } bool DrumGizmo::run(size_t pos, sample_t *samples, size_t nsamples) { -#if 0 - DEBUG(drumgizmo, "loader.isDone() = %d", (int)loader.isDone()); - if(!loader.isDone()) { - /* - // return false; - ie->pre(); - oe->pre(nsamples); - size_t nev; - event_t *evs = ie->run(pos, nsamples, &nev); - free(evs); - // memset(samples, 0, nsamples); - for(size_t i = 0; i < nsamples / 2; i++) samples[i] = sin(pos + i); - for(size_t c = 0; c < 16; c++) oe->run(c, samples, nsamples); - ie->post(); - oe->post(nsamples); - pos += nsamples; - */ - return true; - } -#endif - // Handle engine messages, at most one in each iteration: handleEngineEvents(); @@ -435,8 +445,6 @@ void DrumGizmo::stop() // engine.stop(); } -#include "configuration.h" - std::string float2str(float a) { char buf[256]; diff --git a/src/message.h b/src/message.h index c37db12..9bf2f12 100644 --- a/src/message.h +++ b/src/message.h @@ -36,6 +36,8 @@ public: // GUI -> Engine, Engine -> Engine Messages: LoadDrumKit, // Signal engine to load drumkit. LoadMidimap, // Signal engine to load midimap. + EngineSettingsMessage, // Request or receive engine settings. + ChangeSettingMessage, // Update named setting in engine. } type_t; virtual ~Message() {} @@ -62,4 +64,39 @@ public: std::string midimapfile; }; +class EngineSettingsMessage : public Message { +public: + type_t type() { return Message::EngineSettingsMessage; } + std::string midimapfile; + bool midimap_loaded; + + std::string drumkitfile; + bool drumkit_loaded; + + float enable_velocity_modifier; + float velocity_modifier_falloff; + float velocity_modifier_weight; + float enable_velocity_randomiser; + float velocity_randomiser_weight; +}; + +class ChangeSettingMessage : public Message { +public: + typedef enum { + enable_velocity_modifier, + velocity_modifier_weight, + velocity_modifier_falloff, + } setting_name_t; + + ChangeSettingMessage(setting_name_t n, float v) { + name = n; + value = v; + } + + type_t type() { return Message::ChangeSettingMessage; } + + setting_name_t name; + float value; +}; + #endif/*__DRUMGIZMO_MESSAGE_H__*/ |