allow all types of range location (loop, start, end etc.) to be glued to bars and...
authornick_m <mainsbridge@gmail.com>
Wed, 28 Dec 2016 14:39:31 +0000 (01:39 +1100)
committernick_m <mainsbridge@gmail.com>
Wed, 28 Dec 2016 14:39:31 +0000 (01:39 +1100)
12 files changed:
gtk2_ardour/ardour_ui.cc
gtk2_ardour/editor.cc
gtk2_ardour/editor.h
gtk2_ardour/editor_drag.cc
gtk2_ardour/editor_markers.cc
gtk2_ardour/editor_ops.cc
gtk2_ardour/location_ui.cc
libs/ardour/ardour/location.h
libs/ardour/location.cc
libs/ardour/midi_scene_changer.cc
libs/ardour/session.cc
libs/ardour/session_state.cc

index 2190e274adee9b86d51184760ad0ac0e270523ce..92a2a01fc75c288244a5b79160d726f30442f614 100644 (file)
@@ -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);
        }
 }
index 4ece70ec991c476e22e2d08ff44f36f15231e831..17ed10e68d85eb87b5c2a60318f955326c2eeae7 100644 (file)
@@ -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);
index c76f5c5d97c104710505e3d2340df672088e41c0..8a719b54fd6320e388f2f52a23de228846f324ff 100644 (file)
@@ -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);
index 966cd293f5d78e37f300e308d9a381b8ab45534c..cb972727d8cf984d659164ecb30d28aa1f69300f 100644 (file)
@@ -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();
index a4d990b1e3fa8ede3678929a137588ae7ec6d7b3..ac180d1daf18aa47c27c71cc3cd467243e680865 100644 (file)
@@ -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<Gtk::CheckMenuItem*> (&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<Gtk::CheckMenuItem*> (&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
index 2ca31f2aaf8ecb7a0c7c5c756e18b51f92dffb07..6a21dd84322f5454ca5987d2b737d9ca7fee8e2e 100644 (file)
@@ -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> 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<Location*> 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;
                                }
 
index 76111a49e767b8d779e5537beee4a3c4184c73bb..4bdc9798c5a1a4af56ccfff04009ebc10dec90d4 100644 (file)
@@ -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);
                        }
index 6b61dae74631e9b16c85a03a893a01a4f59c2952..24ee5639153357bf11a40af07d1299b1f0229a4f 100644 (file)
@@ -58,7 +58,7 @@ class LIBARDOUR_API Location : public SessionHandleRef, public PBD::StatefulDest
        };
 
        Location (Session &);
-       Location (Session &, framepos_t, framepos_t, const std::string &, Flags bits = Flags(0));
+       Location (Session &, framepos_t, framepos_t, const std::string &, Flags bits = Flags(0), const uint32_t sub_num = 0);
        Location (const Location& other);
        Location (Session &, const XMLNode&);
        Location* operator= (const Location& other);
@@ -73,11 +73,11 @@ class LIBARDOUR_API Location : public SessionHandleRef, public PBD::StatefulDest
        framepos_t end() const { return _end; }
        framecnt_t length() const { return _end - _start; }
 
-       int set_start (framepos_t s, bool force = false, bool allow_bbt_recompute = true);
-       int set_end (framepos_t e, bool force = false, bool allow_bbt_recompute = true);
-       int set (framepos_t start, framepos_t end, bool allow_bbt_recompute = true);
+       int set_start (framepos_t s, bool force = false, bool allow_beat_recompute = true, const uint32_t sub_num = 0);
+       int set_end (framepos_t e, bool force = false, bool allow_beat_recompute = true, const uint32_t sub_num = 0);
+       int set (framepos_t start, framepos_t end, bool allow_beat_recompute = true, const uint32_t sub_num = 0);
 
-       int move_to (framepos_t pos);
+       int move_to (framepos_t pos, const uint32_t sub_num);
 
        const std::string& name() const { return _name; }
        void set_name (const std::string &str);
