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.
20 #define __STDC_FORMAT_MACROS 1
21 #include <cstdio> // for sprintf, grrr
27 #include <gtk/gtkaction.h>
29 #include "ardour/session.h"
30 #include "ardour/tempo.h"
31 #include "ardour/profile.h"
32 #include <gtkmm2ext/gtk_ui.h>
37 #include "gtk-custom-hruler.h"
38 #include "gui_thread.h"
39 #include "time_axis_view.h"
40 #include "editor_drag.h"
45 using namespace ARDOUR;
48 using namespace Editing;
50 Editor *Editor::ruler_editor;
52 /* the order here must match the "metric" enums in editor.h */
54 GtkCustomMetric Editor::ruler_metrics[4] = {
55 {1, Editor::_metric_get_timecode },
56 {1, Editor::_metric_get_bbt },
57 {1, Editor::_metric_get_frames },
58 {1, Editor::_metric_get_minsec }
62 Editor::initialize_rulers ()
65 ruler_grabbed_widget = 0;
67 _ruler_separator = new Gtk::HSeparator();
68 _ruler_separator->set_size_request(-1, 2);
69 _ruler_separator->set_name("TimebarPadding");
70 _ruler_separator->show();
72 _minsec_ruler = gtk_custom_hruler_new ();
73 minsec_ruler = Glib::wrap (_minsec_ruler);
74 minsec_ruler->set_name ("MinSecRuler");
75 minsec_ruler->set_size_request (-1, (int)timebar_height);
76 gtk_custom_ruler_set_metric (GTK_CUSTOM_RULER(_minsec_ruler), &ruler_metrics[ruler_metric_minsec]);
77 minsec_ruler->hide ();
78 minsec_ruler->set_no_show_all();
80 _timecode_ruler = gtk_custom_hruler_new ();
81 timecode_ruler = Glib::wrap (_timecode_ruler);
82 timecode_ruler->set_name ("TimecodeRuler");
83 timecode_ruler->set_size_request (-1, (int)timebar_height);
84 gtk_custom_ruler_set_metric (GTK_CUSTOM_RULER(_timecode_ruler), &ruler_metrics[ruler_metric_timecode]);
85 timecode_ruler->hide ();
86 timecode_ruler->set_no_show_all();
89 _bbt_ruler = gtk_custom_hruler_new ();
90 bbt_ruler = Glib::wrap (_bbt_ruler);
91 bbt_ruler->set_name ("BBTRuler");
92 bbt_ruler->set_size_request (-1, (int)timebar_height);
93 gtk_custom_ruler_set_metric (GTK_CUSTOM_RULER(_bbt_ruler), &ruler_metrics[ruler_metric_bbt]);
95 bbt_ruler->set_no_show_all();
98 _frames_ruler = gtk_custom_hruler_new ();
99 frames_ruler = Glib::wrap (_frames_ruler);
100 frames_ruler->set_name ("FramesRuler");
101 frames_ruler->set_size_request (-1, (int)timebar_height);
102 gtk_custom_ruler_set_metric (GTK_CUSTOM_RULER(_frames_ruler), &ruler_metrics[ruler_metric_frames]);
103 frames_ruler->hide ();
104 frames_ruler->set_no_show_all();
106 _bbt_ruler = gtk_custom_hruler_new ();
107 bbt_ruler = Glib::wrap (_bbt_ruler);
108 bbt_ruler->set_name ("BBTRuler");
109 bbt_ruler->set_size_request (-1, (int)timebar_height);
110 gtk_custom_ruler_set_metric (GTK_CUSTOM_RULER(_bbt_ruler), &ruler_metrics[ruler_metric_bbt]);
112 bbt_ruler->set_no_show_all();
113 minsec_ruler->hide ();
114 minsec_ruler->set_no_show_all();
117 using namespace Box_Helpers;
118 BoxList & ruler_lab_children = ruler_label_vbox.children();
119 BoxList & ruler_children = time_canvas_vbox.children();
120 BoxList & lab_children = time_button_vbox.children();
122 BoxList::iterator canvaspos = ruler_children.begin();
124 lab_children.push_back (Element(meter_label, PACK_SHRINK, PACK_START));
125 lab_children.push_back (Element(tempo_label, PACK_SHRINK, PACK_START));
126 lab_children.push_back (Element(range_mark_label, PACK_SHRINK, PACK_START));
127 lab_children.push_back (Element(transport_mark_label, PACK_SHRINK, PACK_START));
128 lab_children.push_back (Element(cd_mark_label, PACK_SHRINK, PACK_START));
129 lab_children.push_back (Element(mark_label, PACK_SHRINK, PACK_START));
131 ruler_lab_children.push_back (Element(minsec_label, PACK_SHRINK, PACK_START));
132 ruler_children.insert (canvaspos, Element(*minsec_ruler, PACK_SHRINK, PACK_START));
133 ruler_lab_children.push_back (Element(timecode_label, PACK_SHRINK, PACK_START));
134 ruler_children.insert (canvaspos, Element(*timecode_ruler, PACK_SHRINK, PACK_START));
135 ruler_lab_children.push_back (Element(frame_label, PACK_SHRINK, PACK_START));
136 ruler_children.insert (canvaspos, Element(*frames_ruler, PACK_SHRINK, PACK_START));
137 ruler_lab_children.push_back (Element(bbt_label, PACK_SHRINK, PACK_START));
138 ruler_children.insert (canvaspos, Element(*bbt_ruler, PACK_SHRINK, PACK_START));
140 timecode_ruler->add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::SCROLL_MASK);
141 bbt_ruler->add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::SCROLL_MASK);
142 frames_ruler->add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::SCROLL_MASK);
143 minsec_ruler->add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::SCROLL_MASK);
145 timecode_ruler->signal_button_release_event().connect (sigc::mem_fun(*this, &Editor::ruler_button_release));
146 bbt_ruler->signal_button_release_event().connect (sigc::mem_fun(*this, &Editor::ruler_button_release));
147 frames_ruler->signal_button_release_event().connect (sigc::mem_fun(*this, &Editor::ruler_button_release));
148 minsec_ruler->signal_button_release_event().connect (sigc::mem_fun(*this, &Editor::ruler_button_release));
150 timecode_ruler->signal_button_press_event().connect (sigc::mem_fun(*this, &Editor::ruler_button_press));
151 bbt_ruler->signal_button_press_event().connect (sigc::mem_fun(*this, &Editor::ruler_button_press));
152 frames_ruler->signal_button_press_event().connect (sigc::mem_fun(*this, &Editor::ruler_button_press));
153 minsec_ruler->signal_button_press_event().connect (sigc::mem_fun(*this, &Editor::ruler_button_press));
155 timecode_ruler->signal_motion_notify_event().connect (sigc::mem_fun(*this, &Editor::ruler_mouse_motion));
156 bbt_ruler->signal_motion_notify_event().connect (sigc::mem_fun(*this, &Editor::ruler_mouse_motion));
157 frames_ruler->signal_motion_notify_event().connect (sigc::mem_fun(*this, &Editor::ruler_mouse_motion));
158 minsec_ruler->signal_motion_notify_event().connect (sigc::mem_fun(*this, &Editor::ruler_mouse_motion));
160 timecode_ruler->signal_scroll_event().connect (sigc::mem_fun(*this, &Editor::ruler_scroll));
161 bbt_ruler->signal_scroll_event().connect (sigc::mem_fun(*this, &Editor::ruler_scroll));
162 frames_ruler->signal_scroll_event().connect (sigc::mem_fun(*this, &Editor::ruler_scroll));
163 minsec_ruler->signal_scroll_event().connect (sigc::mem_fun(*this, &Editor::ruler_scroll));
165 visible_timebars = 0; /*this will be changed below */
166 canvas_timebars_vsize = 0;
170 Editor::ruler_scroll (GdkEventScroll* event)
173 int direction = event->direction;
174 bool handled = false;
178 temporal_zoom_step (true);
182 case GDK_SCROLL_DOWN:
183 temporal_zoom_step (false);
187 case GDK_SCROLL_LEFT:
188 xdelta = (current_page_frames() / 2);
189 if (leftmost_frame > xdelta) {
190 reset_x_origin (leftmost_frame - xdelta);
197 case GDK_SCROLL_RIGHT:
198 xdelta = (current_page_frames() / 2);
199 if (max_frames - xdelta > leftmost_frame) {
200 reset_x_origin (leftmost_frame + xdelta);
202 reset_x_origin (max_frames - current_page_frames());
217 Editor::ruler_button_press (GdkEventButton* ev)
223 // jlc: grab ev->window ?
224 //Gtk::Main::grab_add (*minsec_ruler);
225 Widget * grab_widget = 0;
227 if (timecode_ruler->is_realized() && ev->window == timecode_ruler->get_window()->gobj()) {
228 grab_widget = timecode_ruler;
229 } else if (bbt_ruler->is_realized() && ev->window == bbt_ruler->get_window()->gobj()) {
230 grab_widget = bbt_ruler;
231 } else if (frames_ruler->is_realized() && ev->window == frames_ruler->get_window()->gobj()) {
232 grab_widget = frames_ruler;
233 } else if (minsec_ruler->is_realized() && ev->window == minsec_ruler->get_window()->gobj()) {
234 grab_widget = minsec_ruler;
238 grab_widget->add_modal_grab ();
239 ruler_grabbed_widget = grab_widget;
242 if (ev->button == 1) {
243 // Since we will locate the playhead on button release, cancel any running
245 if (session->is_auditioning()) {
246 session->cancel_audition ();
249 /* playhead cursor */
251 _drag = new CursorDrag (this, &playhead_cursor->canvas_item, false);
252 _drag->start_grab (reinterpret_cast<GdkEvent *> (ev));
253 _dragging_playhead = true;
260 Editor::ruler_button_release (GdkEventButton* ev)
267 Gdk::ModifierType state;
270 _drag->end_grab (reinterpret_cast<GdkEvent*> (ev));
273 _dragging_playhead = false;
276 if (ev->button == 3) {
277 /* need to use the correct x,y, the event lies */
278 time_canvas_event_box.get_window()->get_pointer (x, y, state);
280 stop_canvas_autoscroll();
282 nframes64_t where = leftmost_frame + pixel_to_frame (x);
284 popup_ruler_menu (where);
287 if (ruler_grabbed_widget) {
288 ruler_grabbed_widget->remove_modal_grab();
289 ruler_grabbed_widget = 0;
296 Editor::ruler_label_button_release (GdkEventButton* ev)
298 if (ev->button == 3) {
299 Gtk::Menu* m= dynamic_cast<Gtk::Menu*> (ActionManager::get_widget (X_("/RulerMenuPopup")));
301 m->popup (1, ev->time);
310 Editor::ruler_mouse_motion (GdkEventMotion* ev)
317 _drag->motion_handler (reinterpret_cast<GdkEvent*> (ev), false);
325 Editor::popup_ruler_menu (nframes64_t where, ItemType t)
327 using namespace Menu_Helpers;
329 if (editor_ruler_menu == 0) {
330 editor_ruler_menu = new Menu;
331 editor_ruler_menu->set_name ("ArdourContextMenu");
334 // always build from scratch
335 MenuList& ruler_items = editor_ruler_menu->items();
336 editor_ruler_menu->set_name ("ArdourContextMenu");
341 ruler_items.push_back (MenuElem (_("New location marker"), sigc::bind ( sigc::mem_fun(*this, &Editor::mouse_add_new_marker), where, false, false)));
342 ruler_items.push_back (MenuElem (_("Clear all locations"), sigc::mem_fun(*this, &Editor::clear_markers)));
343 ruler_items.push_back (MenuElem (_("Unhide locations"), sigc::mem_fun(*this, &Editor::unhide_markers)));
344 ruler_items.push_back (SeparatorElem ());
346 case RangeMarkerBarItem:
347 //ruler_items.push_back (MenuElem (_("New Range")));
348 ruler_items.push_back (MenuElem (_("Clear all ranges"), sigc::mem_fun(*this, &Editor::clear_ranges)));
349 ruler_items.push_back (MenuElem (_("Unhide ranges"), sigc::mem_fun(*this, &Editor::unhide_ranges)));
350 ruler_items.push_back (SeparatorElem ());
353 case TransportMarkerBarItem:
357 case CdMarkerBarItem:
359 ruler_items.push_back (MenuElem (_("New CD track marker"), sigc::bind ( sigc::mem_fun(*this, &Editor::mouse_add_new_marker), where, true, false)));
364 ruler_items.push_back (MenuElem (_("New Tempo"), sigc::bind ( sigc::mem_fun(*this, &Editor::mouse_add_new_tempo_event), where)));
365 ruler_items.push_back (MenuElem (_("Clear tempo")));
366 ruler_items.push_back (SeparatorElem ());
370 ruler_items.push_back (MenuElem (_("New Meter"), sigc::bind ( sigc::mem_fun(*this, &Editor::mouse_add_new_meter_event), where)));
371 ruler_items.push_back (MenuElem (_("Clear meter")));
372 ruler_items.push_back (SeparatorElem ());
379 Glib::RefPtr<Action> action;
381 action = ActionManager::get_action ("Rulers", "toggle-minsec-ruler");
383 ruler_items.push_back (MenuElem (*action->create_menu_item()));
385 if (!Profile->get_sae()) {
386 action = ActionManager::get_action ("Rulers", "toggle-timecode-ruler");
388 ruler_items.push_back (MenuElem (*action->create_menu_item()));
391 action = ActionManager::get_action ("Rulers", "toggle-samples-ruler");
393 ruler_items.push_back (MenuElem (*action->create_menu_item()));
395 action = ActionManager::get_action ("Rulers", "toggle-bbt-ruler");
397 ruler_items.push_back (MenuElem (*action->create_menu_item()));
399 action = ActionManager::get_action ("Rulers", "toggle-meter-ruler");
401 ruler_items.push_back (MenuElem (*action->create_menu_item()));
403 action = ActionManager::get_action ("Rulers", "toggle-tempo-ruler");
405 ruler_items.push_back (MenuElem (*action->create_menu_item()));
407 if (!Profile->get_sae()) {
408 action = ActionManager::get_action ("Rulers", "toggle-range-ruler");
410 ruler_items.push_back (MenuElem (*action->create_menu_item()));
413 action = ActionManager::get_action ("Rulers", "toggle-loop-punch-ruler");
415 ruler_items.push_back (MenuElem (*action->create_menu_item()));
417 action = ActionManager::get_action ("Rulers", "toggle-cd-marker-ruler");
419 ruler_items.push_back (MenuElem (*action->create_menu_item()));
421 action = ActionManager::get_action ("Rulers", "toggle-marker-ruler");
423 ruler_items.push_back (MenuElem (*action->create_menu_item()));
426 editor_ruler_menu->popup (1, gtk_get_current_event_time());
428 no_ruler_shown_update = false;
432 Editor::store_ruler_visibility ()
434 XMLNode* node = new XMLNode(X_("RulerVisibility"));
436 node->add_property (X_("timecode"), ruler_timecode_action->get_active() ? "yes": "no");
437 node->add_property (X_("bbt"), ruler_bbt_action->get_active() ? "yes": "no");
438 node->add_property (X_("frames"), ruler_samples_action->get_active() ? "yes": "no");
439 node->add_property (X_("minsec"), ruler_minsec_action->get_active() ? "yes": "no");
440 node->add_property (X_("tempo"), ruler_tempo_action->get_active() ? "yes": "no");
441 node->add_property (X_("meter"), ruler_meter_action->get_active() ? "yes": "no");
442 node->add_property (X_("marker"), ruler_marker_action->get_active() ? "yes": "no");
443 node->add_property (X_("rangemarker"), ruler_range_action->get_active() ? "yes": "no");
444 node->add_property (X_("transportmarker"), ruler_loop_punch_action->get_active() ? "yes": "no");
445 node->add_property (X_("cdmarker"), ruler_cd_marker_action->get_active() ? "yes": "no");
447 session->add_extra_xml (*node);
448 session->set_dirty ();
452 Editor::restore_ruler_visibility ()
455 XMLNode * node = session->extra_xml (X_("RulerVisibility"));
457 no_ruler_shown_update = true;
460 if ((prop = node->property ("timecode")) != 0) {
461 if (string_is_affirmative (prop->value())) {
462 ruler_timecode_action->set_active (true);
464 ruler_timecode_action->set_active (false);
467 if ((prop = node->property ("bbt")) != 0) {
468 if (string_is_affirmative (prop->value())) {
469 ruler_bbt_action->set_active (true);
471 ruler_bbt_action->set_active (false);
474 if ((prop = node->property ("frames")) != 0) {
475 if (string_is_affirmative (prop->value())) {
476 ruler_samples_action->set_active (true);
478 ruler_samples_action->set_active (false);
481 if ((prop = node->property ("minsec")) != 0) {
482 if (string_is_affirmative (prop->value())) {
483 ruler_minsec_action->set_active (true);
485 ruler_minsec_action->set_active (false);
488 if ((prop = node->property ("tempo")) != 0) {
489 if (string_is_affirmative (prop->value())) {
490 ruler_tempo_action->set_active (true);
492 ruler_tempo_action->set_active (false);
495 if ((prop = node->property ("meter")) != 0) {
496 if (string_is_affirmative (prop->value())) {
497 ruler_meter_action->set_active (true);
499 ruler_meter_action->set_active (false);
502 if ((prop = node->property ("marker")) != 0) {
503 if (string_is_affirmative (prop->value())) {
504 ruler_marker_action->set_active (true);
506 ruler_marker_action->set_active (false);
509 if ((prop = node->property ("rangemarker")) != 0) {
510 if (string_is_affirmative (prop->value())) {
511 ruler_range_action->set_active (true);
513 ruler_range_action->set_active (false);
517 if ((prop = node->property ("transportmarker")) != 0) {
518 if (string_is_affirmative (prop->value())) {
519 ruler_loop_punch_action->set_active (true);
521 ruler_loop_punch_action->set_active (false);
525 if ((prop = node->property ("cdmarker")) != 0) {
526 if (string_is_affirmative (prop->value())) {
527 ruler_cd_marker_action->set_active (true);
529 ruler_cd_marker_action->set_active (false);
533 // this session doesn't yet know about the cdmarker ruler
534 // as a benefit to the user who doesn't know the feature exists, show the ruler if
535 // any cd marks exist
536 ruler_cd_marker_action->set_active (false);
537 const Locations::LocationList & locs = session->locations()->list();
538 for (Locations::LocationList::const_iterator i = locs.begin(); i != locs.end(); ++i) {
539 if ((*i)->is_cd_marker()) {
540 ruler_cd_marker_action->set_active (true);
548 no_ruler_shown_update = false;
549 update_ruler_visibility ();
553 Editor::update_ruler_visibility ()
555 int visible_rulers = 0;
557 if (no_ruler_shown_update) {
561 visible_timebars = 0;
563 if (ruler_minsec_action->get_active()) {
565 minsec_label.show ();
566 minsec_ruler->show ();
568 minsec_label.hide ();
569 minsec_ruler->hide ();
572 if (ruler_timecode_action->get_active()) {
574 timecode_label.show ();
575 timecode_ruler->show ();
577 timecode_label.hide ();
578 timecode_ruler->hide ();
581 if (ruler_samples_action->get_active()) {
584 frames_ruler->show ();
587 frames_ruler->hide ();
590 if (ruler_bbt_action->get_active()) {
604 /* gtk update probs require this (damn) */
607 range_mark_label.hide();
608 transport_mark_label.hide();
609 cd_mark_label.hide();
612 if (ruler_meter_action->get_active()) {
613 old_unit_pos = meter_group->property_y();
614 if (tbpos != old_unit_pos) {
615 meter_group->move ( 0.0, tbpos - old_unit_pos);
617 old_unit_pos = meter_bar_group->property_y();
618 if (tbgpos != old_unit_pos) {
619 meter_bar_group->move ( 0.0, tbgpos - old_unit_pos);
621 meter_bar_group->show();
624 tbpos += timebar_height;
625 tbgpos += timebar_height;
628 meter_bar_group->hide();
633 if (ruler_tempo_action->get_active()) {
634 old_unit_pos = tempo_group->property_y();
635 if (tbpos != old_unit_pos) {
636 tempo_group->move(0.0, tbpos - old_unit_pos);
638 old_unit_pos = tempo_bar_group->property_y();
639 if (tbgpos != old_unit_pos) {
640 tempo_bar_group->move ( 0.0, tbgpos - old_unit_pos);
642 tempo_bar_group->show();
645 tbpos += timebar_height;
646 tbgpos += timebar_height;
649 tempo_bar_group->hide();
654 if (!Profile->get_sae() && ruler_range_action->get_active()) {
655 old_unit_pos = range_marker_group->property_y();
656 if (tbpos != old_unit_pos) {
657 range_marker_group->move (0.0, tbpos - old_unit_pos);
659 old_unit_pos = range_marker_bar_group->property_y();
660 if (tbgpos != old_unit_pos) {
661 range_marker_bar_group->move (0.0, tbgpos - old_unit_pos);
663 range_marker_bar_group->show();
664 range_marker_group->show();
665 range_mark_label.show();
667 tbpos += timebar_height;
668 tbgpos += timebar_height;
671 range_marker_bar_group->hide();
672 range_marker_group->hide();
673 range_mark_label.hide();
676 if (ruler_loop_punch_action->get_active()) {
677 old_unit_pos = transport_marker_group->property_y();
678 if (tbpos != old_unit_pos) {
679 transport_marker_group->move ( 0.0, tbpos - old_unit_pos);
681 old_unit_pos = transport_marker_bar_group->property_y();
682 if (tbgpos != old_unit_pos) {
683 transport_marker_bar_group->move ( 0.0, tbgpos - old_unit_pos);
685 transport_marker_bar_group->show();
686 transport_marker_group->show();
687 transport_mark_label.show();
688 tbpos += timebar_height;
689 tbgpos += timebar_height;
692 transport_marker_bar_group->hide();
693 transport_marker_group->hide();
694 transport_mark_label.hide();
697 if (ruler_cd_marker_action->get_active()) {
698 old_unit_pos = cd_marker_group->property_y();
699 if (tbpos != old_unit_pos) {
700 cd_marker_group->move (0.0, tbpos - old_unit_pos);
702 old_unit_pos = cd_marker_bar_group->property_y();
703 if (tbgpos != old_unit_pos) {
704 cd_marker_bar_group->move (0.0, tbgpos - old_unit_pos);
706 cd_marker_bar_group->show();
707 cd_marker_group->show();
708 cd_mark_label.show();
709 tbpos += timebar_height;
710 tbgpos += timebar_height;
712 // make sure all cd markers show up in their respective places
713 update_cd_marker_display();
715 cd_marker_bar_group->hide();
716 cd_marker_group->hide();
717 cd_mark_label.hide();
718 // make sure all cd markers show up in their respective places
719 update_cd_marker_display();
722 if (ruler_marker_action->get_active()) {
723 old_unit_pos = marker_group->property_y();
724 if (tbpos != old_unit_pos) {
725 marker_group->move ( 0.0, tbpos - old_unit_pos);
727 old_unit_pos = marker_bar_group->property_y();
728 if (tbgpos != old_unit_pos) {
729 marker_bar_group->move ( 0.0, tbgpos - old_unit_pos);
731 marker_bar_group->show();
732 marker_group->show();
734 tbpos += timebar_height;
735 tbgpos += timebar_height;
738 marker_bar_group->hide();
739 marker_group->hide();
743 gdouble old_canvas_timebars_vsize = canvas_timebars_vsize;
744 canvas_timebars_vsize = (timebar_height * visible_timebars) - 1;
745 gdouble vertical_pos_delta = canvas_timebars_vsize - old_canvas_timebars_vsize;
746 vertical_adjustment.set_upper(vertical_adjustment.get_upper() + vertical_pos_delta);
747 full_canvas_height += vertical_pos_delta;
749 if (vertical_adjustment.get_value() != 0 && (vertical_adjustment.get_value() + _canvas_height >= full_canvas_height)) {
750 /*if we're at the bottom of the canvas, don't move the _trackview_group*/
751 vertical_adjustment.set_value (full_canvas_height - _canvas_height + 1);
753 _trackview_group->property_y () = - get_trackview_group_vertical_offset ();
754 _background_group->property_y () = - get_trackview_group_vertical_offset ();
755 _trackview_group->move (0, 0);
756 _background_group->move (0, 0);
757 last_trackview_group_vertical_offset = get_trackview_group_vertical_offset ();
760 gdouble bottom_track_pos = vertical_adjustment.get_value() + _canvas_height - canvas_timebars_vsize;
761 std::pair<TimeAxisView*, int> const p = trackview_by_y_position (bottom_track_pos);
763 p.first->clip_to_viewport ();
766 ruler_label_vbox.set_size_request (-1, (int)(timebar_height * visible_rulers));
767 time_canvas_vbox.set_size_request (-1,-1);
769 update_fixed_rulers();
770 redisplay_tempo (false);
774 Editor::update_just_timecode ()
776 ENSURE_GUI_THREAD (*this, &Editor::update_just_timecode)
782 nframes64_t rightmost_frame = leftmost_frame + current_page_frames();
784 if (ruler_timecode_action->get_active()) {
785 gtk_custom_ruler_set_range (GTK_CUSTOM_RULER(_timecode_ruler), leftmost_frame, rightmost_frame,
786 leftmost_frame, session->current_end_frame());
791 Editor::compute_fixed_ruler_scale ()
797 if (ruler_timecode_action->get_active()) {
798 set_timecode_ruler_scale (leftmost_frame, leftmost_frame + current_page_frames() );
801 if (ruler_minsec_action->get_active()) {
802 set_minsec_ruler_scale (leftmost_frame, leftmost_frame + current_page_frames() );
807 Editor::update_fixed_rulers ()
809 nframes64_t rightmost_frame;
815 ruler_metrics[ruler_metric_timecode].units_per_pixel = frames_per_unit;
816 ruler_metrics[ruler_metric_frames].units_per_pixel = frames_per_unit;
817 ruler_metrics[ruler_metric_minsec].units_per_pixel = frames_per_unit;
819 rightmost_frame = leftmost_frame + current_page_frames();
821 /* these force a redraw, which in turn will force execution of the metric callbacks
822 to compute the relevant ticks to display.
825 if (ruler_timecode_action->get_active()) {
826 gtk_custom_ruler_set_range (GTK_CUSTOM_RULER(_timecode_ruler), leftmost_frame, rightmost_frame,
827 leftmost_frame, session->current_end_frame());
830 if (ruler_samples_action->get_active()) {
831 gtk_custom_ruler_set_range (GTK_CUSTOM_RULER(_frames_ruler), leftmost_frame, rightmost_frame,
832 leftmost_frame, session->current_end_frame());
835 if (ruler_minsec_action->get_active()) {
836 gtk_custom_ruler_set_range (GTK_CUSTOM_RULER(_minsec_ruler), leftmost_frame, rightmost_frame,
837 leftmost_frame, session->current_end_frame());
842 Editor::update_tempo_based_rulers ()
848 ruler_metrics[ruler_metric_bbt].units_per_pixel = frames_per_unit;
850 if (ruler_bbt_action->get_active()) {
851 gtk_custom_ruler_set_range (GTK_CUSTOM_RULER(_bbt_ruler), leftmost_frame, leftmost_frame+current_page_frames(),
852 leftmost_frame, session->current_end_frame());
856 /* Mark generation */
859 Editor::_metric_get_timecode (GtkCustomRulerMark **marks, gdouble lower, gdouble upper, gint maxchars)
861 return ruler_editor->metric_get_timecode (marks, lower, upper, maxchars);
865 Editor::_metric_get_bbt (GtkCustomRulerMark **marks, gdouble lower, gdouble upper, gint maxchars)
867 return ruler_editor->metric_get_bbt (marks, lower, upper, maxchars);
871 Editor::_metric_get_frames (GtkCustomRulerMark **marks, gdouble lower, gdouble upper, gint maxchars)
873 return ruler_editor->metric_get_frames (marks, lower, upper, maxchars);
877 Editor::_metric_get_minsec (GtkCustomRulerMark **marks, gdouble lower, gdouble upper, gint maxchars)
879 return ruler_editor->metric_get_minsec (marks, lower, upper, maxchars);
883 Editor::set_timecode_ruler_scale (gdouble lower, gdouble upper)
893 fr = session->frame_rate();
895 if (lower > (spacer = (nframes64_t)(128 * Editor::get_current_zoom ()))) {
896 lower = lower - spacer;
900 upper = upper + spacer;
901 range = (nframes64_t) floor (upper - lower);
903 if (range < (2 * session->frames_per_timecode_frame())) { /* 0 - 2 frames */
904 timecode_ruler_scale = timecode_show_bits;
905 timecode_mark_modulo = 20;
906 timecode_nmarks = 2 + (2 * session->config.get_subframes_per_frame());
907 } else if (range <= (fr / 4)) { /* 2 frames - 0.250 second */
908 timecode_ruler_scale = timecode_show_frames;
909 timecode_mark_modulo = 1;
910 timecode_nmarks = 2 + (range / (nframes64_t)session->frames_per_timecode_frame());
911 } else if (range <= (fr / 2)) { /* 0.25-0.5 second */
912 timecode_ruler_scale = timecode_show_frames;
913 timecode_mark_modulo = 2;
914 timecode_nmarks = 2 + (range / (nframes64_t)session->frames_per_timecode_frame());
915 } else if (range <= fr) { /* 0.5-1 second */
916 timecode_ruler_scale = timecode_show_frames;
917 timecode_mark_modulo = 5;
918 timecode_nmarks = 2 + (range / (nframes64_t)session->frames_per_timecode_frame());
919 } else if (range <= 2 * fr) { /* 1-2 seconds */
920 timecode_ruler_scale = timecode_show_frames;
921 timecode_mark_modulo = 10;
922 timecode_nmarks = 2 + (range / (nframes64_t)session->frames_per_timecode_frame());
923 } else if (range <= 8 * fr) { /* 2-8 seconds */
924 timecode_ruler_scale = timecode_show_seconds;
925 timecode_mark_modulo = 1;
926 timecode_nmarks = 2 + (range / fr);
927 } else if (range <= 16 * fr) { /* 8-16 seconds */
928 timecode_ruler_scale = timecode_show_seconds;
929 timecode_mark_modulo = 2;
930 timecode_nmarks = 2 + (range / fr);
931 } else if (range <= 30 * fr) { /* 16-30 seconds */
932 timecode_ruler_scale = timecode_show_seconds;
933 timecode_mark_modulo = 5;
934 timecode_nmarks = 2 + (range / fr);
935 } else if (range <= 60 * fr) { /* 30-60 seconds */
936 timecode_ruler_scale = timecode_show_seconds;
937 timecode_mark_modulo = 5;
938 timecode_nmarks = 2 + (range / fr);
939 } else if (range <= 2 * 60 * fr) { /* 1-2 minutes */
940 timecode_ruler_scale = timecode_show_seconds;
941 timecode_mark_modulo = 15;
942 timecode_nmarks = 2 + (range / fr);
943 } else if (range <= 4 * 60 * fr) { /* 2-4 minutes */
944 timecode_ruler_scale = timecode_show_seconds;
945 timecode_mark_modulo = 30;
946 timecode_nmarks = 2 + (range / fr);
947 } else if (range <= 10 * 60 * fr) { /* 4-10 minutes */
948 timecode_ruler_scale = timecode_show_minutes;
949 timecode_mark_modulo = 2;
950 timecode_nmarks = 2 + 10;
951 } else if (range <= 30 * 60 * fr) { /* 10-30 minutes */
952 timecode_ruler_scale = timecode_show_minutes;
953 timecode_mark_modulo = 5;
954 timecode_nmarks = 2 + 30;
955 } else if (range <= 60 * 60 * fr) { /* 30 minutes - 1hr */
956 timecode_ruler_scale = timecode_show_minutes;
957 timecode_mark_modulo = 10;
958 timecode_nmarks = 2 + 60;
959 } else if (range <= 4 * 60 * 60 * fr) { /* 1 - 4 hrs*/
960 timecode_ruler_scale = timecode_show_minutes;
961 timecode_mark_modulo = 30;
962 timecode_nmarks = 2 + (60 * 4);
963 } else if (range <= 8 * 60 * 60 * fr) { /* 4 - 8 hrs*/
964 timecode_ruler_scale = timecode_show_hours;
965 timecode_mark_modulo = 1;
966 timecode_nmarks = 2 + 8;
967 } else if (range <= 16 * 60 * 60 * fr) { /* 16-24 hrs*/
968 timecode_ruler_scale = timecode_show_hours;
969 timecode_mark_modulo = 1;
970 timecode_nmarks = 2 + 24;
973 /* not possible if nframes64_t is a 32 bit quantity */
975 timecode_ruler_scale = timecode_show_hours;
976 timecode_mark_modulo = 4;
977 timecode_nmarks = 2 + 24;
983 Editor::metric_get_timecode (GtkCustomRulerMark **marks, gdouble lower, gdouble /*upper*/, gint /*maxchars*/)
987 Timecode::Time timecode;
995 if (lower > (spacer = (nframes64_t)(128 * Editor::get_current_zoom ()))) {
996 lower = lower - spacer;
1001 pos = (nframes_t) floor (lower);
1003 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * timecode_nmarks);
1004 switch (timecode_ruler_scale) {
1005 case timecode_show_bits:
1007 // Find timecode time of this sample (pos) with subframe accuracy
1008 session->sample_to_timecode(pos, timecode, true /* use_offset */, true /* use_subframes */ );
1010 for (n = 0; n < timecode_nmarks; n++) {
1011 session->timecode_to_sample(timecode, pos, true /* use_offset */, true /* use_subframes */ );
1012 if ((timecode.subframes % timecode_mark_modulo) == 0) {
1013 if (timecode.subframes == 0) {
1014 (*marks)[n].style = GtkCustomRulerMarkMajor;
1015 snprintf (buf, sizeof(buf), "%s%02u:%02u:%02u:%02u", timecode.negative ? "-" : "", timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
1017 (*marks)[n].style = GtkCustomRulerMarkMinor;
1018 snprintf (buf, sizeof(buf), ".%02u", timecode.subframes);
1021 snprintf (buf, sizeof(buf)," ");
1022 (*marks)[n].style = GtkCustomRulerMarkMicro;
1025 (*marks)[n].label = g_strdup (buf);
1026 (*marks)[n].position = pos;
1028 // Increment subframes by one
1029 Timecode::increment_subframes( timecode, session->config.get_subframes_per_frame() );
1032 case timecode_show_seconds:
1033 // Find timecode time of this sample (pos)
1034 session->sample_to_timecode(pos, timecode, true /* use_offset */, false /* use_subframes */ );
1035 // Go to next whole second down
1036 Timecode::seconds_floor( timecode );
1038 for (n = 0; n < timecode_nmarks; n++) {
1039 session->timecode_to_sample(timecode, pos, true /* use_offset */, false /* use_subframes */ );
1040 if ((timecode.seconds % timecode_mark_modulo) == 0) {
1041 if (timecode.seconds == 0) {
1042 (*marks)[n].style = GtkCustomRulerMarkMajor;
1043 (*marks)[n].position = pos;
1045 (*marks)[n].style = GtkCustomRulerMarkMinor;
1046 (*marks)[n].position = pos;
1048 snprintf (buf, sizeof(buf), "%s%02u:%02u:%02u:%02u", timecode.negative ? "-" : "", timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
1050 snprintf (buf, sizeof(buf)," ");
1051 (*marks)[n].style = GtkCustomRulerMarkMicro;
1052 (*marks)[n].position = pos;
1055 (*marks)[n].label = g_strdup (buf);
1056 Timecode::increment_seconds( timecode, session->config.get_subframes_per_frame() );
1059 case timecode_show_minutes:
1060 // Find timecode time of this sample (pos)
1061 session->sample_to_timecode(pos, timecode, true /* use_offset */, false /* use_subframes */ );
1062 // Go to next whole minute down
1063 Timecode::minutes_floor( timecode );
1065 for (n = 0; n < timecode_nmarks; n++) {
1066 session->timecode_to_sample(timecode, pos, true /* use_offset */, false /* use_subframes */ );
1067 if ((timecode.minutes % timecode_mark_modulo) == 0) {
1068 if (timecode.minutes == 0) {
1069 (*marks)[n].style = GtkCustomRulerMarkMajor;
1071 (*marks)[n].style = GtkCustomRulerMarkMinor;
1073 snprintf (buf, sizeof(buf), "%s%02u:%02u:%02u:%02u", timecode.negative ? "-" : "", timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
1075 snprintf (buf, sizeof(buf)," ");
1076 (*marks)[n].style = GtkCustomRulerMarkMicro;
1079 (*marks)[n].label = g_strdup (buf);
1080 (*marks)[n].position = pos;
1081 Timecode::increment_minutes( timecode, session->config.get_subframes_per_frame() );
1085 case timecode_show_hours:
1086 // Find timecode time of this sample (pos)
1087 session->sample_to_timecode(pos, timecode, true /* use_offset */, false /* use_subframes */ );
1088 // Go to next whole hour down
1089 Timecode::hours_floor( timecode );
1091 for (n = 0; n < timecode_nmarks; n++) {
1092 session->timecode_to_sample(timecode, pos, true /* use_offset */, false /* use_subframes */ );
1093 if ((timecode.hours % timecode_mark_modulo) == 0) {
1094 (*marks)[n].style = GtkCustomRulerMarkMajor;
1095 snprintf (buf, sizeof(buf), "%s%02u:%02u:%02u:%02u", timecode.negative ? "-" : "", timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
1097 snprintf (buf, sizeof(buf)," ");
1098 (*marks)[n].style = GtkCustomRulerMarkMicro;
1101 (*marks)[n].label = g_strdup (buf);
1102 (*marks)[n].position = pos;
1104 Timecode::increment_hours( timecode, session->config.get_subframes_per_frame() );
1107 case timecode_show_frames:
1108 // Find timecode time of this sample (pos)
1109 session->sample_to_timecode(pos, timecode, true /* use_offset */, false /* use_subframes */ );
1110 // Go to next whole frame down
1111 Timecode::frames_floor( timecode );
1113 for (n = 0; n < timecode_nmarks; n++) {
1114 session->timecode_to_sample(timecode, pos, true /* use_offset */, false /* use_subframes */ );
1115 if ((timecode.frames % timecode_mark_modulo) == 0) {
1116 if (timecode.frames == 0) {
1117 (*marks)[n].style = GtkCustomRulerMarkMajor;
1119 (*marks)[n].style = GtkCustomRulerMarkMinor;
1121 (*marks)[n].position = pos;
1122 snprintf (buf, sizeof(buf), "%s%02u:%02u:%02u:%02u", timecode.negative ? "-" : "", timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
1124 snprintf (buf, sizeof(buf)," ");
1125 (*marks)[n].style = GtkCustomRulerMarkMicro;
1126 (*marks)[n].position = pos;
1129 (*marks)[n].label = g_strdup (buf);
1130 Timecode::increment( timecode, session->config.get_subframes_per_frame() );
1136 return timecode_nmarks;
1141 Editor::compute_bbt_ruler_scale (nframes64_t lower, nframes64_t upper)
1146 TempoMap::BBTPointList::iterator i;
1147 BBT_Time lower_beat, upper_beat; // the beats at each end of the ruler
1149 session->bbt_time((jack_nframes_t) lower, lower_beat);
1150 session->bbt_time((jack_nframes_t) upper, upper_beat);
1153 bbt_accent_modulo = 1;
1154 bbt_bar_helper_on = false;
1158 bbt_ruler_scale = bbt_over;
1160 switch (_snap_type) {
1161 case SnapToAThirdBeat:
1162 bbt_beat_subdivision = 3;
1164 case SnapToAQuarterBeat:
1165 bbt_beat_subdivision = 4;
1167 case SnapToAEighthBeat:
1168 bbt_beat_subdivision = 8;
1169 bbt_accent_modulo = 2;
1171 case SnapToASixteenthBeat:
1172 bbt_beat_subdivision = 16;
1173 bbt_accent_modulo = 4;
1175 case SnapToAThirtysecondBeat:
1176 bbt_beat_subdivision = 32;
1177 bbt_accent_modulo = 8;
1180 bbt_beat_subdivision = 4;
1184 if (current_bbt_points == 0 || current_bbt_points->empty()) {
1188 i = current_bbt_points->end();
1190 if ((*i).beat >= (*current_bbt_points->begin()).beat) {
1191 bbt_bars = (*i).bar - (*current_bbt_points->begin()).bar;
1193 bbt_bars = (*i).bar - (*current_bbt_points->begin()).bar - 1;
1195 beats = current_bbt_points->size() - bbt_bars;
1197 /*Only show the bar helper if there aren't many bars on the screen */
1198 if ((bbt_bars < 2) || (beats < 5)) {
1199 bbt_bar_helper_on = true;
1202 if (bbt_bars > 8192) {
1203 bbt_ruler_scale = bbt_over;
1204 } else if (bbt_bars > 1024) {
1205 bbt_ruler_scale = bbt_show_64;
1206 } else if (bbt_bars > 256) {
1207 bbt_ruler_scale = bbt_show_16;
1208 } else if (bbt_bars > 64) {
1209 bbt_ruler_scale = bbt_show_4;
1210 } else if (bbt_bars > 10) {
1211 bbt_ruler_scale = bbt_show_1;
1212 } else if (bbt_bars > 2) {
1213 bbt_ruler_scale = bbt_show_beats;
1214 } else if (bbt_bars > 0) {
1215 bbt_ruler_scale = bbt_show_ticks;
1217 bbt_ruler_scale = bbt_show_ticks_detail;
1220 if ((bbt_ruler_scale == bbt_show_ticks_detail) && (lower_beat.beats == upper_beat.beats) && (upper_beat.ticks - lower_beat.ticks <= Meter::ticks_per_beat / 4)) {
1221 bbt_ruler_scale = bbt_show_ticks_super_detail;
1226 Editor::metric_get_bbt (GtkCustomRulerMark **marks, gdouble lower, gdouble /*upper*/, gint /*maxchars*/)
1232 TempoMap::BBTPointList::iterator i;
1238 nframes64_t next_beat_pos;
1244 nframes64_t frame_skip;
1245 double frame_skip_error;
1246 double bbt_position_of_helper;
1247 double accumulated_error;
1248 bool i_am_accented = false;
1249 bool helper_active = false;
1251 if (current_bbt_points == 0 || current_bbt_points->empty()) {
1255 switch (bbt_ruler_scale) {
1257 case bbt_show_beats:
1258 beats = current_bbt_points->size();
1259 bbt_nmarks = beats + 2;
1261 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1263 (*marks)[0].label = g_strdup(" ");
1264 (*marks)[0].position = lower;
1265 (*marks)[0].style = GtkCustomRulerMarkMicro;
1267 for (n = 1, i = current_bbt_points->begin(); n < bbt_nmarks && i != current_bbt_points->end(); ++i) {
1268 if ((*i).type != TempoMap::Beat) {
1271 if ((*i).frame < lower && (bbt_bar_helper_on)) {
1272 snprintf (buf, sizeof(buf), "<%" PRIu32 "|%" PRIu32, (*i).bar, (*i).beat);
1273 (*marks)[0].label = g_strdup (buf);
1274 helper_active = true;
1277 if ((*i).beat == 1) {
1278 (*marks)[n].style = GtkCustomRulerMarkMajor;
1279 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1280 } else if (((*i).beat % 2 == 1)) {
1281 (*marks)[n].style = GtkCustomRulerMarkMinor;
1282 snprintf (buf, sizeof(buf), " ");
1284 (*marks)[n].style = GtkCustomRulerMarkMicro;
1285 snprintf (buf, sizeof(buf), " ");
1287 (*marks)[n].label = g_strdup (buf);
1288 (*marks)[n].position = (*i).frame;
1294 case bbt_show_ticks:
1296 beats = current_bbt_points->size();
1297 bbt_nmarks = (beats + 2) * bbt_beat_subdivision;
1299 bbt_position_of_helper = lower + (30 * Editor::get_current_zoom ());
1300 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1302 (*marks)[0].label = g_strdup(" ");
1303 (*marks)[0].position = lower;
1304 (*marks)[0].style = GtkCustomRulerMarkMicro;
1306 for (n = 1, i = current_bbt_points->begin(); n < bbt_nmarks && i != current_bbt_points->end(); ++i) {
1307 if ((*i).type != TempoMap::Beat) {
1310 if ((*i).frame < lower && (bbt_bar_helper_on)) {
1311 snprintf (buf, sizeof(buf), "<%" PRIu32 "|%" PRIu32, (*i).bar, (*i).beat);
1312 (*marks)[0].label = g_strdup (buf);
1313 helper_active = true;
1316 if ((*i).beat == 1) {
1317 (*marks)[n].style = GtkCustomRulerMarkMajor;
1318 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1320 (*marks)[n].style = GtkCustomRulerMarkMinor;
1321 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).beat);
1323 if (((*i).frame < bbt_position_of_helper) && helper_active) {
1324 snprintf (buf, sizeof(buf), " ");
1326 (*marks)[n].label = g_strdup (buf);
1327 (*marks)[n].position = (*i).frame;
1331 /* Add the tick marks */
1333 /* Find the next beat */
1334 next_beat.beats = (*i).beat;
1335 next_beat.bars = (*i).bar;
1336 next_beat.ticks = 0;
1338 if ((*i).meter->beats_per_bar() > (next_beat.beats + 1)) {
1339 next_beat.beats += 1;
1341 next_beat.bars += 1;
1342 next_beat.beats = 1;
1345 next_beat_pos = session->tempo_map().frame_time(next_beat);
1347 frame_skip = (nframes64_t) floor (frame_skip_error = (session->frame_rate() * 60) / (bbt_beat_subdivision * (*i).tempo->beats_per_minute()));
1348 frame_skip_error -= frame_skip;
1349 skip = (uint32_t) (Meter::ticks_per_beat / bbt_beat_subdivision);
1351 pos = (*i).frame + frame_skip;
1352 accumulated_error = frame_skip_error;
1356 for (t = 0; (tick < Meter::ticks_per_beat) && (n < bbt_nmarks) && (pos < next_beat_pos) ; pos += frame_skip, tick += skip, ++t) {
1358 if (t % bbt_accent_modulo == (bbt_accent_modulo - 1)) {
1359 i_am_accented = true;
1362 snprintf (buf, sizeof(buf), " ");
1363 (*marks)[n].label = g_strdup (buf);
1365 /* Error compensation for float to nframes64_t*/
1366 accumulated_error += frame_skip_error;
1367 if (accumulated_error > 1) {
1369 accumulated_error -= 1.0f;
1372 (*marks)[n].position = pos;
1374 if ((bbt_beat_subdivision > 4) && i_am_accented) {
1375 (*marks)[n].style = GtkCustomRulerMarkMinor;
1377 (*marks)[n].style = GtkCustomRulerMarkMicro;
1379 i_am_accented = false;
1386 case bbt_show_ticks_detail:
1388 beats = current_bbt_points->size();
1389 bbt_nmarks = (beats + 2) * bbt_beat_subdivision;
1391 bbt_position_of_helper = lower + (30 * Editor::get_current_zoom ());
1392 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1394 (*marks)[0].label = g_strdup(" ");
1395 (*marks)[0].position = lower;
1396 (*marks)[0].style = GtkCustomRulerMarkMicro;
1398 for (n = 1, i = current_bbt_points->begin(); n < bbt_nmarks && i != current_bbt_points->end(); ++i) {
1399 if ((*i).type != TempoMap::Beat) {
1402 if ((*i).frame < lower && (bbt_bar_helper_on)) {
1403 snprintf (buf, sizeof(buf), "<%" PRIu32 "|%" PRIu32, (*i).bar, (*i).beat);
1404 (*marks)[0].label = g_strdup (buf);
1405 helper_active = true;
1408 if ((*i).beat == 1) {
1409 (*marks)[n].style = GtkCustomRulerMarkMajor;
1410 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1412 (*marks)[n].style = GtkCustomRulerMarkMinor;
1413 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).beat);
1415 if (((*i).frame < bbt_position_of_helper) && helper_active) {
1416 snprintf (buf, sizeof(buf), " ");
1418 (*marks)[n].label = g_strdup (buf);
1419 (*marks)[n].position = (*i).frame;
1423 /* Add the tick marks */
1425 /* Find the next beat */
1427 next_beat.beats = (*i).beat;
1428 next_beat.bars = (*i).bar;
1430 if ((*i).meter->beats_per_bar() > (next_beat.beats + 1)) {
1431 next_beat.beats += 1;
1433 next_beat.bars += 1;
1434 next_beat.beats = 1;
1437 next_beat_pos = session->tempo_map().frame_time(next_beat);
1439 frame_skip = (nframes64_t) floor (frame_skip_error = (session->frame_rate() * 60) / (bbt_beat_subdivision * (*i).tempo->beats_per_minute()));
1440 frame_skip_error -= frame_skip;
1441 skip = (uint32_t) (Meter::ticks_per_beat / bbt_beat_subdivision);
1443 pos = (*i).frame + frame_skip;
1444 accumulated_error = frame_skip_error;
1448 for (t = 0; (tick < Meter::ticks_per_beat) && (n < bbt_nmarks) && (pos < next_beat_pos) ; pos += frame_skip, tick += skip, ++t) {
1450 if (t % bbt_accent_modulo == (bbt_accent_modulo - 1)) {
1451 i_am_accented = true;
1454 if (i_am_accented && (pos > bbt_position_of_helper)){
1455 snprintf (buf, sizeof(buf), "%" PRIu32, tick);
1457 snprintf (buf, sizeof(buf), " ");
1460 (*marks)[n].label = g_strdup (buf);
1462 /* Error compensation for float to nframes64_t*/
1463 accumulated_error += frame_skip_error;
1464 if (accumulated_error > 1) {
1466 accumulated_error -= 1.0f;
1469 (*marks)[n].position = pos;
1471 if ((bbt_beat_subdivision > 4) && i_am_accented) {
1472 (*marks)[n].style = GtkCustomRulerMarkMinor;
1474 (*marks)[n].style = GtkCustomRulerMarkMicro;
1476 i_am_accented = false;
1483 case bbt_show_ticks_super_detail:
1485 beats = current_bbt_points->size();
1486 bbt_nmarks = (beats + 2) * bbt_beat_subdivision;
1488 bbt_position_of_helper = lower + (30 * Editor::get_current_zoom ());
1489 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1491 (*marks)[0].label = g_strdup(" ");
1492 (*marks)[0].position = lower;
1493 (*marks)[0].style = GtkCustomRulerMarkMicro;
1495 for (n = 1, i = current_bbt_points->begin(); n < bbt_nmarks && i != current_bbt_points->end(); ++i) {
1496 if ((*i).type != TempoMap::Beat) {
1499 if ((*i).frame < lower && (bbt_bar_helper_on)) {
1500 snprintf (buf, sizeof(buf), "<%" PRIu32 "|%" PRIu32, (*i).bar, (*i).beat);
1501 (*marks)[0].label = g_strdup (buf);
1502 helper_active = true;
1505 if ((*i).beat == 1) {
1506 (*marks)[n].style = GtkCustomRulerMarkMajor;
1507 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1509 (*marks)[n].style = GtkCustomRulerMarkMinor;
1510 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).beat);
1512 if (((*i).frame < bbt_position_of_helper) && helper_active) {
1513 snprintf (buf, sizeof(buf), " ");
1515 (*marks)[n].label = g_strdup (buf);
1516 (*marks)[n].position = (*i).frame;
1520 /* Add the tick marks */
1522 /* Find the next beat */
1524 next_beat.beats = (*i).beat;
1525 next_beat.bars = (*i).bar;
1527 if ((*i).meter->beats_per_bar() > (next_beat.beats + 1)) {
1528 next_beat.beats += 1;
1530 next_beat.bars += 1;
1531 next_beat.beats = 1;
1534 next_beat_pos = session->tempo_map().frame_time(next_beat);
1536 frame_skip = (nframes64_t) floor (frame_skip_error = (session->frame_rate() * 60) / (bbt_beat_subdivision * (*i).tempo->beats_per_minute()));
1537 frame_skip_error -= frame_skip;
1538 skip = (uint32_t) (Meter::ticks_per_beat / bbt_beat_subdivision);
1540 pos = (*i).frame + frame_skip;
1541 accumulated_error = frame_skip_error;
1545 for (t = 0; (tick < Meter::ticks_per_beat) && (n < bbt_nmarks) && (pos < next_beat_pos) ; pos += frame_skip, tick += skip, ++t) {
1547 if (t % bbt_accent_modulo == (bbt_accent_modulo - 1)) {
1548 i_am_accented = true;
1551 if (pos > bbt_position_of_helper) {
1552 snprintf (buf, sizeof(buf), "%" PRIu32, tick);
1554 snprintf (buf, sizeof(buf), " ");
1557 (*marks)[n].label = g_strdup (buf);
1559 /* Error compensation for float to nframes64_t*/
1560 accumulated_error += frame_skip_error;
1561 if (accumulated_error > 1) {
1563 accumulated_error -= 1.0f;
1566 (*marks)[n].position = pos;
1568 if ((bbt_beat_subdivision > 4) && i_am_accented) {
1569 (*marks)[n].style = GtkCustomRulerMarkMinor;
1571 (*marks)[n].style = GtkCustomRulerMarkMicro;
1573 i_am_accented = false;
1582 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1583 snprintf (buf, sizeof(buf), "cannot handle %" PRIu32 " bars", bbt_bars );
1584 (*marks)[0].style = GtkCustomRulerMarkMajor;
1585 (*marks)[0].label = g_strdup (buf);
1586 (*marks)[0].position = lower;
1592 bbt_nmarks = (gint) (bbt_bars / 64) + 1;
1593 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1594 for (n = 0, i = current_bbt_points->begin(); i != current_bbt_points->end() && n < bbt_nmarks; i++) {
1595 if ((*i).type == TempoMap::Bar) {
1596 if ((*i).bar % 64 == 1) {
1597 if ((*i).bar % 256 == 1) {
1598 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1599 (*marks)[n].style = GtkCustomRulerMarkMajor;
1601 snprintf (buf, sizeof(buf), " ");
1602 if ((*i).bar % 256 == 129) {
1603 (*marks)[n].style = GtkCustomRulerMarkMinor;
1605 (*marks)[n].style = GtkCustomRulerMarkMicro;
1608 (*marks)[n].label = g_strdup (buf);
1609 (*marks)[n].position = (*i).frame;
1617 bbt_nmarks = (bbt_bars / 16) + 1;
1618 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1619 for (n = 0, i = current_bbt_points->begin(); i != current_bbt_points->end() && n < bbt_nmarks; i++) {
1620 if ((*i).type == TempoMap::Bar) {
1621 if ((*i).bar % 16 == 1) {
1622 if ((*i).bar % 64 == 1) {
1623 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1624 (*marks)[n].style = GtkCustomRulerMarkMajor;
1626 snprintf (buf, sizeof(buf), " ");
1627 if ((*i).bar % 64 == 33) {
1628 (*marks)[n].style = GtkCustomRulerMarkMinor;
1630 (*marks)[n].style = GtkCustomRulerMarkMicro;
1633 (*marks)[n].label = g_strdup (buf);
1634 (*marks)[n].position = (*i).frame;
1642 bbt_nmarks = (bbt_bars / 4) + 1;
1643 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1644 for (n = 0, i = current_bbt_points->begin(); i != current_bbt_points->end() && n < bbt_nmarks; ++i) {
1645 if ((*i).type == TempoMap::Bar) {
1646 if ((*i).bar % 4 == 1) {
1647 if ((*i).bar % 16 == 1) {
1648 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1649 (*marks)[n].style = GtkCustomRulerMarkMajor;
1651 snprintf (buf, sizeof(buf), " ");
1652 if ((*i).bar % 16 == 9) {
1653 (*marks)[n].style = GtkCustomRulerMarkMinor;
1655 (*marks)[n].style = GtkCustomRulerMarkMicro;
1658 (*marks)[n].label = g_strdup (buf);
1659 (*marks)[n].position = (*i).frame;
1668 bbt_nmarks = bbt_bars + 2;
1669 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks );
1670 for (n = 0, i = current_bbt_points->begin(); i != current_bbt_points->end() && n < bbt_nmarks; i++) {
1671 if ((*i).type == TempoMap::Bar) {
1672 if ((*i).bar % 4 == 1) {
1673 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1674 (*marks)[n].style = GtkCustomRulerMarkMajor;
1676 snprintf (buf, sizeof(buf), " ");
1677 if ((*i).bar % 4 == 3) {
1678 (*marks)[n].style = GtkCustomRulerMarkMinor;
1680 (*marks)[n].style = GtkCustomRulerMarkMicro;
1683 (*marks)[n].label = g_strdup (buf);
1684 (*marks)[n].position = (*i).frame;
1693 return n; //return the actual number of marks made, since we might have skipped some from fractional time signatures
1698 Editor::metric_get_frames (GtkCustomRulerMark **marks, gdouble lower, gdouble upper, gint /*maxchars*/)
1700 nframes64_t mark_interval;
1702 nframes64_t ilower = (nframes64_t) floor (lower);
1703 nframes64_t iupper = (nframes64_t) floor (upper);
1712 mark_interval = (iupper - ilower) / 5;
1713 if (mark_interval > session->frame_rate()) {
1714 mark_interval -= mark_interval % session->frame_rate();
1716 mark_interval = session->frame_rate() / (session->frame_rate() / mark_interval ) ;
1719 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * nmarks);
1720 for (n = 0, pos = ilower; n < nmarks; pos += mark_interval, ++n) {
1721 snprintf (buf, sizeof(buf), "%" PRIi64, pos);
1722 (*marks)[n].label = g_strdup (buf);
1723 (*marks)[n].position = pos;
1724 (*marks)[n].style = GtkCustomRulerMarkMajor;
1731 sample_to_clock_parts ( nframes64_t sample,
1732 nframes64_t sample_rate,
1746 hrs = left / (sample_rate * 60 * 60);
1747 left -= hrs * sample_rate * 60 * 60;
1748 mins = left / (sample_rate * 60);
1749 left -= mins * sample_rate * 60;
1750 secs = left / sample_rate;
1751 left -= secs * sample_rate;
1752 millisecs = left * 1000 / sample_rate;
1754 *millisecs_p = millisecs;
1763 Editor::set_minsec_ruler_scale (gdouble lower, gdouble upper)
1773 fr = session->frame_rate();
1775 /* to prevent 'flashing' */
1776 if (lower > (spacer = (nframes64_t)(128 * Editor::get_current_zoom ()))) {
1782 range = (nframes64_t) (upper - lower);
1784 if (range < (fr / 50)) {
1785 minsec_mark_interval = fr / 1000; /* show 1/1000 seconds */
1786 minsec_ruler_scale = minsec_show_frames;
1787 minsec_mark_modulo = 10;
1788 } else if (range <= (fr / 10)) { /* 0-0.1 second */
1789 minsec_mark_interval = fr / 1000; /* show 1/1000 seconds */
1790 minsec_ruler_scale = minsec_show_frames;
1791 minsec_mark_modulo = 10;
1792 } else if (range <= (fr / 2)) { /* 0-0.5 second */
1793 minsec_mark_interval = fr / 100; /* show 1/100 seconds */
1794 minsec_ruler_scale = minsec_show_frames;
1795 minsec_mark_modulo = 100;
1796 } else if (range <= fr) { /* 0-1 second */
1797 minsec_mark_interval = fr / 10; /* show 1/10 seconds */
1798 minsec_ruler_scale = minsec_show_frames;
1799 minsec_mark_modulo = 200;
1800 } else if (range <= 2 * fr) { /* 1-2 seconds */
1801 minsec_mark_interval = fr / 10; /* show 1/10 seconds */
1802 minsec_ruler_scale = minsec_show_frames;
1803 minsec_mark_modulo = 500;
1804 } else if (range <= 8 * fr) { /* 2-5 seconds */
1805 minsec_mark_interval = fr / 5; /* show 2 seconds */
1806 minsec_ruler_scale = minsec_show_frames;
1807 minsec_mark_modulo = 1000;
1808 } else if (range <= 16 * fr) { /* 8-16 seconds */
1809 minsec_mark_interval = fr; /* show 1 seconds */
1810 minsec_ruler_scale = minsec_show_seconds;
1811 minsec_mark_modulo = 2;
1812 } else if (range <= 30 * fr) { /* 10-30 seconds */
1813 minsec_mark_interval = fr; /* show 1 seconds */
1814 minsec_ruler_scale = minsec_show_seconds;
1815 minsec_mark_modulo = 5;
1816 } else if (range <= 60 * fr) { /* 30-60 seconds */
1817 minsec_mark_interval = fr; /* show 1 seconds */
1818 minsec_ruler_scale = minsec_show_seconds;
1819 minsec_mark_modulo = 5;
1820 } else if (range <= 2 * 60 * fr) { /* 1-2 minutes */
1821 minsec_mark_interval = 5 * fr; /* show 5 seconds */
1822 minsec_ruler_scale = minsec_show_seconds;
1823 minsec_mark_modulo = 3;
1824 } else if (range <= 4 * 60 * fr) { /* 4 minutes */
1825 minsec_mark_interval = 5 * fr; /* show 10 seconds */
1826 minsec_ruler_scale = minsec_show_seconds;
1827 minsec_mark_modulo = 30;
1828 } else if (range <= 10 * 60 * fr) { /* 10 minutes */
1829 minsec_mark_interval = 30 * fr; /* show 30 seconds */
1830 minsec_ruler_scale = minsec_show_seconds;
1831 minsec_mark_modulo = 120;
1832 } else if (range <= 30 * 60 * fr) { /* 10-30 minutes */
1833 minsec_mark_interval = 60 * fr; /* show 1 minute */
1834 minsec_ruler_scale = minsec_show_minutes;
1835 minsec_mark_modulo = 5;
1836 } else if (range <= 60 * 60 * fr) { /* 30 minutes - 1hr */
1837 minsec_mark_interval = 2 * 60 * fr; /* show 2 minutes */
1838 minsec_ruler_scale = minsec_show_minutes;
1839 minsec_mark_modulo = 10;
1840 } else if (range <= 4 * 60 * 60 * fr) { /* 1 - 4 hrs*/
1841 minsec_mark_interval = 5 * 60 * fr; /* show 10 minutes */
1842 minsec_ruler_scale = minsec_show_minutes;
1843 minsec_mark_modulo = 30;
1844 } else if (range <= 8 * 60 * 60 * fr) { /* 4 - 8 hrs*/
1845 minsec_mark_interval = 20 * 60 * fr; /* show 20 minutes */
1846 minsec_ruler_scale = minsec_show_minutes;
1847 minsec_mark_modulo = 60;
1848 } else if (range <= 16 * 60 * 60 * fr) { /* 16-24 hrs*/
1849 minsec_mark_interval = 60 * 60 * fr; /* show 60 minutes */
1850 minsec_ruler_scale = minsec_show_hours;
1851 minsec_mark_modulo = 2;
1854 /* not possible if nframes64_t is a 32 bit quantity */
1856 minsec_mark_interval = 4 * 60 * 60 * fr; /* show 4 hrs */
1858 minsec_nmarks = 2 + (range / minsec_mark_interval);
1862 Editor::metric_get_minsec (GtkCustomRulerMark **marks, gdouble lower, gdouble /*upper*/, gint /*maxchars*/)
1866 long hrs, mins, secs, millisecs;
1874 /* to prevent 'flashing' */
1875 if (lower > (spacer = (nframes64_t)(128 * Editor::get_current_zoom ()))) {
1876 lower = lower - spacer;
1881 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * minsec_nmarks);
1882 pos = ((((nframes64_t) floor(lower)) + (minsec_mark_interval/2))/minsec_mark_interval) * minsec_mark_interval;
1883 switch (minsec_ruler_scale) {
1884 case minsec_show_seconds:
1885 for (n = 0; n < minsec_nmarks; pos += minsec_mark_interval, ++n) {
1886 sample_to_clock_parts (pos, session->frame_rate(), &hrs, &mins, &secs, &millisecs);
1887 if (secs % minsec_mark_modulo == 0) {
1889 (*marks)[n].style = GtkCustomRulerMarkMajor;
1891 (*marks)[n].style = GtkCustomRulerMarkMinor;
1893 snprintf (buf, sizeof(buf), "%02ld:%02ld:%02ld.%03ld", hrs, mins, secs, millisecs);
1895 snprintf (buf, sizeof(buf), " ");
1896 (*marks)[n].style = GtkCustomRulerMarkMicro;
1898 (*marks)[n].label = g_strdup (buf);
1899 (*marks)[n].position = pos;
1902 case minsec_show_minutes:
1903 for (n = 0; n < minsec_nmarks; pos += minsec_mark_interval, ++n) {
1904 sample_to_clock_parts (pos, session->frame_rate(), &hrs, &mins, &secs, &millisecs);
1905 if (mins % minsec_mark_modulo == 0) {
1907 (*marks)[n].style = GtkCustomRulerMarkMajor;
1909 (*marks)[n].style = GtkCustomRulerMarkMinor;
1911 snprintf (buf, sizeof(buf), "%02ld:%02ld:%02ld.%03ld", hrs, mins, secs, millisecs);
1913 snprintf (buf, sizeof(buf), " ");
1914 (*marks)[n].style = GtkCustomRulerMarkMicro;
1916 (*marks)[n].label = g_strdup (buf);
1917 (*marks)[n].position = pos;
1920 case minsec_show_hours:
1921 for (n = 0; n < minsec_nmarks; pos += minsec_mark_interval, ++n) {
1922 sample_to_clock_parts (pos, session->frame_rate(), &hrs, &mins, &secs, &millisecs);
1923 if (hrs % minsec_mark_modulo == 0) {
1924 (*marks)[n].style = GtkCustomRulerMarkMajor;
1925 snprintf (buf, sizeof(buf), "%02ld:%02ld:%02ld.%03ld", hrs, mins, secs, millisecs);
1927 snprintf (buf, sizeof(buf), " ");
1928 (*marks)[n].style = GtkCustomRulerMarkMicro;
1930 (*marks)[n].label = g_strdup (buf);
1931 (*marks)[n].position = pos;
1934 case minsec_show_frames:
1935 for (n = 0; n < minsec_nmarks; pos += minsec_mark_interval, ++n) {
1936 sample_to_clock_parts (pos, session->frame_rate(), &hrs, &mins, &secs, &millisecs);
1937 if (millisecs % minsec_mark_modulo == 0) {
1939 (*marks)[n].style = GtkCustomRulerMarkMajor;
1941 (*marks)[n].style = GtkCustomRulerMarkMinor;
1943 snprintf (buf, sizeof(buf), "%02ld:%02ld:%02ld.%03ld", hrs, mins, secs, millisecs);
1945 snprintf (buf, sizeof(buf), " ");
1946 (*marks)[n].style = GtkCustomRulerMarkMicro;
1948 (*marks)[n].label = g_strdup (buf);
1949 (*marks)[n].position = pos;
1954 return minsec_nmarks;