diff --git a/gtk2_ardour/midi_cue_editor.cc b/gtk2_ardour/midi_cue_editor.cc index ee13b7e27b..49d667c5d9 100644 --- a/gtk2_ardour/midi_cue_editor.cc +++ b/gtk2_ardour/midi_cue_editor.cc @@ -42,6 +42,7 @@ #include "midi_cue_view.h" #include "note_base.h" #include "prh.h" +#include "timers.h" #include "ui_config.h" #include "velocity_ghost_region.h" #include "verbose_cursor.h" @@ -308,6 +309,25 @@ MidiCueEditor::bindings_changed () _canvas->set_data (X_("ardour-bindings"), midi_bindings); } +void +MidiCueEditor::maybe_update () +{ + if (!_track) { + return; + } + + ARDOUR::TriggerPtr trigger = _track->triggerbox()->currently_playing (); + if (!trigger) { + _playhead_cursor->set_position (0); + } else { + if (trigger->active ()) { + _playhead_cursor->set_position (trigger->current_pos().samples()); + } else { + _playhead_cursor->set_position (0); + } + } +} + bool MidiCueEditor::canvas_enter_leave (GdkEventCrossing* ev) { @@ -487,7 +507,20 @@ MidiCueEditor::rec_enable_change (ARDOUR::TriggerBox* b) void MidiCueEditor::set_track (std::shared_ptr t) { + _track = t; + view->set_track (t); + + _update_connection.disconnect (); + capture_connections.drop_connections (); + + if (t) { + set_box (t->triggerbox()); + _update_connection = Timers::rapid_connect (sigc::mem_fun (*this, &MidiCueEditor::maybe_update)); + _track->DropReferences.connect (track_connection, invalidator (*this), boost::bind (&MidiCueEditor::set_track, this, nullptr), gui_context()); + } else { + set_box (nullptr); + } } void @@ -1711,4 +1744,3 @@ MidiCueEditor::selectable_owners() return std::list (); } - diff --git a/gtk2_ardour/midi_cue_editor.h b/gtk2_ardour/midi_cue_editor.h index c73fdc938c..637815011c 100644 --- a/gtk2_ardour/midi_cue_editor.h +++ b/gtk2_ardour/midi_cue_editor.h @@ -137,6 +137,7 @@ class MidiCueEditor : public CueEditor void on_samples_per_pixel_changed (); private: + std::shared_ptr _track; ArdourCanvas::GtkCanvasViewport* _canvas_viewport; ArdourCanvas::GtkCanvas* _canvas; @@ -203,6 +204,10 @@ class MidiCueEditor : public CueEditor void start_canvas_autoscroll (bool allow_horiz, bool allow_vert, const ArdourCanvas::Rect& boundary); void stop_canvas_autoscroll (); + sigc::connection _update_connection; + PBD::ScopedConnection track_connection; + void maybe_update (); + void visual_changer (const VisualChange&); void bindings_changed (); diff --git a/gtk2_ardour/trigger_page.cc b/gtk2_ardour/trigger_page.cc index 209910031b..c923233df6 100644 --- a/gtk2_ardour/trigger_page.cc +++ b/gtk2_ardour/trigger_page.cc @@ -466,8 +466,6 @@ TriggerPage::selection_changed () _midi_trig_box.set_trigger (ref); _midi_trig_box.show (); - _midi_editor->set_box (ref.box()); - std::shared_ptr mt = std::dynamic_pointer_cast (entry->strip().stripable()); assert (mt); _midi_editor->set_track (mt);