X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Fsession_time.cc;h=e9c6d23a97b6e1b9f34a997903c46bab2e8fa0fe;hb=4250940ad83200e065b966d0646c75a48bb0f73d;hp=9a1507831cb178719d033d1fd7dcc687f2d1cdc2;hpb=4a17dd8fb619e7c8d25843c79a662f29b90ce83c;p=ardour.git diff --git a/libs/ardour/session_time.cc b/libs/ardour/session_time.cc index 9a1507831c..e9c6d23a97 100644 --- a/libs/ardour/session_time.cc +++ b/libs/ardour/session_time.cc @@ -35,7 +35,7 @@ #include "ardour/session.h" #include "ardour/tempo.h" -#include "i18n.h" +#include "pbd/i18n.h" using namespace std; using namespace ARDOUR; @@ -44,14 +44,14 @@ using namespace PBD; /* BBT TIME*/ void -Session::bbt_time (framepos_t when, Timecode::BBT_Time& bbt) +Session::bbt_time (samplepos_t when, Timecode::BBT_Time& bbt) { - _tempo_map->bbt_time (when, bbt); + bbt = _tempo_map->bbt_at_sample (when); } /* Timecode TIME */ -float +double Session::timecode_frames_per_second() const { return Timecode::timecode_to_frames_per_second (config.get_timecode_format()); @@ -66,12 +66,12 @@ Session::timecode_drop_frames() const void Session::sync_time_vars () { - _current_frame_rate = (framecnt_t) round (_base_frame_rate * (1.0 + (config.get_video_pullup()/100.0))); - _frames_per_timecode_frame = (double) _current_frame_rate / (double) timecode_frames_per_second(); + _current_sample_rate = (samplecnt_t) round (_nominal_sample_rate * (1.0 + (config.get_video_pullup()/100.0))); + _samples_per_timecode_frame = (double) _current_sample_rate / (double) timecode_frames_per_second(); if (timecode_drop_frames()) { - _frames_per_hour = (int32_t)(107892 * _frames_per_timecode_frame); + _frames_per_hour = (int32_t)(107892 * _samples_per_timecode_frame); } else { - _frames_per_hour = (int32_t)(3600 * rint(timecode_frames_per_second()) * _frames_per_timecode_frame); + _frames_per_hour = (int32_t)(3600 * rint(timecode_frames_per_second()) * _samples_per_timecode_frame); } _timecode_frames_per_hour = rint(timecode_frames_per_second() * 3600.0); @@ -95,16 +95,17 @@ Session::sync_time_vars () } break; }; + ltc_tx_parse_offset(); } void -Session::timecode_to_sample( Timecode::Time& timecode, framepos_t& sample, bool use_offset, bool use_subframes ) const +Session::timecode_to_sample( Timecode::Time& timecode, samplepos_t& sample, bool use_offset, bool use_subframes ) const { timecode.rate = timecode_frames_per_second(); Timecode::timecode_to_sample( timecode, sample, use_offset, use_subframes, - _current_frame_rate, + _current_sample_rate, config.get_subframes_per_frame(), config.get_timecode_offset_negative(), config.get_timecode_offset() ); @@ -112,14 +113,14 @@ Session::timecode_to_sample( Timecode::Time& timecode, framepos_t& sample, bool } void -Session::sample_to_timecode (framepos_t sample, Timecode::Time& timecode, bool use_offset, bool use_subframes ) const +Session::sample_to_timecode (samplepos_t sample, Timecode::Time& timecode, bool use_offset, bool use_subframes ) const { Timecode::sample_to_timecode ( sample, timecode, use_offset, use_subframes, timecode_frames_per_second(), timecode_drop_frames(), - double(_current_frame_rate), + double(_current_sample_rate), config.get_subframes_per_frame(), config.get_timecode_offset_negative(), config.get_timecode_offset() @@ -127,7 +128,7 @@ Session::sample_to_timecode (framepos_t sample, Timecode::Time& timecode, bool u } void -Session::timecode_time (framepos_t when, Timecode::Time& timecode) +Session::timecode_time (samplepos_t when, Timecode::Time& timecode) { if (last_timecode_valid && when == last_timecode_when) { timecode = last_timecode; @@ -142,7 +143,7 @@ Session::timecode_time (framepos_t when, Timecode::Time& timecode) } void -Session::timecode_time_subframes (framepos_t when, Timecode::Time& timecode) +Session::timecode_time_subframes (samplepos_t when, Timecode::Time& timecode) { if (last_timecode_valid && when == last_timecode_when) { timecode = last_timecode; @@ -157,53 +158,59 @@ Session::timecode_time_subframes (framepos_t when, Timecode::Time& timecode) } void -Session::timecode_duration (framecnt_t when, Timecode::Time& timecode) const +Session::timecode_duration (samplecnt_t when, Timecode::Time& timecode) const { this->sample_to_timecode( when, timecode, false /* use_offset */, true /* use_subframes */ ); } void -Session::timecode_duration_string (char* buf, framepos_t when) const +Session::timecode_duration_string (char* buf, size_t len, samplepos_t when) const { Timecode::Time timecode; timecode_duration (when, timecode); - snprintf (buf, sizeof (buf), "%02" PRIu32 ":%02" PRIu32 ":%02" PRIu32 ":%02" PRIu32, timecode.hours, timecode.minutes, timecode.seconds, timecode.frames); + snprintf (buf, len, "%02" PRIu32 ":%02" PRIu32 ":%02" PRIu32 ":%02" PRIu32, timecode.hours, timecode.minutes, timecode.seconds, timecode.frames); } void Session::timecode_time (Timecode::Time &t) { - timecode_time (_transport_frame, t); + timecode_time (_transport_sample, t); } int -Session::jack_sync_callback (jack_transport_state_t state, - jack_position_t* pos) +Session::backend_sync_callback (TransportState state, samplepos_t pos) { - bool slave = synced_to_jack(); + bool slave = synced_to_engine(); + // cerr << "Session::backend_sync_callback() _transport_sample: " << _transport_sample << " pos: " << pos << " audible_sample: " << audible_sample() << endl; + + if (slave) { + // cerr << "Session::backend_sync_callback() emitting Located()" << endl; + Located (); /* EMIT SIGNAL */ + } switch (state) { - case JackTransportStopped: - if (slave && _transport_frame != pos->frame && post_transport_work() == 0) { - request_locate (pos->frame, false); - // cerr << "SYNC: stopped, locate to " << pos->frame << " from " << _transport_frame << endl; + case TransportStopped: + if (slave && _transport_sample != pos && post_transport_work() == 0) { + request_locate (pos, false); + // cerr << "SYNC: stopped, locate to " << pos << " from " << _transport_sample << endl; return false; } else { + // cerr << "SYNC: stopped, nothing to do" << endl; return true; } - case JackTransportStarting: - // cerr << "SYNC: starting @ " << pos->frame << " a@ " << _transport_frame << " our work = " << post_transport_work() << " pos matches ? " << (_transport_frame == pos->frame) << endl; + case TransportStarting: + // cerr << "SYNC: starting @ " << pos << " a@ " << _transport_sample << " our work = " << post_transport_work() << " pos matches ? " << (_transport_sample == pos) << endl; if (slave) { - return _transport_frame == pos->frame && post_transport_work() == 0; + return _transport_sample == pos && post_transport_work() == 0; } else { return true; } break; - case JackTransportRolling: + case TransportRolling: // cerr << "SYNC: rolling slave = " << slave << endl; if (slave) { start_transport (); @@ -211,106 +218,22 @@ Session::jack_sync_callback (jack_transport_state_t state, break; default: - error << string_compose (_("Unknown JACK transport state %1 in sync callback"), state) + error << string_compose (_("Unknown transport state %1 in sync callback"), state) << endmsg; } return true; } -void -Session::jack_timebase_callback (jack_transport_state_t /*state*/, - pframes_t /*nframes*/, - jack_position_t* pos, - int /*new_position*/) -{ - Timecode::BBT_Time bbt; - - if (pos->frame != _transport_frame) { - cerr << "ARDOUR says " << _transport_frame << " JACK says " << pos->frame << endl; - } - - /* BBT info */ - - if (_tempo_map) { - - TempoMetric metric (_tempo_map->metric_at (_transport_frame)); - - try { - _tempo_map->bbt_time_rt (_transport_frame, bbt); - - pos->bar = bbt.bars; - pos->beat = bbt.beats; - pos->tick = bbt.ticks; - - // XXX still need to set bar_start_tick - - pos->beats_per_bar = metric.meter().divisions_per_bar(); - pos->beat_type = metric.meter().note_divisor(); - pos->ticks_per_beat = Timecode::BBT_Time::ticks_per_beat; - pos->beats_per_minute = metric.tempo().beats_per_minute(); - - pos->valid = jack_position_bits_t (pos->valid | JackPositionBBT); - - } catch (...) { - /* no message */ - } - } - -#ifdef HAVE_JACK_VIDEO_SUPPORT - //poke audio video ratio so Ardour can track Video Sync - pos->audio_frames_per_video_frame = frame_rate() / timecode_frames_per_second(); - pos->valid = jack_position_bits_t (pos->valid | JackAudioVideoRatio); -#endif - -#if 0 - /* Timecode info */ - - pos->timecode_offset = config.get_timecode_offset(); - t.timecode_frame_rate = timecode_frames_per_second(); - pos->valid = jack_position_bits_t (pos->valid | JackPositionTimecode; - - if (_transport_speed) { - - if (play_loop) { - - Location* location = _locations.auto_loop_location(); - - if (location) { - - t.transport_state = JackTransportLooping; - t.loop_start = location->start(); - t.loop_end = location->end(); - t.valid = jack_transport_bits_t (t.valid | JackTransportLoop); - - } else { - - t.loop_start = 0; - t.loop_end = 0; - t.transport_state = JackTransportRolling; - - } - - } else { - - t.loop_start = 0; - t.loop_end = 0; - t.transport_state = JackTransportRolling; - - } - - } -#endif -} -ARDOUR::framecnt_t -Session::convert_to_frames (AnyTime const & position) +ARDOUR::samplecnt_t +Session::convert_to_samples (AnyTime const & position) { double secs; switch (position.type) { case AnyTime::BBT: - return _tempo_map->frame_time (position.bbt); + return _tempo_map->sample_at_bbt (position.bbt); break; case AnyTime::Timecode: @@ -320,32 +243,32 @@ Session::convert_to_frames (AnyTime const & position) 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(); + return (samplecnt_t) floor (secs * sample_rate()) - config.get_timecode_offset(); } else { - return (framecnt_t) floor (secs * frame_rate()) + config.get_timecode_offset(); + return (samplecnt_t) floor (secs * sample_rate()) + config.get_timecode_offset(); } break; case AnyTime::Seconds: - return (framecnt_t) floor (position.seconds * frame_rate()); + return (samplecnt_t) floor (position.seconds * sample_rate()); break; - case AnyTime::Frames: - return position.frames; + case AnyTime::Samples: + return position.samples; break; } - return position.frames; + return position.samples; } -ARDOUR::framecnt_t -Session::any_duration_to_frames (framepos_t position, AnyTime const & duration) +ARDOUR::samplecnt_t +Session::any_duration_to_samples (samplepos_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); + return (samplecnt_t) ( _tempo_map->samplepos_plus_bbt (position, duration.bbt) - position); break; case AnyTime::Timecode: @@ -355,20 +278,20 @@ Session::any_duration_to_frames (framepos_t position, AnyTime const & duration) 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(); + return (samplecnt_t) floor (secs * sample_rate()) - config.get_timecode_offset(); } else { - return (framecnt_t) floor (secs * frame_rate()) + config.get_timecode_offset(); + return (samplecnt_t) floor (secs * sample_rate()) + config.get_timecode_offset(); } break; case AnyTime::Seconds: - return (framecnt_t) floor (duration.seconds * frame_rate()); + return (samplecnt_t) floor (duration.seconds * sample_rate()); break; - case AnyTime::Frames: - return duration.frames; + case AnyTime::Samples: + return duration.samples; break; } - return duration.frames; + return duration.samples; }