diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2016-04-08 00:15:32 +0200 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2016-04-08 00:15:32 +0200 |
commit | 057ef1d83ba263fb2adf1aa86f8e281ab0065c43 (patch) | |
tree | 31c1f237e3a9df9fc241d87527f7dd4245665d43 /plugingui | |
parent | b530ac02af61e320e137a392decef1b3cc5af2c4 (diff) |
Refactoring to finally get rid of MessageHandler/Receiver in favor of the new Settings mechanism.
Diffstat (limited to 'plugingui')
-rw-r--r-- | plugingui/Makefile.am | 5 | ||||
-rw-r--r-- | plugingui/button.h | 3 | ||||
-rw-r--r-- | plugingui/checkbox.h | 3 | ||||
-rw-r--r-- | plugingui/dgwindow.cc | 113 | ||||
-rw-r--r-- | plugingui/dgwindow.h | 14 | ||||
-rw-r--r-- | plugingui/eventhandler.h | 3 | ||||
-rw-r--r-- | plugingui/filebrowser.h | 4 | ||||
-rw-r--r-- | plugingui/knob.h | 3 | ||||
-rw-r--r-- | plugingui/layout.h | 2 | ||||
-rw-r--r-- | plugingui/listboxbasic.h | 3 | ||||
-rw-r--r-- | plugingui/listboxthin.h | 3 | ||||
-rw-r--r-- | plugingui/notifier.h | 163 | ||||
-rw-r--r-- | plugingui/plugingui.cc | 183 | ||||
-rw-r--r-- | plugingui/plugingui.h | 36 | ||||
-rw-r--r-- | plugingui/progressbar.cc | 26 | ||||
-rw-r--r-- | plugingui/progressbar.h | 9 | ||||
-rw-r--r-- | plugingui/testmain.cc | 12 |
17 files changed, 165 insertions, 420 deletions
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 <string> +#include <notifier.h> + #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 <notifier.h> + #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 <settings.h> +#include "window.h" #include "label.h" #include "lineedit.h" #include "checkbox.h" @@ -37,10 +38,6 @@ #include "filebrowser.h" #include "layout.h" -#include <settings.h> - -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 <notifier.h> + #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 <notifier.h> +#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 <notifier.h> + #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 <list> #include <cstdlib> -#include "notifier.h" +#include <notifier.h> 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 <string.h> #include <vector> +#include <notifier.h> + #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 <string.h> #include <vector> +#include <notifier.h> + #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 <functional> -#include <vector> -#include <map> -#include <set> -#include <memory> - -namespace aux -{ - template<int> - struct placeholder - { - }; -} - -namespace std -{ - template<int N> - struct is_placeholder<aux::placeholder<N>> - : integral_constant<int, N+1> - { - }; -} - -namespace aux -{ - // std::integer_sequence introduced in C++14 so remove this once we start requiring that. - - template<int... Ns> - struct int_sequence - { - }; - - template<int N, int... Ns> - struct gen_int_sequence - : gen_int_sequence<N-1, N-1, Ns...> - { - }; - - template<int... Ns> - struct gen_int_sequence<0, Ns...> - : int_sequence<Ns...> - { - }; -}; - - -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<NotifierBase*> signals; -}; - -template<typename... Args> -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<void(Args...)>; - - //! \brief Connect object to this Notifier. - template<typename O, typename F> - void connect(O* p, const F& fn) - { - slots[p] = std::move(construct_mem_fn(fn, p, aux::gen_int_sequence<sizeof...(Args)>{})); - if(p && dynamic_cast<Listener*>(p)) - { - dynamic_cast<Listener*>(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<int> foo; foo(42); - void operator()(Args... args) - { - for(auto& slot : slots) - { - slot.second(args...); - } - } - -private: - std::map<Listener*, callback_type> slots; - - template<typename F, typename O, int... Ns> - callback_type construct_mem_fn(const F& fn, O* p, aux::int_sequence<Ns...>) const - { - return std::bind(fn, p, aux::placeholder<Ns>{}...); - } - -}; - -} // 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 <iostream> + #include <hugin.hpp> #include "pluginconfig.h" -#include "messagehandler.h" - -#include <iostream> 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 <settings.h> +#include <notifier.h> + #include "dgwindow.h" #include "eventhandler.h" - #include "pluginconfig.h" -#include <settings.h> - -#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<bool> enable_velocity_modifier_notifier; - Notifier<float> velocity_modifier_falloff_notifier; - Notifier<float> velocity_modifier_weight_notifier; - - Notifier<bool> enable_velocity_randomiser_notifier; - Notifier<float> velocity_randomiser_weight_notifier; - - Notifier<double> samplerate_notifier; - - Notifier<bool> enable_resampling_notifier; - - Notifier<float> drumkit_file_progress_notifier; - //Notifier<std::string> 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 <iostream> + 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 <hugin.hpp> -// Dummy Engine class. -class Engine : public MessageHandler { -public: - void handleMessage(Message *msg) {} -}; +#include <notifier.h> +#include <settings.h> -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() |