From d0580ecfbc1182f3c57b4d04e514f1d944225f14 Mon Sep 17 00:00:00 2001 From: nick_m Date: Thu, 29 Dec 2016 01:39:31 +1100 Subject: allow all types of range location (loop, start, end etc.) to be glued to bars and beats. --- gtk2_ardour/ardour_ui.cc | 2 +- gtk2_ardour/editor.cc | 4 +-- gtk2_ardour/editor.h | 2 +- gtk2_ardour/editor_drag.cc | 32 +++++++++++++----------- gtk2_ardour/editor_markers.cc | 37 +++++++++++++++------------ gtk2_ardour/editor_ops.cc | 58 +++++++++++++++++++++++-------------------- gtk2_ardour/location_ui.cc | 14 +++++++---- 7 files changed, 82 insertions(+), 67 deletions(-) (limited to 'gtk2_ardour') diff --git a/gtk2_ardour/ardour_ui.cc b/gtk2_ardour/ardour_ui.cc index 2190e274ad..92a2a01fc7 100644 --- a/gtk2_ardour/ardour_ui.cc +++ b/gtk2_ardour/ardour_ui.cc @@ -4773,7 +4773,7 @@ void ARDOUR_UI::create_xrun_marker (framepos_t where) { if (_session) { - Location *location = new Location (*_session, where, where, _("xrun"), Location::IsMark); + Location *location = new Location (*_session, where, where, _("xrun"), Location::IsMark, 0); _session->locations()->add (location); } } diff --git a/gtk2_ardour/editor.cc b/gtk2_ardour/editor.cc index 4ece70ec99..17ed10e68d 100644 --- a/gtk2_ardour/editor.cc +++ b/gtk2_ardour/editor.cc @@ -4756,7 +4756,7 @@ Editor::set_loop_range (framepos_t start, framepos_t end, string cmd) Location* tll; if ((tll = transport_loop_location()) == 0) { - Location* loc = new Location (*_session, start, end, _("Loop"), Location::IsAutoLoop); + Location* loc = new Location (*_session, start, end, _("Loop"), Location::IsAutoLoop, get_grid_music_divisions(0)); XMLNode &before = _session->locations()->get_state(); _session->locations()->add (loc, true); _session->set_auto_loop_location (loc); @@ -4783,7 +4783,7 @@ Editor::set_punch_range (framepos_t start, framepos_t end, string cmd) Location* tpl; if ((tpl = transport_punch_location()) == 0) { - Location* loc = new Location (*_session, start, end, _("Punch"), Location::IsAutoPunch); + Location* loc = new Location (*_session, start, end, _("Punch"), Location::IsAutoPunch, get_grid_music_divisions(0)); XMLNode &before = _session->locations()->get_state(); _session->locations()->add (loc, true); _session->set_auto_punch_location (loc); diff --git a/gtk2_ardour/editor.h b/gtk2_ardour/editor.h index c76f5c5d97..8a719b54fd 100644 --- a/gtk2_ardour/editor.h +++ b/gtk2_ardour/editor.h @@ -1698,7 +1698,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD void marker_context_menu (GdkEventButton*, ArdourCanvas::Item*); void tempo_or_meter_marker_context_menu (GdkEventButton*, ArdourCanvas::Item*); void new_transport_marker_context_menu (GdkEventButton*, ArdourCanvas::Item*); - void build_range_marker_menu (bool, bool); + void build_range_marker_menu (ARDOUR::Location *, bool, bool); void build_marker_menu (ARDOUR::Location *); void build_tempo_marker_menu (TempoMarker *, bool); void build_meter_marker_menu (MeterMarker *, bool); diff --git a/gtk2_ardour/editor_drag.cc b/gtk2_ardour/editor_drag.cc index 966cd293f5..cb972727d8 100644 --- a/gtk2_ardour/editor_drag.cc +++ b/gtk2_ardour/editor_drag.cc @@ -4196,6 +4196,8 @@ MarkerDrag::motion (GdkEvent* event, bool) return; } + const int32_t divisions = _editor->get_grid_music_divisions (event->button.state); + /* now move them all */ for (x = _copied_locations.begin(); x != _copied_locations.end(); ++x) { @@ -4213,8 +4215,7 @@ MarkerDrag::motion (GdkEvent* event, bool) if (copy_location->is_mark()) { /* now move it */ - - copy_location->set_start (copy_location->start() + f_delta); + copy_location->set_start (copy_location->start() + f_delta, false, true, divisions); } else { @@ -4224,27 +4225,27 @@ MarkerDrag::motion (GdkEvent* event, bool) if (is_start) { // start-of-range marker if (move_both || (*x).move_both) { - copy_location->set_start (new_start); - copy_location->set_end (new_end); + copy_location->set_start (new_start, false, true, divisions); + copy_location->set_end (new_end, false, true, divisions); } else if (new_start < copy_location->end()) { - copy_location->set_start (new_start); + copy_location->set_start (new_start, false, true, divisions); } else if (newframe > 0) { //_editor->snap_to (next, RoundUpAlways, true); - copy_location->set_end (next); - copy_location->set_start (newframe); + copy_location->set_end (next, false, true, divisions); + copy_location->set_start (newframe, false, true, divisions); } } else { // end marker if (move_both || (*x).move_both) { - copy_location->set_end (new_end); - copy_location->set_start (new_start); + copy_location->set_end (new_end, divisions); + copy_location->set_start (new_start, false, true, divisions); } else if (new_end > copy_location->start()) { - copy_location->set_end (new_end); + copy_location->set_end (new_end, false, true, divisions); } else if (newframe > 0) { //_editor->snap_to (next, RoundDownAlways, true); - copy_location->set_start (next); - copy_location->set_end (newframe); + copy_location->set_start (next, false, true, divisions); + copy_location->set_end (newframe, false, true, divisions); } } } @@ -4321,6 +4322,7 @@ MarkerDrag::finished (GdkEvent* event, bool movement_occurred) MarkerSelection::iterator i; CopiedLocationInfo::iterator x; + const int32_t divisions = _editor->get_grid_music_divisions (event->button.state); bool is_start; for (i = _editor->selection->markers.begin(), x = _copied_locations.begin(); @@ -4339,9 +4341,9 @@ MarkerDrag::finished (GdkEvent* event, bool movement_occurred) in_command = true; } if (location->is_mark()) { - location->set_start (((*x).location)->start()); + location->set_start (((*x).location)->start(), false, true, divisions); } else { - location->set (((*x).location)->start(), ((*x).location)->end()); + location->set (((*x).location)->start(), ((*x).location)->end(), true, divisions); } if (location->is_session_range()) { @@ -5536,7 +5538,7 @@ RangeMarkerBarDrag::finished (GdkEvent* event, bool movement_occurred) } newloc = new Location ( *_editor->session(), _editor->temp_location->start(), _editor->temp_location->end(), rangename, (Location::Flags) flags - ); + , _editor->get_grid_music_divisions (event->button.state)); _editor->session()->locations()->add (newloc, true); XMLNode &after = _editor->session()->locations()->get_state(); diff --git a/gtk2_ardour/editor_markers.cc b/gtk2_ardour/editor_markers.cc index a4d990b1e3..ac180d1daf 100644 --- a/gtk2_ardour/editor_markers.cc +++ b/gtk2_ardour/editor_markers.cc @@ -646,7 +646,7 @@ Editor::mouse_add_new_marker (framepos_t where, bool is_cd) if (!choose_new_marker_name(markername)) { return; } - Location *location = new Location (*_session, where, where, markername, (Location::Flags) flags); + Location *location = new Location (*_session, where, where, markername, (Location::Flags) flags, get_grid_music_divisions (0)); begin_reversible_command (_("add marker")); XMLNode &before = _session->locations()->get_state(); @@ -838,9 +838,8 @@ Editor::marker_context_menu (GdkEventButton* ev, ArdourCanvas::Item* item) if (loc == transport_loop_location() || loc == transport_punch_location() || loc->is_session_range ()) { - if (transport_marker_menu == 0) { - build_range_marker_menu (loc == transport_loop_location() || loc == transport_punch_location(), loc->is_session_range()); - } + delete transport_marker_menu; + build_range_marker_menu (loc, loc == transport_loop_location() || loc == transport_punch_location(), loc->is_session_range()); marker_menu_item = item; transport_marker_menu->popup (1, ev->time); @@ -868,9 +867,9 @@ Editor::marker_context_menu (GdkEventButton* ev, ArdourCanvas::Item* item) marker_menu->popup (1, ev->time); } else if (loc->is_range_marker()) { - if (range_marker_menu == 0) { - build_range_marker_menu (false, false); - } + delete range_marker_menu; + build_range_marker_menu (loc, false, false); + marker_menu_item = item; range_marker_menu->popup (1, ev->time); } @@ -916,9 +915,8 @@ Editor::build_marker_menu (Location* loc) items.push_back (CheckMenuElem (_("Glue to Bars and Beats"))); Gtk::CheckMenuItem* glue_item = static_cast (&items.back()); - if (loc->position_lock_style() == MusicTime) { - glue_item->set_active (); - } + glue_item->set_active (loc->position_lock_style() == MusicTime); + glue_item->signal_activate().connect (sigc::mem_fun (*this, &Editor::toggle_marker_menu_glue)); items.push_back (SeparatorElem()); @@ -927,11 +925,11 @@ Editor::build_marker_menu (Location* loc) } void -Editor::build_range_marker_menu (bool loop_or_punch, bool session) +Editor::build_range_marker_menu (Location* loc, bool loop_or_punch, bool session) { using namespace Menu_Helpers; - bool const loop_or_punch_or_session = loop_or_punch | session; + bool const loop_or_punch_or_session = loop_or_punch || session; Menu *markerMenu = new Menu; if (loop_or_punch_or_session) { @@ -952,6 +950,13 @@ Editor::build_range_marker_menu (bool loop_or_punch, bool session) items.push_back (MenuElem (_("Zoom to Range"), sigc::mem_fun (*this, &Editor::marker_menu_zoom_to_range))); + items.push_back (SeparatorElem()); + items.push_back (CheckMenuElem (_("Glue to Bars and Beats"))); + + Gtk::CheckMenuItem* glue_item = static_cast (&items.back()); + glue_item->set_active (loc->position_lock_style() == MusicTime); + glue_item->signal_activate().connect (sigc::mem_fun (*this, &Editor::toggle_marker_menu_glue)); + items.push_back (SeparatorElem()); items.push_back (MenuElem (_("Export Range..."), sigc::mem_fun(*this, &Editor::export_range))); items.push_back (SeparatorElem()); @@ -1213,17 +1218,18 @@ Editor::marker_menu_set_from_playhead () Location* l; bool is_start; + const int32_t divisions = get_grid_music_divisions (0); if ((l = find_location_from_marker (marker, is_start)) != 0) { if (l->is_mark()) { - l->set_start (_session->audible_frame ()); + l->set_start (_session->audible_frame (), false, true, divisions); } else { if (is_start) { - l->set_start (_session->audible_frame ()); + l->set_start (_session->audible_frame (), false, true, divisions); } else { - l->set_end (_session->audible_frame ()); + l->set_end (_session->audible_frame (), false, true, divisions); } } } @@ -1692,7 +1698,6 @@ Editor::toggle_marker_menu_glue () } else { loc->set_position_lock_style (MusicTime); } - } void diff --git a/gtk2_ardour/editor_ops.cc b/gtk2_ardour/editor_ops.cc index 2ca31f2aaf..6a21dd8432 100644 --- a/gtk2_ardour/editor_ops.cc +++ b/gtk2_ardour/editor_ops.cc @@ -420,6 +420,7 @@ Editor::nudge_forward (bool next, bool force_playhead) bool is_start; bool in_command = false; + const int32_t divisions = get_grid_music_divisions (0); for (MarkerSelection::iterator i = selection->markers.begin(); i != selection->markers.end(); ++i) { @@ -435,9 +436,9 @@ Editor::nudge_forward (bool next, bool force_playhead) distance = next_distance; } if (max_framepos - distance > loc->start() + loc->length()) { - loc->set_start (loc->start() + distance); + loc->set_start (loc->start() + distance, false, true, divisions); } else { - loc->set_start (max_framepos - loc->length()); + loc->set_start (max_framepos - loc->length(), false, true, divisions); } } else { distance = get_nudge_distance (loc->end(), next_distance); @@ -445,9 +446,9 @@ Editor::nudge_forward (bool next, bool force_playhead) distance = next_distance; } if (max_framepos - distance > loc->end()) { - loc->set_end (loc->end() + distance); + loc->set_end (loc->end() + distance, false, true, divisions); } else { - loc->set_end (max_framepos); + loc->set_end (max_framepos, false, true, divisions); } if (loc->is_session_range()) { _session->set_end_is_free (false); @@ -527,9 +528,9 @@ Editor::nudge_backward (bool next, bool force_playhead) distance = next_distance; } if (distance < loc->start()) { - loc->set_start (loc->start() - distance); + loc->set_start (loc->start() - distance, false, true, get_grid_music_divisions(0)); } else { - loc->set_start (0); + loc->set_start (0, false, true, get_grid_music_divisions(0)); } } else { distance = get_nudge_distance (loc->end(), next_distance); @@ -539,9 +540,9 @@ Editor::nudge_backward (bool next, bool force_playhead) } if (distance < loc->end() - loc->length()) { - loc->set_end (loc->end() - distance); + loc->set_end (loc->end() - distance, false, true, get_grid_music_divisions(0)); } else { - loc->set_end (loc->length()); + loc->set_end (loc->length(), false, true, get_grid_music_divisions(0)); } if (loc->is_session_range()) { _session->set_end_is_free (false); @@ -1155,7 +1156,7 @@ Editor::selected_marker_to_region_boundary (bool with_selection, int32_t dir) return; } - loc->move_to (target); + loc->move_to (target, 0); } void @@ -1232,7 +1233,7 @@ Editor::selected_marker_to_region_point (RegionPoint point, int32_t dir) pos = track_frame_to_session_frame(pos, speed); - loc->move_to (pos); + loc->move_to (pos, 0); } void @@ -1279,7 +1280,7 @@ Editor::selected_marker_to_selection_start () return; } - loc->move_to (pos); + loc->move_to (pos, 0); } void @@ -1314,7 +1315,7 @@ Editor::selected_marker_to_selection_end () return; } - loc->move_to (pos); + loc->move_to (pos, 0); } void @@ -1366,6 +1367,7 @@ Editor::cursor_align (bool playhead_to_edit) _session->request_locate (selection->markers.front()->position(), _session->transport_rolling()); } else { + const int32_t divisions = get_grid_music_divisions (0); /* move selected markers to playhead */ for (MarkerSelection::iterator i = selection->markers.begin(); i != selection->markers.end(); ++i) { @@ -1374,10 +1376,10 @@ Editor::cursor_align (bool playhead_to_edit) Location* loc = find_location_from_marker (*i, ignored); if (loc->is_mark()) { - loc->set_start (playhead_cursor->current_frame ()); + loc->set_start (playhead_cursor->current_frame (), false, true, divisions); } else { loc->set (playhead_cursor->current_frame (), - playhead_cursor->current_frame () + loc->length()); + playhead_cursor->current_frame () + loc->length(), true, divisions); } } } @@ -2145,7 +2147,7 @@ Editor::add_location_from_selection () framepos_t end = selection->time[clicked_selection].end; _session->locations()->next_available_name(rangename,"selection"); - Location *location = new Location (*_session, start, end, rangename, Location::IsRangeMarker); + Location *location = new Location (*_session, start, end, rangename, Location::IsRangeMarker, get_grid_music_divisions(0)); begin_reversible_command (_("add marker")); @@ -2168,7 +2170,7 @@ Editor::add_location_mark (framepos_t where) if (!choose_new_marker_name(markername)) { return; } - Location *location = new Location (*_session, where, where, markername, Location::IsMark); + Location *location = new Location (*_session, where, where, markername, Location::IsMark, get_grid_music_divisions (0)); begin_reversible_command (_("add marker")); XMLNode &before = _session->locations()->get_state(); @@ -2297,7 +2299,7 @@ Editor::add_locations_from_region () boost::shared_ptr region = (*i)->region (); - Location *location = new Location (*_session, region->position(), region->last_frame(), region->name(), Location::IsRangeMarker); + Location *location = new Location (*_session, region->position(), region->last_frame(), region->name(), Location::IsRangeMarker, 0); _session->locations()->add (location, true); commit = true; @@ -2338,7 +2340,7 @@ Editor::add_location_from_region () } // single range spanning all selected - Location *location = new Location (*_session, selection->regions.start(), selection->regions.end_frame(), markername, Location::IsRangeMarker); + Location *location = new Location (*_session, selection->regions.start(), selection->regions.end_frame(), markername, Location::IsRangeMarker, 0); _session->locations()->add (location, true); begin_reversible_command (_("add marker")); @@ -2393,7 +2395,7 @@ Editor::set_mark () return; } - _session->locations()->add (new Location (*_session, pos, 0, markername, Location::IsMark), true); + _session->locations()->add (new Location (*_session, pos, 0, markername, Location::IsMark, 0), true); } void @@ -6173,7 +6175,7 @@ Editor::set_edit_point () Location* loc = find_location_from_marker (selection->markers.front(), ignored); if (loc) { - loc->move_to (where); + loc->move_to (where, get_grid_music_divisions(0)); } } } @@ -7486,6 +7488,7 @@ Editor::insert_time ( /* markers */ if (markers_too) { bool moved = false; + const int32_t divisions = get_grid_music_divisions (0); XMLNode& before (_session->locations()->get_state()); Locations::LocationList copy (_session->locations()->list()); @@ -7502,9 +7505,9 @@ Editor::insert_time ( if ((*i)->start() >= pos) { // move end first, in case we're moving by more than the length of the range if (!(*i)->is_mark()) { - (*i)->set_end ((*i)->end() + frames); + (*i)->set_end ((*i)->end() + frames, false, true, divisions); } - (*i)->set_start ((*i)->start() + frames); + (*i)->set_start ((*i)->start() + frames, false, true, divisions); moved = true; } @@ -7617,6 +7620,7 @@ Editor::remove_time (framepos_t pos, framecnt_t frames, InsertTimeOption opt, } } + const int32_t divisions = get_grid_music_divisions (0); std::list loc_kill_list; /* markers */ @@ -7645,20 +7649,20 @@ Editor::remove_time (framepos_t pos, framecnt_t frames, InsertTimeOption opt, // if we're removing more time than the length of the range if ((*i)->start() >= pos && (*i)->start() < pos+frames) { // start is within cut - (*i)->set_start (pos); // bring the start marker to the beginning of the cut + (*i)->set_start (pos, false, true,divisions); // bring the start marker to the beginning of the cut moved = true; } else if ((*i)->start() >= pos+frames) { // start (and thus entire range) lies beyond end of cut - (*i)->set_start ((*i)->start() - frames); // slip the start marker back + (*i)->set_start ((*i)->start() - frames, false, true, divisions); // slip the start marker back moved = true; } if ((*i)->end() >= pos && (*i)->end() < pos+frames) { // end is inside cut - (*i)->set_end (pos); // bring the end to the cut + (*i)->set_end (pos, false, true, divisions); // bring the end to the cut moved = true; } else if ((*i)->end() >= pos+frames) { // end is beyond end of cut - (*i)->set_end ((*i)->end() - frames); // slip the end marker back + (*i)->set_end ((*i)->end() - frames, false, true, divisions); // slip the end marker back moved = true; } @@ -7667,7 +7671,7 @@ Editor::remove_time (framepos_t pos, framecnt_t frames, InsertTimeOption opt, loc_kill_list.push_back(*i); moved = true; } else if ((*i)->start() >= pos) { - (*i)->set_start ((*i)->start() -frames); + (*i)->set_start ((*i)->start() -frames, false, true, divisions); moved = true; } diff --git a/gtk2_ardour/location_ui.cc b/gtk2_ardour/location_ui.cc index 76111a49e7..4bdc9798c5 100644 --- a/gtk2_ardour/location_ui.cc +++ b/gtk2_ardour/location_ui.cc @@ -414,12 +414,14 @@ LocationEditRow::to_playhead_button_pressed (LocationPart part) return; } + const int32_t divisions = PublicEditor::instance().get_grid_music_divisions (0); + switch (part) { case LocStart: - location->set_start (_session->transport_frame ()); + location->set_start (_session->transport_frame (), false, true, divisions); break; case LocEnd: - location->set_end (_session->transport_frame ()); + location->set_end (_session->transport_frame (), false, true,divisions); if (location->is_session_range()) { _session->set_end_is_free (false); } @@ -461,18 +463,20 @@ LocationEditRow::clock_changed (LocationPart part) return; } + const int32_t divisions = PublicEditor::instance().get_grid_music_divisions (0); + switch (part) { case LocStart: - location->set_start (start_clock.current_time()); + location->set_start (start_clock.current_time(), false, true, divisions); break; case LocEnd: - location->set_end (end_clock.current_time()); + location->set_end (end_clock.current_time(), false, true, divisions); if (location->is_session_range()) { _session->set_end_is_free (false); } break; case LocLength: - location->set_end (location->start() + length_clock.current_duration()); + location->set_end (location->start() + length_clock.current_duration(), false, true, divisions); if (location->is_session_range()) { _session->set_end_is_free (false); } -- cgit v1.2.3