From f433b4e735ab5ff5f7f7d89d38d0c25de3641cfa Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Thu, 16 Aug 2007 17:12:30 +0000 Subject: [PATCH] various changes (improvements, hopefully) to range mode menus and related matters git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@2317 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/editor.cc | 86 ++++++++++++++++++++++++++------ gtk2_ardour/editor.h | 6 ++- gtk2_ardour/editor_audiotrack.cc | 28 +++++++---- gtk2_ardour/editor_markers.cc | 55 +++----------------- gtk2_ardour/editor_ops.cc | 18 ++++++- 5 files changed, 119 insertions(+), 74 deletions(-) diff --git a/gtk2_ardour/editor.cc b/gtk2_ardour/editor.cc index fb9f4eee76..3f84140232 100644 --- a/gtk2_ardour/editor.cc +++ b/gtk2_ardour/editor.cc @@ -1387,7 +1387,7 @@ Editor::popup_track_context_menu (int button, int32_t time, ItemType item_type, return; } - if (clicked_audio_trackview && clicked_audio_trackview->audio_track()) { + if (item_type != SelectionItem && clicked_audio_trackview && clicked_audio_trackview->audio_track()) { /* Bounce to disk */ @@ -1554,7 +1554,8 @@ Editor::build_track_selection_context_menu (nframes_t ignored) edit_items.clear (); add_selection_context_items (edit_items); - add_dstream_context_items (edit_items); + // edit_items.push_back (SeparatorElem()); + // add_dstream_context_items (edit_items); return &track_selection_context_menu; } @@ -1789,15 +1790,12 @@ Editor::add_region_context_items (AudioStreamView* sv, boost::shared_ptr } void -Editor::add_selection_context_items (Menu_Helpers::MenuList& edit_items) +Editor::add_selection_context_items (Menu_Helpers::MenuList& items) { using namespace Menu_Helpers; - Menu *selection_menu = manage (new Menu); - MenuList& items = selection_menu->items(); - selection_menu->set_name ("ArdourContextMenu"); items.push_back (MenuElem (_("Play range"), mem_fun(*this, &Editor::play_selection))); - items.push_back (MenuElem (_("Loop range"), mem_fun(*this, &Editor::set_route_loop_selection))); + items.push_back (MenuElem (_("Loop range"), bind (mem_fun(*this, &Editor::set_loop_from_selection), true))); #ifdef FFT_ANALYSIS items.push_back (SeparatorElem()); @@ -1805,15 +1803,22 @@ Editor::add_selection_context_items (Menu_Helpers::MenuList& edit_items) #endif items.push_back (SeparatorElem()); - items.push_back (MenuElem (_("Separate range to track"), mem_fun(*this, &Editor::separate_region_from_selection))); - items.push_back (MenuElem (_("Separate range to region list"), mem_fun(*this, &Editor::new_region_from_selection))); + items.push_back (MenuElem (_("Extend Range to End of Region"), bind (mem_fun(*this, &Editor::extend_selection_to_end_of_region), false))); + items.push_back (MenuElem (_("Extend Range to Start of Region"), bind (mem_fun(*this, &Editor::extend_selection_to_start_of_region), false))); + + items.push_back (SeparatorElem()); + items.push_back (MenuElem (_("Convert to region in-place"), mem_fun(*this, &Editor::separate_region_from_selection))); + items.push_back (MenuElem (_("Convert to region in region list"), mem_fun(*this, &Editor::new_region_from_selection))); items.push_back (SeparatorElem()); items.push_back (MenuElem (_("Select all in range"), mem_fun(*this, &Editor::select_all_selectables_using_time_selection))); + + items.push_back (SeparatorElem()); + items.push_back (MenuElem (_("Set loop from selection"), bind (mem_fun(*this, &Editor::set_loop_from_selection), false))); + items.push_back (MenuElem (_("Set punch from selection"), mem_fun(*this, &Editor::set_punch_from_selection))); + items.push_back (SeparatorElem()); items.push_back (MenuElem (_("Add Range Markers"), mem_fun (*this, &Editor::add_location_from_selection))); - items.push_back (MenuElem (_("Set range to loop range"), mem_fun(*this, &Editor::set_selection_from_loop))); - items.push_back (MenuElem (_("Set range to punch range"), mem_fun(*this, &Editor::set_selection_from_punch))); items.push_back (SeparatorElem()); items.push_back (MenuElem (_("Crop region to range"), mem_fun(*this, &Editor::crop_region_to_selection))); items.push_back (MenuElem (_("Fill range with region"), mem_fun(*this, &Editor::region_fill_selection))); @@ -1822,9 +1827,6 @@ Editor::add_selection_context_items (Menu_Helpers::MenuList& edit_items) items.push_back (SeparatorElem()); items.push_back (MenuElem (_("Bounce range"), mem_fun(*this, &Editor::bounce_range_selection))); items.push_back (MenuElem (_("Export range"), mem_fun(*this, &Editor::export_selection))); - - edit_items.push_back (MenuElem (_("Range"), *selection_menu)); - edit_items.push_back (SeparatorElem()); } void @@ -3830,3 +3832,59 @@ Editor::edit_cursor_position(bool sync) return edit_cursor->current_frame; } + +void +Editor::set_loop_range (nframes_t start, nframes_t end, string cmd) +{ + if (!session) return; + + begin_reversible_command (cmd); + + Location* tll; + + if ((tll = transport_loop_location()) == 0) { + Location* loc = new Location (start, end, _("Loop"), Location::IsAutoLoop); + XMLNode &before = session->locations()->get_state(); + session->locations()->add (loc, true); + session->set_auto_loop_location (loc); + XMLNode &after = session->locations()->get_state(); + session->add_command (new MementoCommand(*(session->locations()), &before, &after)); + } + else { + XMLNode &before = tll->get_state(); + tll->set_hidden (false, this); + tll->set (start, end); + XMLNode &after = tll->get_state(); + session->add_command (new MementoCommand(*tll, &before, &after)); + } + + commit_reversible_command (); +} + +void +Editor::set_punch_range (nframes_t start, nframes_t end, string cmd) +{ + if (!session) return; + + begin_reversible_command (cmd); + + Location* tpl; + + if ((tpl = transport_punch_location()) == 0) { + Location* loc = new Location (start, end, _("Loop"), Location::IsAutoPunch); + XMLNode &before = session->locations()->get_state(); + session->locations()->add (loc, true); + session->set_auto_loop_location (loc); + XMLNode &after = session->locations()->get_state(); + session->add_command (new MementoCommand(*(session->locations()), &before, &after)); + } + else { + XMLNode &before = tpl->get_state(); + tpl->set_hidden (false, this); + tpl->set (start, end); + XMLNode &after = tpl->get_state(); + session->add_command (new MementoCommand(*tpl, &before, &after)); + } + + commit_reversible_command (); +} diff --git a/gtk2_ardour/editor.h b/gtk2_ardour/editor.h index ba2815217b..c21becc1ae 100644 --- a/gtk2_ardour/editor.h +++ b/gtk2_ardour/editor.h @@ -1039,7 +1039,11 @@ class Editor : public PublicEditor void add_location_from_audio_region (); void add_location_from_selection (); - void set_route_loop_selection (); + void set_loop_from_selection (bool play); + void set_punch_from_selection (); + + void set_loop_range (nframes_t start, nframes_t end, std::string cmd); + void set_punch_range (nframes_t start, nframes_t end, std::string cmd); void add_location_from_playhead_cursor (); diff --git a/gtk2_ardour/editor_audiotrack.cc b/gtk2_ardour/editor_audiotrack.cc index 6c74146d75..755437c628 100644 --- a/gtk2_ardour/editor_audiotrack.cc +++ b/gtk2_ardour/editor_audiotrack.cc @@ -26,11 +26,13 @@ #include "region_view.h" #include "selection.h" +#include "i18n.h" + using namespace ARDOUR; using namespace PBD; void -Editor::set_route_loop_selection () +Editor::set_loop_from_selection (bool play) { if (session == 0 || selection->time.empty()) { return; @@ -38,18 +40,26 @@ Editor::set_route_loop_selection () nframes_t start = selection->time[clicked_selection].start; nframes_t end = selection->time[clicked_selection].end; + + set_loop_range (start, end, _("set loop range from selection")); - Location* loc = transport_loop_location(); - - if (loc) { - - loc->set (start, end); - - // enable looping, reposition and start rolling + if (play) { session->request_play_loop (true); - session->request_locate (loc->start(), true); + session->request_locate (start, true); + } +} + +void +Editor::set_punch_from_selection () +{ + if (session == 0 || selection->time.empty()) { + return; } + nframes_t start = selection->time[clicked_selection].start; + nframes_t end = selection->time[clicked_selection].end; + + set_punch_range (start, end, _("set punch range from selection")); } void diff --git a/gtk2_ardour/editor_markers.cc b/gtk2_ardour/editor_markers.cc index 29a212f2f5..c9d30486fb 100644 --- a/gtk2_ardour/editor_markers.cc +++ b/gtk2_ardour/editor_markers.cc @@ -488,12 +488,13 @@ Editor::build_range_marker_menu (bool loop_or_punch) } else { range_marker_menu = markerMenu; } + MenuList& items = markerMenu->items(); markerMenu->set_name ("ArdourContextMenu"); items.push_back (MenuElem (_("Locate to Range Mark"), mem_fun(*this, &Editor::marker_menu_set_playhead))); items.push_back (MenuElem (_("Play from Range Mark"), mem_fun(*this, &Editor::marker_menu_play_from))); - if (! loop_or_punch) { + if (!loop_or_punch) { items.push_back (MenuElem (_("Play Range"), mem_fun(*this, &Editor::marker_menu_play_range))); items.push_back (MenuElem (_("Loop Range"), mem_fun(*this, &Editor::marker_menu_loop_range))); } @@ -503,7 +504,7 @@ Editor::build_range_marker_menu (bool loop_or_punch) items.push_back (SeparatorElem()); items.push_back (MenuElem (_("Hide Range"), mem_fun(*this, &Editor::marker_menu_hide))); - if (! loop_or_punch) { + if (!loop_or_punch) { items.push_back (MenuElem (_("Rename Range"), mem_fun(*this, &Editor::marker_menu_rename))); items.push_back (MenuElem (_("Remove Range"), mem_fun(*this, &Editor::marker_menu_remove))); } @@ -721,8 +722,7 @@ Editor::marker_menu_set_from_selection () if (l->is_mark()) { // nothing for now - } - else { + } else { /* if range selection use first to last */ @@ -909,56 +909,13 @@ Editor::new_transport_marker_menu_popdown (GdkEventAny *ev) void Editor::new_transport_marker_menu_set_loop () { - if (!session) return; - - begin_reversible_command (_("set loop range")); - - Location* tll; - - if ((tll = transport_loop_location()) == 0) { - Location* loc = new Location (temp_location->start(), temp_location->end(), _("Loop"), Location::IsAutoLoop); - XMLNode &before = session->locations()->get_state(); - session->locations()->add (loc, true); - session->set_auto_loop_location (loc); - XMLNode &after = session->locations()->get_state(); - session->add_command (new MementoCommand(*(session->locations()), &before, &after)); - } - else { - XMLNode &before = tll->get_state(); - tll->set_hidden (false, this); - tll->set (temp_location->start(), temp_location->end()); - XMLNode &after = tll->get_state(); - session->add_command (new MementoCommand(*tll, &before, &after)); - } - - commit_reversible_command (); + set_loop_range (temp_location->start(), temp_location->end(), _("set loop range")); } void Editor::new_transport_marker_menu_set_punch () { - if (!session) return; - - begin_reversible_command (_("set punch range")); - - Location* tpl; - - if ((tpl = transport_punch_location()) == 0) { - tpl = new Location (temp_location->start(), temp_location->end(), _("Punch"), Location::IsAutoPunch); - XMLNode &before = session->locations()->get_state(); - session->locations()->add (tpl, true); - session->set_auto_punch_location (tpl); - XMLNode &after = session->locations()->get_state(); - session->add_command (new MementoCommand(*(session->locations()), &before, &after)); - } else { - XMLNode &before = tpl->get_state(); - tpl->set_hidden(false, this); - tpl->set(temp_location->start(), temp_location->end()); - XMLNode &after = tpl->get_state(); - session->add_command (new MementoCommand(*tpl, &before, &after)); - } - - commit_reversible_command (); + set_punch_range (temp_location->start(), temp_location->end(), _("set punch range")); } void diff --git a/gtk2_ardour/editor_ops.cc b/gtk2_ardour/editor_ops.cc index 2267c150bf..b046b763ce 100644 --- a/gtk2_ardour/editor_ops.cc +++ b/gtk2_ardour/editor_ops.cc @@ -115,7 +115,23 @@ Editor::split_regions_at (nframes_t where, RegionSelection& regions) { begin_reversible_command (_("split")); - snap_to (where); + // if splitting a single region, and snap-to is using + // region boundaries, don't pay attention to them + + if (regions.size() == 1) { + switch (snap_type) { + case SnapToRegionStart: + case SnapToRegionSync: + case SnapToRegionEnd: + break; + default: + snap_to (where); + } + } else { + snap_to (where); + } + + for (RegionSelection::iterator a = regions.begin(); a != regions.end(); ) { RegionSelection::iterator tmp;