diff options
-rw-r--r-- | plugin/Makefile.mingw32.in | 1 | ||||
-rw-r--r-- | plugingui/Makefile.am | 1 | ||||
-rw-r--r-- | plugingui/drumkittab.cc | 116 | ||||
-rw-r--r-- | plugingui/drumkittab.h | 75 | ||||
-rw-r--r-- | plugingui/mainwindow.cc | 2 | ||||
-rw-r--r-- | plugingui/mainwindow.h | 2 | ||||
-rw-r--r-- | src/drumgizmo.cc | 19 | ||||
-rw-r--r-- | src/settings.h | 19 |
8 files changed, 235 insertions, 0 deletions
diff --git a/plugin/Makefile.mingw32.in b/plugin/Makefile.mingw32.in index 52d573d..249ee52 100644 --- a/plugin/Makefile.mingw32.in +++ b/plugin/Makefile.mingw32.in @@ -57,6 +57,7 @@ GUI_SRC = \ @top_srcdir@/plugingui/directory.cc \ @top_srcdir@/plugingui/diskstreamingframecontent.cc \ @top_srcdir@/plugingui/drumkitframecontent.cc \ + @top_srcdir@/plugingui/drumkittab.cc \ @top_srcdir@/plugingui/eventhandler.cc \ @top_srcdir@/plugingui/filebrowser.cc \ @top_srcdir@/plugingui/font.cc \ diff --git a/plugingui/Makefile.am b/plugingui/Makefile.am index 3f96ff8..c726088 100644 --- a/plugingui/Makefile.am +++ b/plugingui/Makefile.am @@ -67,6 +67,7 @@ nodist_libdggui_la_SOURCES = \ directory.cc \ diskstreamingframecontent.cc \ drumkitframecontent.cc \ + drumkittab.cc \ eventhandler.cc \ filebrowser.cc \ font.cc \ diff --git a/plugingui/drumkittab.cc b/plugingui/drumkittab.cc new file mode 100644 index 0000000..3f6cd5f --- /dev/null +++ b/plugingui/drumkittab.cc @@ -0,0 +1,116 @@ +/* -*- Mode: c++ -*- */ +/*************************************************************************** + * drumkittab.cc + * + * Fri Jun 8 21:50:03 CEST 2018 + * Copyright 2018 André Nusser + * andre.nusser@googlemail.com + ****************************************************************************/ + +/* + * 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. + */ +#include "drumkittab.h" + +#include <iomanip> +#include <sstream> + +#include "cpp11fix.h" // required for c++11 +#include "painter.h" +#include "settings.h" + +namespace GUI +{ + +DrumkitTab::DrumkitTab(Widget* parent, + Settings& settings, + SettingsNotifier& settings_notifier, + Config& config) + : Widget(parent) + , settings(settings) + , settings_notifier(settings_notifier) + , config(config) +{ + loadImageFiles("/home/chaot/Programming/drumgizmo/crocellkit01.png", "/home/chaot/Programming/drumgizmo/crocellkit01_map.png"); + + velocity_label.move(10, height()-velocity_label.height()-5); + updateVelocityLabel(); + velocity_label.resizeToText(); +} + +void DrumkitTab::resize(std::size_t width, std::size_t height) +{ + Widget::resize(width, height); + + if (drumkit_image) { + Painter painter(*this); + painter.clear(); + painter.drawImage(0 , 0, *drumkit_image); + } + + velocity_label.move(10, height-velocity_label.height()-5); +} + +void DrumkitTab::buttonEvent(ButtonEvent* buttonEvent) +{ + if (buttonEvent->button == MouseButton::left && + buttonEvent->direction == GUI::Direction::down) + { + triggerAudition(buttonEvent->x, buttonEvent->y); + } +} + +void DrumkitTab::scrollEvent(ScrollEvent* scrollEvent) +{ + current_velocity -= 0.01*scrollEvent->delta; + current_velocity = std::max(std::min(current_velocity, 1.0f), 0.0f); + updateVelocityLabel(); + velocity_label.resizeToText(); + + triggerAudition(scrollEvent->x, scrollEvent->y); +} + +void DrumkitTab::triggerAudition(int x, int y) +{ + auto map_colour = map_image->getPixel(x, y); + + // TODO: convert color to instrument + if (map_colour != Colour(0)) + { + return; + } + + ++settings.audition_counter; + settings.audition_instrument = "Snare"; + settings.audition_velocity = current_velocity; +} + +void DrumkitTab::updateVelocityLabel() +{ + std::stringstream stream; + stream << std::fixed << std::setprecision(2) << current_velocity; + velocity_label.setText("Velocity: " + stream.str()); +} + +// FIXME: this should actually be done somewhere else maybe? +void DrumkitTab::loadImageFiles(std::string const& image_file, std::string const& map_file) +{ + drumkit_image = std::make_unique<Image>(image_file); + map_image = std::make_unique<Image>(map_file); +} + +} // GUI:: diff --git a/plugingui/drumkittab.h b/plugingui/drumkittab.h new file mode 100644 index 0000000..1a0eb7a --- /dev/null +++ b/plugingui/drumkittab.h @@ -0,0 +1,75 @@ +/* -*- Mode: c++ -*- */ +/*************************************************************************** + * drumkittab.h + * + * Fri Jun 8 21:50:03 CEST 2018 + * Copyright 2018 André Nusser + * andre.nusser@googlemail.com + ****************************************************************************/ + +/* + * 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 <memory> +#include <string> + +#include "image.h" +#include "label.h" +#include "widget.h" + +struct Settings; +class SettingsNotifier; + +namespace GUI +{ + +class Config; + +class DrumkitTab + : public Widget +{ +public: + DrumkitTab(Widget* parent, + Settings& settings, + SettingsNotifier& settings_notifier, + Config& config); + + // From Widget: + void resize(std::size_t width, std::size_t height) override; + void buttonEvent(ButtonEvent* buttonEvent) override; + void scrollEvent(ScrollEvent* scrollEvent) override; + + void loadImageFiles(std::string const& image_file, std::string const& map_file); + +private: + float current_velocity = .5; + + std::unique_ptr<Image> drumkit_image; + std::unique_ptr<Image> map_image; + Label velocity_label{this}; + + Settings& settings; + SettingsNotifier& settings_notifier; + Config& config; + + void triggerAudition(int x, int y); + void updateVelocityLabel(); +}; + +} // GUI:: diff --git a/plugingui/mainwindow.cc b/plugingui/mainwindow.cc index d98d335..944eb71 100644 --- a/plugingui/mainwindow.cc +++ b/plugingui/mainwindow.cc @@ -39,6 +39,7 @@ MainWindow::MainWindow(Settings& settings, void* native_window) : Window(native_window) , settings_notifier(settings) , main_tab(this, settings, settings_notifier, config) + , drumkit_tab(this, settings, settings_notifier, config) { config.load(); @@ -49,6 +50,7 @@ MainWindow::MainWindow(Settings& settings, void* native_window) tabs.move(16, 0); // x-offset to make room for the left side bar. tabs.addTab("Main", &main_tab); + tabs.addTab("Drumkit", &drumkit_tab); tabs.addTab("About", &about_tab); } diff --git a/plugingui/mainwindow.h b/plugingui/mainwindow.h index 6ab3996..ea05ad6 100644 --- a/plugingui/mainwindow.h +++ b/plugingui/mainwindow.h @@ -29,6 +29,7 @@ #include <settings.h> #include "abouttab.h" +#include "drumkittab.h" #include "image.h" #include "tabwidget.h" #include "texturedbox.h" @@ -65,6 +66,7 @@ private: TabWidget tabs{this}; MainTab main_tab; + DrumkitTab drumkit_tab; AboutTab about_tab{&tabs}; Image back{":resources/bg.png"}; diff --git a/src/drumgizmo.cc b/src/drumgizmo.cc index d389cc2..d15b192 100644 --- a/src/drumgizmo.cc +++ b/src/drumgizmo.cc @@ -137,6 +137,25 @@ bool DrumGizmo::run(size_t pos, sample_t *samples, size_t nsamples) { resample_ratio = 1.0; } + + if (settings_getter.audition_counter.hasChanged()) + { + settings_getter.audition_counter.getValue(); + auto instrument_name = settings.audition_instrument.load(); + auto velocity = settings.audition_velocity.load(); + + std::size_t instrument_index = 0; + for (std::size_t i = 0; i < kit.instruments.size(); ++i) + { + if (instrument_name == kit.instruments[i]->getName()) + { + instrument_index = i; + } + } + + events.emplace_back(event_t{TYPE_ONSET, instrument_index, 0, velocity}); + } + bool active_events_left = input_processor.process(events, pos, resample_ratio); diff --git a/src/settings.h b/src/settings.h index 5137809..13bb956 100644 --- a/src/settings.h +++ b/src/settings.h @@ -128,6 +128,10 @@ struct Settings // Current latency offset in ms - for UI Atomic<float> latency_current{0}; + + Atomic<std::size_t> audition_counter{0}; + Atomic<std::string> audition_instrument; + Atomic<float> audition_velocity; }; //! Settings getter class. @@ -179,6 +183,10 @@ struct SettingsGetter SettingRef<float> latency_regain; SettingRef<float> latency_current; + SettingRef<std::size_t> audition_counter; + SettingRef<std::string> audition_instrument; + SettingRef<float> audition_velocity; + SettingsGetter(Settings& settings) : drumkit_file(settings.drumkit_file) , drumkit_load_status(settings.drumkit_load_status) @@ -216,6 +224,9 @@ struct SettingsGetter , latency_stddev{settings.latency_stddev} , latency_regain{settings.latency_regain} , latency_current{settings.latency_current} + , audition_counter{settings.audition_counter} + , audition_instrument{settings.audition_instrument} + , audition_velocity{settings.audition_velocity} { } }; @@ -270,6 +281,10 @@ public: Notifier<float> latency_regain; Notifier<float> latency_current; + Notifier<std::size_t> audition_counter; + Notifier<std::string> audition_instrument; + Notifier<int> audition_velocity; + void evaluate() { #define EVAL(x) if(settings.x.hasChanged()) { x(settings.x.getValue()); } @@ -319,6 +334,10 @@ public: EVAL(latency_stddev); EVAL(latency_regain); EVAL(latency_current); + + EVAL(audition_counter); + EVAL(audition_instrument); + EVAL(audition_velocity); } SettingsNotifier(Settings& settings) |