@@ -143,7 +143,7 @@ class LIBARDOUR_API Location : public SessionHandleRef, public PBD::StatefulDest
 
        PositionLockStyle position_lock_style() const { return _position_lock_style; }
        void set_position_lock_style (PositionLockStyle ps);
-       void recompute_frames_from_bbt ();
+       void recompute_frames_from_beat ();
 
        static PBD::Signal0<void> scene_changed; /* for use by backend scene change management, class level */
         PBD::Signal0<void> SceneChangeChanged;   /* for use by objects interested in this object */
@@ -151,9 +151,9 @@ class LIBARDOUR_API Location : public SessionHandleRef, public PBD::StatefulDest
   private:
        std::string        _name;
        framepos_t         _start;
-       double             _bbt_start;
+       double             _start_beat;
        framepos_t         _end;
-       double             _bbt_end;
+       double             _end_beat;
        Flags              _flags;
        bool               _locked;
        PositionLockStyle  _position_lock_style;
@@ -161,7 +161,7 @@ class LIBARDOUR_API Location : public SessionHandleRef, public PBD::StatefulDest
 
        void set_mark (bool yn);
        bool set_flag_internal (bool yn, Flags flag);
-       void recompute_bbt_from_frames ();
+       void recompute_beat_from_frames (const uint32_t sub_num);
 };
 
 /** A collection of session locations including unique dedicated locations (loop, punch, etc) */
index 2fd63b61952f729b0b9df27f775cf9a493b0a756..1b53c705d8cd5fac9f30fbca5ab2ac5b81ad695d 100644 (file)
@@ -54,7 +54,9 @@ PBD::Signal1<void,Location*> Location::changed;
 Location::Location (Session& s)
        : SessionHandleRef (s)
        , _start (0)
+       , _start_beat (0.0)
        , _end (0)
+       , _end_beat (0.0)
        , _flags (Flags (0))
        , _locked (false)
        , _position_lock_style (AudioTime)
@@ -64,7 +66,7 @@ Location::Location (Session& s)
 }
 
 /** Construct a new Location, giving it the position lock style determined by glue-new-markers-to-bars-and-beats */
-Location::Location (Session& s, framepos_t sample_start, framepos_t sample_end, const std::string &name, Flags bits)
+Location::Location (Session& s, framepos_t sample_start, framepos_t sample_end, const std::string &name, Flags bits, const uint32_t sub_num)
        : SessionHandleRef (s)
        , _name (name)
        , _start (sample_start)
