From: Robin Gareus Date: Thu, 23 Feb 2017 21:31:03 +0000 (+0100) Subject: Lua bindings to access editor selection + region selection bindings X-Git-Tag: 5.7~40 X-Git-Url: https://main.carlh.net/gitweb/?p=ardour.git;a=commitdiff_plain;h=1e4e97019da3e90f89614da51ac537ed2041bb55 Lua bindings to access editor selection + region selection bindings --- diff --git a/gtk2_ardour/editor.cc b/gtk2_ardour/editor.cc index bb769e30ef..ba07222bdf 100644 --- a/gtk2_ardour/editor.cc +++ b/gtk2_ardour/editor.cc @@ -5087,6 +5087,24 @@ Editor::get_regions_corresponding_to (boost::shared_ptr region, vector region) const +{ + for (TrackViewList::const_iterator i = track_views.begin(); i != track_views.end(); ++i) { + RouteTimeAxisView* tatv; + if ((tatv = dynamic_cast (*i)) != 0) { + if (!tatv->track()) { + continue; + } + RegionView* marv = tatv->view()->find_view (region); + if (marv) { + return marv; + } + } + } + return NULL; +} + void Editor::show_rhythm_ferret () { diff --git a/gtk2_ardour/editor.h b/gtk2_ardour/editor.h index 458753d638..01ef86874e 100644 --- a/gtk2_ardour/editor.h +++ b/gtk2_ardour/editor.h @@ -257,6 +257,8 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD bool get_selection_extents (framepos_t &start, framepos_t &end) const; // the time extents of the current selection, whether Range, Region(s), Control Points, or Notes Selection& get_cut_buffer() const { return *cut_buffer; } + void set_selection (std::list, Selection::Operation); + bool extend_selection_to_track (TimeAxisView&); void play_selection (); @@ -732,6 +734,8 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD void get_equivalent_regions (RegionView* rv, std::vector &, PBD::PropertyID) const; RegionSelection get_equivalent_regions (RegionSelection &, PBD::PropertyID) const; + RegionView* get_regionview_from_region (boost::shared_ptr) const; + void mapover_tracks (sigc::slot sl, TimeAxisView*, PBD::PropertyID) const; void mapover_tracks_with_unique_playlists (sigc::slot sl, TimeAxisView*, PBD::PropertyID) const; diff --git a/gtk2_ardour/editor_selection.cc b/gtk2_ardour/editor_selection.cc index d214d48a32..8c6b16f51d 100644 --- a/gtk2_ardour/editor_selection.cc +++ b/gtk2_ardour/editor_selection.cc @@ -893,6 +893,30 @@ out: return commit; } +void +Editor::set_selection (std::list s, Selection::Operation op) +{ + if (s.empty()) { + return; + } + begin_reversible_selection_op (X_("set selection")); + switch (op) { + case Selection::Toggle: + selection->toggle (s); + break; + case Selection::Set: + selection->set (s); + break; + case Selection::Extend: + selection->add (s); + break; + case Selection::Add: + selection->add (s); + break; + } + + commit_reversible_selection_op () ; +} void Editor::set_selected_regionview_from_region_list (boost::shared_ptr region, Selection::Operation op) diff --git a/gtk2_ardour/luainstance.cc b/gtk2_ardour/luainstance.cc index 1a8bf12d62..c8a4fe9e3b 100644 --- a/gtk2_ardour/luainstance.cc +++ b/gtk2_ardour/luainstance.cc @@ -37,8 +37,10 @@ #include "luainstance.h" #include "luasignal.h" #include "marker.h" +#include "region_view.h" #include "processor_box.h" #include "time_axis_view.h" +#include "time_axis_view_item.h" #include "selection.h" #include "script_selector.h" #include "timers.h" @@ -582,8 +584,17 @@ LuaInstance::register_classes (lua_State* L) .endClass () #endif + .beginClass ("Selectable") + .endClass () + .deriveClass ("TimeAxisViewItem") + .endClass () + .deriveClass ("RegionView") + .endClass () + + .beginStdCPtrList ("SelectionList") + .endClass () + .beginClass ("RegionSelection") - .addFunction ("clear_all", &RegionSelection::clear_all) .addFunction ("start", &RegionSelection::start) .addFunction ("end_frame", &RegionSelection::end_frame) .addFunction ("n_midi_regions", &RegionSelection::n_midi_regions) @@ -646,6 +657,8 @@ LuaInstance::register_classes (lua_State* L) .addFunction ("get_cut_buffer", &PublicEditor::get_cut_buffer) .addRefFunction ("get_selection_extents", &PublicEditor::get_selection_extents) + .addFunction ("set_selection", &PublicEditor::set_selection) + .addFunction ("play_selection", &PublicEditor::play_selection) .addFunction ("play_with_preroll", &PublicEditor::play_with_preroll) .addFunction ("maybe_locate_with_edit_preroll", &PublicEditor::maybe_locate_with_edit_preroll) @@ -691,6 +704,8 @@ LuaInstance::register_classes (lua_State* L) .addFunction ("set_selected_mixer_strip", &PublicEditor::set_selected_mixer_strip) .addFunction ("hide_track_in_display", &PublicEditor::hide_track_in_display) #endif + + .addFunction ("get_regionview_from_region", &PublicEditor::get_regionview_from_region) .addFunction ("set_stationary_playhead", &PublicEditor::set_stationary_playhead) .addFunction ("stationary_playhead", &PublicEditor::stationary_playhead) .addFunction ("set_follow_playhead", &PublicEditor::set_follow_playhead) @@ -783,6 +798,13 @@ LuaInstance::register_classes (lua_State* L) .addConst ("PunchOut", ArdourMarker::Type(ArdourMarker::PunchOut)) .endNamespace () + .beginNamespace ("SelectionOp") + .addConst ("Toggle", Selection::Operation(Selection::Toggle)) + .addConst ("Set", Selection::Operation(Selection::Set)) + .addConst ("Extend", Selection::Operation(Selection::Extend)) + .addConst ("Add", Selection::Operation(Selection::Add)) + .endNamespace () + .endNamespace (); // end ArdourUI // Editing Symbols diff --git a/gtk2_ardour/public_editor.h b/gtk2_ardour/public_editor.h index 5cfedb11f1..62cb9f2bcb 100644 --- a/gtk2_ardour/public_editor.h +++ b/gtk2_ardour/public_editor.h @@ -204,9 +204,13 @@ class PublicEditor : public Gtkmm2ext::Tabbable { virtual framepos_t playhead_cursor_sample () const = 0; virtual double sample_to_pixel (framepos_t frame) const = 0; virtual double sample_to_pixel_unrounded (framepos_t frame) const = 0; + virtual Selection& get_selection () const = 0; virtual bool get_selection_extents (framepos_t &start, framepos_t &end) const = 0; virtual Selection& get_cut_buffer () const = 0; + + virtual void set_selection (std::list, Selection::Operation) = 0; + virtual bool extend_selection_to_track (TimeAxisView&) = 0; virtual void play_selection () = 0; virtual void play_with_preroll () = 0; @@ -348,6 +352,7 @@ class PublicEditor : public Gtkmm2ext::Tabbable { virtual RouteTimeAxisView* get_route_view_by_route_id (const PBD::ID& id) const = 0; virtual void get_equivalent_regions (RegionView* rv, std::vector&, PBD::PropertyID) const = 0; + virtual RegionView* get_regionview_from_region (boost::shared_ptr) const = 0; sigc::signal ZoomChanged; sigc::signal Realized; diff --git a/scripts/select_every_2nd_region.lua b/scripts/select_every_2nd_region.lua new file mode 100644 index 0000000000..4e6d156f5a --- /dev/null +++ b/scripts/select_every_2nd_region.lua @@ -0,0 +1,42 @@ +ardour { + ["type"] = "EditorAction", + name = "Region Select/2", + license = "MIT", + author = "Ardour Team", + description = [[select every 2nd region on all selected tracks]] +} + +-- select every 2nd region on all selected tracks +function factory () return function () + + local sl = ArdourUI.SelectionList () -- empty selection list + + local sel = Editor:get_selection () -- get current selection + -- for each selected track/bus.. + for route in sel.tracks:routelist ():iter () do + -- consider only tracks + local track = route:to_track () + if track:isnil() then + goto continue + end + + local skip = false; + -- iterate over all regions of the given track + for region in track:playlist():region_list():iter() do + if skip then + -- skip every 2nd region + skip = false; + else + skip = true; + -- get RegionView (GUI object to be selected) + local rv = Editor:get_regionview_from_region (region) + -- add it to the list of Objects to be selected + sl:push_back (rv); + end + end + ::continue:: + end + + -- set/replace current selection in the editor + Editor:set_selection (sl, ArdourUI.SelectionOp.Set); +end end