2 Copyright (C) 2000 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.
21 #include "gtk2ardour-config.h"
24 #include <cstdio> // for sprintf, grrr
30 #include <gtk/gtkaction.h>
32 #include "canvas/group.h"
33 #include "canvas/canvas.h"
34 #include "canvas/ruler.h"
35 #include "canvas/debug.h"
37 #include "ardour/session.h"
38 #include "ardour/tempo.h"
39 #include "ardour/profile.h"
41 #include "gtkmm2ext/gtk_ui.h"
46 #include "gui_thread.h"
47 #include "time_axis_view.h"
48 #include "editor_drag.h"
49 #include "editor_cursors.h"
54 using namespace ARDOUR;
57 using namespace Editing;
59 /* the order here must match the "metric" enums in editor.h */
61 class TimecodeMetric : public ArdourCanvas::Ruler::Metric
64 TimecodeMetric (Editor* e) : _editor (e) {}
66 void get_marks (std::vector<ArdourCanvas::Ruler::Mark>& marks, double lower, double upper, int maxchars) const {
67 _editor->metric_get_timecode (marks, lower, upper, maxchars);
74 class SamplesMetric : public ArdourCanvas::Ruler::Metric
77 SamplesMetric (Editor* e) : _editor (e) {}
79 void get_marks (std::vector<ArdourCanvas::Ruler::Mark>& marks, double lower, double upper, int maxchars) const {
80 _editor->metric_get_samples (marks, lower, upper, maxchars);
87 class BBTMetric : public ArdourCanvas::Ruler::Metric
90 BBTMetric (Editor* e) : _editor (e) {}
92 void get_marks (std::vector<ArdourCanvas::Ruler::Mark>& marks, double lower, double upper, int maxchars) const {
93 _editor->metric_get_bbt (marks, lower, upper, maxchars);
100 class MinsecMetric : public ArdourCanvas::Ruler::Metric
103 MinsecMetric (Editor* e) : _editor (e) {}
105 void get_marks (std::vector<ArdourCanvas::Ruler::Mark>& marks, double lower, double upper, int maxchars) const {
106 _editor->metric_get_minsec (marks, lower, upper, maxchars);
113 static ArdourCanvas::Ruler::Metric* _bbt_metric;
114 static ArdourCanvas::Ruler::Metric* _timecode_metric;
115 static ArdourCanvas::Ruler::Metric* _samples_metric;
116 static ArdourCanvas::Ruler::Metric* _minsec_metric;
119 Editor::initialize_rulers ()
121 ruler_grabbed_widget = 0;
122 Pango::FontDescription font = get_font_for_style ("editor_time_ruler");
124 _timecode_metric = new TimecodeMetric (this);
125 _bbt_metric = new BBTMetric (this);
126 _minsec_metric = new MinsecMetric (this);
127 _samples_metric = new SamplesMetric (this);
129 timecode_ruler = new ArdourCanvas::Ruler (_time_markers_group, *_timecode_metric);
130 timecode_ruler->set_size (ArdourCanvas::Rect (0, 0, ArdourCanvas::COORD_MAX, timebar_height));
131 timecode_ruler->set_font_description (font);
132 CANVAS_DEBUG_NAME (timecode_ruler, "timecode ruler");
135 samples_ruler = new ArdourCanvas::Ruler (_time_markers_group, *_samples_metric);
136 samples_ruler->set_size (ArdourCanvas::Rect (0, 0, ArdourCanvas::COORD_MAX, timebar_height));
137 samples_ruler->set_font_description (font);
138 CANVAS_DEBUG_NAME (samples_ruler, "samples ruler");
140 minsec_ruler = new ArdourCanvas::Ruler (_time_markers_group, *_minsec_metric);
141 minsec_ruler->set_size (ArdourCanvas::Rect (0, 0, ArdourCanvas::COORD_MAX, timebar_height));
142 minsec_ruler->set_font_description (font);
143 CANVAS_DEBUG_NAME (minsec_ruler, "minsec ruler");
146 bbt_ruler = new ArdourCanvas::Ruler (_time_markers_group, *_bbt_metric);
147 bbt_ruler->set_size (ArdourCanvas::Rect (0, 0, ArdourCanvas::COORD_MAX, timebar_height));
148 bbt_ruler->set_font_description (font);
149 CANVAS_DEBUG_NAME (bbt_ruler, "bbt ruler");
152 using namespace Box_Helpers;
153 BoxList & lab_children = time_bars_vbox.children();
155 lab_children.push_back (Element(minsec_label, PACK_SHRINK, PACK_START));
156 lab_children.push_back (Element(timecode_label, PACK_SHRINK, PACK_START));
157 lab_children.push_back (Element(samples_label, PACK_SHRINK, PACK_START));
158 lab_children.push_back (Element(bbt_label, PACK_SHRINK, PACK_START));
159 lab_children.push_back (Element(meter_label, PACK_SHRINK, PACK_START));
160 lab_children.push_back (Element(tempo_label, PACK_SHRINK, PACK_START));
161 lab_children.push_back (Element(range_mark_label, PACK_SHRINK, PACK_START));
162 lab_children.push_back (Element(transport_mark_label, PACK_SHRINK, PACK_START));
163 lab_children.push_back (Element(cd_mark_label, PACK_SHRINK, PACK_START));
164 lab_children.push_back (Element(mark_label, PACK_SHRINK, PACK_START));
165 lab_children.push_back (Element(videotl_label, PACK_SHRINK, PACK_START));
167 // timecode_ruler->Event.connect (...);
168 // samples_ruler->Event.connect (...);
169 // bbt_ruler->Event.connect (...);
170 // minsec_ruler->Event.connect (...);
172 visible_timebars = 0; /*this will be changed below */
176 Editor::ruler_scroll (GdkEventScroll* event)
179 int direction = event->direction;
180 bool handled = false;
184 temporal_zoom_step (false);
188 case GDK_SCROLL_DOWN:
189 temporal_zoom_step (true);
193 case GDK_SCROLL_LEFT:
194 xdelta = (current_page_samples() / 2);
195 if (leftmost_frame > xdelta) {
196 reset_x_origin (leftmost_frame - xdelta);
203 case GDK_SCROLL_RIGHT:
204 xdelta = (current_page_samples() / 2);
205 if (max_framepos - xdelta > leftmost_frame) {
206 reset_x_origin (leftmost_frame + xdelta);
208 reset_x_origin (max_framepos - current_page_samples());
223 Editor::ruler_button_press (GdkEventButton* /*ev*/)
231 Widget * grab_widget = 0;
233 if (bbt_ruler->is_realized() && ev->window == bbt_ruler->get_window()->gobj()) {
234 grab_widget = bbt_ruler;
235 } else if (samples_ruler->is_realized() && ev->window == samples_ruler->get_window()->gobj()) {
236 grab_widget = samples_ruler;
237 } else if (minsec_ruler->is_realized() && ev->window == minsec_ruler->get_window()->gobj()) {
238 grab_widget = minsec_ruler;
242 grab_widget->add_modal_grab ();
243 ruler_grabbed_widget = grab_widget;
246 if (ev->button == 1) {
247 // Since we will locate the playhead on button release, cancel any running
249 if (_session->is_auditioning()) {
250 _session->cancel_audition ();
253 /* playhead cursor drag: CursorDrag expects an event with
254 * canvas coordinates, so convert from window coordinates,
255 * since for now, rulers are still Gtk::Widgets.
258 GdkEventButton canvas_ev = *ev;
259 ArdourCanvas::Duple d = _track_canvas->window_to_canvas (ArdourCanvas::Duple (ev->x, ev->y));
260 canvas_ev.x = rint (d.x);
261 canvas_ev.y = rint (d.y);
263 _drags->set (new CursorDrag (this, *playhead_cursor, false), reinterpret_cast<GdkEvent *> (&canvas_ev));
264 _dragging_playhead = true;
272 Editor::ruler_button_release (GdkEventButton* ev)
278 if (_drags->active ()) {
279 GdkEventButton canvas_ev = *ev;
280 ArdourCanvas::Duple d = _track_canvas->window_to_canvas (ArdourCanvas::Duple (ev->x, ev->y));
281 canvas_ev.x = rint (d.x);
282 canvas_ev.x = rint (d.y);
283 _drags->end_grab (reinterpret_cast<GdkEvent*> (&canvas_ev));
284 _dragging_playhead = false;
287 if (ev->button == 3) {
289 stop_canvas_autoscroll();
291 framepos_t where = window_event_sample ((GdkEvent*) ev);
294 popup_ruler_menu (where);
297 if (ruler_grabbed_widget) {
298 ruler_grabbed_widget->remove_modal_grab();
299 ruler_grabbed_widget = 0;
306 Editor::ruler_label_button_release (GdkEventButton* ev)
308 if (ev->button == 3) {
309 Gtk::Menu* m = dynamic_cast<Gtk::Menu*> (ActionManager::get_widget (X_("/RulerMenuPopup")));
311 m->popup (1, ev->time);
320 Editor::ruler_mouse_motion (GdkEventMotion* ev)
326 if (_drags->active ()) {
327 GdkEventMotion canvas_ev = *ev;
328 ArdourCanvas::Duple d = _track_canvas->window_to_canvas (ArdourCanvas::Duple (ev->x, ev->y));
329 canvas_ev.x = rint (d.x);
330 canvas_ev.y = rint (d.y);
331 _drags->window_motion_handler (reinterpret_cast<GdkEvent*> (&canvas_ev), false);
339 Editor::popup_ruler_menu (framepos_t where, ItemType t)
341 using namespace Menu_Helpers;
343 if (editor_ruler_menu == 0) {
344 editor_ruler_menu = new Menu;
345 editor_ruler_menu->set_name ("ArdourContextMenu");
348 // always build from scratch
349 MenuList& ruler_items = editor_ruler_menu->items();
350 editor_ruler_menu->set_name ("ArdourContextMenu");
355 ruler_items.push_back (MenuElem (_("New location marker"), sigc::bind ( sigc::mem_fun(*this, &Editor::mouse_add_new_marker), where, false, false)));
356 ruler_items.push_back (MenuElem (_("Clear all locations"), sigc::mem_fun(*this, &Editor::clear_markers)));
357 ruler_items.push_back (MenuElem (_("Unhide locations"), sigc::mem_fun(*this, &Editor::unhide_markers)));
358 ruler_items.push_back (SeparatorElem ());
360 case RangeMarkerBarItem:
361 ruler_items.push_back (MenuElem (_("New range"), sigc::bind (sigc::mem_fun (*this, &Editor::mouse_add_new_range), where)));
362 ruler_items.push_back (MenuElem (_("Clear all ranges"), sigc::mem_fun(*this, &Editor::clear_ranges)));
363 ruler_items.push_back (MenuElem (_("Unhide ranges"), sigc::mem_fun(*this, &Editor::unhide_ranges)));
364 ruler_items.push_back (SeparatorElem ());
367 case TransportMarkerBarItem:
371 case CdMarkerBarItem:
373 ruler_items.push_back (MenuElem (_("New CD track marker"), sigc::bind ( sigc::mem_fun(*this, &Editor::mouse_add_new_marker), where, true, false)));
378 ruler_items.push_back (MenuElem (_("New Tempo"), sigc::bind ( sigc::mem_fun(*this, &Editor::mouse_add_new_tempo_event), where)));
379 ruler_items.push_back (SeparatorElem ());
383 ruler_items.push_back (MenuElem (_("New Meter"), sigc::bind ( sigc::mem_fun(*this, &Editor::mouse_add_new_meter_event), where)));
384 ruler_items.push_back (SeparatorElem ());
388 ruler_items.push_back (MenuElem (_("Timeline height")));
389 static_cast<MenuItem*>(&ruler_items.back())->set_sensitive(false);
390 ruler_items.push_back (CheckMenuElem (_("Large"), sigc::bind ( sigc::mem_fun(*this, &Editor::set_video_timeline_height), 6)));
391 if (videotl_bar_height == 6) { static_cast<Gtk::CheckMenuItem*>(&ruler_items.back())->set_active(true);}
392 ruler_items.push_back (CheckMenuElem (_("Normal"), sigc::bind ( sigc::mem_fun(*this, &Editor::set_video_timeline_height), 4)));
393 if (videotl_bar_height == 4) { static_cast<Gtk::CheckMenuItem*>(&ruler_items.back())->set_active(true);}
394 ruler_items.push_back (CheckMenuElem (_("Small"), sigc::bind ( sigc::mem_fun(*this, &Editor::set_video_timeline_height), 3)));
395 if (videotl_bar_height == 3) { static_cast<Gtk::CheckMenuItem*>(&ruler_items.back())->set_active(true);}
396 ruler_items.push_back (SeparatorElem ());
398 ruler_items.push_back (MenuElem (_("Align Video Track")));
399 static_cast<MenuItem*>(&ruler_items.back())->set_sensitive(false);
401 ruler_items.push_back (CheckMenuElem (_("Lock")));
403 Gtk::CheckMenuItem* vtl_lock = static_cast<Gtk::CheckMenuItem*>(&ruler_items.back());
404 vtl_lock->set_active(is_video_timeline_locked());
405 vtl_lock->signal_activate().connect (sigc::mem_fun(*this, &Editor::toggle_video_timeline_locked));
408 ruler_items.push_back (SeparatorElem ());
415 Glib::RefPtr<Action> action;
417 action = ActionManager::get_action ("Rulers", "toggle-minsec-ruler");
419 ruler_items.push_back (MenuElem (*action->create_menu_item()));
421 if (!Profile->get_sae()) {
422 action = ActionManager::get_action ("Rulers", "toggle-timecode-ruler");
424 ruler_items.push_back (MenuElem (*action->create_menu_item()));
427 action = ActionManager::get_action ("Rulers", "toggle-samples-ruler");
429 ruler_items.push_back (MenuElem (*action->create_menu_item()));
431 action = ActionManager::get_action ("Rulers", "toggle-bbt-ruler");
433 ruler_items.push_back (MenuElem (*action->create_menu_item()));
435 action = ActionManager::get_action ("Rulers", "toggle-meter-ruler");
437 ruler_items.push_back (MenuElem (*action->create_menu_item()));
439 action = ActionManager::get_action ("Rulers", "toggle-tempo-ruler");
441 ruler_items.push_back (MenuElem (*action->create_menu_item()));
443 if (!Profile->get_sae()) {
444 action = ActionManager::get_action ("Rulers", "toggle-range-ruler");
446 ruler_items.push_back (MenuElem (*action->create_menu_item()));
449 action = ActionManager::get_action ("Rulers", "toggle-loop-punch-ruler");
451 ruler_items.push_back (MenuElem (*action->create_menu_item()));
453 action = ActionManager::get_action ("Rulers", "toggle-cd-marker-ruler");
455 ruler_items.push_back (MenuElem (*action->create_menu_item()));
457 action = ActionManager::get_action ("Rulers", "toggle-marker-ruler");
459 ruler_items.push_back (MenuElem (*action->create_menu_item()));
461 action = ActionManager::get_action ("Rulers", "toggle-video-ruler");
463 ruler_items.push_back (MenuElem (*action->create_menu_item()));
466 editor_ruler_menu->popup (1, gtk_get_current_event_time());
468 no_ruler_shown_update = false;
472 Editor::store_ruler_visibility ()
474 XMLNode* node = new XMLNode(X_("RulerVisibility"));
476 node->add_property (X_("timecode"), ruler_timecode_action->get_active() ? "yes": "no");
477 node->add_property (X_("bbt"), ruler_bbt_action->get_active() ? "yes": "no");
478 node->add_property (X_("samples"), ruler_samples_action->get_active() ? "yes": "no");
479 node->add_property (X_("minsec"), ruler_minsec_action->get_active() ? "yes": "no");
480 node->add_property (X_("tempo"), ruler_tempo_action->get_active() ? "yes": "no");
481 node->add_property (X_("meter"), ruler_meter_action->get_active() ? "yes": "no");
482 node->add_property (X_("marker"), ruler_marker_action->get_active() ? "yes": "no");
483 node->add_property (X_("rangemarker"), ruler_range_action->get_active() ? "yes": "no");
484 node->add_property (X_("transportmarker"), ruler_loop_punch_action->get_active() ? "yes": "no");
485 node->add_property (X_("cdmarker"), ruler_cd_marker_action->get_active() ? "yes": "no");
486 node->add_property (X_("videotl"), ruler_video_action->get_active() ? "yes": "no");
488 _session->add_extra_xml (*node);
489 _session->set_dirty ();
493 Editor::restore_ruler_visibility ()
496 XMLNode * node = _session->extra_xml (X_("RulerVisibility"));
498 no_ruler_shown_update = true;
501 if ((prop = node->property ("timecode")) != 0) {
502 if (string_is_affirmative (prop->value())) {
503 ruler_timecode_action->set_active (true);
505 ruler_timecode_action->set_active (false);
508 if ((prop = node->property ("bbt")) != 0) {
509 if (string_is_affirmative (prop->value())) {
510 ruler_bbt_action->set_active (true);
512 ruler_bbt_action->set_active (false);
515 if ((prop = node->property ("samples")) != 0) {
516 if (string_is_affirmative (prop->value())) {
517 ruler_samples_action->set_active (true);
519 ruler_samples_action->set_active (false);
522 if ((prop = node->property ("minsec")) != 0) {
523 if (string_is_affirmative (prop->value())) {
524 ruler_minsec_action->set_active (true);
526 ruler_minsec_action->set_active (false);
529 if ((prop = node->property ("tempo")) != 0) {
530 if (string_is_affirmative (prop->value())) {
531 ruler_tempo_action->set_active (true);
533 ruler_tempo_action->set_active (false);
536 if ((prop = node->property ("meter")) != 0) {
537 if (string_is_affirmative (prop->value())) {
538 ruler_meter_action->set_active (true);
540 ruler_meter_action->set_active (false);
543 if ((prop = node->property ("marker")) != 0) {
544 if (string_is_affirmative (prop->value())) {
545 ruler_marker_action->set_active (true);
547 ruler_marker_action->set_active (false);
550 if ((prop = node->property ("rangemarker")) != 0) {
551 if (string_is_affirmative (prop->value())) {
552 ruler_range_action->set_active (true);
554 ruler_range_action->set_active (false);
558 if ((prop = node->property ("transportmarker")) != 0) {
559 if (string_is_affirmative (prop->value())) {
560 ruler_loop_punch_action->set_active (true);
562 ruler_loop_punch_action->set_active (false);
566 if ((prop = node->property ("cdmarker")) != 0) {
567 if (string_is_affirmative (prop->value())) {
568 ruler_cd_marker_action->set_active (true);
570 ruler_cd_marker_action->set_active (false);
574 // this _session doesn't yet know about the cdmarker ruler
575 // as a benefit to the user who doesn't know the feature exists, show the ruler if
576 // any cd marks exist
577 ruler_cd_marker_action->set_active (false);
578 const Locations::LocationList & locs = _session->locations()->list();
579 for (Locations::LocationList::const_iterator i = locs.begin(); i != locs.end(); ++i) {
580 if ((*i)->is_cd_marker()) {
581 ruler_cd_marker_action->set_active (true);
587 if ((prop = node->property ("videotl")) != 0) {
588 if (string_is_affirmative (prop->value())) {
589 ruler_video_action->set_active (true);
591 ruler_video_action->set_active (false);
597 no_ruler_shown_update = false;
598 update_ruler_visibility ();
602 Editor::update_ruler_visibility ()
604 int visible_timebars = 0;
606 if (no_ruler_shown_update) {
610 /* the order of the timebars is fixed, so we have to go through each one
611 * and adjust its position depending on what is shown.
613 * Order: minsec, timecode, samples, bbt, meter, tempo, ranges,
614 * loop/punch, cd markers, location markers
622 /* gtk update probs require this (damn) */
625 range_mark_label.hide();
626 transport_mark_label.hide();
627 cd_mark_label.hide();
629 videotl_label.hide();
632 if (ruler_minsec_action->get_active()) {
633 old_unit_pos = minsec_ruler->position().y;
634 if (tbpos != old_unit_pos) {
635 minsec_ruler->move (ArdourCanvas::Duple (0.0, tbpos - old_unit_pos));
637 minsec_ruler->show();
639 tbpos += timebar_height;
640 tbgpos += timebar_height;
643 minsec_ruler->hide();
647 if (ruler_timecode_action->get_active()) {
648 old_unit_pos = timecode_ruler->position().y;
649 if (tbpos != old_unit_pos) {
650 timecode_ruler->move (ArdourCanvas::Duple (0.0, tbpos - old_unit_pos));
652 timecode_ruler->show();
653 timecode_label.show();
654 tbpos += timebar_height;
655 tbgpos += timebar_height;
658 timecode_ruler->hide();
659 timecode_label.hide();
662 if (ruler_samples_action->get_active()) {
663 old_unit_pos = samples_ruler->position().y;
664 if (tbpos != old_unit_pos) {
665 samples_ruler->move (ArdourCanvas::Duple (0.0, tbpos - old_unit_pos));
667 samples_ruler->show();
668 samples_label.show();
669 tbpos += timebar_height;
670 tbgpos += timebar_height;
673 samples_ruler->hide();
674 samples_label.hide();
677 if (ruler_bbt_action->get_active()) {
678 old_unit_pos = bbt_ruler->position().y;
679 if (tbpos != old_unit_pos) {
680 bbt_ruler->move (ArdourCanvas::Duple (0.0, tbpos - old_unit_pos));
684 tbpos += timebar_height;
685 tbgpos += timebar_height;
692 if (ruler_meter_action->get_active()) {
693 old_unit_pos = meter_group->position().y;
694 if (tbpos != old_unit_pos) {
695 meter_group->move (ArdourCanvas::Duple (0.0, tbpos - old_unit_pos));
699 tbpos += timebar_height;
700 tbgpos += timebar_height;
707 if (ruler_tempo_action->get_active()) {
708 old_unit_pos = tempo_group->position().y;
709 if (tbpos != old_unit_pos) {
710 tempo_group->move (ArdourCanvas::Duple (0.0, tbpos - old_unit_pos));
714 tbpos += timebar_height;
715 tbgpos += timebar_height;
722 if (!Profile->get_sae() && ruler_range_action->get_active()) {
723 old_unit_pos = range_marker_group->position().y;
724 if (tbpos != old_unit_pos) {
725 range_marker_group->move (ArdourCanvas::Duple (0.0, tbpos - old_unit_pos));
727 range_marker_group->show();
728 range_mark_label.show();
730 tbpos += timebar_height;
731 tbgpos += timebar_height;
734 range_marker_group->hide();
735 range_mark_label.hide();
738 if (ruler_loop_punch_action->get_active()) {
739 old_unit_pos = transport_marker_group->position().y;
740 if (tbpos != old_unit_pos) {
741 transport_marker_group->move (ArdourCanvas::Duple (0.0, tbpos - old_unit_pos));
743 transport_marker_group->show();
744 transport_mark_label.show();
745 tbpos += timebar_height;
746 tbgpos += timebar_height;
749 transport_marker_group->hide();
750 transport_mark_label.hide();
753 if (ruler_cd_marker_action->get_active()) {
754 old_unit_pos = cd_marker_group->position().y;
755 if (tbpos != old_unit_pos) {
756 cd_marker_group->move (ArdourCanvas::Duple (0.0, tbpos - old_unit_pos));
758 cd_marker_group->show();
759 cd_mark_label.show();
760 tbpos += timebar_height;
761 tbgpos += timebar_height;
763 // make sure all cd markers show up in their respective places
764 update_cd_marker_display();
766 cd_marker_group->hide();
767 cd_mark_label.hide();
768 // make sure all cd markers show up in their respective places
769 update_cd_marker_display();
772 if (ruler_marker_action->get_active()) {
773 old_unit_pos = marker_group->position().y;
774 if (tbpos != old_unit_pos) {
775 marker_group->move (ArdourCanvas::Duple (0.0, tbpos - old_unit_pos));
777 marker_group->show();
779 tbpos += timebar_height;
780 tbgpos += timebar_height;
783 marker_group->hide();
787 if (ruler_video_action->get_active()) {
788 old_unit_pos = videotl_group->position().y;
789 if (tbpos != old_unit_pos) {
790 videotl_group->move (ArdourCanvas::Duple (0.0, tbpos - old_unit_pos));
792 videotl_group->show();
793 videotl_label.show();
794 tbpos += timebar_height * videotl_bar_height;
795 tbgpos += timebar_height * videotl_bar_height;
796 visible_timebars+=videotl_bar_height;
797 queue_visual_videotimeline_update();
799 videotl_group->hide();
800 videotl_label.hide();
801 update_video_timeline(true);
804 time_bars_vbox.set_size_request (-1, (int)(timebar_height * visible_timebars));
806 /* move hv_scroll_group (trackviews) to the end of the timebars
809 hv_scroll_group->set_y_position (timebar_height * visible_timebars);
811 compute_fixed_ruler_scale ();
812 update_fixed_rulers();
813 redisplay_tempo (false);
815 /* Changing ruler visibility means that any lines on markers might need updating */
816 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
817 i->second->setup_lines ();
822 Editor::update_just_timecode ()
824 ENSURE_GUI_THREAD (*this, &Editor::update_just_timecode)
830 framepos_t rightmost_frame = leftmost_frame + current_page_samples();
832 if (ruler_timecode_action->get_active()) {
833 timecode_ruler->set_range (leftmost_frame, rightmost_frame);
838 Editor::compute_fixed_ruler_scale ()
844 if (ruler_timecode_action->get_active()) {
845 set_timecode_ruler_scale (leftmost_frame, leftmost_frame + current_page_samples());
848 if (ruler_minsec_action->get_active()) {
849 set_minsec_ruler_scale (leftmost_frame, leftmost_frame + current_page_samples());
852 if (ruler_samples_action->get_active()) {
853 set_samples_ruler_scale (leftmost_frame, leftmost_frame + current_page_samples());
858 Editor::update_fixed_rulers ()
860 framepos_t rightmost_frame;
866 compute_fixed_ruler_scale ();
868 _timecode_metric->units_per_pixel = samples_per_pixel;
869 _samples_metric->units_per_pixel = samples_per_pixel;
870 _minsec_metric->units_per_pixel = samples_per_pixel;
872 rightmost_frame = leftmost_frame + current_page_samples();
874 /* these force a redraw, which in turn will force execution of the metric callbacks
875 to compute the relevant ticks to display.
878 if (ruler_timecode_action->get_active()) {
879 timecode_ruler->set_range (leftmost_frame, rightmost_frame);
882 if (ruler_samples_action->get_active()) {
883 samples_ruler->set_range (leftmost_frame, rightmost_frame);
886 if (ruler_minsec_action->get_active()) {
887 minsec_ruler->set_range (leftmost_frame, rightmost_frame);
892 Editor::update_tempo_based_rulers (ARDOUR::TempoMap::BBTPointList::const_iterator& begin,
893 ARDOUR::TempoMap::BBTPointList::const_iterator& end)
899 compute_bbt_ruler_scale (leftmost_frame, leftmost_frame+current_page_samples(),
902 _bbt_metric->units_per_pixel = samples_per_pixel;
904 if (ruler_bbt_action->get_active()) {
905 bbt_ruler->set_range (leftmost_frame, leftmost_frame+current_page_samples());
910 Editor::set_timecode_ruler_scale (framepos_t lower, framepos_t upper)
919 fr = _session->frame_rate();
921 if (lower > (spacer = (framepos_t) (128 * Editor::get_current_zoom ()))) {
922 lower = lower - spacer;
926 upper = upper + spacer;
927 framecnt_t const range = upper - lower;
929 if (range < (2 * _session->frames_per_timecode_frame())) { /* 0 - 2 frames */
930 timecode_ruler_scale = timecode_show_bits;
931 timecode_mark_modulo = 20;
932 timecode_nmarks = 2 + (2 * _session->config.get_subframes_per_frame());
933 } else if (range <= (fr / 4)) { /* 2 frames - 0.250 second */
934 timecode_ruler_scale = timecode_show_frames;
935 timecode_mark_modulo = 1;
936 timecode_nmarks = 2 + (range / (framepos_t)_session->frames_per_timecode_frame());
937 } else if (range <= (fr / 2)) { /* 0.25-0.5 second */
938 timecode_ruler_scale = timecode_show_frames;
939 timecode_mark_modulo = 2;
940 timecode_nmarks = 2 + (range / (framepos_t)_session->frames_per_timecode_frame());
941 } else if (range <= fr) { /* 0.5-1 second */
942 timecode_ruler_scale = timecode_show_frames;
943 timecode_mark_modulo = 5;
944 timecode_nmarks = 2 + (range / (framepos_t)_session->frames_per_timecode_frame());
945 } else if (range <= 2 * fr) { /* 1-2 seconds */
946 timecode_ruler_scale = timecode_show_frames;
947 timecode_mark_modulo = 10;
948 timecode_nmarks = 2 + (range / (framepos_t)_session->frames_per_timecode_frame());
949 } else if (range <= 8 * fr) { /* 2-8 seconds */
950 timecode_ruler_scale = timecode_show_seconds;
951 timecode_mark_modulo = 1;
952 timecode_nmarks = 2 + (range / fr);
953 } else if (range <= 16 * fr) { /* 8-16 seconds */
954 timecode_ruler_scale = timecode_show_seconds;
955 timecode_mark_modulo = 2;
956 timecode_nmarks = 2 + (range / fr);
957 } else if (range <= 30 * fr) { /* 16-30 seconds */
958 timecode_ruler_scale = timecode_show_seconds;
959 timecode_mark_modulo = 5;
960 timecode_nmarks = 2 + (range / fr);
961 } else if (range <= 60 * fr) { /* 30-60 seconds */
962 timecode_ruler_scale = timecode_show_seconds;
963 timecode_mark_modulo = 5;
964 timecode_nmarks = 2 + (range / fr);
965 } else if (range <= 2 * 60 * fr) { /* 1-2 minutes */
966 timecode_ruler_scale = timecode_show_seconds;
967 timecode_mark_modulo = 15;
968 timecode_nmarks = 2 + (range / fr);
969 } else if (range <= 4 * 60 * fr) { /* 2-4 minutes */
970 timecode_ruler_scale = timecode_show_seconds;
971 timecode_mark_modulo = 30;
972 timecode_nmarks = 2 + (range / fr);
973 } else if (range <= 10 * 60 * fr) { /* 4-10 minutes */
974 timecode_ruler_scale = timecode_show_minutes;
975 timecode_mark_modulo = 2;
976 timecode_nmarks = 2 + 10;
977 } else if (range <= 30 * 60 * fr) { /* 10-30 minutes */
978 timecode_ruler_scale = timecode_show_minutes;
979 timecode_mark_modulo = 5;
980 timecode_nmarks = 2 + 30;
981 } else if (range <= 60 * 60 * fr) { /* 30 minutes - 1hr */
982 timecode_ruler_scale = timecode_show_minutes;
983 timecode_mark_modulo = 10;
984 timecode_nmarks = 2 + 60;
985 } else if (range <= 4 * 60 * 60 * fr) { /* 1 - 4 hrs*/
986 timecode_ruler_scale = timecode_show_minutes;
987 timecode_mark_modulo = 30;
988 timecode_nmarks = 2 + (60 * 4);
989 } else if (range <= 8 * 60 * 60 * fr) { /* 4 - 8 hrs*/
990 timecode_ruler_scale = timecode_show_hours;
991 timecode_mark_modulo = 1;
992 timecode_nmarks = 2 + 8;
993 } else if (range <= 16 * 60 * 60 * fr) { /* 16-24 hrs*/
994 timecode_ruler_scale = timecode_show_hours;
995 timecode_mark_modulo = 1;
996 timecode_nmarks = 2 + 24;
999 /* not possible if framepos_t is a 32 bit quantity */
1001 timecode_ruler_scale = timecode_show_hours;
1002 timecode_mark_modulo = 4;
1003 timecode_nmarks = 2 + 24;
1009 Editor::metric_get_timecode (std::vector<ArdourCanvas::Ruler::Mark>& marks, gdouble lower, gdouble /*upper*/, gint /*maxchars*/)
1013 Timecode::Time timecode;
1016 ArdourCanvas::Ruler::Mark mark;
1018 if (_session == 0) {
1022 if (lower > (spacer = (framecnt_t)(128 * Editor::get_current_zoom ()))) {
1023 lower = lower - spacer;
1028 pos = (framecnt_t) floor (lower);
1030 switch (timecode_ruler_scale) {
1031 case timecode_show_bits:
1033 // Find timecode time of this sample (pos) with subframe accuracy
1034 _session->sample_to_timecode(pos, timecode, true /* use_offset */, true /* use_subframes */ );
1036 for (n = 0; n < timecode_nmarks; n++) {
1037 _session->timecode_to_sample(timecode, pos, true /* use_offset */, true /* use_subframes */ );
1038 if ((timecode.subframes % timecode_mark_modulo) == 0) {
1039 if (timecode.subframes == 0) {
1040 mark.style = ArdourCanvas::Ruler::Mark::Major;
1041 snprintf (buf, sizeof(buf), "%s%02u:%02u:%02u:%02u", timecode.negative ? "-" : "", timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
1043 mark.style = ArdourCanvas::Ruler::Mark::Minor;
1044 snprintf (buf, sizeof(buf), ".%02u", timecode.subframes);
1047 snprintf (buf, sizeof(buf)," ");
1048 mark.style = ArdourCanvas::Ruler::Mark::Micro;
1052 mark.position = pos;
1054 marks.push_back (mark);
1056 // Increment subframes by one
1057 Timecode::increment_subframes( timecode, _session->config.get_subframes_per_frame() );
1060 case timecode_show_seconds:
1061 // Find timecode time of this sample (pos)
1062 _session->sample_to_timecode(pos, timecode, true /* use_offset */, false /* use_subframes */ );
1063 // Go to next whole second down
1064 Timecode::seconds_floor( timecode );
1066 for (n = 0; n < timecode_nmarks; n++) {
1067 _session->timecode_to_sample(timecode, pos, true /* use_offset */, false /* use_subframes */ );
1068 if ((timecode.seconds % timecode_mark_modulo) == 0) {
1069 if (timecode.seconds == 0) {
1070 mark.style = ArdourCanvas::Ruler::Mark::Major;
1071 mark.position = pos;
1073 mark.style = ArdourCanvas::Ruler::Mark::Minor;
1074 mark.position = pos;
1076 snprintf (buf, sizeof(buf), "%s%02u:%02u:%02u:%02u", timecode.negative ? "-" : "", timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
1078 snprintf (buf, sizeof(buf)," ");
1079 mark.style = ArdourCanvas::Ruler::Mark::Micro;
1080 mark.position = pos;
1084 marks.push_back (mark);
1086 Timecode::increment_seconds( timecode, _session->config.get_subframes_per_frame() );
1089 case timecode_show_minutes:
1090 // Find timecode time of this sample (pos)
1091 _session->sample_to_timecode(pos, timecode, true /* use_offset */, false /* use_subframes */ );
1092 // Go to next whole minute down
1093 Timecode::minutes_floor( timecode );
1095 for (n = 0; n < timecode_nmarks; n++) {
1096 _session->timecode_to_sample(timecode, pos, true /* use_offset */, false /* use_subframes */ );
1097 if ((timecode.minutes % timecode_mark_modulo) == 0) {
1098 if (timecode.minutes == 0) {
1099 mark.style = ArdourCanvas::Ruler::Mark::Major;
1101 mark.style = ArdourCanvas::Ruler::Mark::Minor;
1103 snprintf (buf, sizeof(buf), "%s%02u:%02u:%02u:%02u", timecode.negative ? "-" : "", timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
1105 snprintf (buf, sizeof(buf)," ");
1106 mark.style = ArdourCanvas::Ruler::Mark::Micro;
1110 mark.position = pos;
1111 marks.push_back (mark);
1112 Timecode::increment_minutes( timecode, _session->config.get_subframes_per_frame() );
1116 case timecode_show_hours:
1117 // Find timecode time of this sample (pos)
1118 _session->sample_to_timecode(pos, timecode, true /* use_offset */, false /* use_subframes */ );
1119 // Go to next whole hour down
1120 Timecode::hours_floor( timecode );
1122 for (n = 0; n < timecode_nmarks; n++) {
1123 _session->timecode_to_sample(timecode, pos, true /* use_offset */, false /* use_subframes */ );
1124 if ((timecode.hours % timecode_mark_modulo) == 0) {
1125 mark.style = ArdourCanvas::Ruler::Mark::Major;
1126 snprintf (buf, sizeof(buf), "%s%02u:%02u:%02u:%02u", timecode.negative ? "-" : "", timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
1128 snprintf (buf, sizeof(buf)," ");
1129 mark.style = ArdourCanvas::Ruler::Mark::Micro;
1133 mark.position = pos;
1134 marks.push_back (mark);
1135 Timecode::increment_hours( timecode, _session->config.get_subframes_per_frame() );
1138 case timecode_show_frames:
1139 // Find timecode time of this sample (pos)
1140 _session->sample_to_timecode(pos, timecode, true /* use_offset */, false /* use_subframes */ );
1141 // Go to next whole frame down
1142 Timecode::frames_floor( timecode );
1144 for (n = 0; n < timecode_nmarks; n++) {
1145 _session->timecode_to_sample(timecode, pos, true /* use_offset */, false /* use_subframes */ );
1146 if ((timecode.frames % timecode_mark_modulo) == 0) {
1147 if (timecode.frames == 0) {
1148 mark.style = ArdourCanvas::Ruler::Mark::Major;
1150 mark.style = ArdourCanvas::Ruler::Mark::Minor;
1152 mark.position = pos;
1153 snprintf (buf, sizeof(buf), "%s%02u:%02u:%02u:%02u", timecode.negative ? "-" : "", timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
1155 snprintf (buf, sizeof(buf)," ");
1156 mark.style = ArdourCanvas::Ruler::Mark::Micro;
1157 mark.position = pos;
1161 marks.push_back (mark);
1162 Timecode::increment( timecode, _session->config.get_subframes_per_frame() );
1172 Editor::compute_bbt_ruler_scale (framepos_t lower, framepos_t upper,
1173 ARDOUR::TempoMap::BBTPointList::const_iterator begin,
1174 ARDOUR::TempoMap::BBTPointList::const_iterator end)
1176 if (_session == 0) {
1180 TempoMap::BBTPointList::const_iterator i;
1181 Timecode::BBT_Time lower_beat, upper_beat; // the beats at each end of the ruler
1183 _session->bbt_time (lower, lower_beat);
1184 _session->bbt_time (upper, upper_beat);
1187 bbt_accent_modulo = 1;
1188 bbt_bar_helper_on = false;
1192 bbt_ruler_scale = bbt_over;
1194 switch (_snap_type) {
1195 case SnapToBeatDiv2:
1196 bbt_beat_subdivision = 2;
1198 case SnapToBeatDiv3:
1199 bbt_beat_subdivision = 3;
1201 case SnapToBeatDiv4:
1202 bbt_beat_subdivision = 4;
1204 case SnapToBeatDiv5:
1205 bbt_beat_subdivision = 5;
1206 bbt_accent_modulo = 2; // XXX YIKES
1208 case SnapToBeatDiv6:
1209 bbt_beat_subdivision = 6;
1210 bbt_accent_modulo = 2; // XXX YIKES
1212 case SnapToBeatDiv7:
1213 bbt_beat_subdivision = 7;
1214 bbt_accent_modulo = 2; // XXX YIKES
1216 case SnapToBeatDiv8:
1217 bbt_beat_subdivision = 8;
1218 bbt_accent_modulo = 2;
1220 case SnapToBeatDiv10:
1221 bbt_beat_subdivision = 10;
1222 bbt_accent_modulo = 2; // XXX YIKES
1224 case SnapToBeatDiv12:
1225 bbt_beat_subdivision = 12;
1226 bbt_accent_modulo = 3;
1228 case SnapToBeatDiv14:
1229 bbt_beat_subdivision = 14;
1230 bbt_accent_modulo = 3; // XXX YIKES!
1232 case SnapToBeatDiv16:
1233 bbt_beat_subdivision = 16;
1234 bbt_accent_modulo = 4;
1236 case SnapToBeatDiv20:
1237 bbt_beat_subdivision = 20;
1238 bbt_accent_modulo = 5;
1240 case SnapToBeatDiv24:
1241 bbt_beat_subdivision = 24;
1242 bbt_accent_modulo = 6;
1244 case SnapToBeatDiv28:
1245 bbt_beat_subdivision = 28;
1246 bbt_accent_modulo = 7;
1248 case SnapToBeatDiv32:
1249 bbt_beat_subdivision = 32;
1250 bbt_accent_modulo = 8;
1252 case SnapToBeatDiv64:
1253 bbt_beat_subdivision = 64;
1254 bbt_accent_modulo = 8;
1256 case SnapToBeatDiv128:
1257 bbt_beat_subdivision = 128;
1258 bbt_accent_modulo = 8;
1261 bbt_beat_subdivision = 4;
1265 if (distance (begin, end) == 0) {
1271 if ((*i).beat >= (*begin).beat) {
1272 bbt_bars = (*i).bar - (*begin).bar;
1274 bbt_bars = (*i).bar - (*begin).bar - 1;
1276 beats = distance (begin, end) - bbt_bars;
1278 /* Only show the bar helper if there aren't many bars on the screen */
1279 if ((bbt_bars < 2) || (beats < 5)) {
1280 bbt_bar_helper_on = true;
1283 if (bbt_bars > 8192) {
1284 bbt_ruler_scale = bbt_over;
1285 } else if (bbt_bars > 1024) {
1286 bbt_ruler_scale = bbt_show_64;
1287 } else if (bbt_bars > 256) {
1288 bbt_ruler_scale = bbt_show_16;
1289 } else if (bbt_bars > 64) {
1290 bbt_ruler_scale = bbt_show_4;
1291 } else if (bbt_bars > 10) {
1292 bbt_ruler_scale = bbt_show_1;
1293 } else if (bbt_bars > 2) {
1294 bbt_ruler_scale = bbt_show_beats;
1295 } else if (bbt_bars > 0) {
1296 bbt_ruler_scale = bbt_show_ticks;
1298 bbt_ruler_scale = bbt_show_ticks_detail;
1301 if ((bbt_ruler_scale == bbt_show_ticks_detail) && (lower_beat.beats == upper_beat.beats) && (upper_beat.ticks - lower_beat.ticks <= Timecode::BBT_Time::ticks_per_beat / 4)) {
1302 bbt_ruler_scale = bbt_show_ticks_super_detail;
1307 edit_last_mark_label (std::vector<ArdourCanvas::Ruler::Mark>& marks, const std::string& newlabel)
1309 ArdourCanvas::Ruler::Mark copy = marks.back();
1310 copy.label = newlabel;
1312 marks.push_back (copy);
1316 Editor::metric_get_bbt (std::vector<ArdourCanvas::Ruler::Mark>& marks, gdouble lower, gdouble upper, gint /*maxchars*/)
1318 if (_session == 0) {
1322 TempoMap::BBTPointList::const_iterator i;
1327 Timecode::BBT_Time next_beat;
1328 framepos_t next_beat_pos;
1333 framepos_t frame_skip;
1334 double frame_skip_error;
1335 double bbt_position_of_helper;
1336 double accumulated_error;
1337 bool i_am_accented = false;
1338 bool helper_active = false;
1339 ArdourCanvas::Ruler::Mark mark;
1341 ARDOUR::TempoMap::BBTPointList::const_iterator begin;
1342 ARDOUR::TempoMap::BBTPointList::const_iterator end;
1344 compute_current_bbt_points (lower, upper, begin, end);
1346 if (distance (begin, end) == 0) {
1350 switch (bbt_ruler_scale) {
1352 case bbt_show_beats:
1353 beats = distance (begin, end);
1354 bbt_nmarks = beats + 2;
1357 mark.position = lower;
1358 mark.style = ArdourCanvas::Ruler::Mark::Micro;
1359 marks.push_back (mark);
1361 for (n = 1, i = begin; n < bbt_nmarks && i != end; ++i) {
1363 if ((*i).frame < lower && (bbt_bar_helper_on)) {
1364 snprintf (buf, sizeof(buf), "<%" PRIu32 "|%" PRIu32, (*i).bar, (*i).beat);
1365 edit_last_mark_label (marks, buf);
1366 helper_active = true;
1369 if ((*i).is_bar()) {
1370 mark.style = ArdourCanvas::Ruler::Mark::Major;
1371 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1372 } else if (((*i).beat % 2 == 1)) {
1373 mark.style = ArdourCanvas::Ruler::Mark::Minor;
1376 mark.style = ArdourCanvas::Ruler::Mark::Micro;
1380 mark.position = (*i).frame;
1381 marks.push_back (mark);
1387 case bbt_show_ticks:
1389 beats = distance (begin, end);
1390 bbt_nmarks = (beats + 2) * bbt_beat_subdivision;
1392 bbt_position_of_helper = lower + (30 * Editor::get_current_zoom ());
1394 // could do marks.assign() here to preallocate
1397 mark.position = lower;
1398 mark.style = ArdourCanvas::Ruler::Mark::Micro;
1399 marks.push_back (mark);
1401 for (n = 1, i = begin; n < bbt_nmarks && i != end; ++i) {
1403 if ((*i).frame < lower && (bbt_bar_helper_on)) {
1404 snprintf (buf, sizeof(buf), "<%" PRIu32 "|%" PRIu32, (*i).bar, (*i).beat);
1405 edit_last_mark_label (marks, buf);
1406 helper_active = true;
1409 if ((*i).is_bar()) {
1410 mark.style = ArdourCanvas::Ruler::Mark::Major;
1411 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1413 mark.style = ArdourCanvas::Ruler::Mark::Minor;
1414 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).beat);
1416 if (((*i).frame < bbt_position_of_helper) && helper_active) {
1420 mark.position = (*i).frame;
1421 marks.push_back (mark);
1425 /* Add the tick marks */
1427 /* Find the next beat */
1428 next_beat.beats = (*i).beat;
1429 next_beat.bars = (*i).bar;
1430 next_beat.ticks = 0;
1432 if ((*i).meter->divisions_per_bar() > (next_beat.beats + 1)) {
1433 next_beat.beats += 1;
1435 next_beat.bars += 1;
1436 next_beat.beats = 1;
1439 next_beat_pos = _session->tempo_map().frame_time(next_beat);
1441 frame_skip = (framepos_t) floor (frame_skip_error = (_session->frame_rate() * 60) / (bbt_beat_subdivision * (*i).tempo->beats_per_minute()));
1442 frame_skip_error -= frame_skip;
1443 skip = (uint32_t) (Timecode::BBT_Time::ticks_per_beat / bbt_beat_subdivision);
1445 pos = (*i).frame + frame_skip;
1446 accumulated_error = frame_skip_error;
1450 for (t = 0; (tick < Timecode::BBT_Time::ticks_per_beat) && (n < bbt_nmarks) && (pos < next_beat_pos) ; pos += frame_skip, tick += skip, ++t) {
1452 if (t % bbt_accent_modulo == (bbt_accent_modulo - 1)) {
1453 i_am_accented = true;
1458 /* Error compensation for float to framepos_t*/
1459 accumulated_error += frame_skip_error;
1460 if (accumulated_error > 1) {
1462 accumulated_error -= 1.0f;
1465 mark.position = pos;
1467 if ((bbt_beat_subdivision > 4) && i_am_accented) {
1468 mark.style = ArdourCanvas::Ruler::Mark::Minor;
1470 mark.style = ArdourCanvas::Ruler::Mark::Micro;
1472 i_am_accented = false;
1473 marks.push_back (mark);
1480 case bbt_show_ticks_detail:
1482 beats = distance (begin, end);
1483 bbt_nmarks = (beats + 2) * bbt_beat_subdivision;
1485 bbt_position_of_helper = lower + (30 * Editor::get_current_zoom ());
1488 mark.position = lower;
1489 mark.style = ArdourCanvas::Ruler::Mark::Micro;
1490 marks.push_back (mark);
1492 for (n = 1, i = begin; n < bbt_nmarks && i != end; ++i) {
1494 if ((*i).frame < lower && (bbt_bar_helper_on)) {
1495 snprintf (buf, sizeof(buf), "<%" PRIu32 "|%" PRIu32, (*i).bar, (*i).beat);
1496 edit_last_mark_label (marks, buf);
1497 helper_active = true;
1500 if ((*i).is_bar()) {
1501 mark.style = ArdourCanvas::Ruler::Mark::Major;
1502 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1504 mark.style = ArdourCanvas::Ruler::Mark::Minor;
1505 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).beat);
1507 if (((*i).frame < bbt_position_of_helper) && helper_active) {
1511 mark.position = (*i).frame;
1512 marks.push_back (mark);
1516 /* Add the tick marks */
1518 /* Find the next beat */
1520 next_beat.beats = (*i).beat;
1521 next_beat.bars = (*i).bar;
1523 if ((*i).meter->divisions_per_bar() > (next_beat.beats + 1)) {
1524 next_beat.beats += 1;
1526 next_beat.bars += 1;
1527 next_beat.beats = 1;
1530 next_beat_pos = _session->tempo_map().frame_time(next_beat);
1532 frame_skip = (framepos_t) floor (frame_skip_error = (_session->frame_rate() * 60) / (bbt_beat_subdivision * (*i).tempo->beats_per_minute()));
1533 frame_skip_error -= frame_skip;
1534 skip = (uint32_t) (Timecode::BBT_Time::ticks_per_beat / bbt_beat_subdivision);
1536 pos = (*i).frame + frame_skip;
1537 accumulated_error = frame_skip_error;
1541 for (t = 0; (tick < Timecode::BBT_Time::ticks_per_beat) && (n < bbt_nmarks) && (pos < next_beat_pos) ; pos += frame_skip, tick += skip, ++t) {
1543 if (t % bbt_accent_modulo == (bbt_accent_modulo - 1)) {
1544 i_am_accented = true;
1547 if (i_am_accented && (pos > bbt_position_of_helper)){
1548 snprintf (buf, sizeof(buf), "%" PRIu32, tick);
1555 /* Error compensation for float to framepos_t*/
1556 accumulated_error += frame_skip_error;
1557 if (accumulated_error > 1) {
1559 accumulated_error -= 1.0f;
1562 mark.position = pos;
1564 if ((bbt_beat_subdivision > 4) && i_am_accented) {
1565 mark.style = ArdourCanvas::Ruler::Mark::Minor;
1567 mark.style = ArdourCanvas::Ruler::Mark::Micro;
1569 i_am_accented = false;
1576 case bbt_show_ticks_super_detail:
1578 beats = distance (begin, end);
1579 bbt_nmarks = (beats + 2) * bbt_beat_subdivision;
1581 bbt_position_of_helper = lower + (30 * Editor::get_current_zoom ());
1584 mark.position = lower;
1585 mark.style = ArdourCanvas::Ruler::Mark::Micro;
1586 marks.push_back (mark);
1588 for (n = 1, i = begin; n < bbt_nmarks && i != end; ++i) {
1590 if ((*i).frame < lower && (bbt_bar_helper_on)) {
1591 snprintf (buf, sizeof(buf), "<%" PRIu32 "|%" PRIu32, (*i).bar, (*i).beat);
1592 edit_last_mark_label (marks, buf);
1593 helper_active = true;
1596 if ((*i).is_bar()) {
1597 mark.style = ArdourCanvas::Ruler::Mark::Major;
1598 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1600 mark.style = ArdourCanvas::Ruler::Mark::Minor;
1601 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).beat);
1603 if (((*i).frame < bbt_position_of_helper) && helper_active) {
1607 mark.position = (*i).frame;
1608 marks.push_back (mark);
1612 /* Add the tick marks */
1614 /* Find the next beat */
1616 next_beat.beats = (*i).beat;
1617 next_beat.bars = (*i).bar;
1619 if ((*i).meter->divisions_per_bar() > (next_beat.beats + 1)) {
1620 next_beat.beats += 1;
1622 next_beat.bars += 1;
1623 next_beat.beats = 1;
1626 next_beat_pos = _session->tempo_map().frame_time(next_beat);
1628 frame_skip = (framepos_t) floor (frame_skip_error = (_session->frame_rate() * 60) / (bbt_beat_subdivision * (*i).tempo->beats_per_minute()));
1629 frame_skip_error -= frame_skip;
1630 skip = (uint32_t) (Timecode::BBT_Time::ticks_per_beat / bbt_beat_subdivision);
1632 pos = (*i).frame + frame_skip;
1633 accumulated_error = frame_skip_error;
1637 for (t = 0; (tick < Timecode::BBT_Time::ticks_per_beat) && (n < bbt_nmarks) && (pos < next_beat_pos) ; pos += frame_skip, tick += skip, ++t) {
1639 if (t % bbt_accent_modulo == (bbt_accent_modulo - 1)) {
1640 i_am_accented = true;
1643 if (pos > bbt_position_of_helper) {
1644 snprintf (buf, sizeof(buf), "%" PRIu32, tick);
1651 /* Error compensation for float to framepos_t*/
1652 accumulated_error += frame_skip_error;
1653 if (accumulated_error > 1) {
1655 accumulated_error -= 1.0f;
1658 mark.position = pos;
1660 if ((bbt_beat_subdivision > 4) && i_am_accented) {
1661 mark.style = ArdourCanvas::Ruler::Mark::Minor;
1663 mark.style = ArdourCanvas::Ruler::Mark::Micro;
1665 i_am_accented = false;
1666 marks.push_back (mark);
1675 snprintf (buf, sizeof(buf), "cannot handle %" PRIu32 " bars", bbt_bars );
1676 mark.style = ArdourCanvas::Ruler::Mark::Major;
1678 mark.position = lower;
1679 marks.push_back (mark);
1684 bbt_nmarks = (gint) (bbt_bars / 64) + 1;
1685 for (n = 0, i = begin; i != end && n < bbt_nmarks; i++) {
1686 if ((*i).is_bar()) {
1687 if ((*i).bar % 64 == 1) {
1688 if ((*i).bar % 256 == 1) {
1689 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1690 mark.style = ArdourCanvas::Ruler::Mark::Major;
1693 if ((*i).bar % 256 == 129) {
1694 mark.style = ArdourCanvas::Ruler::Mark::Minor;
1696 mark.style = ArdourCanvas::Ruler::Mark::Micro;
1700 mark.position = (*i).frame;
1701 marks.push_back (mark);
1709 bbt_nmarks = (bbt_bars / 16) + 1;
1710 for (n = 0, i = begin; i != end && n < bbt_nmarks; i++) {
1711 if ((*i).is_bar()) {
1712 if ((*i).bar % 16 == 1) {
1713 if ((*i).bar % 64 == 1) {
1714 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1715 mark.style = ArdourCanvas::Ruler::Mark::Major;
1718 if ((*i).bar % 64 == 33) {
1719 mark.style = ArdourCanvas::Ruler::Mark::Minor;
1721 mark.style = ArdourCanvas::Ruler::Mark::Micro;
1725 mark.position = (*i).frame;
1726 marks.push_back (mark);
1734 bbt_nmarks = (bbt_bars / 4) + 1;
1735 for (n = 0, i = begin; i != end && n < bbt_nmarks; ++i) {
1736 if ((*i).is_bar()) {
1737 if ((*i).bar % 4 == 1) {
1738 if ((*i).bar % 16 == 1) {
1739 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1740 mark.style = ArdourCanvas::Ruler::Mark::Major;
1743 if ((*i).bar % 16 == 9) {
1744 mark.style = ArdourCanvas::Ruler::Mark::Minor;
1746 mark.style = ArdourCanvas::Ruler::Mark::Micro;
1750 mark.position = (*i).frame;
1751 marks.push_back (mark);
1760 bbt_nmarks = bbt_bars + 2;
1761 for (n = 0, i = begin; i != end && n < bbt_nmarks; ++i) {
1762 if ((*i).is_bar()) {
1763 if ((*i).bar % 4 == 1) {
1764 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1765 mark.style = ArdourCanvas::Ruler::Mark::Major;
1768 if ((*i).bar % 4 == 3) {
1769 mark.style = ArdourCanvas::Ruler::Mark::Minor;
1771 mark.style = ArdourCanvas::Ruler::Mark::Micro;
1775 mark.position = (*i).frame;
1776 marks.push_back (mark);
1786 Editor::set_samples_ruler_scale (framepos_t lower, framepos_t upper)
1788 _samples_ruler_interval = (upper - lower) / 5;
1792 Editor::metric_get_samples (std::vector<ArdourCanvas::Ruler::Mark>& marks, gdouble lower, gdouble /*upper*/, gint /*maxchars*/)
1795 framepos_t const ilower = (framepos_t) floor (lower);
1799 ArdourCanvas::Ruler::Mark mark;
1801 if (_session == 0) {
1806 for (n = 0, pos = ilower; n < nmarks; pos += _samples_ruler_interval, ++n) {
1807 snprintf (buf, sizeof(buf), "%" PRIi64, pos);
1809 mark.position = pos;
1810 mark.style = ArdourCanvas::Ruler::Mark::Major;
1811 marks.push_back (mark);
1816 sample_to_clock_parts ( framepos_t sample,
1817 framepos_t sample_rate,
1831 hrs = left / (sample_rate * 60 * 60 * 1000);
1832 left -= hrs * sample_rate * 60 * 60 * 1000;
1833 mins = left / (sample_rate * 60 * 1000);
1834 left -= mins * sample_rate * 60 * 1000;
1835 secs = left / (sample_rate * 1000);
1836 left -= secs * sample_rate * 1000;
1837 millisecs = left / sample_rate;
1839 *millisecs_p = millisecs;
1848 Editor::set_minsec_ruler_scale (framepos_t lower, framepos_t upper)
1853 if (_session == 0) {
1857 fr = _session->frame_rate() * 1000;
1859 /* to prevent 'flashing' */
1860 if (lower > (spacer = (framepos_t)(128 * Editor::get_current_zoom ()))) {
1866 framecnt_t const range = (upper - lower) * 1000;
1868 if (range < (fr / 50)) {
1869 minsec_mark_interval = fr / 1000; /* show 1/1000 seconds */
1870 minsec_ruler_scale = minsec_show_frames;
1871 minsec_mark_modulo = 10;
1872 } else if (range <= (fr / 10)) { /* 0-0.1 second */
1873 minsec_mark_interval = fr / 1000; /* show 1/1000 seconds */
1874 minsec_ruler_scale = minsec_show_frames;
1875 minsec_mark_modulo = 10;
1876 } else if (range <= (fr / 2)) { /* 0-0.5 second */
1877 minsec_mark_interval = fr / 100; /* show 1/100 seconds */
1878 minsec_ruler_scale = minsec_show_frames;
1879 minsec_mark_modulo = 100;
1880 } else if (range <= fr) { /* 0-1 second */
1881 minsec_mark_interval = fr / 10; /* show 1/10 seconds */
1882 minsec_ruler_scale = minsec_show_frames;
1883 minsec_mark_modulo = 200;
1884 } else if (range <= 2 * fr) { /* 1-2 seconds */
1885 minsec_mark_interval = fr / 10; /* show 1/10 seconds */
1886 minsec_ruler_scale = minsec_show_frames;
1887 minsec_mark_modulo = 500;
1888 } else if (range <= 8 * fr) { /* 2-5 seconds */
1889 minsec_mark_interval = fr / 5; /* show 2 seconds */
1890 minsec_ruler_scale = minsec_show_frames;
1891 minsec_mark_modulo = 1000;
1892 } else if (range <= 16 * fr) { /* 8-16 seconds */
1893 minsec_mark_interval = fr; /* show 1 seconds */
1894 minsec_ruler_scale = minsec_show_seconds;
1895 minsec_mark_modulo = 2;
1896 } else if (range <= 30 * fr) { /* 10-30 seconds */
1897 minsec_mark_interval = fr; /* show 1 seconds */
1898 minsec_ruler_scale = minsec_show_seconds;
1899 minsec_mark_modulo = 5;
1900 } else if (range <= 60 * fr) { /* 30-60 seconds */
1901 minsec_mark_interval = fr; /* show 1 seconds */
1902 minsec_ruler_scale = minsec_show_seconds;
1903 minsec_mark_modulo = 5;
1904 } else if (range <= 2 * 60 * fr) { /* 1-2 minutes */
1905 minsec_mark_interval = 5 * fr; /* show 5 seconds */
1906 minsec_ruler_scale = minsec_show_seconds;
1907 minsec_mark_modulo = 3;
1908 } else if (range <= 4 * 60 * fr) { /* 4 minutes */
1909 minsec_mark_interval = 5 * fr; /* show 10 seconds */
1910 minsec_ruler_scale = minsec_show_seconds;
1911 minsec_mark_modulo = 30;
1912 } else if (range <= 10 * 60 * fr) { /* 10 minutes */
1913 minsec_mark_interval = 30 * fr; /* show 30 seconds */
1914 minsec_ruler_scale = minsec_show_seconds;
1915 minsec_mark_modulo = 120;
1916 } else if (range <= 30 * 60 * fr) { /* 10-30 minutes */
1917 minsec_mark_interval = 60 * fr; /* show 1 minute */
1918 minsec_ruler_scale = minsec_show_minutes;
1919 minsec_mark_modulo = 5;
1920 } else if (range <= 60 * 60 * fr) { /* 30 minutes - 1hr */
1921 minsec_mark_interval = 2 * 60 * fr; /* show 2 minutes */
1922 minsec_ruler_scale = minsec_show_minutes;
1923 minsec_mark_modulo = 10;
1924 } else if (range <= 4 * 60 * 60 * fr) { /* 1 - 4 hrs*/
1925 minsec_mark_interval = 5 * 60 * fr; /* show 10 minutes */
1926 minsec_ruler_scale = minsec_show_minutes;
1927 minsec_mark_modulo = 30;
1928 } else if (range <= 8 * 60 * 60 * fr) { /* 4 - 8 hrs*/
1929 minsec_mark_interval = 20 * 60 * fr; /* show 20 minutes */
1930 minsec_ruler_scale = minsec_show_minutes;
1931 minsec_mark_modulo = 60;
1932 } else if (range <= 16 * 60 * 60 * fr) { /* 16-24 hrs*/
1933 minsec_mark_interval = 60 * 60 * fr; /* show 60 minutes */
1934 minsec_ruler_scale = minsec_show_hours;
1935 minsec_mark_modulo = 2;
1938 /* not possible if framepos_t is a 32 bit quantity */
1940 minsec_mark_interval = 4 * 60 * 60 * fr; /* show 4 hrs */
1942 minsec_nmarks = 2 + (range / minsec_mark_interval);
1946 Editor::metric_get_minsec (std::vector<ArdourCanvas::Ruler::Mark>& marks, gdouble lower, gdouble /*upper*/, gint /*maxchars*/)
1950 long hrs, mins, secs, millisecs;
1953 ArdourCanvas::Ruler::Mark mark;
1955 if (_session == 0) {
1959 /* to prevent 'flashing' */
1960 if (lower > (spacer = (framepos_t) (128 * Editor::get_current_zoom ()))) {
1961 lower = lower - spacer;
1966 pos = (((1000 * (framepos_t) floor(lower)) + (minsec_mark_interval/2))/minsec_mark_interval) * minsec_mark_interval;
1967 switch (minsec_ruler_scale) {
1968 case minsec_show_seconds:
1969 for (n = 0; n < minsec_nmarks; pos += minsec_mark_interval, ++n) {
1970 sample_to_clock_parts (pos, _session->frame_rate(), &hrs, &mins, &secs, &millisecs);
1971 if (secs % minsec_mark_modulo == 0) {
1973 mark.style = ArdourCanvas::Ruler::Mark::Major;
1975 mark.style = ArdourCanvas::Ruler::Mark::Minor;
1977 snprintf (buf, sizeof(buf), "%02ld:%02ld:%02ld.%03ld", hrs, mins, secs, millisecs);
1980 mark.style = ArdourCanvas::Ruler::Mark::Micro;
1983 mark.position = pos/1000.0;
1984 marks.push_back (mark);
1987 case minsec_show_minutes:
1988 for (n = 0; n < minsec_nmarks; pos += minsec_mark_interval, ++n) {
1989 sample_to_clock_parts (pos, _session->frame_rate(), &hrs, &mins, &secs, &millisecs);
1990 if (mins % minsec_mark_modulo == 0) {
1992 mark.style = ArdourCanvas::Ruler::Mark::Major;
1994 mark.style = ArdourCanvas::Ruler::Mark::Minor;
1996 snprintf (buf, sizeof(buf), "%02ld:%02ld:%02ld.%03ld", hrs, mins, secs, millisecs);
1999 mark.style = ArdourCanvas::Ruler::Mark::Micro;
2002 mark.position = pos/1000.0;
2003 marks.push_back (mark);
2006 case minsec_show_hours:
2007 for (n = 0; n < minsec_nmarks; pos += minsec_mark_interval, ++n) {
2008 sample_to_clock_parts (pos, _session->frame_rate(), &hrs, &mins, &secs, &millisecs);
2009 if (hrs % minsec_mark_modulo == 0) {
2010 mark.style = ArdourCanvas::Ruler::Mark::Major;
2011 snprintf (buf, sizeof(buf), "%02ld:%02ld:%02ld.%03ld", hrs, mins, secs, millisecs);
2014 mark.style = ArdourCanvas::Ruler::Mark::Micro;
2017 mark.position = pos/1000.0;
2018 marks.push_back (mark);
2021 case minsec_show_frames:
2022 for (n = 0; n < minsec_nmarks; pos += minsec_mark_interval, ++n) {
2023 sample_to_clock_parts (pos, _session->frame_rate(), &hrs, &mins, &secs, &millisecs);
2024 if (millisecs % minsec_mark_modulo == 0) {
2025 if (millisecs == 0) {
2026 mark.style = ArdourCanvas::Ruler::Mark::Major;
2028 mark.style = ArdourCanvas::Ruler::Mark::Minor;
2030 snprintf (buf, sizeof(buf), "%02ld:%02ld:%02ld.%03ld", hrs, mins, secs, millisecs);
2033 mark.style = ArdourCanvas::Ruler::Mark::Micro;
2036 mark.position = pos/1000.0;
2037 marks.push_back (mark);