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) {
893 editing_field = (Field) cell->id ();
894 display->start_editing (cell);
897 Keyboard::magic_widget_grab_focus ();
899 /* make absolutely sure that the pointer is grabbed */
900 gdk_pointer_grab(ev->window,false ,
901 GdkEventMask( Gdk::POINTER_MOTION_MASK | Gdk::BUTTON_PRESS_MASK |Gdk::BUTTON_RELEASE_MASK),
905 drag_start_y = ev->y;
918 AudioClock::button_release (GdkEventButton *ev, CairoCell*)
921 gdk_pointer_ungrab (GDK_CURRENT_TIME);
923 if (ev->y > drag_start_y+1 || ev->y < drag_start_y-1 || Keyboard::modifier_state_equals (ev->state, Keyboard::TertiaryModifier)){
924 // we actually dragged so return without setting editing focus, or we shift clicked
933 ops_menu->popup (1, ev->time);
937 if (Keyboard::is_context_menu_event (ev)) {
941 ops_menu->popup (1, ev->time);
949 AudioClock::scroll (GdkEventScroll *ev, CairoCell* cell)
955 framepos_t frames = 0;
957 switch (ev->direction) {
960 frames = get_frames ((Field) cell->id());
962 if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
965 set (current_time() + frames, true);
966 ValueChanged (); /* EMIT_SIGNAL */
970 case GDK_SCROLL_DOWN:
971 frames = get_frames ((Field) cell->id());
973 if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
977 if ((double)current_time() - (double)frames < 0.0) {
980 set (current_time() - frames, true);
983 ValueChanged (); /* EMIT_SIGNAL */
996 AudioClock::field_motion_notify_event (GdkEventMotion *ev, Field field)
998 if (_session == 0 || !dragging) {
1002 float pixel_frame_scale_factor = 0.2f;
1005 if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
1006 pixel_frame_scale_factor = 0.1f;
1010 if (Keyboard::modifier_state_contains (ev->state,
1011 Keyboard::PrimaryModifier|Keyboard::SecondaryModifier)) {
1013 pixel_frame_scale_factor = 0.025f;
1016 double y_delta = ev->y - drag_y;
1018 drag_accum += y_delta*pixel_frame_scale_factor;
1022 if (trunc(drag_accum) != 0) {
1027 dir = (drag_accum < 0 ? 1:-1);
1028 pos = current_time();
1029 frames = get_frames (field,pos,dir);
1031 if (frames != 0 && frames * drag_accum < current_time()) {
1033 set ((framepos_t) floor (pos - drag_accum * frames), false); // minus because up is negative in computer-land
1041 ValueChanged(); /* EMIT_SIGNAL */
1050 AudioClock::get_frames (Field field, framepos_t pos, int dir)
1053 Timecode::BBT_Time BBT;
1055 case Timecode_Hours:
1056 f = (framecnt_t) floor (3600.0 * _session->frame_rate());
1058 case Timecode_Minutes:
1059 f = (framecnt_t) floor (60.0 * _session->frame_rate());
1061 case Timecode_Seconds:
1062 f = _session->frame_rate();
1064 case Timecode_Frames:
1065 f = (framecnt_t) floor (_session->frame_rate() / _session->timecode_frames_per_second());
1073 f = (framecnt_t) floor (3600.0 * _session->frame_rate());
1076 f = (framecnt_t) floor (60.0 * _session->frame_rate());
1079 f = (framecnt_t) _session->frame_rate();
1081 case MS_Milliseconds:
1082 f = (framecnt_t) floor (_session->frame_rate() / 1000.0);
1089 f = _session->tempo_map().bbt_duration_at (pos,BBT,dir);
1095 f = _session->tempo_map().bbt_duration_at(pos,BBT,dir);
1101 f = _session->tempo_map().bbt_duration_at(pos,BBT,dir);
1104 error << string_compose (_("programming error: %1"), "attempt to get frames from non-text field!") << endmsg;
1113 AudioClock::current_time (framepos_t pos) const
1115 if (!_canonical_time_is_displayed) {
1116 return _canonical_time;
1123 ret = timecode_frame_from_display ();
1126 ret = bbt_frame_from_display (pos);
1130 ret = minsec_frame_from_display ();
1134 ret = audio_frame_from_display ();
1145 AudioClock::current_duration (framepos_t pos) const
1151 ret = timecode_frame_from_display ();
1154 ret = bbt_frame_duration_from_display (pos);
1158 ret = minsec_frame_from_display ();
1162 ret = audio_frame_from_display ();
1173 AudioClock::timecode_sanitize_display()
1175 // Check Timecode fields for sanity, possibly adjusting values
1176 if (atoi (_text_cells[Timecode_Minutes]->get_text()) > 59) {
1177 display->set_text (_text_cells[Timecode_Minutes], "59");
1178 _canonical_time_is_displayed = true;
1181 if (atoi (_text_cells[Timecode_Seconds]->get_text()) > 59) {
1182 display->set_text (_text_cells[Timecode_Seconds], "59");
1183 _canonical_time_is_displayed = true;
1186 switch ((long)rint(_session->timecode_frames_per_second())) {
1188 if (atoi (_text_cells[Timecode_Frames]->get_text()) > 23) {
1189 display->set_text (_text_cells[Timecode_Frames], "23");
1190 _canonical_time_is_displayed = true;
1194 if (atoi (_text_cells[Timecode_Frames]->get_text()) > 24) {
1195 display->set_text (_text_cells[Timecode_Frames], "24");
1196 _canonical_time_is_displayed = true;
1200 if (atoi (_text_cells[Timecode_Frames]->get_text()) > 29) {
1201 display->set_text (_text_cells[Timecode_Frames], "29");
1202 _canonical_time_is_displayed = true;
1209 if (_session->timecode_drop_frames()) {
1210 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)) {
1211 display->set_text (_text_cells[Timecode_Frames], "02");
1212 _canonical_time_is_displayed = true;
1217 /** This is necessary because operator[] isn't const with std::map.
1219 * @return Label widget.
1222 AudioClock::label (Field f) const
1224 std::map<Field,CairoTextCell*>::const_iterator i = _text_cells.find (f);
1225 assert (i != _text_cells.end ());
1231 AudioClock::timecode_frame_from_display () const
1233 if (_session == 0) {
1240 TC.hours = atoi (label (Timecode_Hours)->get_text());
1241 TC.minutes = atoi (label (Timecode_Minutes)->get_text());
1242 TC.seconds = atoi (label (Timecode_Seconds)->get_text());
1243 TC.frames = atoi (label (Timecode_Frames)->get_text());
1244 TC.rate = _session->timecode_frames_per_second();
1245 TC.drop= _session->timecode_drop_frames();
1247 _session->timecode_to_sample (TC, sample, false /* use_offset */, false /* use_subframes */ );
1251 #define Timecode_SAMPLE_TEST_1
1252 #define Timecode_SAMPLE_TEST_2
1253 #define Timecode_SAMPLE_TEST_3
1254 #define Timecode_SAMPLE_TEST_4
1255 #define Timecode_SAMPLE_TEST_5
1256 #define Timecode_SAMPLE_TEST_6
1257 #define Timecode_SAMPLE_TEST_7
1259 // Testcode for timecode<->sample conversions (P.S.)
1260 Timecode::Time timecode1;
1262 framepos_t oldsample = 0;
1263 Timecode::Time timecode2;
1264 framecnt_t sample_increment;
1266 sample_increment = (framecnt_t)rint(_session->frame_rate() / _session->timecode_frames_per_second);
1268 #ifdef Timecode_SAMPLE_TEST_1
1269 // Test 1: use_offset = false, use_subframes = false
1270 cout << "use_offset = false, use_subframes = false" << endl;
1271 for (int i = 0; i < 108003; i++) {
1272 _session->timecode_to_sample( timecode1, sample1, false /* use_offset */, false /* use_subframes */ );
1273 _session->sample_to_timecode( sample1, timecode2, false /* use_offset */, false /* use_subframes */ );
1275 if ((i > 0) && ( ((sample1 - oldsample) != sample_increment) && ((sample1 - oldsample) != (sample_increment + 1)) && ((sample1 - oldsample) != (sample_increment - 1)))) {
1276 cout << "ERROR: sample increment not right: " << (sample1 - oldsample) << " != " << sample_increment << endl;
1277 cout << "timecode1: " << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
1278 cout << "sample: " << sample1 << endl;
1279 cout << "sample: " << sample1 << " -> ";
1280 cout << "timecode2: " << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
1284 if (timecode2.hours != timecode1.hours || timecode2.minutes != timecode1.minutes || timecode2.seconds != timecode2.seconds || timecode2.frames != timecode1.frames) {
1285 cout << "ERROR: timecode2 not equal timecode1" << endl;
1286 cout << "timecode1: " << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
1287 cout << "sample: " << sample1 << endl;
1288 cout << "sample: " << sample1 << " -> ";
1289 cout << "timecode2: " << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
1292 oldsample = sample1;
1293 _session->timecode_increment( timecode1 );
1296 cout << "sample_increment: " << sample_increment << endl;
1297 cout << "sample: " << sample1 << " -> ";
1298 cout << "timecode: " << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
1301 #ifdef Timecode_SAMPLE_TEST_2
1302 // Test 2: use_offset = true, use_subframes = false
1303 cout << "use_offset = true, use_subframes = false" << endl;
1305 timecode1.hours = 0;
1306 timecode1.minutes = 0;
1307 timecode1.seconds = 0;
1308 timecode1.frames = 0;
1309 timecode1.subframes = 0;
1310 sample1 = oldsample = 0;
1312 _session->sample_to_timecode( sample1, timecode1, true /* use_offset */, false /* use_subframes */ );
1313 cout << "Starting at sample: " << sample1 << " -> ";
1314 cout << "timecode: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << endl;
1316 for (int i = 0; i < 108003; i++) {
1317 _session->timecode_to_sample( timecode1, sample1, true /* use_offset */, false /* use_subframes */ );
1318 _session->sample_to_timecode( sample1, timecode2, true /* use_offset */, false /* use_subframes */ );
1320 // cout << "timecode: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
1321 // cout << "sample: " << sample1 << endl;
1322 // cout << "sample: " << sample1 << " -> ";
1323 // cout << "timecode: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
1325 if ((i > 0) && ( ((sample1 - oldsample) != sample_increment) && ((sample1 - oldsample) != (sample_increment + 1)) && ((sample1 - oldsample) != (sample_increment - 1)))) {
1326 cout << "ERROR: sample increment not right: " << (sample1 - oldsample) << " != " << sample_increment << endl;
1327 cout << "timecode1: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
1328 cout << "sample: " << sample1 << endl;
1329 cout << "sample: " << sample1 << " -> ";
1330 cout << "timecode2: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
1334 if (timecode2.hours != timecode1.hours || timecode2.minutes != timecode1.minutes || timecode2.seconds != timecode2.seconds || timecode2.frames != timecode1.frames) {
1335 cout << "ERROR: timecode2 not equal timecode1" << endl;
1336 cout << "timecode1: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
1337 cout << "sample: " << sample1 << endl;
1338 cout << "sample: " << sample1 << " -> ";
1339 cout << "timecode2: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
1342 oldsample = sample1;
1343 _session->timecode_increment( timecode1 );
1346 cout << "sample_increment: " << sample_increment << endl;
1347 cout << "sample: " << sample1 << " -> ";
1348 cout << "timecode: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
1351 #ifdef Timecode_SAMPLE_TEST_3
1352 // Test 3: use_offset = true, use_subframes = false, decrement
1353 cout << "use_offset = true, use_subframes = false, decrement" << endl;
1355 _session->sample_to_timecode( sample1, timecode1, true /* use_offset */, false /* use_subframes */ );
1356 cout << "Starting at sample: " << sample1 << " -> ";
1357 cout << "timecode: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << endl;
1359 for (int i = 0; i < 108003; i++) {
1360 _session->timecode_to_sample( timecode1, sample1, true /* use_offset */, false /* use_subframes */ );
1361 _session->sample_to_timecode( sample1, timecode2, true /* use_offset */, false /* use_subframes */ );
1363 // cout << "timecode: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
1364 // cout << "sample: " << sample1 << endl;
1365 // cout << "sample: " << sample1 << " -> ";
1366 // cout << "timecode: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
1368 if ((i > 0) && ( ((oldsample - sample1) != sample_increment) && ((oldsample - sample1) != (sample_increment + 1)) && ((oldsample - sample1) != (sample_increment - 1)))) {
1369 cout << "ERROR: sample increment not right: " << (oldsample - sample1) << " != " << sample_increment << endl;
1370 cout << "timecode1: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
1371 cout << "sample: " << sample1 << endl;
1372 cout << "sample: " << sample1 << " -> ";
1373 cout << "timecode2: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
1377 if (timecode2.hours != timecode1.hours || timecode2.minutes != timecode1.minutes || timecode2.seconds != timecode2.seconds || timecode2.frames != timecode1.frames) {
1378 cout << "ERROR: timecode2 not equal timecode1" << endl;
1379 cout << "timecode1: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
1380 cout << "sample: " << sample1 << endl;
1381 cout << "sample: " << sample1 << " -> ";
1382 cout << "timecode2: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
1385 oldsample = sample1;
1386 _session->timecode_decrement( timecode1 );
1389 cout << "sample_decrement: " << sample_increment << endl;
1390 cout << "sample: " << sample1 << " -> ";
1391 cout << "timecode: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
1395 #ifdef Timecode_SAMPLE_TEST_4
1396 // Test 4: use_offset = true, use_subframes = true
1397 cout << "use_offset = true, use_subframes = true" << endl;
1399 for (long sub = 5; sub < 80; sub += 5) {
1400 timecode1.hours = 0;
1401 timecode1.minutes = 0;
1402 timecode1.seconds = 0;
1403 timecode1.frames = 0;
1404 timecode1.subframes = 0;
1405 sample1 = oldsample = (sample_increment * sub) / 80;
1407 _session->sample_to_timecode( sample1, timecode1, true /* use_offset */, true /* use_subframes */ );
1409 cout << "starting at sample: " << sample1 << " -> ";
1410 cout << "timecode: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << endl;
1412 for (int i = 0; i < 108003; i++) {
1413 _session->timecode_to_sample( timecode1, sample1, true /* use_offset */, true /* use_subframes */ );
1414 _session->sample_to_timecode( sample1, timecode2, true /* use_offset */, true /* use_subframes */ );
1416 if ((i > 0) && ( ((sample1 - oldsample) != sample_increment) && ((sample1 - oldsample) != (sample_increment + 1)) && ((sample1 - oldsample) != (sample_increment - 1)))) {
1417 cout << "ERROR: sample increment not right: " << (sample1 - oldsample) << " != " << sample_increment << endl;
1418 cout << "timecode1: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
1419 cout << "sample: " << sample1 << endl;
1420 cout << "sample: " << sample1 << " -> ";
1421 cout << "timecode2: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
1425 if (timecode2.hours != timecode1.hours || timecode2.minutes != timecode1.minutes || timecode2.seconds != timecode2.seconds || timecode2.frames != timecode1.frames || timecode2.subframes != timecode1.subframes) {
1426 cout << "ERROR: timecode2 not equal timecode1" << endl;
1427 cout << "timecode1: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
1428 cout << "sample: " << sample1 << endl;
1429 cout << "sample: " << sample1 << " -> ";
1430 cout << "timecode2: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
1433 oldsample = sample1;
1434 _session->timecode_increment( timecode1 );
1437 cout << "sample_increment: " << sample_increment << endl;
1438 cout << "sample: " << sample1 << " -> ";
1439 cout << "timecode: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
1441 for (int i = 0; i < 108003; i++) {
1442 _session->timecode_to_sample( timecode1, sample1, true /* use_offset */, true /* use_subframes */ );
1443 _session->sample_to_timecode( sample1, timecode2, true /* use_offset */, true /* use_subframes */ );
1445 if ((i > 0) && ( ((oldsample - sample1) != sample_increment) && ((oldsample - sample1) != (sample_increment + 1)) && ((oldsample - sample1) != (sample_increment - 1)))) {
1446 cout << "ERROR: sample increment not right: " << (oldsample - sample1) << " != " << sample_increment << endl;
1447 cout << "timecode1: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
1448 cout << "sample: " << sample1 << endl;
1449 cout << "sample: " << sample1 << " -> ";
1450 cout << "timecode2: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
1454 if (timecode2.hours != timecode1.hours || timecode2.minutes != timecode1.minutes || timecode2.seconds != timecode2.seconds || timecode2.frames != timecode1.frames || timecode2.subframes != timecode1.subframes) {
1455 cout << "ERROR: timecode2 not equal timecode1" << endl;
1456 cout << "timecode1: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
1457 cout << "sample: " << sample1 << endl;
1458 cout << "sample: " << sample1 << " -> ";
1459 cout << "timecode2: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
1462 oldsample = sample1;
1463 _session->timecode_decrement( timecode1 );
1466 cout << "sample_decrement: " << sample_increment << endl;
1467 cout << "sample: " << sample1 << " -> ";
1468 cout << "timecode: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
1473 #ifdef Timecode_SAMPLE_TEST_5
1474 // Test 5: use_offset = true, use_subframes = false, increment seconds
1475 cout << "use_offset = true, use_subframes = false, increment seconds" << endl;
1477 timecode1.hours = 0;
1478 timecode1.minutes = 0;
1479 timecode1.seconds = 0;
1480 timecode1.frames = 0;
1481 timecode1.subframes = 0;
1482 sample1 = oldsample = 0;
1483 sample_increment = _session->frame_rate();
1485 _session->sample_to_timecode( sample1, timecode1, true /* use_offset */, false /* use_subframes */ );
1486 cout << "Starting at sample: " << sample1 << " -> ";
1487 cout << "timecode: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << endl;
1489 for (int i = 0; i < 3600; i++) {
1490 _session->timecode_to_sample( timecode1, sample1, true /* use_offset */, false /* use_subframes */ );
1491 _session->sample_to_timecode( sample1, timecode2, true /* use_offset */, false /* use_subframes */ );
1493 // cout << "timecode: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
1494 // cout << "sample: " << sample1 << endl;
1495 // cout << "sample: " << sample1 << " -> ";
1496 // cout << "timecode: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
1498 // if ((i > 0) && ( ((sample1 - oldsample) != sample_increment) && ((sample1 - oldsample) != (sample_increment + 1)) && ((sample1 - oldsample) != (sample_increment - 1))))
1500 // cout << "ERROR: sample increment not right: " << (sample1 - oldsample) << " != " << sample_increment << endl;
1504 if (timecode2.hours != timecode1.hours || timecode2.minutes != timecode1.minutes || timecode2.seconds != timecode2.seconds || timecode2.frames != timecode1.frames) {
1505 cout << "ERROR: timecode2 not equal timecode1" << endl;
1506 cout << "timecode: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
1507 cout << "sample: " << sample1 << endl;
1508 cout << "sample: " << sample1 << " -> ";
1509 cout << "timecode: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
1512 oldsample = sample1;
1513 _session->timecode_increment_seconds( timecode1 );
1516 cout << "sample_increment: " << sample_increment << endl;
1517 cout << "sample: " << sample1 << " -> ";
1518 cout << "timecode: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
1522 #ifdef Timecode_SAMPLE_TEST_6
1523 // Test 6: use_offset = true, use_subframes = false, increment minutes
1524 cout << "use_offset = true, use_subframes = false, increment minutes" << endl;
1526 timecode1.hours = 0;
1527 timecode1.minutes = 0;
1528 timecode1.seconds = 0;
1529 timecode1.frames = 0;
1530 timecode1.subframes = 0;
1531 sample1 = oldsample = 0;
1532 sample_increment = _session->frame_rate() * 60;
1534 _session->sample_to_timecode( sample1, timecode1, true /* use_offset */, false /* use_subframes */ );
1535 cout << "Starting at sample: " << sample1 << " -> ";
1536 cout << "timecode: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << endl;
1538 for (int i = 0; i < 60; i++) {
1539 _session->timecode_to_sample( timecode1, sample1, true /* use_offset */, false /* use_subframes */ );
1540 _session->sample_to_timecode( sample1, timecode2, true /* use_offset */, false /* use_subframes */ );
1542 // cout << "timecode: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
1543 // cout << "sample: " << sample1 << endl;
1544 // cout << "sample: " << sample1 << " -> ";
1545 // cout << "timecode: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
1547 // if ((i > 0) && ( ((sample1 - oldsample) != sample_increment) && ((sample1 - oldsample) != (sample_increment + 1)) && ((sample1 - oldsample) != (sample_increment - 1))))
1549 // cout << "ERROR: sample increment not right: " << (sample1 - oldsample) << " != " << sample_increment << endl;
1553 if (timecode2.hours != timecode1.hours || timecode2.minutes != timecode1.minutes || timecode2.seconds != timecode2.seconds || timecode2.frames != timecode1.frames) {
1554 cout << "ERROR: timecode2 not equal timecode1" << endl;
1555 cout << "timecode: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
1556 cout << "sample: " << sample1 << endl;
1557 cout << "sample: " << sample1 << " -> ";
1558 cout << "timecode: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
1561 oldsample = sample1;
1562 _session->timecode_increment_minutes( timecode1 );
1565 cout << "sample_increment: " << sample_increment << endl;
1566 cout << "sample: " << sample1 << " -> ";
1567 cout << "timecode: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
1570 #ifdef Timecode_SAMPLE_TEST_7
1571 // Test 7: use_offset = true, use_subframes = false, increment hours
1572 cout << "use_offset = true, use_subframes = false, increment hours" << endl;
1574 timecode1.hours = 0;
1575 timecode1.minutes = 0;
1576 timecode1.seconds = 0;
1577 timecode1.frames = 0;
1578 timecode1.subframes = 0;
1579 sample1 = oldsample = 0;
1580 sample_increment = _session->frame_rate() * 60 * 60;
1582 _session->sample_to_timecode( sample1, timecode1, true /* use_offset */, false /* use_subframes */ );
1583 cout << "Starting at sample: " << sample1 << " -> ";
1584 cout << "timecode: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << endl;
1586 for (int i = 0; i < 10; i++) {
1587 _session->timecode_to_sample( timecode1, sample1, true /* use_offset */, false /* use_subframes */ );
1588 _session->sample_to_timecode( sample1, timecode2, true /* use_offset */, false /* use_subframes */ );
1590 // cout << "timecode: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
1591 // cout << "sample: " << sample1 << endl;
1592 // cout << "sample: " << sample1 << " -> ";
1593 // cout << "timecode: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
1595 // if ((i > 0) && ( ((sample1 - oldsample) != sample_increment) && ((sample1 - oldsample) != (sample_increment + 1)) && ((sample1 - oldsample) != (sample_increment - 1))))
1597 // cout << "ERROR: sample increment not right: " << (sample1 - oldsample) << " != " << sample_increment << endl;
1601 if (timecode2.hours != timecode1.hours || timecode2.minutes != timecode1.minutes || timecode2.seconds != timecode2.seconds || timecode2.frames != timecode1.frames) {
1602 cout << "ERROR: timecode2 not equal timecode1" << endl;
1603 cout << "timecode: " << (timecode1.negative ? "-" : "") << timecode1.hours << ":" << timecode1.minutes << ":" << timecode1.seconds << ":" << timecode1.frames << "::" << timecode1.subframes << " -> ";
1604 cout << "sample: " << sample1 << endl;
1605 cout << "sample: " << sample1 << " -> ";
1606 cout << "timecode: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
1609 oldsample = sample1;
1610 _session->timecode_increment_hours( timecode1 );
1613 cout << "sample_increment: " << sample_increment << endl;
1614 cout << "sample: " << sample1 << " -> ";
1615 cout << "timecode: " << (timecode2.negative ? "-" : "") << timecode2.hours << ":" << timecode2.minutes << ":" << timecode2.seconds << ":" << timecode2.frames << "::" << timecode2.subframes << endl;
1624 AudioClock::minsec_frame_from_display () const
1626 if (_session == 0) {
1630 int hrs = atoi (label (MS_Hours)->get_text());
1631 int mins = atoi (label (MS_Minutes)->get_text());
1632 int secs = atoi (label (MS_Seconds)->get_text());
1633 int millisecs = atoi (label (MS_Milliseconds)->get_text());
1635 framecnt_t sr = _session->frame_rate();
1637 return (framepos_t) floor ((hrs * 60.0f * 60.0f * sr) + (mins * 60.0f * sr) + (secs * sr) + (millisecs * sr / 1000.0));
1641 AudioClock::bbt_frame_from_display (framepos_t pos) const
1643 if (_session == 0) {
1644 error << "AudioClock::current_time() called with BBT mode but without session!" << endmsg;
1649 any.type = AnyTime::BBT;
1651 any.bbt.bars = atoi (label (Bars)->get_text());
1652 any.bbt.beats = atoi (label (Beats)->get_text());
1653 any.bbt.ticks = atoi (label (Ticks)->get_text());
1658 return _session->any_duration_to_frames (pos, any);
1660 return _session->convert_to_frames (any);
1666 AudioClock::bbt_frame_duration_from_display (framepos_t pos) const
1668 if (_session == 0) {
1669 error << "AudioClock::current_time() called with BBT mode but without session!" << endmsg;
1673 Timecode::BBT_Time bbt;
1676 bbt.bars = atoi (label (Bars)->get_text());
1677 bbt.beats = atoi (label (Beats)->get_text());
1678 bbt.ticks = atoi (label (Ticks)->get_text());
1680 return _session->tempo_map().bbt_duration_at(pos,bbt,1);
1684 AudioClock::audio_frame_from_display () const
1686 return (framepos_t) atoi (label (AudioFrames)->get_text ());
1690 AudioClock::build_ops_menu ()
1692 using namespace Menu_Helpers;
1693 ops_menu = new Menu;
1694 MenuList& ops_items = ops_menu->items();
1695 ops_menu->set_name ("ArdourContextMenu");
1697 if (!Profile->get_sae()) {
1698 ops_items.push_back (MenuElem (_("Timecode"), sigc::bind (sigc::mem_fun(*this, &AudioClock::set_mode), Timecode)));
1700 ops_items.push_back (MenuElem (_("Bars:Beats"), sigc::bind (sigc::mem_fun(*this, &AudioClock::set_mode), BBT)));
1701 ops_items.push_back (MenuElem (_("Minutes:Seconds"), sigc::bind (sigc::mem_fun(*this, &AudioClock::set_mode), MinSec)));
1702 ops_items.push_back (MenuElem (_("Samples"), sigc::bind (sigc::mem_fun(*this, &AudioClock::set_mode), Frames)));
1703 ops_items.push_back (MenuElem (_("Off"), sigc::bind (sigc::mem_fun(*this, &AudioClock::set_mode), Off)));
1705 if (editable && !is_duration && !_follows_playhead) {
1706 ops_items.push_back (SeparatorElem());
1707 ops_items.push_back (MenuElem (_("Set From Playhead"), sigc::mem_fun(*this, &AudioClock::set_from_playhead)));
1708 ops_items.push_back (MenuElem (_("Locate to This Time"), sigc::mem_fun(*this, &AudioClock::locate)));
1713 AudioClock::set_from_playhead ()
1719 set (_session->transport_frame());
1724 AudioClock::locate ()
1726 if (!_session || is_duration) {
1730 _session->request_locate (current_time(), _session->transport_rolling ());
1734 AudioClock::disconnect_signals ()
1736 scroll_connection.disconnect ();
1737 button_press_connection.disconnect ();
1738 button_release_connection.disconnect ();
1742 AudioClock::connect_signals ()
1744 disconnect_signals ();
1747 scroll_connection = display->scroll.connect (sigc::mem_fun (*this, &AudioClock::scroll));
1748 button_press_connection = display->button_press.connect (sigc::mem_fun (*this, &AudioClock::button_press));
1749 button_release_connection = display->button_release.connect (sigc::mem_fun (*this, &AudioClock::button_release));
1754 AudioClock::set_mode (Mode m)
1762 display->clear_cells ();
1764 if (supplemental_left) {
1765 supplemental_left->clear_cells ();
1766 supplemental_right->clear_cells ();
1771 display->add_cell (_text_cells[Timecode_Hours]);
1772 display->add_cell (_fixed_cells[Colon1]);
1773 display->add_cell (_text_cells[Timecode_Minutes]);
1774 display->add_cell (_fixed_cells[Colon2]);
1775 display->add_cell (_text_cells[Timecode_Seconds]);
1776 display->add_cell (_fixed_cells[Colon3]);
1777 display->add_cell (_text_cells[Timecode_Frames]);
1779 if (supplemental_left) {
1780 supplemental_left->add_cell (_text_cells[LowerLeft1]);
1781 supplemental_left->add_cell (_text_cells[LowerLeft2]);
1782 supplemental_right->add_cell (_text_cells[LowerRight1]);
1783 supplemental_right->add_cell (_text_cells[LowerRight2]);
1785 supplemental_left->set_width_chars (_text_cells[LowerLeft1], 4);
1786 supplemental_left->set_width_chars (_text_cells[LowerLeft2], 8);
1788 supplemental_right->set_width_chars (_text_cells[LowerRight1], 4);
1789 supplemental_right->set_width_chars (_text_cells[LowerRight2], 6.25);
1791 supplemental_left->set_text (_text_cells[LowerLeft1], _("EXT"));
1792 supplemental_right->set_text (_text_cells[LowerRight1], _("FPS"));
1797 display->add_cell (_text_cells[Bars]);
1798 display->add_cell (_fixed_cells[Bar1]);
1799 display->add_cell (_text_cells[Beats]);
1800 display->add_cell (_fixed_cells[Bar2]);
1801 display->add_cell (_text_cells[Ticks]);
1802 if (supplemental_left) {
1803 supplemental_left->add_cell (_text_cells[LowerLeft1]);
1804 supplemental_left->add_cell (_text_cells[LowerLeft2]);
1805 supplemental_right->add_cell (_text_cells[LowerRight1]);
1806 supplemental_right->add_cell (_text_cells[LowerRight2]);
1808 supplemental_left->set_width_chars (_text_cells[LowerLeft1], 1);
1809 supplemental_left->set_width_chars (_text_cells[LowerLeft2], 5.25);
1811 supplemental_right->set_width_chars (_text_cells[LowerRight1], 1);
1812 supplemental_right->set_width_chars (_text_cells[LowerRight2], 5);
1814 supplemental_left->set_text (_text_cells[LowerLeft1], _("M"));
1815 supplemental_right->set_text (_text_cells[LowerRight1], _("T"));
1820 display->add_cell (_text_cells[MS_Hours]);
1821 display->add_cell (_fixed_cells[Colon1]);
1822 display->add_cell (_text_cells[MS_Minutes]);
1823 display->add_cell (_fixed_cells[Colon2]);
1824 display->add_cell (_text_cells[MS_Seconds]);
1825 display->add_cell (_fixed_cells[Colon3]);
1826 display->add_cell (_text_cells[MS_Milliseconds]);
1830 display->add_cell (_text_cells[AudioFrames]);
1831 if (supplemental_left) {
1832 supplemental_left->add_cell (_text_cells[LowerLeft1]);
1833 supplemental_left->add_cell (_text_cells[LowerLeft2]);
1834 supplemental_right->add_cell (_text_cells[LowerRight1]);
1835 supplemental_right->add_cell (_text_cells[LowerRight2]);
1837 supplemental_left->set_width_chars (_text_cells[LowerLeft1], 3);
1838 supplemental_left->set_width_chars (_text_cells[LowerLeft2], 5);
1840 supplemental_right->set_width_chars (_text_cells[LowerRight1], 5);
1841 supplemental_right->set_width_chars (_text_cells[LowerRight2], 5);
1843 supplemental_left->set_text (_text_cells[LowerLeft1], _("SR"));
1844 supplemental_right->set_text (_text_cells[LowerRight1], _("Pull"));
1852 if (supplemental_left) {
1853 /* clear information cells */
1854 supplemental_left->set_text (_text_cells[LowerLeft2], _(""));
1855 supplemental_right->set_text (_text_cells[LowerRight2], _(""));
1857 /* propagate font style,but smaller, into cells */
1858 boost::shared_ptr<CairoFontDescription> smaller_font (new CairoFontDescription (*display->font().get()));
1859 smaller_font->set_size (12);
1860 supplemental_right->set_font (smaller_font);
1861 supplemental_left->set_font (smaller_font);
1867 disconnect_signals ();
1870 set (last_when, true);
1872 if (!is_transient) {
1873 ModeChanged (); /* EMIT SIGNAL (the static one)*/
1876 mode_changed (); /* EMIT SIGNAL (the member one) */
1880 AudioClock::set_bbt_reference (framepos_t pos)
1882 bbt_reference_time = pos;
1886 AudioClock::on_style_changed (const Glib::RefPtr<Gtk::Style>& old_style)
1888 VBox::on_style_changed (old_style);
1893 AudioClock::set_is_duration (bool yn)
1895 if (yn == is_duration) {
1900 set (last_when, true, 0, 's');