From caaf19cf0e45fb1e7156ee82ee49d396f286b56b Mon Sep 17 00:00:00 2001 From: Aleks Rutins Date: Sat, 15 Apr 2023 20:44:51 -0400 Subject: [PATCH] Add Transmogrifier --- dynamite.ttl | 9 +++++++++ gui.cc | 21 ++++++++++++--------- plugin.cc | 6 +++++- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/dynamite.ttl b/dynamite.ttl index b46a5a1..c606f9a 100644 --- a/dynamite.ttl +++ b/dynamite.ttl @@ -73,4 +73,13 @@ lv2:default 0.5 ; lv2:minimum 0.0 ; lv2:maximum 1.0 ; + ] , + [ + a lv2:InputPort , lv2:ControlPort ; + lv2:index 6 ; + lv2:symbol "algorithm_mix" ; + lv2:name "Transmogrify" ; + lv2:default 0.5 ; + lv2:minimum 0.0 ; + lv2:maximum 1.0 ; ] . \ No newline at end of file diff --git a/gui.cc b/gui.cc index 08db9a6..0a3c520 100644 --- a/gui.cc +++ b/gui.cc @@ -24,9 +24,10 @@ namespace Dynamite { Scale *threshold_scale; Scale *gain_scale; Scale *mix_scale; - Scale *create_vscale(p_port_enum nport) { + Scale *transmogrify_scale; + Scale *create_scale(p_port_enum nport, Orientation orient = ORIENTATION_VERTICAL) { auto port = p_ports[nport]; - auto result = manage(new VScale(port.min, port.max, 0.01)); + Scale *result = manage(orient == ORIENTATION_VERTICAL ? (Scale *)new VScale(port.min, port.max, 0.01) : (Scale *)new HScale(port.min, port.max, 0.01)); auto scale_slot = bind<0>(bind<0>(bind<0>(&DriveGUI::write_control_ptr, this), (uint32_t)nport), result); result->signal_value_changed().connect(scale_slot); return result; @@ -38,20 +39,20 @@ namespace Dynamite { vbox->add(*manage(new Label("Dynamite"))); - drive_scale = create_vscale(p_drive); + drive_scale = create_scale(p_drive); hbox->add(*manage(new LabeledWidget("Drive", *drive_scale))); - threshold_scale = create_vscale(p_threshold); + threshold_scale = create_scale(p_threshold); hbox->add(*manage(new LabeledWidget("Threshold", *threshold_scale))); - gain_scale = create_vscale(p_gain); + gain_scale = create_scale(p_gain); hbox->add(*manage(new LabeledWidget("Gain", *gain_scale))); vbox->add(*hbox); - auto mix = p_ports[p_mix]; - mix_scale = manage(new HScale(mix.min, mix.max, 0.01)); - auto mix_slot = bind<0>(bind<0>(bind<0>(&DriveGUI::write_control_ptr, this), (uint32_t)p_mix), mix_scale); - mix_scale->signal_value_changed().connect(mix_slot); + transmogrify_scale = create_scale(p_algorithm_mix, ORIENTATION_HORIZONTAL); + vbox->add(*manage(new LabeledWidget("Transmogrify", *transmogrify_scale))); + mix_scale = create_scale(p_mix, ORIENTATION_HORIZONTAL); vbox->add(*manage(new LabeledWidget("Mix", *mix_scale))); + add(*vbox); } @@ -68,6 +69,8 @@ namespace Dynamite { threshold_scale->set_value(value); break; case p_gain: gain_scale->set_value(value); break; + case p_algorithm_mix: + transmogrify_scale->set_value(value); break; case p_mix: mix_scale->set_value(value); break; diff --git a/plugin.cc b/plugin.cc index 4f6b599..631ef73 100644 --- a/plugin.cc +++ b/plugin.cc @@ -7,6 +7,7 @@ namespace Dynamite { const float threshCoeff = dbCo(*p(p_threshold)); const float gainCoeff = dbCo(*p(p_gain)); const float mix = *p(p_mix); + const float algoMix = *p(p_algorithm_mix); const float *input = p(p_audio_in); float *output = p(p_audio_out); @@ -22,7 +23,10 @@ namespace Dynamite { dist = dist * gainCoeff; - output[pos] = (mix * dist) + ((1.0 - mix) * input[pos] * gainCoeff); + float transmogrifier = threshCoeff * gainCoeff; + float transmogrified = (input[pos] < 0 ? -transmogrifier : transmogrifier); + + output[pos] = (mix * ((algoMix * transmogrified) + ((1.0 - algoMix) * dist))) + ((1.0 - mix) * input[pos] * gainCoeff); } } }