diff --git a/gtk2_ardour/audio_clock.cc b/gtk2_ardour/audio_clock.cc index f0ae7c76f4..4e29cc3c8b 100644 --- a/gtk2_ardour/audio_clock.cc +++ b/gtk2_ardour/audio_clock.cc @@ -1916,9 +1916,10 @@ AudioClock::bbt_frame_from_display (framepos_t pos) const if (is_duration) { any.bbt.bars++; any.bbt.beats++; - } - - return _session->convert_to_frames_at (pos, any); + return _session->any_duration_to_frames (pos, any); + } else { + return _session->convert_to_frames (any); + } } diff --git a/gtk2_ardour/export_format_dialog.cc b/gtk2_ardour/export_format_dialog.cc index ceea2b1082..89762be583 100644 --- a/gtk2_ardour/export_format_dialog.cc +++ b/gtk2_ardour/export_format_dialog.cc @@ -732,7 +732,7 @@ void ExportFormatDialog::update_clock (AudioClock & clock, ARDOUR::AnyTime const & time) { // TODO position - clock.set (_session->convert_to_frames_at (0, time), true); + clock.set (_session->convert_to_frames (time), true); AudioClock::Mode mode(AudioClock::Timecode); diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index 393c9d1356..7abeabd647 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -460,7 +460,8 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi void timecode_duration (framecnt_t, Timecode::Time&) const; void timecode_duration_string (char *, framecnt_t) const; - framecnt_t convert_to_frames_at (framepos_t position, AnyTime const &); + framecnt_t convert_to_frames (AnyTime const & position); + framecnt_t any_duration_to_frames (framepos_t position, AnyTime const & duration); static PBD::Signal1 StartTimeChanged; static PBD::Signal1 EndTimeChanged; diff --git a/libs/ardour/export_format_specification.cc b/libs/ardour/export_format_specification.cc index b85d060e2f..bf2585a281 100644 --- a/libs/ardour/export_format_specification.cc +++ b/libs/ardour/export_format_specification.cc @@ -49,7 +49,7 @@ ExportFormatSpecification::Time::operator= (AnyTime const & other) framecnt_t ExportFormatSpecification::Time::get_frames_at (framepos_t position, framecnt_t target_rate) const { - framecnt_t duration = session.convert_to_frames_at (position, *this); + framecnt_t duration = session.any_duration_to_frames (position, *this); return ((double) target_rate / session.frame_rate()) * duration + 0.5; } diff --git a/libs/ardour/session_time.cc b/libs/ardour/session_time.cc index 7bd0ad1164..d9c612fbee 100644 --- a/libs/ardour/session_time.cc +++ b/libs/ardour/session_time.cc @@ -547,21 +547,21 @@ Session::jack_timebase_callback (jack_transport_state_t /*state*/, } ARDOUR::framecnt_t -Session::convert_to_frames_at (framepos_t /*position*/, AnyTime const & any) +Session::convert_to_frames (AnyTime const & position) { double secs; - switch (any.type) { + switch (position.type) { case AnyTime::BBT: - return _tempo_map->frame_time (any.bbt); + return _tempo_map->frame_time (position.bbt); break; case AnyTime::Timecode: /* XXX need to handle negative values */ - secs = any.timecode.hours * 60 * 60; - secs += any.timecode.minutes * 60; - secs += any.timecode.seconds; - secs += any.timecode.frames / timecode_frames_per_second(); + secs = position.timecode.hours * 60 * 60; + secs += position.timecode.minutes * 60; + secs += position.timecode.seconds; + secs += position.timecode.frames / timecode_frames_per_second(); if (config.get_timecode_offset_negative()) { return (framecnt_t) floor (secs * frame_rate()) - config.get_timecode_offset(); } else { @@ -570,13 +570,48 @@ Session::convert_to_frames_at (framepos_t /*position*/, AnyTime const & any) break; case AnyTime::Seconds: - return (framecnt_t) floor (any.seconds * frame_rate()); + return (framecnt_t) floor (position.seconds * frame_rate()); break; case AnyTime::Frames: - return any.frames; + return position.frames; break; } - return any.frames; + return position.frames; +} + +ARDOUR::framecnt_t +Session::any_duration_to_frames (framepos_t position, AnyTime const & duration) +{ + double secs; + + switch (duration.type) { + case AnyTime::BBT: + return (framecnt_t) ( _tempo_map->framepos_plus_bbt (position, duration.bbt) - position); + break; + + case AnyTime::Timecode: + /* XXX need to handle negative values */ + secs = duration.timecode.hours * 60 * 60; + secs += duration.timecode.minutes * 60; + secs += duration.timecode.seconds; + secs += duration.timecode.frames / timecode_frames_per_second(); + if (config.get_timecode_offset_negative()) { + return (framecnt_t) floor (secs * frame_rate()) - config.get_timecode_offset(); + } else { + return (framecnt_t) floor (secs * frame_rate()) + config.get_timecode_offset(); + } + break; + + case AnyTime::Seconds: + return (framecnt_t) floor (duration.seconds * frame_rate()); + break; + + case AnyTime::Frames: + return duration.frames; + break; + } + + return duration.frames; }