From c2997b9b1a5b831e76b1779aa957f2312a6e5089 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Wed, 23 Mar 2016 22:38:44 +0100 Subject: Settings. --- plugingui/dgwindow.cc | 31 +++++++++-------- plugingui/dgwindow.h | 7 +++- plugingui/plugingui.cc | 90 ++++++++++++++++++++++++++++++++++++++++++++++++-- plugingui/plugingui.h | 24 +++++++++++--- 4 files changed, 131 insertions(+), 21 deletions(-) (limited to 'plugingui') diff --git a/plugingui/dgwindow.cc b/plugingui/dgwindow.cc index 86a985d..25cbdf0 100644 --- a/plugingui/dgwindow.cc +++ b/plugingui/dgwindow.cc @@ -120,10 +120,11 @@ public: }; DGWindow::DGWindow(void* native_window, MessageHandler& messageHandler, - Config& config) + Config& config, Settings& settings) : Window(native_window) , messageHandler(messageHandler) , config(config) + , settings(settings) { int vlineSpacing = 16; @@ -233,11 +234,12 @@ void DGWindow::repaintEvent(RepaintEvent* repaintEvent) void DGWindow::attackValueChanged(float value) { - ChangeSettingMessage *msg = - new ChangeSettingMessage(ChangeSettingMessage::velocity_modifier_weight, - value); + //ChangeSettingMessage *msg = + // new ChangeSettingMessage(ChangeSettingMessage::velocity_modifier_weight, + // value); + //messageHandler.sendMessage(MSGRCV_ENGINE, msg); - messageHandler.sendMessage(MSGRCV_ENGINE, msg); + settings.velocity_modifier_weight.store(value); #ifdef STANDALONE int i = value * 4; @@ -253,10 +255,12 @@ void DGWindow::attackValueChanged(float value) void DGWindow::falloffValueChanged(float value) { - ChangeSettingMessage *msg = - new ChangeSettingMessage(ChangeSettingMessage::velocity_modifier_falloff, - value); - messageHandler.sendMessage(MSGRCV_ENGINE, msg); + //ChangeSettingMessage *msg = + // new ChangeSettingMessage(ChangeSettingMessage::velocity_modifier_falloff, + // value); + //messageHandler.sendMessage(MSGRCV_ENGINE, msg); + + settings.velocity_modifier_falloff.store(value); #ifdef STANDALONE drumkitFileProgress->setProgress(value); @@ -265,10 +269,11 @@ void DGWindow::falloffValueChanged(float value) void DGWindow::velocityCheckClick(bool checked) { - ChangeSettingMessage *msg = - new ChangeSettingMessage(ChangeSettingMessage::enable_velocity_modifier, - checked); - messageHandler.sendMessage(MSGRCV_ENGINE, msg); +// ChangeSettingMessage *msg = +// new ChangeSettingMessage(ChangeSettingMessage::enable_velocity_modifier, +// checked); +// messageHandler.sendMessage(MSGRCV_ENGINE, msg); + settings.enable_velocity_modifier.store(checked); } void DGWindow::kitBrowseClick() diff --git a/plugingui/dgwindow.h b/plugingui/dgwindow.h index 605e87a..c4fbeab 100644 --- a/plugingui/dgwindow.h +++ b/plugingui/dgwindow.h @@ -37,6 +37,8 @@ #include "filebrowser.h" #include "layout.h" +#include + class MessageHandler; namespace GUI { @@ -47,7 +49,8 @@ class File; class DGWindow : public Window { public: - DGWindow(void* native_window, MessageHandler& messageHandler, Config& config); + DGWindow(void* native_window, MessageHandler& messageHandler, Config& config, + Settings& settings); Header* header; @@ -85,6 +88,8 @@ private: Image back{":bg.png"}; Image logo{":logo.png"}; + + Settings& settings; }; } // GUI:: diff --git a/plugingui/plugingui.cc b/plugingui/plugingui.cc index e34c471..9bac007 100644 --- a/plugingui/plugingui.cc +++ b/plugingui/plugingui.cc @@ -31,6 +31,8 @@ #include "pluginconfig.h" #include "messagehandler.h" +#include + namespace GUI { PluginGUI::PluginGUI(void* native_window) @@ -116,7 +118,68 @@ bool PluginGUI::processEvents() } window->eventHandler()->processEvents(); - handleMessages(); + //handleMessages(); + + static bool foo = false; + static int t = 0; + if(t != time(nullptr)) + { + t = time(nullptr); + foo = !foo; + float v = settings.velocity_modifier_falloff.load(); + v += 0.1f; + settings.velocity_modifier_falloff.store(v); + } + + Painter p(*window); + + // Run through all settings one at a time propagate changes to the UI. + if(getter.enable_velocity_modifier.hasChanged()) + { + enable_velocity_modifier_notifier(getter.enable_velocity_modifier.getValue()); + } + + if(getter.velocity_modifier_falloff.hasChanged()) + { + velocity_modifier_falloff_notifier(getter.velocity_modifier_falloff.getValue()); + } + + if(getter.velocity_modifier_weight.hasChanged()) + { + velocity_modifier_weight_notifier(getter.velocity_modifier_weight.getValue()); + } + + if(getter.enable_velocity_randomiser.hasChanged()) + { + enable_velocity_randomiser_notifier(getter.enable_velocity_randomiser.getValue()); + } + + if(getter.velocity_randomiser_weight.hasChanged()) + { + velocity_randomiser_weight_notifier(getter.velocity_randomiser_weight.getValue()); + } + + if(getter.samplerate.hasChanged()) + { + samplerate_notifier(getter.samplerate.getValue()); + } + + if(getter.enable_resampling.hasChanged()) + { + enable_resampling_notifier(getter.enable_resampling.getValue()); + } + + if(getter.number_of_files.hasChanged() || + getter.number_of_files_loaded.hasChanged()) + { + drumkit_file_progress_notifier((float)getter.number_of_files_loaded.getValue() / + (float)getter.number_of_files.getValue()); + } + + //if(getter.current_file.hasChanged()) + //{ + // current_file_notifier(getter.current_file.getValue()); + //} if(closing) { @@ -135,7 +198,30 @@ void PluginGUI::init() config = new Config(); config->load(); - window = new DGWindow(native_window, msghandler, *config); + window = new DGWindow(native_window, msghandler, *config, settings); + + CONNECT(this, enable_velocity_modifier_notifier, + window->velocityCheck, &CheckBox::setChecked); + + CONNECT(this, velocity_modifier_falloff_notifier, + window->falloffKnob, &Knob::setValue); + CONNECT(this, velocity_modifier_weight_notifier, + window->attackKnob, &Knob::setValue); + + + //CONNECT(this, enable_velocity_randomiser_notifier, + // window->velocityCheck, &CheckBox::setChecked); + //CONNECT(this, velocity_randomiser_weight_notifier, + // window->velocityCheck, &CheckBox::setChecked); + + //CONNECT(this, samplerate_notifier, + // window->velocityCheck, &CheckBox::setChecked); + + //CONNECT(this, enable_resampling_notifier, + // window->velocityCheck, &CheckBox::setChecked); + + CONNECT(this, drumkit_file_progress_notifier, + window->drumkitFileProgress, &ProgressBar::setProgress); auto eventHandler = window->eventHandler(); CONNECT(eventHandler, closeNotifier, this, &PluginGUI::closeEventHandler); diff --git a/plugingui/plugingui.h b/plugingui/plugingui.h index f441696..ca31c41 100644 --- a/plugingui/plugingui.h +++ b/plugingui/plugingui.h @@ -31,9 +31,7 @@ #include "pluginconfig.h" - -#include "thread.h" -#include "semaphore.h" +#include #include "messagereceiver.h" #include "notifier.h" @@ -68,6 +66,21 @@ public: Notifier<> closeNotifier; + // Setting notifiers: + Notifier enable_velocity_modifier_notifier; + Notifier velocity_modifier_falloff_notifier; + Notifier velocity_modifier_weight_notifier; + + Notifier enable_velocity_randomiser_notifier; + Notifier velocity_randomiser_weight_notifier; + + Notifier samplerate_notifier; + + Notifier enable_resampling_notifier; + + Notifier drumkit_file_progress_notifier; + //Notifier current_file_notifier; + // Support old interface a little while longer.. void setWindowClosedCallback(void (*handler)(void*), void* ptr); @@ -80,11 +93,12 @@ private: volatile bool closing{false}; volatile bool initialised{false}; - Semaphore sem{"plugingui"}; - // For the old-style notifier. void (*windowClosedHandler)(void *){nullptr}; void *windowClosedPtr{nullptr}; + + Settings settings; + SettingsGetter getter{settings}; }; } // GUI:: -- cgit v1.2.3 From e9c4a96ad32c2ab22f6f3edc5b68f1eb414c041e Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Thu, 31 Mar 2016 15:21:28 +0200 Subject: Fix missing include on windows. --- plugingui/testmain.cc | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'plugingui') diff --git a/plugingui/testmain.cc b/plugingui/testmain.cc index 8282bc8..b3a0d8d 100644 --- a/plugingui/testmain.cc +++ b/plugingui/testmain.cc @@ -26,6 +26,11 @@ */ #include "plugingui.h" +#ifdef WIN32 +#define WIN32_LEAN_AND_MEAN +#include +#endif + #include // Dummy Engine class. -- cgit v1.2.3 From 057ef1d83ba263fb2adf1aa86f8e281ab0065c43 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Fri, 8 Apr 2016 00:15:32 +0200 Subject: Refactoring to finally get rid of MessageHandler/Receiver in favor of the new Settings mechanism. --- plugingui/Makefile.am | 5 +- plugingui/button.h | 3 +- plugingui/checkbox.h | 3 +- plugingui/dgwindow.cc | 113 ++++++++++++++++++----------- plugingui/dgwindow.h | 14 ++-- plugingui/eventhandler.h | 3 +- plugingui/filebrowser.h | 4 +- plugingui/knob.h | 3 +- plugingui/layout.h | 2 +- plugingui/listboxbasic.h | 3 +- plugingui/listboxthin.h | 3 +- plugingui/notifier.h | 163 ----------------------------------------- plugingui/plugingui.cc | 183 ++++++++++------------------------------------- plugingui/plugingui.h | 36 ++-------- plugingui/progressbar.cc | 26 ++++--- plugingui/progressbar.h | 9 +-- plugingui/testmain.cc | 12 ++-- 17 files changed, 165 insertions(+), 420 deletions(-) delete mode 100644 plugingui/notifier.h (limited to 'plugingui') diff --git a/plugingui/Makefile.am b/plugingui/Makefile.am index 3dee864..4176c07 100644 --- a/plugingui/Makefile.am +++ b/plugingui/Makefile.am @@ -16,9 +16,7 @@ plugingui_SOURCES = \ $(top_srcdir)/src/configfile.cc \ $(top_srcdir)/src/thread.cc \ $(top_srcdir)/src/semaphore.cc \ - $(top_srcdir)/src/mutex.cc \ - $(top_srcdir)/src/messagehandler.cc \ - $(top_srcdir)/src/messagereceiver.cc + $(top_srcdir)/src/mutex.cc rcgen_SOURCES = rcgen.cc @@ -46,7 +44,6 @@ EXTRA_DIST = \ nativewindow.h \ nativewindow_win32.h \ nativewindow_x11.h \ - notifier.h \ painter.h \ pixelbuffer.h \ pluginconfig.h \ diff --git a/plugingui/button.h b/plugingui/button.h index 7e3e168..1bfeb2d 100644 --- a/plugingui/button.h +++ b/plugingui/button.h @@ -28,9 +28,10 @@ #include +#include + #include "widget.h" #include "painter.h" -#include "notifier.h" #include "font.h" namespace GUI { diff --git a/plugingui/checkbox.h b/plugingui/checkbox.h index 3da5511..5c658a5 100644 --- a/plugingui/checkbox.h +++ b/plugingui/checkbox.h @@ -26,9 +26,10 @@ */ #pragma once +#include + #include "widget.h" #include "image.h" -#include "notifier.h" namespace GUI { diff --git a/plugingui/dgwindow.cc b/plugingui/dgwindow.cc index 25cbdf0..c325703 100644 --- a/plugingui/dgwindow.cc +++ b/plugingui/dgwindow.cc @@ -30,12 +30,12 @@ #include "verticalline.h" #include "../version.h" -#include "messagehandler.h" #include "pluginconfig.h" namespace GUI { -class LabeledControl : public Widget +class LabeledControl + : public Widget { public: LabeledControl(Widget* parent, const std::string& name) @@ -60,7 +60,8 @@ public: Label caption{this}; }; -class File : public Widget +class File + : public Widget { public: File(Widget* parent) @@ -83,7 +84,8 @@ public: Button browseButton{this}; }; -class HumanizeControls : public Widget +class HumanizeControls + : public Widget { public: HumanizeControls(Widget* parent) @@ -119,10 +121,8 @@ public: Knob falloffKnob{&falloff}; }; -DGWindow::DGWindow(void* native_window, MessageHandler& messageHandler, - Config& config, Settings& settings) +DGWindow::DGWindow(void* native_window, Config& config, Settings& settings) : Window(native_window) - , messageHandler(messageHandler) , config(config) , settings(settings) { @@ -180,6 +180,7 @@ DGWindow::DGWindow(void* native_window, MessageHandler& messageHandler, midimapFileProgress = new ProgressBar(this); midimapFileProgress->resize(width() - 40, 11); + midimapFileProgress->setTotal(2); layout.addItem(midimapFileProgress); VerticalLine *l2 = new VerticalLine(this); @@ -208,7 +209,7 @@ DGWindow::DGWindow(void* native_window, MessageHandler& messageHandler, layout.addItem(l3); Label *lbl_version = new Label(this); - lbl_version->setText(".::. v" VERSION " .::. http://www.drumgizmo.org .::. LGPLv3 .::."); + lbl_version->setText(".::. v" VERSION " .::. http://www.drumgizmo.org .::. LGPLv3 .::."); lbl_version->resize(width(), 20); lbl_version->setAlignment(TextAlignment::center); layout.addItem(lbl_version); @@ -220,6 +221,50 @@ DGWindow::DGWindow(void* native_window, MessageHandler& messageHandler, fileBrowser->hide(); } +void DGWindow::setDrumKitLoadStatus(LoadStatus load_status) +{ + ProgressBarState state = ProgressBarState::Blue; + switch(load_status) + { + case LoadStatus::Idle: + case LoadStatus::Loading: + state = ProgressBarState::Blue; + break; + case LoadStatus::Done: + state = ProgressBarState::Green; + break; + case LoadStatus::Error: + state = ProgressBarState::Red; + break; + } + drumkitFileProgress->setState(state); +} + +void DGWindow::setMidiMapLoadStatus(LoadStatus load_status) +{ + ProgressBarState state = ProgressBarState::Blue; + switch(load_status) + { + case LoadStatus::Idle: + midimapFileProgress->setValue(0); + break; + case LoadStatus::Loading: + midimapFileProgress->setValue(1); + state = ProgressBarState::Blue; + break; + case LoadStatus::Done: + midimapFileProgress->setValue(2); + state = ProgressBarState::Green; + break; + case LoadStatus::Error: + midimapFileProgress->setValue(2); + state = ProgressBarState::Red; + break; + } + + midimapFileProgress->setState(state); +} + void DGWindow::repaintEvent(RepaintEvent* repaintEvent) { if(!visible()) @@ -234,45 +279,41 @@ void DGWindow::repaintEvent(RepaintEvent* repaintEvent) void DGWindow::attackValueChanged(float value) { - //ChangeSettingMessage *msg = - // new ChangeSettingMessage(ChangeSettingMessage::velocity_modifier_weight, - // value); - //messageHandler.sendMessage(MSGRCV_ENGINE, msg); - settings.velocity_modifier_weight.store(value); -#ifdef STANDALONE +#ifdef STANDALONE // For GUI debugging 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; + 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); - settings.velocity_modifier_falloff.store(value); -#ifdef STANDALONE - drumkitFileProgress->setProgress(value); +#ifdef STANDALONE // For GUI debugging + drumkitFileProgress->setTotal(100); + drumkitFileProgress->setValue(value * 100); #endif } void DGWindow::velocityCheckClick(bool checked) { -// ChangeSettingMessage *msg = -// new ChangeSettingMessage(ChangeSettingMessage::enable_velocity_modifier, -// checked); -// messageHandler.sendMessage(MSGRCV_ENGINE, msg); settings.enable_velocity_modifier.store(checked); } @@ -323,13 +364,7 @@ void DGWindow::selectKitFile(const std::string& filename) config.lastkit = drumkit; config.save(); - drumkitFileProgress->setProgress(0); - drumkitFileProgress->setState(ProgressBarState::Blue); - - LoadDrumKitMessage *msg = new LoadDrumKitMessage(); - msg->drumkitfile = drumkit; - - messageHandler.sendMessage(MSGRCV_ENGINE, msg); + settings.drumkit_file.store(drumkit); } void DGWindow::selectMapFile(const std::string& filename) @@ -342,9 +377,7 @@ void DGWindow::selectMapFile(const std::string& filename) config.lastmidimap = midimap; config.save(); - LoadMidimapMessage *msg = new LoadMidimapMessage(); - msg->midimapfile = midimap; - messageHandler.sendMessage(MSGRCV_ENGINE, msg); + settings.midimap_file.store(midimap); } diff --git a/plugingui/dgwindow.h b/plugingui/dgwindow.h index c4fbeab..72e4679 100644 --- a/plugingui/dgwindow.h +++ b/plugingui/dgwindow.h @@ -26,8 +26,9 @@ */ #pragma once -#include "window.h" +#include +#include "window.h" #include "label.h" #include "lineedit.h" #include "checkbox.h" @@ -37,10 +38,6 @@ #include "filebrowser.h" #include "layout.h" -#include - -class MessageHandler; - namespace GUI { class Config; @@ -49,8 +46,7 @@ class File; class DGWindow : public Window { public: - DGWindow(void* native_window, MessageHandler& messageHandler, Config& config, - Settings& settings); + DGWindow(void* native_window, Config& config, Settings& settings); Header* header; @@ -68,6 +64,9 @@ public: Knob* falloffKnob; FileBrowser* fileBrowser; + void setDrumKitLoadStatus(LoadStatus load_status); + void setMidiMapLoadStatus(LoadStatus load_status); + protected: // From Widget: void repaintEvent(RepaintEvent* repaintEvent) override; @@ -81,7 +80,6 @@ private: void selectKitFile(const std::string& filename); void selectMapFile(const std::string& filename); - MessageHandler& messageHandler; Config& config; VBoxLayout layout{this}; diff --git a/plugingui/eventhandler.h b/plugingui/eventhandler.h index 1fdb1e8..490c515 100644 --- a/plugingui/eventhandler.h +++ b/plugingui/eventhandler.h @@ -26,9 +26,10 @@ */ #pragma once +#include + #include "guievent.h" #include "nativewindow.h" -#include "notifier.h" namespace GUI { diff --git a/plugingui/filebrowser.h b/plugingui/filebrowser.h index 04b34f6..bc2019f 100644 --- a/plugingui/filebrowser.h +++ b/plugingui/filebrowser.h @@ -26,15 +26,15 @@ */ #pragma once -#include "widget.h" +#include +#include "widget.h" #include "button.h" #include "listbox.h" #include "lineedit.h" #include "label.h" #include "image.h" #include "directory.h" -#include "notifier.h" namespace GUI { diff --git a/plugingui/knob.h b/plugingui/knob.h index 10d91d6..d144184 100644 --- a/plugingui/knob.h +++ b/plugingui/knob.h @@ -26,10 +26,11 @@ */ #pragma once +#include + #include "widget.h" #include "image.h" #include "font.h" -#include "notifier.h" namespace GUI { diff --git a/plugingui/layout.h b/plugingui/layout.h index 55cc93f..49bf75c 100644 --- a/plugingui/layout.h +++ b/plugingui/layout.h @@ -29,7 +29,7 @@ #include #include -#include "notifier.h" +#include namespace GUI { diff --git a/plugingui/listboxbasic.h b/plugingui/listboxbasic.h index 7953dc3..2ebe845 100644 --- a/plugingui/listboxbasic.h +++ b/plugingui/listboxbasic.h @@ -29,11 +29,12 @@ #include #include +#include + #include "widget.h" #include "font.h" #include "painter.h" #include "scrollbar.h" -#include "notifier.h" namespace GUI { diff --git a/plugingui/listboxthin.h b/plugingui/listboxthin.h index 3139ecc..1617234 100644 --- a/plugingui/listboxthin.h +++ b/plugingui/listboxthin.h @@ -29,10 +29,11 @@ #include #include +#include + #include "widget.h" #include "painter.h" #include "listboxbasic.h" -#include "notifier.h" namespace GUI { diff --git a/plugingui/notifier.h b/plugingui/notifier.h deleted file mode 100644 index 9e9f6eb..0000000 --- a/plugingui/notifier.h +++ /dev/null @@ -1,163 +0,0 @@ -/* -*- 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 Lesser General Public License as published by - * the Free Software Foundation; either version 3 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser 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 -#include -#include -#include -#include - -namespace aux -{ - template - struct placeholder - { - }; -} - -namespace std -{ - template - struct is_placeholder> - : integral_constant - { - }; -} - -namespace aux -{ - // std::integer_sequence introduced in C++14 so remove this once we start requiring that. - - template - struct int_sequence - { - }; - - template - struct gen_int_sequence - : gen_int_sequence - { - }; - - template - struct gen_int_sequence<0, Ns...> - : int_sequence - { - }; -}; - - -namespace GUI { - -class Listener; -class NotifierBase { -public: - virtual void disconnect(Listener* object) {} -}; - -class Listener { -public: - virtual ~Listener() - { - for(auto signal : signals) - { - signal->disconnect(this); - } - } - - void registerNotifier(NotifierBase* signal) - { - signals.insert(signal); - } - - void unregisterNotifier(NotifierBase* signal) - { - signals.erase(signal); - } - -private: - std::set signals; -}; - -template -class Notifier : public NotifierBase { -public: - Notifier() {} - - //! \brief When dtor is called it will automatically disconnect all its listeners. - ~Notifier() - { - for(auto& slot : slots) - { - slot.first->unregisterNotifier(this); - } - } - - using callback_type = std::function; - - //! \brief Connect object to this Notifier. - template - void connect(O* p, const F& fn) - { - slots[p] = std::move(construct_mem_fn(fn, p, aux::gen_int_sequence{})); - if(p && dynamic_cast(p)) - { - dynamic_cast(p)->registerNotifier(this); - } - } - - //! \brief Disconnect object from this Notifier. - void disconnect(Listener* object) - { - slots.erase(object); - } - - //! \brief Activate this notifier by pretending it is a function. - //! Example: Notifier foo; foo(42); - void operator()(Args... args) - { - for(auto& slot : slots) - { - slot.second(args...); - } - } - -private: - std::map slots; - - template - callback_type construct_mem_fn(const F& fn, O* p, aux::int_sequence) const - { - return std::bind(fn, p, aux::placeholder{}...); - } - -}; - -} // GUI:: - -#define CONNECT(SRC, SIG, TAR, SLO) (SRC)->SIG.connect(TAR, SLO) diff --git a/plugingui/plugingui.cc b/plugingui/plugingui.cc index 9bac007..2802c44 100644 --- a/plugingui/plugingui.cc +++ b/plugingui/plugingui.cc @@ -26,18 +26,17 @@ */ #include "plugingui.h" +#include + #include #include "pluginconfig.h" -#include "messagehandler.h" - -#include namespace GUI { -PluginGUI::PluginGUI(void* native_window) - : MessageReceiver(MSGRCV_UI) - , native_window(native_window) +PluginGUI::PluginGUI(Settings& settings, void* native_window) + : native_window(native_window) + , settings(settings) { init(); } @@ -46,70 +45,6 @@ PluginGUI::~PluginGUI() { } -void PluginGUI::handleMessage(Message *msg) -{ - 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; - } -} - bool PluginGUI::processEvents() { if(!initialised) @@ -118,69 +53,13 @@ bool PluginGUI::processEvents() } window->eventHandler()->processEvents(); - //handleMessages(); - - static bool foo = false; - static int t = 0; - if(t != time(nullptr)) - { - t = time(nullptr); - foo = !foo; - float v = settings.velocity_modifier_falloff.load(); - v += 0.1f; - settings.velocity_modifier_falloff.store(v); - } - - Painter p(*window); - - // Run through all settings one at a time propagate changes to the UI. - if(getter.enable_velocity_modifier.hasChanged()) - { - enable_velocity_modifier_notifier(getter.enable_velocity_modifier.getValue()); - } - if(getter.velocity_modifier_falloff.hasChanged()) { - velocity_modifier_falloff_notifier(getter.velocity_modifier_falloff.getValue()); - } + Painter p(*window); - if(getter.velocity_modifier_weight.hasChanged()) - { - velocity_modifier_weight_notifier(getter.velocity_modifier_weight.getValue()); - } - - if(getter.enable_velocity_randomiser.hasChanged()) - { - enable_velocity_randomiser_notifier(getter.enable_velocity_randomiser.getValue()); + settings_notifier.evaluate(); } - if(getter.velocity_randomiser_weight.hasChanged()) - { - velocity_randomiser_weight_notifier(getter.velocity_randomiser_weight.getValue()); - } - - if(getter.samplerate.hasChanged()) - { - samplerate_notifier(getter.samplerate.getValue()); - } - - if(getter.enable_resampling.hasChanged()) - { - enable_resampling_notifier(getter.enable_resampling.getValue()); - } - - if(getter.number_of_files.hasChanged() || - getter.number_of_files_loaded.hasChanged()) - { - drumkit_file_progress_notifier((float)getter.number_of_files_loaded.getValue() / - (float)getter.number_of_files.getValue()); - } - - //if(getter.current_file.hasChanged()) - //{ - // current_file_notifier(getter.current_file.getValue()); - //} - if(closing) { closeNotifier(); @@ -198,41 +77,51 @@ void PluginGUI::init() config = new Config(); config->load(); - window = new DGWindow(native_window, msghandler, *config, settings); + window = new DGWindow(native_window, *config, settings); + + + CONNECT(this, settings_notifier.drumkit_file, + window->lineedit, &LineEdit::setText); + CONNECT(this, settings_notifier.drumkit_load_status, + window, &DGWindow::setDrumKitLoadStatus); - CONNECT(this, enable_velocity_modifier_notifier, + CONNECT(this, settings_notifier.midimap_file, + window->lineedit2, &LineEdit::setText); + CONNECT(this, settings_notifier.midimap_load_status, + window, &DGWindow::setMidiMapLoadStatus); + + CONNECT(this, settings_notifier.enable_velocity_modifier, window->velocityCheck, &CheckBox::setChecked); - CONNECT(this, velocity_modifier_falloff_notifier, + CONNECT(this, settings_notifier.velocity_modifier_falloff, window->falloffKnob, &Knob::setValue); - CONNECT(this, velocity_modifier_weight_notifier, + CONNECT(this, settings_notifier.velocity_modifier_weight, window->attackKnob, &Knob::setValue); - //CONNECT(this, enable_velocity_randomiser_notifier, - // window->velocityCheck, &CheckBox::setChecked); - //CONNECT(this, velocity_randomiser_weight_notifier, - // window->velocityCheck, &CheckBox::setChecked); + // TODO: + //CONNECT(this, settings_notifier.enable_velocity_randomiser, + // window->, &CheckBox::setChecked); + //CONNECT(this, settings_notifier.velocity_randomiser_weight, + // window->, &Knob::setValue); + + //CONNECT(this, settings_notifier.samplerate, + // window->, &Knob::setValue); - //CONNECT(this, samplerate_notifier, - // window->velocityCheck, &CheckBox::setChecked); + //CONNECT(this, settings_notifier.enable_resampling, + // window->, &CheckBox::setChecked); - //CONNECT(this, enable_resampling_notifier, - // window->velocityCheck, &CheckBox::setChecked); + CONNECT(this, settings_notifier.number_of_files, + window->drumkitFileProgress, &ProgressBar::setTotal); - CONNECT(this, drumkit_file_progress_notifier, - window->drumkitFileProgress, &ProgressBar::setProgress); + CONNECT(this, settings_notifier.number_of_files_loaded, + window->drumkitFileProgress, &ProgressBar::setValue); auto eventHandler = window->eventHandler(); CONNECT(eventHandler, closeNotifier, this, &PluginGUI::closeEventHandler); window->show(); - { // Request all engine settings - EngineSettingsMessage *msg = new EngineSettingsMessage(); - msghandler.sendMessage(MSGRCV_ENGINE, msg); - } - initialised = true; } diff --git a/plugingui/plugingui.h b/plugingui/plugingui.h index ca31c41..04b0a29 100644 --- a/plugingui/plugingui.h +++ b/plugingui/plugingui.h @@ -26,24 +26,20 @@ */ #pragma once +#include +#include + #include "dgwindow.h" #include "eventhandler.h" - #include "pluginconfig.h" -#include - -#include "messagereceiver.h" -#include "notifier.h" - namespace GUI { class PluginGUI - : public MessageReceiver - , public Listener + : public Listener { public: - PluginGUI(void* native_window = nullptr); + PluginGUI(Settings& settings, void* native_window = nullptr); virtual ~PluginGUI(); //! Process all events and messages in queue @@ -56,9 +52,6 @@ public: void show(); void hide(); - - void handleMessage(Message* msg); - DGWindow* window{nullptr}; EventHandler* eventhandler{nullptr}; @@ -66,21 +59,6 @@ public: Notifier<> closeNotifier; - // Setting notifiers: - Notifier enable_velocity_modifier_notifier; - Notifier velocity_modifier_falloff_notifier; - Notifier velocity_modifier_weight_notifier; - - Notifier enable_velocity_randomiser_notifier; - Notifier velocity_randomiser_weight_notifier; - - Notifier samplerate_notifier; - - Notifier enable_resampling_notifier; - - Notifier drumkit_file_progress_notifier; - //Notifier current_file_notifier; - // Support old interface a little while longer.. void setWindowClosedCallback(void (*handler)(void*), void* ptr); @@ -97,8 +75,8 @@ private: void (*windowClosedHandler)(void *){nullptr}; void *windowClosedPtr{nullptr}; - Settings settings; - SettingsGetter getter{settings}; + Settings& settings; + SettingsNotifier settings_notifier{settings}; }; } // GUI:: diff --git a/plugingui/progressbar.cc b/plugingui/progressbar.cc index 932f17c..f934664 100644 --- a/plugingui/progressbar.cc +++ b/plugingui/progressbar.cc @@ -26,6 +26,8 @@ */ #include "progressbar.h" +#include + namespace GUI { ProgressBar::ProgressBar(Widget *parent) @@ -46,9 +48,6 @@ ProgressBar::ProgressBar(Widget *parent) bar_green.left = new Image(":progress_front_green_l.png"); bar_green.right = new Image(":progress_front_green_r.png"); bar_green.center = new Image(":progress_front_green_c.png"); - - state = ProgressBarState::Blue; - _progress = .5; } ProgressBar::~ProgressBar() @@ -79,22 +78,31 @@ void ProgressBar::setState(ProgressBarState state) } } -float ProgressBar::progress() +void ProgressBar::setTotal(int total) { - return _progress; + if(this->total != total) + { + this->total = total; + repaintEvent(nullptr); + } } -void ProgressBar::setProgress(float progress) +void ProgressBar::setValue(int value) { - _progress = progress; - repaintEvent(nullptr); + if(this->value != value) + { + this->value = value; + repaintEvent(nullptr); + } } void ProgressBar::repaintEvent(RepaintEvent* repaintEvent) { Painter p(*this); - int max = width() * _progress; + float progress = (float)value / (float)total; + + int max = width() * progress; p.clear(); diff --git a/plugingui/progressbar.h b/plugingui/progressbar.h index d5f6c61..d48a8b5 100644 --- a/plugingui/progressbar.h +++ b/plugingui/progressbar.h @@ -46,8 +46,8 @@ public: ProgressBar(Widget *parent); ~ProgressBar(); - float progress(); - void setProgress(float progress); + void setTotal(int total); + void setValue(int value); void setState(ProgressBarState state); @@ -56,7 +56,7 @@ protected: virtual void repaintEvent(RepaintEvent* repaintEvent) override; private: - ProgressBarState state; + ProgressBarState state{ProgressBarState::Blue}; Painter::Bar bar_bg; @@ -64,7 +64,8 @@ private: Painter::Bar bar_blue; Painter::Bar bar_red; - float _progress; + int total{0}; + int value{0}; }; } // GUI:: diff --git a/plugingui/testmain.cc b/plugingui/testmain.cc index b3a0d8d..84d813d 100644 --- a/plugingui/testmain.cc +++ b/plugingui/testmain.cc @@ -33,13 +33,10 @@ #include -// Dummy Engine class. -class Engine : public MessageHandler { -public: - void handleMessage(Message *msg) {} -}; +#include +#include -class TestMain : public GUI::Listener { +class TestMain : public Listener { public: TestMain() { @@ -67,7 +64,8 @@ public: bool running = true; - GUI::PluginGUI gui; + Settings settings; + GUI::PluginGUI gui{settings}; }; int main() -- cgit v1.2.3 From 0ae4539e7f42d21b3ebc8ec1914a32b5cf58d490 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Wed, 13 Apr 2016 18:53:25 +0200 Subject: Remove message files. --- plugingui/Makefile.mingw32 | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'plugingui') diff --git a/plugingui/Makefile.mingw32 b/plugingui/Makefile.mingw32 index 3f52e8a..9820d1a 100644 --- a/plugingui/Makefile.mingw32 +++ b/plugingui/Makefile.mingw32 @@ -2,9 +2,7 @@ DG_SRC = \ ../src/configfile.cc \ ../src/thread.cc \ ../src/semaphore.cc \ - ../src/mutex.cc \ - ../src/messagehandler.cc \ - ../src/messagereceiver.cc + ../src/mutex.cc DG_CFLAGS = -I.. -I../include -I../src -DSSE -msse -msse2 -DDISABLE_HUGIN -- cgit v1.2.3 From 35e804b984c28131fe13d229c5a0867762c6e8cf Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sat, 16 Apr 2016 13:23:11 +0200 Subject: Some DrumKitLoader refactoring. --- plugingui/progressbar.cc | 4 ++-- plugingui/progressbar.h | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'plugingui') diff --git a/plugingui/progressbar.cc b/plugingui/progressbar.cc index f934664..8a382f5 100644 --- a/plugingui/progressbar.cc +++ b/plugingui/progressbar.cc @@ -78,7 +78,7 @@ void ProgressBar::setState(ProgressBarState state) } } -void ProgressBar::setTotal(int total) +void ProgressBar::setTotal(std::size_t total) { if(this->total != total) { @@ -87,7 +87,7 @@ void ProgressBar::setTotal(int total) } } -void ProgressBar::setValue(int value) +void ProgressBar::setValue(std::size_t value) { if(this->value != value) { diff --git a/plugingui/progressbar.h b/plugingui/progressbar.h index d48a8b5..7485e40 100644 --- a/plugingui/progressbar.h +++ b/plugingui/progressbar.h @@ -43,11 +43,11 @@ enum class ProgressBarState class ProgressBar : public Widget { public: - ProgressBar(Widget *parent); + ProgressBar(Widget* parent); ~ProgressBar(); - void setTotal(int total); - void setValue(int value); + void setTotal(std::size_t total); + void setValue(std::size_t value); void setState(ProgressBarState state); @@ -64,8 +64,8 @@ private: Painter::Bar bar_blue; Painter::Bar bar_red; - int total{0}; - int value{0}; + std::size_t total{0}; + std::size_t value{0}; }; } // GUI:: -- cgit v1.2.3