2 Copyright (C) 1999 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include <cstdio> // for sprintf
23 #include "pbd/convert.h"
24 #include "pbd/enumwriter.h"
26 #include <gtkmm/style.h>
28 #include "gtkmm2ext/cairocell.h"
29 #include <gtkmm2ext/utils.h>
31 #include "ardour/ardour.h"
32 #include "ardour/session.h"
33 #include "ardour/tempo.h"
34 #include "ardour/profile.h"
35 #include <sigc++/bind.h>
37 #include "ardour_ui.h"
38 #include "audio_clock.h"
41 #include "gui_thread.h"
44 using namespace ARDOUR;
49 using Gtkmm2ext::Keyboard;
54 sigc::signal<void> AudioClock::ModeChanged;
55 vector<AudioClock*> AudioClock::clocks;
57 uint32_t AudioClock::field_length[] = {
58 2, /* Timecode_Hours */
59 2, /* Timecode_Minutes */
60 2, /* Timecode_Seconds */
61 2, /* Timecode_Frames */
65 3, /* MS_Milliseconds */
72 AudioClock::AudioClock (const string& clock_name, bool transient, const string& widget_name,
73 bool allow_edit, bool follows_playhead, bool duration, bool with_info)
75 , is_transient (transient)
76 , is_duration (duration)
77 , editable (allow_edit)
78 , _follows_playhead (follows_playhead)
79 , supplemental_left (0)
80 , supplemental_right (0)
82 , _canonical_time_is_displayed (true)
95 ms_last_millisecs = 99999;
97 last_negative = false;
104 bbt_reference_time = -1;
105 editing_field = (Field) 0;
107 /* basic per-mode editable text "arrays" */
109 display = new CairoEditableText ();
111 _fixed_cells[Colon1] = new CairoCharCell (Colon1, ':');
112 _fixed_cells[Colon2] = new CairoCharCell (Colon2, ':');
113 _fixed_cells[Colon3] = new CairoCharCell (Colon3, ':');
114 _fixed_cells[Bar1] = new CairoCharCell (Bar1, '|');
115 _fixed_cells[Bar2] = new CairoCharCell (Bar2, '|');
117 // add an extra character for the negative sign
118 _text_cells[Timecode_Hours] = new CairoTextCell (Timecode_Hours, field_length[Timecode_Hours] + 1);
119 _text_cells[Timecode_Minutes] = new CairoTextCell (Timecode_Minutes, field_length[Timecode_Minutes]);
120 _text_cells[Timecode_Seconds] = new CairoTextCell (Timecode_Seconds, field_length[Timecode_Seconds]);
121 _text_cells[Timecode_Frames] = new CairoTextCell (Timecode_Frames, field_length[Timecode_Frames]);
123 /* Minutes/Seconds */
125 _text_cells[MS_Hours] = new CairoTextCell (MS_Hours, field_length[MS_Hours]);
126 _text_cells[MS_Minutes] = new CairoTextCell (MS_Minutes, field_length[MS_Minutes]);
127 _text_cells[MS_Seconds] = new CairoTextCell (MS_Seconds, field_length[MS_Seconds]);
128 _text_cells[MS_Milliseconds] = new CairoTextCell (MS_Milliseconds, field_length[MS_Milliseconds]);
130 /* Beats/Bars/Ticks */
132 _text_cells[Bars] = new CairoTextCell (Bars, field_length[Bars]);
133 _text_cells[Beats] = new CairoTextCell (Beats, field_length[Beats]);
134 _text_cells[Ticks] = new CairoTextCell (Ticks, field_length[Ticks]);
138 _text_cells[AudioFrames] = new CairoTextCell (AudioFrames, field_length[AudioFrames]);
140 set_homogeneous (false);
144 supplemental_left = new CairoEditableText ();
145 supplemental_right = new CairoEditableText ();
147 /* field lengths of these cells will be set dynamically by ::set_mode()
150 _text_cells[LowerLeft1] = new CairoTextCell (LowerLeft1, 0);
151 _text_cells[LowerLeft2] = new CairoTextCell (LowerLeft2, 0);
152 _text_cells[LowerRight1] = new CairoTextCell (LowerRight1, 0);
153 _text_cells[LowerRight2] = new CairoTextCell (LowerRight2, 0);
155 bottom.set_spacing (1);
156 bottom.set_homogeneous (false);
157 bottom.pack_start (*supplemental_left, true, true);
158 bottom.pack_start (*supplemental_right, true, true);
160 top.pack_start (*display, true, true);
164 pack_start (top, true, true);
165 pack_start (bottom, true, true);
167 pack_start (*display, true, true);
172 set_widget_name (widget_name);
174 _mode = BBT; /* lie to force mode switch */
176 set (last_when, true);
179 clocks.push_back (this);
183 AudioClock::~AudioClock ()
185 /* these are not manage()'d, so that we can add/remove
186 them from containers as necessary.
189 delete supplemental_left;
190 delete supplemental_right;
191 /* XXX need to delete all cells too */
195 AudioClock::set_widget_name (const string& name)
197 Widget::set_name (name);
203 AudioClock::set_theme ()
205 Glib::RefPtr<Gtk::Style> style = get_style ();
212 Pango::FontDescription font;
214 if (!is_realized()) {
215 font = get_font_for_style (get_name());
217 font = style->get_font();
220 display->set_font (font);
222 /* propagate font style,but smaller, into supplemental text */
223 if (supplemental_left) {
224 boost::shared_ptr<CairoFontDescription> smaller_font (new CairoFontDescription (*display->font().get()));
225 smaller_font->set_size (12);
226 supplemental_right->set_font (smaller_font);
227 supplemental_left->set_font (smaller_font);
230 Gdk::Color bg = style->get_base (Gtk::STATE_NORMAL);
231 Gdk::Color fg = style->get_text (Gtk::STATE_NORMAL);
232 Gdk::Color eg = style->get_text (Gtk::STATE_ACTIVE);
235 g = bg.get_green_p ();
236 b = bg.get_blue_p ();
239 display->set_bg (r, g, b, a);
241 if (supplemental_right) {
242 supplemental_right->set_bg (r,g,b,a);
243 supplemental_left->set_bg (r,g,b,a);
247 g = fg.get_green_p ();
248 b = fg.get_blue_p ();
251 display->set_colors (r, g, b, a);
253 if (supplemental_right) {
254 supplemental_right->set_colors (r,g,b,a);
255 supplemental_left->set_colors (r,g,b,a);
259 g = eg.get_green_p ();
260 b = eg.get_blue_p ();
263 display->set_edit_colors (r, g, b, a);
265 if (supplemental_right) {
266 supplemental_right->set_edit_colors (r,g,b,a);
267 supplemental_left->set_edit_colors (r,g,b,a);
279 AudioClock::end_edit ()
281 display->stop_editing ();
282 editing_field = (Field) 0;
285 /* move focus back to the default widget in the top level window */
287 Keyboard::magic_widget_drop_focus ();
289 Widget* top = get_toplevel();
291 if (top->is_toplevel ()) {
292 Window* win = dynamic_cast<Window*> (top);
298 AudioClock::on_realize ()
302 /* styles are not available until the widgets are bound to a window */
308 AudioClock::set (framepos_t when, bool force, framecnt_t offset, char which)
310 if ((!force && !is_visible()) || _session == 0) {
314 bool const pdelta = Config->get_primary_clock_delta_edit_cursor ();
315 bool const sdelta = Config->get_secondary_clock_delta_edit_cursor ();
317 if (offset && which == 'p' && pdelta) {
318 when = (when > offset) ? when - offset : offset - when;
319 } else if (offset && which == 's' && sdelta) {
320 when = (when > offset) ? when - offset : offset - when;
323 if (when == last_when && !force) {
327 if (which == 'p' && pdelta && !last_pdelta) {
328 set_widget_name("TransportClockDisplayDelta");
330 } else if (which == 'p' && !pdelta && last_pdelta) {
331 set_widget_name("TransportClockDisplay");
333 } else if (which == 's' && sdelta && !last_sdelta) {
334 set_widget_name("SecondaryClockDisplayDelta");
336 } else if (which == 's' && !sdelta && last_sdelta) {
337 set_widget_name("SecondaryClockDisplay");
343 set_timecode (when, force);
347 set_bbt (when, force);
351 set_minsec (when, force);
355 set_frames (when, force);
364 /* we're setting the time from a frames value, so keep it as the canonical value */
365 _canonical_time = when;
366 _canonical_time_is_displayed = false;
370 AudioClock::session_configuration_changed (std::string p)
372 if (p != "timecode-offset" && p != "timecode-offset-negative") {
381 current = current_duration ();
383 current = current_time ();
393 AudioClock::set_frames (framepos_t when, bool /*force*/)
396 snprintf (buf, sizeof (buf), "%" PRId64, when);
398 display->set_text (_text_cells[AudioFrames], buf);
400 if (supplemental_left) {
401 framecnt_t rate = _session->frame_rate();
403 if (fmod (rate, 1000.0) == 0.000) {
404 sprintf (buf, "%" PRId64 "K", rate/1000);
406 sprintf (buf, "%" PRId64, rate);
409 supplemental_left->set_text (_text_cells[LowerLeft2], buf);
411 float vid_pullup = _session->config.get_video_pullup();
413 if (vid_pullup == 0.0) {
414 supplemental_right->set_text (_text_cells[LowerRight2], _("none"));
416 sprintf (buf, "%-6.4f", vid_pullup);
417 supplemental_right->set_text (_text_cells[LowerRight2], buf);
423 AudioClock::set_minsec (framepos_t when, bool force)
433 hrs = (int) floor (left / (_session->frame_rate() * 60.0f * 60.0f));
434 left -= (framecnt_t) floor (hrs * _session->frame_rate() * 60.0f * 60.0f);
435 mins = (int) floor (left / (_session->frame_rate() * 60.0f));
436 left -= (framecnt_t) floor (mins * _session->frame_rate() * 60.0f);
437 secs = (int) floor (left / (float) _session->frame_rate());
438 left -= (framecnt_t) floor (secs * _session->frame_rate());
439 millisecs = floor (left * 1000.0 / (float) _session->frame_rate());
441 if (force || hrs != ms_last_hrs) {
442 sprintf (buf, "%02d", hrs);
443 display->set_text (_text_cells[MS_Hours], buf);
447 if (force || mins != ms_last_mins) {
448 sprintf (buf, "%02d", mins);
449 display->set_text (_text_cells[MS_Minutes], buf);
453 if (force || secs != ms_last_secs) {
454 sprintf (buf, "%02d", secs);
455 display->set_text (_text_cells[MS_Seconds], buf);
459 if (force || millisecs != ms_last_millisecs) {
460 sprintf (buf, "%03d", millisecs);
461 display->set_text (_text_cells[MS_Milliseconds], buf);
462 ms_last_millisecs = millisecs;
467 AudioClock::set_timecode (framepos_t when, bool force)
473 _session->timecode_duration (when, TC);
475 _session->timecode_time (when, TC);
478 if (force || TC.hours != last_hrs || TC.negative != last_negative) {
480 sprintf (buf, "-%0*" PRIu32, field_length[Timecode_Hours], TC.hours);
482 sprintf (buf, " %0*" PRIu32, field_length[Timecode_Hours], TC.hours);
484 display->set_text (_text_cells[Timecode_Hours], buf);
486 last_negative = TC.negative;
489 if (force || TC.minutes != last_mins) {
490 sprintf (buf, "%0*" PRIu32, field_length[Timecode_Minutes], TC.minutes);
491 display->set_text (_text_cells[Timecode_Minutes], buf);
492 last_mins = TC.minutes;
495 if (force || TC.seconds != last_secs) {
496 sprintf (buf, "%0*" PRIu32, field_length[Timecode_Seconds], TC.seconds);
497 display->set_text (_text_cells[Timecode_Seconds], buf);
498 last_secs = TC.seconds;
501 if (force || TC.frames != last_frames) {
502 sprintf (buf, "%0*" PRIu32, field_length[Timecode_Frames], TC.frames);
503 display->set_text (_text_cells[Timecode_Frames], buf);
504 last_frames = TC.frames;
507 if (supplemental_right) {
508 double timecode_frames = _session->timecode_frames_per_second();
511 if ((fabs(timecode_frames - 29.97) < 0.0001) || timecode_frames == 30) {
512 if (_session->timecode_drop_frames()) {
519 if (fmod(timecode_frames, 1.0) == 0.0) {
520 sprintf (buf, "%u %s", int (timecode_frames), (drop ? "D" : ""));
522 sprintf (buf, "%.2f %s", timecode_frames, (drop ? "D" : ""));
525 supplemental_right->set_text (_text_cells[LowerRight2], buf);
530 AudioClock::set_bbt (framepos_t when, bool force)
533 Timecode::BBT_Time BBT;
535 /* handle a common case */
542 _session->tempo_map().bbt_time (when, BBT);
547 _session->tempo_map().bbt_time (when, BBT);
550 sprintf (buf, "%0*" PRIu32, field_length[Bars], BBT.bars);
551 if (force || _text_cells[Bars]->get_text () != buf) {
552 display->set_text (_text_cells[Bars], buf);
554 sprintf (buf, "%0*" PRIu32, field_length[Beats], BBT.beats);
555 if (force || _text_cells[Beats]->get_text () != buf) {
556 display->set_text (_text_cells[Beats], buf);
558 sprintf (buf, "%0*" PRIu32, field_length[Ticks], BBT.ticks);
559 if (force || _text_cells[Ticks]->get_text () != buf) {
560 display->set_text (_text_cells[Ticks], buf);
563 if (supplemental_right) {
566 if (bbt_reference_time < 0) {
569 pos = bbt_reference_time;
572 TempoMetric m (_session->tempo_map().metric_at (pos));
574 sprintf (buf, "%-5.2f", m.tempo().beats_per_minute());
575 supplemental_left->set_text (_text_cells[LowerLeft2], buf);
577 sprintf (buf, "%g|%g", m.meter().beats_per_bar(), m.meter().note_divisor());
578 supplemental_right->set_text (_text_cells[LowerRight2], buf);
583 AudioClock::set_session (Session *s)
585 SessionHandlePtr::set_session (s);
589 _session->config.ParameterChanged.connect (_session_connections, invalidator (*this), boost::bind (&AudioClock::session_configuration_changed, this, _1), gui_context());
592 XMLNode* node = _session->extra_xml (X_("ClockModes"));
593 AudioClock::Mode amode;
596 if ((prop = node->property (_name)) != 0) {
597 amode = AudioClock::Mode (string_2_enum (prop->value(), amode));
602 set (last_when, true);
607 AudioClock::edit_next_field ()
609 /* move on to the next field.
612 switch (editing_field) {
617 editing_field = Timecode_Minutes;
618 display->start_editing (_text_cells[Timecode_Minutes]);
620 case Timecode_Minutes:
621 editing_field = Timecode_Seconds;
622 display->start_editing (_text_cells[Timecode_Seconds]);
624 case Timecode_Seconds:
625 editing_field = Timecode_Frames;
626 display->start_editing (_text_cells[Timecode_Frames]);
628 case Timecode_Frames:
635 editing_field = MS_Minutes;
636 display->start_editing (_text_cells[MS_Minutes]);
639 editing_field = MS_Seconds;
640 display->start_editing (_text_cells[MS_Seconds]);
643 editing_field = MS_Milliseconds;
644 display->start_editing (_text_cells[MS_Milliseconds]);
646 case MS_Milliseconds:
653 editing_field = Beats;
654 display->start_editing (_text_cells[Beats]);
657 editing_field = Ticks;
658 display->start_editing (_text_cells[Ticks]);
677 AudioClock::on_key_press_event (GdkEventKey* ev)
679 /* return true for keys that we MIGHT use
682 switch (ev->keyval) {
717 AudioClock::on_key_release_event (GdkEventKey *ev)
719 if (editing_field == 0) {
723 CairoTextCell *cell = _text_cells[editing_field];
731 bool move_on = false;
733 switch (ev->keyval) {
778 if (_mode == MinSec && editing_field == MS_Seconds) {
779 new_char = '.'; // XXX i18n
793 ChangeAborted(); /* EMIT SIGNAL */
802 if (key_entry_state == 0) {
804 /* initialize with a fresh new string */
806 if (editing_field != AudioFrames) {
807 for (uint32_t xn = 0; xn < field_length[editing_field] - 1; ++xn) {
816 string existing = cell->get_text();
817 if (existing.length() >= field_length[editing_field]) {
818 new_text = existing.substr (1, field_length[editing_field] - 1);
820 new_text = existing.substr (0, field_length[editing_field] - 1);
824 new_text += new_char;
825 display->set_text (cell, new_text);
826 _canonical_time_is_displayed = true;
830 if (key_entry_state == field_length[editing_field]) {
836 if (key_entry_state) {
838 /* if key_entry_state != then we edited the text
843 switch (editing_field) {
845 case Timecode_Minutes:
846 case Timecode_Seconds:
847 case Timecode_Frames:
848 // Check Timecode fields for sanity (may also adjust fields)
849 timecode_sanitize_display();
854 // Bars should never be zero, unless this clock is for a duration
855 if (atoi (_text_cells[Bars]->get_text()) == 0 && !is_duration) {
856 snprintf (buf, sizeof (buf), "%0*" PRIu32, field_length[Bars], 1);
857 display->set_text (_text_cells[Bars], buf);
858 _canonical_time_is_displayed = true;
860 // beats should never be zero, unless this clock is for a duration
861 if (atoi (_text_cells[Beats]->get_text()) == 0 && !is_duration) {
862 snprintf (buf, sizeof (buf), "%0*" PRIu32, field_length[Beats], 1);
863 display->set_text (_text_cells[Beats], buf);
864 _canonical_time_is_displayed = true;
871 ValueChanged(); /* EMIT_SIGNAL */
877 //if user hit Enter, lose focus
878 switch (ev->keyval) {
888 AudioClock::button_press (GdkEventButton *ev, CairoCell* cell)
890 switch (ev->button) {
894 editing_field = (Field) cell->id ();
895 display->start_editing (cell);
898 Keyboard::magic_widget_grab_focus ();
900 /* make absolutely sure that the pointer is grabbed */
901 gdk_pointer_grab(ev->window,false ,
902 GdkEventMask( Gdk::POINTER_MOTION_MASK | Gdk::BUTTON_PRESS_MASK |Gdk::BUTTON_RELEASE_MASK),
906 drag_start_y = ev->y;
920 AudioClock::button_release (GdkEventButton *ev, CairoCell* cell)
924 gdk_pointer_ungrab (GDK_CURRENT_TIME);
926 if (ev->y > drag_start_y+1 || ev->y < drag_start_y-1 || Keyboard::modifier_state_equals (ev->state, Keyboard::TertiaryModifier)){
927 // we actually dragged so return without setting editing focus, or we shift clicked
933 if (Keyboard::is_context_menu_event (ev)) {
937 ops_menu->popup (1, ev->time);
945 AudioClock::scroll (GdkEventScroll *ev, CairoCell* cell)
947 if (_session == 0 || !editable) {
951 framepos_t frames = 0;
953 switch (ev->direction) {
956 frames = get_frames ((Field) cell->id());
958 if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
961 set (current_time() + frames, true);
962 ValueChanged (); /* EMIT_SIGNAL */
966 case GDK_SCROLL_DOWN:
967 frames = get_frames ((Field) cell->id());
969 if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
973 if ((double)current_time() - (double)frames < 0.0) {
976 set (current_time() - frames, true);
979 ValueChanged (); /* EMIT_SIGNAL */
992 AudioClock::field_motion_notify_event (GdkEventMotion *ev, Field field)
994 if (_session == 0 || !dragging) {
998 float pixel_frame_scale_factor = 0.2f;
1001 if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
1002 pixel_frame_scale_factor = 0.1f;
1006 if (Keyboard::modifier_state_contains (ev->state,
1007 Keyboard::PrimaryModifier|Keyboard::SecondaryModifier)) {
1009 pixel_frame_scale_factor = 0.025f;
1012 double y_delta = ev->y - drag_y;
1014 drag_accum += y_delta*pixel_frame_scale_factor;
1018 if (trunc(drag_accum) != 0) {
1023 dir = (drag_accum < 0 ? 1:-1);
1024 pos = current_time();
1025 frames = get_frames (field,pos,dir);
1027 if (frames != 0 && frames * drag_accum < current_time()) {
1029 set ((framepos_t) floor (pos - drag_accum * frames), false); // minus because up is negative in computer-land
1037 ValueChanged(); /* EMIT_SIGNAL */
1046 AudioClock::get_frames (Field field, framepos_t pos, int dir)
1049 Timecode::BBT_Time BBT;
1051 case Timecode_Hours:
1052 f = (framecnt_t) floor (3600.0 * _session->frame_rate());
1054 case Timecode_Minutes:
1055 f = (framecnt_t) floor (60.0 * _session->frame_rate());
1057 case Timecode_Seconds:
1058 f = _session->frame_rate();
1060 case Timecode_Frames:
1061 f = (framecnt_t) floor (_session->frame_rate() / _session->timecode_frames_per_second());
1069 f = (framecnt_t) floor (3600.0 * _session->frame_rate());
1072 f = (framecnt_t) floor (60.0 * _session->frame_rate());
1075 f = (framecnt_t) _session->frame_rate();
1077 case MS_Milliseconds:
1078 f = (framecnt_t) floor (_session->frame_rate() / 1000.0);
1085 f = _session->tempo_map().bbt_duration_at (pos,BBT,dir);
1091 f = _session->tempo_map().bbt_duration_at(pos,BBT,dir);
1097 f = _session->tempo_map().bbt_duration_at(pos,BBT,dir);
1100 error << string_compose (_("programming error: %1"), "attempt to get frames from non-text field!") << endmsg;
1109 AudioClock::current_time (framepos_t pos) const
1111 if (!_canonical_time_is_displayed) {
1112 return _canonical_time;
1119 ret = timecode_frame_from_display ();
1122 ret = bbt_frame_from_display (pos);
1126 ret = minsec_frame_from_display ();
1130 ret = audio_frame_from_display ();
1141 AudioClock::current_duration (framepos_t pos) const
1147 ret = timecode_frame_from_display ();
1150 ret = bbt_frame_duration_from_display (pos);
1154 ret = minsec_frame_from_display ();
1158 ret = audio_frame_from_display ();
1169 AudioClock::timecode_sanitize_display()
1171 // Check Timecode fields for sanity, possibly adjusting values
1172 if (atoi (_text_cells[Timecode_Minutes]->get_text()) > 59) {
1173 display->set_text (_text_cells[Timecode_Minutes], "59");
1174 _canonical_time_is_displayed = true;
1177 if (atoi (_text_cells[Timecode_Seconds]->get_text()) > 59) {
1178 display->set_text (_text_cells[Timecode_Seconds], "59");
1179 _canonical_time_is_displayed = true;
1182 switch ((long)rint(_session->timecode_frames_per_second())) {
1184 if (atoi (_text_cells[Timecode_Frames]->get_text()) > 23) {
1185 display->set_text (_text_cells[Timecode_Frames], "23");
1186 _canonical_time_is_displayed = true;
1190 if (atoi (_text_cells[Timecode_Frames]->get_text()) > 24) {
1191 display->set_text (_text_cells[Timecode_Frames], "24");
1192 _canonical_time_is_displayed = true;
1196 if (atoi (_text_cells[Timecode_Frames]->get_text()) > 29) {
1197 display->set_text (_text_cells[Timecode_Frames], "29");
1198 _canonical_time_is_displayed = true;
1205 if (_session->timecode_drop_frames()) {
1206 if ((atoi (_text_cells[Timecode_Minutes]->get_text()) % 10) && (atoi (_text_cells[Timecode_Seconds]->get_text()) == 0) && (atoi (_text_cells[Timecode_Frames]->get_text()) < 2)) {
1207 display->set_text (_text_cells[Timecode_Frames], "02");
1208 _canonical_time_is_displayed = true;
1213 /** This is necessary because operator[] isn't const with std::map.
1215 * @return Label widget.
1218 AudioClock::label (Field f) const
1220 std::map<Field,CairoTextCell*>::const_iterator i = _text_cells.find (f);
1221 assert (i != _text_cells.end ());
1227 AudioClock::timecode_frame_from_display () const
1229 if (_session == 0) {
1236 TC.hours = atoi (label (Timecode_Hours)->get_text());
1237 TC.minutes = atoi (label (Timecode_Minutes)->get_text());
1238 TC.seconds = atoi (label (Timecode_Seconds)->get_text());
1239 TC.frames = atoi (label (Timecode_Frames)->get_text());
1240 TC.rate = _session->timecode_frames_per_second();
1241 TC.drop= _session->timecode_drop_frames();
1243 _session->timecode_to_sample (TC, sample, false /* use_offset */, false /* use_subframes */ );
1247 #define Timecode_SAMPLE_TEST_1
1248 #define Timecode_SAMPLE_TEST_2
1249 #define Timecode_SAMPLE_TEST_3
1250 #define Timecode_SAMPLE_TEST_4
1251 #define Timecode_SAMPLE_TEST_5
1252 #define Timecode_SAMPLE_TEST_6
1253 #define Timecode_SAMPLE_TEST_7
1255 // Testcode for timecode<->sample conversions (P.S.)
1256 Timecode::Time timecode1;
1258 framepos_t oldsample = 0;
1259 Timecode::Time timecode2;
1260 framecnt_t sample_increment;
1262 sample_increment = (framecnt_t)rint(_session->frame_rate() / _session->timecode_frames_per_second);
1264 #ifdef Timecode_SAMPLE_TEST_1
1265 // Test 1: use_offset = false, use_subframes = false
1266 cout << "use_offset = false, use_subframes = false" << endl;
1267 for (int i = 0; i < 108003; i++) {
1268 _session->timecode_to_sample( timecode1, sample1, false /* use_offset */, false /* use_subframes */ );
1269 _session->sample_to_timecode( sample1, timecode2, false /* use_offset */, false /* use_subframes */ );
1271 if ((i > 0) && ( ((sample1 - oldsample) != sample_increment) && ((sample1 - oldsample) != (sample_increment + 1)) && ((sample1 - oldsample) != (sample_increment - 1)))) {
1272 cout << "ERROR: sample increment not right: " << (sample1 - oldsample) << " != " << sample_increment << endl;
1273 cout << "timecode1: " << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
1274 cout << "sample: " << sample1 << endl;
1275 cout << "sample: " << sample1 << " -> ";
1276 cout << "timecode2: " << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
1280 if (timecode2.hours != timecode1.hours || timecode2.minutes != timecode1.minutes || timecode2.seconds != timecode2.seconds || timecode2.frames != timecode1.frames) {
1281 cout << "ERROR: timecode2 not equal timecode1" << endl;
1282 cout << "timecode1: " << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
1283 cout << "sample: " << sample1 << endl;
1284 cout << "sample: " << sample1 << " -> ";
1285 cout << "timecode2: " << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
1288 oldsample = sample1;
1289 _session->timecode_increment( timecode1 );
1292 cout << "sample_increment: " << sample_increment << endl;
1293 cout << "sample: " << sample1 << " -> ";
1294 cout << "timecode: " << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
1297 #ifdef Timecode_SAMPLE_TEST_2
1298 // Test 2: use_offset = true, use_subframes = false
1299 cout << "use_offset = true, use_subframes = false" << endl;
1301 timecode1.hours = 0;
1302 timecode1.minutes = 0;
1303 timecode1.seconds = 0;
1304 timecode1.frames = 0;
1305 timecode1.subframes = 0;
1306 sample1 = oldsample = 0;
1308 _session->sample_to_timecode( sample1, timecode1, true /* use_offset */, false /* use_subframes */ );
1309 cout << "Starting at sample: " << sample1 << " -> ";
1310 cout << "timecode: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << endl;
1312 for (int i = 0; i < 108003; i++) {
1313 _session->timecode_to_sample( timecode1, sample1, true /* use_offset */, false /* use_subframes */ );
1314 _session->sample_to_timecode( sample1, timecode2, true /* use_offset */, false /* use_subframes */ );
1316 // cout << "timecode: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
1317 // cout << "sample: " << sample1 << endl;
1318 // cout << "sample: " << sample1 << " -> ";
1319 // cout << "timecode: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
1321 if ((i > 0) && ( ((sample1 - oldsample) != sample_increment) && ((sample1 - oldsample) != (sample_increment + 1)) && ((sample1 - oldsample) != (sample_increment - 1)))) {
1322 cout << "ERROR: sample increment not right: " << (sample1 - oldsample) << " != " << sample_increment << endl;
1323 cout << "timecode1: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
1324 cout << "sample: " << sample1 << endl;
1325 cout << "sample: " << sample1 << " -> ";
1326 cout << "timecode2: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
1330 if (timecode2.hours != timecode1.hours || timecode2.minutes != timecode1.minutes || timecode2.seconds != timecode2.seconds || timecode2.frames != timecode1.frames) {
1331 cout << "ERROR: timecode2 not equal timecode1" << endl;
1332 cout << "timecode1: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
1333 cout << "sample: " << sample1 << endl;
1334 cout << "sample: " << sample1 << " -> ";
1335 cout << "timecode2: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
1338 oldsample = sample1;
1339 _session->timecode_increment( timecode1 );
1342 cout << "sample_increment: " << sample_increment << endl;
1343 cout << "sample: " << sample1 << " -> ";
1344 cout << "timecode: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
1347 #ifdef Timecode_SAMPLE_TEST_3
1348 // Test 3: use_offset = true, use_subframes = false, decrement
1349 cout << "use_offset = true, use_subframes = false, decrement" << endl;
1351 _session->sample_to_timecode( sample1, timecode1, true /* use_offset */, false /* use_subframes */ );
1352 cout << "Starting at sample: " << sample1 << " -> ";
1353 cout << "timecode: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << endl;
1355 for (int i = 0; i < 108003; i++) {
1356 _session->timecode_to_sample( timecode1, sample1, true /* use_offset */, false /* use_subframes */ );
1357 _session->sample_to_timecode( sample1, timecode2, true /* use_offset */, false /* use_subframes */ );
1359 // cout << "timecode: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
1360 // cout << "sample: " << sample1 << endl;
1361 // cout << "sample: " << sample1 << " -> ";
1362 // cout << "timecode: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
1364 if ((i > 0) && ( ((oldsample - sample1) != sample_increment) && ((oldsample - sample1) != (sample_increment + 1)) && ((oldsample - sample1) != (sample_increment - 1)))) {
1365 cout << "ERROR: sample increment not right: " << (oldsample - sample1) << " != " << sample_increment << endl;
1366 cout << "timecode1: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
1367 cout << "sample: " << sample1 << endl;
1368 cout << "sample: " << sample1 << " -> ";
1369 cout << "timecode2: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
1373 if (timecode2.hours != timecode1.hours || timecode2.minutes != timecode1.minutes || timecode2.seconds != timecode2.seconds || timecode2.frames != timecode1.frames) {
1374 cout << "ERROR: timecode2 not equal timecode1" << endl;
1375 cout << "timecode1: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
1376 cout << "sample: " << sample1 << endl;
1377 cout << "sample: " << sample1 << " -> ";
1378 cout << "timecode2: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
1381 oldsample = sample1;
1382 _session->timecode_decrement( timecode1 );
1385 cout << "sample_decrement: " << sample_increment << endl;
1386 cout << "sample: " << sample1 << " -> ";
1387 cout << "timecode: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
1391 #ifdef Timecode_SAMPLE_TEST_4
1392 // Test 4: use_offset = true, use_subframes = true
1393 cout << "use_offset = true, use_subframes = true" << endl;
1395 for (long sub = 5; sub < 80; sub += 5) {
1396 timecode1.hours = 0;
1397 timecode1.minutes = 0;
1398 timecode1.seconds = 0;
1399 timecode1.frames = 0;
1400 timecode1.subframes = 0;
1401 sample1 = oldsample = (sample_increment * sub) / 80;
1403 _session->sample_to_timecode( sample1, timecode1, true /* use_offset */, true /* use_subframes */ );
1405 cout << "starting at sample: " << sample1 << " -> ";
1406 cout << "timecode: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << endl;
1408 for (int i = 0; i < 108003; i++) {
1409 _session->timecode_to_sample( timecode1, sample1, true /* use_offset */, true /* use_subframes */ );
1410 _session->sample_to_timecode( sample1, timecode2, true /* use_offset */, true /* use_subframes */ );
1412 if ((i > 0) && ( ((sample1 - oldsample) != sample_increment) && ((sample1 - oldsample) != (sample_increment + 1)) && ((sample1 - oldsample) != (sample_increment - 1)))) {
1413 cout << "ERROR: sample increment not right: " << (sample1 - oldsample) << " != " << sample_increment << endl;
1414 cout << "timecode1: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
1415 cout << "sample: " << sample1 << endl;
1416 cout << "sample: " << sample1 << " -> ";
1417 cout << "timecode2: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
1421 if (timecode2.hours != timecode1.hours || timecode2.minutes != timecode1.minutes || timecode2.seconds != timecode2.seconds || timecode2.frames != timecode1.frames || timecode2.subframes != timecode1.subframes) {
1422 cout << "ERROR: timecode2 not equal timecode1" << endl;
1423 cout << "timecode1: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
1424 cout << "sample: " << sample1 << endl;
1425 cout << "sample: " << sample1 << " -> ";
1426 cout << "timecode2: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
1429 oldsample = sample1;
1430 _session->timecode_increment( timecode1 );
1433 cout << "sample_increment: " << sample_increment << endl;
1434 cout << "sample: " << sample1 << " -> ";
1435 cout << "timecode: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
1437 for (int i = 0; i < 108003; i++) {
1438 _session->timecode_to_sample( timecode1, sample1, true /* use_offset */, true /* use_subframes */ );
1439 _session->sample_to_timecode( sample1, timecode2, true /* use_offset */, true /* use_subframes */ );
1441 if ((i > 0) && ( ((oldsample - sample1) != sample_increment) && ((oldsample - sample1) != (sample_increment + 1)) && ((oldsample - sample1) != (sample_increment - 1)))) {
1442 cout << "ERROR: sample increment not right: " << (oldsample - sample1) << " != " << sample_increment << endl;
1443 cout << "timecode1: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
1444 cout << "sample: " << sample1 << endl;
1445 cout << "sample: " << sample1 << " -> ";
1446 cout << "timecode2: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
1450 if (timecode2.hours != timecode1.hours || timecode2.minutes != timecode1.minutes || timecode2.seconds != timecode2.seconds || timecode2.frames != timecode1.frames || timecode2.subframes != timecode1.subframes) {
1451 cout << "ERROR: timecode2 not equal timecode1" << endl;
1452 cout << "timecode1: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
1453 cout << "sample: " << sample1 << endl;
1454 cout << "sample: " << sample1 << " -> ";
1455 cout << "timecode2: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
1458 oldsample = sample1;
1459 _session->timecode_decrement( timecode1 );
1462 cout << "sample_decrement: " << sample_increment << endl;
1463 cout << "sample: " << sample1 << " -> ";
1464 cout << "timecode: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
1469 #ifdef Timecode_SAMPLE_TEST_5
1470 // Test 5: use_offset = true, use_subframes = false, increment seconds
1471 cout << "use_offset = true, use_subframes = false, increment seconds" << endl;
1473 timecode1.hours = 0;
1474 timecode1.minutes = 0;
1475 timecode1.seconds = 0;
1476 timecode1.frames = 0;
1477 timecode1.subframes = 0;
1478 sample1 = oldsample = 0;
1479 sample_increment = _session->frame_rate();
1481 _session->sample_to_timecode( sample1, timecode1, true /* use_offset */, false /* use_subframes */ );
1482 cout << "Starting at sample: " << sample1 << " -> ";
1483 cout << "timecode: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << endl;
1485 for (int i = 0; i < 3600; i++) {
1486 _session->timecode_to_sample( timecode1, sample1, true /* use_offset */, false /* use_subframes */ );
1487 _session->sample_to_timecode( sample1, timecode2, true /* use_offset */, false /* use_subframes */ );
1489 // cout << "timecode: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
1490 // cout << "sample: " << sample1 << endl;
1491 // cout << "sample: " << sample1 << " -> ";
1492 // cout << "timecode: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
1494 // if ((i > 0) && ( ((sample1 - oldsample) != sample_increment) && ((sample1 - oldsample) != (sample_increment + 1)) && ((sample1 - oldsample) != (sample_increment - 1))))
1496 // cout << "ERROR: sample increment not right: " << (sample1 - oldsample) << " != " << sample_increment << endl;
1500 if (timecode2.hours != timecode1.hours || timecode2.minutes != timecode1.minutes || timecode2.seconds != timecode2.seconds || timecode2.frames != timecode1.frames) {
1501 cout << "ERROR: timecode2 not equal timecode1" << endl;
1502 cout << "timecode: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
1503 cout << "sample: " << sample1 << endl;
1504 cout << "sample: " << sample1 << " -> ";
1505 cout << "timecode: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
1508 oldsample = sample1;
1509 _session->timecode_increment_seconds( timecode1 );
1512 cout << "sample_increment: " << sample_increment << endl;
1513 cout << "sample: " << sample1 << " -> ";
1514 cout << "timecode: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
1518 #ifdef Timecode_SAMPLE_TEST_6
1519 // Test 6: use_offset = true, use_subframes = false, increment minutes
1520 cout << "use_offset = true, use_subframes = false, increment minutes" << endl;
1522 timecode1.hours = 0;
1523 timecode1.minutes = 0;
1524 timecode1.seconds = 0;
1525 timecode1.frames = 0;
1526 timecode1.subframes = 0;
1527 sample1 = oldsample = 0;
1528 sample_increment = _session->frame_rate() * 60;
1530 _session->sample_to_timecode( sample1, timecode1, true /* use_offset */, false /* use_subframes */ );
1531 cout << "Starting at sample: " << sample1 << " -> ";
1532 cout << "timecode: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << endl;
1534 for (int i = 0; i < 60; i++) {
1535 _session->timecode_to_sample( timecode1, sample1, true /* use_offset */, false /* use_subframes */ );
1536 _session->sample_to_timecode( sample1, timecode2, true /* use_offset */, false /* use_subframes */ );
1538 // cout << "timecode: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
1539 // cout << "sample: " << sample1 << endl;
1540 // cout << "sample: " << sample1 << " -> ";
1541 // cout << "timecode: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
1543 // if ((i > 0) && ( ((sample1 - oldsample) != sample_increment) && ((sample1 - oldsample) != (sample_increment + 1)) && ((sample1 - oldsample) != (sample_increment - 1))))
1545 // cout << "ERROR: sample increment not right: " << (sample1 - oldsample) << " != " << sample_increment << endl;
1549 if (timecode2.hours != timecode1.hours || timecode2.minutes != timecode1.minutes || timecode2.seconds != timecode2.seconds || timecode2.frames != timecode1.frames) {
1550 cout << "ERROR: timecode2 not equal timecode1" << endl;
1551 cout << "timecode: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
1552 cout << "sample: " << sample1 << endl;
1553 cout << "sample: " << sample1 << " -> ";
1554 cout << "timecode: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
1557 oldsample = sample1;
1558 _session->timecode_increment_minutes( timecode1 );
1561 cout << "sample_increment: " << sample_increment << endl;
1562 cout << "sample: " << sample1 << " -> ";
1563 cout << "timecode: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
1566 #ifdef Timecode_SAMPLE_TEST_7
1567 // Test 7: use_offset = true, use_subframes = false, increment hours
1568 cout << "use_offset = true, use_subframes = false, increment hours" << endl;
1570 timecode1.hours = 0;
1571 timecode1.minutes = 0;
1572 timecode1.seconds = 0;
1573 timecode1.frames = 0;
1574 timecode1.subframes = 0;
1575 sample1 = oldsample = 0;
1576 sample_increment = _session->frame_rate() * 60 * 60;
1578 _session->sample_to_timecode( sample1, timecode1, true /* use_offset */, false /* use_subframes */ );
1579 cout << "Starting at sample: " << sample1 << " -> ";
1580 cout << "timecode: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << endl;
1582 for (int i = 0; i < 10; i++) {
1583 _session->timecode_to_sample( timecode1, sample1, true /* use_offset */, false /* use_subframes */ );
1584 _session->sample_to_timecode( sample1, timecode2, true /* use_offset */, false /* use_subframes */ );
1586 // cout << "timecode: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
1587 // cout << "sample: " << sample1 << endl;
1588 // cout << "sample: " << sample1 << " -> ";
1589 // cout << "timecode: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
1591 // if ((i > 0) && ( ((sample1 - oldsample) != sample_increment) && ((sample1 - oldsample) != (sample_increment + 1)) && ((sample1 - oldsample) != (sample_increment - 1))))
1593 // cout << "ERROR: sample increment not right: " << (sample1 - oldsample) << " != " << sample_increment << endl;
1597 if (timecode2.hours != timecode1.hours || timecode2.minutes != timecode1.minutes || timecode2.seconds != timecode2.seconds || timecode2.frames != timecode1.frames) {
1598 cout << "ERROR: timecode2 not equal timecode1" << endl;
1599 cout << "timecode: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
1600 cout << "sample: " << sample1 << endl;
1601 cout << "sample: " << sample1 << " -> ";
1602 cout << "timecode: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
1605 oldsample = sample1;
1606 _session->timecode_increment_hours( timecode1 );
1609 cout << "sample_increment: " << sample_increment << endl;
1610 cout << "sample: " << sample1 << " -> ";
1611 cout << "timecode: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
1620 AudioClock::minsec_frame_from_display () const
1622 if (_session == 0) {
1626 int hrs = atoi (label (MS_Hours)->get_text());
1627 int mins = atoi (label (MS_Minutes)->get_text());
1628 int secs = atoi (label (MS_Seconds)->get_text());
1629 int millisecs = atoi (label (MS_Milliseconds)->get_text());
1631 framecnt_t sr = _session->frame_rate();
1633 return (framepos_t) floor ((hrs * 60.0f * 60.0f * sr) + (mins * 60.0f * sr) + (secs * sr) + (millisecs * sr / 1000.0));
1637 AudioClock::bbt_frame_from_display (framepos_t pos) const
1639 if (_session == 0) {
1640 error << "AudioClock::current_time() called with BBT mode but without session!" << endmsg;
1645 any.type = AnyTime::BBT;
1647 any.bbt.bars = atoi (label (Bars)->get_text());
1648 any.bbt.beats = atoi (label (Beats)->get_text());
1649 any.bbt.ticks = atoi (label (Ticks)->get_text());
1654 return _session->any_duration_to_frames (pos, any);
1656 return _session->convert_to_frames (any);
1662 AudioClock::bbt_frame_duration_from_display (framepos_t pos) const
1664 if (_session == 0) {
1665 error << "AudioClock::current_time() called with BBT mode but without session!" << endmsg;
1669 Timecode::BBT_Time bbt;
1672 bbt.bars = atoi (label (Bars)->get_text());
1673 bbt.beats = atoi (label (Beats)->get_text());
1674 bbt.ticks = atoi (label (Ticks)->get_text());
1676 return _session->tempo_map().bbt_duration_at(pos,bbt,1);
1680 AudioClock::audio_frame_from_display () const
1682 return (framepos_t) atoi (label (AudioFrames)->get_text ());
1686 AudioClock::build_ops_menu ()
1688 using namespace Menu_Helpers;
1689 ops_menu = new Menu;
1690 MenuList& ops_items = ops_menu->items();
1691 ops_menu->set_name ("ArdourContextMenu");
1693 if (!Profile->get_sae()) {
1694 ops_items.push_back (MenuElem (_("Timecode"), sigc::bind (sigc::mem_fun(*this, &AudioClock::set_mode), Timecode)));
1696 ops_items.push_back (MenuElem (_("Bars:Beats"), sigc::bind (sigc::mem_fun(*this, &AudioClock::set_mode), BBT)));
1697 ops_items.push_back (MenuElem (_("Minutes:Seconds"), sigc::bind (sigc::mem_fun(*this, &AudioClock::set_mode), MinSec)));
1698 ops_items.push_back (MenuElem (_("Samples"), sigc::bind (sigc::mem_fun(*this, &AudioClock::set_mode), Frames)));
1699 ops_items.push_back (MenuElem (_("Off"), sigc::bind (sigc::mem_fun(*this, &AudioClock::set_mode), Off)));
1701 if (editable && !is_duration && !_follows_playhead) {
1702 ops_items.push_back (SeparatorElem());
1703 ops_items.push_back (MenuElem (_("Set From Playhead"), sigc::mem_fun(*this, &AudioClock::set_from_playhead)));
1704 ops_items.push_back (MenuElem (_("Locate to This Time"), sigc::mem_fun(*this, &AudioClock::locate)));
1709 AudioClock::set_from_playhead ()
1715 set (_session->transport_frame());
1720 AudioClock::locate ()
1722 if (!_session || is_duration) {
1726 _session->request_locate (current_time(), _session->transport_rolling ());
1730 AudioClock::disconnect_signals ()
1732 scroll_connection.disconnect ();
1733 button_press_connection.disconnect ();
1734 button_release_connection.disconnect ();
1738 AudioClock::connect_signals ()
1740 disconnect_signals ();
1742 scroll_connection = display->scroll.connect (sigc::mem_fun (*this, &AudioClock::scroll));
1743 button_press_connection = display->button_press.connect (sigc::mem_fun (*this, &AudioClock::button_press));
1744 button_release_connection = display->button_release.connect (sigc::mem_fun (*this, &AudioClock::button_release));
1748 AudioClock::set_mode (Mode m)
1756 display->clear_cells ();
1758 if (supplemental_left) {
1759 supplemental_left->clear_cells ();
1760 supplemental_right->clear_cells ();
1765 display->add_cell (_text_cells[Timecode_Hours]);
1766 display->add_cell (_fixed_cells[Colon1]);
1767 display->add_cell (_text_cells[Timecode_Minutes]);
1768 display->add_cell (_fixed_cells[Colon2]);
1769 display->add_cell (_text_cells[Timecode_Seconds]);
1770 display->add_cell (_fixed_cells[Colon3]);
1771 display->add_cell (_text_cells[Timecode_Frames]);
1773 if (supplemental_left) {
1774 supplemental_left->add_cell (_text_cells[LowerLeft1]);
1775 supplemental_left->add_cell (_text_cells[LowerLeft2]);
1776 supplemental_right->add_cell (_text_cells[LowerRight1]);
1777 supplemental_right->add_cell (_text_cells[LowerRight2]);
1779 supplemental_left->set_width_chars (_text_cells[LowerLeft1], 4);
1780 supplemental_left->set_width_chars (_text_cells[LowerLeft2], 8);
1782 supplemental_right->set_width_chars (_text_cells[LowerRight1], 4);
1783 supplemental_right->set_width_chars (_text_cells[LowerRight2], 6.25);
1785 supplemental_left->set_text (_text_cells[LowerLeft1], _("EXT"));
1786 supplemental_right->set_text (_text_cells[LowerRight1], _("FPS"));
1791 display->add_cell (_text_cells[Bars]);
1792 display->add_cell (_fixed_cells[Bar1]);
1793 display->add_cell (_text_cells[Beats]);
1794 display->add_cell (_fixed_cells[Bar2]);
1795 display->add_cell (_text_cells[Ticks]);
1796 if (supplemental_left) {
1797 supplemental_left->add_cell (_text_cells[LowerLeft1]);
1798 supplemental_left->add_cell (_text_cells[LowerLeft2]);
1799 supplemental_right->add_cell (_text_cells[LowerRight1]);
1800 supplemental_right->add_cell (_text_cells[LowerRight2]);
1802 supplemental_left->set_width_chars (_text_cells[LowerLeft1], 1);
1803 supplemental_left->set_width_chars (_text_cells[LowerLeft2], 5.25);
1805 supplemental_right->set_width_chars (_text_cells[LowerRight1], 1);
1806 supplemental_right->set_width_chars (_text_cells[LowerRight2], 5);
1808 supplemental_left->set_text (_text_cells[LowerLeft1], _("M"));
1809 supplemental_right->set_text (_text_cells[LowerRight1], _("T"));
1814 display->add_cell (_text_cells[MS_Hours]);
1815 display->add_cell (_fixed_cells[Colon1]);
1816 display->add_cell (_text_cells[MS_Minutes]);
1817 display->add_cell (_fixed_cells[Colon2]);
1818 display->add_cell (_text_cells[MS_Seconds]);
1819 display->add_cell (_fixed_cells[Colon3]);
1820 display->add_cell (_text_cells[MS_Milliseconds]);
1824 display->add_cell (_text_cells[AudioFrames]);
1825 if (supplemental_left) {
1826 supplemental_left->add_cell (_text_cells[LowerLeft1]);
1827 supplemental_left->add_cell (_text_cells[LowerLeft2]);
1828 supplemental_right->add_cell (_text_cells[LowerRight1]);
1829 supplemental_right->add_cell (_text_cells[LowerRight2]);
1831 supplemental_left->set_width_chars (_text_cells[LowerLeft1], 3);
1832 supplemental_left->set_width_chars (_text_cells[LowerLeft2], 5);
1834 supplemental_right->set_width_chars (_text_cells[LowerRight1], 5);
1835 supplemental_right->set_width_chars (_text_cells[LowerRight2], 5);
1837 supplemental_left->set_text (_text_cells[LowerLeft1], _("SR"));
1838 supplemental_right->set_text (_text_cells[LowerRight1], _("Pull"));
1846 if (supplemental_left) {
1847 /* clear information cells */
1848 supplemental_left->set_text (_text_cells[LowerLeft2], _(""));
1849 supplemental_right->set_text (_text_cells[LowerRight2], _(""));
1851 /* propagate font style,but smaller, into cells */
1852 boost::shared_ptr<CairoFontDescription> smaller_font (new CairoFontDescription (*display->font().get()));
1853 smaller_font->set_size (12);
1854 supplemental_right->set_font (smaller_font);
1855 supplemental_left->set_font (smaller_font);
1861 disconnect_signals ();
1864 set (last_when, true);
1866 if (!is_transient) {
1867 ModeChanged (); /* EMIT SIGNAL (the static one)*/
1870 mode_changed (); /* EMIT SIGNAL (the member one) */
1874 AudioClock::set_bbt_reference (framepos_t pos)
1876 bbt_reference_time = pos;
1880 AudioClock::on_style_changed (const Glib::RefPtr<Gtk::Style>& old_style)
1882 VBox::on_style_changed (old_style);
1887 AudioClock::set_is_duration (bool yn)
1889 if (yn == is_duration) {
1894 set (last_when, true, 0, 's');