-Session::sample_to_timecode( nframes_t sample, Timecode::Time& timecode, bool use_offset, bool use_subframes ) const
-{
- nframes_t offset_sample;
-
- if (!use_offset) {
- offset_sample = sample;
- timecode.negative = false;
- } else {
- if (_timecode_offset_negative) {
- offset_sample = sample + _timecode_offset;
- timecode.negative = false;
- } else {
- if (sample < _timecode_offset) {
- offset_sample = (_timecode_offset - sample);
- timecode.negative = true;
- } else {
- offset_sample = sample - _timecode_offset;
- timecode.negative = false;
- }
- }
- }
-
- double timecode_frames_left_exact;
- double timecode_frames_fraction;
- uint32_t timecode_frames_left;
-
- // Extract whole hours. Do this to prevent rounding errors with
- // high sample numbers in the calculations that follow.
- timecode.hours = offset_sample / _frames_per_hour;
- offset_sample = offset_sample % _frames_per_hour;
-
- // Calculate exact number of (exceeding) timecode frames and fractional frames
- timecode_frames_left_exact = (double) offset_sample / _frames_per_timecode_frame;
- timecode_frames_fraction = timecode_frames_left_exact - floor( timecode_frames_left_exact );
- timecode.subframes = (int32_t) rint(timecode_frames_fraction * config.get_subframes_per_frame());
-
- // XXX Not sure if this is necessary anymore...
- if (timecode.subframes == config.get_subframes_per_frame()) {
- // This can happen with 24 fps (and 29.97 fps ?)
- timecode_frames_left_exact = ceil( timecode_frames_left_exact );
- timecode.subframes = 0;
- }
-
- // Extract hour-exceeding frames for minute, second and frame calculations
- timecode_frames_left = (uint32_t) floor (timecode_frames_left_exact);
-
- if (timecode_drop_frames()) {
- // See int32_t explanation in timecode_to_sample()...
-
- // Number of 10 minute chunks
- timecode.minutes = (timecode_frames_left / 17982) * 10; // exactly 17982 frames in 10 minutes
- // frames exceeding the nearest 10 minute barrier
- int32_t exceeding_df_frames = timecode_frames_left % 17982;
-
- // Find minutes exceeding the nearest 10 minute barrier
- if (exceeding_df_frames >= 1800) { // nothing to do if we are inside the first minute (0-1799)
- exceeding_df_frames -= 1800; // take away first minute (different number of frames than the others)
- int32_t extra_minutes_minus_1 = exceeding_df_frames / 1798; // how many minutes after the first one
- exceeding_df_frames -= extra_minutes_minus_1 * 1798; // take away the (extra) minutes just found
- timecode.minutes += extra_minutes_minus_1 + 1; // update with exceeding minutes
- }
-
- // Adjust frame numbering for dropped frames (frame 0 and 1 skipped at start of every minute except every 10th)
- if (timecode.minutes % 10) {
- // Every minute except every 10th
- if (exceeding_df_frames < 28) {
- // First second, frames 0 and 1 are skipped
- timecode.seconds = 0;
- timecode.frames = exceeding_df_frames + 2;
- } else {
- // All other seconds, all 30 frames are counted
- exceeding_df_frames -= 28;
- timecode.seconds = (exceeding_df_frames / 30) + 1;
- timecode.frames = exceeding_df_frames % 30;
- }
- } else {
- // Every 10th minute, all 30 frames counted in all seconds
- timecode.seconds = exceeding_df_frames / 30;
- timecode.frames = exceeding_df_frames % 30;
- }
- } else {
- // Non drop is easy
- timecode.minutes = timecode_frames_left / ((int32_t) rint (timecode_frames_per_second ()) * 60);
- timecode_frames_left = timecode_frames_left % ((int32_t) rint (timecode_frames_per_second ()) * 60);
- timecode.seconds = timecode_frames_left / (int32_t) rint(timecode_frames_per_second ());
- timecode.frames = timecode_frames_left % (int32_t) rint(timecode_frames_per_second ());
- }
-
- if (!use_subframes) {
- timecode.subframes = 0;
- }
- /* set frame rate and drop frame */
- timecode.rate = timecode_frames_per_second ();
- timecode.drop = timecode_drop_frames();
-}
-
-void
-Session::timecode_time (nframes_t when, Timecode::Time& timecode)