@@ -74,7 +76,7 @@ Location::Location (Session& s, framepos_t sample_start, framepos_t sample_end,
        , _position_lock_style (s.config.get_glue_new_markers_to_bars_and_beats() ? MusicTime : AudioTime)
 
 {
-       recompute_bbt_from_frames ();
+       recompute_beat_from_frames (sub_num);
 
        assert (_start >= 0);
        assert (_end >= 0);
@@ -85,9 +87,9 @@ Location::Location (const Location& other)
        , StatefulDestructible()
        , _name (other._name)
        , _start (other._start)
-       , _bbt_start (other._bbt_start)
+       , _start_beat (other._start_beat)
        , _end (other._end)
-       , _bbt_end (other._bbt_end)
+       , _end_beat (other._end_beat)
        , _flags (other._flags)
        , _position_lock_style (other._position_lock_style)
 
@@ -125,8 +127,8 @@ Location::operator== (const Location& other)
        if (_name != other._name ||
            _start != other._start ||
            _end != other._end ||
-           _bbt_start != other._bbt_start ||
-           _bbt_end != other._bbt_end ||
+           _start_beat != other._start_beat ||
+           _end_beat != other._end_beat ||
            _flags != other._flags ||
            _position_lock_style != other._position_lock_style) {
                return false;
@@ -143,9 +145,9 @@ Location::operator= (const Location& other)
 
        _name = other._name;
        _start = other._start;
-       _bbt_start = other._bbt_start;
+       _start_beat = other._start_beat;
        _end = other._end;
-       _bbt_end = other._bbt_end;
+       _end_beat = other._end_beat;
        _flags = other._flags;
        _position_lock_style = other._position_lock_style;
 
@@ -178,10 +180,10 @@ Location::set_name (const std::string& str)
 /** Set start position.
  *  @param s New start.
  *  @param force true to force setting, even if the given new start is after the current end.
- *  @param allow_bbt_recompute True to recompute BBT start time from the new given start time.
+ *  @param allow_beat_recompute True to recompute BEAT start time from the new given start time.
  */
 int
-Location::set_start (framepos_t s, bool force, bool allow_bbt_recompute)
+Location::set_start (framepos_t s, bool force, bool allow_beat_recompute, const uint32_t sub_num)
 {
        if (s < 0) {
                return -1;
@@ -201,8 +203,8 @@ Location::set_start (framepos_t s, bool force, bool allow_bbt_recompute)
                if (_start != s) {
                        _start = s;
                        _end = s;
-                       if (allow_bbt_recompute) {
-                               recompute_bbt_from_frames ();
+                       if (allow_beat_recompute) {
+                               recompute_beat_from_frames (sub_num);
                        }
 
                        start_changed (this); /* EMIT SIGNAL */
@@ -235,8 +237,8 @@ Location::set_start (framepos_t s, bool force, bool allow_bbt_recompute)
                framepos_t const old = _start;
 
                _start = s;
-               if (allow_bbt_recompute) {
-                       recompute_bbt_from_frames ();
+               if (allow_beat_recompute) {
+                       recompute_beat_from_frames (sub_num);
                }
                start_changed (this); /* EMIT SIGNAL */
                StartChanged (); /* EMIT SIGNAL */
@@ -255,10 +257,10 @@ Location::set_start (framepos_t s, bool force, bool allow_bbt_recompute)
 /** Set end position.
  *  @param s New end.
  *  @param force true to force setting, even if the given new end is before the current start.
- *  @param allow_bbt_recompute True to recompute BBT end time from the new given end time.
+ *  @param allow_beat_recompute True to recompute BEAT end time from the new given end time.
  */
 int
-Location::set_end (framepos_t e, bool force, bool allow_bbt_recompute)
+Location::set_end (framepos_t e, bool force, bool allow_beat_recompute, const uint32_t sub_num)
 {
        if (e < 0) {
                return -1;
@@ -278,8 +280,8 @@ Location::set_end (framepos_t e, bool force, bool allow_bbt_recompute)
                if (_start != e) {
                        _start = e;
                        _end = e;
-                       if (allow_bbt_recompute) {
-                               recompute_bbt_from_frames ();
+                       if (allow_beat_recompute) {
+                               recompute_beat_from_frames (sub_num);
                        }
                        //start_changed (this); /* EMIT SIGNAL */
                        //StartChanged (); /* EMIT SIGNAL */
@@ -303,8 +305,8 @@ Location::set_end (framepos_t e, bool force, bool allow_bbt_recompute)
                framepos_t const old = _end;
 
                _end = e;
-               if (allow_bbt_recompute) {
-                       recompute_bbt_from_frames ();
+               if (allow_beat_recompute) {
+                       recompute_beat_from_frames (sub_num);
                }
 
                end_changed(this); /* EMIT SIGNAL */
@@ -321,7 +323,7 @@ Location::set_end (framepos_t e, bool force, bool allow_bbt_recompute)
 }
 
 int
-Location::set (framepos_t s, framepos_t e, bool allow_bbt_recompute)
+Location::set (framepos_t s, framepos_t e, bool allow_beat_recompute, const uint32_t sub_num)
 {
        if (s < 0 || e < 0) {
                return -1;
@@ -341,8 +343,8 @@ Location::set (framepos_t s, framepos_t e, bool allow_bbt_recompute)
                        _start = s;
                        _end = s;
 
-                       if (allow_bbt_recompute) {
-                               recompute_bbt_from_frames ();
+                       if (allow_beat_recompute) {
+                               recompute_beat_from_frames (sub_num);
                        }
 
                        start_change = true;
@@ -364,8 +366,8 @@ Location::set (framepos_t s, framepos_t e, bool allow_bbt_recompute)
                        framepos_t const old = _start;
                        _start = s;
 
-                       if (allow_bbt_recompute) {
-                               recompute_bbt_from_frames ();
+                       if (allow_beat_recompute) {
+                               recompute_beat_from_frames (sub_num);
                        }
 
                        start_change = true;
@@ -382,8 +384,8 @@ Location::set (framepos_t s, framepos_t e, bool allow_bbt_recompute)
                        framepos_t const old = _end;
                        _end = e;
 
-                       if (allow_bbt_recompute) {
-                               recompute_bbt_from_frames ();
+                       if (allow_beat_recompute) {
+                               recompute_beat_from_frames (sub_num);
                        }
 
                        end_change = true;
@@ -411,7 +413,7 @@ Location::set (framepos_t s, framepos_t e, bool allow_bbt_recompute)
 }
 
 int
-Location::move_to (framepos_t pos)
+Location::move_to (framepos_t pos, const uint32_t sub_num)
 {
        if (pos < 0) {
                return -1;
@@ -424,7 +426,7 @@ Location::move_to (framepos_t pos)
        if (_start != pos) {
                _start = pos;
                _end = _start + length();
-               recompute_bbt_from_frames ();
+               recompute_beat_from_frames (sub_num);
 
                changed (this); /* EMIT SIGNAL */
                Changed (); /* EMIT SIGNAL */
@@ -580,6 +582,14 @@ Location::get_state ()
        node->add_property ("start", buf);
        snprintf (buf, sizeof (buf), "%" PRId64, end());
        node->add_property ("end", buf);
+
+       if (position_lock_style() == MusicTime) {
+               snprintf (buf, sizeof (buf), "%lf", _start_beat);
+               node->add_property ("start-beat", buf);
+               snprintf (buf, sizeof (buf), "%lf", _end_beat);
+               node->add_property ("end-beat", buf);
+       }
+
        node->add_property ("flags", enum_2_string (_flags));
        node->add_property ("locked", (_locked ? "yes" : "no"));
        node->add_property ("position-lock-style", enum_2_string (_position_lock_style));
@@ -689,7 +699,27 @@ Location::set_state (const XMLNode& node, int version)
                _scene_change = SceneChange::factory (*scene_child, version);
        }
 
-       recompute_bbt_from_frames ();
+       if (position_lock_style() == AudioTime) {
+               recompute_beat_from_frames (0);
+       } else{
+               /* music */
+               bool has_beat = false;
+
+               if ((prop = node.property ("start-beat")) != 0) {
+                       sscanf (prop->value().c_str(), "%lf", &_start_beat);
+                       has_beat = true;
+               }
+
+               if ((prop = node.property ("end-beat")) != 0) {
+                       sscanf (prop->value().c_str(), "%lf", &_end_beat);
+                       has_beat = true;
+               }
+
+               if (!has_beat) {
+                       recompute_beat_from_frames (0);
+               }
+       }
+
 
        changed (this); /* EMIT SIGNAL */
        Changed (); /* EMIT SIGNAL */
@@ -709,32 +739,30 @@ Location::set_position_lock_style (PositionLockStyle ps)
 
        _position_lock_style = ps;
 
-       recompute_bbt_from_frames ();
+       if (ps == MusicTime) {
+               recompute_beat_from_frames (0);
+       }
 
        position_lock_style_changed (this); /* EMIT SIGNAL */
        PositionLockStyleChanged (); /* EMIT SIGNAL */
 }
 
 void
-Location::recompute_bbt_from_frames ()
+Location::recompute_beat_from_frames (const uint32_t sub_num)
 {
-       if (_position_lock_style != MusicTime) {
-               return;
-       }
-
-       _bbt_start = _session.tempo_map().beat_at_frame (_start);
-       _bbt_end = _session.tempo_map().beat_at_frame (_end);
+       _start_beat = _session.tempo_map().exact_beat_at_frame (_start, sub_num);
+       _end_beat = _session.tempo_map().exact_beat_at_frame (_end, sub_num);
 }
 
 void
-Location::recompute_frames_from_bbt ()
+Location::recompute_frames_from_beat ()
 {
        if (_position_lock_style != MusicTime) {
                return;
        }
 
        TempoMap& map (_session.tempo_map());
-       set (map.frame_at_beat (_bbt_start), map.frame_at_beat (_bbt_end), false);
+       set (map.frame_at_beat (_start_beat), map.frame_at_beat (_end_beat), false);
 }
 
 void
@@ -1060,7 +1088,7 @@ Locations::set_state (const XMLNode& node, int version)
 
        Location* session_range_location = 0;
        if (version < 3000) {
-               session_range_location = new Location (_session, 0, 0, _("session"), Location::IsSessionRange);
+               session_range_location = new Location (_session, 0, 0, _("session"), Location::IsSessionRange, 0);
                new_locations.push_back (session_range_location);
        }
 
index 0c2880dcaf97afda5fbf6453550328c7dfc057b3..ce2559180f9baa777bceb39c8f2fd0871b3b16b2 100644 (file)
@@ -314,7 +314,7 @@ MIDISceneChanger::program_change_input (MIDI::Parser& parser, MIDI::byte program
                        return;
                }
 
-               loc = new Location (_session, time, time, new_name, Location::IsMark);
+               loc = new Location (_session, time, time, new_name, Location::IsMark, 0);
                new_mark = true;
        }
 
index 112a933e1900f0060dde4f37695408ccecda9c0d..56b3f2a38cb9a80b9fd07d6bd0503379bd86ef5d 100644 (file)
@@ -1682,7 +1682,7 @@ Session::set_session_extents (framepos_t start, framepos_t end)
        Location* existing;
        if ((existing = _locations->session_range_location()) == 0) {
                //if there is no existing session, we need to make a new session location  (should never happen)
-               existing = new Location (*this, 0, 0, _("session"), Location::IsSessionRange);
+               existing = new Location (*this, 0, 0, _("session"), Location::IsSessionRange, 0);
        }
 
        if (end <= start) {
@@ -5582,7 +5582,7 @@ void
 Session::update_locations_after_tempo_map_change (const Locations::LocationList& loc)
 {
        for (Locations::LocationList::const_iterator i = loc.begin(); i != loc.end(); ++i) {
-               (*i)->recompute_frames_from_bbt ();
+               (*i)->recompute_frames_from_beat ();
        }
 }
 
@@ -6340,7 +6340,7 @@ Session::current_end_frame () const
 void
 Session::set_session_range_location (framepos_t start, framepos_t end)
 {
-       _session_range_location = new Location (*this, start, end, _("session"), Location::IsSessionRange);
+       _session_range_location = new Location (*this, start, end, _("session"), Location::IsSessionRange, 0);
        _locations->add (_session_range_location);
 }
 
index 506bc58fdfbe95eb0d4d7c190351e5219addaa40..3d839d818634f4519bf8377d0b0bbd6744cd27f1 100644 (file)
@@ -634,7 +634,7 @@ Session::create (const string& session_template, BusProfile* bus_profile)
 
                /* Initial loop location, from absolute zero, length 10 seconds  */
 
-               Location* loc = new Location (*this, 0, 10.0 * _engine.sample_rate(), _("Loop"),  Location::IsAutoLoop);
+               Location* loc = new Location (*this, 0, 10.0 * _engine.sample_rate(), _("Loop"),  Location::IsAutoLoop, 0);
                _locations->add (loc, true);
                set_auto_loop_location (loc);
        }
@@ -1220,7 +1220,7 @@ Session::state (bool full_state)
                Locations loc (*this);
                // for a template, just create a new Locations, populate it
                // with the default start and end, and get the state for that.
-               Location* range = new Location (*this, 0, 0, _("session"), Location::IsSessionRange);
+               Location* range = new Location (*this, 0, 0, _("session"), Location::IsSessionRange, 0);
                range->set (max_framepos, 0);
                loc.add (range);
                XMLNode& locations_state = loc.get_state();