summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugingui/checkbox.cc73
-rw-r--r--plugingui/checkbox.h26
-rw-r--r--plugingui/plugingui.cc74
-rw-r--r--plugingui/plugingui.h11
4 files changed, 62 insertions, 122 deletions
diff --git a/plugingui/checkbox.cc b/plugingui/checkbox.cc
index faf3741..ec0456f 100644
--- a/plugingui/checkbox.cc
+++ b/plugingui/checkbox.cc
@@ -30,22 +30,23 @@
#include <stdio.h>
-GUI::CheckBox::CheckBox(Widget *parent)
- : GUI::Widget(parent),
- bg_on(":switch_back_on.png"), bg_off(":switch_back_off.png"),
- knob(":switch_front.png")
+namespace GUI {
+
+CheckBox::CheckBox(Widget *parent)
+ : Widget(parent)
+ , bg_on(":switch_back_on.png")
+ , bg_off(":switch_back_off.png")
+ , knob(":switch_front.png")
+ , state(false)
+ , middle(false)
{
- middle = false;
- state = false;
- handler = NULL;
}
-void GUI::CheckBox::buttonEvent(ButtonEvent *e)
+void CheckBox::buttonEvent(ButtonEvent *e)
{
if(e->direction == -1 || e->doubleclick) {
- state = !state;
middle = false;
- if(handler) handler(ptr);
+ internalSetChecked(!state);
} else {
middle = true;
}
@@ -53,24 +54,18 @@ void GUI::CheckBox::buttonEvent(ButtonEvent *e)
repaintEvent(NULL);
}
-void GUI::CheckBox::setText(std::string text)
+void CheckBox::setText(std::string text)
{
_text = text;
repaintEvent(NULL);
}
-void GUI::CheckBox::registerClickHandler(void (*handler)(void *), void *ptr)
+void CheckBox::keyEvent(KeyEvent *e)
{
- this->handler = handler;
- this->ptr = ptr;
-}
-
-void GUI::CheckBox::keyEvent(KeyEvent *e)
-{
- if(e->keycode == GUI::KeyEvent::KEY_CHARACTER && e->text == " ") {
+ if(e->keycode == KeyEvent::KEY_CHARACTER && e->text == " ") {
if(e->direction == -1) {
- state = !state;
middle = false;
+ internalSetChecked(!state);
} else {
middle = true;
}
@@ -79,7 +74,7 @@ void GUI::CheckBox::keyEvent(KeyEvent *e)
}
}
-void GUI::CheckBox::repaintEvent(GUI::RepaintEvent *e)
+void CheckBox::repaintEvent(RepaintEvent *e)
{
Painter p(this);
@@ -94,37 +89,27 @@ void GUI::CheckBox::repaintEvent(GUI::RepaintEvent *e)
if(middle) p.drawImage((bg_on.width() - knob.width()) / 2 + 1, 0, &knob);
else p.drawImage(0, 0, &knob);
}
- /*
- p.setColour(Colour(1));
- Font font;
- p.drawText(box + 8, height() / 2 + 5, font, _text);
- */
}
-bool GUI::CheckBox::checked()
+bool CheckBox::checked()
{
return state;
}
-void GUI::CheckBox::setChecked(bool c)
+void CheckBox::setChecked(bool c)
{
- state = c;
- repaintEvent(NULL);
+ internalSetChecked(c);
}
-#ifdef TEST_CHECKBOX
-//Additional dependency files
-//deps:
-//Required cflags (autoconf vars may be used)
-//cflags:
-//Required link options (autoconf vars may be used)
-//libs:
-#include "test.h"
-
-TEST_BEGIN;
-
-// TODO: Put some testcode here (see test.h for usable macros).
+void CheckBox::internalSetChecked(bool checked)
+{
+ if(checked == state) {
+ return;
+ }
-TEST_END;
+ state = checked;
+ stateChangedNotifier.notify(state);
+ repaintEvent(NULL);
+}
-#endif/*TEST_CHECKBOX*/
+} // GUI::
diff --git a/plugingui/checkbox.h b/plugingui/checkbox.h
index 1d6f9d6..8dd3821 100644
--- a/plugingui/checkbox.h
+++ b/plugingui/checkbox.h
@@ -24,11 +24,11 @@
* along with DrumGizmo; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
-#ifndef __DRUMGIZMO_CHECKBOX_H__
-#define __DRUMGIZMO_CHECKBOX_H__
+#pragma once
#include "widget.h"
#include "image.h"
+#include "notifier.h"
namespace GUI {
@@ -38,21 +38,24 @@ public:
void setText(std::string text);
- bool isFocusable() { return true; }
+ bool isFocusable() override { return true; }
bool checked();
void setChecked(bool checked);
- void registerClickHandler(void (*handler)(void *), void *ptr);
+ Notifier<bool> stateChangedNotifier;
- //protected:
+protected:
virtual void clicked() {}
- virtual void repaintEvent(RepaintEvent *e);
- virtual void buttonEvent(ButtonEvent *e);
- virtual void keyEvent(KeyEvent *e);
+ // From Widget:
+ virtual void repaintEvent(RepaintEvent *e) override;
+ virtual void buttonEvent(ButtonEvent *e) override;
+ virtual void keyEvent(KeyEvent *e) override;
private:
+ void internalSetChecked(bool checked);
+
Image bg_on;
Image bg_off;
Image knob;
@@ -60,12 +63,7 @@ private:
bool state;
bool middle;
- void (*handler)(void *);
- void *ptr;
-
std::string _text;
};
-};
-
-#endif/*__DRUMGIZMO_CHECKBOX_H__*/
+} // GUI::
diff --git a/plugingui/plugingui.cc b/plugingui/plugingui.cc
index 064a015..262b34b 100644
--- a/plugingui/plugingui.cc
+++ b/plugingui/plugingui.cc
@@ -38,59 +38,6 @@
namespace GUI {
-static void checkClick(void *ptr)
-{
- PluginGUI *gui = (PluginGUI*)ptr;
-
- ChangeSettingMessage *msg =
- new ChangeSettingMessage(ChangeSettingMessage::enable_velocity_modifier,
- gui->check->checked());
- msghandler.sendMessage(MSGRCV_ENGINE, msg);
-}
-/*
-static void knobChange(void *ptr)
-{
- PluginGUI *gui = (PluginGUI*)ptr;
-
- ChangeSettingMessage *msg =
- new ChangeSettingMessage(ChangeSettingMessage::velocity_modifier_weight,
- gui->knob->value());
-
- msghandler.sendMessage(MSGRCV_ENGINE, msg);
-
-#ifdef STANDALONE
- int i = gui->knob->value() * 4;
- switch(i) {
- case 0: gui->progress->setState(ProgressBar::off); break;
- case 1: gui->progress->setState(ProgressBar::blue); break;
- case 2: gui->progress->setState(ProgressBar::green); break;
- case 3: gui->progress->setState(ProgressBar::red); break;
- default: break;
- }
-#endif
-}
-
-static void knobChange2(void *ptr)
-{
- PluginGUI *gui = (PluginGUI*)ptr;
-
- ChangeSettingMessage *msg =
- new ChangeSettingMessage(ChangeSettingMessage::velocity_modifier_falloff,
- gui->knob2->value());
- msghandler.sendMessage(MSGRCV_ENGINE, msg);
-
-#ifdef STANDALONE
- gui->progress->setProgress(gui->knob2->value());
-#endif
-}
-*/
-
-//static void quit(void *ptr) {
-// PluginGUI *gui = (PluginGUI*)ptr;
-//
-// gui->stopThread();
-//}
-
FileBrowser *fb;
static void selectKitFile(void *ptr, std::string filename)
{
@@ -252,7 +199,7 @@ void PluginGUI::handleMessage(Message *msg)
progress2->setProgress(0);
progress2->setState(ProgressBar::blue);
}
- check->setChecked(settings->enable_velocity_modifier);
+ velocityCheck->setChecked(settings->enable_velocity_modifier);
attackKnob->setValue(settings->velocity_modifier_weight);
falloffKnob->setValue(settings->velocity_modifier_falloff);
@@ -402,11 +349,12 @@ void PluginGUI::init()
lbl_velocity->move(16, y);
lbl_velocity->setText("Humanizer");
- check = new CheckBox(window);
- //check->setText("Enable Velocity Modifier");
- check->move(26, y + OFFSET4);
- check->resize(59,38);
- check->registerClickHandler(checkClick, this);
+ velocityCheck = new CheckBox(window);
+ //velocityCheck->setText("Enable Velocity Modifier");
+ velocityCheck->move(26, y + OFFSET4);
+ velocityCheck->resize(59,38);
+ obj_connect(velocityCheck, stateChangedNotifier,
+ this, PluginGUI::velocityCheckClick);
// Velocity Weight Modifier:
{
@@ -542,6 +490,14 @@ void PluginGUI::falloffValueChanged(float value)
#endif
}
+void PluginGUI::velocityCheckClick(bool checked)
+{
+ ChangeSettingMessage *msg =
+ new ChangeSettingMessage(ChangeSettingMessage::enable_velocity_modifier,
+ checked);
+ msghandler.sendMessage(MSGRCV_ENGINE, msg);
+}
+
} // GUI::
#ifdef STANDALONE
diff --git a/plugingui/plugingui.h b/plugingui/plugingui.h
index a5f2fe8..dfcbcb8 100644
--- a/plugingui/plugingui.h
+++ b/plugingui/plugingui.h
@@ -65,16 +65,11 @@ public:
void handleMessage(Message *msg);
- //private:
Window *window;
EventHandler *eventhandler;
FileBrowser *filebrowser;
- CheckBox *check;
- Knob *attackKnob;
- Knob *falloffKnob;
-
Label *lbl;
LineEdit *lineedit;
ProgressBar *progress;
@@ -94,6 +89,12 @@ public:
private:
void attackValueChanged(float value);
void falloffValueChanged(float value);
+ void velocityCheckClick(bool checked);
+
+ // Humanized velocity controls:
+ CheckBox *velocityCheck;
+ Knob *attackKnob;
+ Knob *falloffKnob;
volatile bool running;
volatile bool closing;