From 0034f7ddeef9a2564f0ae51a7c815a6652a0f9e0 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Mon, 21 Dec 2015 13:59:37 +0100 Subject: New DGWindow class for the actual UI implementation. PluginGUI is now just handles events and acts as an interface. testcode. --- plugingui/Makefile.am | 1 + plugingui/Makefile.am.plugingui | 1 + plugingui/dgwindow.cc | 339 +++++++++++++++++++++++ plugingui/dgwindow.h | 90 +++++++ plugingui/plugingui.cc | 582 ++++++++++------------------------------ plugingui/plugingui.h | 77 ++---- plugingui/testmain.cc | 75 ++++++ 7 files changed, 675 insertions(+), 490 deletions(-) create mode 100644 plugingui/dgwindow.cc create mode 100644 plugingui/dgwindow.h create mode 100644 plugingui/testmain.cc (limited to 'plugingui') diff --git a/plugingui/Makefile.am b/plugingui/Makefile.am index e93ffa0..bc90f09 100644 --- a/plugingui/Makefile.am +++ b/plugingui/Makefile.am @@ -11,6 +11,7 @@ plugingui_CXXFLAGS = $(SNDFILE_CXXFLAGS) $(PTHREAD_CFLAGS) $(EXPAT_CFLAGS) \ plugingui_CFLAGS = $(plugingui_CXXFLAGS) plugingui_SOURCES = \ + testmain.cc \ $(PLUGIN_GUI_SOURCES) \ $(top_srcdir)/src/configfile.cc \ $(top_srcdir)/src/thread.cc \ diff --git a/plugingui/Makefile.am.plugingui b/plugingui/Makefile.am.plugingui index e337ed6..f4c0a55 100644 --- a/plugingui/Makefile.am.plugingui +++ b/plugingui/Makefile.am.plugingui @@ -1,6 +1,7 @@ PLUGIN_GUI_SOURCES = \ $(top_srcdir)/hugin/hugin.c \ $(top_srcdir)/hugin/hugin_syslog.c \ + $(top_srcdir)/plugingui/dgwindow.cc \ $(top_srcdir)/plugingui/plugingui.cc \ $(top_srcdir)/plugingui/label.cc \ $(top_srcdir)/plugingui/eventhandler.cc \ diff --git a/plugingui/dgwindow.cc b/plugingui/dgwindow.cc new file mode 100644 index 0000000..36d106c --- /dev/null +++ b/plugingui/dgwindow.cc @@ -0,0 +1,339 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * dgwindow.cc + * + * Mon Nov 23 20:30:45 CET 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. + */ +#include "dgwindow.h" + +#include "knob.h" +#include "verticalline.h" +#include "../version.h" + +#include "messagehandler.h" +#include "pluginconfig.h" + +namespace GUI { + +class LabeledControl : public Widget +{ +public: + LabeledControl(Widget* parent, const std::string& name) + : Widget(parent) + { + layout.setResizeChildren(false); + layout.setHAlignment(HAlignment::center); + + caption.setText(name); + caption.resize(100, 20); + caption.setAlignment(TextAlignment::center); + layout.addItem(&caption); + } + + void setControl(Widget* control) + { + layout.addItem(control); + } + + VBoxLayout layout{this}; + + Label caption{this}; +}; + +class File : public Widget +{ +public: + File(Widget* parent) + : Widget(parent) + { + layout.setResizeChildren(false); + layout.setVAlignment(VAlignment::center); + + lineedit.resize(243, 29); + layout.addItem(&lineedit); + + browseButton.setText("Browse..."); + browseButton.resize(85, 41); + layout.addItem(&browseButton); + } + + HBoxLayout layout{this}; + + LineEdit lineedit{this}; + Button browseButton{this}; +}; + +class HumanizeControls : public Widget +{ +public: + HumanizeControls(Widget* parent) + : Widget(parent) + { + layout.setResizeChildren(false); + layout.setVAlignment(VAlignment::center); + + velocity.resize(80, 80); + velocityCheck.resize(59, 38); + velocity.setControl(&velocityCheck); + layout.addItem(&velocity); + + attack.resize(80, 80); + attackKnob.resize(60, 60); + attack.setControl(&attackKnob); + layout.addItem(&attack); + + falloff.resize(80, 80); + falloffKnob.resize(60, 60); + falloff.setControl(&falloffKnob); + layout.addItem(&falloff); + } + + HBoxLayout layout{this}; + + LabeledControl velocity{this, "Humanizer"}; + LabeledControl attack{this, "Attack"}; + LabeledControl falloff{this, "Release"}; + + CheckBox velocityCheck{&velocity}; + Knob attackKnob{&attack}; + Knob falloffKnob{&falloff}; +}; + +DGWindow::DGWindow(MessageHandler& messageHandler, Config& config) + : messageHandler(messageHandler) + , config(config) +{ + + int vlineSpacing = 16; + + setFixedSize(370, 330); + setCaption("DrumGizmo v" VERSION); + + layout.setResizeChildren(false); + layout.setHAlignment(HAlignment::center); +// layout.setSpacing(0); + + auto headerCaption = new Label(this); + headerCaption->setText("DrumGizmo"); + headerCaption->setAlignment(TextAlignment::center); + headerCaption->resize(width() - 40, 32); + layout.addItem(headerCaption); + + auto headerLine = new VerticalLine(this); + headerLine->resize(width() - 40, vlineSpacing); + layout.addItem(headerLine); + + auto drumkitCaption = new Label(this); + drumkitCaption->setText("Drumkit file:"); + drumkitCaption->resize(width() - 40, 15); + layout.addItem(drumkitCaption); + + auto drumkitFile = new File(this); + drumkitFile->resize(width() - 40, 37); + lineedit = &drumkitFile->lineedit; + CONNECT(&drumkitFile->browseButton, clickNotifier, + this, &DGWindow::kitBrowseClick); + layout.addItem(drumkitFile); + + drumkitFileProgress = new ProgressBar(this); + drumkitFileProgress->resize(width() - 40, 11); + layout.addItem(drumkitFileProgress); + + VerticalLine *l = new VerticalLine(this); + l->resize(width() - 40, vlineSpacing); + layout.addItem(l); + + auto midimapCaption = new Label(this); + midimapCaption->setText("Midimap file:"); + midimapCaption->resize(width() - 40, 15); + layout.addItem(midimapCaption); + + auto midimapFile = new File(this); + midimapFile->resize(width() - 40, 37); + lineedit2 = &midimapFile->lineedit; + CONNECT(&midimapFile->browseButton, clickNotifier, + this, &DGWindow::midimapBrowseClick); + layout.addItem(midimapFile); + + midimapFileProgress = new ProgressBar(this); + midimapFileProgress->resize(width() - 40, 11); + layout.addItem(midimapFileProgress); + + VerticalLine *l2 = new VerticalLine(this); + l2->resize(width() - 40, vlineSpacing); + layout.addItem(l2); + + HumanizeControls* humanizeControls = new HumanizeControls(this); + humanizeControls->resize(80 * 3, 80); + layout.addItem(humanizeControls); + CONNECT(&humanizeControls->velocityCheck, stateChangedNotifier, + this, &DGWindow::velocityCheckClick); + + CONNECT(&humanizeControls->attackKnob, valueChangedNotifier, + this, &DGWindow::attackValueChanged); + + CONNECT(&humanizeControls->falloffKnob, valueChangedNotifier, + this, &DGWindow::falloffValueChanged); + + VerticalLine *l3 = new VerticalLine(this); + l3->resize(width() - 40, vlineSpacing); + layout.addItem(l3); + + Label *lbl_version = new Label(this); + lbl_version->setText(".::. v" VERSION " .::. http://www.drumgizmo.org .::. GPLv3 .::."); + lbl_version->resize(width(), 20); + lbl_version->setAlignment(TextAlignment::center); + layout.addItem(lbl_version); + + // Create file browser + fileBrowser = new FileBrowser(this); + fileBrowser->move(0, 0); + fileBrowser->resize(this->width() - 1, this->height() - 1); + fileBrowser->hide(); +} + +void DGWindow::repaintEvent(RepaintEvent* repaintEvent) +{ + if(!visible()) + { + return; + } + + Painter p(*this); + p.drawImageStretched(0,0, back, width(), height()); + p.drawImage(width() - logo.width(), height() - logo.height(), logo); +} + +void DGWindow::attackValueChanged(float value) +{ + ChangeSettingMessage *msg = + new ChangeSettingMessage(ChangeSettingMessage::velocity_modifier_weight, + value); + + messageHandler.sendMessage(MSGRCV_ENGINE, msg); + +#ifdef STANDALONE + int i = value * 4; + switch(i) { + case 0: drumkitFileProgress->setState(ProgressBarState::Off); break; + case 1: drumkitFileProgress->setState(ProgressBarState::Blue); break; + case 2: drumkitFileProgress->setState(ProgressBarState::Green); break; + case 3: drumkitFileProgress->setState(ProgressBarState::Red); break; + default: break; + } +#endif +} + +void DGWindow::falloffValueChanged(float value) +{ + ChangeSettingMessage *msg = + new ChangeSettingMessage(ChangeSettingMessage::velocity_modifier_falloff, + value); + messageHandler.sendMessage(MSGRCV_ENGINE, msg); + +#ifdef STANDALONE + drumkitFileProgress->setProgress(value); +#endif +} + +void DGWindow::velocityCheckClick(bool checked) +{ + ChangeSettingMessage *msg = + new ChangeSettingMessage(ChangeSettingMessage::enable_velocity_modifier, + checked); + messageHandler.sendMessage(MSGRCV_ENGINE, msg); +} + +void DGWindow::kitBrowseClick() +{ + std::string path = lineedit->text(); + if(path == "") + { + path = config.lastkit; + } + + if(path == "") + { + path = lineedit2->text(); + } + + fileBrowser->setPath(path); + CONNECT(fileBrowser, fileSelectNotifier, this, &DGWindow::selectKitFile); + fileBrowser->show(); +} + +void DGWindow::midimapBrowseClick() +{ + std::string path = lineedit2->text(); + if(path == "") + { + path = config.lastmidimap; + } + + if(path == "") + { + path = lineedit->text(); + } + + fileBrowser->setPath(path); + CONNECT(fileBrowser, fileSelectNotifier, this, &DGWindow::selectMapFile); + fileBrowser->show(); +} + +void DGWindow::selectKitFile(const std::string& filename) +{ + lineedit->setText(filename); + + fileBrowser->hide(); + + std::string drumkit = lineedit->text(); + + config.lastkit = drumkit; + config.save(); + + drumkitFileProgress->setProgress(0); + drumkitFileProgress->setState(ProgressBarState::Blue); + + LoadDrumKitMessage *msg = new LoadDrumKitMessage(); + msg->drumkitfile = drumkit; + + messageHandler.sendMessage(MSGRCV_ENGINE, msg); +} + +void DGWindow::selectMapFile(const std::string& filename) +{ + lineedit2->setText(filename); + fileBrowser->hide(); + + std::string midimap = lineedit2->text(); + + config.lastmidimap = midimap; + config.save(); + + LoadMidimapMessage *msg = new LoadMidimapMessage(); + msg->midimapfile = midimap; + messageHandler.sendMessage(MSGRCV_ENGINE, msg); +} + + +} // GUI:: diff --git a/plugingui/dgwindow.h b/plugingui/dgwindow.h new file mode 100644 index 0000000..6eb4226 --- /dev/null +++ b/plugingui/dgwindow.h @@ -0,0 +1,90 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * dgwindow.h + * + * Mon Nov 23 20:30:45 CET 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 "window.h" + +#include "label.h" +#include "lineedit.h" +#include "checkbox.h" +#include "button.h" +#include "knob.h" +#include "progressbar.h" +#include "filebrowser.h" +#include "layout.h" + +class MessageHandler; + +namespace GUI { + +class Config; +class Header; +class File; + +class DGWindow : public Window { +public: + DGWindow(MessageHandler& messageHandler, Config& config); + + Header* header; + + File* drumkitFile; + LineEdit* lineedit; + ProgressBar* drumkitFileProgress; + + File* midimapFile; + LineEdit* lineedit2; + ProgressBar* midimapFileProgress; + + // Humanized velocity controls: + CheckBox* velocityCheck; + Knob* attackKnob; + Knob* falloffKnob; + FileBrowser* fileBrowser; + +protected: + // From Widget: + void repaintEvent(RepaintEvent* repaintEvent) override; + +private: + void attackValueChanged(float value); + void falloffValueChanged(float value); + void velocityCheckClick(bool checked); + void kitBrowseClick(); + void midimapBrowseClick(); + void selectKitFile(const std::string& filename); + void selectMapFile(const std::string& filename); + + MessageHandler& messageHandler; + Config& config; + + VBoxLayout layout{this}; + + Image back{":bg.png"}; + Image logo{":logo.png"}; +}; + +} // GUI:: diff --git a/plugingui/plugingui.cc b/plugingui/plugingui.cc index 5de74fb..a56818c 100644 --- a/plugingui/plugingui.cc +++ b/plugingui/plugingui.cc @@ -27,522 +27,222 @@ #include "plugingui.h" #include -#include - -#include "knob.h" -#include "verticalline.h" -#include "../version.h" #include "pluginconfig.h" #include "messagehandler.h" namespace GUI { -/* -void closeClick(void *ptr) -{ - PluginGUI *gui = (PluginGUI*)ptr; - if(gui->windowClosedHandler) gui->windowClosedHandler(gui->windowClosedPtr); -} -*/ - PluginGUI::PluginGUI() - : MessageReceiver(MSGRCV_UI) - , initialised(false) - , sem("plugingui") + : MessageReceiver(MSGRCV_UI) { - windowClosedHandler = NULL; - changeMidimapHandler = NULL; - - window = NULL; - - running = true; - closing = false; - #ifdef USE_THREAD - run(); + run(); #else - init(); + init(); #endif/*USE_THREAD*/ - sem.wait(); + sem.wait(); } PluginGUI::~PluginGUI() { - stopThread(); -} - -void PluginGUI::stopThread() -{ - if(running) { - running = false; - wait_stop(); - } + stopThread(); } - void PluginGUI::handleMessage(Message *msg) { - Painter p(*window);// Make sure we only redraw buffer one time. - - switch(msg->type()) { - case Message::LoadStatus: - { - LoadStatusMessage *ls = (LoadStatusMessage*)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(ProgressBarState::Green); - } - } - break; - case Message::LoadStatusMidimap: - { - LoadStatusMessageMidimap *ls = (LoadStatusMessageMidimap*)msg; - progress2->setProgress(1); - if(ls->success) { - progress2->setState(ProgressBarState::Green); - } else { - progress2->setState(ProgressBarState::Red); - } - } - break; - case Message::EngineSettingsMessage: - { - EngineSettingsMessage *settings = (EngineSettingsMessage *)msg; - lineedit->setText(settings->drumkitfile); - if(settings->drumkit_loaded) { - progress->setProgress(1); - progress->setState(ProgressBarState::Green); - } else { - progress->setProgress(0); - progress->setState(ProgressBarState::Blue); - } - lineedit2->setText(settings->midimapfile); - if(settings->midimap_loaded) { - progress2->setProgress(1); - progress2->setState(ProgressBarState::Green); - } else { - progress2->setProgress(0); - progress2->setState(ProgressBarState::Blue); - } - velocityCheck->setChecked(settings->enable_velocity_modifier); - attackKnob->setValue(settings->velocity_modifier_weight); - falloffKnob->setValue(settings->velocity_modifier_falloff); - - } - default: - break; - } + Painter p(*window);// Make sure we only redraw buffer once (set refcount to 1) + + switch(msg->type()) { + case Message::LoadStatus: + { + LoadStatusMessage *ls = (LoadStatusMessage*)msg; + window->drumkitFileProgress->setProgress((float)ls->numer_of_files_loaded / + (float)ls->number_of_files); + if(ls->numer_of_files_loaded == ls->number_of_files) + { + window->drumkitFileProgress->setState(ProgressBarState::Green); + } + } + break; + case Message::LoadStatusMidimap: + { + LoadStatusMessageMidimap *ls = (LoadStatusMessageMidimap*)msg; + window->midimapFileProgress->setProgress(1); + if(ls->success) + { + window->midimapFileProgress->setState(ProgressBarState::Green); + } + else + { + window->midimapFileProgress->setState(ProgressBarState::Red); + } + } + break; + case Message::EngineSettingsMessage: + { + EngineSettingsMessage *settings = (EngineSettingsMessage *)msg; + window->lineedit->setText(settings->drumkitfile); + if(settings->drumkit_loaded) + { + window->drumkitFileProgress->setProgress(1); + window->drumkitFileProgress->setState(ProgressBarState::Green); + } + else + { + window->drumkitFileProgress->setProgress(0); + window->drumkitFileProgress->setState(ProgressBarState::Blue); + } + window->lineedit2->setText(settings->midimapfile); + if(settings->midimap_loaded) + { + window->midimapFileProgress->setProgress(1); + window->midimapFileProgress->setState(ProgressBarState::Green); + } + else + { + window->midimapFileProgress->setProgress(0); + window->midimapFileProgress->setState(ProgressBarState::Blue); + } + window->velocityCheck->setChecked(settings->enable_velocity_modifier); + window->attackKnob->setValue(settings->velocity_modifier_weight); + window->falloffKnob->setValue(settings->velocity_modifier_falloff); + } + default: + break; + } } void PluginGUI::thread_main() { - init(); + init(); - { // Request all engine settings - EngineSettingsMessage *msg = new EngineSettingsMessage(); - msghandler.sendMessage(MSGRCV_ENGINE, msg); - } + { // Request all engine settings + EngineSettingsMessage *msg = new EngineSettingsMessage(); + msghandler.sendMessage(MSGRCV_ENGINE, msg); + } - while(running) { + while(processEvents()) + { #ifdef WIN32 - SleepEx(50, FALSE); + SleepEx(50, FALSE); #else - usleep(50000); + usleep(50000); #endif/*WIN32*/ + } - // DEBUG(gui, "loop"); - - window->eventHandler()->processEvents(); - handleMessages(); - -#ifdef STANDALONE - if(closing) { - if(windowClosedHandler) windowClosedHandler(windowClosedPtr); - break; - } -#endif - } - - deinit(); -} - -void PluginGUI::deinit() -{ - if(config) { - config->save(); - delete config; - } - if(window) delete window; -} - -void PluginGUI::closeEventHandler() -{ - closing = true; + deinit(); } -void PluginGUI::selectKitFile(const std::string& filename) +bool PluginGUI::processEvents() { - lineedit->setText(filename); - - fileBrowser->hide(); - - std::string drumkit = lineedit->text(); - - config->lastkit = drumkit; - config->save(); + if(!initialised) + { + return running; + } - progress->setProgress(0); - progress->setState(ProgressBarState::Blue); + window->eventHandler()->processEvents(); + handleMessages(); - LoadDrumKitMessage *msg = new LoadDrumKitMessage(); - msg->drumkitfile = drumkit; + if(closing) + { + closeNotifier(); + closing = false; + return false; + } - msghandler.sendMessage(MSGRCV_ENGINE, msg); + return running; } -void PluginGUI::selectMapFile(const std::string& filename) +void PluginGUI::stopThread() { - lineedit2->setText(filename); - fileBrowser->hide(); - - std::string midimap = lineedit2->text(); - - config->lastmidimap = midimap; - config->save(); - - LoadMidimapMessage *msg = new LoadMidimapMessage(); - msg->midimapfile = midimap; - msghandler.sendMessage(MSGRCV_ENGINE, msg); - - /* - if(gui->changeMidimapHandler) - gui->changeMidimapHandler(gui->changeMidimapPtr, midimap.c_str()); - gui->progress2->setState(ProgressBarState::Green); - */ + if(running) + { + running = false; + wait_stop(); + } } void PluginGUI::init() { - DEBUG(gui, "init"); - - config = new Config(); - config->load(); - - window = new Window(); - auto eventHandler = window->eventHandler(); - CONNECT(eventHandler, closeNotifier, this, &PluginGUI::closeEventHandler); - - window->setFixedSize(370, 330); - window->setCaption("DrumGizmo v" VERSION); - - Label *lbl_title = new Label(window); - lbl_title->setText("DrumGizmo"); - lbl_title->move(127, 7); - lbl_title->resize(200, 20); - - VerticalLine *l1 = new VerticalLine(window); - l1->move(20, 30); - l1->resize(window->width() - 40, 2); - -#define OFFSET1 17 -#define OFFSET2 38 -#define OFFSET3 20 - -#define XOFFSET 20 - // Drumkit file - { - int y = 37; - Label *lbl = new Label(window); - lbl->setText("Drumkit file:"); - lbl->move(XOFFSET - 4, y); - lbl->resize(100, 20); - - y += OFFSET1; - lineedit = new LineEdit(window); - lineedit->move(XOFFSET, y); - lineedit->resize(243, 29); - lineedit->setReadOnly(true); - - 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); - CONNECT(btn_brw, clickNotifier, this, &PluginGUI::kitBrowseClick); - - y += OFFSET2; - progress = new ProgressBar(window); - progress->move(XOFFSET, y); - progress->resize(window->width() - 2*XOFFSET, 11); - - y += OFFSET3; - VerticalLine *l = new VerticalLine(window); - l->move(XOFFSET, y); - l->resize(window->width() - 2*XOFFSET, 2); - } - - // Midimap file - { - int y = 120; - lbl2 = new Label(window); - lbl2->setText("Midimap file:"); - lbl2->move(XOFFSET - 4, y); - lbl2->resize(100, 20); - - y += OFFSET1; - lineedit2 = new LineEdit(window); - lineedit2->move(XOFFSET, y); - lineedit2->resize(243, 29); - lineedit2->setReadOnly(true); - - Button *btn_brw = new Button(window); - btn_brw->setText("Browse..."); - btn_brw->move(266, y - 6 + 4); - btn_brw->resize(85, 35 + 6 - 4); - CONNECT(btn_brw, clickNotifier, this, &PluginGUI::midimapBrowseClick); - - y += OFFSET2; - progress2 = new ProgressBar(window); - progress2->move(XOFFSET, y); - progress2->resize(window->width() - 2*XOFFSET, 11); - - y += OFFSET3; - VerticalLine *l = new VerticalLine(window); - l->move(XOFFSET, y); - l->resize(window->width() - 2*XOFFSET, 2); - } - - { - int y = 203; -#define OFFSET4 21 - - // Enable Velocity - Label *lbl_velocity = new Label(window); - lbl_velocity->resize(78 ,20); - lbl_velocity->move(16, y); - lbl_velocity->setText("Humanizer"); - - velocityCheck = new CheckBox(window); - //velocityCheck->setText("Enable Velocity Modifier"); - velocityCheck->move(26, y + OFFSET4); - velocityCheck->resize(59,38); - CONNECT(velocityCheck, stateChangedNotifier, this, &PluginGUI::velocityCheckClick); - - // Velocity Weight Modifier: - { - Label *lbl_weight = new Label(window); - lbl_weight->setText("Attack"); - lbl_weight->move(107, y); - lbl_weight->resize(100, 20); - - attackKnob = new Knob(window); - attackKnob->move(109, y + OFFSET4 - 4); - attackKnob->resize(57, 57); - CONNECT(attackKnob, valueChangedNotifier, this, &PluginGUI::attackValueChanged); - } - - // Velocity Falloff Modifier: - { - Label *lbl_falloff = new Label(window); - lbl_falloff->setText("Release"); - lbl_falloff->move(202 - 17 - 7, y); - lbl_falloff->resize(100, 20); - - falloffKnob = new Knob(window); - falloffKnob->move(202 - 13 - 5, y + OFFSET4 - 4); - falloffKnob->resize(57, 57); - CONNECT(falloffKnob, valueChangedNotifier, this, &PluginGUI::falloffValueChanged); - } - } - - VerticalLine *l2 = new VerticalLine(window); - l2->move(20, 310 - 15 - 9); - l2->resize(window->width() - 40, 2); - - 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); - /* - { - ComboBox *cmb = new ComboBox(window); - cmb->addItem("Foo", "Bar"); - cmb->addItem("Hello", "World"); - cmb->move(10,10); - cmb->resize(70, 30); - } - */ - // Create file browser - fileBrowser = new FileBrowser(window); - fileBrowser->move(0, 0); - fileBrowser->resize(window->width() - 1, window->height() - 1); - fileBrowser->hide(); - - // Enable quit button -// Button *btn_quit = new Button(window); -// btn_quit->setText("Quit"); -// btn_quit->move(50,280); -// btn_quit->resize(80,80); -// btn_quit->registerClickHandler(quit, this); - - window->show(); - - sem.post(); - - initialised = true; -} + DEBUG(gui, "init"); -void PluginGUI::show() -{ - while(!initialised) usleep(10000); - - if(!window) init(); + config = new Config(); + config->load(); - window->show(); -} + window = new DGWindow(msghandler, *config); -void PluginGUI::hide() -{ - while(!initialised) usleep(10000); + auto eventHandler = window->eventHandler(); + CONNECT(eventHandler, closeNotifier, this, &PluginGUI::closeEventHandler); - if(window) window->hide(); -} - -void PluginGUI::processEvents() -{ - if(!initialised) return; - - if(closing) { - if(windowClosedHandler) windowClosedHandler(windowClosedPtr); - closing = false; - } - -#ifndef USE_THREAD - window->eventHandler()->processEvents(window); -#endif/*USE_THREAD*/ -} + window->show(); -void PluginGUI::setWindowClosedCallback(void (*handler)(void *), void *ptr) -{ - windowClosedHandler = handler; - windowClosedPtr = ptr; -} + sem.post(); -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(ProgressBarState::Off); break; - case 1: progress->setState(ProgressBarState::Blue); break; - case 2: progress->setState(ProgressBarState::Green); break; - case 3: progress->setState(ProgressBarState::Red); break; - default: break; - } -#endif + initialised = true; } -void PluginGUI::falloffValueChanged(float value) +void PluginGUI::deinit() { - ChangeSettingMessage *msg = - new ChangeSettingMessage(ChangeSettingMessage::velocity_modifier_falloff, - value); - msghandler.sendMessage(MSGRCV_ENGINE, msg); - -#ifdef STANDALONE - progress->setProgress(value); -#endif -} + if(config) + { + config->save(); + delete config; + } -void PluginGUI::velocityCheckClick(bool checked) -{ - ChangeSettingMessage *msg = - new ChangeSettingMessage(ChangeSettingMessage::enable_velocity_modifier, - checked); - msghandler.sendMessage(MSGRCV_ENGINE, msg); + if(window) + { + delete window; + } } -void PluginGUI::kitBrowseClick() +void PluginGUI::show() { - std::string path = lineedit->text(); - if(path == "") + while(!initialised) { - path = config->lastkit; + usleep(10000); } - if(path == "") + if(!window) { - path = lineedit2->text(); + init(); } - fileBrowser->setPath(path); - CONNECT(fileBrowser, fileSelectNotifier, this, &PluginGUI::selectKitFile); - fileBrowser->show(); + if(window) + { + window->show(); + } } -void PluginGUI::midimapBrowseClick() +void PluginGUI::hide() { - std::string path = lineedit2->text(); - if(path == "") + while(!initialised) { - path = config->lastmidimap; + usleep(10000); } - if(path == "") + if(window) { - path = lineedit->text(); + window->hide(); } - - fileBrowser->setPath(path); - CONNECT(fileBrowser, fileSelectNotifier, this, &PluginGUI::selectMapFile); - fileBrowser->show(); } -} // GUI:: - -#ifdef STANDALONE - -class Engine : public MessageHandler { -public: - void handleMessage(Message *msg) {} -}; - -void stop(void *ptr) +void PluginGUI::setWindowClosedCallback(void (*handler)(void *), void* ptr) { - DEBUG(stop, "Stopping...\n"); - bool *running = (bool*)ptr; - *running = false; + windowClosedHandler = handler; + windowClosedPtr = ptr; } -int main() +void PluginGUI::closeEventHandler() { - INFO(example, "We are up and running"); - - bool running = true; - - GUI::PluginGUI gui; - gui.setWindowClosedCallback(stop, &running); - - // gui.show(); - - while(running) { -#ifdef WIN32 - SleepEx(1000, FALSE); -#else - sleep(1); -#endif - } - - return 0; + closing = true; + closeNotifier(); + // Call old-style notifier if one is registered. + if(windowClosedHandler) + { + windowClosedHandler(windowClosedPtr); + } } -#endif/*STANDALONE*/ +} // GUI:: diff --git a/plugingui/plugingui.h b/plugingui/plugingui.h index 5e617dc..bdb7da5 100644 --- a/plugingui/plugingui.h +++ b/plugingui/plugingui.h @@ -26,18 +26,11 @@ */ #pragma once -#include "window.h" +#include "dgwindow.h" #include "eventhandler.h" -#include "label.h" -#include "lineedit.h" -#include "checkbox.h" -#include "button.h" -#include "knob.h" -#include "progressbar.h" #include "pluginconfig.h" -#include "filebrowser.h" #include "thread.h" #include "semaphore.h" @@ -49,63 +42,49 @@ namespace GUI { class PluginGUI : public Thread, public MessageReceiver, public Listener { public: - PluginGUI(); - virtual ~PluginGUI(); + PluginGUI(); + virtual ~PluginGUI(); - void thread_main(); - void stopThread(); + void thread_main(); - void init(); - void deinit(); + //! Process all events and messages in queue + //! \return true if not closing, returns false if closing. + bool processEvents(); - void show(); - void hide(); - void processEvents(); - void setWindowClosedCallback(void (*handler)(void *), void *ptr); + void stopThread(); - void handleMessage(Message *msg); + void init(); + void deinit(); - Window *window; - EventHandler *eventhandler; + void show(); + void hide(); - Label *lbl; - LineEdit *lineedit; - ProgressBar *progress; - Label *lbl2; - LineEdit *lineedit2; - ProgressBar *progress2; + void handleMessage(Message* msg); - Config *config; + DGWindow* window{nullptr}; + EventHandler* eventhandler; - void (*windowClosedHandler)(void *); - void *windowClosedPtr; - void (*changeMidimapHandler)(void *, const char *); - void *changeMidimapPtr; + Config* config; + + Notifier<> closeNotifier; + + // Support old interface a little while longer.. + void setWindowClosedCallback(void (*handler)(void*), void* ptr); private: - void attackValueChanged(float value); - void falloffValueChanged(float value); - void velocityCheckClick(bool checked); - void kitBrowseClick(); - void midimapBrowseClick(); void closeEventHandler(); - void selectKitFile(const std::string& filename); - void selectMapFile(const std::string& filename); - // Humanized velocity controls: - CheckBox* velocityCheck; - Knob* attackKnob; - Knob* falloffKnob; - FileBrowser* fileBrowser; + volatile bool running{true}; + volatile bool closing{false}; + volatile bool initialised{false}; - volatile bool running; - volatile bool closing; - volatile bool initialised; + Semaphore sem{"plugingui"}; - Semaphore sem; + // For the old-style notifier. + void (*windowClosedHandler)(void *){nullptr}; + void *windowClosedPtr{nullptr}; }; } // GUI:: - diff --git a/plugingui/testmain.cc b/plugingui/testmain.cc new file mode 100644 index 0000000..7b1bfec --- /dev/null +++ b/plugingui/testmain.cc @@ -0,0 +1,75 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * testmain.cc + * + * Sun Nov 22 20:06:42 CET 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. + */ +#include "plugingui.h" + +#include + +// Dummy Engine class. +class Engine : public MessageHandler { +public: + void handleMessage(Message *msg) {} +}; + +class TestMain : public GUI::Listener { +public: + TestMain() + { + CONNECT(&gui, closeNotifier, this, &TestMain::stop); + } + + void stop() + { + DEBUG(stop, "Stopping...\n"); + running = false; + } + + void run() + { + while(running) + { +#ifdef WIN32 + SleepEx(1000, FALSE); +#else + sleep(1); +#endif + } + } + + bool running = true; + + GUI::PluginGUI gui; +}; + +int main() +{ + INFO(example, "We are up and running"); + + TestMain testMain; + testMain.run(); + + return 0; +} -- cgit v1.2.3