From 04e8dbb342b6e154e3dd366c30ee0f719a4a0acc Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Fri, 2 Oct 2020 21:26:17 -0600 Subject: [PATCH] another day of slow timeline type conversion --- gtk2_ardour/ardour_ui2.cc | 4 +- gtk2_ardour/audio_region_view.cc | 66 +++++++++++++++------------- gtk2_ardour/automation_line.cc | 29 ++++++++---- gtk2_ardour/automation_line.h | 11 ++++- gtk2_ardour/automation_streamview.cc | 2 +- gtk2_ardour/automation_streamview.h | 2 +- gtk2_ardour/automation_time_axis.cc | 31 ++++++++----- gtk2_ardour/automation_time_axis.h | 2 +- gtk2_ardour/editor_canvas_events.cc | 4 +- gtk2_ardour/lv2_plugin_ui.cc | 4 +- gtk2_ardour/patch_change_dialog.cc | 15 ++++--- gtk2_ardour/patch_change_dialog.h | 6 +-- gtk2_ardour/region_gain_line.cc | 2 +- gtk2_ardour/route_time_axis.h | 2 +- gtk2_ardour/step_editor.cc | 27 +++++++----- gtk2_ardour/step_editor.h | 2 +- gtk2_ardour/streamview.cc | 8 ++-- gtk2_ardour/streamview.h | 2 +- gtk2_ardour/time_axis_view.h | 2 +- gtk2_ardour/time_info_box.cc | 16 ++++--- 20 files changed, 138 insertions(+), 99 deletions(-) diff --git a/gtk2_ardour/ardour_ui2.cc b/gtk2_ardour/ardour_ui2.cc index a1bb19c01f..f69fef03a1 100644 --- a/gtk2_ardour/ardour_ui2.cc +++ b/gtk2_ardour/ardour_ui2.cc @@ -331,8 +331,8 @@ ARDOUR_UI::setup_transport () set_size_request_to_display_given_text (io_latency_value, "1000 spl", 0, 0); /* connect signals */ - ARDOUR_UI::Clock.connect (sigc::bind (sigc::mem_fun (primary_clock, &MainClock::set), false, 0)); - ARDOUR_UI::Clock.connect (sigc::bind (sigc::mem_fun (secondary_clock, &MainClock::set), false, 0)); + ARDOUR_UI::Clock.connect (sigc::bind (sigc::mem_fun (primary_clock, &MainClock::set), false, timecnt_t::zero (Temporal::AudioTime))); + ARDOUR_UI::Clock.connect (sigc::bind (sigc::mem_fun (secondary_clock, &MainClock::set), false, timecnt_t::zero (Temporal::AudioTime))); primary_clock->ValueChanged.connect (sigc::mem_fun(*this, &ARDOUR_UI::primary_clock_value_changed)); secondary_clock->ValueChanged.connect (sigc::mem_fun(*this, &ARDOUR_UI::secondary_clock_value_changed)); diff --git a/gtk2_ardour/audio_region_view.cc b/gtk2_ardour/audio_region_view.cc index d198edaa5d..fb760f5126 100644 --- a/gtk2_ardour/audio_region_view.cc +++ b/gtk2_ardour/audio_region_view.cc @@ -483,7 +483,7 @@ AudioRegionView::reset_width_dependent_items (double pixel_width) return; } - samplepos_t position = _region->position(); + samplepos_t position = _region->position_sample(); AnalysisFeatureList::const_iterator i; list >::iterator l; @@ -598,7 +598,7 @@ AudioRegionView::set_height (gdouble height) reset_fade_shapes (); /* Update heights for any feature lines */ - samplepos_t position = _region->position(); + samplepos_t position = _region->position_sample(); list >::iterator l; double y1; if (_height >= NAME_HIGHLIGHT_THRESH) { @@ -629,7 +629,7 @@ AudioRegionView::reset_fade_shapes () void AudioRegionView::reset_fade_in_shape () { - reset_fade_in_shape_width (audio_region(), (samplecnt_t) audio_region()->fade_in()->back()->when); + reset_fade_in_shape_width (audio_region(), audio_region()->fade_in()->back()->when.samples()); } void @@ -645,7 +645,7 @@ AudioRegionView::reset_fade_in_shape_width (boost::shared_ptr ar, s width = std::max ((samplecnt_t) 64, width); /* round here to prevent little visual glitches with sub-pixel placement */ - double const pwidth = floor (width / samples_per_pixel); + double const pwidth = (double) width / samples_per_pixel; double const handle_left = pwidth; /* Put the fade in handle so that its left side is at the end-of-fade line */ @@ -662,7 +662,7 @@ AudioRegionView::reset_fade_in_shape_width (boost::shared_ptr ar, s entered(); } - if (pwidth < 5) { + if (pwidth < 5.f) { hide_start_xfade(); return; } @@ -686,12 +686,13 @@ AudioRegionView::reset_fade_in_shape_width (boost::shared_ptr ar, s Points::size_type pi; boost::shared_ptr list (audio_region()->fade_in()); Evoral::ControlList::const_iterator x; - double length = list->length(); + samplecnt_t length = list->length().samples(); points.assign (list->size(), Duple()); for (x = list->begin(), pi = 0; x != list->end(); ++x, ++pi) { - points[pi].x = (pwidth * ((*x)->when/length)); + const double p = (*x)->when.samples(); + points[pi].x = (p * pwidth) / length; points[pi].y = effective_height - ((*x)->value * (effective_height - 1.)); } @@ -708,7 +709,7 @@ AudioRegionView::reset_fade_in_shape_width (boost::shared_ptr ar, s void AudioRegionView::reset_fade_out_shape () { - reset_fade_out_shape_width (audio_region(), (samplecnt_t) audio_region()->fade_out()->back()->when); + reset_fade_out_shape_width (audio_region(), audio_region()->fade_out()->back()->when.samples()); } void @@ -730,8 +731,8 @@ AudioRegionView::reset_fade_out_shape_width (boost::shared_ptr ar, * width is zero. Hence the additional + 1.0 at the end. */ - double const handle_right = rint(trackview.editor().sample_to_pixel (_region->length()) - pwidth); - double const trim_handle_right = rint(trackview.editor().sample_to_pixel (_region->length())); + double const handle_right = rint(trackview.editor().sample_to_pixel (_region->length_samples()) - pwidth); + double const trim_handle_right = rint(trackview.editor().sample_to_pixel (_region->length_samples())); /* Put the fade out handle so that its right side is at the end-of-fade line; */ @@ -772,12 +773,13 @@ AudioRegionView::reset_fade_out_shape_width (boost::shared_ptr ar, Points::size_type pi; boost::shared_ptr list (audio_region()->fade_out()); Evoral::ControlList::const_iterator x; - double length = list->length(); + double length = list->length().samples(); points.assign (list->size(), Duple()); for (x = list->begin(), pi = 0; x != list->end(); ++x, ++pi) { - points[pi].x = _pixel_width - pwidth + (pwidth * ((*x)->when/length)); + const double p = (*x)->when.samples(); + points[pi].x = _pixel_width - pwidth + (pwidth * (p/length)); points[pi].y = effective_height - ((*x)->value * (effective_height - 1.)); } @@ -794,13 +796,13 @@ AudioRegionView::reset_fade_out_shape_width (boost::shared_ptr ar, samplepos_t AudioRegionView::get_fade_in_shape_width () { - return audio_region()->fade_in()->back()->when; + return audio_region()->fade_in()->back()->when.samples(); } samplepos_t AudioRegionView::get_fade_out_shape_width () { - return audio_region()->fade_out()->back()->when; + return audio_region()->fade_out()->back()->when.samples(); } @@ -814,7 +816,7 @@ AudioRegionView::redraw_start_xfade () } show_start_xfade(); - reset_fade_in_shape_width (ar, ar->fade_in()->back()->when); + reset_fade_in_shape_width (ar, ar->fade_in()->back()->when.samples()); } void @@ -878,11 +880,12 @@ AudioRegionView::redraw_start_xfade_to (boost::shared_ptr ar, sampl Evoral::ControlList::const_iterator x; Points::size_type pi; - double length = inverse->length(); + const double length = inverse->length().samples(); for (x = inverse->begin(), pi = 0; x != inverse->end(); ++x, ++pi) { ArdourCanvas::Duple& p (ipoints[pi]); - p.x = (rect_width * ((*x)->when/length)); + double pos = (*x)->when.samples(); + p.x = (rect_width * (pos/length)); p.y = effective_height - ((*x)->value * (effective_height)); } } @@ -903,7 +906,7 @@ AudioRegionView::redraw_end_xfade () show_end_xfade(); - reset_fade_out_shape_width (ar, ar->fade_out()->back()->when); + reset_fade_out_shape_width (ar, ar->fade_out()->back()->when.samples()); } void @@ -967,15 +970,16 @@ AudioRegionView::redraw_end_xfade_to (boost::shared_ptr ar, samplec npoints = inverse->size(); ipoints.assign (npoints, Duple()); - const double rend = trackview.editor().sample_to_pixel (_region->length() - width); + const double rend = trackview.editor().sample_to_pixel (_region->length_samples() - width); Evoral::ControlList::const_iterator x; Points::size_type pi; - double length = inverse->length(); + const double length = inverse->length().samples(); for (x = inverse->begin(), pi = 0; x != inverse->end(); ++x, ++pi) { ArdourCanvas::Duple& p (ipoints[pi]); - p.x = (rect_width * ((*x)->when/length)) + rend; + const double pos = (*x)->when.samples(); + p.x = (rect_width * (pos/length)) + rend; p.y = effective_height - ((*x)->value * (effective_height)); } } @@ -1375,12 +1379,12 @@ AudioRegionView::add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev, b /* don't create points that can't be seen */ update_envelope_visibility (); - samplepos_t rpos = region ()->position (); - MusicSample snap_pos (trackview.editor().pixel_to_sample (mx) + rpos, 0); + samplepos_t rpos = region ()->position_sample(); + timepos_t snap_pos = timepos_t (trackview.editor().pixel_to_sample (mx) + rpos); trackview.editor ().snap_to_with_modifier (snap_pos, ev); - samplepos_t fx = snap_pos.sample - rpos; + samplepos_t fx = snap_pos.samples() - rpos; - if (fx > _region->length()) { + if (fx > _region->length_samples()) { return; } @@ -1406,7 +1410,7 @@ AudioRegionView::add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev, b region_memento = new MementoCommand(*(audio_region().get()), ®ion_before, ®ion_after); } - if (audio_region()->envelope()->editor_add (fx, y, with_guard_points)) { + if (audio_region()->envelope()->editor_add (timepos_t (fx), y, with_guard_points)) { XMLNode &after = audio_region()->envelope()->get_state(); std::list results; @@ -1418,7 +1422,7 @@ AudioRegionView::add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev, b trackview.session()->add_command (new MementoCommand(*audio_region()->envelope().get(), &before, &after)); - gain_line->get_selectables (fx + region ()->position (), fx + region ()->position (), 0.0, 1.0, results); + gain_line->get_selectables (region ()->nt_position () + timecnt_t (fx), region ()->nt_position () + timecnt_t (fx), 0.0, 1.0, results); trackview.editor ().get_selection ().set (results); trackview.editor ().commit_reversible_command (); @@ -1444,7 +1448,7 @@ AudioRegionView::add_ghost (TimeAxisView& tv) return 0; } - double unit_position = _region->position () / samples_per_pixel; + double unit_position = _region->position_sample () / samples_per_pixel; AudioGhostRegion* ghost = new AudioGhostRegion (*this, tv, trackview, unit_position); uint32_t nchans; @@ -1467,7 +1471,7 @@ AudioRegionView::add_ghost (TimeAxisView& tv) } ghost->set_height (); - ghost->set_duration (_region->length() / samples_per_pixel); + ghost->set_duration (_region->length_samples() / samples_per_pixel); ghost->set_colors(); ghosts.push_back (ghost); @@ -1682,7 +1686,7 @@ AudioRegionView::transients_changed () { AnalysisFeatureList analysis_features; _region->transients (analysis_features); - samplepos_t position = _region->position(); + samplepos_t position = _region->position_sample(); samplepos_t first = _region->first_sample(); samplepos_t last = _region->last_sample(); @@ -1753,7 +1757,7 @@ AudioRegionView::update_transient(float /*old_pos*/, float new_pos) float* pos = (float*) (*l).second->get_data ("position"); if (rint(new_pos) == rint(*pos)) { - samplepos_t position = _region->position(); + samplepos_t position = _region->position_sample(); samplepos_t old_sample = (*l).first; samplepos_t new_sample = trackview.editor().pixel_to_sample (new_pos) + position; _region->update_transient (old_sample, new_sample); diff --git a/gtk2_ardour/automation_line.cc b/gtk2_ardour/automation_line.cc index 452b53f777..343641aa1d 100644 --- a/gtk2_ardour/automation_line.cc +++ b/gtk2_ardour/automation_line.cc @@ -76,6 +76,10 @@ using namespace ARDOUR; using namespace PBD; using namespace Editing; + +#define TIME_TO_SAMPLES(x) (_distance_measure (x, Temporal::AudioTime)) +#define SAMPLES_TO_TIME(x) (_distance_measure (x, alist->time_style())) + /** @param converter A TimeConverter whose origin_b is the start time of the AutomationList in session samples. * This will not be deleted by AutomationLine. */ @@ -83,16 +87,17 @@ AutomationLine::AutomationLine (const string& name, TimeAxisView& tv, ArdourCanvas::Item& parent, boost::shared_ptr al, - const ParameterDescriptor& desc) + const ParameterDescriptor& desc, + DistanceMeasure const & m) : trackview (tv) , _name (name) , alist (al) - , _time_converter (converter ? converter : new Evoral::IdentityConverter) , _parent_group (parent) , _offset (0) , _maximum_time (timepos_t::max (al->time_domain())) , _fill (false) , _desc (desc) + , _distance_measure (m) { if (converter) { _our_time_converter = false; @@ -782,11 +787,13 @@ AutomationLine::sync_model_with_view_point (ControlPoint& cp) /* if xval has not changed, set it directly from the model to avoid rounding errors */ - if (view_x == trackview.editor().sample_to_pixel_unrounded (_time_converter->to ((*cp.model())->when)) - _offset) { - view_x = (*cp.model())->when - _offset; - } else { - view_x = trackview.editor().pixel_to_sample (view_x); - view_x = _time_converter->from (view_x + _offset); + timepos_t model_x = alist->control_point_time (**(cp.model())); + + if (view_x != trackview.editor().time_to_pixel_unrounded (model_x.earlier (_offset))) { + /* convert from view coordinates, via pixels->samples->timepos_t + */ + const timecnt_t p = timecnt_t (trackview.editor().pixel_to_sample (view_x), timepos_t()); /* samples */ + model_x = SAMPLES_TO_TIME (p + _offset); /* correct time domain for list */ } update_pending = true; @@ -1380,9 +1387,15 @@ AutomationLine::get_point_x_range () const } samplepos_t +AutomationLine::session_sample_position (AutomationList::const_iterator p) const +{ + return alist->control_point_time (ev).sample() + _offset.samples() + _distance_measure.origin().samples(); +} + +timepos_t AutomationLine::session_position (AutomationList::const_iterator p) const { - return _time_converter->to ((*p)->when) + _offset + _time_converter->origin_b (); + return alist->control_point_time (ev) + _offset + _distance_measure.origin(); } void diff --git a/gtk2_ardour/automation_line.h b/gtk2_ardour/automation_line.h index 16c5429001..619ab7bf07 100644 --- a/gtk2_ardour/automation_line.h +++ b/gtk2_ardour/automation_line.h @@ -37,6 +37,8 @@ #include "pbd/statefuldestructible.h" #include "pbd/memento_command.h" +#include "temporal/time_converter.h" + #include "ardour/automation_list.h" #include "ardour/parameter_descriptor.h" #include "ardour/types.h" @@ -79,7 +81,7 @@ public: void set_fill (bool f) { _fill = f; } // owner needs to call set_height void set_selected_points (PointSelection const &); - void get_selectables (ARDOUR::samplepos_t, ARDOUR::samplepos_t, double, double, std::list&); + void get_selectables (Temporal::timepos_t const &, Temporal::timepos_t const &, double, double, std::list&); void get_inverted_selectables (Selection&, std::list& results); virtual void remove_point (ControlPoint&); @@ -159,7 +161,11 @@ public: Temporal::timecnt_t offset () { return _offset; } void set_width (Temporal::timecnt_t const &); - samplepos_t session_position (ARDOUR::AutomationList::const_iterator) const; + samplepos_t session_sample_position (ARDOUR::AutomationList::const_iterator) const; + Temporal::timepos_t session_position (ARDOUR::AutomationList::const_iterator) const; + + Temporal::DistanceMeasure const & distance_measure () const { return _distance_measure; } + void set_distance_measure_origin (Temporal::timepos_t const &); protected: @@ -239,6 +245,7 @@ private: bool _fill; const ARDOUR::ParameterDescriptor _desc; + Temporal::DistanceMeasure _distance_measure; friend class AudioRegionGainLine; }; diff --git a/gtk2_ardour/automation_streamview.cc b/gtk2_ardour/automation_streamview.cc index de38d94f73..8ebebff5e4 100644 --- a/gtk2_ardour/automation_streamview.cc +++ b/gtk2_ardour/automation_streamview.cc @@ -287,7 +287,7 @@ AutomationStreamView::clear () * confusing. */ void -AutomationStreamView::get_selectables (samplepos_t start, samplepos_t end, double botfrac, double topfrac, list& results, bool /*within*/) +AutomationStreamView::get_selectables (timepos_t const & start, timepos_t const & end, double botfrac, double topfrac, list& results, bool /*within*/) { for (list::iterator i = region_views.begin(); i != region_views.end(); ++i) { AutomationRegionView* arv = dynamic_cast (*i); diff --git a/gtk2_ardour/automation_streamview.h b/gtk2_ardour/automation_streamview.h index 77e5c58263..0d872d3a03 100644 --- a/gtk2_ardour/automation_streamview.h +++ b/gtk2_ardour/automation_streamview.h @@ -63,7 +63,7 @@ public: void clear (); - void get_selectables (ARDOUR::samplepos_t, ARDOUR::samplepos_t, double, double, std::list &, bool within = false); + void get_selectables (Temporal::timepos_t const &, Temporal::timepos_t const &, double, double, std::list &, bool within = false); void set_selected_points (PointSelection &); std::list > get_lines () const; diff --git a/gtk2_ardour/automation_time_axis.cc b/gtk2_ardour/automation_time_axis.cc index 1eaa778427..15d9b9fa4f 100644 --- a/gtk2_ardour/automation_time_axis.cc +++ b/gtk2_ardour/automation_time_axis.cc @@ -306,6 +306,7 @@ AutomationTimeAxisView::AutomationTimeAxisView ( *_canvas_display, _control->alist(), _control->desc() + Temporal::DistanceMeasure (_session->tempo_map(), timepos_t()) /* default distance measure, origin at absolute zero */ ) ); @@ -853,22 +854,30 @@ AutomationTimeAxisView::paste_one (samplepos_t pos, unsigned paste_count, float /* add multi-paste offset if applicable */ - AutomationType src_type = (AutomationType)(*p)->parameter().type (); - double len = (*p)->length(); - if (parameter_is_midi (src_type)) { - // convert length to samples (incl tempo-ramps) - len = BeatsSamplesConverter (_session->tempo_map(), pos).to (Temporal::Beats::from_double (len * paste_count)); - pos += _editor.get_paste_offset (pos, paste_count > 0 ? 1 : 0, len); - } else { - pos += _editor.get_paste_offset (pos, paste_count, len); + Temporal::timecnt_t len = (*p)->length(); + Temporal::timepos_t tpos (pos); + + assert (line()->the_list()->time_style() != Temporal::BarTime); + + switch (line()->the_list()->time_style()) { + case Temporal::BeatTime: + tpos += _editor.get_paste_offset (pos, paste_count > 0 ? 1 : 0, len); + break; + case Temporal::AudioTime: + tpos += _editor.get_paste_offset (pos, paste_count, len); + break; + case Temporal::BarTime: + /*NOTREACHED*/ + break; } - /* convert sample-position to model's unit and position */ - double const model_pos = _line->time_converter().from (pos - _line->time_converter().origin_b ()); + /* convert position to model's unit and position */ + Temporal::DistanceMeasure const & dm (_line->distance_measure()); + Temporal::timepos_t model_pos = dm (_line->distance_measure().origin().distance (tpos), line()->the_list()->time_style()); XMLNode &before = alist->get_state(); - alist->paste (**p, model_pos, BeatsSamplesConverter (_session->tempo_map(), pos)); + alist->paste (**p, model_pos, _session->tempo_map()); _session->add_command (new MementoCommand(*alist.get(), &before, &alist->get_state())); return true; diff --git a/gtk2_ardour/automation_time_axis.h b/gtk2_ardour/automation_time_axis.h index 3c826819ea..3024aad54c 100644 --- a/gtk2_ardour/automation_time_axis.h +++ b/gtk2_ardour/automation_time_axis.h @@ -98,7 +98,7 @@ public: std::list > lines () const; void set_selected_points (PointSelection&); - void get_selectables (ARDOUR::samplepos_t start, ARDOUR::samplepos_t end, double top, double bot, std::list&, bool within = false); + 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*/) {} diff --git a/gtk2_ardour/editor_canvas_events.cc b/gtk2_ardour/editor_canvas_events.cc index 2d52558854..bdecd0047a 100644 --- a/gtk2_ardour/editor_canvas_events.cc +++ b/gtk2_ardour/editor_canvas_events.cc @@ -1289,12 +1289,12 @@ Editor::drop_regions (const Glib::RefPtr& /*context*/, } else { try { if (boost::dynamic_pointer_cast (region)) { - uint32_t output_chan = region->n_channels(); + uint32_t output_chan = region->sources().size(); if ((Config->get_output_auto_connect() & AutoConnectMaster) && session()->master_out()) { output_chan = session()->master_out()->n_inputs().n_audio(); } list > audio_tracks; - audio_tracks = session()->new_audio_track (region->n_channels(), output_chan, 0, 1, region->name(), PresentationInfo::max_order); + audio_tracks = session()->new_audio_track (region->sources().size(), output_chan, 0, 1, region->name(), PresentationInfo::max_order); rtav = dynamic_cast (time_axis_view_from_stripable (audio_tracks.front())); } else if (boost::dynamic_pointer_cast (region)) { ChanCount one_midi_port (DataType::MIDI, 1); diff --git a/gtk2_ardour/lv2_plugin_ui.cc b/gtk2_ardour/lv2_plugin_ui.cc index 9bc5016638..b205c8ccbc 100644 --- a/gtk2_ardour/lv2_plugin_ui.cc +++ b/gtk2_ardour/lv2_plugin_ui.cc @@ -115,9 +115,9 @@ LV2PluginUI::touch(void* controller, ControllableRef control = me->_controllables[port_index]; if (grabbed) { - control->start_touch(control->session().transport_sample()); + control->start_touch (timepos_t (control->session().transport_sample())); } else { - control->stop_touch(control->session().transport_sample()); + control->stop_touch (timepos_t (control->session().transport_sample())); } } diff --git a/gtk2_ardour/patch_change_dialog.cc b/gtk2_ardour/patch_change_dialog.cc index 9fc6b693f7..a6ea57f109 100644 --- a/gtk2_ardour/patch_change_dialog.cc +++ b/gtk2_ardour/patch_change_dialog.cc @@ -28,8 +28,8 @@ #include "midi++/midnam_patch.h" -#include "ardour/beats_samples_converter.h" #include "ardour/instrument_info.h" +#include "ardour/region.h" #include "patch_change_dialog.h" #include "gui_thread.h" @@ -48,9 +48,10 @@ PatchChangeDialog::PatchChangeDialog ( ARDOUR::InstrumentInfo& info, const Gtk::BuiltinStockID& ok, bool allow_delete, - bool modal) + bool modal, + boost::shared_ptr region) : ArdourDialog (_("Patch Change"), modal) - , _time_converter (tc) + , _region (region) , _info (info) , _time (X_("patchchangetime"), true, "", true, false) , _channel (*manage (new Adjustment (1, 1, 16, 1, 4))) @@ -65,7 +66,7 @@ PatchChangeDialog::PatchChangeDialog ( t->set_spacings (6); int r = 0; - if (_time_converter) { + if (_region) { l = manage (left_aligned_label (_("Time"))); t->attach (*l, 0, 1, r, r + 1); @@ -74,7 +75,7 @@ PatchChangeDialog::PatchChangeDialog ( _time.set_session (session); _time.set_mode (AudioClock::BBT); - _time.set (_time_converter->to (patch.time ()), true); + _time.set (_region->source_beats_to_absolute_time (patch.time ()), true); } l = manage (left_aligned_label (_("Patch Bank"))); @@ -175,8 +176,8 @@ PatchChangeDialog::patch () const { Temporal::Beats t = Temporal::Beats(); - if (_time_converter) { - t = _time_converter->from (_time.current_time ()); + if (_region) { + t = _region->region_beats_to_source_beats (_time.current_time ().beats()); } return Evoral::PatchChange ( diff --git a/gtk2_ardour/patch_change_dialog.h b/gtk2_ardour/patch_change_dialog.h index 7a7b69119e..d45c2d2a20 100644 --- a/gtk2_ardour/patch_change_dialog.h +++ b/gtk2_ardour/patch_change_dialog.h @@ -48,7 +48,8 @@ public: ARDOUR::InstrumentInfo&, const Gtk::BuiltinStockID&, bool allow_delete = false, - bool modal = true + bool modal = true, + boost::shared_ptr region = boost::shared_ptr() ); Evoral::PatchChange patch () const; @@ -69,10 +70,9 @@ private: int get_14bit_bank () const; - const ARDOUR::BeatsSamplesConverter* _time_converter; + const boost::shared_ptr _region; ARDOUR::InstrumentInfo& _info; AudioClock _time; - Gtk::SpinButton _channel; Gtk::SpinButton _program; Gtk::SpinButton _bank_msb; diff --git a/gtk2_ardour/region_gain_line.cc b/gtk2_ardour/region_gain_line.cc index a31d31b76e..bb474edd1a 100644 --- a/gtk2_ardour/region_gain_line.cc +++ b/gtk2_ardour/region_gain_line.cc @@ -44,7 +44,7 @@ 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()) + : AutomationLine (name, r.get_time_axis_view(), parent, l, l->parameter(), Temporal::DistanceMeasure (r.get_time_axis_view().session()->tempo_map(), r.region()->position())) , rv (r) { // If this isn't true something is horribly wrong, and we'll get catastrophic gain values diff --git a/gtk2_ardour/route_time_axis.h b/gtk2_ardour/route_time_axis.h index 95f3eb7d01..9bd493d195 100644 --- a/gtk2_ardour/route_time_axis.h +++ b/gtk2_ardour/route_time_axis.h @@ -100,7 +100,7 @@ public: void selection_click (GdkEventButton*); void set_selected_points (PointSelection&); void set_selected_regionviews (RegionSelection&); - void get_selectables (ARDOUR::samplepos_t start, ARDOUR::samplepos_t end, double top, double bot, std::list&, bool within = false); + 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&); void get_regionviews_at_or_after (ARDOUR::samplepos_t, RegionSelection&); void set_layer_display (LayerDisplay d); diff --git a/gtk2_ardour/step_editor.cc b/gtk2_ardour/step_editor.cc index f2b6711777..c96e9dc786 100644 --- a/gtk2_ardour/step_editor.cc +++ b/gtk2_ardour/step_editor.cc @@ -115,13 +115,15 @@ StepEditor::prepare_step_edit_region () } else { +#warning NUTEMPO new tempo map API +#if 0 const Meter& m = _mtv.session()->tempo_map().meter_at_sample (step_edit_insert_position); double baf = max (0.0, _mtv.session()->tempo_map().beat_at_sample (step_edit_insert_position)); double next_bar_in_beats = baf + m.divisions_per_bar(); samplecnt_t next_bar_pos = _mtv.session()->tempo_map().sample_at_beat (next_bar_in_beats); samplecnt_t len = next_bar_pos - step_edit_insert_position; - step_edit_region = _mtv.add_region (step_edit_insert_position, len, true); +#endif RegionView* rv = _mtv.midi_view()->find_view (step_edit_region); step_edit_region_view = dynamic_cast(rv); @@ -135,16 +137,17 @@ StepEditor::reset_step_edit_beat_pos () assert (step_edit_region); assert (step_edit_region_view); - samplecnt_t samples_from_start = _editor.get_preferred_edit_position() - step_edit_region->position(); + const timepos_t ep = _editor.get_preferred_edit_position(); + timecnt_t distance_from_start (step_edit_region->nt_position().distance (ep)); - if (samples_from_start < 0) { + if (distance_from_start < 0) { /* this can happen with snap enabled, and the edit point == Playhead. we snap the position of the new region, and it can end up after the edit point. */ - samples_from_start = 0; + distance_from_start = 0; } - step_edit_beat_pos = step_edit_region_view->region_samples_to_region_beats (samples_from_start); + step_edit_beat_pos = distance_from_start.beats(); step_edit_region_view->move_step_edit_cursor (step_edit_beat_pos); } @@ -239,8 +242,7 @@ StepEditor::move_step_edit_beat_pos (Temporal::Beats beats) return; } if (beats > 0.0) { - step_edit_beat_pos = min (step_edit_beat_pos + beats, - step_edit_region_view->region_samples_to_region_beats (step_edit_region->length())); + step_edit_beat_pos = min (step_edit_beat_pos + beats, step_edit_region->nt_length().beats()); } else if (beats < 0.0) { if (-beats < step_edit_beat_pos) { step_edit_beat_pos += beats; // its negative, remember @@ -289,10 +291,10 @@ StepEditor::step_add_note (uint8_t channel, uint8_t pitch, uint8_t velocity, Tem /* make sure its visible on the horizontal axis */ - samplepos_t fpos = step_edit_region_view->region_beats_to_absolute_samples (step_edit_beat_pos + beat_duration); + timepos_t fpos = step_edit_region_view->region()->region_beats_to_absolute_time (step_edit_beat_pos + beat_duration); if (fpos >= (_editor.leftmost_sample() + _editor.current_page_samples())) { - _editor.reset_x_origin (fpos - (_editor.current_page_samples()/4)); + _editor.reset_x_origin (fpos.samples() - (_editor.current_page_samples()/4)); } Temporal::Beats at = step_edit_beat_pos; @@ -415,9 +417,10 @@ StepEditor::step_edit_bar_sync () return; } - samplepos_t fpos = step_edit_region_view->region_beats_to_absolute_samples (step_edit_beat_pos); - fpos = _session->tempo_map().round_to_bar (fpos, RoundUpAlways).sample; - step_edit_beat_pos = step_edit_region_view->region_samples_to_region_beats (fpos - step_edit_region->position()).round_up_to_beat(); + timepos_t fpos = step_edit_region_view->region()->region_beats_to_absolute_time (step_edit_beat_pos); +#warning NUTEMPO FIXME need way to get bbt from timepos_t + //fpos = fpos.bbt().round_up_to_bar (); + step_edit_beat_pos = step_edit_region->nt_position().distance (fpos).beats().round_up_to_beat(); step_edit_region_view->move_step_edit_cursor (step_edit_beat_pos); } diff --git a/gtk2_ardour/step_editor.h b/gtk2_ardour/step_editor.h index b0242fca16..c1cdeb416f 100644 --- a/gtk2_ardour/step_editor.h +++ b/gtk2_ardour/step_editor.h @@ -82,7 +82,7 @@ public: void stop_step_editing (); private: - ARDOUR::samplepos_t step_edit_insert_position; + Temporal::timepos_t step_edit_insert_position; Temporal::Beats step_edit_beat_pos; boost::shared_ptr step_edit_region; MidiRegionView* step_edit_region_view; diff --git a/gtk2_ardour/streamview.cc b/gtk2_ardour/streamview.cc index 6638b3462b..a7fae495d5 100644 --- a/gtk2_ardour/streamview.cc +++ b/gtk2_ardour/streamview.cc @@ -541,7 +541,7 @@ StreamView::set_selected_regionviews (RegionSelection& regions) * @param result Filled in with selectable things. */ void -StreamView::get_selectables (samplepos_t start, samplepos_t end, double top, double bottom, list& results, bool within) +StreamView::get_selectables (timepos_t const & start, timepos_t const & end, double top, double bottom, list& results, bool within) { if (_trackview.editor().internal_editing()) { return; // Don't select regions with an internal tool @@ -579,11 +579,11 @@ StreamView::get_selectables (samplepos_t start, samplepos_t end, double top, dou } if (within) { - if ((*i)->region()->coverage (start, end) == Evoral::OverlapExternal && layer_ok) { + if ((*i)->region()->coverage (start, end) == Temporal::OverlapExternal && layer_ok) { results.push_back (*i); } } else { - if ((*i)->region()->coverage (start, end) != Evoral::OverlapNone && layer_ok) { + if ((*i)->region()->coverage (start, end) != Temporal::OverlapNone && layer_ok) { results.push_back (*i); } } @@ -719,7 +719,7 @@ StreamView::setup_new_rec_layer_time (boost::shared_ptr region) top-layered region after the start of the region we are recording and make a note of it. */ if (_layer_display == Stacked) { - _new_rec_layer_time = _trackview.track()->playlist()->find_next_top_layer_position (region->position()); + _new_rec_layer_time = _trackview.track()->playlist()->find_next_top_layer_position (region->nt_position()).samples(); } else { _new_rec_layer_time = max_samplepos; } diff --git a/gtk2_ardour/streamview.h b/gtk2_ardour/streamview.h index 504c4b2c5f..4308825b43 100644 --- a/gtk2_ardour/streamview.h +++ b/gtk2_ardour/streamview.h @@ -104,7 +104,7 @@ public: void foreach_selected_regionview (sigc::slot slot); void set_selected_regionviews (RegionSelection&); - void get_selectables (ARDOUR::samplepos_t, ARDOUR::samplepos_t, double, double, std::list&, bool within = false); + void get_selectables (Temporal::timepos_t const &, Temporal::timepos_t const &, double, double, std::list&, bool within = false); void get_inverted_selectables (Selection&, std::list& results); void get_regionviews_at_or_after (ARDOUR::samplepos_t, RegionSelection&); diff --git a/gtk2_ardour/time_axis_view.h b/gtk2_ardour/time_axis_view.h index 04f8f25f43..5e5ff9dcc5 100644 --- a/gtk2_ardour/time_axis_view.h +++ b/gtk2_ardour/time_axis_view.h @@ -209,7 +209,7 @@ public: void order_selection_trims (ArdourCanvas::Item *item, bool put_start_on_top); - virtual void get_selectables (ARDOUR::samplepos_t, ARDOUR::samplepos_t, double, double, std::list&, bool within = false); + virtual void get_selectables (Temporal::timepos_t const &, Temporal::timepos_t const &, double, double, std::list&, bool within = false); virtual void get_inverted_selectables (Selection&, std::list& results); virtual void get_regionviews_at_or_after (ARDOUR::samplepos_t, RegionSelection&) {} diff --git a/gtk2_ardour/time_info_box.cc b/gtk2_ardour/time_info_box.cc index 627191bdac..39d25a9946 100644 --- a/gtk2_ardour/time_info_box.cc +++ b/gtk2_ardour/time_info_box.cc @@ -249,7 +249,7 @@ TimeInfoBox::region_selection_changed () void TimeInfoBox::selection_changed () { - samplepos_t s, e; + timepos_t s, e; Selection& selection (Editor::instance().get_selection()); region_property_connections.drop_connections(); @@ -282,8 +282,8 @@ TimeInfoBox::selection_changed () selection_length->set_off (true); } } else { - s = max_samplepos; - e = 0; + s = timepos_t::max (selection.points.front()->line().the_list()->time_domain()); + e = timepos_t::zero (s.time_domain()); for (PointSelection::iterator i = selection.points.begin(); i != selection.points.end(); ++i) { timepos_t const p = (*i)->line().session_position ((*i)->model ()); s = min (s, p); @@ -294,7 +294,8 @@ TimeInfoBox::selection_changed () selection_length->set_off (false); selection_start->set (s); selection_end->set (e); - selection_length->set (e, false, s); + selection_length->set_is_duration (true, s); + selection_length->set (e, false, timecnt_t (s)); } } else { /* this is more efficient than tracking changes per region in large selections */ @@ -319,14 +320,15 @@ TimeInfoBox::selection_changed () if (tact->get_active() && !selection.regions.empty()) { /* show selected regions */ - s = selection.regions.start(); - e = selection.regions.end_sample(); + s = selection.regions.start_time(); + e = selection.regions.end_time(); selection_start->set_off (false); selection_end->set_off (false); selection_length->set_off (false); selection_start->set (s); selection_end->set (e); - selection_length->set (e, false, s); + selection_length->set_is_duration (true, s); + selection_length->set (e, false, timecnt_t (s)); } else { selection_start->set_off (true); selection_end->set_off (true);