/* BBT TIME*/
void
-Session::bbt_time (nframes_t when, BBT_Time& bbt)
+Session::bbt_time (framepos_t when, Timecode::BBT_Time& bbt)
{
_tempo_map->bbt_time (when, bbt);
}
void
Session::sync_time_vars ()
{
- _current_frame_rate = (nframes_t) round (_base_frame_rate * (1.0 + (config.get_video_pullup()/100.0)));
+ _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();
if (timecode_drop_frames()) {
_frames_per_hour = (int32_t)(107892 * _frames_per_timecode_frame);
} else {
_frames_per_hour = (int32_t)(3600 * rint(timecode_frames_per_second()) * _frames_per_timecode_frame);
}
- _timecode_frames_per_hour = (nframes_t)rint(timecode_frames_per_second() * 3600.0);
+ _timecode_frames_per_hour = rint(timecode_frames_per_second() * 3600.0);
last_timecode_valid = false;
// timecode type bits are the middle two in the upper nibble
}
void
-Session::set_timecode_offset (nframes_t off)
-{
- _timecode_offset = off;
- last_timecode_valid = false;
-
- TimecodeOffsetChanged (); /* EMIT SIGNAL */
-}
-
-void
-Session::set_timecode_offset_negative (bool neg)
-{
- _timecode_offset_negative = neg;
- last_timecode_valid = false;
-
- TimecodeOffsetChanged (); /* EMIT SIGNAL */
-}
-
-void
-Session::timecode_to_sample( Timecode::Time& timecode, nframes_t& sample, bool use_offset, bool use_subframes ) const
+Session::timecode_to_sample( Timecode::Time& timecode, framepos_t& sample, bool use_offset, bool use_subframes ) const
{
if (timecode.drop) {
// Per Sigmond <per@sigmond.no>
// Samples inside time dividable by 10 minutes (real time accurate)
- nframes_t base_samples = (nframes_t) (((timecode.hours * 107892) + ((timecode.minutes / 10) * 17982)) * _frames_per_timecode_frame);
+ framecnt_t base_samples = (framecnt_t) (((timecode.hours * 107892) + ((timecode.minutes / 10) * 17982)) * _frames_per_timecode_frame);
// Samples inside time exceeding the nearest 10 minutes (always offset, see above)
int32_t exceeding_df_minutes = timecode.minutes % 10;
int32_t exceeding_df_seconds = (exceeding_df_minutes * 60) + timecode.seconds;
int32_t exceeding_df_frames = (30 * exceeding_df_seconds) + timecode.frames - (2 * exceeding_df_minutes);
- nframes_t exceeding_samples = (nframes_t) rint(exceeding_df_frames * _frames_per_timecode_frame);
+ framecnt_t exceeding_samples = (framecnt_t) rint(exceeding_df_frames * _frames_per_timecode_frame);
sample = base_samples + exceeding_samples;
} else {
/*
frame_rate() in the non-integer Timecode rate case.
*/
- sample = (nframes_t)rint((((timecode.hours * 60 * 60) + (timecode.minutes * 60) + timecode.seconds) * (rint(timecode.rate) * _frames_per_timecode_frame)) + (timecode.frames * _frames_per_timecode_frame));
+ sample = (framecnt_t)rint((((timecode.hours * 60 * 60) + (timecode.minutes * 60) + timecode.seconds) * (rint(timecode.rate) * _frames_per_timecode_frame)) + (timecode.frames * _frames_per_timecode_frame));
}
if (use_subframes) {
}
if (use_offset) {
- if (timecode_offset_negative()) {
- if (sample >= timecode_offset()) {
- sample -= timecode_offset();
+ if (config.get_timecode_offset_negative()) {
+ if (sample >= config.get_timecode_offset()) {
+ sample -= config.get_timecode_offset();
} else {
/* Prevent song-time from becoming negative */
sample = 0;
}
} else {
if (timecode.negative) {
- if (sample <= timecode_offset()) {
- sample = timecode_offset() - sample;
+ if (sample <= config.get_timecode_offset()) {
+ sample = config.get_timecode_offset() - sample;
} else {
sample = 0;
}
} else {
- sample += timecode_offset();
+ sample += config.get_timecode_offset();
}
}
}
void
-Session::sample_to_timecode( nframes_t sample, Timecode::Time& timecode, bool use_offset, bool use_subframes ) const
+Session::sample_to_timecode (framepos_t sample, Timecode::Time& timecode, bool use_offset, bool use_subframes ) const
{
- nframes_t offset_sample;
+ framepos_t offset_sample;
if (!use_offset) {
offset_sample = sample;
timecode.negative = false;
} else {
- if (_timecode_offset_negative) {
- offset_sample = sample + _timecode_offset;
+ if (config.get_timecode_offset_negative()) {
+ offset_sample = sample + config.get_timecode_offset ();
timecode.negative = false;
} else {
- if (sample < _timecode_offset) {
- offset_sample = (_timecode_offset - sample);
+ if (sample < config.get_timecode_offset()) {
+ offset_sample = (config.get_timecode_offset() - sample);
timecode.negative = true;
} else {
- offset_sample = sample - _timecode_offset;
+ offset_sample = sample - config.get_timecode_offset();
timecode.negative = false;
}
}
}
void
-Session::timecode_time (nframes_t when, Timecode::Time& timecode)
+Session::timecode_time (framepos_t when, Timecode::Time& timecode)
{
if (last_timecode_valid && when == last_timecode_when) {
timecode = last_timecode;
}
void
-Session::timecode_time_subframes (nframes_t when, Timecode::Time& timecode)
+Session::timecode_time_subframes (framepos_t when, Timecode::Time& timecode)
{
if (last_timecode_valid && when == last_timecode_when) {
timecode = last_timecode;
}
void
-Session::timecode_duration (nframes_t when, Timecode::Time& timecode) const
+Session::timecode_duration (framecnt_t when, Timecode::Time& timecode) const
{
sample_to_timecode( when, timecode, false /* use_offset */, true /* use_subframes */ );
}
void
-Session::timecode_duration_string (char* buf, nframes_t when) const
+Session::timecode_duration_string (char* buf, framepos_t when) const
{
Timecode::Time timecode;
void
Session::jack_timebase_callback (jack_transport_state_t /*state*/,
- nframes_t /*nframes*/,
+ pframes_t /*nframes*/,
jack_position_t* pos,
int /*new_position*/)
{
- BBT_Time bbt;
+ Timecode::BBT_Time bbt;
- /* frame info */
-
- pos->frame = _transport_frame;
- pos->valid = JackPositionTimecode;
+ if (pos->frame != _transport_frame) {
+ cerr << "ARDOUR says " << _transport_frame << " JACK says " << pos->frame << endl;
+ }
/* BBT info */
pos->beats_per_bar = metric.meter().beats_per_bar();
pos->beat_type = metric.meter().note_divisor();
- pos->ticks_per_beat = Meter::ticks_per_beat;
+ 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);
#if 0
/* Timecode info */
- t.timecode_offset = _timecode_offset;
+ 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) {
}
}
-
#endif
}
-ARDOUR::nframes_t
-Session::convert_to_frames_at (nframes_t /*position*/, AnyTime const & any)
+ARDOUR::framecnt_t
+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();
- if (_timecode_offset_negative)
- {
- return (nframes_t) floor (secs * frame_rate()) - _timecode_offset;
+ 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 {
+ return (framecnt_t) floor (secs * frame_rate()) + config.get_timecode_offset();
}
- else
- {
- return (nframes_t) floor (secs * frame_rate()) + _timecode_offset;
+ break;
+
+ case AnyTime::Seconds:
+ return (framecnt_t) floor (position.seconds * frame_rate());
+ break;
+
+ case AnyTime::Frames:
+ return position.frames;
+ break;
+ }
+
+ 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 (nframes_t) floor (any.seconds * frame_rate());
+ return (framecnt_t) floor (duration.seconds * frame_rate());
break;
case AnyTime::Frames:
- return any.frames;
+ return duration.frames;
break;
}
- return any.frames;
+ return duration.frames;
}