From 018fa325c8f4d5b4c63b3e078e4efb06a1a958ae Mon Sep 17 00:00:00 2001 From: Sebastian Lohff Date: Sat, 16 Oct 2021 13:58:39 +0200 Subject: [PATCH] Add setting to copy loop flags on loop create A new setting now controls if a newly created loop inherits all flags from the previous loop (sync, play sync, feedback play, tempo stretch, discrete prefader). This is a gui-only implementation. The MainPanel class has an extra counter to track when this instance of slgui has created a panel, to then copy the values over. This was done to not interfere with other sooperlooper clients that might not wish the values to be copied. --- src/gui/latency_panel.cpp | 10 +++++++++- src/gui/latency_panel.hpp | 1 + src/gui/main_panel.cpp | 37 ++++++++++++++++++++++++++++++++++--- src/gui/main_panel.hpp | 4 ++++ 4 files changed, 48 insertions(+), 4 deletions(-) diff --git a/src/gui/latency_panel.cpp b/src/gui/latency_panel.cpp index 92a25c7a..1c6d25cf 100644 --- a/src/gui/latency_panel.cpp +++ b/src/gui/latency_panel.cpp @@ -44,7 +44,8 @@ enum { ID_UseMidiStop, ID_SendMidiStartOnTrigger, ID_OutputClockCheck, - ID_SliderMousewheelCheck + ID_SliderMousewheelCheck, + ID_CopyLoopValuesOnCreateCheck }; BEGIN_EVENT_TABLE(SooperLooperGui::LatencyPanel, wxPanel) @@ -57,6 +58,7 @@ BEGIN_EVENT_TABLE(SooperLooperGui::LatencyPanel, wxPanel) EVT_CHECKBOX (ID_SendMidiStartOnTrigger, SooperLooperGui::LatencyPanel::on_check) EVT_CHECKBOX(ID_OutputClockCheck, SooperLooperGui::LatencyPanel::on_check) EVT_CHECKBOX(ID_SliderMousewheelCheck, SooperLooperGui::LatencyPanel::on_check) + EVT_CHECKBOX(ID_CopyLoopValuesOnCreateCheck, SooperLooperGui::LatencyPanel::on_check) EVT_TIMER(ID_UpdateTimer, SooperLooperGui::LatencyPanel::OnUpdateTimer) EVT_SIZE (SooperLooperGui::LatencyPanel::onSize) @@ -195,6 +197,8 @@ void LatencyPanel::init() _slider_mousewheel_check = new wxCheckBox(this, ID_SliderMousewheelCheck, wxT("Allow mouse scroll wheel to change sliders")); topsizer->Add(_slider_mousewheel_check, 0, wxALL, 3); + _copy_loop_values_on_create_check = new wxCheckBox(this, ID_CopyLoopValuesOnCreateCheck, wxT("Copy loop flags from last loop when creating a new one")); + topsizer->Add(_copy_loop_values_on_create_check, 0, wxALL, 3); _update_timer = new wxTimer(this, ID_UpdateTimer); _update_timer->Start(5000, true); @@ -258,6 +262,7 @@ void LatencyPanel::refresh_state() } _slider_mousewheel_check->SetValue(_parent->get_sliders_allow_mousewheel() ); + _copy_loop_values_on_create_check->SetValue(_parent->get_copy_loop_values() ); if (_auto_check->GetValue()) { @@ -303,6 +308,9 @@ void LatencyPanel::on_check (wxCommandEvent &ev) else if (ev.GetId() == ID_AutoDisableCheck) { lcontrol.post_ctrl_change (-2, wxT("auto_disable_latency"), _auto_disable_check->GetValue() ? 1.0f : 0.0f); } + else if (ev.GetId() == ID_CopyLoopValuesOnCreateCheck) { + _parent->set_copy_loop_values (_copy_loop_values_on_create_check->GetValue()); + } diff --git a/src/gui/latency_panel.hpp b/src/gui/latency_panel.hpp index 6cd1293d..14deb728 100644 --- a/src/gui/latency_panel.hpp +++ b/src/gui/latency_panel.hpp @@ -81,6 +81,7 @@ class LatencyPanel wxCheckBox * _output_clock_check; wxCheckBox * _slider_mousewheel_check; + wxCheckBox * _copy_loop_values_on_create_check; MainPanel * _parent; diff --git a/src/gui/main_panel.cpp b/src/gui/main_panel.cpp index 1f8056a6..cf3cbad3 100644 --- a/src/gui/main_panel.cpp +++ b/src/gui/main_panel.cpp @@ -129,6 +129,8 @@ END_EVENT_TABLE() _add_num_channels = 1; _add_discrete = true; _add_secs_channel = 40.0f; + _copy_loop_values = false; + _copy_loop_values_counter = 0; _default_position.x = 100; _default_position.y = 100; @@ -450,6 +452,23 @@ MainPanel::init_loopers (int count) looperpan->set_index(_looper_panels.size()); _main_sizer->Add (looperpan, 0, wxEXPAND|wxALL, 0); _looper_panels.push_back (looperpan); + + // copy settings of last loop (but only if we created it and if there is more than one loop) + if (_copy_loop_values && _looper_panels.size() > 1 && _copy_loop_values_counter > 0) { + long curr_loop = _looper_panels.size() - 1; + float val; + + const wchar_t *sync_settings[] = {wxT("sync"), wxT("playback_sync"), wxT("use_feedback_play"), + wxT("tempo_stretch"), wxT("discrete_prefader")}; + for(int i=0; i<5; i++) { + _loop_control->get_value(curr_loop-1, sync_settings[i], val); + if(val > 0.0f || i == 4) // disable val check for prefader, as it's default is "on" + _loop_control->post_ctrl_change(curr_loop, sync_settings[i], 1.0f); + + } + _copy_loop_values_counter--; + } + } } else if (count < (int)_looper_panels.size()) { @@ -832,15 +851,21 @@ MainPanel::do_add_loop (const string & type) { LoopControl::SpawnConfig & sconf = _loop_control->get_spawn_config(); + bool loop_created; + long num_loops = sconf.num_loops; if (type == "mono") { - _loop_control->post_add_loop (1, sconf.mem_secs, sconf.discrete_io); + loop_created = _loop_control->post_add_loop (1, sconf.mem_secs, sconf.discrete_io); } else if (type == "stereo") { - _loop_control->post_add_loop (2, sconf.mem_secs, sconf.discrete_io); + loop_created = _loop_control->post_add_loop (2, sconf.mem_secs, sconf.discrete_io); } else { - _loop_control->post_add_loop(); + loop_created = _loop_control->post_add_loop(); + } + + if (_copy_loop_values && loop_created && num_loops >= 1) { + _copy_loop_values_counter++; } } @@ -1354,6 +1379,10 @@ bool MainPanel::load_rc() set_sliders_allow_mousewheel( (bool) atoi (prop->value().c_str())); } + if ((prop = rootNode->property ("copy_loop_values_on_create")) != 0) { + set_copy_loop_values( (bool) atoi (prop->value().c_str())); + } + XMLNode * bindingsNode = rootNode->find_named_node ("KeyBindings"); @@ -1403,6 +1432,8 @@ bool MainPanel::save_rc() rootNode->add_property ("window_y_pos", buf); snprintf(buf, sizeof(buf), "%d", (int)_sliders_allow_mousewheel); rootNode->add_property ("sliders_allow_mousewheel", buf); + snprintf(buf, sizeof(buf), "%d", (int)_copy_loop_values); + rootNode->add_property ("copy_loop_values_on_create", buf); configdoc.set_root (rootNode); diff --git a/src/gui/main_panel.hpp b/src/gui/main_panel.hpp index 57f6af66..041840e6 100644 --- a/src/gui/main_panel.hpp +++ b/src/gui/main_panel.hpp @@ -89,6 +89,8 @@ class MainPanel void set_force_local(bool flag) { _force_local = flag; } bool get_force_local() const { return _force_local; } + void set_copy_loop_values(bool flag) { _copy_loop_values = flag; } + bool get_copy_loop_values() { return _copy_loop_values; } void init_loopers (int count); @@ -226,6 +228,8 @@ class MainPanel wxString _last_used_path; bool _sliders_allow_mousewheel; + bool _copy_loop_values; + int _copy_loop_values_counter; private: // any class wishing to process wxWindows events must use this macro