Skip to content

Commit

Permalink
Add global cycle pos cmds and show cycle in GUI
Browse files Browse the repository at this point in the history
This commit adds the commands "global_cycle_len" and "global_cycle_pos"
to sooperlooper. The current cycle position is displayed as a bar in the
quantize GUI element. This feature only works with Internal sync at the
moment, as this is the only case where sooperlooper has an internal
cycle pos (JackSync has a cycle length, but no position). Quantize has
to be set to cycle or 8th. The current cycle is only displayed when it
is >= 1s to avoid having too much visual noise in the GUI.

When recording the first loop in sync internal + quantize cycle + first
loop on sync it is hard to hit the first note at the beginning of the
cycle. A visual indicator of where we are in the cycle helps to be on
time in situations where no other cue is available.

ChoiceBox has been augmented with the feature to draw a bar in its
background. It is similar to what SliderBar can do but has less options
(e.g. it only displays values from 0.0f to 1.0f, no value text
rendering).
  • Loading branch information
sebageek authored and essej committed Jun 17, 2023
1 parent 3230300 commit 221db5f
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/command_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ CommandMap::CommandMap()
add_global_control("use_midi_start", Event::UseMidiStart, UnitBoolean, 0.0f, 1.0f, 1.0f);
add_global_control("use_midi_stop", Event::UseMidiStop, UnitBoolean, 0.0f, 1.0f, 1.0f);
add_global_control("send_midi_start_on_trigger", Event::SendMidiStartOnTrigger, UnitBoolean, 0.0f, 1.0f, 1.0f);
add_global_control("global_cycle_len", Event::GlobalCycleLen, UnitSeconds, 0.0f, 1e6);
add_global_control("global_cycle_pos", Event::GlobalCyclePos, UnitSeconds, 0.0f, 1e6);
_str_ctrl_map.insert (_global_controls.begin(), _global_controls.end());

// reverse it
Expand Down
6 changes: 6 additions & 0 deletions src/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1542,6 +1542,12 @@ Engine::get_control_value (Event::control_t ctrl, int8_t instance)
else if (ctrl == Event::JackTimebaseMaster) {
return _jack_timebase_master ? 1.0f: 0.0f;
}
else if (ctrl == Event::GlobalCycleLen) {
return _tempo_frames / _driver->get_samplerate();
}
else if (ctrl == Event::GlobalCyclePos) {
return _tempo_counter / _driver->get_samplerate();
}

}

Expand Down
4 changes: 3 additions & 1 deletion src/event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,9 @@ namespace SooperLooper {
// Put all new controls at the end to avoid screwing up the order of existing AU sessions (who store these numbers)
ReplaceQuantized,
SendMidiStartOnTrigger,
DiscretePreFader
DiscretePreFader,
GlobalCycleLen,
GlobalCyclePos
} Control;

