summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugingui/knob.cc131
-rw-r--r--plugingui/knob.h38
-rw-r--r--plugingui/notifier.h149
-rw-r--r--plugingui/plugingui.cc152
-rw-r--r--plugingui/plugingui.h38
-rw-r--r--plugingui/widget.cc77
-rw-r--r--plugingui/widget.h10
7 files changed, 363 insertions, 232 deletions
diff --git a/plugingui/knob.cc b/plugingui/knob.cc
index 4cac180..b843106 100644
--- a/plugingui/knob.cc
+++ b/plugingui/knob.cc
@@ -37,118 +37,101 @@
#endif
#include <math.h>
-GUI::Knob::Knob(Widget *parent)
- : GUI::Widget(parent), img_knob(":knob.png")
+namespace GUI {
+
+Knob::Knob(Widget *parent)
+ : Widget(parent)
+ , img_knob(":knob.png")
{
state = up;
- val = 0.0;
maximum = 1.0;
minimum = 0.0;
- mouse_offset_x = 0;
- handler = NULL;
- ptr = NULL;
-}
+ currentValue = minimum;
-void GUI::Knob::setValue(float v)
-{
- val = v;
- if(handler) handler(ptr);
- repaintEvent(NULL);
+ mouse_offset_x = 0;
}
-float GUI::Knob::value()
+void Knob::setValue(float value)
{
- return val;
+ internalSetValue(value);
}
-void GUI::Knob::registerClickHandler(void (*handler)(void *), void *ptr)
+float Knob::value()
{
- this->handler = handler;
- this->ptr = ptr;
+ return currentValue;
}
-void GUI::Knob::scrollEvent(ScrollEvent *e)
+void Knob::scrollEvent(ScrollEvent *e)
{
- val -= e->delta / 200.0;
- if(val < 0) val = 0;
- if(val > 1) val = 1;
-
- if(handler) handler(ptr);
-
- repaintEvent(NULL);
+ float value = currentValue - (e->delta / 200.0);
+ internalSetValue(value);
}
-void GUI::Knob::mouseMoveEvent(MouseMoveEvent *e)
+void Knob::mouseMoveEvent(MouseMoveEvent *e)
{
if(state == down) {
- if(mouse_offset_x == (e->x + -1*e->y)) return;
-
- float dval = mouse_offset_x - (e->x + -1*e->y);
- val -= dval / 300.0;
+ if(mouse_offset_x == (e->x + -1 * e->y)) {
+ return;
+ }
- if(val < 0) val = 0;
- if(val > 1) val = 1;
+ float dval = mouse_offset_x - (e->x + -1 * e->y);
+ float value = currentValue - (dval / 300.0);
- if(handler) handler(ptr);
- repaintEvent(NULL);
+ internalSetValue(value);
- mouse_offset_x = e->x + -1*e->y;
+ mouse_offset_x = e->x + -1 * e->y;
}
}
-void GUI::Knob::keyEvent(KeyEvent *e)
+void Knob::keyEvent(KeyEvent *e)
{
- if(e->direction != -1) return;
+ if(e->direction != -1) {
+ return;
+ }
+ float value = currentValue;
switch(e->keycode) {
- case GUI::KeyEvent::KEY_UP:
- val += 0.01;
+ case KeyEvent::KEY_UP:
+ value += 0.01;
break;
- case GUI::KeyEvent::KEY_DOWN:
- val -= 0.01;
+ case KeyEvent::KEY_DOWN:
+ value -= 0.01;
break;
- case GUI::KeyEvent::KEY_RIGHT:
- val += 0.01;
+ case KeyEvent::KEY_RIGHT:
+ value += 0.01;
break;
- case GUI::KeyEvent::KEY_LEFT:
- val -= 0.01;
+ case KeyEvent::KEY_LEFT:
+ value -= 0.01;
break;
- case GUI::KeyEvent::KEY_HOME:
- val = 0;
+ case KeyEvent::KEY_HOME:
+ value = 0;
break;
- case GUI::KeyEvent::KEY_END:
- val = 1;
+ case KeyEvent::KEY_END:
+ value = 1;
break;
default:
break;
}
- if(val < 0) val = 0;
- if(val > 1) val = 1;
-
- repaintEvent(NULL);
+ internalSetValue(value);
}
-void GUI::Knob::buttonEvent(ButtonEvent *e)
+void Knob::buttonEvent(ButtonEvent *e)
{
if(e->direction == 1) {
state = down;
mouse_offset_x = e->x + -1*e->y;
- if(handler) handler(ptr);
- repaintEvent(NULL);
}
if(e->direction == -1) {
state = up;
mouse_offset_x = e->x + -1*e->y;
- repaintEvent(NULL);
clicked();
- if(handler) handler(ptr);
}
}
-void GUI::Knob::repaintEvent(GUI::RepaintEvent *e)
+void Knob::repaintEvent(RepaintEvent *e)
{
int diameter = (width()>height()?height():width());
int radius = diameter / 2;
@@ -161,12 +144,13 @@ void GUI::Knob::repaintEvent(GUI::RepaintEvent *e)
p.drawImageStretched(0, 0, &img_knob, diameter, diameter);
char buf[64];
- sprintf(buf, "%.2f", val * maximum);
+ sprintf(buf, "%.2f", currentValue * maximum);
Font font;
p.drawText(center_x - font.textWidth(buf) / 2 + 1,
center_y + font.textHeight(buf) / 2 + 1, font, buf);
- double padval = val * 0.8 + 0.1; // Make it start from 20% and stop at 80%
+ // Make it start from 20% and stop at 80%
+ double padval = currentValue * 0.8 + 0.1;
double from_x = sin((-1 * padval + 1) * 2 * M_PI) * radius * 0.6;
double from_y = cos((-1 * padval + 1) * 2 * M_PI) * radius * 0.6;
@@ -187,19 +171,18 @@ void GUI::Knob::repaintEvent(GUI::RepaintEvent *e)
}
}
-#ifdef TEST_KNOB
-//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;
+void Knob::internalSetValue(float value)
+{
+ if(value < minimum) value = minimum;
+ if(value > maximum) value = maximum;
-// TODO: Put some testcode here (see test.h for usable macros).
+ if(value == currentValue) {
+ return;
+ }
-TEST_END;
+ currentValue = value;
+ valueChangedNotifier.notify(currentValue);
+ repaintEvent(NULL);
+}
-#endif/*TEST_KNOB*/
+} // GUI::
diff --git a/plugingui/knob.h b/plugingui/knob.h
index a6af499..d14a5b3 100644
--- a/plugingui/knob.h
+++ b/plugingui/knob.h
@@ -24,13 +24,14 @@
* along with DrumGizmo; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
-#ifndef __DRUMGIZMO_KNOB_H__
-#define __DRUMGIZMO_KNOB_H__
+#pragma once
#include "widget.h"
#include "image.h"
+#include "notifier.h"
+
namespace GUI {
class Knob : public Widget {
@@ -43,38 +44,37 @@ public:
void setValue(float value);
float value();
- void registerClickHandler(void (*handler)(void *), void *ptr);
+ Notifier<float> valueChangedNotifier; // (float newValue)
- //protected:
+protected:
virtual void clicked() {}
- virtual void repaintEvent(RepaintEvent *e);
- virtual void buttonEvent(ButtonEvent *e);
- virtual void mouseMoveEvent(MouseMoveEvent *e);
- virtual void scrollEvent(ScrollEvent *e);
- virtual void keyEvent(KeyEvent *e);
+ // From Widget:
+ virtual void repaintEvent(RepaintEvent *e) override;
+ virtual void buttonEvent(ButtonEvent *e) override;
+ virtual void mouseMoveEvent(MouseMoveEvent *e) override;
+ virtual void scrollEvent(ScrollEvent *e) override;
+ virtual void keyEvent(KeyEvent *e) override;
private:
+ //! Sets the internal value and sends out the changed notification.
+ void internalSetValue(float value);
+
typedef enum {
up,
down
} state_t;
- float val;
- float maximum;
- float minimum;
-
state_t state;
- GUI::Image img_knob;
+ float currentValue;
+ float maximum;
+ float minimum;
- void (*handler)(void *);
- void *ptr;
+ Image img_knob;
int mouse_offset_x;
-
};
-};
+} // GUI::
-#endif/*__DRUMGIZMO_KNOB_H__*/
diff --git a/plugingui/notifier.h b/plugingui/notifier.h
new file mode 100644
index 0000000..d68e28c
--- /dev/null
+++ b/plugingui/notifier.h
@@ -0,0 +1,149 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * notifier.h
+ *
+ * Thu Sep 3 15:48:39 CEST 2015
+ * Copyright 2015 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of DrumGizmo.
+ *
+ * DrumGizmo 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; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * DrumGizmo 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 DrumGizmo; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#pragma once
+
+#include <iostream>
+#include <functional>
+#include <vector>
+#include <map>
+#include <set>
+#include <type_traits>
+#include <utility>
+
+namespace GUI {
+
+class Listener;
+class NotifierBase {
+public:
+ virtual void disconnect(Listener* object) {}
+};
+
+class Listener {
+public:
+ virtual ~Listener()
+ {
+ for(auto signal = signals.begin(); signal != signals.end(); ++signal) {
+ (*signal)->disconnect(this);
+ }
+ }
+
+ void registerNotifier(NotifierBase* signal)
+ {
+ signals.insert(signal);
+ }
+
+ void unregisterNotifier(NotifierBase* signal)
+ {
+ signals.erase(signal);
+ }
+
+ std::set<NotifierBase*> signals;
+};
+
+template<typename T, typename... Args>
+class Notifier : public NotifierBase {
+public:
+ Notifier() {}
+ ~Notifier()
+ {
+ for(auto slot = slots.begin(); slot != slots.end(); ++slot) {
+ (*slot).first->unregisterNotifier(this);
+ }
+ }
+
+ void connect(Listener* object, std::function<void(T, Args...)> slot)
+ {
+ slots[object] = slot;
+ if(object) {
+ object->registerNotifier(this);
+ }
+ }
+
+ void disconnect(Listener* object)
+ {
+ slots.erase(object);
+ }
+
+ void notify(T t, Args...args)
+ {
+ for(auto slot = slots.begin(); slot != slots.end(); ++slot) {
+ (*slot).second(t, args...);
+ }
+ }
+
+ std::map<Listener*, std::function<void(T, Args...)>> slots;
+};
+
+} // GUI::
+
+template<unsigned... Is> struct seq{};
+template<unsigned I, unsigned... Is>
+struct gen_seq : gen_seq<I-1, I-1, Is...>{};
+template<unsigned... Is>
+struct gen_seq<0, Is...> : seq<Is...>{};
+
+template<unsigned I> struct placeholder{};
+
+namespace std{
+template<unsigned I>
+struct is_placeholder< ::placeholder<I> > : integral_constant<int, I>{};
+} // std::
+
+namespace aux{
+template<unsigned... Is, class F, class... Ts>
+auto easy_bind(seq<Is...>, F&& f, Ts&&... vs)
+ -> decltype(std::bind(std::forward<F>(f), std::forward<Ts>(vs)..., ::placeholder<1 + Is>()...))
+{
+ return std::bind(std::forward<F>(f), std::forward<Ts>(vs)..., ::placeholder<1 + Is>()...);
+}
+} // aux::
+
+template<class R, class C, class... FArgs, class... Args>
+auto mem_bind(R (C::*ptmf)(FArgs...), Args&&... vs)
+ -> decltype(aux::easy_bind(gen_seq<(sizeof...(FArgs) + 1) - sizeof...(Args)>(), ptmf, std::forward<Args>(vs)...))
+{
+ // the +1s for 'this' argument
+ static_assert(sizeof...(Args) <= sizeof...(FArgs) + 1, "too many arguments to mem_bind");
+ return aux::easy_bind(gen_seq<(sizeof...(FArgs) + 1) - sizeof...(Args)>(), ptmf, std::forward<Args>(vs)...);
+}
+
+template<class T, class C, class... Args>
+auto mem_bind(T C::*ptmd, Args&&... vs)
+ -> decltype(aux::easy_bind(gen_seq<1 - sizeof...(Args)>(), ptmd, std::forward<Args>(vs)...))
+{
+ // just 'this' argument
+ static_assert(sizeof...(Args) <= 1, "too many arguments to mem_bind");
+ return aux::easy_bind(gen_seq<1 - sizeof...(Args)>(), ptmd, std::forward<Args>(vs)...);
+}
+
+//#define obj_connect_old(SRC, SIG, TAR, SLO) (SRC).SIG.connect(&(TAR), mem_bind(&decltype(TAR)::SLO, TAR))
+
+#define fun_connect(SRC, SIG, SLO) \
+ (SRC).SIG.connect(nullptr, SLO)
+
+#define obj_connect(SRC, SIG, TAR, SLO) \
+ (SRC)->SIG.connect(TAR, mem_bind(&SLO, std::ref(*TAR)))
diff --git a/plugingui/plugingui.cc b/plugingui/plugingui.cc
index 170f4f9..064a015 100644
--- a/plugingui/plugingui.cc
+++ b/plugingui/plugingui.cc
@@ -36,6 +36,8 @@
#include "pluginconfig.h"
#include "messagehandler.h"
+namespace GUI {
+
static void checkClick(void *ptr)
{
PluginGUI *gui = (PluginGUI*)ptr;
@@ -45,7 +47,7 @@ static void checkClick(void *ptr)
gui->check->checked());
msghandler.sendMessage(MSGRCV_ENGINE, msg);
}
-
+/*
static void knobChange(void *ptr)
{
PluginGUI *gui = (PluginGUI*)ptr;
@@ -59,10 +61,10 @@ static void knobChange(void *ptr)
#ifdef STANDALONE
int i = gui->knob->value() * 4;
switch(i) {
- case 0: gui->progress->setState(GUI::ProgressBar::off); break;
- case 1: gui->progress->setState(GUI::ProgressBar::blue); break;
- case 2: gui->progress->setState(GUI::ProgressBar::green); break;
- case 3: gui->progress->setState(GUI::ProgressBar::red); break;
+ 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
@@ -81,6 +83,7 @@ static void knobChange2(void *ptr)
gui->progress->setProgress(gui->knob2->value());
#endif
}
+*/
//static void quit(void *ptr) {
// PluginGUI *gui = (PluginGUI*)ptr;
@@ -88,7 +91,7 @@ static void knobChange2(void *ptr)
// gui->stopThread();
//}
-GUI::FileBrowser *fb;
+FileBrowser *fb;
static void selectKitFile(void *ptr, std::string filename)
{
PluginGUI *gui = (PluginGUI*)ptr;
@@ -103,7 +106,7 @@ static void selectKitFile(void *ptr, std::string filename)
gui->config->save();
gui->progress->setProgress(0);
- gui->progress->setState(GUI::ProgressBar::blue);
+ gui->progress->setState(ProgressBar::blue);
LoadDrumKitMessage *msg = new LoadDrumKitMessage();
msg->drumkitfile = drumkit;
@@ -143,7 +146,7 @@ static void selectMapFile(void *ptr, std::string filename)
/*
if(gui->changeMidimapHandler)
gui->changeMidimapHandler(gui->changeMidimapPtr, midimap.c_str());
- gui->progress2->setState(GUI::ProgressBar::green);
+ gui->progress2->setState(ProgressBar::green);
*/
}
@@ -206,7 +209,7 @@ void PluginGUI::stopThread()
void PluginGUI::handleMessage(Message *msg)
{
- GUI::Painter p(window);// Make sure we only redraw buffer one time.
+ Painter p(window);// Make sure we only redraw buffer one time.
switch(msg->type()) {
case Message::LoadStatus:
@@ -215,7 +218,7 @@ void PluginGUI::handleMessage(Message *msg)
progress->setProgress((float)ls->numer_of_files_loaded /
(float)ls->number_of_files);
if(ls->numer_of_files_loaded == ls->number_of_files) {
- progress->setState(GUI::ProgressBar::green);
+ progress->setState(ProgressBar::green);
}
}
break;
@@ -224,9 +227,9 @@ void PluginGUI::handleMessage(Message *msg)
LoadStatusMessageMidimap *ls = (LoadStatusMessageMidimap*)msg;
progress2->setProgress(1);
if(ls->success) {
- progress2->setState(GUI::ProgressBar::green);
+ progress2->setState(ProgressBar::green);
} else {
- progress2->setState(GUI::ProgressBar::red);
+ progress2->setState(ProgressBar::red);
}
}
break;
@@ -236,22 +239,22 @@ void PluginGUI::handleMessage(Message *msg)
lineedit->setText(settings->drumkitfile);
if(settings->drumkit_loaded) {
progress->setProgress(1);
- progress->setState(GUI::ProgressBar::green);
+ progress->setState(ProgressBar::green);
} else {
progress->setProgress(0);
- progress->setState(GUI::ProgressBar::blue);
+ progress->setState(ProgressBar::blue);
}
lineedit2->setText(settings->midimapfile);
if(settings->midimap_loaded) {
progress2->setProgress(1);
- progress2->setState(GUI::ProgressBar::green);
+ progress2->setState(ProgressBar::green);
} else {
progress2->setProgress(0);
- progress2->setState(GUI::ProgressBar::blue);
+ progress2->setState(ProgressBar::blue);
}
check->setChecked(settings->enable_velocity_modifier);
- knob->setValue(settings->velocity_modifier_weight);
- knob2->setValue(settings->velocity_modifier_falloff);
+ attackKnob->setValue(settings->velocity_modifier_weight);
+ falloffKnob->setValue(settings->velocity_modifier_falloff);
}
default:
@@ -306,19 +309,19 @@ void PluginGUI::init()
config = new Config();
config->load();
- window = new GUI::Window();
+ window = new Window();
window->eventHandler()->registerCloseHandler(closeEventHandler,
(void*)&closing);
window->setFixedSize(370, 330);
window->setCaption("DrumGizmo v" VERSION);
- GUI::Label *lbl_title = new GUI::Label(window);
+ Label *lbl_title = new Label(window);
lbl_title->setText("DrumGizmo");
lbl_title->move(127, 7);
lbl_title->resize(200, 20);
- GUI::VerticalLine *l1 = new GUI::VerticalLine(window);
+ VerticalLine *l1 = new VerticalLine(window);
l1->move(20, 30);
l1->resize(window->width() - 40, 2);
@@ -330,30 +333,30 @@ void PluginGUI::init()
// Drumkit file
{
int y = 37;
- GUI::Label *lbl = new GUI::Label(window);
+ Label *lbl = new Label(window);
lbl->setText("Drumkit file:");
lbl->move(XOFFSET - 4, y);
lbl->resize(100, 20);
y += OFFSET1;
- lineedit = new GUI::LineEdit(window);
+ lineedit = new LineEdit(window);
lineedit->move(XOFFSET, y);
lineedit->resize(243, 29);
lineedit->setReadOnly(true);
- GUI::Button *btn_brw = new GUI::Button(window);
+ Button *btn_brw = new Button(window);
btn_brw->setText("Browse...");
btn_brw->move(266, y - 6 + 4);
btn_brw->resize(85, 35 + 6 - 4);
btn_brw->registerClickHandler(kitBrowseClick, this);
y += OFFSET2;
- progress = new GUI::ProgressBar(window);
+ progress = new ProgressBar(window);
progress->move(XOFFSET, y);
progress->resize(window->width() - 2*XOFFSET, 11);
y += OFFSET3;
- GUI::VerticalLine *l = new GUI::VerticalLine(window);
+ VerticalLine *l = new VerticalLine(window);
l->move(XOFFSET, y);
l->resize(window->width() - 2*XOFFSET, 2);
}
@@ -361,30 +364,30 @@ void PluginGUI::init()
// Midimap file
{
int y = 120;
- lbl2 = new GUI::Label(window);
+ lbl2 = new Label(window);
lbl2->setText("Midimap file:");
lbl2->move(XOFFSET - 4, y);
lbl2->resize(100, 20);
y += OFFSET1;
- lineedit2 = new GUI::LineEdit(window);
+ lineedit2 = new LineEdit(window);
lineedit2->move(XOFFSET, y);
lineedit2->resize(243, 29);
lineedit2->setReadOnly(true);
- GUI::Button *btn_brw = new GUI::Button(window);
+ Button *btn_brw = new Button(window);
btn_brw->setText("Browse...");
btn_brw->move(266, y - 6 + 4);
btn_brw->resize(85, 35 + 6 - 4);
btn_brw->registerClickHandler(midimapBrowseClick, this);
y += OFFSET2;
- progress2 = new GUI::ProgressBar(window);
+ progress2 = new ProgressBar(window);
progress2->move(XOFFSET, y);
progress2->resize(window->width() - 2*XOFFSET, 11);
y += OFFSET3;
- GUI::VerticalLine *l = new GUI::VerticalLine(window);
+ VerticalLine *l = new VerticalLine(window);
l->move(XOFFSET, y);
l->resize(window->width() - 2*XOFFSET, 2);
}
@@ -394,12 +397,12 @@ void PluginGUI::init()
#define OFFSET4 21
// Enable Velocity
- GUI::Label *lbl_velocity = new GUI::Label(window);
+ Label *lbl_velocity = new Label(window);
lbl_velocity->resize(78 ,20);
lbl_velocity->move(16, y);
lbl_velocity->setText("Humanizer");
- check = new GUI::CheckBox(window);
+ check = new CheckBox(window);
//check->setText("Enable Velocity Modifier");
check->move(26, y + OFFSET4);
check->resize(59,38);
@@ -407,42 +410,43 @@ void PluginGUI::init()
// Velocity Weight Modifier:
{
- GUI::Label *lbl_weight = new GUI::Label(window);
+ Label *lbl_weight = new Label(window);
lbl_weight->setText("Attack");
lbl_weight->move(107, y);
lbl_weight->resize(100, 20);
- knob = new GUI::Knob(window);
- knob->move(109, y + OFFSET4 - 4);
- knob->resize(57, 57);
- knob->registerClickHandler(knobChange, this);
+ attackKnob = new Knob(window);
+ attackKnob->move(109, y + OFFSET4 - 4);
+ attackKnob->resize(57, 57);
+ obj_connect(attackKnob, valueChangedNotifier,
+ this, PluginGUI::attackValueChanged);
}
// Velocity Falloff Modifier:
{
- GUI::Label *lbl_falloff = new GUI::Label(window);
+ Label *lbl_falloff = new Label(window);
lbl_falloff->setText("Release");
lbl_falloff->move(202 - 17 - 7, y);
lbl_falloff->resize(100, 20);
- knob2 = new GUI::Knob(window);
- knob2->move(202 - 13 - 5, y + OFFSET4 - 4);
- knob2->resize(57, 57);
- knob2->registerClickHandler(knobChange2, this);
- }
+ falloffKnob = new Knob(window);
+ falloffKnob->move(202 - 13 - 5, y + OFFSET4 - 4);
+ falloffKnob->resize(57, 57);
+ obj_connect(falloffKnob, valueChangedNotifier,
+ this, PluginGUI::falloffValueChanged); }
}
- GUI::VerticalLine *l2 = new GUI::VerticalLine(window);
+ VerticalLine *l2 = new VerticalLine(window);
l2->move(20, 310 - 15 - 9);
l2->resize(window->width() - 40, 2);
- GUI::Label *lbl_version = new GUI::Label(window);
+ Label *lbl_version = new Label(window);
lbl_version->setText(".::. v" VERSION " .::. http://www.drumgizmo.org .::. GPLv3 .::.");
lbl_version->move(16, 300);
lbl_version->resize(window->width(), 20);
/*
{
- GUI::ComboBox *cmb = new GUI::ComboBox(window);
+ ComboBox *cmb = new ComboBox(window);
cmb->addItem("Foo", "Bar");
cmb->addItem("Hello", "World");
cmb->move(10,10);
@@ -450,14 +454,14 @@ void PluginGUI::init()
}
*/
// Create filebrowser
- filebrowser = new GUI::FileBrowser(window);
+ filebrowser = new FileBrowser(window);
filebrowser->move(0, 0);
filebrowser->resize(window->width() - 1, window->height() - 1);
filebrowser->hide();
fb = filebrowser;
// Enable quit button
-// GUI::Button *btn_quit = new GUI::Button(window);
+// Button *btn_quit = new Button(window);
// btn_quit->setText("Quit");
// btn_quit->move(50,280);
// btn_quit->resize(80,80);
@@ -506,6 +510,40 @@ void PluginGUI::setWindowClosedCallback(void (*handler)(void *), void *ptr)
windowClosedPtr = ptr;
}
+void PluginGUI::attackValueChanged(float value)
+{
+ ChangeSettingMessage *msg =
+ new ChangeSettingMessage(ChangeSettingMessage::velocity_modifier_weight,
+ value);
+
+ msghandler.sendMessage(MSGRCV_ENGINE, msg);
+
+#ifdef STANDALONE
+ int i = value * 4;
+ switch(i) {
+ case 0: progress->setState(ProgressBar::off); break;
+ case 1: progress->setState(ProgressBar::blue); break;
+ case 2: progress->setState(ProgressBar::green); break;
+ case 3: progress->setState(ProgressBar::red); break;
+ default: break;
+ }
+#endif
+}
+
+void PluginGUI::falloffValueChanged(float value)
+{
+ ChangeSettingMessage *msg =
+ new ChangeSettingMessage(ChangeSettingMessage::velocity_modifier_falloff,
+ value);
+ msghandler.sendMessage(MSGRCV_ENGINE, msg);
+
+#ifdef STANDALONE
+ progress->setProgress(value);
+#endif
+}
+
+} // GUI::
+
#ifdef STANDALONE
class Engine : public MessageHandler {
@@ -513,7 +551,6 @@ public:
void handleMessage(Message *msg) {}
};
-
void stop(void *ptr)
{
DEBUG(stop, "Stopping...\n");
@@ -523,32 +560,19 @@ void stop(void *ptr)
int main()
{
-/*
- hug_status_t status = hug_init(HUG_FLAG_OUTPUT_TO_SYSLOG,
- HUG_OPTION_SYSLOG_HOST, "192.168.0.10",
- HUG_OPTION_SYSLOG_PORT, 514,
- HUG_OPTION_END);
-
- if(status != HUG_STATUS_OK) {
- printf("Error: %d\n", status);
- return 1;
- }
-*/
INFO(example, "We are up and running");
bool running = true;
- PluginGUI gui;
+ GUI::PluginGUI gui;
gui.setWindowClosedCallback(stop, &running);
// gui.show();
while(running) {
- // gui.processEvents();
#ifdef WIN32
SleepEx(1000, FALSE);
#else
- // usleep(10000);
sleep(1);
#endif
}
diff --git a/plugingui/plugingui.h b/plugingui/plugingui.h
index 39643e1..a5f2fe8 100644
--- a/plugingui/plugingui.h
+++ b/plugingui/plugingui.h
@@ -24,8 +24,7 @@
* along with DrumGizmo; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
-#ifndef __DRUMGIZMO_PLUGINGUI_H__
-#define __DRUMGIZMO_PLUGINGUI_H__
+#pragma once
#include "window.h"
#include "eventhandler.h"
@@ -44,8 +43,11 @@
#include "semaphore.h"
#include "messagereceiver.h"
+#include "notifier.h"
-class PluginGUI : public Thread, public MessageReceiver {
+namespace GUI {
+
+class PluginGUI : public Thread, public MessageReceiver, public Listener {
public:
PluginGUI();
virtual ~PluginGUI();
@@ -64,22 +66,22 @@ public:
void handleMessage(Message *msg);
//private:
- GUI::Window *window;
- GUI::EventHandler *eventhandler;
+ Window *window;
+ EventHandler *eventhandler;
- GUI::FileBrowser *filebrowser;
+ FileBrowser *filebrowser;
- GUI::CheckBox *check;
- GUI::Knob *knob;
- GUI::Knob *knob2;
+ CheckBox *check;
+ Knob *attackKnob;
+ Knob *falloffKnob;
- GUI::Label *lbl;
- GUI::LineEdit *lineedit;
- GUI::ProgressBar *progress;
+ Label *lbl;
+ LineEdit *lineedit;
+ ProgressBar *progress;
- GUI::Label *lbl2;
- GUI::LineEdit *lineedit2;
- GUI::ProgressBar *progress2;
+ Label *lbl2;
+ LineEdit *lineedit2;
+ ProgressBar *progress2;
Config *config;
@@ -90,6 +92,9 @@ public:
void *changeMidimapPtr;
private:
+ void attackValueChanged(float value);
+ void falloffValueChanged(float value);
+
volatile bool running;
volatile bool closing;
volatile bool initialised;
@@ -97,4 +102,5 @@ private:
Semaphore sem;
};
-#endif/*__DRUMGIZMO_PLUGINGUI_H__*/
+} // GUI::
+
diff --git a/plugingui/widget.cc b/plugingui/widget.cc
index 05966aa..0919e22 100644
--- a/plugingui/widget.cc
+++ b/plugingui/widget.cc
@@ -31,7 +31,9 @@
#include <stdio.h>
-GUI::Widget::Widget(Widget *parent)
+namespace GUI {
+
+Widget::Widget(Widget *parent)
: pixbuf(1, 1)
{
_width = _height = 10;
@@ -45,38 +47,38 @@ GUI::Widget::Widget(Widget *parent)
_visible = true;
}
-GUI::Widget::~Widget()
+Widget::~Widget()
{
if(parent) parent->removeChild(this);
}
-void GUI::Widget::show()
+void Widget::show()
{
setVisible(true);
}
-void GUI::Widget::hide()
+void Widget::hide()
{
setVisible(false);
}
-void GUI::Widget::setVisible(bool v)
+void Widget::setVisible(bool v)
{
_visible = v;
repaintEvent(NULL);
}
-bool GUI::Widget::visible()
+bool Widget::visible()
{
return _visible;
}
-void GUI::Widget::addChild(GUI::Widget *widget)
+void Widget::addChild(Widget *widget)
{
children.push_back(widget);
}
-void GUI::Widget::removeChild(GUI::Widget *widget)
+void Widget::removeChild(Widget *widget)
{
std::vector<Widget *>::iterator i = children.begin();
while(i != children.end()) {
@@ -88,7 +90,7 @@ void GUI::Widget::removeChild(GUI::Widget *widget)
}
}
-void GUI::Widget::resize(int width, int height)
+void Widget::resize(int width, int height)
{
if(width < 1 || height < 1) return;
_width = width;
@@ -96,32 +98,32 @@ void GUI::Widget::resize(int width, int height)
pixbuf.realloc(width, height);
}
-void GUI::Widget::move(size_t x, size_t y)
+void Widget::move(size_t x, size_t y)
{
_x = x;
_y = y;
}
-size_t GUI::Widget::x() { return _x; }
-size_t GUI::Widget::y() { return _y; }
-size_t GUI::Widget::width() { return _width; }
-size_t GUI::Widget::height() { return _height; }
+size_t Widget::x() { return _x; }
+size_t Widget::y() { return _y; }
+size_t Widget::width() { return _width; }
+size_t Widget::height() { return _height; }
-size_t GUI::Widget::windowX()
+size_t Widget::windowX()
{
size_t window_x = x();
if(parent) window_x += parent->windowX();
return window_x;
}
-size_t GUI::Widget::windowY()
+size_t Widget::windowY()
{
size_t window_y = y();
if(parent) window_y += parent->windowY();
return window_y;
}
-GUI::Widget *GUI::Widget::find(size_t x, size_t y)
+Widget *Widget::find(size_t x, size_t y)
{
std::vector<Widget*>::reverse_iterator i = children.rbegin();
while(i != children.rend()) {
@@ -138,12 +140,12 @@ GUI::Widget *GUI::Widget::find(size_t x, size_t y)
return this;
}
-GUI::Window *GUI::Widget::window()
+Window *Widget::window()
{
return _window;
}
-void GUI::Widget::repaint_r(GUI::RepaintEvent *e)
+void Widget::repaint_r(RepaintEvent *e)
{
Painter p(this); // make sure pixbuf refcount is incremented.
@@ -157,7 +159,7 @@ void GUI::Widget::repaint_r(GUI::RepaintEvent *e)
}
}
-std::vector<GUI::PixelBufferAlpha *> GUI::Widget::getPixelBuffers()
+std::vector<PixelBufferAlpha *> Widget::getPixelBuffers()
{
std::vector<PixelBufferAlpha *> pbs;
@@ -179,40 +181,9 @@ std::vector<GUI::PixelBufferAlpha *> GUI::Widget::getPixelBuffers()
return pbs;
}
-bool GUI::Widget::hasKeyboardFocus()
+bool Widget::hasKeyboardFocus()
{
return window()->keyboardFocus() == this;
}
-#ifdef TEST_WIDGET
-//deps: window.cc globalcontext.cc
-//cflags:
-//libs:
-#include "test.h"
-
-#include "window.h"
-
-TEST_BEGIN;
-
-GUI::Window w1(NULL);
-w1.move(0,0);
-w1.resize(100, 100);
-
-GUI::Widget w2(&w1);
-w2.resize(40,40);
-w2.move(10,10);
-
-GUI::Widget w3(&w2);
-w3.resize(20,20);
-w3.move(10,10);
-
-TEST_EQUAL_PTR(w1.find(101,0), NULL, "Miss?");
-TEST_EQUAL_PTR(w1.find(0,0), &w1, "Hit w1?");
-TEST_EQUAL_PTR(w1.find(100,100), &w1, "Hit w1?");
-TEST_EQUAL_PTR(w1.find(0,0), &w1, "Hit w1?");
-TEST_EQUAL_PTR(w1.find(11,11), &w2, "Hit w2?");
-TEST_EQUAL_PTR(w1.find(22,22), &w3, "Hit w3?");
-
-TEST_END;
-
-#endif/*TEST_WIDGET*/
+} // GUI::
diff --git a/plugingui/widget.h b/plugingui/widget.h
index 47c374e..13725f0 100644
--- a/plugingui/widget.h
+++ b/plugingui/widget.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_WIDGET_H__
-#define __DRUMGIZMO_WIDGET_H__
+#pragma once
#include "guievent.h"
#include "pixelbuffer.h"
+#include "notifier.h"
#include <vector>
@@ -36,7 +36,7 @@ namespace GUI {
class Window;
-class Widget {
+class Widget : public Listener {
public:
Widget(Widget *parent);
virtual ~Widget();
@@ -94,6 +94,4 @@ private:
bool _visible;
};
-};
-
-#endif/*__DRUMGIZMO_WIDGET_H__*/
+} // GUI::