diff options
-rw-r--r-- | plugin/Makefile.mingw32.in | 1 | ||||
-rw-r--r-- | plugin/drumgizmo_plugin.cc | 21 | ||||
-rw-r--r-- | plugingui/Makefile.am | 2 | ||||
-rw-r--r-- | plugingui/Makefile.mingw32 | 1 | ||||
-rw-r--r-- | plugingui/labeledcontrol.h | 19 | ||||
-rw-r--r-- | plugingui/maintab.cc | 52 | ||||
-rw-r--r-- | plugingui/maintab.h | 6 | ||||
-rw-r--r-- | plugingui/voicelimitframecontent.cc | 123 | ||||
-rw-r--r-- | plugingui/voicelimitframecontent.h | 73 | ||||
-rw-r--r-- | src/inputprocessor.cc | 87 | ||||
-rw-r--r-- | src/inputprocessor.h | 5 | ||||
-rw-r--r-- | src/settings.h | 24 |
12 files changed, 398 insertions, 16 deletions
diff --git a/plugin/Makefile.mingw32.in b/plugin/Makefile.mingw32.in index 4e324af..2c2055c 100644 --- a/plugin/Makefile.mingw32.in +++ b/plugin/Makefile.mingw32.in @@ -113,6 +113,7 @@ GUI_SRC = \ @top_srcdir@/plugingui/utf8.cc \ @top_srcdir@/plugingui/verticalline.cc \ @top_srcdir@/plugingui/visualizerframecontent.cc \ + @top_srcdir@/plugingui/voicelimitframecontent.cc \ @top_srcdir@/plugingui/widget.cc \ @top_srcdir@/plugingui/window.cc \ @top_srcdir@/plugingui/lodepng/lodepng.cpp diff --git a/plugin/drumgizmo_plugin.cc b/plugin/drumgizmo_plugin.cc index 98299ee..b955eb3 100644 --- a/plugin/drumgizmo_plugin.cc +++ b/plugin/drumgizmo_plugin.cc @@ -651,6 +651,12 @@ std::string DrumGizmoPlugin::ConfigStringIO::get() float2str(settings.powermap_fixed2_y.load()) + "</value>\n" " <value name=\"powermap_shelf\">" + bool2str(settings.powermap_shelf.load()) + "</value>\n" + " <value name=\"enable_voice_limit\">" + + bool2str(settings.enable_voice_limit.load()) + "</value>\n" + " <value name=\"voice_limit_max\">" + + int2str(settings.voice_limit_max.load()) + "</value>\n" + " <value name=\"voice_limit_rampdown\">" + + float2str(settings.voice_limit_rampdown.load()) + "</value>\n" "</config>"; } @@ -811,6 +817,21 @@ bool DrumGizmoPlugin::ConfigStringIO::set(std::string config_string) settings.powermap_shelf.store(p.value("powermap_shelf") == "true"); } + if(p.value("enable_voice_limit") != "") + { + settings.enable_voice_limit.store(p.value("enable_voice_limit") == "true"); + } + + if(p.value("voice_limit_max") != "") + { + settings.voice_limit_max.store(str2int(p.value("voice_limit_max"))); + } + + if(p.value("voice_limit_rampdown") != "") + { + settings.voice_limit_rampdown.store(str2float(p.value("voice_limit_rampdown"))); + } + std::string newkit = p.value("drumkitfile"); if(newkit != "") { diff --git a/plugingui/Makefile.am b/plugingui/Makefile.am index 65e7011..d102024 100644 --- a/plugingui/Makefile.am +++ b/plugingui/Makefile.am @@ -154,6 +154,7 @@ GUI_SRC = \ utf8.cc \ verticalline.cc \ visualizerframecontent.cc \ + voicelimitframecontent.cc \ widget.cc \ window.cc @@ -227,6 +228,7 @@ GUI_HDR = \ utf8.h \ verticalline.h \ visualizerframecontent.h \ + voicelimitframecontent.h \ widget.h \ window.h diff --git a/plugingui/Makefile.mingw32 b/plugingui/Makefile.mingw32 index df735d5..bc58c11 100644 --- a/plugingui/Makefile.mingw32 +++ b/plugingui/Makefile.mingw32 @@ -56,6 +56,7 @@ GUI_SRC = \ verticalline.cc \ resource.cc \ resource_data.cc \ + voicelimitframecontent.cc \ lodepng/lodepng.cpp GUI_CFLAGS=-DUSE_THREAD -DUI_WIN32 -DSTANDALONE diff --git a/plugingui/labeledcontrol.h b/plugingui/labeledcontrol.h index cf01b46..3cbae39 100644 --- a/plugingui/labeledcontrol.h +++ b/plugingui/labeledcontrol.h @@ -31,6 +31,7 @@ #include <iomanip> #include <sstream> +#include <functional> namespace GUI { @@ -39,6 +40,10 @@ class LabeledControl : public Widget { public: + + using ValueTransformationFunction = + std::function<std::string(float, float, float)>; + LabeledControl(Widget* parent, const std::string& name) : Widget(parent) { @@ -63,6 +68,11 @@ public: layout.addItem(&value); } + void setValueTransformationFunction(ValueTransformationFunction function) + { + value_transformation_func = function; + } + float offset{0.0f}; float scale{1.0f}; @@ -71,8 +81,17 @@ private: Label caption{this}; Label value{this}; + ValueTransformationFunction value_transformation_func; + void setValue(float new_value) { + if(value_transformation_func) + { + value.setText(value_transformation_func(new_value, scale, offset)); + return; + } + + //TODO: Surely this could be the "default transformation function"? new_value *= scale; new_value += offset; std::stringstream stream; diff --git a/plugingui/maintab.cc b/plugingui/maintab.cc index 05c5e6f..d6da057 100644 --- a/plugingui/maintab.cc +++ b/plugingui/maintab.cc @@ -46,6 +46,7 @@ MainTab::MainTab(Widget* parent, , sampleselectionframe_content{this, settings, settings_notifier} , visualizerframe_content{this, settings, settings_notifier} , powerframe_content{this, settings, settings_notifier} + , voicelimit_content{this, settings, settings_notifier} , settings(settings) , settings_notifier(settings_notifier) { @@ -116,30 +117,50 @@ MainTab::MainTab(Widget* parent, _("the lower left corner, then the three control points, and then\n") + _("the upper right corner, enabling to draw more complicated functions."); - layout.setResizeChildren(true); + const std::string voice_limit_tip = std::string( + _("This feature controls how many voices can simultaneously be in play for a given\n")) + + _("instrument. When this feature is active, Drumgizmo will silence any excess \n") + + _("voices to ease the burden of processing.\n") + + _("\n") + + _("This feature works on a per-instrument basis, e.g., voices played on the bass\n") + + _("drum can only be silenced by other bass drum hits, and not by the snare.\n") + + _("\n") + + _(" * Max voices: The maximum number of voices that should be allowed to play.\n") + + _(" * Rampdown time: How many seconds it takes to silence a voice."); - add(_("Drumkit"), drumkit_frame, drumkitframe_content, 12, 0); - add(_("Status"), status_frame, statusframe_content, 14, 0); - add(_("Resampling"), resampling_frame, resamplingframe_content, 9, 0); - add(_("Disk Streaming"), diskstreaming_frame, diskstreamingframe_content, 7, 0); - add(_("Bleed Control"), bleedcontrol_frame, bleedcontrolframe_content, 7, 0); + layout.setResizeChildren(true); - add(_("Velocity Humanizer"), humanizer_frame, humanizerframe_content, 8, 1); + //Left column... + add(_("Drumkit"), drumkit_frame, drumkitframe_content, 14, 0); + add(_("Status"), status_frame, statusframe_content, 12, 0); + add(_("Resampling"), resampling_frame, resamplingframe_content, 10, 0); + add(_("Voice Limit"), voicelimit_frame, voicelimit_content, 10, 0); + voicelimit_frame.setHelpText(voice_limit_tip); + add(_("Disk Streaming"), diskstreaming_frame, diskstreamingframe_content, 9, 0); + add(_("Bleed Control"), bleedcontrol_frame, bleedcontrolframe_content, 9, 0); + + //Right column + add(_("Velocity Humanizer"), humanizer_frame, humanizerframe_content,10, 1); humanizer_frame.setHelpText(humanizer_tip); - add(_("Timing Humanizer"), timing_frame, timingframe_content, 8, 1); + + add(_("Timing Humanizer"), timing_frame, timingframe_content, 10, 1); timing_frame.setHelpText(timing_tip); + add(_("Sample Selection"), sampleselection_frame, - sampleselectionframe_content, 8, 1); + sampleselectionframe_content, 10, 1); sampleselection_frame.setHelpText(sampleselection_tip); - add(_("Visualizer"), visualizer_frame, visualizerframe_content, 8, 1); + + add(_("Visualizer"), visualizer_frame, visualizerframe_content, 14, 1); visualizer_frame.setHelpText(visualizer_tip); - add(_("Velocity Curve"), power_frame, powerframe_content, 17, 1); + + add(_("Velocity Curve"), power_frame, powerframe_content, 20, 1); power_frame.setHelpText(power_tip); humanizer_frame.setOnSwitch(settings.enable_velocity_modifier); bleedcontrol_frame.setOnSwitch(settings.enable_bleed_control); resampling_frame.setOnSwitch(settings.enable_resampling); timing_frame.setOnSwitch(settings.enable_latency_modifier); + voicelimit_frame.setOnSwitch(settings.enable_voice_limit); // FIXME: bleedcontrol_frame.setEnabled(false); @@ -160,11 +181,13 @@ MainTab::MainTab(Widget* parent, this, &MainTab::timingOnChange); CONNECT(&bleedcontrol_frame, onEnabledChanged, &bleedcontrolframe_content, &BleedcontrolframeContent::setEnabled); - CONNECT(&settings_notifier, enable_powermap, &power_frame, &FrameWidget::setOnSwitch); CONNECT(&power_frame, onSwitchChangeNotifier, this, &MainTab::powerOnChange); + CONNECT(&voicelimit_frame, onSwitchChangeNotifier, + this, &MainTab::voicelimitOnChange); + } void MainTab::resize(std::size_t width, std::size_t height) @@ -202,6 +225,11 @@ void MainTab::powerOnChange(bool on) settings.enable_powermap.store(on); } +void MainTab::voicelimitOnChange(bool status) +{ + settings.enable_voice_limit.store(status); +} + void MainTab::add(std::string const& title, FrameWidget& frame, Widget& content, std::size_t height, int column) { diff --git a/plugingui/maintab.h b/plugingui/maintab.h index a19b183..57aec72 100644 --- a/plugingui/maintab.h +++ b/plugingui/maintab.h @@ -39,6 +39,7 @@ #include "sampleselectionframecontent.h" #include "visualizerframecontent.h" #include "powerwidget.h" +#include "voicelimitframecontent.h" struct Settings; class SettingsNotifier; @@ -65,10 +66,11 @@ private: void resamplingOnChange(bool on); void timingOnChange(bool on); void powerOnChange(bool on); + void voicelimitOnChange(bool status); Image logo{":resources/logo.png"}; - GridLayout layout{this, 2, 49}; + GridLayout layout{this, 2, 64}; FrameWidget drumkit_frame{this, false}; FrameWidget status_frame{this, false}; @@ -80,6 +82,7 @@ private: FrameWidget sampleselection_frame{this, false, true}; FrameWidget visualizer_frame{this, false, true}; FrameWidget power_frame{this, true, true}; + FrameWidget voicelimit_frame{this, true, true}; DrumkitframeContent drumkitframe_content; StatusframeContent statusframe_content; @@ -91,6 +94,7 @@ private: SampleselectionframeContent sampleselectionframe_content; VisualizerframeContent visualizerframe_content; PowerWidget powerframe_content; + VoiceLimitFrameContent voicelimit_content; void add(std::string const& title, FrameWidget& frame, Widget& content, std::size_t height, int column); diff --git a/plugingui/voicelimitframecontent.cc b/plugingui/voicelimitframecontent.cc new file mode 100644 index 0000000..c7c8c28 --- /dev/null +++ b/plugingui/voicelimitframecontent.cc @@ -0,0 +1,123 @@ +/*************************************************************************** + * voicelimitframecontent.cc + * + * Wed Aug 26 14:53:03 CEST 2020 + * Copyright 2020 The Marlboro Man + * marlborometal@gmail.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 "voicelimitframecontent.h" + +#include <settings.h> + +namespace GUI +{ + +VoiceLimitFrameContent::VoiceLimitFrameContent(Widget* parent, + Settings& settings, + SettingsNotifier& settings_notifier) + : Widget(parent) + , settings(settings) + , settings_notifier(settings_notifier) +{ + //Setup frame. + label_text.setText(_("Per-instrument voice limit:")); + label_text.setAlignment(TextAlignment::center); + + //Setup layout + layout.setResizeChildren(false); + + auto setup_control = + [](Knob& knob, + LabeledControl& label, + GridLayout& layout, + const GridLayout::GridRange& gridrange, + float min, + float max, + float defaultval) + { + knob.resize(30, 30); + knob.showValue(false); + knob.setDefaultValue(defaultval); + knob.setRange(min, max); + label.resize(80, 80); + label.setControl(&knob); + layout.addItem(&label); + layout.setPosition(&label, gridrange); + }; + + setup_control(knob_max_voices, lc_max_voices, layout, {0, 1, 0, 1}, + 1.0f, 30.0f, Settings::voice_limit_max_default); + + setup_control(knob_rampdown_time, lc_rampdown_time, layout, {1, 2, 0, 1}, + 0.01f, 2.0f, Settings::voice_limit_rampdown_default); + + + auto voices_transform = + [this](double new_value, double scale, double offset) -> std::string + { + new_value *= scale; + new_value += offset; + return std::to_string(convertMaxVoices(new_value)); + }; + + lc_max_voices.setValueTransformationFunction(voices_transform); + + //GUI to settings. + CONNECT(&knob_max_voices, valueChangedNotifier, + this, &VoiceLimitFrameContent::maxvoicesKnobValueChanged); + + CONNECT(&knob_rampdown_time, valueChangedNotifier, + this, &VoiceLimitFrameContent::rampdownKnobValueChanged); + + //Settings to GUI + CONNECT(this, settings_notifier.voice_limit_max, + this, &VoiceLimitFrameContent::maxvoicesSettingsValueChanged); + + CONNECT(this, settings_notifier.voice_limit_rampdown, + this, &VoiceLimitFrameContent::rampdownSettingsValueChanged); +} + +void VoiceLimitFrameContent::maxvoicesKnobValueChanged(float value) +{ + settings.voice_limit_max.store((int)value); +} + +void VoiceLimitFrameContent::rampdownKnobValueChanged(float value) +{ + settings.voice_limit_rampdown.store(value); +} + +void VoiceLimitFrameContent::maxvoicesSettingsValueChanged(float value) +{ + knob_max_voices.setValue(convertMaxVoices(value)); +} + +void VoiceLimitFrameContent::rampdownSettingsValueChanged(float value) +{ + knob_rampdown_time.setValue(value); +} + +std::size_t VoiceLimitFrameContent::convertMaxVoices(float value) +{ + return static_cast<std::size_t>(value); +} + +} diff --git a/plugingui/voicelimitframecontent.h b/plugingui/voicelimitframecontent.h new file mode 100644 index 0000000..8b08014 --- /dev/null +++ b/plugingui/voicelimitframecontent.h @@ -0,0 +1,73 @@ +/* -*- Mode: c++ -*- */ +/*************************************************************************** + * voicelimitframecontent.h + * + * Wed Aug 26 14:53:03 CEST 2020 + * Copyright 2020 The Marlboro Man + * marlborometal@gmail.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 <translation.h> + +#include "label.h" +#include "knob.h" +#include "labeledcontrol.h" +#include "widget.h" + +struct Settings; +class SettingsNotifier; + +namespace GUI +{ + +class VoiceLimitFrameContent + : public Widget +{ +public: + VoiceLimitFrameContent(Widget* parent, + Settings& settings, + SettingsNotifier& settings_notifier); + +private: + void maxvoicesKnobValueChanged(float value); + void rampdownKnobValueChanged(float value); + + void maxvoicesSettingsValueChanged(float value); + void rampdownSettingsValueChanged(float value); + + std::size_t convertMaxVoices(float value); + + Settings& settings; + SettingsNotifier& settings_notifier; + + Label label_text{this}; + + GridLayout layout{this, 2, 1}; + + LabeledControl lc_max_voices{this, _("Max voices")}; + LabeledControl lc_rampdown_time{this, _("Rampdown time")}; + + Knob knob_max_voices{&lc_max_voices}; + Knob knob_rampdown_time{&lc_rampdown_time}; +}; + +} // GUI:: diff --git a/src/inputprocessor.cc b/src/inputprocessor.cc index 2da5dbc..fd6e5b9 100644 --- a/src/inputprocessor.cc +++ b/src/inputprocessor.cc @@ -252,7 +252,16 @@ bool InputProcessor::processOnset(event_t& event, std::size_t pos, return false; } - events_ds.startAddingNewGroup(instrument_id); + if(settings.enable_voice_limit.load()) + { + limitVoices(instrument_id, + settings.voice_limit_max.load(), + settings.voice_limit_rampdown.load()); + } + + //Given that audio files could be invalid, maybe we must add the new + //group just before adding the first new sample... + bool new_group_added = false; for(Channel& ch: kit.channels) { const auto af = sample->getAudioFile(ch); @@ -263,8 +272,15 @@ bool InputProcessor::processOnset(event_t& event, std::size_t pos, else { //DEBUG(inputprocessor, "Adding event %d.\n", event.offset); - auto& event_sample = events_ds.emplace<SampleEvent>(ch.num, ch.num, 1.0, af, - instr->getGroup(), instrument_id); + if(!new_group_added) + { + new_group_added=true; + events_ds.startAddingNewGroup(instrument_id); + } + + auto& event_sample = + events_ds.emplace<SampleEvent>(ch.num, ch.num, 1.0, af, + instr->getGroup(), instrument_id); event_sample.offset = (event.offset + pos) * resample_ratio; if(settings.normalized_samples.load() && sample->getNormalized()) @@ -353,3 +369,68 @@ bool InputProcessor::processStop(event_t& event) return true; } + +void InputProcessor::limitVoices(std::size_t instrument_id, + std::size_t max_voices, + float rampdown_time) +{ + const auto& group_ids=events_ds.getSampleEventGroupIDsOf(instrument_id); + + if(group_ids.size() <= max_voices) + { + return; + } + + //Filter out ramping events... + auto filter_ramping_predicate = + [this](EventGroupID group_id) -> bool + { + const auto& event_ids=events_ds.getEventIDsOf(group_id); + //TODO: This should not happen. + if(!event_ids.size()) + { + return false; + } + + const auto& sample=events_ds.get<SampleEvent>(event_ids[0]); + return !sample.rampdownInProgress(); + }; + + EventGroupIDs non_ramping; + std::copy_if(std::begin(group_ids), + std::end(group_ids), + std::back_inserter(non_ramping), filter_ramping_predicate); + + if(!non_ramping.size()) + { + return; + } + + //Let us get the eldest... + //TODO: where is the playhead? Should we add it to the offset? + auto compare_event_offsets = + [this](EventGroupID a, EventGroupID b) + { + const auto& event_ids_a=events_ds.getEventIDsOf(a); + const auto& event_ids_b=events_ds.getEventIDsOf(b); + + const auto& sample_a=events_ds.get<SampleEvent>(event_ids_a[0]); + const auto& sample_b=events_ds.get<SampleEvent>(event_ids_b[0]); + return sample_a.offset < sample_b.offset; + }; + + auto it = std::min_element(std::begin(non_ramping), + std::end(non_ramping), + compare_event_offsets); + if(it == std::end(non_ramping)) + { + return; + } + + const auto& event_ids = events_ds.getEventIDsOf(*it); + for(const auto& event_id : event_ids) + { + auto& sample=events_ds.get<SampleEvent>(event_id); + applyChoke(settings, sample, rampdown_time, sample.offset); + } +} diff --git a/src/inputprocessor.h b/src/inputprocessor.h index 3c2cd5a..971cc85 100644 --- a/src/inputprocessor.h +++ b/src/inputprocessor.h @@ -64,6 +64,11 @@ private: bool processChoke(event_t& event, std::size_t pos, double resample_ratio); bool processStop(event_t& event); + //! Ramps down samples from events_ds is there are more groups playing than + //! max_voices for a given instrument. + void limitVoices(std::size_t instrument_id, std::size_t max_voices, + float rampdown_time); + std::vector<std::unique_ptr<InputFilter>> filters; Settings& settings; diff --git a/src/settings.h b/src/settings.h index 7749adf..7507827 100644 --- a/src/settings.h +++ b/src/settings.h @@ -165,6 +165,15 @@ struct Settings // Notify UI about load errors Atomic<std::string> load_status_text; + + // Enables the ramping down of old samples once X groups of the same instrument are playing. + Atomic<bool> enable_voice_limit{false}; + // Max number of voices before old samples are ramped down. + static std::size_t constexpr voice_limit_max_default = 15; + Atomic<std::size_t> voice_limit_max{voice_limit_max_default}; + // Time it takes for an old sample to completely fall silent. + static float constexpr voice_limit_rampdown_default = 0.5f; + Atomic<float> voice_limit_rampdown{voice_limit_rampdown_default}; }; //! Settings getter class. @@ -243,6 +252,10 @@ struct SettingsGetter SettingRef<std::string> load_status_text; + SettingRef<bool> enable_voice_limit; + SettingRef<std::size_t> voice_limit_max; + SettingRef<float> voice_limit_rampdown; + SettingsGetter(Settings& settings) : drumkit_file(settings.drumkit_file) , drumkit_load_status(settings.drumkit_load_status) @@ -300,6 +313,9 @@ struct SettingsGetter , audition_instrument{settings.audition_instrument} , audition_velocity{settings.audition_velocity} , load_status_text{settings.load_status_text} + , enable_voice_limit{settings.enable_voice_limit} + , voice_limit_max{settings.voice_limit_max} + , voice_limit_rampdown{settings.voice_limit_rampdown} { } }; @@ -379,6 +395,10 @@ public: Notifier<std::string> load_status_text; + Notifier<bool> enable_voice_limit; + Notifier<std::size_t> voice_limit_max; + Notifier<float> voice_limit_rampdown; + void evaluate() { #define EVAL(x) if(settings.x.hasChanged()) { x(settings.x.getValue()); } @@ -453,6 +473,10 @@ public: EVAL(audition_velocity); EVAL(load_status_text); + + EVAL(enable_voice_limit); + EVAL(voice_limit_max); + EVAL(voice_limit_rampdown); } SettingsNotifier(Settings& settings) |