From 5b2a435e02858d74465ec9246cb83a7d8b313787 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Wed, 14 Oct 2020 23:09:22 -0600 Subject: [PATCH] getting editor_drag.cc to compile --- gtk2_ardour/automation_controller.cc | 4 +- gtk2_ardour/automation_time_axis.cc | 5 +- gtk2_ardour/automation_time_axis.h | 2 +- gtk2_ardour/editor.cc | 4 +- gtk2_ardour/editor.h | 4 +- gtk2_ardour/editor_drag.cc | 1468 ++++++++++++++++---------- gtk2_ardour/editor_drag.h | 213 ++-- gtk2_ardour/editor_mouse.cc | 6 +- gtk2_ardour/editor_tempodisplay.cc | 5 +- gtk2_ardour/marker_selection.h | 2 +- gtk2_ardour/midi_list_editor.cc | 10 +- gtk2_ardour/midi_region_view.cc | 23 +- gtk2_ardour/midi_region_view.h | 8 +- gtk2_ardour/midi_streamview.cc | 39 +- gtk2_ardour/midi_time_axis.h | 2 +- gtk2_ardour/mini_timeline.cc | 14 +- gtk2_ardour/mixer_strip.cc | 4 +- gtk2_ardour/public_editor.h | 2 +- gtk2_ardour/region_editor.cc | 6 +- gtk2_ardour/region_gain_line.cc | 12 +- gtk2_ardour/region_view.cc | 6 +- gtk2_ardour/region_view.h | 6 +- gtk2_ardour/route_time_axis.cc | 8 +- gtk2_ardour/route_time_axis.h | 2 +- gtk2_ardour/selection.cc | 20 +- gtk2_ardour/selection.h | 6 +- gtk2_ardour/time_axis_view.cc | 2 +- gtk2_ardour/time_axis_view.h | 2 +- 28 files changed, 1136 insertions(+), 749 deletions(-) diff --git a/gtk2_ardour/automation_controller.cc b/gtk2_ardour/automation_controller.cc index 6bd40a527c..e5462008b4 100644 --- a/gtk2_ardour/automation_controller.cc +++ b/gtk2_ardour/automation_controller.cc @@ -215,13 +215,13 @@ void AutomationController::start_touch() { _grabbed = true; - _controllable->start_touch (_controllable->session().transport_sample()); + _controllable->start_touch (timepos_t (_controllable->session().transport_sample())); } void AutomationController::end_touch () { - _controllable->stop_touch (_controllable->session().transport_sample()); + _controllable->stop_touch (timepos_t (_controllable->session().transport_sample())); if (_grabbed) { _grabbed = false; display_effective_value (); diff --git a/gtk2_ardour/automation_time_axis.cc b/gtk2_ardour/automation_time_axis.cc index 53d48c19ef..f44671ac57 100644 --- a/gtk2_ardour/automation_time_axis.cc +++ b/gtk2_ardour/automation_time_axis.cc @@ -299,8 +299,6 @@ AutomationTimeAxisView::AutomationTimeAxisView ( assert (_control); -#warning NUTEMPO new tempo map API required -#if 0 boost::shared_ptr line ( new AutomationLine ( ARDOUR::EventTypeMap::instance().to_symbol(_parameter), @@ -308,7 +306,7 @@ AutomationTimeAxisView::AutomationTimeAxisView ( *_canvas_display, _control->alist(), _control->desc(), - Temporal::DistanceMeasure (_session->tempo_map(), timepos_t()) /* default distance measure, origin at absolute zero */ + Temporal::DistanceMeasure (timepos_t()) /* default distance measure, origin at absolute zero */ ) ); @@ -316,7 +314,6 @@ AutomationTimeAxisView::AutomationTimeAxisView ( line->set_fill (true); line->queue_reset (); add_line (line); -#endif 0 } /* make sure labels etc. are correct */ diff --git a/gtk2_ardour/automation_time_axis.h b/gtk2_ardour/automation_time_axis.h index 555f467cac..46b3415592 100644 --- a/gtk2_ardour/automation_time_axis.h +++ b/gtk2_ardour/automation_time_axis.h @@ -101,7 +101,7 @@ public: void get_selectables (Temporal::timepos_t const &, Temporal::timepos_t const &, double top, double bot, std::list&, bool within = false); void get_inverted_selectables (Selection&, std::list& results); - void show_timestretch (samplepos_t /*start*/, samplepos_t /*end*/, int /*layers*/, int /*layer*/) {} + void show_timestretch (Temporal::timepos_t const &/*start*/, Temporal::timepos_t const & /*end*/, int /*layers*/, int /*layer*/) {} void hide_timestretch () {} /* editing operations */ diff --git a/gtk2_ardour/editor.cc b/gtk2_ardour/editor.cc index 349a65b2e0..9457693a83 100644 --- a/gtk2_ardour/editor.cc +++ b/gtk2_ardour/editor.cc @@ -2596,10 +2596,10 @@ Editor::trackview_by_y_position (double y, bool trackview_relative_offset) const } void -Editor::set_snapped_cursor_position (samplepos_t pos) +Editor::set_snapped_cursor_position (timepos_t const & pos) { if (_edit_point == EditAtMouse) { - _snapped_cursor->set_position(pos); + snapped_cursor->set_position (pos.samples()); } } diff --git a/gtk2_ardour/editor.h b/gtk2_ardour/editor.h index 8eb8006d88..80fbe90c8e 100644 --- a/gtk2_ardour/editor.h +++ b/gtk2_ardour/editor.h @@ -491,7 +491,7 @@ public: Temporal::RoundMode direction = Temporal::RoundNearest, ARDOUR::SnapPref gpref = ARDOUR::SnapToAny_Visual); - void set_snapped_cursor_position (samplepos_t pos); + void set_snapped_cursor_position (Temporal::timepos_t const & pos); void begin_selection_op_history (); void begin_reversible_selection_op (std::string cmd_name); @@ -2016,7 +2016,7 @@ private: void stop_canvas_autoscroll (); /* trimming */ - void point_trim (GdkEvent*, samplepos_t); + void point_trim (GdkEvent*, Temporal::timepos_t const &); void trim_region_front(); void trim_region_back(); diff --git a/gtk2_ardour/editor_drag.cc b/gtk2_ardour/editor_drag.cc index d0d79410d9..af52c1dcdb 100644 --- a/gtk2_ardour/editor_drag.cc +++ b/gtk2_ardour/editor_drag.cc @@ -86,6 +86,7 @@ using namespace Gtk; using namespace Gtkmm2ext; using namespace Editing; using namespace ArdourCanvas; +using namespace Temporal; using Gtkmm2ext::Keyboard; @@ -96,7 +97,7 @@ DragManager::DragManager (Editor* e) , _ending (false) , _current_pointer_x (0.0) , _current_pointer_y (0.0) - , _current_pointer_sample (0) + , _current_pointer_time (0) , _old_follow_playhead (false) { } @@ -159,7 +160,7 @@ DragManager::start_grab (GdkEvent* e, Gdk::Cursor* c) _old_follow_playhead = _editor->follow_playhead (); _editor->set_follow_playhead (false); - _current_pointer_sample = _editor->canvas_event_sample (e, &_current_pointer_x, &_current_pointer_y); + _current_pointer_time = timepos_t (_editor->canvas_event_sample (e, &_current_pointer_x, &_current_pointer_y)); for (list::const_iterator i = _drags.begin(); i != _drags.end(); ++i) { if ((*i)->grab_button() < 0) { @@ -223,7 +224,7 @@ DragManager::motion_handler (GdkEvent* e, bool from_autoscroll) * Can we guarantee that this is true? */ - _current_pointer_sample = _editor->canvas_event_sample (e, &_current_pointer_x, &_current_pointer_y); + _current_pointer_time = timepos_t (_editor->canvas_event_sample (e, &_current_pointer_x, &_current_pointer_y)); for (list::iterator i = _drags.begin(); i != _drags.end(); ++i) { bool const t = (*i)->motion_handler (e, from_autoscroll); @@ -254,8 +255,8 @@ Drag::Drag (Editor* e, ArdourCanvas::Item* i, bool trackview_only) : _editor (e) , _drags (0) , _item (i) - , _pointer_sample_offset (0) - , _video_sample_offset (0) + , _pointer_offset (0) + , _video_offset (0) , _preview_video (false) , _x_constrained (false) , _y_constrained (false) @@ -270,11 +271,7 @@ Drag::Drag (Editor* e, ArdourCanvas::Item* i, bool trackview_only) , _grab_y (0.0) , _last_pointer_x (0.0) , _last_pointer_y (0.0) - , _raw_grab_sample (0) - , _grab_sample (0) - , _last_pointer_sample (0) , _snap_delta (0) - , _snap_delta_music (0.0) , _constraint_pressed (false) , _grab_button (-1) { @@ -299,20 +296,19 @@ Drag::swap_grab (ArdourCanvas::Item* new_item, Gdk::Cursor* cursor, uint32_t /*t void Drag::start_grab (GdkEvent* event, Gdk::Cursor *cursor) { - /* we set up x/y dragging constraints on first move */ _constraint_pressed = ArdourKeyboard::indicates_constraint (event->button.state); - _raw_grab_sample = _editor->canvas_event_sample (event, &_grab_x, &_grab_y); + _raw_grab_time = timepos_t (_editor->canvas_event_sample (event, &_grab_x, &_grab_y)); _grab_button = event->button.button; - setup_pointer_sample_offset (); - setup_video_sample_offset (); + setup_pointer_offset (); + setup_video_offset (); if (! UIConfiguration::instance ().get_preview_video_frame_on_drag ()) { _preview_video = false; } - _grab_sample = adjusted_sample (_raw_grab_sample, event).sample; - _last_pointer_sample = _grab_sample; + _grab_time = adjusted_time (_raw_grab_time, event); + _last_pointer_time = _grab_time; _last_pointer_x = _grab_x; if (_trackview_only) { @@ -360,13 +356,13 @@ Drag::end_grab (GdkEvent* event) return _move_threshold_passed; } -MusicSample -Drag::adjusted_sample (samplepos_t f, GdkEvent const * event, bool snap) const +timepos_t +Drag::adjusted_time (timepos_t const & f, GdkEvent const * event, bool snap) const { - MusicSample pos (0, 0); + timepos_t pos (f); - if (f > _pointer_sample_offset) { - pos.sample = f - _pointer_sample_offset; + if (f > _pointer_offset) { + pos.shift_earlier (_pointer_offset); } if (snap) { @@ -376,29 +372,30 @@ Drag::adjusted_sample (samplepos_t f, GdkEvent const * event, bool snap) const return pos; } -samplepos_t -Drag::adjusted_current_sample (GdkEvent const * event, bool snap) const +timepos_t +Drag::adjusted_current_time (GdkEvent const * event, bool snap) const { - return adjusted_sample (_drags->current_pointer_sample (), event, snap).sample; + return adjusted_time (_drags->current_pointer_time (), event, snap); } -sampleoffset_t +timecnt_t Drag::snap_delta (guint state) const { if (ArdourKeyboard::indicates_snap_delta (state)) { return _snap_delta; } - return 0; + return timecnt_t(); } -double + +Beats Drag::snap_delta_music (guint state) const { if (ArdourKeyboard::indicates_snap_delta (state)) { return _snap_delta_music; } - return 0.0; + return Beats(); } double @@ -418,17 +415,16 @@ Drag::current_pointer_y () const } void -Drag::setup_snap_delta (MusicSample pos) +Drag::setup_snap_delta (timepos_t const & pos) { - TempoMap& map (_editor->session()->tempo_map()); - MusicSample snap (pos); + timepos_t snap (pos); _editor->snap_to (snap, Temporal::RoundNearest, ARDOUR::SnapToAny_Visual, true); - _snap_delta = snap.sample - pos.sample; + _snap_delta = pos.distance (snap); - _snap_delta_music = 0.0; + _snap_delta_music = Temporal::Beats(); if (_snap_delta != 0) { - _snap_delta_music = map.exact_qn_at_sample (snap.sample, snap.division) - map.exact_qn_at_sample (pos.sample, pos.division); + _snap_delta_music = snap.beats() - pos.beats(); } } @@ -442,13 +438,13 @@ Drag::motion_handler (GdkEvent* event, bool from_autoscroll) return false; } - pair const threshold = move_threshold (); + pair const threshold = move_threshold (); bool const old_move_threshold_passed = _move_threshold_passed; if (!_move_threshold_passed) { - bool const xp = (::fabs ((current_pointer_x () - _grab_x)) >= threshold.first); + bool const xp = (_raw_grab_time.distance (_drags->current_pointer_time ()).abs() >= threshold.first); bool const yp = (::fabs ((current_pointer_y () - _grab_y)) >= threshold.second); _move_threshold_passed = ((xp && x_movement_matters()) || (yp && y_movement_matters())); @@ -519,7 +515,7 @@ Drag::motion_handler (GdkEvent* event, bool from_autoscroll) _last_pointer_x = _drags->current_pointer_x (); _last_pointer_y = current_pointer_y (); - _last_pointer_sample = adjusted_current_sample (event, false); + _last_pointer_time = adjusted_current_time (event, false); } return true; @@ -544,16 +540,16 @@ Drag::abort () } void -Drag::show_verbose_cursor_time (samplepos_t sample) +Drag::show_verbose_cursor_time (timepos_t const & pos) { - _editor->verbose_cursor()->set_time (sample); + _editor->verbose_cursor()->set_time (pos.samples()); _editor->verbose_cursor()->show (); } void -Drag::show_verbose_cursor_duration (samplepos_t start, samplepos_t end, double /*xoffset*/) +Drag::show_verbose_cursor_duration (timepos_t const & start, timepos_t const & end, double /*xoffset*/) { - _editor->verbose_cursor()->set_duration (start, end); + _editor->verbose_cursor()->set_duration (start.samples(), end.samples()); _editor->verbose_cursor()->show (); } @@ -565,10 +561,10 @@ Drag::show_verbose_cursor_text (string const & text) } void -Drag::show_view_preview (samplepos_t sample) +Drag::show_view_preview (timepos_t const & pos) { if (_preview_video) { - ARDOUR_UI::instance()->video_timeline->manual_seek_video_monitor (sample); + ARDOUR_UI::instance()->video_timeline->manual_seek_video_monitor (pos.samples()); } } @@ -576,13 +572,12 @@ boost::shared_ptr Drag::add_midi_region (MidiTimeAxisView* view, bool commit) { if (_editor->session()) { - const TempoMap& map (_editor->session()->tempo_map()); - samplecnt_t pos = grab_sample(); + const timepos_t pos (grab_time()); /* not that the frame rate used here can be affected by pull up/down which might be wrong. */ - samplecnt_t len = map.sample_at_beat (max (0.0, map.beat_at_sample (pos)) + 1.0) - pos; - return view->add_region (grab_sample(), len, commit); + timecnt_t len = pos.distance (max (timepos_t::zero (Temporal::BeatTime), timepos_t (pos.beats() + Beats (1, 0)))); + return view->add_region (grab_time(), len, commit); } return boost::shared_ptr(); @@ -662,17 +657,17 @@ RegionDrag::find_time_axis_view (TimeAxisView* t) const } void -RegionDrag::setup_video_sample_offset () +RegionDrag::setup_video_offset () { if (_views.empty ()) { _preview_video = true; return; } - samplepos_t first_sync = _views.begin()->view->region()->sync_position (); + timepos_t first_sync = _views.begin()->view->region()->sync_position (); for (list::const_iterator i = _views.begin(); i != _views.end(); ++i) { first_sync = std::min (first_sync, i->view->region()->sync_position ()); } - _video_sample_offset = first_sync + _pointer_sample_offset - raw_grab_sample (); + _video_offset = raw_grab_time().distance (first_sync + _pointer_offset); _preview_video = true; } @@ -805,7 +800,6 @@ RegionBrushDrag::aborted (bool movement_occurred) RegionMotionDrag::RegionMotionDrag (Editor* e, ArdourCanvas::Item* i, RegionView* p, list const & v) : RegionDrag (e, i, p, v) , _ignore_video_lock (false) - , _last_position (0, 0) , _total_x_delta (0) , _last_pointer_time_axis_view (0) , _last_pointer_layer (0) @@ -822,8 +816,8 @@ RegionMotionDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor) Drag::start_grab (event, cursor); setup_snap_delta (_last_position); - show_verbose_cursor_time (_last_position.sample); - show_view_preview (_last_position.sample + _video_sample_offset); + show_verbose_cursor_time (_last_position); + show_view_preview (_last_position + _video_offset); /* this conditional is required because drag-n-drop'ed regions end up * here, and at this point they are not attached to a playlist. @@ -851,41 +845,41 @@ RegionMotionDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor) } double -RegionMotionDrag::compute_x_delta (GdkEvent const * event, MusicSample* pending_region_position) +RegionMotionDrag::compute_x_delta (GdkEvent const * event, Temporal::timepos_t & pending_region_position) { /* compute the amount of pointer motion in samples, and where the region would be if we moved it by that much. */ if (_x_constrained) { - *pending_region_position = _last_position; + pending_region_position = _last_position; return 0.0; } - *pending_region_position = adjusted_sample (_drags->current_pointer_sample (), event, false); + pending_region_position = adjusted_time (_drags->current_pointer_time (), event, false); - samplecnt_t sync_offset; + timecnt_t sync_offset; int32_t sync_dir; sync_offset = _primary->region()->sync_offset (sync_dir); /* we don't handle a sync point that lies before zero. */ - if (sync_dir >= 0 || (sync_dir < 0 && pending_region_position->sample >= sync_offset)) { + if (sync_dir >= 0 || (sync_dir < 0 && pending_region_position >= sync_offset)) { - samplecnt_t const sd = snap_delta (event->button.state); - MusicSample sync_snap (pending_region_position->sample + (sync_dir * sync_offset) + sd, 0); + timecnt_t const sd = snap_delta (event->button.state); + timepos_t sync_snap (pending_region_position + (sync_offset * sync_dir) + sd); _editor->snap_to_with_modifier (sync_snap, event); - if (sync_offset == 0 && sd == 0) { - *pending_region_position = sync_snap; + if (sync_offset.zero() && sd.zero()) { + pending_region_position = sync_snap; } else { - pending_region_position->set (_primary->region()->adjust_to_sync (sync_snap.sample) - sd, 0); + pending_region_position = _primary->region()->adjust_to_sync (sync_snap).earlier (sd); } } else { - *pending_region_position = _last_position; + pending_region_position = _last_position; } - if (pending_region_position->sample > max_samplepos - _primary->region()->length()) { - *pending_region_position = _last_position; + if (pending_region_position > timepos_t::max (pending_region_position.time_domain()).earlier (_primary->region()->nt_length())) { + pending_region_position = _last_position; } if (pending_region_position->sample <= _earliest_time_limit) { @@ -897,25 +891,25 @@ RegionMotionDrag::compute_x_delta (GdkEvent const * event, MusicSample* pending_ bool const x_move_allowed = !_x_constrained; - if ((pending_region_position->sample != _last_position.sample) && x_move_allowed) { + if ((pending_region_position != _last_position) && x_move_allowed) { /* x movement since last time (in pixels) */ - dx = _editor->sample_to_pixel_unrounded (pending_region_position->sample - _last_position.sample); + dx = _editor->duration_to_pixels_unrounded (_last_position.distance (pending_region_position)); /* total x movement */ - samplecnt_t total_dx = _editor->pixel_to_sample (_total_x_delta + dx); + timecnt_t total_dx = timecnt_t (samplepos_t (_editor->pixel_to_sample (_total_x_delta + dx)), grab_time()); for (list::const_iterator i = _views.begin(); i != _views.end(); ++i) { - sampleoffset_t const off = i->view->region()->position() + total_dx; - if (off < 0) { - dx = dx - _editor->sample_to_pixel_unrounded (off); - *pending_region_position = MusicSample (pending_region_position->sample - off, 0); + const timepos_t off = i->view->region()->nt_position() + total_dx; + if (off.negative()) { + dx = dx - _editor->time_to_pixel_unrounded (off); + pending_region_position = pending_region_position.earlier (timecnt_t (off, timepos_t (pending_region_position.time_domain()))); break; } } } - _editor->set_snapped_cursor_position(pending_region_position->sample); + _editor->set_snapped_cursor_position (pending_region_position); return dx; } @@ -1167,12 +1161,11 @@ RegionMotionDrag::motion (GdkEvent* event, bool first_move) } /* Work out the change in x */ - TempoMap& tmap = _editor->session()->tempo_map(); - MusicSample pending_region_position (0, 0); - double const x_delta = compute_x_delta (event, &pending_region_position); + timepos_t pending_region_position; + double const x_delta = compute_x_delta (event, pending_region_position); - double const last_pos_qn = tmap.exact_qn_at_sample (_last_position.sample, _last_position.division); - double const qn_delta = tmap.exact_qn_at_sample (pending_region_position.sample, pending_region_position.division) - last_pos_qn; + Temporal::Beats const last_pos_qn = _last_position.beats(); + Temporal::Beats const qn_delta = pending_region_position.beats() - last_pos_qn; _last_position = pending_region_position; @@ -1418,11 +1411,9 @@ RegionMotionDrag::motion (GdkEvent* event, bool first_move) } /* Now move the region view */ - if (rv->region()->position_lock_style() == MusicTime) { - double const last_qn = tmap.quarter_note_at_sample (rv->get_position()); - samplepos_t const x_pos_music = tmap.sample_at_quarter_note (last_qn + qn_delta); - - rv->set_position (x_pos_music, 0); + if (rv->region()->position_time_domain() == Temporal::BeatTime) { + Temporal::Beats const last_qn = rv->get_position().beats(); + rv->set_position (timepos_t (last_qn + qn_delta), 0); rv->move (0, y_delta); } else { rv->move (x_delta, y_delta); @@ -1432,8 +1423,8 @@ RegionMotionDrag::motion (GdkEvent* event, bool first_move) _total_x_delta += x_delta; if (x_delta != 0) { - show_verbose_cursor_time (_last_position.sample); - show_view_preview (_last_position.sample + _video_sample_offset); + show_verbose_cursor_time (_last_position); + show_view_preview (_last_position + _video_offset); } /* keep track of pointer movement */ @@ -1622,7 +1613,7 @@ RegionMoveDrag::finished (GdkEvent* ev, bool movement_occurred) i->view->get_canvas_group()->show (); } - bool const changed_position = (_last_position.sample != _primary->region()->position()); + bool const changed_position = (_last_position != _primary->region()->nt_position()); bool changed_tracks; if (_views.front().time_axis_view >= (int) _time_axis_views.size()) { @@ -1676,11 +1667,11 @@ RegionMoveDrag::create_destination_time_axis (boost::shared_ptr region, try { if (boost::dynamic_pointer_cast (region)) { list > audio_tracks; - uint32_t output_chan = region->n_channels(); + uint32_t output_chan = region->sources().size(); if ((Config->get_output_auto_connect() & AutoConnectMaster) && _editor->session()->master_out()) { output_chan = _editor->session()->master_out()->n_inputs().n_audio(); } - audio_tracks = _editor->session()->new_audio_track (region->n_channels(), output_chan, 0, 1, region->name(), PresentationInfo::max_order); + audio_tracks = _editor->session()->new_audio_track (region->sources().size(), output_chan, 0, 1, region->name(), PresentationInfo::max_order); tav =_editor->time_axis_view_from_stripable (audio_tracks.front()); } else { ChanCount one_midi_port (DataType::MIDI, 1); @@ -1715,19 +1706,14 @@ RegionMoveDrag::clear_draggingview_list () _views.clear(); } -void -RegionMoveDrag::finished_copy (bool const changed_position, bool const changed_tracks, MusicSample last_position, int32_t const ev_state) +RegionMoveDrag::finished_copy (bool const changed_position, bool const /*changed_tracks*/, timepos_t const & last_position, int32_t const ev_state) { RegionSelection new_views; PlaylistSet modified_playlists; RouteTimeAxisView* new_time_axis_view = 0; - samplecnt_t const drag_delta = _primary->region()->position() - _last_position.sample; + timecnt_t const drag_delta = _last_position.distance (_primary->region()->nt_position()); RegionList ripple_exclude; - TempoMap& tmap (_editor->session()->tempo_map()); - const double last_pos_qn = tmap.exact_qn_at_sample (last_position.sample, last_position.division); - const double qn_delta = _primary->region()->quarter_note() - last_pos_qn; - /*x_contrained on the same track: this will just make a duplicate region in the same place: abort the operation */ if (_x_constrained && !changed_tracks) { clear_draggingview_list(); @@ -1751,16 +1737,12 @@ RegionMoveDrag::finished_copy (bool const changed_position, bool const changed_t continue; } - MusicSample where (0, 0); - double quarter_note; + timepos_t where; if (changed_position && !_x_constrained) { - where.set (i->view->region()->position() - drag_delta, 0); - quarter_note = i->view->region()->quarter_note() - qn_delta; + where = timepos_t (i->view->region()->nt_position().earlier (drag_delta)); } else { - /* region has not moved - divisor will not affect musical pos */ - where.set (i->view->region()->position(), 0); - quarter_note = i->view->region()->quarter_note(); + where = timepos_t (i->view->region()->nt_position()); } /* compute full extent of regions that we're going to insert */ @@ -1799,14 +1781,14 @@ RegionMoveDrag::finished_copy (bool const changed_position, bool const changed_t if (dest_rtv != 0) { RegionView* new_view; if (i->view == _primary && !_x_constrained) { - new_view = insert_region_into_playlist (i->view->region(), dest_rtv, i->layer, last_position, last_pos_qn, + new_view = insert_region_into_playlist (i->view->region(), dest_rtv, i->layer, last_position, modified_playlists, true); } else { - if (i->view->region()->position_lock_style() == AudioTime) { - new_view = insert_region_into_playlist (i->view->region(), dest_rtv, i->layer, where, quarter_note, + if (i->view->region()->position_time_domain() == Temporal::AudioTime) { + new_view = insert_region_into_playlist (i->view->region(), dest_rtv, i->layer, where, modified_playlists); } else { - new_view = insert_region_into_playlist (i->view->region(), dest_rtv, i->layer, where, quarter_note, + new_view = insert_region_into_playlist (i->view->region(), dest_rtv, i->layer, where, modified_playlists, true); } } @@ -1849,7 +1831,7 @@ void RegionMoveDrag::finished_no_copy ( bool const changed_position, bool const changed_tracks, - MusicSample last_position, + timepos_t const & last_position, int32_t const ev_state ) { @@ -1858,18 +1840,14 @@ RegionMoveDrag::finished_no_copy ( PlaylistSet frozen_playlists; set views_to_update; RouteTimeAxisView* new_time_axis_view = 0; - samplecnt_t const drag_delta = _primary->region()->position() - last_position.sample; + timecnt_t const drag_delta = last_position.distance (_primary->region()->nt_position()); RegionList ripple_exclude; typedef map, RouteTimeAxisView*> PlaylistMapping; PlaylistMapping playlist_mapping; - TempoMap& tmap (_editor->session()->tempo_map()); - const double last_pos_qn = tmap.exact_qn_at_sample (last_position.sample, last_position.division); - const double qn_delta = _primary->region()->quarter_note() - last_pos_qn; - /* determine earliest position affected by the drag, across all playlists */ - samplepos_t extent_min = max_samplepos; + timepos_t extent_min = timepos_t::max (Temporal::AudioTime); /* NUTEMPO fix domain */ std::set > uniq; for (list::const_iterator i = _views.begin(); i != _views.end(); ) { @@ -1919,15 +1897,12 @@ RegionMoveDrag::finished_no_copy ( views_to_update.insert (dest_rtv); - MusicSample where (0, 0); - double quarter_note; + timepos_t where; if (changed_position && !_x_constrained) { - where.set (rv->region()->position() - drag_delta, 0); - quarter_note = i->view->region()->quarter_note() - qn_delta; + where = rv->region()->nt_position().earlier (drag_delta); } else { - where.set (rv->region()->position(), 0); - quarter_note = i->view->region()->quarter_note(); + where = rv->region()->nt_position(); } /* compute full extent of regions that we're going to insert */ @@ -1944,21 +1919,15 @@ RegionMoveDrag::finished_no_copy ( RegionView* new_view; if (rv == _primary && !_x_constrained) { new_view = insert_region_into_playlist ( - RegionFactory::create (rv->region (), true), dest_rtv, dest_layer, last_position, last_pos_qn, - modified_playlists, true - ); + RegionFactory::create (rv->region (), true), dest_rtv, dest_layer, last_position,modified_playlists, true); } else { - if (rv->region()->position_lock_style() == AudioTime) { + if (rv->region()->position_time_domain() == Temporal::AudioTime) { new_view = insert_region_into_playlist ( - RegionFactory::create (rv->region (), true), dest_rtv, dest_layer, where, quarter_note, - modified_playlists - ); + RegionFactory::create (rv->region (), true), dest_rtv, dest_layer, where, modified_playlists); } else { new_view = insert_region_into_playlist ( - RegionFactory::create (rv->region (), true), dest_rtv, dest_layer, where, quarter_note, - modified_playlists, true - ); + RegionFactory::create (rv->region (), true), dest_rtv, dest_layer, where, modified_playlists, true); } } @@ -2018,17 +1987,9 @@ RegionMoveDrag::finished_no_copy ( if (r.second) { playlist->freeze (); } - if (rv == _primary) { - rv->region()->set_position (where.sample, last_position.division); - } else { - if (rv->region()->position_lock_style() == AudioTime) { - /* move by sample offset */ - rv->region()->set_position (where.sample, 0); - } else { - /* move by music offset */ - rv->region()->set_position (rv->region()->quarter_note() - qn_delta); - } - } + + rv->region()->set_position (where); + _editor->session()->add_command (new StatefulDiffCommand (rv->region())); } @@ -2135,8 +2096,7 @@ RegionMoveDrag::insert_region_into_playlist ( boost::shared_ptr region, RouteTimeAxisView* dest_rtv, layer_t dest_layer, - MusicSample where, - double quarter_note, + timepos_t const & where, PlaylistSet& modified_playlists, bool for_music ) @@ -2159,11 +2119,7 @@ RegionMoveDrag::insert_region_into_playlist ( /* cannot freeze because we need the new region announcements */ } - if (for_music) { - dest_playlist->add_region (region, where.sample, 1.0, false, where.division, quarter_note, true); - } else { - dest_playlist->add_region (region, where.sample, 1.0, false, where.division); - } + dest_playlist->add_region (region, where, 1.0, for_music); if (dest_rtv->view()->layer_display() == Stacked || dest_rtv->view()->layer_display() == Expanded) { dest_playlist->set_layer (region, dest_layer); @@ -2233,17 +2189,17 @@ RegionMoveDrag::RegionMoveDrag (Editor* e, ArdourCanvas::Item* i, RegionView* p, { DEBUG_TRACE (DEBUG::Drags, "New RegionMoveDrag\n"); - _last_position = MusicSample (_primary->region()->position(), 0); + _last_position = _primary->region()->nt_position(); } void -RegionMoveDrag::setup_pointer_sample_offset () +RegionMoveDrag::setup_pointer_offset () { - _pointer_sample_offset = raw_grab_sample() - _last_position.sample; + _pointer_offset = timecnt_t (_last_position.distance (raw_grab_time()), _last_position); } -RegionInsertDrag::RegionInsertDrag (Editor* e, boost::shared_ptr r, RouteTimeAxisView* v, samplepos_t pos) - : RegionMotionDrag (e, 0, 0, list ()) +RegionInsertDrag::RegionInsertDrag (Editor* e, boost::shared_ptr r, RouteTimeAxisView* v, timepos_t const & pos) + : RegionMotionDrag (e, 0, 0, list (), false) { DEBUG_TRACE (DEBUG::Drags, "New RegionInsertDrag\n"); @@ -2256,7 +2212,7 @@ RegionInsertDrag::RegionInsertDrag (Editor* e, boost::shared_ptr r, Rout _primary->set_position (pos, 0); _views.push_back (DraggingView (_primary, this, v)); - _last_position = MusicSample (pos, 0); + _last_position = pos; _item = _primary->get_canvas_group (); } @@ -2279,10 +2235,10 @@ RegionInsertDrag::finished (GdkEvent * event, bool) playlist->clear_owned_changes (); _editor->snap_to_with_modifier (_last_position, event); - playlist->add_region (_primary->region (), _last_position.sample, 1.0, false, _last_position.division); + playlist->add_region (_primary->region (), _last_position, 1.0, false); if (_editor->should_ripple()) { - _editor->do_ripple (playlist,_last_position.sample, _primary->region()->length(), _primary->region(), true); + playlist->ripple (_last_position, _primary->region()->nt_length(), _primary->region()); } else { playlist->rdiff_and_add_command (_editor->session()); } @@ -2302,6 +2258,330 @@ RegionInsertDrag::aborted (bool) _views.clear (); } + +/*** + * ripple mode... + */ + +void +RegionRippleDrag::add_all_after_to_views(TimeAxisView *tav, timepos_t const & where, const RegionSelection &exclude, bool drag_in_progress) +{ + + boost::shared_ptr rl = tav->playlist()->regions_with_start_within (TimelineRange (where, timepos_t::max (where.time_domain()), 0)); + + RouteTimeAxisView* rtv = dynamic_cast(tav); + RegionSelection to_ripple; + for (RegionList::iterator i = rl->begin(); i != rl->end(); ++i) { + if ((*i)->nt_position() >= where) { + to_ripple.push_back (rtv->view()->find_view(*i)); + } + } + + for (RegionSelection::reverse_iterator i = to_ripple.rbegin(); i != to_ripple.rend(); ++i) { + if (!exclude.contains (*i)) { + // the selection has already been added to _views + + if (drag_in_progress) { + // do the same things that RegionMotionDrag::motion does when + // first_move is true, for the region views that we're adding + // to _views this time + + (*i)->drag_start(); + ArdourCanvas::Item* rvg = (*i)->get_canvas_group(); + Duple rv_canvas_offset = rvg->item_to_canvas (Duple (0,0)); + Duple dmg_canvas_offset = _editor->_drag_motion_group->canvas_origin (); + rvg->reparent (_editor->_drag_motion_group); + + // we only need to move in the y direction + Duple fudge = rv_canvas_offset - dmg_canvas_offset; + fudge.x = 0; + rvg->move (fudge); + + } + _views.push_back (DraggingView (*i, this, tav)); + } + } +} + +void +RegionRippleDrag::remove_unselected_from_views(timecnt_t const & amount, bool move_regions) +{ + ThawList thawlist; + + for (std::list::iterator i = _views.begin(); i != _views.end(); ) { + // we added all the regions after the selection + + std::list::iterator to_erase = i++; + if (!_editor->selection->regions.contains (to_erase->view)) { + // restore the non-selected regions to their original playlist & positions, + // and then ripple them back by the length of the regions that were dragged away + // do the same things as RegionMotionDrag::aborted + + RegionView *rv = to_erase->view; + TimeAxisView* tv = &(rv->get_time_axis_view ()); + RouteTimeAxisView* rtv = dynamic_cast (tv); + assert (rtv); + + // plonk them back onto their own track + rv->get_canvas_group()->reparent(rtv->view()->canvas_item()); + rv->get_canvas_group()->set_y_position (0); + rv->drag_end (); + + if (move_regions) { + thawlist.add (rv->region ()); + // move the underlying region to match the view + rv->region()->set_position (rv->region()->nt_position() + amount); + } else { + // restore the view to match the underlying region's original position +#warning NUTEMPO ALERT paul test this code in 5.x /* how can this work ... amount used to be in samples but ::move() expect pixels */ + //rv->move(-amount, 0); // second parameter is y delta - seems 0 is OK + } + + rv->set_height (rtv->view()->child_height ()); + _views.erase (to_erase); + } + } + thawlist.release (); +} + +bool +RegionRippleDrag::y_movement_allowed (int delta_track, double delta_layer, int skip_invisible) const +{ + if (RegionMotionDrag::y_movement_allowed (delta_track, delta_layer, skip_invisible)) { + if (delta_track) { + return allow_moves_across_tracks; + } else { + return true; + } + } + return false; +} + +RegionRippleDrag::RegionRippleDrag (Editor* e, ArdourCanvas::Item* i, RegionView* p, list const & v) + : RegionMoveDrag (e, i, p, v, false) +{ + DEBUG_TRACE (DEBUG::Drags, "New RegionRippleDrag\n"); + // compute length of selection + RegionSelection selected_regions = _editor->selection->regions; + selection_length = selected_regions.start_time().distance (selected_regions.end_time()); + + // Rippling accross tracks disabled. Rippling on all tracks is the way to go in the future. + allow_moves_across_tracks = false; // (selected_regions.playlists().size() == 1); + prev_tav = NULL; + prev_amount = 0; + exclude = new RegionList; + for (RegionSelection::iterator i =selected_regions.begin(); i != selected_regions.end(); ++i) { + exclude->push_back((*i)->region()); + } + + // also add regions before start of selection to exclude, to be consistent with how Mixbus does ripple + RegionSelection copy; + selected_regions.by_position(copy); // get selected regions sorted by position into copy + + std::set > playlists = copy.playlists(); + std::set >::const_iterator pi; + + for (pi = playlists.begin(); pi != playlists.end(); ++pi) { + // find ripple start point on each applicable playlist + RegionView *first_selected_on_this_track = NULL; + for (RegionSelection::iterator i = copy.begin(); i != copy.end(); ++i) { + if ((*i)->region()->playlist() == (*pi)) { + // region is on this playlist - it's the first, because they're sorted + first_selected_on_this_track = *i; + break; + } + } + assert (first_selected_on_this_track); // we should always find the region in one of the playlists... + add_all_after_to_views ( + &first_selected_on_this_track->get_time_axis_view(), + first_selected_on_this_track->region()->nt_position(), + selected_regions, false); + } + + if (allow_moves_across_tracks) { + orig_tav = &(*selected_regions.begin())->get_time_axis_view(); + for (std::list::const_iterator it = _views.begin(); it != _views.end(); ++it) { + _orig_tav_ripples.push_back((*it).view->region()); + } + } else { + orig_tav = NULL; + } + +} + +void +RegionRippleDrag::motion (GdkEvent* event, bool first_move) +{ + /* Which trackview is this ? */ + + pair const tvp = _editor->trackview_by_y_position (current_pointer_y ()); + RouteTimeAxisView* tv = dynamic_cast (tvp.first); + + /* The region motion is only processed if the pointer is over + an audio track. + */ + + if (!tv || !tv->is_track()) { + /* To make sure we hide the verbose canvas cursor when the mouse is + not held over an audiotrack. + */ + _editor->verbose_cursor()->hide (); + return; + } + + timepos_t where = adjusted_current_time (event); + assert (!where.negative()); + timepos_t after; + double delta = compute_x_delta (event, after); + + timecnt_t amount = timecnt_t (_editor->pixel_to_sample (delta), grab_time()); + + if (allow_moves_across_tracks) { + // all the originally selected regions were on the same track + + timecnt_t adjust; + + if (prev_tav && tv != prev_tav) { + // dragged onto a different track + // remove the unselected regions from _views, restore them to their original positions + // and add the regions after the drop point on the new playlist to _views instead. + // undo the effect of rippling the previous playlist, and include the effect of removing + // the dragged region(s) from this track + + remove_unselected_from_views (prev_amount, false); + // ripple previous playlist according to the regions that have been removed onto the new playlist + prev_tav->playlist()->ripple(prev_position, -selection_length, exclude); + prev_amount = 0; + + // move just the selected regions + RegionMoveDrag::motion(event, first_move); + + // ensure that the ripple operation on the new playlist inserts selection_length time + adjust = selection_length; + // ripple the new current playlist + tv->playlist()->ripple (where, amount+adjust, exclude); + + // add regions after point where drag entered this track to subsequent ripples + add_all_after_to_views (tv, where, _editor->selection->regions, true); + + } else { + // motion on same track + RegionMoveDrag::motion(event, first_move); + } + prev_tav = tv; + + // remember what we've done to this playlist so we can undo it if the selection is dragged to another track + prev_position = where; + } else { + // selection encompasses multiple tracks - just drag + // cross-track drags are forbidden + RegionMoveDrag::motion(event, first_move); + } + + if (!_x_constrained) { + prev_amount += amount; + } + + _last_position = after; +} + +void +RegionRippleDrag::finished (GdkEvent* event, bool movement_occurred) +{ + if (!movement_occurred) { + + /* just a click */ + + if (was_double_click() && !_views.empty()) { + DraggingView dv = _views.front(); + _editor->edit_region (dv.view); + } + + return; + } + + _editor->begin_reversible_command(_("Ripple drag")); + + // remove the regions being rippled from the dragging view, updating them to + // their new positions + + if (allow_moves_across_tracks) { + if (orig_tav) { + // if regions were dragged across tracks, we've rippled any later + // regions on the track the regions were dragged off, so we need + // to add the original track to the undo record + orig_tav->playlist()->clear_changes(); + orig_tav->playlist()->clear_owned_changes(); + orig_tav->playlist()->freeze (); + + remove_unselected_from_views (prev_amount, true); + + std::list >::const_iterator it = _orig_tav_ripples.begin(); + for (; it != _orig_tav_ripples.end(); ++it) { + const boost::shared_ptr r = *it; + bool found = false; + for (std::list::const_iterator it = _views.begin(); it != _views.end(); ++it) { + if (it->view->region() == r) { + found = true; + break; + } + } + if (!found) { + const timepos_t pos_after = r->nt_position(); + const timepos_t pos_before = pos_after + selection_length; + r->set_position(pos_before); + r->clear_changes(); + r->set_position(pos_after); + } + } + + orig_tav->playlist()->thaw (); + + vector cmds; + orig_tav->playlist()->rdiff (cmds); + _editor->session()->add_commands (cmds); + } + if (prev_tav && prev_tav != orig_tav) { + prev_tav->playlist()->clear_changes(); + vector cmds; + prev_tav->playlist()->rdiff (cmds); + _editor->session()->add_commands (cmds); + } + } else { + // selection spanned multiple tracks - all will need adding to undo record + + std::set > playlists = _editor->selection->regions.playlists(); + std::set >::const_iterator pi; + + for (pi = playlists.begin(); pi != playlists.end(); ++pi) { + (*pi)->clear_changes(); + (*pi)->clear_owned_changes(); + (*pi)->freeze(); + } + + remove_unselected_from_views (prev_amount, true); + + for (pi = playlists.begin(); pi != playlists.end(); ++pi) { + (*pi)->thaw(); + vector cmds; + (*pi)->rdiff (cmds); + _editor->session()->add_commands (cmds); + } + } + + // other modified playlists are added to undo by RegionMoveDrag::finished() + RegionMoveDrag::finished (event, movement_occurred); + _editor->commit_reversible_command(); +} + +void +RegionRippleDrag::aborted (bool movement_occurred) +{ + RegionMoveDrag::aborted (movement_occurred); + _views.clear (); +} + + RegionCreateDrag::RegionCreateDrag (Editor* e, ArdourCanvas::Item* i, TimeAxisView* v) : Drag (e, i), _view (dynamic_cast (v)) @@ -2322,14 +2602,14 @@ RegionCreateDrag::motion (GdkEvent* event, bool first_move) } else { if (_region) { - samplepos_t const f = adjusted_current_sample (event); - if (f <= grab_sample()) { - _region->set_initial_position (f); + timepos_t const pos = adjusted_current_time (event); + if (pos <= grab_time()) { + _region->set_initial_position (pos); } - if (f != grab_sample()) { - samplecnt_t const len = ::llabs (f - grab_sample ()); - _region->set_length (len, _editor->get_grid_music_divisions (event->button.state)); + if (pos != grab_time()) { + timecnt_t const len = grab_time().distance (pos).abs(); + _region->set_length (len); } } } @@ -2574,7 +2854,7 @@ NoteResizeDrag::aborted (bool) AVDraggingView::AVDraggingView (RegionView* v) : view (v) { - initial_position = v->region()->position (); + initial_position = v->region()->position_sample(); } VideoTimeLineDrag::VideoTimeLineDrag (Editor* e, ArdourCanvas::Item* i) @@ -2585,7 +2865,7 @@ VideoTimeLineDrag::VideoTimeLineDrag (Editor* e, ArdourCanvas::Item* i) RegionSelection rs; TrackViewList empty; empty.clear(); - _editor->get_regions_after(rs, (samplepos_t) 0, empty); + _editor->get_regions_after(rs, timepos_t::zero (Temporal::AudioTime), empty); std::list views = rs.by_layer(); _stuck = false; @@ -2654,7 +2934,7 @@ VideoTimeLineDrag::motion (GdkEvent* event, bool first_move) return; } - samplecnt_t dt = adjusted_current_sample (event) - raw_grab_sample() + _pointer_sample_offset; + samplecnt_t dt = adjusted_current_time (event).samples() - raw_grab_time().samples() + _pointer_offset.samples(); dt = ARDOUR_UI::instance()->video_timeline->quantify_samples_to_apv(_startdrag_video_offset+dt) - _startdrag_video_offset; if (_max_backwards_drag >= 0 && dt <= - _max_backwards_drag) { @@ -2672,7 +2952,7 @@ VideoTimeLineDrag::motion (GdkEvent* event, bool first_move) rv->region()->clear_changes (); rv->region()->suspend_property_changes(); } - rv->region()->set_position(i->initial_position + dt); + rv->region()->set_position(timepos_t (i->initial_position + dt)); rv->region_changed(ARDOUR::Properties::position); } @@ -2724,9 +3004,9 @@ VideoTimeLineDrag::finished (GdkEvent * /*event*/, bool movement_occurred) } _editor->session()->maybe_update_session_range( - std::max(ARDOUR_UI::instance()->video_timeline->get_offset(), (ARDOUR::sampleoffset_t) 0), - std::max(ARDOUR_UI::instance()->video_timeline->get_offset() + ARDOUR_UI::instance()->video_timeline->get_duration(), (ARDOUR::sampleoffset_t) 0) - ); + timepos_t (std::max(ARDOUR_UI::instance()->video_timeline->get_offset(), (sampleoffset_t) 0)), + timepos_t (std::max(ARDOUR_UI::instance()->video_timeline->get_offset() + ARDOUR_UI::instance()->video_timeline->get_duration(), (sampleoffset_t) 0)) + ); _editor->commit_reversible_command (); @@ -2743,7 +3023,7 @@ VideoTimeLineDrag::aborted (bool) for (list::iterator i = _views.begin(); i != _views.end(); ++i) { i->view->region()->resume_property_changes (); - i->view->region()->set_position(i->initial_position); + i->view->region()->set_position(timepos_t (i->initial_position)); } } @@ -2759,12 +3039,12 @@ TrimDrag::TrimDrag (Editor* e, ArdourCanvas::Item* i, RegionView* p, listregion()->position(); - samplepos_t const region_end = _primary->region()->last_sample(); - samplecnt_t const region_length = _primary->region()->length(); + timepos_t const region_start = _primary->region()->nt_position(); + timepos_t const region_end = _primary->region()->nt_end(); + timecnt_t const region_length = _primary->region()->nt_length(); - samplepos_t const pf = adjusted_current_sample (event); - setup_snap_delta (MusicSample(region_start, 0)); + timepos_t const pf = adjusted_current_time (event); + setup_snap_delta (region_start); /* These will get overridden for a point trim.*/ if (pf < (region_start + region_length/2)) { @@ -2812,9 +3092,9 @@ TrimDrag::motion (GdkEvent* event, bool first_move) RegionView* rv = _primary; pair >::iterator,bool> insert_result; - - MusicSample adj_sample = adjusted_sample (_drags->current_pointer_sample () + snap_delta (event->button.state), event, true); - samplecnt_t dt = adj_sample.sample - raw_grab_sample () + _pointer_sample_offset - snap_delta (event->button.state); + timecnt_t delta; + timepos_t adj_time = adjusted_time (_drags->current_pointer_time () + snap_delta (event->button.state), event, true); + timecnt_t dt = adj_time.distance (raw_grab_time ()) + _pointer_offset - snap_delta (event->button.state); if (first_move) { @@ -2884,6 +3164,11 @@ TrimDrag::motion (GdkEvent* event, bool first_move) /* contstrain trim to fade length */ if (_preserve_fade_anchor) { + + /* fades are audio and always use AudioTime domain */ + + samplecnt_t dts = dt.samples(); + switch (_operation) { case StartTrim: for (list::const_iterator i = _views.begin(); i != _views.end(); ++i) { @@ -2891,8 +3176,8 @@ TrimDrag::motion (GdkEvent* event, bool first_move) if (!arv) continue; boost::shared_ptr ar (arv->audio_region()); if (ar->locked()) continue; - samplecnt_t len = ar->fade_in()->back()->when; - if (len < dt) dt = min(dt, len); + samplecnt_t len = ar->fade_in()->back()->when.samples(); + if (len < dts) dts = min(dts, len); } break; case EndTrim: @@ -2901,8 +3186,8 @@ TrimDrag::motion (GdkEvent* event, bool first_move) if (!arv) continue; boost::shared_ptr ar (arv->audio_region()); if (ar->locked()) continue; - samplecnt_t len = ar->fade_out()->back()->when; - if (len < -dt) dt = max(dt, -len); + samplecnt_t len = ar->fade_out()->back()->when.samples(); + if (len < -dts) dts = max(dts, -len); } break; } @@ -2911,17 +3196,17 @@ TrimDrag::motion (GdkEvent* event, bool first_move) switch (_operation) { case StartTrim: for (list::iterator i = _views.begin(); i != _views.end(); ++i) { - bool changed = i->view->trim_front (i->initial_position + dt, non_overlap_trim - , adj_sample.division); + bool changed = i->view->trim_front (timepos_t (i->initial_position) + dt, non_overlap_trim); + if (changed && _preserve_fade_anchor) { AudioRegionView* arv = dynamic_cast (i->view); if (arv) { boost::shared_ptr ar (arv->audio_region()); - samplecnt_t len = ar->fade_in()->back()->when; - samplecnt_t diff = ar->first_sample() - i->initial_position; + samplecnt_t len = ar->fade_in()->back()->when.samples(); + samplecnt_t diff = ar->first_sample() - i->initial_position.samples(); samplepos_t new_length = len - diff; - i->anchored_fade_length = min (ar->length(), new_length); + i->anchored_fade_length = min (ar->length_samples(), new_length); //i->anchored_fade_length = ar->verify_xfade_bounds (new_length, true /*START*/ ); arv->reset_fade_in_shape_width (ar, i->anchored_fade_length, true); } @@ -2931,15 +3216,16 @@ TrimDrag::motion (GdkEvent* event, bool first_move) case EndTrim: for (list::iterator i = _views.begin(); i != _views.end(); ++i) { - bool changed = i->view->trim_end (i->initial_end + dt, non_overlap_trim, adj_sample.division); + bool changed = i->view->trim_end (timepos_t (i->initial_end) + dt, non_overlap_trim); + if (changed && _preserve_fade_anchor) { AudioRegionView* arv = dynamic_cast (i->view); if (arv) { boost::shared_ptr ar (arv->audio_region()); - samplecnt_t len = ar->fade_out()->back()->when; - samplecnt_t diff = 1 + ar->last_sample() - i->initial_end; + samplecnt_t len = ar->fade_out()->back()->when.samples(); + samplecnt_t diff = 1 + ar->last_sample() - i->initial_end.samples(); samplepos_t new_length = len + diff; - i->anchored_fade_length = min (ar->length(), new_length); + i->anchored_fade_length = min (ar->length_samples(), new_length); //i->anchored_fade_length = ar->verify_xfade_bounds (new_length, false /*END*/ ); arv->reset_fade_out_shape_width (ar, i->anchored_fade_length, true); } @@ -2951,13 +3237,13 @@ TrimDrag::motion (GdkEvent* event, bool first_move) switch (_operation) { case StartTrim: - show_verbose_cursor_time (rv->region()->position()); + show_verbose_cursor_time (rv->region()->nt_position()); break; case EndTrim: - show_verbose_cursor_duration (rv->region()->position(), rv->region()->last_sample()); + show_verbose_cursor_duration (rv->region()->nt_position(), rv->region()->nt_end()); break; } - show_view_preview ((_operation == StartTrim ? rv->region()->position() : rv->region()->last_sample())); + show_view_preview ((_operation == StartTrim ? rv->region()->nt_position() : rv->region()->nt_end())); } void @@ -2985,7 +3271,7 @@ TrimDrag::finished (GdkEvent* event, bool movement_occurred) } } if (_jump_position_when_done) { - i->view->region()->set_position (i->initial_position); + i->view->region()->set_position (timepos_t (i->initial_position)); } } } else if (_operation == EndTrim) { @@ -3000,7 +3286,7 @@ TrimDrag::finished (GdkEvent* event, bool movement_occurred) } } if (_jump_position_when_done) { - i->view->region()->set_position (i->initial_end - i->view->region()->length()); + i->view->region()->set_position (timepos_t (i->initial_end).earlier (i->view->region()->nt_length())); } } } @@ -3032,8 +3318,8 @@ TrimDrag::finished (GdkEvent* event, bool movement_occurred) } else { /* no mouse movement */ - if (adjusted_current_sample (event) != adjusted_sample (_drags->current_pointer_sample(), event, false).sample) { - _editor->point_trim (event, adjusted_current_sample (event)); + if (adjusted_current_time (event) != adjusted_time (_drags->current_pointer_time(), event, false)) { + _editor->point_trim (event, adjusted_current_time (event)); } } @@ -3064,7 +3350,7 @@ TrimDrag::aborted (bool movement_occurred) } void -TrimDrag::setup_pointer_sample_offset () +TrimDrag::setup_pointer_offset () { list::iterator i = _views.begin (); while (i != _views.end() && i->view != _primary) { @@ -3077,10 +3363,10 @@ TrimDrag::setup_pointer_sample_offset () switch (_operation) { case StartTrim: - _pointer_sample_offset = raw_grab_sample() - i->initial_position; + _pointer_offset = i->initial_position.distance (raw_grab_time()); break; case EndTrim: - _pointer_sample_offset = raw_grab_sample() - i->initial_end; + _pointer_offset = i->initial_end.distance (raw_grab_time()); break; } } @@ -3103,18 +3389,22 @@ void MeterMarkerDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor) { Drag::start_grab (event, cursor); - show_verbose_cursor_time (adjusted_current_sample(event)); + show_verbose_cursor_time (adjusted_current_time (event)); } void -MeterMarkerDrag::setup_pointer_sample_offset () +MeterMarkerDrag::setup_pointer_offset () { - _pointer_sample_offset = raw_grab_sample() - _marker->meter().sample(); +#warning NUTEMPO fixme needs new tempo map API to get "time()" for meter + // _pointer_offset = raw_grab_time() - _marker->meter().time(); } void MeterMarkerDrag::motion (GdkEvent* event, bool first_move) { +#warning NUTEMPO fixme needs new tempo map +#if 0 + if (first_move) { // create a dummy marker to catch events, then hide it. @@ -3136,7 +3426,6 @@ MeterMarkerDrag::motion (GdkEvent* event, bool first_move) TempoMap& map (_editor->session()->tempo_map()); /* get current state */ before_state = &map.get_state(); - if (!_copy) { _editor->begin_reversible_command (_("move meter mark")); } else { @@ -3145,30 +3434,29 @@ MeterMarkerDrag::motion (GdkEvent* event, bool first_move) Temporal::BBT_Time bbt = _real_section->bbt(); /* we can't add a meter where one currently exists */ - if (_real_section->sample() < adjusted_current_sample (event, false)) { + if (_real_section->time() < adjusted_current_time (event, false)) { ++bbt.bars; } else { --bbt.bars; } const samplepos_t sample = map.sample_at_bbt (bbt); _real_section = map.add_meter (Meter (_marker->meter().divisions_per_bar(), _marker->meter().note_divisor()) - , bbt, sample, _real_section->position_lock_style()); + , bbt, sample, _real_section->position_time_domain()); if (!_real_section) { aborted (true); return; } - - } +1 } /* only snap to bars. leave snap mode alone for audio locked meters.*/ - if (_real_section->position_lock_style() != AudioTime) { + if (_real_section->position_time_domain() != AudioTime) { _editor->set_grid_to (GridTypeBar); _editor->set_snap_mode (SnapMagnetic); } } - samplepos_t pf = adjusted_current_sample (event); + timepos_t pf = adjusted_current_time (event); - if (_real_section->position_lock_style() == AudioTime && _editor->grid_musical()) { + if (_real_section->position_time_domain() == Temporal::AudioTime && _editor->grid_musical()) { /* never snap to music for audio locked */ pf = adjusted_current_sample (event, false); } @@ -3176,10 +3464,11 @@ MeterMarkerDrag::motion (GdkEvent* event, bool first_move) _editor->session()->tempo_map().gui_set_meter_position (_real_section, pf); /* fake marker meeds to stay under the mouse, unlike the real one. */ - _marker->set_position (adjusted_current_sample (event, false)); + _marker->set_position (adjusted_current_time (event, false)); - show_verbose_cursor_time (_real_section->sample()); + show_verbose_cursor_time (_real_section->time()); _editor->set_snapped_cursor_position(_real_section->sample()); +#endif } void @@ -3196,11 +3485,14 @@ MeterMarkerDrag::finished (GdkEvent* event, bool movement_occurred) _editor->set_grid_to (_old_grid_type); _editor->set_snap_mode (_old_snap_mode); +#warning NUTEMPO fixme needs new tempo map +#if 0 TempoMap& map (_editor->session()->tempo_map()); XMLNode &after = map.get_state(); _editor->session()->add_command(new MementoCommand(map, before_state, &after)); _editor->commit_reversible_command (); +#endif // delete the dummy marker we used for visual representation while moving. // a new visual marker will show up automatically. @@ -3210,6 +3502,8 @@ MeterMarkerDrag::finished (GdkEvent* event, bool movement_occurred) void MeterMarkerDrag::aborted (bool moved) { +#warning NUTEMPO fixme needs new tempo map +#if 0 _marker->set_position (_marker->meter().sample ()); if (moved) { /* reinstate old snap setting */ @@ -3221,6 +3515,7 @@ MeterMarkerDrag::aborted (bool moved) // a new visual marker will show up automatically. delete _marker; } +#endif } TempoMarkerDrag::TempoMarkerDrag (Editor* e, ArdourCanvas::Item* i, bool c) @@ -3232,12 +3527,15 @@ TempoMarkerDrag::TempoMarkerDrag (Editor* e, ArdourCanvas::Item* i, bool c) { DEBUG_TRACE (DEBUG::Drags, "New TempoMarkerDrag\n"); +#warning NUTEMPO fixme needs new tempo map +#if 0 _marker = reinterpret_cast (_item->get_data ("marker")); _real_section = &_marker->tempo(); _movable = !_real_section->initial(); _grab_bpm = Tempo (_real_section->note_types_per_minute(), _real_section->note_type(), _real_section->end_note_types_per_minute()); _grab_qn = _real_section->pulse() * 4.0; assert (_marker); +#endif } void @@ -3247,14 +3545,17 @@ TempoMarkerDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor) if (!_real_section->active()) { show_verbose_cursor_text (_("inactive")); } else { - show_verbose_cursor_time (adjusted_current_sample (event)); + show_verbose_cursor_time (adjusted_current_time (event)); } } void -TempoMarkerDrag::setup_pointer_sample_offset () +TempoMarkerDrag::setup_pointer_offset () { - _pointer_sample_offset = raw_grab_sample() - _real_section->sample(); +#warning NUTEMPO fixme needs new tempo map +#if 0 + _pointer_offset = raw_grab_time() - _real_section->time(); +#endif } void @@ -3263,6 +3564,9 @@ TempoMarkerDrag::motion (GdkEvent* event, bool first_move) if (!_real_section->active()) { return; } +#warning NUTEMPO fixme needs new tempo map +#if 0 + TempoMap& map (_editor->session()->tempo_map()); if (first_move) { @@ -3298,9 +3602,9 @@ TempoMarkerDrag::motion (GdkEvent* event, bool first_move) _editor->begin_reversible_command (_("copy tempo mark")); - if (_real_section->position_lock_style() == MusicTime) { + if (_real_section->position_time_domain() == BeatTime) { const int32_t divisions = _editor->get_grid_music_divisions (event->button.state); - _real_section = map.add_tempo (tempo, map.exact_qn_at_sample (sample, divisions), 0, MusicTime); + _real_section = map.add_tempo (tempo, map.exact_qn_at_sample (sample, divisions), 0, BeatTime); } else { _real_section = map.add_tempo (tempo, 0.0, sample, AudioTime); } @@ -3312,6 +3616,7 @@ TempoMarkerDrag::motion (GdkEvent* event, bool first_move) } } + if (ArdourKeyboard::indicates_constraint (event->button.state) && ArdourKeyboard::indicates_copy (event->button.state)) { double new_bpm = max (1.5, _grab_bpm.end_note_types_per_minute() + ((grab_y() - min (-1.0, current_pointer_y())) / 5.0)); stringstream strs; @@ -3347,12 +3652,16 @@ TempoMarkerDrag::motion (GdkEvent* event, bool first_move) show_verbose_cursor_time (_real_section->sample()); _editor->set_snapped_cursor_position(_real_section->sample()); } + _marker->set_position (adjusted_current_sample (event, false)); +#endif } void TempoMarkerDrag::finished (GdkEvent* event, bool movement_occurred) { +#warning NUTEMPO fixme needs new tempo map +#if 0 if (!_real_section->active()) { return; } @@ -3368,7 +3677,7 @@ TempoMarkerDrag::finished (GdkEvent* event, bool movement_occurred) XMLNode &after = map.get_state(); _editor->session()->add_command (new MementoCommand(map, _before_state, &after)); _editor->commit_reversible_command (); - +#endif // delete the dummy marker we used for visual representation while moving. // a new visual marker will show up automatically. delete _marker; @@ -3377,6 +3686,8 @@ TempoMarkerDrag::finished (GdkEvent* event, bool movement_occurred) void TempoMarkerDrag::aborted (bool moved) { +#warning NUTEMPO fixme needs new tempo map +#if 0 _marker->set_position (_marker->tempo().sample()); if (moved) { TempoMap& map (_editor->session()->tempo_map()); @@ -3384,6 +3695,7 @@ TempoMarkerDrag::aborted (bool moved) // delete the dummy (hidden) marker we used for events while moving. delete _marker; } +#endif } BBTRulerDrag::BBTRulerDrag (Editor* e, ArdourCanvas::Item* i) @@ -3401,10 +3713,13 @@ void BBTRulerDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor) { Drag::start_grab (event, cursor); + +#warning NUTEMPO fixme needs new tempo map +#if 0 TempoMap& map (_editor->session()->tempo_map()); _tempo = const_cast (&map.tempo_section_at_sample (raw_grab_sample())); - if (adjusted_current_sample (event, false) <= _tempo->sample()) { + if (adjusted_current_time (event, false) <= _tempo->time()) { _drag_valid = false; return; } @@ -3421,11 +3736,14 @@ BBTRulerDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor) sstr << "start: " << fixed << setprecision(3) << _tempo->note_types_per_minute(); show_verbose_cursor_text (sstr.str()); +#endif } void -BBTRulerDrag::setup_pointer_sample_offset () +BBTRulerDrag::setup_pointer_offset () { +#warning NUTEMPO fixme needs new tempo map +#if 0 TempoMap& map (_editor->session()->tempo_map()); /* get current state */ _before_state = &map.get_state(); @@ -3446,8 +3764,9 @@ BBTRulerDrag::setup_pointer_sample_offset () _grab_qn = map.quarter_note_at_beat (beat); - _pointer_sample_offset = raw_grab_sample() - map.sample_at_quarter_note (_grab_qn); + _pointer_offset = raw_grab_sample() - map.sample_at_quarter_note (_grab_qn); +#endif } void @@ -3461,6 +3780,8 @@ BBTRulerDrag::motion (GdkEvent* event, bool first_move) _editor->begin_reversible_command (_("stretch tempo")); } +#warning NUTEMPO fixme needs new tempo map +#if 0 TempoMap& map (_editor->session()->tempo_map()); samplepos_t pf; @@ -3485,6 +3806,7 @@ BBTRulerDrag::motion (GdkEvent* event, bool first_move) } sstr << "start: " << fixed << setprecision(3) << _tempo->note_types_per_minute(); show_verbose_cursor_text (sstr.str()); +#endif } void @@ -3494,6 +3816,8 @@ BBTRulerDrag::finished (GdkEvent* event, bool movement_occurred) return; } +#warning NUTEMPO fixme needs new tempo map +#if 0 TempoMap& map (_editor->session()->tempo_map()); _editor->tempo_curve_selected (_tempo, false); @@ -3511,17 +3835,24 @@ BBTRulerDrag::finished (GdkEvent* event, bool movement_occurred) XMLNode &after = map.get_state(); _editor->session()->add_command(new MementoCommand(map, _before_state, &after)); _editor->commit_reversible_command (); - +#endif } void BBTRulerDrag::aborted (bool moved) { +#warning NUTEMPO fixme needs new tempo map +#if 0 if (moved) { _editor->session()->tempo_map().set_state (*_before_state, Stateful::current_state_version); } +#endif } + +#warning NUTEMPO fixme no tempo twist drag for now +#if 0 + TempoTwistDrag::TempoTwistDrag (Editor* e, ArdourCanvas::Item* i) : Drag (e, i) , _grab_qn (0.0) @@ -3573,7 +3904,7 @@ TempoTwistDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor) } void -TempoTwistDrag::setup_pointer_sample_offset () +TempoTwistDrag::setup_pointer_offset () { TempoMap& map (_editor->session()->tempo_map()); const double beat_at_sample = max (0.0, map.beat_at_sample (raw_grab_sample())); @@ -3592,7 +3923,7 @@ TempoTwistDrag::setup_pointer_sample_offset () _grab_qn = map.quarter_note_at_beat (beat); - _pointer_sample_offset = raw_grab_sample() - map.sample_at_quarter_note (_grab_qn); + _pointer_offset = raw_grab_sample() - map.sample_at_quarter_note (_grab_qn); } @@ -3652,10 +3983,10 @@ TempoTwistDrag::aborted (bool moved) _editor->session()->tempo_map().set_state (*_before_state, Stateful::current_state_version); } } +#endif TempoEndDrag::TempoEndDrag (Editor* e, ArdourCanvas::Item* i) : Drag (e, i) - , _grab_qn (0.0) , _tempo (0) , _before_state (0) , _drag_valid (true) @@ -3670,11 +4001,12 @@ void TempoEndDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor) { Drag::start_grab (event, cursor); +#warning NUTEMPO fixme needs new tmepo map +#if 0 TempoMap& tmap (_editor->session()->tempo_map()); /* get current state */ _before_state = &tmap.get_state(); - if (_tempo->locked_to_meter()) { _drag_valid = false; return; @@ -3694,15 +4026,14 @@ TempoEndDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor) } show_verbose_cursor_text (sstr.str()); +#endif } void -TempoEndDrag::setup_pointer_sample_offset () +TempoEndDrag::setup_pointer_offset () { - TempoMap& map (_editor->session()->tempo_map()); - - _pointer_sample_offset = raw_grab_sample() - map.sample_at_quarter_note (_grab_qn); - +#warning NUTEMPO grab_qn should be timepos_t + // _pointer_offset = _grab_qn.distance (raw_grab_time()); } void @@ -3712,6 +4043,8 @@ TempoEndDrag::motion (GdkEvent* event, bool first_move) return; } +#warning NUTEMPO fixme needs new tempo map +#if 0 TempoMap& map (_editor->session()->tempo_map()); if (first_move) { @@ -3729,6 +4062,7 @@ TempoEndDrag::motion (GdkEvent* event, bool first_move) } show_verbose_cursor_text (sstr.str()); +#endif } void @@ -3738,6 +4072,8 @@ TempoEndDrag::finished (GdkEvent* event, bool movement_occurred) return; } +#warning NUTEMPO fixme needs new tempo map +#if 0 TempoMap& tmap (_editor->session()->tempo_map()); XMLNode &after = tmap.get_state(); @@ -3753,14 +4089,18 @@ TempoEndDrag::finished (GdkEvent* event, bool movement_occurred) _editor->tempo_curve_selected (_tempo, false); } +#endif } void TempoEndDrag::aborted (bool moved) { +#warning NUTEMPO fixme needs new tempo map +#if 0 if (moved) { _editor->session()->tempo_map().set_state (*_before_state, Stateful::current_state_version); } +#endif } CursorDrag::CursorDrag (Editor* e, EditorCursor& c, bool s) @@ -3798,7 +4138,7 @@ CursorDrag::fake_locate (samplepos_t t) s->queue_song_position_pointer (); } - show_verbose_cursor_time (t); + show_verbose_cursor_time (timepos_t (t)); _editor->UpdateAllTransportClocks (t); } @@ -3807,16 +4147,16 @@ CursorDrag::start_grab (GdkEvent* event, Gdk::Cursor* c) { Drag::start_grab (event, c); - setup_snap_delta (MusicSample (_editor->playhead_cursor ()->current_sample(), 0)); + setup_snap_delta (timepos_t (_editor->playhead_cursor->current_sample())); _grab_zoom = _editor->samples_per_pixel; - MusicSample where (_editor->canvas_event_sample (event) + snap_delta (event->button.state), 0); + timepos_t where (timepos_t (_editor->canvas_event_sample (event)) + snap_delta (event->button.state)); _editor->snap_to_with_modifier (where, event); _editor->_dragging_playhead = true; - _editor->_control_scroll_target = where.sample; + _editor->_control_scroll_target = where.samples(); Session* s = _editor->session (); @@ -3850,7 +4190,7 @@ CursorDrag::start_grab (GdkEvent* event, Gdk::Cursor* c) } } - fake_locate (where.sample - snap_delta (event->button.state)); + fake_locate (where.earlier (snap_delta (event->button.state)).samples()); _last_mx = event->button.x; _last_my = event->button.y; @@ -3861,12 +4201,12 @@ CursorDrag::start_grab (GdkEvent* event, Gdk::Cursor* c) void CursorDrag::motion (GdkEvent* event, bool) { - MusicSample where (_editor->canvas_event_sample (event) + snap_delta (event->button.state), 0); + timepos_t where (timepos_t (_editor->canvas_event_sample (event)) + snap_delta (event->button.state)); _editor->snap_to_with_modifier (where, event); - if (where.sample != last_pointer_sample()) { - fake_locate (where.sample - snap_delta (event->button.state)); + if (where != last_pointer_time()) { + fake_locate (where.earlier (snap_delta (event->button.state)).samples());; } //maybe do zooming, too, if the option is enabled @@ -3934,7 +4274,7 @@ CursorDrag::aborted (bool) _editor->_dragging_playhead = false; } - _editor->playhead_cursor ()->set_position (adjusted_sample (grab_sample (), 0, false).sample); + _editor->playhead_cursor->set_position (adjusted_time (grab_time (), 0, false).samples()); } FadeInDrag::FadeInDrag (Editor* e, ArdourCanvas::Item* i, RegionView* p, list const & v) @@ -3950,38 +4290,40 @@ FadeInDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor) AudioRegionView* arv = dynamic_cast (_primary); boost::shared_ptr const r = arv->audio_region (); - setup_snap_delta (MusicSample (r->position(), 0)); + setup_snap_delta (r->nt_position()); - show_verbose_cursor_duration (r->position(), r->position() + r->fade_in()->back()->when, 32); - show_view_preview (r->position() + r->fade_in()->back()->when); + show_verbose_cursor_duration (r->nt_position(), r->nt_position() + r->fade_in()->back()->when, 32); + show_view_preview (r->nt_position() + r->fade_in()->back()->when); } void -FadeInDrag::setup_pointer_sample_offset () +FadeInDrag::setup_pointer_offset () { AudioRegionView* arv = dynamic_cast (_primary); boost::shared_ptr const r = arv->audio_region (); - _pointer_sample_offset = raw_grab_sample() - ((samplecnt_t) r->fade_in()->back()->when + r->position()); + _pointer_offset = (r->fade_in()->back()->when + r->nt_position()).distance (raw_grab_time()); } void FadeInDrag::motion (GdkEvent* event, bool) { - samplecnt_t fade_length; - MusicSample pos (_editor->canvas_event_sample (event) + snap_delta (event->button.state), 0); - _editor->snap_to_with_modifier (pos, event); + timepos_t tpos (timepos_t (_editor->canvas_event_sample (event)) + snap_delta (event->button.state)); + _editor->snap_to_with_modifier (tpos, event); + tpos.shift_earlier (snap_delta (event->button.state)); - pos.sample -= snap_delta (event->button.state); + samplepos_t pos = tpos.samples (); boost::shared_ptr region = boost::dynamic_pointer_cast (_primary->region ()); - if (pos.sample < (region->position() + 64)) { + samplecnt_t fade_length; + + if (pos < (region->position_sample() + 64)) { fade_length = 64; // this should be a minimum defined somewhere - } else if (pos.sample > region->position() + region->length() - region->fade_out()->back()->when) { - fade_length = region->length() - region->fade_out()->back()->when - 1; + } else if (pos > region->position_sample() + region->length_samples() - region->fade_out()->back()->when.samples()) { + fade_length = region->length_samples() - region->fade_out()->back()->when.samples() - 1; } else { - fade_length = pos.sample - region->position(); + fade_length = pos - region->position_sample(); } for (list::iterator i = _views.begin(); i != _views.end(); ++i) { @@ -3995,8 +4337,8 @@ FadeInDrag::motion (GdkEvent* event, bool) tmp->reset_fade_in_shape_width (tmp->audio_region(), fade_length); } - show_verbose_cursor_duration (region->position(), region->position() + fade_length, 32); - show_view_preview (region->position() + fade_length); + show_verbose_cursor_duration (region->nt_position(), region->nt_position() + timepos_t (fade_length), 32); + show_view_preview (region->nt_position() + timepos_t (fade_length)); } void @@ -4006,20 +4348,21 @@ FadeInDrag::finished (GdkEvent* event, bool movement_occurred) return; } - samplecnt_t fade_length; - MusicSample pos (_editor->canvas_event_sample (event) + snap_delta (event->button.state), 0); + timepos_t tpos (timepos_t (_editor->canvas_event_sample (event)) + snap_delta (event->button.state)); + _editor->snap_to_with_modifier (tpos, event); + tpos.shift_earlier (snap_delta (event->button.state)); - _editor->snap_to_with_modifier (pos, event); - pos.sample -= snap_delta (event->button.state); + samplepos_t pos = tpos.samples (); + samplecnt_t fade_length; boost::shared_ptr region = boost::dynamic_pointer_cast (_primary->region ()); - if (pos.sample < (region->position() + 64)) { + if (pos < (region->position_sample() + 64)) { fade_length = 64; // this should be a minimum defined somewhere - } else if (pos.sample >= region->position() + region->length() - region->fade_out()->back()->when) { - fade_length = region->length() - region->fade_out()->back()->when - 1; + } else if (pos >= region->position_sample() + region->length_samples() - region->fade_out()->back()->when.samples()) { + fade_length = region->length_samples() - region->fade_out()->back()->when.samples() - 1; } else { - fade_length = pos.sample - region->position(); + fade_length = pos - region->position_sample(); } bool in_command = false; @@ -4061,7 +4404,7 @@ FadeInDrag::aborted (bool) continue; } - tmp->reset_fade_in_shape_width (tmp->audio_region(), tmp->audio_region()->fade_in()->back()->when); + tmp->reset_fade_in_shape_width (tmp->audio_region(), tmp->audio_region()->fade_in()->back()->when.samples()); } } @@ -4078,37 +4421,39 @@ FadeOutDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor) AudioRegionView* arv = dynamic_cast (_primary); boost::shared_ptr r = arv->audio_region (); - setup_snap_delta (MusicSample (r->last_sample(), 0)); + setup_snap_delta (r->nt_last()); - show_verbose_cursor_duration (r->last_sample() - r->fade_out()->back()->when, r->last_sample()); + show_verbose_cursor_duration (r->nt_last().earlier (r->fade_out()->back()->when), r->nt_last()); show_view_preview (r->fade_out()->back()->when); } void -FadeOutDrag::setup_pointer_sample_offset () +FadeOutDrag::setup_pointer_offset () { AudioRegionView* arv = dynamic_cast (_primary); boost::shared_ptr r = arv->audio_region (); - _pointer_sample_offset = raw_grab_sample() - (r->length() - (samplecnt_t) r->fade_out()->back()->when + r->position()); + _pointer_offset = (r->nt_position() + (r->nt_length() - r->fade_out()->back()->when)).distance (raw_grab_time()); } void FadeOutDrag::motion (GdkEvent* event, bool) { samplecnt_t fade_length; - MusicSample pos (_editor->canvas_event_sample (event) + snap_delta (event->button.state), 0); - _editor->snap_to_with_modifier (pos, event); - pos.sample -= snap_delta (event->button.state); + timepos_t tpos (timepos_t (_editor->canvas_event_sample (event)) + snap_delta (event->button.state)); + _editor->snap_to_with_modifier (tpos, event); + tpos.shift_earlier (snap_delta (event->button.state)); + + samplepos_t pos (tpos.samples()); boost::shared_ptr region = boost::dynamic_pointer_cast (_primary->region ()); - if (pos.sample > (region->last_sample() - 64)) { + if (pos > (region->last_sample() - 64)) { fade_length = 64; // this should really be a minimum fade defined somewhere - } else if (pos.sample <= region->position() + region->fade_in()->back()->when) { - fade_length = region->length() - region->fade_in()->back()->when - 1; + } else if (pos <= region->position_sample() + region->fade_in()->back()->when.samples()) { + fade_length = region->length_samples() - region->fade_in()->back()->when.samples() - 1; } else { - fade_length = region->last_sample() - pos.sample; + fade_length = region->last_sample() - pos; } for (list::iterator i = _views.begin(); i != _views.end(); ++i) { @@ -4122,8 +4467,9 @@ FadeOutDrag::motion (GdkEvent* event, bool) tmp->reset_fade_out_shape_width (tmp->audio_region(), fade_length); } - show_verbose_cursor_duration (region->last_sample() - fade_length, region->last_sample()); - show_view_preview (region->last_sample() - fade_length); +#warning NUTEMPO the mix of timepos_t and duration does not seem correct + show_verbose_cursor_duration (timepos_t (region->last_sample() - fade_length), region->nt_last()); + show_view_preview (timepos_t (region->last_sample() - fade_length)); } void @@ -4133,20 +4479,22 @@ FadeOutDrag::finished (GdkEvent* event, bool movement_occurred) return; } - samplecnt_t fade_length; - MusicSample pos (_editor->canvas_event_sample (event) + snap_delta (event->button.state), 0); + timepos_t tpos (timepos_t (_editor->canvas_event_sample (event)) + snap_delta (event->button.state)); + _editor->snap_to_with_modifier (tpos, event); + tpos.shift_earlier (snap_delta (event->button.state)); - _editor->snap_to_with_modifier (pos, event); - pos.sample -= snap_delta (event->button.state); + samplepos_t pos (tpos.samples()); + + samplecnt_t fade_length; boost::shared_ptr region = boost::dynamic_pointer_cast (_primary->region ()); - if (pos.sample > (region->last_sample() - 64)) { + if (pos > (region->last_sample() - 64)) { fade_length = 64; // this should really be a minimum fade defined somewhere - } else if (pos.sample <= region->position() + region->fade_in()->back()->when) { - fade_length = region->length() - region->fade_in()->back()->when - 1; + } else if (pos <= region->position_sample() + region->fade_in()->back()->when.samples()) { + fade_length = region->length_samples() - region->fade_in()->back()->when.samples() - 1; } else { - fade_length = region->last_sample() - pos.sample; + fade_length = region->last_sample() - pos; } bool in_command = false; @@ -4188,7 +4536,7 @@ FadeOutDrag::aborted (bool) continue; } - tmp->reset_fade_out_shape_width (tmp->audio_region(), tmp->audio_region()->fade_out()->back()->when); + tmp->reset_fade_out_shape_width (tmp->audio_region(), tmp->audio_region()->fade_out()->back()->when.samples()); } } @@ -4240,8 +4588,8 @@ MarkerDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor) } else { show_verbose_cursor_time (location->end()); } - show_view_preview ((is_start ? location->start() : location->end()) + _video_sample_offset); - setup_snap_delta (MusicSample (is_start ? location->start() : location->end(), 0)); + show_view_preview ((is_start ? location->start() : location->end()) + _video_offset); + setup_snap_delta (timepos_t (is_start ? location->start() : location->end())); Selection::Operation op = ArdourKeyboard::selection_type (event->button.state); @@ -4259,14 +4607,14 @@ MarkerDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor) { Locations::LocationList ll; list to_add; - samplepos_t s, e; + timepos_t s, e; _editor->selection->markers.range (s, e); s = min (_marker->position(), s); e = max (_marker->position(), e); s = min (s, e); e = max (s, e); - if (e < max_samplepos) { - ++e; + if (e < timepos_t::max (e.time_domain())) { + e.increment(); } _editor->session()->locations()->find_all_between (s, e, ll, Location::Flags (0)); for (Locations::LocationList::iterator i = ll.begin(); i != ll.end(); ++i) { @@ -4328,32 +4676,32 @@ MarkerDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor) } void -MarkerDrag::setup_pointer_sample_offset () +MarkerDrag::setup_pointer_offset () { bool is_start; Location *location = _editor->find_location_from_marker (_marker, is_start); - _pointer_sample_offset = raw_grab_sample() - (is_start ? location->start() : location->end()); + _pointer_offset = (is_start ? location->start() : location->end()).distance (raw_grab_time()); } void -MarkerDrag::setup_video_sample_offset () +MarkerDrag::setup_video_offset () { - _video_sample_offset = 0; + _video_offset = 0; _preview_video = true; } void MarkerDrag::motion (GdkEvent* event, bool) { - samplecnt_t f_delta = 0; + timecnt_t f_delta; bool is_start; bool move_both = false; Location *real_location; Location *copy_location = 0; - samplecnt_t const sd = snap_delta (event->button.state); + timecnt_t const sd = snap_delta (event->button.state); - samplecnt_t const newframe = adjusted_sample (_drags->current_pointer_sample () + sd, event, true).sample - sd; - samplepos_t next = newframe; + timepos_t const newpos = adjusted_time (_drags->current_pointer_time () + sd, event, true).earlier (sd); + timepos_t next = newpos; if (Keyboard::modifier_state_contains (event->button.state, ArdourKeyboard::push_points_modifier ())) { move_both = true; @@ -4379,7 +4727,7 @@ MarkerDrag::motion (GdkEvent* event, bool) } if (real_location->is_mark()) { - f_delta = newframe - copy_location->start(); + f_delta = copy_location->start().distance (newpos); } else { @@ -4388,14 +4736,14 @@ MarkerDrag::motion (GdkEvent* event, bool) case ArdourMarker::RangeStart: case ArdourMarker::LoopStart: case ArdourMarker::PunchIn: - f_delta = newframe - copy_location->start(); + f_delta = copy_location->start().distance (newpos); break; case ArdourMarker::SessionEnd: case ArdourMarker::RangeEnd: case ArdourMarker::LoopEnd: case ArdourMarker::PunchOut: - f_delta = newframe - copy_location->end(); + f_delta = copy_location->end().distance (newpos); break; default: /* what kind of marker is this ? */ @@ -4412,8 +4760,6 @@ 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) { @@ -4431,37 +4777,37 @@ MarkerDrag::motion (GdkEvent* event, bool) if (copy_location->is_mark()) { /* now move it */ - copy_location->set_start (copy_location->start() + f_delta, false, true, divisions); + copy_location->set_start (copy_location->start() + f_delta, false); } else { - samplepos_t new_start = copy_location->start() + f_delta; - samplepos_t new_end = copy_location->end() + f_delta; + timepos_t new_start = copy_location->start() + f_delta; + timepos_t new_end = copy_location->end() + f_delta; if (is_start) { // start-of-range marker if (move_both || (*x).move_both) { - copy_location->set_start (new_start, false, true, divisions); - copy_location->set_end (new_end, false, true, divisions); + copy_location->set_start (new_start, false); + copy_location->set_end (new_end, false); } else if (new_start < copy_location->end()) { - copy_location->set_start (new_start, false, true, divisions); - } else if (newframe > 0) { + copy_location->set_start (new_start, false); + } else if (newpos.positive()) { //_editor->snap_to (next, RoundUpAlways, true); - copy_location->set_end (next, false, true, divisions); - copy_location->set_start (newframe, false, true, divisions); + copy_location->set_end (next, false); + copy_location->set_start (newpos, false); } } else { // end marker if (move_both || (*x).move_both) { - copy_location->set_end (new_end, divisions); - copy_location->set_start (new_start, false, true, divisions); + copy_location->set_end (new_end); + copy_location->set_start (new_start, false); } else if (new_end > copy_location->start()) { - copy_location->set_end (new_end, false, true, divisions); - } else if (newframe > 0) { + copy_location->set_end (new_end, false); + } else if (newpos.positive()) { //_editor->snap_to (next, RoundDownAlways, true); - copy_location->set_start (next, false, true, divisions); - copy_location->set_end (newframe, false, true, divisions); + copy_location->set_start (next, false); + copy_location->set_end (newpos, false); } } } @@ -4485,9 +4831,9 @@ MarkerDrag::motion (GdkEvent* event, bool) assert (!_copied_locations.empty()); - show_verbose_cursor_time (newframe); - show_view_preview (newframe + _video_sample_offset); - _editor->set_snapped_cursor_position(newframe); + show_verbose_cursor_time (newpos); + show_view_preview (newpos + _video_offset); + _editor->set_snapped_cursor_position (newpos); } void @@ -4557,9 +4903,9 @@ MarkerDrag::finished (GdkEvent* event, bool movement_occurred) in_command = true; } if (location->is_mark()) { - location->set_start (((*x).location)->start(), false, true, divisions); + location->set_start (((*x).location)->start(), false); } else { - location->set (((*x).location)->start(), ((*x).location)->end(), true, divisions); + location->set (((*x).location)->start(), ((*x).location)->end()); } if (location->is_session_range()) { @@ -4632,10 +4978,11 @@ ControlPointDrag::start_grab (GdkEvent* event, Gdk::Cursor* /*cursor*/) // start the grab at the center of the control point so // the point doesn't 'jump' to the mouse after the first drag - _fixed_grab_x = _point->get_x() + _editor->sample_to_pixel_unrounded (_point->line().offset()); + _fixed_grab_x = _point->get_x() + _editor->time_to_pixel_unrounded (timepos_t (_point->line().offset())); _fixed_grab_y = _point->get_y(); - setup_snap_delta (MusicSample (_editor->pixel_to_sample (_fixed_grab_x), 0)); +#warning NUTEMPO is it right that this forced to be samples? + setup_snap_delta (timepos_t (_editor->pixel_to_sample (_fixed_grab_x))); float const fraction = 1 - (_point->get_y() / _point->line().height()); show_verbose_cursor_text (_point->line().get_verbose_cursor_string (fraction)); @@ -4684,14 +5031,14 @@ ControlPointDrag::motion (GdkEvent* event, bool first_motion) cy = zero_gain_y; } - MusicSample cx_mf (_editor->pixel_to_sample (cx) + snap_delta (event->button.state), 0); + timepos_t cx_pos (timepos_t (_editor->pixel_to_sample (cx)) + snap_delta (event->button.state)); if (need_snap) { - _editor->snap_to_with_modifier (cx_mf, event); + _editor->snap_to_with_modifier (cx_pos, event); } - cx_mf.sample -= snap_delta (event->button.state); - cx_mf.sample = min (cx_mf.sample, _point->line().maximum_time() + _point->line().offset()); + cx_pos.shift_earlier (snap_delta (event->button.state)); + cx_pos = min (cx_pos, _point->line().maximum_time() + _point->line().offset()); float const fraction = 1.0 - (cy / _point->line().height()); @@ -4701,7 +5048,7 @@ ControlPointDrag::motion (GdkEvent* event, bool first_motion) _point->line().start_drag_single (_point, _fixed_grab_x, initial_fraction); } pair result; - result = _point->line().drag_motion (_editor->sample_to_pixel_unrounded (cx_mf.sample), fraction, false, _pushing, _final_index); + result = _point->line().drag_motion (_editor->time_to_pixel_unrounded (cx_pos), fraction, false, _pushing, _final_index); show_verbose_cursor_text (_point->line().get_verbose_cursor_relative_string (result.first, result.second)); } @@ -4896,7 +5243,7 @@ FeatureLineDrag::start_grab (GdkEvent* event, Gdk::Cursor* /*cursor*/) _arv = reinterpret_cast (_item->get_data ("regionview")); - _max_x = _editor->sample_to_pixel(_arv->get_duration()); + _max_x = _editor->duration_to_pixels (_arv->get_duration()); } void @@ -4953,33 +5300,33 @@ void RubberbandSelectDrag::start_grab (GdkEvent* event, Gdk::Cursor *) { Drag::start_grab (event); - show_verbose_cursor_time (adjusted_current_sample (event, UIConfiguration::instance().get_rubberbanding_snaps_to_grid())); + show_verbose_cursor_time (adjusted_current_time (event, UIConfiguration::instance().get_rubberbanding_snaps_to_grid())); } void RubberbandSelectDrag::motion (GdkEvent* event, bool) { - samplepos_t start; - samplepos_t end; + timepos_t start; + timepos_t end; double y1; double y2; - samplepos_t const pf = adjusted_current_sample (event, UIConfiguration::instance().get_rubberbanding_snaps_to_grid()); - MusicSample grab (grab_sample (), 0); + timepos_t const pf = adjusted_current_time (event, UIConfiguration::instance().get_rubberbanding_snaps_to_grid()); + timepos_t grab (grab_time ()); if (UIConfiguration::instance().get_rubberbanding_snaps_to_grid ()) { _editor->snap_to_with_modifier (grab, event, RoundNearest, SnapToGrid_Scaled); } else { - grab.sample = raw_grab_sample (); + grab = raw_grab_time (); } /* base start and end on initial click position */ - if (pf < grab.sample) { + if (pf < grab) { start = pf; - end = grab.sample; + end = grab; } else { end = pf; - start = grab.sample; + start = grab; } if (current_pointer_y() < grab_y()) { @@ -4992,8 +5339,8 @@ RubberbandSelectDrag::motion (GdkEvent* event, bool) if (start != end || y1 != y2) { - double x1 = _editor->sample_to_pixel (start); - double x2 = _editor->sample_to_pixel (end); + double x1 = _editor->time_to_pixel (start); + double x2 = _editor->time_to_pixel (end); const double min_dimension = 2.0; if (_vertical_only) { @@ -5038,13 +5385,13 @@ RubberbandSelectDrag::motion (GdkEvent* event, bool) void RubberbandSelectDrag::do_select_things (GdkEvent* event, bool drag_in_progress) { - samplepos_t x1; - samplepos_t x2; - samplepos_t grab = grab_sample (); - samplepos_t lpf = last_pointer_sample (); + timepos_t x1; + timepos_t x2; + timepos_t grab = grab_time (); + timepos_t lpf = last_pointer_time (); if (!UIConfiguration::instance().get_rubberbanding_snaps_to_grid ()) { - grab = raw_grab_sample (); + grab = raw_grab_time (); lpf = _editor->pixel_to_sample_from_event (last_pointer_x()); } @@ -5133,11 +5480,10 @@ TimeFXDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor) Drag::start_grab (event, cursor); _editor->get_selection().add (_primary); + timepos_t where (_primary->region()->nt_position()); + setup_snap_delta (_primary->region()->nt_position()); - MusicSample where (_primary->region()->position(), 0); - setup_snap_delta (where); - - show_verbose_cursor_duration (where.sample, adjusted_current_sample (event), 0); + show_verbose_cursor_duration (where, adjusted_current_time (event), 0); } void @@ -5148,16 +5494,17 @@ TimeFXDrag::motion (GdkEvent* event, bool) pair const tv = _editor->trackview_by_y_position (grab_y()); int layer = tv.first->layer_display() == Overlaid ? 0 : tv.second; int layers = tv.first->layer_display() == Overlaid ? 1 : cv->layers(); - MusicSample pf (_editor->canvas_event_sample (event) + snap_delta (event->button.state), 0); +#warning NUTEMPO should this really be in samples always + timepos_t pf (timepos_t (_editor->canvas_event_sample (event)) + snap_delta (event->button.state)); _editor->snap_to_with_modifier (pf, event); - pf.sample -= snap_delta (event->button.state); + pf.shift_earlier (snap_delta (event->button.state)); - if (pf.sample > rv->region()->position()) { - rv->get_time_axis_view().show_timestretch (rv->region()->position(), pf.sample, layers, layer); + if (pf > rv->region()->nt_position()) { + rv->get_time_axis_view().show_timestretch (rv->region()->nt_position(), pf, layers, layer); } - show_verbose_cursor_duration (_primary->region()->position(), pf.sample, 0); + show_verbose_cursor_duration (_primary->region()->nt_position(), pf); } void @@ -5168,7 +5515,8 @@ TimeFXDrag::finished (GdkEvent* event, bool movement_occurred) parameters for the timestretch. */ - float fraction = 1.0; + ratio_t fraction (1, 1); + float ffraction; if (movement_occurred) { @@ -5176,21 +5524,21 @@ TimeFXDrag::finished (GdkEvent* event, bool movement_occurred) _primary->get_time_axis_view().hide_timestretch (); - samplepos_t adjusted_sample_pos = adjusted_current_sample (event); + timepos_t adjusted_pos = adjusted_current_time (event); - if (adjusted_sample_pos < _primary->region()->position()) { + if (adjusted_pos < _primary->region()->nt_position()) { /* backwards drag of the left edge - not usable */ return; } - samplecnt_t newlen = adjusted_sample_pos - _primary->region()->position(); + timecnt_t newlen = _primary->region()->nt_position().distance (adjusted_pos); - fraction = (double) newlen / (double) _primary->region()->length(); + fraction = newlen / _primary->region()->nt_length(); #ifndef USE_RUBBERBAND // Soundtouch uses fraction / 100 instead of normal (/ 1) if (_primary->region()->data_type() == DataType::AUDIO) { - fraction = (float) ((double) newlen - (double) _primary->region()->length()) / ((double) newlen) * 100.0f; + fraction = ((newlen - _primary->region()->nt_length()) / newlen) * 100; } #endif } @@ -5229,7 +5577,7 @@ ScrubDrag::start_grab (GdkEvent* event, Gdk::Cursor *) void ScrubDrag::motion (GdkEvent* /*event*/, bool) { - _editor->scrub (adjusted_current_sample (0, false), _drags->current_pointer_x ()); + _editor->scrub (adjusted_current_time (0, false).samples(), _drags->current_pointer_x ()); } void @@ -5256,8 +5604,8 @@ SelectionDrag::SelectionDrag (Editor* e, ArdourCanvas::Item* i, Operation o) DEBUG_TRACE (DEBUG::Drags, "New SelectionDrag\n"); if (_time_selection_at_start) { - start_at_start = _editor->get_selection().time.start(); - end_at_start = _editor->get_selection().time.end_sample(); + start_at_start = _editor->get_selection().time.start_time(); + end_at_start = _editor->get_selection().time.end_time(); } } @@ -5305,27 +5653,27 @@ SelectionDrag::start_grab (GdkEvent* event, Gdk::Cursor*) } if (_operation == SelectionMove) { - show_verbose_cursor_time (_editor->selection->time[_editor->clicked_selection].start); + show_verbose_cursor_time (_editor->selection->time[_editor->clicked_selection].start()); } else { - show_verbose_cursor_time (adjusted_current_sample (event)); + show_verbose_cursor_time (adjusted_current_time (event)); } } void -SelectionDrag::setup_pointer_sample_offset () +SelectionDrag::setup_pointer_offset () { switch (_operation) { case CreateSelection: - _pointer_sample_offset = 0; + _pointer_offset = 0; break; case SelectionStartTrim: case SelectionMove: - _pointer_sample_offset = raw_grab_sample() - _editor->selection->time[_editor->clicked_selection].start; + _pointer_offset = _editor->selection->time[_editor->clicked_selection].start().distance (raw_grab_time()); break; case SelectionEndTrim: - _pointer_sample_offset = raw_grab_sample() - _editor->selection->time[_editor->clicked_selection].end; + _pointer_offset = _editor->selection->time[_editor->clicked_selection].end().distance (raw_grab_time()); break; case SelectionExtend: @@ -5336,14 +5684,14 @@ SelectionDrag::setup_pointer_sample_offset () void SelectionDrag::motion (GdkEvent* event, bool first_move) { - samplepos_t start = 0; - samplepos_t end = 0; - samplecnt_t length = 0; - samplecnt_t distance = 0; - MusicSample start_mf (0, 0); - samplepos_t const pending_position = adjusted_current_sample (event); + timepos_t start; + timepos_t end; + timecnt_t length; + timecnt_t distance; + timepos_t start_mf; + timepos_t const pending_position = adjusted_current_time (event); - if (_operation != CreateSelection && pending_position == last_pointer_sample()) { + if (_operation != CreateSelection && pending_position == last_pointer_time()) { return; } @@ -5357,22 +5705,22 @@ SelectionDrag::motion (GdkEvent* event, bool first_move) switch (_operation) { case CreateSelection: { - MusicSample grab (grab_sample (), 0); + timepos_t grab (grab_time()); if (first_move) { - grab.sample = adjusted_current_sample (event, false); - if (grab.sample < pending_position) { + grab = adjusted_current_time (event, false); + if (grab < pending_position) { _editor->snap_to (grab, RoundDownMaybe); } else { _editor->snap_to (grab, RoundUpMaybe); } } - if (pending_position < grab.sample) { + if (pending_position < grab) { start = pending_position; - end = grab.sample; + end = grab; } else { end = pending_position; - start = grab.sample; + start = grab; } /* first drag: Either add to the selection @@ -5483,7 +5831,7 @@ SelectionDrag::motion (GdkEvent* event, bool first_move) case SelectionStartTrim: - end = _editor->selection->time[_editor->clicked_selection].end; + end = _editor->selection->time[_editor->clicked_selection].end(); if (pending_position > end) { start = end; @@ -5494,7 +5842,7 @@ SelectionDrag::motion (GdkEvent* event, bool first_move) case SelectionEndTrim: - start = _editor->selection->time[_editor->clicked_selection].start; + start = _editor->selection->time[_editor->clicked_selection].start(); if (pending_position < start) { end = start; @@ -5506,17 +5854,17 @@ SelectionDrag::motion (GdkEvent* event, bool first_move) case SelectionMove: - start = _editor->selection->time[_editor->clicked_selection].start; - end = _editor->selection->time[_editor->clicked_selection].end; + start = _editor->selection->time[_editor->clicked_selection].start(); + end = _editor->selection->time[_editor->clicked_selection].end(); - length = end - start; - distance = pending_position - start; + length = start.distance (end);; + distance = start.distance (pending_position); start = pending_position; - start_mf.sample = start; + start_mf = start; _editor->snap_to (start_mf); - end = start_mf.sample + length; + end = start_mf + length; break; @@ -5567,11 +5915,11 @@ SelectionDrag::finished (GdkEvent* event, bool movement_occurred) s->request_play_range (&_editor->selection->time, true); //play the newly selected range } } else if ( !s->transport_rolling() && UIConfiguration::instance().get_follow_edits() ) { - s->request_locate (_editor->get_selection().time.start()); + s->request_locate (_editor->get_selection().time.start_sample()); } if (_editor->get_selection().time.length() != 0) { - s->set_range_selection (_editor->get_selection().time.start(), _editor->get_selection().time.end_sample()); + s->set_range_selection (_editor->get_selection().time.start_time(), _editor->get_selection().time.end_time ()); } else { s->clear_range_selection (); } @@ -5590,9 +5938,9 @@ SelectionDrag::finished (GdkEvent* event, bool movement_occurred) if (_operation == SelectionExtend) { if (_time_selection_at_start) { - samplepos_t pos = adjusted_current_sample (event, false); - samplepos_t start = min (pos, start_at_start); - samplepos_t end = max (pos, end_at_start); + timepos_t pos = adjusted_current_time (event, false); + timepos_t start = min (pos, start_at_start); + timepos_t end = max (pos, end_at_start); _editor->selection->set (start, end); } } else { @@ -5683,14 +6031,14 @@ RangeMarkerBarDrag::start_grab (GdkEvent* event, Gdk::Cursor *) Drag::start_grab (event, cursor); - show_verbose_cursor_time (adjusted_current_sample (event)); + show_verbose_cursor_time (adjusted_current_time (event)); } void RangeMarkerBarDrag::motion (GdkEvent* event, bool first_move) { - samplepos_t start = 0; - samplepos_t end = 0; + timepos_t start; + timepos_t end; ArdourCanvas::Rectangle *crect; switch (_operation) { @@ -5712,18 +6060,18 @@ RangeMarkerBarDrag::motion (GdkEvent* event, bool first_move) break; } - samplepos_t const pf = adjusted_current_sample (event); + timepos_t const pf = adjusted_current_time (event); if (_operation == CreateSkipMarker || _operation == CreateRangeMarker || _operation == CreateTransportMarker || _operation == CreateCDMarker) { - MusicSample grab (grab_sample (), 0); + timepos_t grab (grab_time()); _editor->snap_to (grab); - if (pf < grab_sample()) { + if (pf < grab_time()) { start = pf; - end = grab.sample; + end = grab; } else { end = pf; - start = grab.sample; + start = grab; } /* first drag: Either add to the selection @@ -5746,8 +6094,8 @@ RangeMarkerBarDrag::motion (GdkEvent* event, bool first_move) if (start != end) { _editor->temp_location->set (start, end); - double x1 = _editor->sample_to_pixel (start); - double x2 = _editor->sample_to_pixel (end); + double x1 = _editor->time_to_pixel (start); + double x2 = _editor->time_to_pixel (end); crect->set_x0 (x1); crect->set_x1 (x2); @@ -5791,9 +6139,8 @@ RangeMarkerBarDrag::finished (GdkEvent* event, bool movement_occurred) flags = Location::IsRangeMarker; _editor->range_bar_drag_rect->hide(); } - 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)); + + newloc = new Location (*_editor->session(), _editor->temp_location->start(), _editor->temp_location->end(), rangename, (Location::Flags) flags); _editor->session()->locations()->add (newloc, true); XMLNode &after = _editor->session()->locations()->get_state(); @@ -5825,17 +6172,17 @@ RangeMarkerBarDrag::finished (GdkEvent* event, bool movement_occurred) } else { /* operation == CreateRangeMarker || CreateSkipMarker */ - samplepos_t start; - samplepos_t end; + timepos_t start; + timepos_t end; - _editor->session()->locations()->marks_either_side (grab_sample(), start, end); + _editor->session()->locations()->marks_either_side (grab_time(), start, end); - if (end == max_samplepos) { - end = _editor->session()->current_end_sample (); + if (end == timepos_t::max (end.time_domain())) { + end = _editor->session()->current_end (); } - if (start == max_samplepos) { - start = _editor->session()->current_start_sample (); + if (start == timepos_t::max (start.time_domain())) { + start = _editor->session()->current_start (); } switch (_editor->mouse_mode) { @@ -5869,8 +6216,8 @@ RangeMarkerBarDrag::aborted (bool movement_occurred) void RangeMarkerBarDrag::update_item (Location* location) { - double const x1 = _editor->sample_to_pixel (location->start()); - double const x2 = _editor->sample_to_pixel (location->end()); + double const x1 = _editor->time_to_pixel (location->start()); + double const x2 = _editor->time_to_pixel (location->end()); _drag_rect->set_x0 (x1); _drag_rect->set_x1 (x2); @@ -5878,9 +6225,7 @@ RangeMarkerBarDrag::update_item (Location* location) NoteDrag::NoteDrag (Editor* e, ArdourCanvas::Item* i) : Drag (e, i) - , _cumulative_dx (0) , _cumulative_dy (0) - , _earliest (0.0) , _was_selected (false) , _copy (false) { @@ -5893,10 +6238,9 @@ NoteDrag::NoteDrag (Editor* e, ArdourCanvas::Item* i) } void -NoteDrag::setup_pointer_sample_offset () +NoteDrag::setup_pointer_offset () { - _pointer_sample_offset = raw_grab_sample() - - _editor->session()->tempo_map().sample_at_quarter_note (_region->session_relative_qn (_primary->note()->time().to_double())); + _pointer_offset = _region->region()->source_beats_to_absolute_time (_primary->note()->time()).distance (raw_grab_time()); } void @@ -5910,7 +6254,7 @@ NoteDrag::start_grab (GdkEvent* event, Gdk::Cursor *) _copy = false; } - setup_snap_delta (MusicSample (_region->source_beats_to_absolute_samples (_primary->note()->time ()), 0)); + setup_snap_delta (_region->region()->source_beats_to_absolute_time (_primary->note()->time ())); if (!(_was_selected = _primary->selected())) { @@ -5935,35 +6279,30 @@ NoteDrag::start_grab (GdkEvent* event, Gdk::Cursor *) } /** @return Current total drag x change in quarter notes */ -Temporal::Beats +Temporal::timecnt_t NoteDrag::total_dx (GdkEvent * event) const { if (_x_constrained) { - return Temporal::Beats(); + return timecnt_t::zero (Temporal::BeatTime); } - TempoMap& map (_editor->session()->tempo_map()); - - /* dx in samples */ - sampleoffset_t const dx = _editor->pixel_to_sample (_drags->current_pointer_x() - grab_x()); - - /* primary note time */ - sampleoffset_t const n = map.sample_at_quarter_note (_region->session_relative_qn (_primary->note()->time())); + /* dx in as samples, because we can't do any better */ + timecnt_t const dx = timecnt_t (_editor->pixel_to_sample (_drags->current_pointer_x() - grab_x()), timepos_t()); /* primary note time in quarter notes */ - double const n_qn = _region->session_relative_qn (_primary->note()->time()); + timepos_t const n_qn = _region->region()->source_beats_to_absolute_time (_primary->note()->time()); - /* new time of the primary note in session samples */ - sampleoffset_t st = n + dx + snap_delta (event->button.state); + /* new session relative time of the primary note (will be in beats) */ + timepos_t snap = n_qn + dx + snap_delta (event->button.state); - /* possibly snap and return corresponding delta in quarter notes */ - MusicSample snap (st, 0); - _editor->snap_to_with_modifier (snap, event, RoundNearest, SnapToGrid_Unscaled); - Temporal::Beats ret = Temporal::Beats::from_double (map.exact_qn_at_sample (snap.sample, snap.division) - n_qn - snap_delta_music (event->button.state)); + /* possibly snap and return corresponding delta (will be in beats) */ + _editor->snap_to_with_modifier (snap, event); + + timecnt_t ret = timecnt_t (snap.earlier (n_qn).earlier (snap_delta (event->button.state))); /* prevent the earliest note being dragged earlier than the region's start position */ - if (_earliest + ret < _region->midi_region()->start_beats()) { - ret -= (_earliest + ret) - _region->midi_region()->start_beats(); + if (ret + _earliest < _region->region()->nt_start()) { + ret -= (ret + _earliest) - _region->region()->nt_start(); } return ret; @@ -5992,7 +6331,7 @@ void NoteDrag::motion (GdkEvent * event, bool first_move) { if (first_move) { - _earliest = _region->earliest_in_selection().to_double(); + _earliest = timepos_t (_region->earliest_in_selection()); if (_copy) { /* make copies of all the selected notes */ _primary = _region->copy_selection (_primary); @@ -6000,20 +6339,20 @@ NoteDrag::motion (GdkEvent * event, bool first_move) } /* Total change in x and y since the start of the drag */ - Temporal::Beats const dx_qn = total_dx (event); + timecnt_t const dx_qn = total_dx (event); int8_t const dy = total_dy (); /* Now work out what we have to do to the note canvas items to set this new drag delta */ - double const tdx = _x_constrained ? 0 : dx_qn - _cumulative_dx; + timecnt_t const tdx = _x_constrained ? timecnt_t::zero (_cumulative_dx.time_domain()) : dx_qn - _cumulative_dx; double const tdy = _y_constrained ? 0 : -dy * _note_height - _cumulative_dy; - if (tdx || tdy) { + if (!tdx.zero() || tdy) { _cumulative_dx = dx_qn; _cumulative_dy += tdy; int8_t note_delta = total_dy(); - if (tdx || tdy) { + if (!tdx.zero() || tdy) { if (_copy) { _region->move_copies (dx_qn, tdy, note_delta); } else { @@ -6030,7 +6369,7 @@ NoteDrag::motion (GdkEvent * event, bool first_move) _region->show_verbose_cursor_for_new_note_value (_primary->note(), new_note); - _editor->set_snapped_cursor_position( _region->source_beats_to_absolute_samples(_primary->note()->time()) ); + _editor->set_snapped_cursor_position( _region->region()->source_beats_to_absolute_time (_primary->note()->time()) ); } } } @@ -6140,7 +6479,7 @@ AutomationRangeDrag::setup (list > const & lin list >::const_iterator j = i; ++j; - pair r = (*i)->get_point_x_range (); + pair r = (*i)->get_point_x_range (); //need a special detection for automation lanes (not region gain line) //TODO: if we implement automation regions, this check can probably be removed @@ -6154,7 +6493,7 @@ AutomationRangeDrag::setup (list > const & lin /* check this range against all the TimelineRanges that we are using */ list::const_iterator k = _ranges.begin (); while (k != _ranges.end()) { - if (k->coverage (r.first, r.second) != Evoral::OverlapNone) { + if (k->coverage (r.first, r.second) != Temporal::OverlapNone) { break; } ++k; @@ -6182,7 +6521,7 @@ AutomationRangeDrag::y_fraction (double global_y) const } double -AutomationRangeDrag::value (boost::shared_ptr list, double x) const +AutomationRangeDrag::value (boost::shared_ptr list, timepos_t const & x) const { const double v = list->eval(x); return _integral ? rint(v) : v; @@ -6230,10 +6569,10 @@ AutomationRangeDrag::motion (GdkEvent*, bool first_move) /* add guard points */ for (list::const_iterator i = _ranges.begin(); i != _ranges.end(); ++i) { - samplecnt_t const half = (i->start + i->end) / 2; + timepos_t const half = (i->start() + i->end()) / 2; for (list::iterator j = _lines.begin(); j != _lines.end(); ++j) { - if (j->range.first > i->start || j->range.second < i->start) { + if (j->range.first > i->start() || j->range.second < i->start()) { continue; } @@ -6243,11 +6582,12 @@ AutomationRangeDrag::motion (GdkEvent*, bool first_move) * 64 samples length plucked out of thin air. */ - samplepos_t a = i->start + 64; + timepos_t a = i->start() + timepos_t (64); if (a > half) { a = half; } - +#warning NUTEMPO figure out what this code is/was doing and replace it +#if 0 double const p = j->line->time_converter().from (i->start - j->line->time_converter().origin_b ()); double const q = j->line->time_converter().from (a - j->line->time_converter().origin_b ()); @@ -6259,12 +6599,13 @@ AutomationRangeDrag::motion (GdkEvent*, bool first_move) _editor->session()->add_command ( new MementoCommand(*the_list.get (), &before, &the_list->get_state())); } +#endif } /* same thing for the end */ for (list::iterator j = _lines.begin(); j != _lines.end(); ++j) { - if (j->range.first > i->end || j->range.second < i->end) { + if (j->range.first > i->end() || j->range.second < i->end()) { continue; } @@ -6274,11 +6615,13 @@ AutomationRangeDrag::motion (GdkEvent*, bool first_move) * 64 samples length plucked out of thin air. */ - samplepos_t b = i->end - 64; + timepos_t b = i->end().earlier (timepos_t (64)); if (b < half) { b = half; } +#warning NUTEMPO figure out what this code is/was doing and replace it +#if 0 double const p = j->line->time_converter().from (b - j->line->time_converter().origin_b ()); double const q = j->line->time_converter().from (i->end - j->line->time_converter().origin_b ()); @@ -6290,6 +6633,7 @@ AutomationRangeDrag::motion (GdkEvent*, bool first_move) _editor->session()->add_command ( new MementoCommand(*the_list.get (), &before, &the_list->get_state())); } +#endif } } @@ -6305,11 +6649,13 @@ AutomationRangeDrag::motion (GdkEvent*, bool first_move) /* here's a control point on this line */ ControlPoint* p = i->line->nth (j); - double const w = i->line->time_converter().to ((*p->model())->when) + i->line->time_converter().origin_b (); +#warning NUTEMPO figure out what this code is/was doing and replace it + //double const w = i->line->time_converter().to ((*p->model())->when) + i->line->time_converter().origin_b (); + double const w = 0;; /* see if it's inside a range */ list::const_iterator k = _ranges.begin (); - while (k != _ranges.end() && (k->start >= w || k->end <= w)) { + while (k != _ranges.end() && (k->start() >= w || k->end() <= w)) { ++k; } @@ -6373,8 +6719,8 @@ DraggingView::DraggingView (RegionView* v, RegionDrag* parent, TimeAxisView* ita layer = v->region()->layer (); initial_y = v->get_canvas_group()->position().y; initial_playlist = v->region()->playlist (); - initial_position = v->region()->position (); - initial_end = v->region()->position () + v->region()->length (); + initial_position = v->region()->nt_position (); + initial_end = v->region()->nt_position () + v->region()->nt_length (); } PatchChangeDrag::PatchChangeDrag (Editor* e, PatchChange* i, MidiRegionView* r) @@ -6384,20 +6730,20 @@ PatchChangeDrag::PatchChangeDrag (Editor* e, PatchChange* i, MidiRegionView* r) , _cumulative_dx (0) { DEBUG_TRACE (DEBUG::Drags, string_compose ("New PatchChangeDrag, patch @ %1, grab @ %2\n", - _region_view->source_beats_to_absolute_samples (_patch_change->patch()->time()), - grab_sample())); + _region_view->region()->source_beats_to_absolute_time (_patch_change->patch()->time()), + grab_time())); } void PatchChangeDrag::motion (GdkEvent* ev, bool) { - samplepos_t f = adjusted_current_sample (ev); + timepos_t f = adjusted_current_time (ev); boost::shared_ptr r = _region_view->region (); - f = max (f, r->position ()); - f = min (f, r->last_sample ()); + f = max (f, r->nt_position ()); + f = min (f, r->nt_last ()); - samplecnt_t const dxf = f - grab_sample(); // permitted dx in samples - double const dxu = _editor->sample_to_pixel (dxf); // permitted fx in units + timecnt_t const dxf = grab_time().distance (f); // permitted dx + double const dxu = _editor->duration_to_pixels (dxf); // permitted fx in units _patch_change->move (ArdourCanvas::Duple (dxu - _cumulative_dx, 0)); _cumulative_dx = dxu; } @@ -6413,14 +6759,11 @@ PatchChangeDrag::finished (GdkEvent* ev, bool movement_occurred) } boost::shared_ptr r (_region_view->region ()); - samplepos_t f = adjusted_current_sample (ev); - f = max (f, r->position ()); - f = min (f, r->last_sample ()); + timepos_t f = adjusted_current_time (ev); + f = max (f, r->nt_position ()); + f = min (f, r->nt_last ()); - _region_view->move_patch_change ( - *_patch_change, - _region_view->region_samples_to_region_beats (f - (r->position() - r->start())) - ); + _region_view->move_patch_change (*_patch_change, _region_view->region()->absolute_time_to_region_beats (f)); } void @@ -6430,10 +6773,10 @@ PatchChangeDrag::aborted (bool) } void -PatchChangeDrag::setup_pointer_sample_offset () +PatchChangeDrag::setup_pointer_offset () { boost::shared_ptr region = _region_view->region (); - _pointer_sample_offset = raw_grab_sample() - _region_view->source_beats_to_absolute_samples (_patch_change->patch()->time()); + _pointer_offset = region->source_beats_to_absolute_time (_patch_change->patch()->time()).distance (raw_grab_time()); } MidiRubberbandSelectDrag::MidiRubberbandSelectDrag (Editor* e, MidiRegionView* rv) @@ -6444,7 +6787,7 @@ MidiRubberbandSelectDrag::MidiRubberbandSelectDrag (Editor* e, MidiRegionView* r } void -MidiRubberbandSelectDrag::select_things (int button_state, samplepos_t x1, samplepos_t x2, double y1, double y2, bool /*drag_in_progress*/) +MidiRubberbandSelectDrag::select_things (int button_state, timepos_t const & x1, timepos_t const & x2, double y1, double y2, bool /*drag_in_progress*/) { _region_view->update_drag_selection ( x1, x2, y1, y2, @@ -6465,7 +6808,7 @@ MidiVerticalSelectDrag::MidiVerticalSelectDrag (Editor* e, MidiRegionView* rv) } void -MidiVerticalSelectDrag::select_things (int button_state, samplepos_t /*x1*/, samplepos_t /*x2*/, double y1, double y2, bool /*drag_in_progress*/) +MidiVerticalSelectDrag::select_things (int button_state, timepos_t const & /*x1*/, timepos_t const & /*x2*/, double y1, double y2, bool /*drag_in_progress*/) { double const y = _region_view->midi_view()->y_position (); @@ -6492,7 +6835,7 @@ EditorRubberbandSelectDrag::EditorRubberbandSelectDrag (Editor* e, ArdourCanvas: } void -EditorRubberbandSelectDrag::select_things (int button_state, samplepos_t x1, samplepos_t x2, double y1, double y2, bool drag_in_progress) +EditorRubberbandSelectDrag::select_things (int button_state, timepos_t const & x1, timepos_t const & x2, double y1, double y2, bool drag_in_progress) { if (drag_in_progress) { /* We just want to select things at the end of the drag, not during it */ @@ -6503,7 +6846,7 @@ EditorRubberbandSelectDrag::select_things (int button_state, samplepos_t x1, sam _editor->begin_reversible_selection_op (X_("rubberband selection")); - _editor->select_all_within (x1, x2 - 1, y1, y2, _editor->track_views, op, false); + _editor->select_all_within (x1, x2.decrement(), y1, y2, _editor->track_views, op, false); _editor->commit_reversible_selection_op (); } @@ -6535,15 +6878,32 @@ NoteCreateDrag::~NoteCreateDrag () delete _drag_rect; } -samplecnt_t -NoteCreateDrag::grid_samples (samplepos_t t) const +Temporal::Beats +NoteCreateDrag::grid_aligned_beats (timepos_t const & pos, GdkEvent const * event) const { + Temporal::Beats beats; - const Temporal::Beats grid_beats = _region_view->get_grid_beats (t); - const Temporal::Beats t_beats = _region_view->region_samples_to_region_beats (t); +#warning NUTEMPO needs new tempo map API +#if 0 + TempoMap& map (_editor->session()->tempo_map()); + const int32_t divisions = _editor->get_grid_music_divisions (event->button.state); - return _region_view->region_beats_to_region_samples (t_beats + grid_beats) - - _region_view->region_beats_to_region_samples (t_beats); + switch (divisions) { + case 0: /* no rounding */ + case 1: /* round to beat */ + beats = pos.beats (); + break; + case -1: /* round to bar */ +#warning NUTEMPO need map/BBT API + //map.quarter_note_at (map.metric_at (pos).meter().round_to_bar (map.bbt_at (pos))); + break; + default: /* round to some beat subdivision */ + beats = (pos).beats().round_to_subdivision (divisions, Temporal::RoundNearest); + break; + } +#endif + + return beats; } void @@ -6552,35 +6912,32 @@ NoteCreateDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor) Drag::start_grab (event, cursor); _drag_rect = new ArdourCanvas::Rectangle (_region_view->get_canvas_group ()); - TempoMap& map (_editor->session()->tempo_map()); - const samplepos_t pf = _drags->current_pointer_sample (); + const timepos_t pos = _drags->current_pointer_time (); + Temporal::Beats grid_beats = grid_aligned_beats (pos, event); const int32_t divisions = _editor->get_grid_music_divisions (event->button.state); - const Temporal::Beats grid_beats = _region_view->get_grid_beats (pf); - - double eqaf = map.exact_qn_at_sample (pf, divisions); - if (divisions != 0) { - const double qaf = map.quarter_note_at_sample (pf); + const Temporal::Beats unaligned_beats = pos.beats (); /* Hack so that we always snap to the note that we are over, instead of snapping to the next one if we're more than halfway through the one we're over. */ - const double rem = eqaf - qaf; - if (rem >= 0.0) { - eqaf -= grid_beats.to_double(); + const Temporal::Beats rem = grid_beats - unaligned_beats; + + if (rem >= std::numeric_limits::lowest ()) { + grid_beats = rem; } } - _note[0] = map.sample_at_quarter_note (eqaf) - _region_view->region()->position(); + _note[0] = grid_beats; /* minimum initial length is grid beats */ - _note[1] = map.sample_at_quarter_note (eqaf + grid_beats.to_double()) - _region_view->region()->position(); + _note[1] = grid_beats + grid_beats; - double const x0 = _editor->sample_to_pixel (_note[0]); - double const x1 = _editor->sample_to_pixel (_note[1]); + double const x0 = _editor->time_to_pixel (_note[0]); + double const x1 = _editor->time_to_pixel (_note[1]); double const y = _region_view->note_to_y (_region_view->y_to_note (y_to_region (event->button.y))); _drag_rect->set (ArdourCanvas::Rect (x0, y, x1, y + floor (_region_view->midi_stream_view()->note_height ()))); @@ -6592,31 +6949,32 @@ NoteCreateDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor) void NoteCreateDrag::motion (GdkEvent* event, bool) { - TempoMap& map (_editor->session()->tempo_map()); - const samplepos_t pf = _drags->current_pointer_sample (); + const timepos_t pos = _drags->current_pointer_time (); const int32_t divisions = _editor->get_grid_music_divisions (event->button.state); - double eqaf = map.exact_qn_at_sample (pf, divisions); + Temporal::Beats aligned_beats = grid_aligned_beats (pos, event); - if (divisions != 0) { + if (_editor->snap_mode() != SnapOff) { - const Temporal::Beats grid_beats = _region_view->get_grid_beats (pf); + const Temporal::Beats grid_beats = _region_view->get_grid_beats (pos); + const Temporal::Beats unaligned_beats = pos.beats (); - const double qaf = map.quarter_note_at_sample (pf); /* Hack so that we always snap to the note that we are over, instead of snapping to the next one if we're more than halfway through the one we're over. */ - const double rem = eqaf - qaf; - if (rem >= 0.0) { - eqaf -= grid_beats.to_double(); + const Temporal::Beats rem = aligned_beats - unaligned_beats; + + if (rem >= std::numeric_limits::lowest()) { + aligned_beats -= grid_beats; } - eqaf += grid_beats.to_double(); + aligned_beats += grid_beats; } - _note[1] = max ((samplepos_t)0, map.sample_at_quarter_note (eqaf) - _region_view->region()->position ()); - double const x0 = _editor->sample_to_pixel (_note[0]); - double const x1 = _editor->sample_to_pixel (_note[1]); + _note[1] = max (Temporal::Beats(), aligned_beats - _region_view->region()->nt_position ().beats()); + + double const x0 = _editor->time_to_pixel (_note[0]); + double const x1 = _editor->time_to_pixel (_note[1]); _drag_rect->set_x0 (std::min(x0, x1)); _drag_rect->set_x1 (std::max(x0, x1)); } @@ -6625,21 +6983,17 @@ void NoteCreateDrag::finished (GdkEvent* ev, bool had_movement) { /* we create a note even if there was no movement */ - samplepos_t const start = min (_note[0], _note[1]); - samplepos_t const start_sess_rel = start + _region_view->region()->position(); - samplecnt_t length = max (_editor->pixel_to_sample (1.0), (samplecnt_t) fabs ((double)(_note[0] - _note[1]))); - samplecnt_t const g = grid_samples (start_sess_rel); + Beats const start = (min (_note[0], _note[1])).beats (); + Beats length = max (Beats (1, 0), (_note[1].distance (_note[0]).abs().beats())); - if (_editor->get_grid_music_divisions (ev->button.state) != 0 && length < g) { - length = g; + int32_t div = _editor->get_grid_music_divisions (ev->button.state); + + if (div > 0) { + length = length.round_to_subdivision (div, RoundUpMaybe); } - TempoMap& map (_editor->session()->tempo_map()); - const double qn_length = map.quarter_notes_between_samples (start_sess_rel, start_sess_rel + length); - Temporal::Beats qn_length_beats = max (Temporal::Beats::ticks(1), Temporal::Beats (qn_length)); - _editor->begin_reversible_command (_("Create Note")); - _region_view->create_note_at (start, _drag_rect->y0(), qn_length_beats, ev->button.state, false); + _region_view->create_note_at (start, _drag_rect->y0(), length, ev->button.state, false); _editor->commit_reversible_command (); } @@ -6674,23 +7028,21 @@ HitCreateDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor) { Drag::start_grab (event, cursor); - TempoMap& map (_editor->session()->tempo_map()); - _y = _region_view->note_to_y (_region_view->y_to_note (y_to_region (event->button.y))); - const samplepos_t pf = _drags->current_pointer_sample (); + const timepos_t pos = _drags->current_pointer_time (); const int32_t divisions = _editor->get_grid_music_divisions (event->button.state); - const double eqaf = map.exact_qn_at_sample (pf, divisions); + const Beats beats = pos.beats (); boost::shared_ptr mr = _region_view->midi_region(); - if (eqaf >= mr->quarter_note() + mr->length_beats()) { + if (beats >= mr->nt_last().beats()) { return; } - const samplepos_t start = map.sample_at_quarter_note (eqaf) - _region_view->region()->position(); - Temporal::Beats length = Temporal::Beats::from_double (1.0 / 32.0); /* 1/32 beat = 1/128 note */ + const Temporal::Beats start = beats - _region_view->region()->nt_position().beats (); + Temporal::Beats length = _region_view->get_grid_beats (pos); _editor->begin_reversible_command (_("Create Hit")); _region_view->clear_note_selection(); @@ -6702,27 +7054,25 @@ HitCreateDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor) void HitCreateDrag::motion (GdkEvent* event, bool) { - TempoMap& map (_editor->session()->tempo_map()); - - const samplepos_t pf = _drags->current_pointer_sample (); + const timepos_t pos = _drags->current_pointer_time (); const int32_t divisions = _editor->get_grid_music_divisions (event->button.state); if (divisions == 0) { return; } - const double eqaf = map.exact_qn_at_sample (pf, divisions); - const samplepos_t start = map.sample_at_quarter_note (eqaf) - _region_view->region()->position (); + const Beats beats = pos.beats (); + const Temporal::Beats start = beats - _region_view->region()->nt_position ().beats(); if (_last_pos == start) { return; } - Temporal::Beats length = _region_view->get_grid_beats (pf); + Temporal::Beats length = _region_view->get_grid_beats (pos); boost::shared_ptr mr = _region_view->midi_region(); - if (eqaf >= mr->quarter_note() + mr->length_beats()) { + if (beats > mr->nt_last().beats()) { return; } @@ -6770,31 +7120,31 @@ void CrossfadeEdgeDrag::motion (GdkEvent*, bool) { double distance; - double new_length; - samplecnt_t len; + timecnt_t new_length; + timecnt_t len; boost::shared_ptr ar (arv->audio_region()); if (start) { distance = _drags->current_pointer_x() - grab_x(); - len = ar->fade_in()->back()->when; + len = timecnt_t (ar->fade_in()->back()->when); } else { distance = grab_x() - _drags->current_pointer_x(); - len = ar->fade_out()->back()->when; + len = timecnt_t (ar->fade_out()->back()->when); } /* how long should it be ? */ - new_length = len + _editor->pixel_to_sample (distance); + new_length = len + timecnt_t (_editor->pixel_to_sample (distance)); /* now check with the region that this is legal */ - new_length = ar->verify_xfade_bounds (new_length, start); + new_length = ar->verify_xfade_bounds (new_length.samples(), start); if (start) { - arv->reset_fade_in_shape_width (ar, new_length); + arv->reset_fade_in_shape_width (ar, new_length.samples()); } else { - arv->reset_fade_out_shape_width (ar, new_length); + arv->reset_fade_out_shape_width (ar, new_length.samples()); } } @@ -6802,28 +7152,28 @@ void CrossfadeEdgeDrag::finished (GdkEvent*, bool) { double distance; - double new_length; - samplecnt_t len; + timecnt_t new_length; + timecnt_t len; boost::shared_ptr ar (arv->audio_region()); if (start) { distance = _drags->current_pointer_x() - grab_x(); - len = ar->fade_in()->back()->when; + len = timecnt_t (ar->fade_in()->back()->when); } else { distance = grab_x() - _drags->current_pointer_x(); - len = ar->fade_out()->back()->when; + len = timecnt_t (ar->fade_out()->back()->when); } - new_length = ar->verify_xfade_bounds (len + _editor->pixel_to_sample (distance), start); + new_length = ar->verify_xfade_bounds ((len + timecnt_t (_editor->pixel_to_sample (distance))).samples(), start); _editor->begin_reversible_command ("xfade trim"); ar->playlist()->clear_owned_changes (); if (start) { - ar->set_fade_in_length (new_length); + ar->set_fade_in_length (new_length.samples()); } else { - ar->set_fade_out_length (new_length); + ar->set_fade_out_length (new_length.samples()); } /* Adjusting the xfade may affect other regions in the playlist, so we need @@ -6875,10 +7225,10 @@ RegionCutDrag::finished (GdkEvent* event, bool) _editor->get_track_canvas()->canvas()->re_enter(); - MusicSample pos (_drags->current_pointer_sample(), 0); + timepos_t pos (_drags->current_pointer_time()); _editor->snap_to_with_modifier (pos, event); - RegionSelection rs = _editor->get_regions_from_selection_and_mouse (pos.sample); + RegionSelection rs = _editor->get_regions_from_selection_and_mouse (pos); if (rs.empty()) { return; diff --git a/gtk2_ardour/editor_drag.h b/gtk2_ardour/editor_drag.h index 372e8ad198..6c2f687ae9 100644 --- a/gtk2_ardour/editor_drag.h +++ b/gtk2_ardour/editor_drag.h @@ -118,7 +118,12 @@ public: /** @return current pointer sample */ ARDOUR::samplepos_t current_pointer_sample () const { - return _current_pointer_sample; + return _current_pointer_time.samples(); + } + + /** @return current pointer time */ + Temporal::timepos_t current_pointer_time () const { + return _current_pointer_time; } /** return drag-motion displays video-frame of drag-location */ @@ -130,7 +135,7 @@ private: bool _ending; ///< true if end_grab or abort is in progress, otherwise false double _current_pointer_x; ///< canvas-coordinate space x of the current pointer double _current_pointer_y; ///< canvas-coordinate space y of the current pointer - ARDOUR::samplepos_t _current_pointer_sample; ///< sample that the pointer is now at + Temporal::timepos_t _current_pointer_time; ///< time that the pointer is now at bool _old_follow_playhead; ///< state of Editor::follow_playhead() before the drags started }; @@ -154,8 +159,8 @@ public: bool motion_handler (GdkEvent*, bool); void abort (); - ARDOUR::MusicSample adjusted_sample (ARDOUR::samplepos_t, GdkEvent const *, bool snap = true) const; - ARDOUR::samplepos_t adjusted_current_sample (GdkEvent const *, bool snap = true) const; + Temporal::timepos_t adjusted_time (Temporal::timepos_t const &, GdkEvent const *, bool snap = true) const; + Temporal::timepos_t adjusted_current_time (GdkEvent const *, bool snap = true) const; bool was_double_click() const { return _was_double_click; } void set_double_click (bool yn) { _was_double_click = yn; } @@ -197,9 +202,9 @@ public: return _preview_video; } - /** @return minimum number of pixels (x, y) that should be considered a movement */ - virtual std::pair move_threshold () const { - return std::make_pair (1, 1); + /** @return minimum number of samples (in x) and pixels (in y) that should be considered a movement */ + std::pair move_threshold () const { + return std::make_pair (Temporal::timecnt_t (1, Temporal::AudioTime), 1); } virtual bool allow_vertical_autoscroll () const { @@ -220,14 +225,15 @@ public: return _initially_vertical; } - /** Set up the _pointer_sample_offset */ - virtual void setup_pointer_sample_offset () { - _pointer_sample_offset = 0; + /** Set up the _pointer_offset */ + virtual void setup_pointer_offset () { + _pointer_offset = Temporal::timecnt_t(); } - /** Set up the _video_sample_offset - relative to _current_pointer_sample */ - virtual void setup_video_sample_offset () { - _video_sample_offset = 0; + /** Set up the _video_offset - relative to _current_pointer_time */ + virtual void setup_video_offset () { + /* video offset is always in audio time */ + _video_offset = Temporal::timecnt_t (Temporal::AudioTime); _preview_video = false; } @@ -243,12 +249,16 @@ protected: return _grab_y; } - ARDOUR::samplepos_t raw_grab_sample () const { - return _raw_grab_sample; + Temporal::timepos_t raw_grab_time () const { + return _raw_grab_time; } ARDOUR::samplepos_t grab_sample () const { - return _grab_sample; + return _grab_time.samples(); + } + + Temporal::timepos_t grab_time () const { + return _grab_time; } double last_pointer_x () const { @@ -260,31 +270,35 @@ protected: } ARDOUR::samplepos_t last_pointer_sample () const { - return _last_pointer_sample; + return _last_pointer_time.samples(); } - ARDOUR::sampleoffset_t snap_delta (guint const) const; - double snap_delta_music (guint const) const; + Temporal::timepos_t last_pointer_time () const { + return _last_pointer_time; + } + + Temporal::timecnt_t snap_delta (guint const) const; + Temporal::Beats snap_delta_music (guint const) const; double current_pointer_x () const; double current_pointer_y () const; /* sets snap delta from unsnapped pos */ - void setup_snap_delta (ARDOUR::MusicSample pos); + void setup_snap_delta (Temporal::timepos_t const & pos); boost::shared_ptr add_midi_region (MidiTimeAxisView*, bool commit); - void show_verbose_cursor_time (samplepos_t); - void show_verbose_cursor_duration (samplepos_t, samplepos_t, double xoffset = 0); + void show_verbose_cursor_time (Temporal::timepos_t const &); + void show_verbose_cursor_duration (Temporal::timepos_t const & , Temporal::timepos_t const & , double xoffset = 0); void show_verbose_cursor_text (std::string const &); - void show_view_preview (samplepos_t); + void show_view_preview (Temporal::timepos_t const &); Editor* _editor; ///< our editor DragManager* _drags; ArdourCanvas::Item* _item; ///< our item /** Offset from the mouse's position for the drag to the start of the thing that is being dragged */ - ARDOUR::samplecnt_t _pointer_sample_offset; - ARDOUR::samplecnt_t _video_sample_offset; + Temporal::timecnt_t _pointer_offset; + Temporal::timecnt_t _video_offset; bool _preview_video; bool _x_constrained; ///< true if x motion is constrained, otherwise false bool _y_constrained; ///< true if y motion is constrained, otherwise false @@ -301,15 +315,15 @@ private: double _grab_y; ///< y of the grab start position, possibly adjusted if _trackview_only is true double _last_pointer_x; ///< trackview x of the pointer last time a motion occurred double _last_pointer_y; ///< trackview y of the pointer last time a motion occurred - ARDOUR::samplepos_t _raw_grab_sample; ///< unsnapped sample that the mouse was at when start_grab was called, or 0 - ARDOUR::samplepos_t _grab_sample; ///< adjusted_sample that the mouse was at when start_grab was called, or 0 - ARDOUR::samplepos_t _last_pointer_sample; ///< adjusted_sample the last time a motion occurred + Temporal::timepos_t _raw_grab_time; ///< unsnapped time that the mouse was at when start_grab was called, or 0 + Temporal::timepos_t _grab_time; ///< adjusted_time that the mouse was at when start_grab was called, or 0 + Temporal::timepos_t _last_pointer_time; ///< adjusted_time the last time a motion occurred /* difference between some key position's snapped and unsnapped * samplepos. used for relative snap. */ - samplepos_t _snap_delta; - double _snap_delta_music; + Temporal::timecnt_t _snap_delta; + Temporal::Beats _snap_delta_music; CursorContext::Handle _cursor_ctx; ///< cursor change context bool _constraint_pressed; ///< if the keyboard indicated constraint modifier was pressed on start_grab() int _grab_button; @@ -334,8 +348,8 @@ public: */ double layer; double initial_y; ///< the initial y position of the view before any reparenting - samplepos_t initial_position; ///< initial position of the region - samplepos_t initial_end; ///< initial end position of the region + Temporal::timepos_t initial_position; ///< initial position of the region + Temporal::timepos_t initial_end; ///< initial end position of the region samplepos_t anchored_fade_length; ///< fade_length when anchored during drag boost::shared_ptr initial_playlist; TimeAxisView* initial_time_axis_view; @@ -362,7 +376,7 @@ protected: int _visible_y_high; uint32_t _ntracks; - void setup_video_sample_offset (); + void setup_video_offset (); friend class DraggingView; @@ -426,12 +440,12 @@ public: protected: - double compute_x_delta (GdkEvent const *, ARDOUR::MusicSample *); + double compute_x_delta (GdkEvent const *, Temporal::timepos_t &); virtual bool y_movement_allowed (int, double, int skip_invisible = 0) const; void collect_ripple_views (); bool _ignore_video_lock; - ARDOUR::MusicSample _last_position; ///< last position of the thing being dragged + Temporal::timepos_t _last_position; ///< last position of the thing being dragged double _total_x_delta; int _last_pointer_time_axis_view; double _last_pointer_layer; @@ -463,28 +477,24 @@ public: return true; } - std::pair move_threshold () const { - if (_copy) { - return std::make_pair (6, 4); - } else { - return std::make_pair (2, 4); - } + std::pair move_threshold () const { + return std::make_pair (Temporal::timecnt_t (4, Temporal::AudioTime), 4); } - void setup_pointer_sample_offset (); + void setup_pointer_offset (); private: void finished_no_copy ( bool const, bool const, - ARDOUR::MusicSample, + Temporal::timepos_t const &, int32_t const ev_state ); void finished_copy ( bool const, bool const, - ARDOUR::MusicSample, + Temporal::timepos_t const &, int32_t const ev_state ); @@ -492,8 +502,7 @@ private: boost::shared_ptr, RouteTimeAxisView*, ARDOUR::layer_t, - ARDOUR::MusicSample, - double quarter_note, + Temporal::timepos_t const &, PlaylistSet&, bool for_music = false ); @@ -516,7 +525,7 @@ private: class RegionInsertDrag : public RegionMotionDrag { public: - RegionInsertDrag (Editor *, boost::shared_ptr, RouteTimeAxisView*, ARDOUR::samplepos_t); + RegionInsertDrag (Editor *, boost::shared_ptr, RouteTimeAxisView*, Temporal::timepos_t const &); void finished (GdkEvent *, bool); void aborted (bool); @@ -526,6 +535,35 @@ public: } }; +/** Region drag in ripple mode */ + +class RegionRippleDrag : public RegionMoveDrag +{ +public: + RegionRippleDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list const &); + ~RegionRippleDrag () { delete exclude; } + + void motion (GdkEvent *, bool); + void finished (GdkEvent *, bool); + void aborted (bool); +protected: + bool y_movement_allowed (int delta_track, double delta_layer, int skip_invisible = 0) const; + +private: + TimeAxisView *prev_tav; // where regions were most recently dragged from + TimeAxisView *orig_tav; // where drag started + Temporal::timecnt_t prev_amount; + Temporal::timepos_t prev_position; + Temporal::timecnt_t selection_length; + bool allow_moves_across_tracks; // only if all selected regions are on one track + ARDOUR::RegionList *exclude; + void add_all_after_to_views (TimeAxisView *tav, Temporal::timepos_t const & where, const RegionSelection &exclude, bool drag_in_progress); + void remove_unselected_from_views (Temporal::timecnt_t const & amount, bool move_regions); + + std::list > _orig_tav_ripples; +}; + +/** "Drag" to cut a region (action only on button release) */ class RegionCutDrag : public Drag { public: @@ -597,14 +635,14 @@ public: private: - Temporal::Beats total_dx (GdkEvent * event) const; // total movement in quarter notes + Temporal::timecnt_t total_dx (GdkEvent * event) const; // total movement in quarter notes int8_t total_dy () const; MidiRegionView* _region; NoteBase* _primary; - double _cumulative_dx; + Temporal::timecnt_t _cumulative_dx; double _cumulative_dy; - double _earliest; // earliest quarter note in note selection + Temporal::timepos_t _earliest; // earliest note in note selection bool _was_selected; double _note_height; bool _copy; @@ -635,16 +673,16 @@ public: private: double y_to_region (double) const; - ARDOUR::samplecnt_t grid_samples (samplepos_t) const; + Temporal::Beats grid_aligned_beats (Temporal::timepos_t const & pos, GdkEvent const * event) const; - /** @return minimum number of pixels (x, y) that should be considered a movement */ - virtual std::pair move_threshold () const { - return std::make_pair (0, 0); + /** @return minimum number of samples (in x) and pixels (in y) that should be considered a movement */ + std::pair move_threshold () const { + return std::make_pair (Temporal::timecnt_t (0, Temporal::AudioTime), 0); } MidiRegionView* _region_view; ArdourCanvas::Rectangle* _drag_rect; - samplepos_t _note[2]; + Temporal::timepos_t _note[2]; }; class HitCreateDrag : public Drag @@ -668,11 +706,10 @@ public: private: double y_to_region (double) const; - ARDOUR::samplecnt_t grid_samples (samplepos_t) const; - /** @return minimum number of pixels (x, y) that should be considered a movement */ - virtual std::pair move_threshold () const { - return std::make_pair (0, 0); + /** @return minimum number of samples (in x) and pixels (in y) that should be considered a movement */ + std::pair move_threshold () const { + return std::make_pair (Temporal::timecnt_t::zero (Temporal::AudioTime), 0); } MidiRegionView* _region_view; @@ -699,7 +736,7 @@ public: return false; } - void setup_pointer_sample_offset (); + void setup_pointer_offset (); private: MidiRegionView* _region_view; @@ -770,7 +807,7 @@ public: return false; } - void setup_pointer_sample_offset (); + void setup_pointer_offset (); private: @@ -799,7 +836,7 @@ public: return false; } - void setup_pointer_sample_offset (); + void setup_pointer_offset (); private: MeterMarker* _marker; @@ -830,7 +867,7 @@ public: return true; } - void setup_pointer_sample_offset (); + void setup_pointer_offset (); private: TempoMarker* _marker; @@ -862,7 +899,7 @@ public: return false; } - void setup_pointer_sample_offset (); + void setup_pointer_offset (); private: double _grab_qn; @@ -890,7 +927,7 @@ public: return true; } - void setup_pointer_sample_offset (); + void setup_pointer_offset (); private: double _grab_qn; @@ -921,7 +958,7 @@ public: return true; } - void setup_pointer_sample_offset (); + void setup_pointer_offset (); private: double _grab_qn; @@ -982,7 +1019,7 @@ public: return false; } - void setup_pointer_sample_offset (); + void setup_pointer_offset (); }; /** Region fade-out drag */ @@ -1004,7 +1041,7 @@ public: return false; } - void setup_pointer_sample_offset (); + void setup_pointer_offset (); }; /** Marker drag */ @@ -1027,8 +1064,8 @@ public: return false; } - void setup_pointer_sample_offset (); - void setup_video_sample_offset (); + void setup_pointer_offset (); + void setup_video_offset (); private: void update_item (ARDOUR::Location *); @@ -1136,22 +1173,21 @@ public: void finished (GdkEvent *, bool); void aborted (bool); - /** @return minimum number of pixels (x, y) that should be considered a movement */ - std::pair move_threshold () const { - return std::make_pair (1, 1); + std::pair move_threshold () const { + return std::make_pair (Temporal::timecnt_t (8, Temporal::AudioTime), 1); } void do_select_things (GdkEvent *, bool); /** Select some things within a rectangle. * @param button_state The button state from the GdkEvent. - * @param x1 The left-hand side of the rectangle in session samples. - * @param x2 The right-hand side of the rectangle in session samples. + * @param x1 The left-hand side of the rectangle as a timepos_t + * @param x2 The right-hand side of the rectangle as a timepos_t. * @param y1 The top of the rectangle in trackview coordinates. * @param y2 The bottom of the rectangle in trackview coordinates. * @param drag_in_progress true if the drag is currently happening. */ - virtual void select_things (int button_state, samplepos_t x1, samplepos_t x2, double y1, double y2, bool drag_in_progress) = 0; + virtual void select_things (int button_state, Temporal::timepos_t const & x1, Temporal::timepos_t const & x2, double y1, double y2, bool drag_in_progress) = 0; virtual void deselect_things () = 0; @@ -1165,7 +1201,7 @@ class EditorRubberbandSelectDrag : public RubberbandSelectDrag public: EditorRubberbandSelectDrag (Editor *, ArdourCanvas::Item *); - void select_things (int, samplepos_t, samplepos_t, double, double, bool); + void select_things (int, Temporal::timepos_t const &, Temporal::timepos_t const &, double, double, bool); void deselect_things (); }; @@ -1175,7 +1211,7 @@ class MidiRubberbandSelectDrag : public RubberbandSelectDrag public: MidiRubberbandSelectDrag (Editor *, MidiRegionView *); - void select_things (int, samplepos_t, samplepos_t, double, double, bool); + void select_things (int, Temporal::timepos_t const &, Temporal::timepos_t const &, double, double, bool); void deselect_things (); private: @@ -1188,7 +1224,7 @@ class MidiVerticalSelectDrag : public RubberbandSelectDrag public: MidiVerticalSelectDrag (Editor *, MidiRegionView *); - void select_things (int, samplepos_t, samplepos_t, double, double, bool); + void select_things (int, Temporal::timepos_t const &, Temporal::timepos_t const &, double, double, bool); void deselect_things (); private: @@ -1238,15 +1274,15 @@ public: void finished (GdkEvent *, bool); void aborted (bool); - void setup_pointer_sample_offset (); + void setup_pointer_offset (); private: Operation _operation; bool _add; TrackSelection _track_selection_at_start; bool _time_selection_at_start; - samplepos_t start_at_start; - samplepos_t end_at_start; + Temporal::timepos_t start_at_start; + Temporal::timepos_t end_at_start; }; /** Range marker drag */ @@ -1295,9 +1331,8 @@ public: void finished (GdkEvent *, bool); void aborted (bool); - /** @return minimum number of pixels (x, y) that should be considered a movement */ - std::pair move_threshold () const { - return std::make_pair (4, 4); + std::pair move_threshold () const { + return std::make_pair (Temporal::timecnt_t (4, Temporal::AudioTime), 4); } private: @@ -1325,7 +1360,7 @@ public: private: void setup (std::list > const &); double y_fraction (double global_y_position) const; - double value (boost::shared_ptr list, double x) const; + double value (boost::shared_ptr list, Temporal::timepos_t const & x) const; std::list _ranges; @@ -1333,7 +1368,7 @@ private: struct Line { boost::shared_ptr line; ///< the line std::list points; ///< points to drag on the line - std::pair range; ///< the range of all points on the line, in session samples + std::pair range; ///< the range of all points on the line, in session time XMLNode* state; ///< the XML state node before the drag }; @@ -1360,8 +1395,8 @@ public: return false; } - virtual std::pair move_threshold () const { - return std::make_pair (1, 4); + std::pair move_threshold () const { + return std::make_pair (Temporal::timecnt_t (4, Temporal::AudioTime), 4); } private: diff --git a/gtk2_ardour/editor_mouse.cc b/gtk2_ardour/editor_mouse.cc index 7828a28d81..7fbd64fe49 100644 --- a/gtk2_ardour/editor_mouse.cc +++ b/gtk2_ardour/editor_mouse.cc @@ -2427,7 +2427,7 @@ Editor::cancel_time_selection () } void -Editor::point_trim (GdkEvent* event, samplepos_t new_bound) +Editor::point_trim (GdkEvent* event, timepos_t const & new_bound) { RegionView* rv = clicked_regionview; @@ -2530,7 +2530,7 @@ Editor::mouse_rename_region (ArdourCanvas::Item* /*item*/, GdkEvent* /*event*/) void -Editor::mouse_brush_insert_region (RegionView* rv, samplepos_t pos) +Editor::mouse_brush_insert_region (RegionView* rv, timepos_t const & pos) { /* no brushing without a useful quantize setting */ if (_grid_type == GridTypeNone) @@ -2538,7 +2538,7 @@ Editor::mouse_brush_insert_region (RegionView* rv, samplepos_t pos) /* don't brush a copy over the original */ - if (pos == rv->region()->position()) { + if (pos == rv->region()->nt_position()) { return; } diff --git a/gtk2_ardour/editor_tempodisplay.cc b/gtk2_ardour/editor_tempodisplay.cc index 85069b971e..7e01dce8c5 100644 --- a/gtk2_ardour/editor_tempodisplay.cc +++ b/gtk2_ardour/editor_tempodisplay.cc @@ -208,6 +208,8 @@ Editor::tempometric_position_changed (const PropertyChange& /*ignored*/) double max_tempo = 0.0; double min_tempo = DBL_MAX; +#warning NUTEMPO needs new tempo map API +#if 0 for (Marks::iterator x = metric_marks.begin(); x != metric_marks.end(); ++x) { TempoMarker* tempo_marker; MeterMarker* meter_marker; @@ -282,6 +284,7 @@ Editor::tempometric_position_changed (const PropertyChange& /*ignored*/) update_tempo_based_rulers (); maybe_draw_grid_lines (); +#endif } void @@ -296,7 +299,7 @@ Editor::redisplay_grid (bool immediate_redraw) update_tempo_based_rulers (); update_grid(); - + } else { Glib::signal_idle().connect (sigc::bind_return (sigc::bind (sigc::mem_fun (*this, &Editor::redisplay_grid), true), false)); } diff --git a/gtk2_ardour/marker_selection.h b/gtk2_ardour/marker_selection.h index be7d1ae9ca..ed65e03095 100644 --- a/gtk2_ardour/marker_selection.h +++ b/gtk2_ardour/marker_selection.h @@ -27,7 +27,7 @@ class MarkerSelection : public std::list { public: - void range (ARDOUR::samplepos_t& start, ARDOUR::samplepos_t& end); + void range (Temporal::timepos_t& start, Temporal::timepos_t& end); }; #endif /* __ardour_gtk_marker_selection_h__ */ diff --git a/gtk2_ardour/midi_list_editor.cc b/gtk2_ardour/midi_list_editor.cc index 0d47a3aa8a..92aa2c0086 100644 --- a/gtk2_ardour/midi_list_editor.cc +++ b/gtk2_ardour/midi_list_editor.cc @@ -761,13 +761,13 @@ MidiListEditor::redisplay_model () if (_session) { - BeatsSamplesConverter conv (_session->tempo_map(), region->position()); boost::shared_ptr m (region->midi_source(0)->model()); TreeModel::Row row; stringstream ss; - MidiModel::Notes::const_iterator i = m->note_lower_bound(conv.from (region->start())); - Temporal::Beats end_time = conv.from (region->start()) + conv.from (region->length()); + MidiModel::Notes::const_iterator i = m->note_lower_bound (region->nt_start().beats()); + Temporal::Beats end_time = (region->nt_start() + region->nt_length()).beats(); + for (; i != m->notes().end() && (*i)->time() < end_time; ++i) { row = *(model->append()); row[columns.channel] = (*i)->channel() + 1; @@ -775,7 +775,9 @@ MidiListEditor::redisplay_model () row[columns.note] = (*i)->note(); row[columns.velocity] = (*i)->velocity(); - Temporal::BBT_Time bbt (_session->tempo_map().bbt_at_sample (region->position() - region->start() + conv.to ((*i)->time()))); +#warning NUTEMPO needs ::bbt() method for timeline types + // Temporal::BBT_Time bbt (((region->position() + (*i)->time()).earlier (start)).bbt()); + Temporal::BBT_Time bbt; ss.str (""); ss << bbt; diff --git a/gtk2_ardour/midi_region_view.cc b/gtk2_ardour/midi_region_view.cc index fca2a3bc61..865e1cfe54 100644 --- a/gtk2_ardour/midi_region_view.cc +++ b/gtk2_ardour/midi_region_view.cc @@ -2368,14 +2368,14 @@ MidiRegionView::note_deselected(NoteBase* ev) } void -MidiRegionView::update_drag_selection(samplepos_t start, samplepos_t end, double gy0, double gy1, bool extend) +MidiRegionView::update_drag_selection(timepos_t const & start, timepos_t const & end, double gy0, double gy1, bool extend) { PublicEditor& editor = trackview.editor(); // Convert to local coordinates const double y = midi_view()->y_position(); - const double x0 = editor.time_to_pixel (max (timepos_t(), _region->region_relative_position (timepos_t (start)))); - const double x1 = editor.time_to_pixel (max (timepos_t(), _region->region_relative_position (timepos_t (end)))); + const double x0 = editor.time_to_pixel (max (timepos_t(), _region->region_relative_position (start))); + const double x1 = editor.time_to_pixel (max (timepos_t(), _region->region_relative_position (end))); const double y0 = max(0.0, gy0 - y); const double y1 = max(0.0, gy1 - y); @@ -2504,11 +2504,10 @@ MidiRegionView::earliest_in_selection () } void -MidiRegionView::move_selection(Temporal::Beats const & dx_qn, double dy, double cumulative_dy) +MidiRegionView::move_selection(timecnt_t const & dx_qn, double dy, double cumulative_dy) { typedef vector > PossibleChord; Editor* editor = dynamic_cast (&trackview.editor()); - TempoMap& tmap (editor->session()->tempo_map()); PossibleChord to_play; Temporal::Beats earliest = earliest_in_selection(); @@ -2521,13 +2520,13 @@ MidiRegionView::move_selection(Temporal::Beats const & dx_qn, double dy, double double dx = 0.0; if (midi_view()->note_mode() == Sustained) { - dx = editor->sample_to_pixel_unrounded (tmap.sample_at_quarter_note (note_time_qn + dx_qn)) + dx = editor->time_to_pixel_unrounded ((note_time_qn + dx_qn)) - n->item()->item_to_canvas (ArdourCanvas::Duple (n->x0(), 0)).x; } else { /* Hit::x0() is offset by _position.x, unlike Note::x0() */ Hit* hit = dynamic_cast(n); if (hit) { - dx = editor->sample_to_pixel_unrounded (tmap.sample_at_quarter_note (note_time_qn + dx_qn)) + dx = editor->time_to_pixel_unrounded ((note_time_qn + dx_qn)) - n->item()->item_to_canvas (ArdourCanvas::Duple (((hit->x0() + hit->x1()) / 2.0) - hit->position().x, 0)).x; } } @@ -2537,7 +2536,7 @@ MidiRegionView::move_selection(Temporal::Beats const & dx_qn, double dy, double /* update length */ if (midi_view()->note_mode() == Sustained) { Note* sus = dynamic_cast (*i); - double const len_dx = editor->sample_to_pixel_unrounded (tmap.sample_at_quarter_note (note_time_qn + dx_qn + n->note()->length())); + double const len_dx = editor->time_to_pixel_unrounded ((note_time_qn + dx_qn + n->note()->length())); sus->set_x1 (n->item()->canvas_to_item (ArdourCanvas::Duple (len_dx, 0)).x); } @@ -2601,7 +2600,7 @@ MidiRegionView::copy_selection (NoteBase* primary) } void -MidiRegionView::move_copies (Temporal::Beats const & dx_qn, double dy, double cumulative_dy) +MidiRegionView::move_copies (timecnt_t const & dx_qn, double dy, double cumulative_dy) { typedef vector > PossibleChord; Editor* editor = dynamic_cast (&trackview.editor()); @@ -2615,8 +2614,8 @@ MidiRegionView::move_copies (Temporal::Beats const & dx_qn, double dy, double c to_play.push_back (n->note()); } - Temporal::Beats const note_time_qn = _region->source_beats_to_absolute_beats (n->note()->time()); - double dx = 0.0; + timepos_t const note_time_qn = _region->source_beats_to_absolute_beats (n->note()->time()); + timecnt_t dx (dx_qn.time_domain()); if (midi_view()->note_mode() == Sustained) { dx = editor->sample_to_pixel_unrounded (tmap.sample_at_quarter_note (note_time_qn + dx_qn)) @@ -2663,7 +2662,7 @@ MidiRegionView::move_copies (Temporal::Beats const & dx_qn, double dy, double c } void -MidiRegionView::note_dropped(NoteBase *, Temporal::Beats const & d_qn, int8_t dnote, bool copy) +MidiRegionView::note_dropped(NoteBase *, timecnt_t const & d_qn, int8_t dnote, bool copy) { uint8_t lowest_note_in_selection = 127; uint8_t highest_note_in_selection = 0; diff --git a/gtk2_ardour/midi_region_view.h b/gtk2_ardour/midi_region_view.h index 2a092f172e..c7a4bb8d04 100644 --- a/gtk2_ardour/midi_region_view.h +++ b/gtk2_ardour/midi_region_view.h @@ -210,10 +210,10 @@ public: void extend_selection (); Temporal::Beats earliest_in_selection (); - void move_selection(Temporal::Beats const & dx, double dy, double cumulative_dy); - void note_dropped (NoteBase* ev, Temporal::Beats const & d_qn, int8_t d_note, bool copy); + void move_selection(Temporal::timecnt_t const & dx, double dy, double cumulative_dy); + void note_dropped (NoteBase* ev, Temporal::timecnt_t const & d_qn, int8_t d_note, bool copy); NoteBase* copy_selection (NoteBase* primary); - void move_copies(Temporal::Beats const & dx_qn, double dy, double cumulative_dy); + void move_copies(Temporal::timecnt_t const & dx_qn, double dy, double cumulative_dy); void select_notes (std::list, bool allow_audition); void select_matching_notes (uint8_t notenum, uint16_t channel_mask, bool add, bool extend); @@ -429,7 +429,7 @@ public: void trim_note(NoteBase* ev, ARDOUR::MidiModel::TimeType start_delta, ARDOUR::MidiModel::TimeType end_delta); - void update_drag_selection (samplepos_t start, samplepos_t end, double y0, double y1, bool extend); + void update_drag_selection (Temporal::timepos_t const & start, Temporal::timepos_t const & end, double y0, double y1, bool extend); void update_vertical_drag_selection (double last_y, double y, bool extend); void add_to_selection (NoteBase*); diff --git a/gtk2_ardour/midi_streamview.cc b/gtk2_ardour/midi_streamview.cc index f00a268c05..0ac640c140 100644 --- a/gtk2_ardour/midi_streamview.cc +++ b/gtk2_ardour/midi_streamview.cc @@ -474,10 +474,10 @@ MidiStreamView::setup_rec_box () // handle multi - samplepos_t start = 0; + timepos_t start; if (rec_regions.size() > 0) { - start = rec_regions.back().first->start() - + _trackview.track()->get_captured_samples (rec_regions.size() - 1); + start = rec_regions.back().first->nt_start() + + timepos_t (_trackview.track()->get_captured_samples (rec_regions.size() - 1)); } if (!rec_regions.empty()) { @@ -488,27 +488,26 @@ MidiStreamView::setup_rec_box () PropertyList plist; plist.add (ARDOUR::Properties::start, start); - plist.add (ARDOUR::Properties::length, 1); - /* Just above we're setting this nascent region's length to 1. I think this - is so that the RegionView gets created with a non-zero width, as apparently - creating a RegionView with a zero width causes it never to be displayed - (there is a warning in TimeAxisViewItem::init about this). However, we - must also set length_beats to something non-zero, otherwise the sample length - of 1 causes length_beats to be set to some small quantity << 1. Then - when the position is set up below, this length_beats is used to recompute - length using BeatsSamplesConverter::to, which is slightly innacurate for small - beats values because it converts floating point beats to bars, beats and - integer ticks. The upshot of which being that length gets set back to 0, - meaning no region view is ever seen, meaning no MIDI notes during record (#3820). + plist.add (ARDOUR::Properties::length, timepos_t (Temporal::Beats::ticks (1))); + /* Just above we're setting this nascent region's length to 1 tick. I think this is so + that the RegionView gets created with a non-zero width, as apparently creating a + RegionView with a zero width causes it never to be displayed (there is a warning in + TimeAxisViewItem::init about this). We don't want to use 1 sample since that results + in zero length musical time duration. */ - plist.add (ARDOUR::Properties::length_beats, 1); plist.add (ARDOUR::Properties::name, string()); plist.add (ARDOUR::Properties::layer, 0); boost::shared_ptr region (boost::dynamic_pointer_cast (RegionFactory::create (sources, plist, false))); if (region) { - region->set_position (_trackview.track()->current_capture_start ()); + + /* MIDI regions should likely not be positioned using audio time, but this is + * just a rec-region, so we don't really care + */ + region->set_start (timecnt_t (_trackview.track()->current_capture_start() + - _trackview.track()->get_capture_start_sample (0))); + region->set_position (_trackview.track()->current_capture_start ().samples()); RegionView* rv = add_region_view_internal (region, false, true); MidiRegionView* mrv = dynamic_cast (rv); @@ -675,12 +674,12 @@ MidiStreamView::resume_updates () struct RegionPositionSorter { bool operator() (RegionView* a, RegionView* b) { - return a->region()->position() < b->region()->position(); + return a->region()->nt_position() < b->region()->nt_position(); } }; bool -MidiStreamView::paste (ARDOUR::samplepos_t pos, const Selection& selection, PasteContext& ctx, const int32_t sub_num) +MidiStreamView::paste (timepos_t const & pos, const Selection& selection, PasteContext& ctx, const int32_t sub_num) { /* Paste into the first region which starts on or before pos. Only called when using an internal editing tool. */ @@ -694,7 +693,7 @@ MidiStreamView::paste (ARDOUR::samplepos_t pos, const Selection& selection, Past list::const_iterator prev = region_views.begin (); for (list::const_iterator i = region_views.begin(); i != region_views.end(); ++i) { - if ((*i)->region()->position() > pos) { + if ((*i)->region()->nt_position() > pos) { break; } prev = i; diff --git a/gtk2_ardour/midi_time_axis.h b/gtk2_ardour/midi_time_axis.h index 10c3de96c4..4c31792b0a 100644 --- a/gtk2_ardour/midi_time_axis.h +++ b/gtk2_ardour/midi_time_axis.h @@ -87,7 +87,7 @@ public: void set_height (uint32_t, TrackHeightMode m = OnlySelf); - boost::shared_ptr add_region (ARDOUR::samplepos_t, ARDOUR::samplecnt_t, bool); + boost::shared_ptr add_region (Temporal::timepos_t const &, Temporal::timecnt_t const &, bool); void show_all_automation (bool apply_to_selection = false); void show_existing_automation (bool apply_to_selection = false); diff --git a/gtk2_ardour/mini_timeline.cc b/gtk2_ardour/mini_timeline.cc index 061671e002..67a8ae46b6 100644 --- a/gtk2_ardour/mini_timeline.cc +++ b/gtk2_ardour/mini_timeline.cc @@ -475,10 +475,10 @@ MiniTimeline::draw_edge (cairo_t* cr, int x0, int x1, bool left, const std::stri struct LocationMarker { - LocationMarker (const std::string& l, samplepos_t w) + LocationMarker (const std::string& l, Temporal::timepos_t const & w) : label (l), when (w) {} std::string label; - samplepos_t when; + Temporal::timepos_t when; }; struct LocationMarkerSort { @@ -589,11 +589,11 @@ MiniTimeline::render (Cairo::RefPtr const& ctx, cairo_rectangle_ int id = 0; for (std::vector::const_iterator l = lm.begin(); l != lm.end(); ++id) { - samplepos_t when = (*l).when; + const samplepos_t when = (*l).when.samples(); if (when < lmin) { outside_left = l; if (++l != lm.end()) { - left_limit = floor (width * .5 + ((*l).when - p) * _px_per_sample) - 1 - mw; + left_limit = floor (width * .5 + (when - p) * _px_per_sample) - 1 - mw; } else { left_limit = width * .5 - mw; } @@ -607,7 +607,7 @@ MiniTimeline::render (Cairo::RefPtr const& ctx, cairo_rectangle_ int x1 = width; const std::string& label = (*l).label; if (++l != lm.end()) { - x1 = floor (width * .5 + ((*l).when - p) * _px_per_sample) - 1 - mw; + x1 = floor (width * .5 + (when - p) * _px_per_sample) - 1 - mw; } bool prelight = false; x1 = draw_mark (cr, x0, x1, label, prelight); @@ -622,7 +622,7 @@ MiniTimeline::render (Cairo::RefPtr const& ctx, cairo_rectangle_ bool prelight = false; x1 = draw_edge (cr, x0, x1, true, (*outside_left).label, prelight); if (x0 != x1) { - _jumplist.push_back (JumpRange (x0, x1, (*outside_left).when, prelight)); + _jumplist.push_back (JumpRange (x0, x1, (*outside_left).when.samples(), prelight)); right_limit = std::max (x1, right_limit); } } @@ -635,7 +635,7 @@ MiniTimeline::render (Cairo::RefPtr const& ctx, cairo_rectangle_ bool prelight = false; x0 = draw_edge (cr, x0, x1, false, (*outside_right).label, prelight); if (x0 != x1) { - _jumplist.push_back (JumpRange (x0, x1, (*outside_right).when, prelight)); + _jumplist.push_back (JumpRange (x0, x1, (*outside_right).when.samples(), prelight)); } } } diff --git a/gtk2_ardour/mixer_strip.cc b/gtk2_ardour/mixer_strip.cc index 364f123cff..32398b1c2a 100644 --- a/gtk2_ardour/mixer_strip.cc +++ b/gtk2_ardour/mixer_strip.cc @@ -498,7 +498,7 @@ MixerStrip::trim_start_touch () { assert (_route && _session); if (route()->trim() && route()->trim()->active() && route()->n_inputs().n_audio() > 0) { - route()->trim()->gain_control ()->start_touch (_session->transport_sample()); + route()->trim()->gain_control ()->start_touch (timepos_t (_session->transport_sample())); } } @@ -507,7 +507,7 @@ MixerStrip::trim_end_touch () { assert (_route && _session); if (route()->trim() && route()->trim()->active() && route()->n_inputs().n_audio() > 0) { - route()->trim()->gain_control ()->stop_touch (_session->transport_sample()); + route()->trim()->gain_control ()->stop_touch (timepos_t (_session->transport_sample())); } } diff --git a/gtk2_ardour/public_editor.h b/gtk2_ardour/public_editor.h index 9bc7c88ee4..b5eaead014 100644 --- a/gtk2_ardour/public_editor.h +++ b/gtk2_ardour/public_editor.h @@ -505,7 +505,7 @@ public: Temporal::RoundMode direction = Temporal::RoundNearest, ARDOUR::SnapPref gpref = ARDOUR::SnapToAny_Visual) = 0; - virtual void set_snapped_cursor_position (samplepos_t pos) = 0; + virtual void set_snapped_cursor_position (Temporal::timepos_t const & pos) = 0; virtual void get_regions_at (RegionSelection &, Temporal::timepos_t const & where, TrackViewList const &) const = 0; virtual void get_regions_after (RegionSelection&, Temporal::timepos_t const & where, const TrackViewList& ts) const = 0; diff --git a/gtk2_ardour/region_editor.cc b/gtk2_ardour/region_editor.cc index b9dc925387..953e57ada2 100644 --- a/gtk2_ardour/region_editor.cc +++ b/gtk2_ardour/region_editor.cc @@ -391,11 +391,11 @@ RegionEditor::bounds_changed (const PropertyChange& what_changed) sync_offset_relative_clock.set_duration (off, true); } - sync_offset_absolute_clock (_region->nt_position () + off, true); + sync_offset_absolute_clock.set (_region->nt_position () + off, true); } if (what_changed.contains (ARDOUR::Properties::start)) { - start_clock.set (_region->nt_start(), true); + start_clock.set (timepos_t (_region->nt_start()), true); } } @@ -441,7 +441,7 @@ RegionEditor::sync_offset_relative_clock_changed () PublicEditor::instance().begin_reversible_command (_("change region sync point")); _region->clear_changes (); - _region->set_sync_position (sync_offset_relative_clock.current_time() + _region->position ()); + _region->set_sync_position (sync_offset_relative_clock.current_time() + _region->nt_position ()); _session->add_command (new StatefulDiffCommand (_region)); PublicEditor::instance().commit_reversible_command (); diff --git a/gtk2_ardour/region_gain_line.cc b/gtk2_ardour/region_gain_line.cc index bb474edd1a..1ef098fede 100644 --- a/gtk2_ardour/region_gain_line.cc +++ b/gtk2_ardour/region_gain_line.cc @@ -44,14 +44,12 @@ using namespace ARDOUR; using namespace PBD; AudioRegionGainLine::AudioRegionGainLine (const string & name, AudioRegionView& r, ArdourCanvas::Container& parent, boost::shared_ptr l) - : AutomationLine (name, r.get_time_axis_view(), parent, l, l->parameter(), Temporal::DistanceMeasure (r.get_time_axis_view().session()->tempo_map(), r.region()->position())) + : AutomationLine (name, r.get_time_axis_view(), parent, l, l->parameter(), Temporal::DistanceMeasure (r.region()->nt_position())) , rv (r) { // If this isn't true something is horribly wrong, and we'll get catastrophic gain values assert(l->parameter().type() == EnvelopeAutomation); - _time_converter->set_origin_b (rv.region()->position()); - r.region()->PropertyChanged.connect (_region_changed_connection, invalidator (*this), boost::bind (&AudioRegionGainLine::region_changed, this, _1), gui_context()); group->raise_to_top (); @@ -112,14 +110,10 @@ AudioRegionGainLine::region_changed (const PropertyChange& what_changed) interesting_stuff.add (ARDOUR::Properties::start); interesting_stuff.add (ARDOUR::Properties::position); - if (what_changed.contains (interesting_stuff)) { - _time_converter->set_origin_b (rv.region()->position()); + if (what_changed.containts (ARDOUR::Properties::position)) { + set_distance_measure_origin (rv.region()->nt_position()); } - interesting_stuff.clear (); - interesting_stuff.add (ARDOUR::Properties::start); - interesting_stuff.add (ARDOUR::Properties::length); - if (what_changed.contains (interesting_stuff)) { reset (); } diff --git a/gtk2_ardour/region_view.cc b/gtk2_ardour/region_view.cc index 2d22a43081..b3dddc8c0a 100644 --- a/gtk2_ardour/region_view.cc +++ b/gtk2_ardour/region_view.cc @@ -1066,7 +1066,7 @@ RegionView::update_coverage_frame (LayerDisplay d) } bool -RegionView::trim_front (samplepos_t new_bound, bool no_overlap, const int32_t sub_num) +RegionView::trim_front (timepos_t const & new_bound, bool no_overlap, const int32_t sub_num) { if (_region->locked()) { return false; @@ -1103,7 +1103,7 @@ RegionView::trim_front (samplepos_t new_bound, bool no_overlap, const int32_t su } bool -RegionView::trim_end (samplepos_t new_bound, bool no_overlap, const int32_t sub_num) +RegionView::trim_end (timepos_t const & new_bound, bool no_overlap, const int32_t sub_num) { if (_region->locked()) { return false; @@ -1151,7 +1151,7 @@ RegionView::thaw_after_trim () void -RegionView::move_contents (sampleoffset_t distance) +RegionView::move_contents (timecnt_t const & distance) { if (_region->locked()) { return; diff --git a/gtk2_ardour/region_view.h b/gtk2_ardour/region_view.h index 7e00c90e99..90ed0936b6 100644 --- a/gtk2_ardour/region_view.h +++ b/gtk2_ardour/region_view.h @@ -110,13 +110,13 @@ public: /** Called when a front trim is about to begin */ virtual void trim_front_starting () {} - bool trim_front (samplepos_t, bool, const int32_t sub_num); + bool trim_front (Temporal::timepos_t const &, bool); /** Called when a start trim has finished */ virtual void trim_front_ending () {} - bool trim_end (samplepos_t, bool, const int32_t sub_num); - void move_contents (ARDOUR::sampleoffset_t); + bool trim_end (Temporal::timepos_t const &, bool); + void move_contents (Temporal::timecnt_t const &); virtual void thaw_after_trim (); void set_silent_frames (const ARDOUR::AudioIntervalResult&, double threshold); diff --git a/gtk2_ardour/route_time_axis.cc b/gtk2_ardour/route_time_axis.cc index 5d886f1797..37fb0385d3 100644 --- a/gtk2_ardour/route_time_axis.cc +++ b/gtk2_ardour/route_time_axis.cc @@ -883,7 +883,7 @@ RouteTimeAxisView::layer_display_menu_change (Gtk::MenuItem* item) } void -RouteTimeAxisView::show_timestretch (samplepos_t start, samplepos_t end, int layers, int layer) +RouteTimeAxisView::show_timestretch (timepos_t const & start, timepos_t const & end, int layers, int layer) { TimeAxisView::show_timestretch (start, end, layers, layer); @@ -920,8 +920,10 @@ RouteTimeAxisView::show_timestretch (samplepos_t start, samplepos_t end, int lay timestretch_rect->show (); timestretch_rect->raise_to_top (); - double const x1 = start / _editor.get_current_zoom(); - double const x2 = (end - 1) / _editor.get_current_zoom(); +#warning NUTEMPO is it ok to just fudge this being in samples? + + double const x1 = start.samples() / _editor.get_current_zoom(); + double const x2 = (end.samples() - 1) / _editor.get_current_zoom(); timestretch_rect->set (ArdourCanvas::Rect (x1, current_height() * (layers - layer - 1) / layers, x2, current_height() * (layers - layer) / layers)); diff --git a/gtk2_ardour/route_time_axis.h b/gtk2_ardour/route_time_axis.h index 9bd493d195..5a253c86fc 100644 --- a/gtk2_ardour/route_time_axis.h +++ b/gtk2_ardour/route_time_axis.h @@ -95,7 +95,7 @@ public: void set_samples_per_pixel (double); void set_height (uint32_t h, TrackHeightMode m = OnlySelf); - void show_timestretch (samplepos_t start, samplepos_t end, int layers, int layer); + void show_timestretch (Temporal::timepos_t const & start, Temporal::timepos_t const & end, int layers, int layer); void hide_timestretch (); void selection_click (GdkEventButton*); void set_selected_points (PointSelection&); diff --git a/gtk2_ardour/selection.cc b/gtk2_ardour/selection.cc index eecb7e5163..2725be44b7 100644 --- a/gtk2_ardour/selection.cc +++ b/gtk2_ardour/selection.cc @@ -433,7 +433,7 @@ Selection::add (RegionView* r) } long -Selection::add (samplepos_t start, samplepos_t end) +Selection::add (timepos_t const & start, timepos_t const & end) { clear_objects(); // enforce object/range exclusivity @@ -451,7 +451,7 @@ Selection::add (samplepos_t start, samplepos_t end) } void -Selection::move_time (samplecnt_t distance) +Selection::move_time (timecnt_t const & distance) { if (distance == 0) { return; @@ -466,14 +466,14 @@ Selection::move_time (samplecnt_t distance) } void -Selection::replace (uint32_t sid, samplepos_t start, samplepos_t end) +Selection::replace (uint32_t sid, timepos_t const & start, timepos_t const & end) { clear_objects(); // enforce object/range exclusivity for (list::iterator i = time.begin(); i != time.end(); ++i) { if ((*i).id == sid) { time.erase (i); - time.push_back (TimelineRange(start,end, sid)); + time.push_back (TimelineRange (start,end, sid)); /* don't consolidate here */ @@ -1040,10 +1040,16 @@ Selection::add (const list& m) } void -MarkerSelection::range (samplepos_t& s, samplepos_t& e) +MarkerSelection::range (timepos_t& s, timepos_t& e) { - s = max_samplepos; - e = 0; + if (empty()) { + s = timepos_t::zero (Temporal::AudioTime); + e = timepos_t::zero (Temporal::AudioTime); + return; + } + + s = timepos_t::max (front()->position().time_domain()); + e = timepos_t::zero (front()->position().time_domain()); for (MarkerSelection::iterator i = begin(); i != end(); ++i) { diff --git a/gtk2_ardour/selection.h b/gtk2_ardour/selection.h index 8fc1bfd77e..b14ad79664 100644 --- a/gtk2_ardour/selection.h +++ b/gtk2_ardour/selection.h @@ -165,7 +165,7 @@ public: void add (RegionView*); void add (MidiCutBuffer*); void add (std::vector&); - long add (samplepos_t, samplepos_t); + long add (Temporal::timepos_t const &, Temporal::timepos_t const &); void add (boost::shared_ptr); void add (boost::shared_ptr); void add (const std::list >&); @@ -192,9 +192,9 @@ public: void remove_regions (TimeAxisView *); - void move_time (samplecnt_t); + void move_time (Temporal::timecnt_t const &); - void replace (uint32_t time_index, samplepos_t start, samplepos_t end); + void replace (uint32_t time_index, Temporal::timepos_t const & start, Temporal::timepos_t const & end); /* * A note about items in an editing Selection: diff --git a/gtk2_ardour/time_axis_view.cc b/gtk2_ardour/time_axis_view.cc index 2c6a898f82..6b196e4f64 100644 --- a/gtk2_ardour/time_axis_view.cc +++ b/gtk2_ardour/time_axis_view.cc @@ -828,7 +828,7 @@ TimeAxisView::set_samples_per_pixel (double fpp) } void -TimeAxisView::show_timestretch (samplepos_t start, samplepos_t end, int layers, int layer) +TimeAxisView::show_timestretch (timepos_t const & start, timepos_t const & end, int layers, int layer) { for (Children::iterator i = children.begin(); i != children.end(); ++i) { (*i)->show_timestretch (start, end, layers, layer); diff --git a/gtk2_ardour/time_axis_view.h b/gtk2_ardour/time_axis_view.h index 5e5ff9dcc5..729a72ca83 100644 --- a/gtk2_ardour/time_axis_view.h +++ b/gtk2_ardour/time_axis_view.h @@ -177,7 +177,7 @@ public: virtual void show_selection (TimeSelection&); virtual void hide_selection (); virtual void reshow_selection (TimeSelection&); - virtual void show_timestretch (samplepos_t start, samplepos_t end, int layers, int layer); + virtual void show_timestretch (Temporal::timepos_t const & start, Temporal::timepos_t const & end, int layers, int layer); virtual void hide_timestretch (); /* editing operations */