int8_t Instance;
Expand Down
19 changes: 18 additions & 1 deletion src/gui/choice_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ ChoiceBox::ChoiceBox(wxWindow * parent, wxWindowID id, bool bindable, const wxPo
_popup_menu = 0;
_data_value = 0;
_bindable = bindable;
_bar_value = 0.0f;

_bgcolor.Set(0,0,0);
_bgbrush.SetColour (_bgcolor);
Expand All @@ -69,7 +70,7 @@ ChoiceBox::ChoiceBox(wxWindow * parent, wxWindowID id, bool bindable, const wxPo
_textcolor = *wxWHITE;
_barcolor.Set(14, 50, 89);
_overbarcolor.Set(20, 40, 50);
_barbrush.SetColour(_bgcolor);
_barbrush.SetColour(_barcolor);

_bgbordercolor.Set(30,30,30);
_bordercolor.Set(67, 83, 103);
Expand Down Expand Up @@ -429,6 +430,11 @@ void ChoiceBox::draw_area(wxDC & dc)
shape[5].x = _width -1; shape[5].y = _height -1;

dc.DrawPolygon (6, shape);

if (_bar_value > 0.0f) {
dc.SetBrush(_barbrush);
dc.DrawRectangle (1, 1, (wxCoord)(_width*_bar_value-1), _height-2);
}

dc.SetPen(*wxTRANSPARENT_PEN);

Expand All @@ -443,3 +449,14 @@ void ChoiceBox::draw_area(wxDC & dc)


}

void ChoiceBox::set_bar_value(float val) {
if(val >= 0.0f && val <= 1.0f && _bar_value != val) {
_bar_value = val;
Refresh(false);
}
}

float ChoiceBox::get_bar_value() {
return _bar_value;
}
3 changes: 3 additions & 0 deletions src/gui/choice_box.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ class ChoiceBox
static void set_use_mousewheel_default (bool flag) { s_use_wheel_def = flag; }
static bool get_use_mousewheel_default () { return s_use_wheel_def; }

void set_bar_value (float val);
float get_bar_value ();

sigc::signal2<void, int, wxString> value_changed;
sigc::signal0<void> bind_request;
Expand Down Expand Up @@ -138,6 +140,7 @@ class ChoiceBox

bool _dragging;
int _last_x;
float _bar_value;

private:
// any class wishing to process wxWindows events must use this macro
Expand Down
4 changes: 4 additions & 0 deletions src/gui/loop_control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,10 +385,14 @@ LoopControl::register_global_updates(bool unreg)
if (unreg) {
lo_send(_osc_addr, "/unregister_auto_update", "siss", "in_peak_meter", 100, _our_url.c_str(), "/ctrl");
lo_send(_osc_addr, "/unregister_auto_update", "siss", "out_peak_meter", 100, _our_url.c_str(), "/ctrl");
lo_send(_osc_addr, "/unregister_auto_update", "siss", "global_cycle_len", 100, _our_url.c_str(), "/ctrl");
lo_send(_osc_addr, "/unregister_auto_update", "siss", "global_cycle_pos", 100, _our_url.c_str(), "/ctrl");
}
else {
lo_send(_osc_addr, "/register_auto_update", "siss", "in_peak_meter", 100, _our_url.c_str(), "/ctrl");
lo_send(_osc_addr, "/register_auto_update", "siss", "out_peak_meter", 100, _our_url.c_str(), "/ctrl");
lo_send(_osc_addr, "/register_auto_update", "siss", "global_cycle_len", 100, _our_url.c_str(), "/ctrl");
lo_send(_osc_addr, "/register_auto_update", "siss", "global_cycle_pos", 100, _our_url.c_str(), "/ctrl");
}
}

Expand Down
16 changes: 14 additions & 2 deletions src/gui/main_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ enum {
ID_MuteQuantCheck,
ID_OdubQuantCheck,
ID_SmartEighthCheck,
ID_ReplQuantCheck
ID_ReplQuantCheck,
ID_GlobalCyclePos
};


Expand Down Expand Up @@ -294,7 +295,6 @@ MainPanel::init()
_repl_quant_check->bind_request.connect (sigc::bind(mem_fun (*this, &MainPanel::on_bind_request), wxT("replace_quantized")));
rowsizer->Add (_repl_quant_check, 0, wxALL|wxEXPAND, 2);


rowsizer->Add (1, 1, 1);

wxStaticBitmap * logobit = new wxStaticBitmap(_top_panel, -1, wxBitmap(sl_logo_xpm));
Expand Down Expand Up @@ -740,6 +740,18 @@ MainPanel::update_controls()
_loop_control->get_global_value(wxT("selected_loop_num"), val);
set_curr_loop ((int) val);
}

if (_loop_control->is_global_updated(wxT("global_cycle_pos"))) {
float gclen, gcpos;
_loop_control->get_global_value(wxT("global_cycle_len"), gclen);
_loop_control->get_global_value(wxT("global_cycle_pos"), gcpos);
val = 0.0f;
// only display global cycle len if it is >= 1s to reduce visual noise
if(gclen >= 1.0f)
val = gcpos / gclen;
_quantize_choice->set_bar_value(val);
}

}

void
Expand Down

0 comments on commit 221db5f

Please sign in to comment.