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"
44 using namespace ARDOUR;
47 using namespace Editing;
49 Editor *Editor::ruler_editor;
51 /* the order here must match the "metric" enums in editor.h */
53 GtkCustomMetric Editor::ruler_metrics[4] = {
54 {1, Editor::_metric_get_timecode },
55 {1, Editor::_metric_get_bbt },
56 {1, Editor::_metric_get_frames },
57 {1, Editor::_metric_get_minsec }
61 Editor::initialize_rulers ()
64 ruler_grabbed_widget = 0;
66 _ruler_separator = new Gtk::HSeparator();
67 _ruler_separator->set_size_request(-1, 2);
68 _ruler_separator->set_name("TimebarPadding");
69 _ruler_separator->show();
71 _minsec_ruler = gtk_custom_hruler_new ();
72 minsec_ruler = Glib::wrap (_minsec_ruler);
73 minsec_ruler->set_name ("MinSecRuler");
74 minsec_ruler->set_size_request (-1, (int)timebar_height);
75 gtk_custom_ruler_set_metric (GTK_CUSTOM_RULER(_minsec_ruler), &ruler_metrics[ruler_metric_minsec]);
76 minsec_ruler->hide ();
77 minsec_ruler->set_no_show_all();
79 _timecode_ruler = gtk_custom_hruler_new ();
80 timecode_ruler = Glib::wrap (_timecode_ruler);
81 timecode_ruler->set_name ("TimecodeRuler");
82 timecode_ruler->set_size_request (-1, (int)timebar_height);
83 gtk_custom_ruler_set_metric (GTK_CUSTOM_RULER(_timecode_ruler), &ruler_metrics[ruler_metric_timecode]);
84 timecode_ruler->hide ();
85 timecode_ruler->set_no_show_all();
88 _bbt_ruler = gtk_custom_hruler_new ();
89 bbt_ruler = Glib::wrap (_bbt_ruler);
90 bbt_ruler->set_name ("BBTRuler");
91 bbt_ruler->set_size_request (-1, (int)timebar_height);
92 gtk_custom_ruler_set_metric (GTK_CUSTOM_RULER(_bbt_ruler), &ruler_metrics[ruler_metric_bbt]);
94 bbt_ruler->set_no_show_all();
97 _frames_ruler = gtk_custom_hruler_new ();
98 frames_ruler = Glib::wrap (_frames_ruler);
99 frames_ruler->set_name ("FramesRuler");
100 frames_ruler->set_size_request (-1, (int)timebar_height);
101 gtk_custom_ruler_set_metric (GTK_CUSTOM_RULER(_frames_ruler), &ruler_metrics[ruler_metric_frames]);
102 frames_ruler->hide ();
103 frames_ruler->set_no_show_all();
105 _bbt_ruler = gtk_custom_hruler_new ();
106 bbt_ruler = Glib::wrap (_bbt_ruler);
107 bbt_ruler->set_name ("BBTRuler");
108 bbt_ruler->set_size_request (-1, (int)timebar_height);
109 gtk_custom_ruler_set_metric (GTK_CUSTOM_RULER(_bbt_ruler), &ruler_metrics[ruler_metric_bbt]);
111 bbt_ruler->set_no_show_all();
112 minsec_ruler->hide ();
113 minsec_ruler->set_no_show_all();
116 using namespace Box_Helpers;
117 BoxList & ruler_lab_children = ruler_label_vbox.children();
118 BoxList & ruler_children = time_canvas_vbox.children();
119 BoxList & lab_children = time_button_vbox.children();
121 BoxList::iterator canvaspos = ruler_children.begin();
123 lab_children.push_back (Element(meter_label, PACK_SHRINK, PACK_START));
124 lab_children.push_back (Element(tempo_label, PACK_SHRINK, PACK_START));
125 lab_children.push_back (Element(range_mark_label, PACK_SHRINK, PACK_START));
126 lab_children.push_back (Element(transport_mark_label, PACK_SHRINK, PACK_START));
127 lab_children.push_back (Element(cd_mark_label, PACK_SHRINK, PACK_START));
128 lab_children.push_back (Element(mark_label, PACK_SHRINK, PACK_START));
130 ruler_lab_children.push_back (Element(minsec_label, PACK_SHRINK, PACK_START));
131 ruler_children.insert (canvaspos, Element(*minsec_ruler, PACK_SHRINK, PACK_START));
132 ruler_lab_children.push_back (Element(timecode_label, PACK_SHRINK, PACK_START));
133 ruler_children.insert (canvaspos, Element(*timecode_ruler, PACK_SHRINK, PACK_START));
134 ruler_lab_children.push_back (Element(frame_label, PACK_SHRINK, PACK_START));
135 ruler_children.insert (canvaspos, Element(*frames_ruler, PACK_SHRINK, PACK_START));
136 ruler_lab_children.push_back (Element(bbt_label, PACK_SHRINK, PACK_START));
137 ruler_children.insert (canvaspos, Element(*bbt_ruler, PACK_SHRINK, PACK_START));
139 timecode_ruler->add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::SCROLL_MASK);
140 bbt_ruler->add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::SCROLL_MASK);
141 frames_ruler->add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::SCROLL_MASK);
142 minsec_ruler->add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::SCROLL_MASK);
144 timecode_ruler->signal_button_release_event().connect (sigc::mem_fun(*this, &Editor::ruler_button_release));
145 bbt_ruler->signal_button_release_event().connect (sigc::mem_fun(*this, &Editor::ruler_button_release));
146 frames_ruler->signal_button_release_event().connect (sigc::mem_fun(*this, &Editor::ruler_button_release));
147 minsec_ruler->signal_button_release_event().connect (sigc::mem_fun(*this, &Editor::ruler_button_release));
149 timecode_ruler->signal_button_press_event().connect (sigc::mem_fun(*this, &Editor::ruler_button_press));
150 bbt_ruler->signal_button_press_event().connect (sigc::mem_fun(*this, &Editor::ruler_button_press));
151 frames_ruler->signal_button_press_event().connect (sigc::mem_fun(*this, &Editor::ruler_button_press));
152 minsec_ruler->signal_button_press_event().connect (sigc::mem_fun(*this, &Editor::ruler_button_press));
154 timecode_ruler->signal_motion_notify_event().connect (sigc::mem_fun(*this, &Editor::ruler_mouse_motion));
155 bbt_ruler->signal_motion_notify_event().connect (sigc::mem_fun(*this, &Editor::ruler_mouse_motion));
156 frames_ruler->signal_motion_notify_event().connect (sigc::mem_fun(*this, &Editor::ruler_mouse_motion));
157 minsec_ruler->signal_motion_notify_event().connect (sigc::mem_fun(*this, &Editor::ruler_mouse_motion));
159 timecode_ruler->signal_scroll_event().connect (sigc::mem_fun(*this, &Editor::ruler_scroll));
160 bbt_ruler->signal_scroll_event().connect (sigc::mem_fun(*this, &Editor::ruler_scroll));
161 frames_ruler->signal_scroll_event().connect (sigc::mem_fun(*this, &Editor::ruler_scroll));
162 minsec_ruler->signal_scroll_event().connect (sigc::mem_fun(*this, &Editor::ruler_scroll));
164 visible_timebars = 0; /*this will be changed below */
165 canvas_timebars_vsize = 0;
169 Editor::ruler_scroll (GdkEventScroll* event)
172 int direction = event->direction;
173 bool handled = false;
177 temporal_zoom_step (true);
181 case GDK_SCROLL_DOWN:
182 temporal_zoom_step (false);
186 case GDK_SCROLL_LEFT:
187 xdelta = (current_page_frames() / 2);
188 if (leftmost_frame > xdelta) {
189 reset_x_origin (leftmost_frame - xdelta);
196 case GDK_SCROLL_RIGHT:
197 xdelta = (current_page_frames() / 2);
198 if (max_frames - xdelta > leftmost_frame) {
199 reset_x_origin (leftmost_frame + xdelta);
201 reset_x_origin (max_frames - current_page_frames());
216 Editor::ruler_button_press (GdkEventButton* ev)
222 // jlc: grab ev->window ?
223 //Gtk::Main::grab_add (*minsec_ruler);
224 Widget * grab_widget = 0;
226 if (timecode_ruler->is_realized() && ev->window == timecode_ruler->get_window()->gobj()) {
227 grab_widget = timecode_ruler;
228 } else if (bbt_ruler->is_realized() && ev->window == bbt_ruler->get_window()->gobj()) {
229 grab_widget = bbt_ruler;
230 } else if (frames_ruler->is_realized() && ev->window == frames_ruler->get_window()->gobj()) {
231 grab_widget = frames_ruler;
232 } else if (minsec_ruler->is_realized() && ev->window == minsec_ruler->get_window()->gobj()) {
233 grab_widget = minsec_ruler;
237 grab_widget->add_modal_grab ();
238 ruler_grabbed_widget = grab_widget;
241 if (ev->button == 1) {
242 // Since we will locate the playhead on button release, cancel any running
244 if (_session->is_auditioning()) {
245 _session->cancel_audition ();
248 /* playhead cursor */
249 _drags->set (new CursorDrag (this, &playhead_cursor->canvas_item, false), reinterpret_cast<GdkEvent *> (ev));
250 _dragging_playhead = true;
257 Editor::ruler_button_release (GdkEventButton* ev)
264 Gdk::ModifierType state;
266 if (_drags->active ()) {
267 _drags->end_grab (reinterpret_cast<GdkEvent*> (ev));
268 _dragging_playhead = false;
271 if (ev->button == 3) {
272 /* need to use the correct x,y, the event lies */
273 time_canvas_event_box.get_window()->get_pointer (x, y, state);
275 stop_canvas_autoscroll();
277 nframes64_t where = leftmost_frame + pixel_to_frame (x);
279 popup_ruler_menu (where);
282 if (ruler_grabbed_widget) {
283 ruler_grabbed_widget->remove_modal_grab();
284 ruler_grabbed_widget = 0;
291 Editor::ruler_label_button_release (GdkEventButton* ev)
293 if (ev->button == 3) {
294 Gtk::Menu* m= dynamic_cast<Gtk::Menu*> (ActionManager::get_widget (X_("/RulerMenuPopup")));
296 m->popup (1, ev->time);
305 Editor::ruler_mouse_motion (GdkEventMotion* ev)
311 if (_drags->active ()) {
312 _drags->motion_handler (reinterpret_cast<GdkEvent*> (ev), false);
320 Editor::popup_ruler_menu (nframes64_t where, ItemType t)
322 using namespace Menu_Helpers;
324 if (editor_ruler_menu == 0) {
325 editor_ruler_menu = new Menu;
326 editor_ruler_menu->set_name ("ArdourContextMenu");
329 // always build from scratch
330 MenuList& ruler_items = editor_ruler_menu->items();
331 editor_ruler_menu->set_name ("ArdourContextMenu");
336 ruler_items.push_back (MenuElem (_("New location marker"), sigc::bind ( sigc::mem_fun(*this, &Editor::mouse_add_new_marker), where, false, false)));
337 ruler_items.push_back (MenuElem (_("Clear all locations"), sigc::mem_fun(*this, &Editor::clear_markers)));
338 ruler_items.push_back (MenuElem (_("Unhide locations"), sigc::mem_fun(*this, &Editor::unhide_markers)));
339 ruler_items.push_back (SeparatorElem ());
341 case RangeMarkerBarItem:
342 //ruler_items.push_back (MenuElem (_("New Range")));
343 ruler_items.push_back (MenuElem (_("Clear all ranges"), sigc::mem_fun(*this, &Editor::clear_ranges)));
344 ruler_items.push_back (MenuElem (_("Unhide ranges"), sigc::mem_fun(*this, &Editor::unhide_ranges)));
345 ruler_items.push_back (SeparatorElem ());
348 case TransportMarkerBarItem:
352 case CdMarkerBarItem:
354 ruler_items.push_back (MenuElem (_("New CD track marker"), sigc::bind ( sigc::mem_fun(*this, &Editor::mouse_add_new_marker), where, true, false)));
359 ruler_items.push_back (MenuElem (_("New Tempo"), sigc::bind ( sigc::mem_fun(*this, &Editor::mouse_add_new_tempo_event), where)));
360 ruler_items.push_back (MenuElem (_("Clear tempo")));
361 ruler_items.push_back (SeparatorElem ());
365 ruler_items.push_back (MenuElem (_("New Meter"), sigc::bind ( sigc::mem_fun(*this, &Editor::mouse_add_new_meter_event), where)));
366 ruler_items.push_back (MenuElem (_("Clear meter")));
367 ruler_items.push_back (SeparatorElem ());
374 Glib::RefPtr<Action> action;
376 action = ActionManager::get_action ("Rulers", "toggle-minsec-ruler");
378 ruler_items.push_back (MenuElem (*action->create_menu_item()));
380 if (!Profile->get_sae()) {
381 action = ActionManager::get_action ("Rulers", "toggle-timecode-ruler");
383 ruler_items.push_back (MenuElem (*action->create_menu_item()));
386 action = ActionManager::get_action ("Rulers", "toggle-samples-ruler");
388 ruler_items.push_back (MenuElem (*action->create_menu_item()));
390 action = ActionManager::get_action ("Rulers", "toggle-bbt-ruler");
392 ruler_items.push_back (MenuElem (*action->create_menu_item()));
394 action = ActionManager::get_action ("Rulers", "toggle-meter-ruler");
396 ruler_items.push_back (MenuElem (*action->create_menu_item()));
398 action = ActionManager::get_action ("Rulers", "toggle-tempo-ruler");
400 ruler_items.push_back (MenuElem (*action->create_menu_item()));
402 if (!Profile->get_sae()) {
403 action = ActionManager::get_action ("Rulers", "toggle-range-ruler");
405 ruler_items.push_back (MenuElem (*action->create_menu_item()));
408 action = ActionManager::get_action ("Rulers", "toggle-loop-punch-ruler");
410 ruler_items.push_back (MenuElem (*action->create_menu_item()));
412 action = ActionManager::get_action ("Rulers", "toggle-cd-marker-ruler");
414 ruler_items.push_back (MenuElem (*action->create_menu_item()));
416 action = ActionManager::get_action ("Rulers", "toggle-marker-ruler");
418 ruler_items.push_back (MenuElem (*action->create_menu_item()));
421 editor_ruler_menu->popup (1, gtk_get_current_event_time());
423 no_ruler_shown_update = false;
427 Editor::store_ruler_visibility ()
429 XMLNode* node = new XMLNode(X_("RulerVisibility"));
431 node->add_property (X_("timecode"), ruler_timecode_action->get_active() ? "yes": "no");
432 node->add_property (X_("bbt"), ruler_bbt_action->get_active() ? "yes": "no");
433 node->add_property (X_("frames"), ruler_samples_action->get_active() ? "yes": "no");
434 node->add_property (X_("minsec"), ruler_minsec_action->get_active() ? "yes": "no");
435 node->add_property (X_("tempo"), ruler_tempo_action->get_active() ? "yes": "no");
436 node->add_property (X_("meter"), ruler_meter_action->get_active() ? "yes": "no");
437 node->add_property (X_("marker"), ruler_marker_action->get_active() ? "yes": "no");
438 node->add_property (X_("rangemarker"), ruler_range_action->get_active() ? "yes": "no");
439 node->add_property (X_("transportmarker"), ruler_loop_punch_action->get_active() ? "yes": "no");
440 node->add_property (X_("cdmarker"), ruler_cd_marker_action->get_active() ? "yes": "no");
442 _session->add_extra_xml (*node);
443 _session->set_dirty ();
447 Editor::restore_ruler_visibility ()
450 XMLNode * node = _session->extra_xml (X_("RulerVisibility"));
452 no_ruler_shown_update = true;
455 if ((prop = node->property ("timecode")) != 0) {
456 if (string_is_affirmative (prop->value())) {
457 ruler_timecode_action->set_active (true);
459 ruler_timecode_action->set_active (false);
462 if ((prop = node->property ("bbt")) != 0) {
463 if (string_is_affirmative (prop->value())) {
464 ruler_bbt_action->set_active (true);
466 ruler_bbt_action->set_active (false);
469 if ((prop = node->property ("frames")) != 0) {
470 if (string_is_affirmative (prop->value())) {
471 ruler_samples_action->set_active (true);
473 ruler_samples_action->set_active (false);
476 if ((prop = node->property ("minsec")) != 0) {
477 if (string_is_affirmative (prop->value())) {
478 ruler_minsec_action->set_active (true);
480 ruler_minsec_action->set_active (false);
483 if ((prop = node->property ("tempo")) != 0) {
484 if (string_is_affirmative (prop->value())) {
485 ruler_tempo_action->set_active (true);
487 ruler_tempo_action->set_active (false);
490 if ((prop = node->property ("meter")) != 0) {
491 if (string_is_affirmative (prop->value())) {
492 ruler_meter_action->set_active (true);
494 ruler_meter_action->set_active (false);
497 if ((prop = node->property ("marker")) != 0) {
498 if (string_is_affirmative (prop->value())) {
499 ruler_marker_action->set_active (true);
501 ruler_marker_action->set_active (false);
504 if ((prop = node->property ("rangemarker")) != 0) {
505 if (string_is_affirmative (prop->value())) {
506 ruler_range_action->set_active (true);
508 ruler_range_action->set_active (false);
512 if ((prop = node->property ("transportmarker")) != 0) {
513 if (string_is_affirmative (prop->value())) {
514 ruler_loop_punch_action->set_active (true);
516 ruler_loop_punch_action->set_active (false);
520 if ((prop = node->property ("cdmarker")) != 0) {
521 if (string_is_affirmative (prop->value())) {
522 ruler_cd_marker_action->set_active (true);
524 ruler_cd_marker_action->set_active (false);
528 // this _session doesn't yet know about the cdmarker ruler
529 // as a benefit to the user who doesn't know the feature exists, show the ruler if
530 // any cd marks exist
531 ruler_cd_marker_action->set_active (false);
532 const Locations::LocationList & locs = _session->locations()->list();
533 for (Locations::LocationList::const_iterator i = locs.begin(); i != locs.end(); ++i) {
534 if ((*i)->is_cd_marker()) {
535 ruler_cd_marker_action->set_active (true);
543 no_ruler_shown_update = false;
544 update_ruler_visibility ();
548 Editor::update_ruler_visibility ()
550 int visible_rulers = 0;
552 if (no_ruler_shown_update) {
556 visible_timebars = 0;
558 if (ruler_minsec_action->get_active()) {
560 minsec_label.show ();
561 minsec_ruler->show ();
563 minsec_label.hide ();
564 minsec_ruler->hide ();
567 if (ruler_timecode_action->get_active()) {
569 timecode_label.show ();
570 timecode_ruler->show ();
572 timecode_label.hide ();
573 timecode_ruler->hide ();
576 if (ruler_samples_action->get_active()) {
579 frames_ruler->show ();
582 frames_ruler->hide ();
585 if (ruler_bbt_action->get_active()) {
599 /* gtk update probs require this (damn) */
602 range_mark_label.hide();
603 transport_mark_label.hide();
604 cd_mark_label.hide();
607 if (ruler_meter_action->get_active()) {
608 old_unit_pos = meter_group->property_y();
609 if (tbpos != old_unit_pos) {
610 meter_group->move ( 0.0, tbpos - old_unit_pos);
612 old_unit_pos = meter_bar_group->property_y();
613 if (tbgpos != old_unit_pos) {
614 meter_bar_group->move ( 0.0, tbgpos - old_unit_pos);
616 meter_bar_group->show();
619 tbpos += timebar_height;
620 tbgpos += timebar_height;
623 meter_bar_group->hide();
628 if (ruler_tempo_action->get_active()) {
629 old_unit_pos = tempo_group->property_y();
630 if (tbpos != old_unit_pos) {
631 tempo_group->move(0.0, tbpos - old_unit_pos);
633 old_unit_pos = tempo_bar_group->property_y();
634 if (tbgpos != old_unit_pos) {
635 tempo_bar_group->move ( 0.0, tbgpos - old_unit_pos);
637 tempo_bar_group->show();
640 tbpos += timebar_height;
641 tbgpos += timebar_height;
644 tempo_bar_group->hide();
649 if (!Profile->get_sae() && ruler_range_action->get_active()) {
650 old_unit_pos = range_marker_group->property_y();
651 if (tbpos != old_unit_pos) {
652 range_marker_group->move (0.0, tbpos - old_unit_pos);
654 old_unit_pos = range_marker_bar_group->property_y();
655 if (tbgpos != old_unit_pos) {
656 range_marker_bar_group->move (0.0, tbgpos - old_unit_pos);
658 range_marker_bar_group->show();
659 range_marker_group->show();
660 range_mark_label.show();
662 tbpos += timebar_height;
663 tbgpos += timebar_height;
666 range_marker_bar_group->hide();
667 range_marker_group->hide();
668 range_mark_label.hide();
671 if (ruler_loop_punch_action->get_active()) {
672 old_unit_pos = transport_marker_group->property_y();
673 if (tbpos != old_unit_pos) {
674 transport_marker_group->move ( 0.0, tbpos - old_unit_pos);
676 old_unit_pos = transport_marker_bar_group->property_y();
677 if (tbgpos != old_unit_pos) {
678 transport_marker_bar_group->move ( 0.0, tbgpos - old_unit_pos);
680 transport_marker_bar_group->show();
681 transport_marker_group->show();
682 transport_mark_label.show();
683 tbpos += timebar_height;
684 tbgpos += timebar_height;
687 transport_marker_bar_group->hide();
688 transport_marker_group->hide();
689 transport_mark_label.hide();
692 if (ruler_cd_marker_action->get_active()) {
693 old_unit_pos = cd_marker_group->property_y();
694 if (tbpos != old_unit_pos) {
695 cd_marker_group->move (0.0, tbpos - old_unit_pos);
697 old_unit_pos = cd_marker_bar_group->property_y();
698 if (tbgpos != old_unit_pos) {
699 cd_marker_bar_group->move (0.0, tbgpos - old_unit_pos);
701 cd_marker_bar_group->show();
702 cd_marker_group->show();
703 cd_mark_label.show();
704 tbpos += timebar_height;
705 tbgpos += timebar_height;
707 // make sure all cd markers show up in their respective places
708 update_cd_marker_display();
710 cd_marker_bar_group->hide();
711 cd_marker_group->hide();
712 cd_mark_label.hide();
713 // make sure all cd markers show up in their respective places
714 update_cd_marker_display();
717 if (ruler_marker_action->get_active()) {
718 old_unit_pos = marker_group->property_y();
719 if (tbpos != old_unit_pos) {
720 marker_group->move ( 0.0, tbpos - old_unit_pos);
722 old_unit_pos = marker_bar_group->property_y();
723 if (tbgpos != old_unit_pos) {
724 marker_bar_group->move ( 0.0, tbgpos - old_unit_pos);
726 marker_bar_group->show();
727 marker_group->show();
729 tbpos += timebar_height;
730 tbgpos += timebar_height;
733 marker_bar_group->hide();
734 marker_group->hide();
738 gdouble old_canvas_timebars_vsize = canvas_timebars_vsize;
739 canvas_timebars_vsize = (timebar_height * visible_timebars) - 1;
740 gdouble vertical_pos_delta = canvas_timebars_vsize - old_canvas_timebars_vsize;
741 vertical_adjustment.set_upper(vertical_adjustment.get_upper() + vertical_pos_delta);
742 full_canvas_height += vertical_pos_delta;
744 if (vertical_adjustment.get_value() != 0 && (vertical_adjustment.get_value() + _canvas_height >= full_canvas_height)) {
745 /*if we're at the bottom of the canvas, don't move the _trackview_group*/
746 vertical_adjustment.set_value (full_canvas_height - _canvas_height + 1);
748 _trackview_group->property_y () = - get_trackview_group_vertical_offset ();
749 _background_group->property_y () = - get_trackview_group_vertical_offset ();
750 _trackview_group->move (0, 0);
751 _background_group->move (0, 0);
752 last_trackview_group_vertical_offset = get_trackview_group_vertical_offset ();
755 gdouble bottom_track_pos = vertical_adjustment.get_value() + _canvas_height - canvas_timebars_vsize;
756 std::pair<TimeAxisView*, int> const p = trackview_by_y_position (bottom_track_pos);
758 p.first->clip_to_viewport ();
761 ruler_label_vbox.set_size_request (-1, (int)(timebar_height * visible_rulers));
762 time_canvas_vbox.set_size_request (-1,-1);
764 update_fixed_rulers();
765 redisplay_tempo (false);
769 Editor::update_just_timecode ()
771 ENSURE_GUI_THREAD (*this, &Editor::update_just_timecode)
777 nframes64_t rightmost_frame = leftmost_frame + current_page_frames();
779 if (ruler_timecode_action->get_active()) {
780 gtk_custom_ruler_set_range (GTK_CUSTOM_RULER(_timecode_ruler), leftmost_frame, rightmost_frame,
781 leftmost_frame, _session->current_end_frame());
786 Editor::compute_fixed_ruler_scale ()
792 if (ruler_timecode_action->get_active()) {
793 set_timecode_ruler_scale (leftmost_frame, leftmost_frame + current_page_frames() );
796 if (ruler_minsec_action->get_active()) {
797 set_minsec_ruler_scale (leftmost_frame, leftmost_frame + current_page_frames() );
802 Editor::update_fixed_rulers ()
804 nframes64_t rightmost_frame;
810 ruler_metrics[ruler_metric_timecode].units_per_pixel = frames_per_unit;
811 ruler_metrics[ruler_metric_frames].units_per_pixel = frames_per_unit;
812 ruler_metrics[ruler_metric_minsec].units_per_pixel = frames_per_unit;
814 rightmost_frame = leftmost_frame + current_page_frames();
816 /* these force a redraw, which in turn will force execution of the metric callbacks
817 to compute the relevant ticks to display.
820 if (ruler_timecode_action->get_active()) {
821 gtk_custom_ruler_set_range (GTK_CUSTOM_RULER(_timecode_ruler), leftmost_frame, rightmost_frame,
822 leftmost_frame, _session->current_end_frame());
825 if (ruler_samples_action->get_active()) {
826 gtk_custom_ruler_set_range (GTK_CUSTOM_RULER(_frames_ruler), leftmost_frame, rightmost_frame,
827 leftmost_frame, _session->current_end_frame());
830 if (ruler_minsec_action->get_active()) {
831 gtk_custom_ruler_set_range (GTK_CUSTOM_RULER(_minsec_ruler), leftmost_frame, rightmost_frame,
832 leftmost_frame, _session->current_end_frame());
837 Editor::update_tempo_based_rulers ()
843 ruler_metrics[ruler_metric_bbt].units_per_pixel = frames_per_unit;
845 if (ruler_bbt_action->get_active()) {
846 gtk_custom_ruler_set_range (GTK_CUSTOM_RULER(_bbt_ruler), leftmost_frame, leftmost_frame+current_page_frames(),
847 leftmost_frame, _session->current_end_frame());
851 /* Mark generation */
854 Editor::_metric_get_timecode (GtkCustomRulerMark **marks, gdouble lower, gdouble upper, gint maxchars)
856 return ruler_editor->metric_get_timecode (marks, lower, upper, maxchars);
860 Editor::_metric_get_bbt (GtkCustomRulerMark **marks, gdouble lower, gdouble upper, gint maxchars)
862 return ruler_editor->metric_get_bbt (marks, lower, upper, maxchars);
866 Editor::_metric_get_frames (GtkCustomRulerMark **marks, gdouble lower, gdouble upper, gint maxchars)
868 return ruler_editor->metric_get_frames (marks, lower, upper, maxchars);
872 Editor::_metric_get_minsec (GtkCustomRulerMark **marks, gdouble lower, gdouble upper, gint maxchars)
874 return ruler_editor->metric_get_minsec (marks, lower, upper, maxchars);
878 Editor::set_timecode_ruler_scale (gdouble lower, gdouble upper)
888 fr = _session->frame_rate();
890 if (lower > (spacer = (nframes64_t)(128 * Editor::get_current_zoom ()))) {
891 lower = lower - spacer;
895 upper = upper + spacer;
896 range = (nframes64_t) floor (upper - lower);
898 if (range < (2 * _session->frames_per_timecode_frame())) { /* 0 - 2 frames */
899 timecode_ruler_scale = timecode_show_bits;
900 timecode_mark_modulo = 20;
901 timecode_nmarks = 2 + (2 * _session->config.get_subframes_per_frame());
902 } else if (range <= (fr / 4)) { /* 2 frames - 0.250 second */
903 timecode_ruler_scale = timecode_show_frames;
904 timecode_mark_modulo = 1;
905 timecode_nmarks = 2 + (range / (nframes64_t)_session->frames_per_timecode_frame());
906 } else if (range <= (fr / 2)) { /* 0.25-0.5 second */
907 timecode_ruler_scale = timecode_show_frames;
908 timecode_mark_modulo = 2;
909 timecode_nmarks = 2 + (range / (nframes64_t)_session->frames_per_timecode_frame());
910 } else if (range <= fr) { /* 0.5-1 second */
911 timecode_ruler_scale = timecode_show_frames;
912 timecode_mark_modulo = 5;
913 timecode_nmarks = 2 + (range / (nframes64_t)_session->frames_per_timecode_frame());
914 } else if (range <= 2 * fr) { /* 1-2 seconds */
915 timecode_ruler_scale = timecode_show_frames;
916 timecode_mark_modulo = 10;
917 timecode_nmarks = 2 + (range / (nframes64_t)_session->frames_per_timecode_frame());
918 } else if (range <= 8 * fr) { /* 2-8 seconds */
919 timecode_ruler_scale = timecode_show_seconds;
920 timecode_mark_modulo = 1;
921 timecode_nmarks = 2 + (range / fr);
922 } else if (range <= 16 * fr) { /* 8-16 seconds */
923 timecode_ruler_scale = timecode_show_seconds;
924 timecode_mark_modulo = 2;
925 timecode_nmarks = 2 + (range / fr);
926 } else if (range <= 30 * fr) { /* 16-30 seconds */
927 timecode_ruler_scale = timecode_show_seconds;
928 timecode_mark_modulo = 5;
929 timecode_nmarks = 2 + (range / fr);
930 } else if (range <= 60 * fr) { /* 30-60 seconds */
931 timecode_ruler_scale = timecode_show_seconds;
932 timecode_mark_modulo = 5;
933 timecode_nmarks = 2 + (range / fr);
934 } else if (range <= 2 * 60 * fr) { /* 1-2 minutes */
935 timecode_ruler_scale = timecode_show_seconds;
936 timecode_mark_modulo = 15;
937 timecode_nmarks = 2 + (range / fr);
938 } else if (range <= 4 * 60 * fr) { /* 2-4 minutes */
939 timecode_ruler_scale = timecode_show_seconds;
940 timecode_mark_modulo = 30;
941 timecode_nmarks = 2 + (range / fr);
942 } else if (range <= 10 * 60 * fr) { /* 4-10 minutes */
943 timecode_ruler_scale = timecode_show_minutes;
944 timecode_mark_modulo = 2;
945 timecode_nmarks = 2 + 10;
946 } else if (range <= 30 * 60 * fr) { /* 10-30 minutes */
947 timecode_ruler_scale = timecode_show_minutes;
948 timecode_mark_modulo = 5;
949 timecode_nmarks = 2 + 30;
950 } else if (range <= 60 * 60 * fr) { /* 30 minutes - 1hr */
951 timecode_ruler_scale = timecode_show_minutes;
952 timecode_mark_modulo = 10;
953 timecode_nmarks = 2 + 60;
954 } else if (range <= 4 * 60 * 60 * fr) { /* 1 - 4 hrs*/
955 timecode_ruler_scale = timecode_show_minutes;
956 timecode_mark_modulo = 30;
957 timecode_nmarks = 2 + (60 * 4);
958 } else if (range <= 8 * 60 * 60 * fr) { /* 4 - 8 hrs*/
959 timecode_ruler_scale = timecode_show_hours;
960 timecode_mark_modulo = 1;
961 timecode_nmarks = 2 + 8;
962 } else if (range <= 16 * 60 * 60 * fr) { /* 16-24 hrs*/
963 timecode_ruler_scale = timecode_show_hours;
964 timecode_mark_modulo = 1;
965 timecode_nmarks = 2 + 24;
968 /* not possible if nframes64_t is a 32 bit quantity */
970 timecode_ruler_scale = timecode_show_hours;
971 timecode_mark_modulo = 4;
972 timecode_nmarks = 2 + 24;
978 Editor::metric_get_timecode (GtkCustomRulerMark **marks, gdouble lower, gdouble /*upper*/, gint /*maxchars*/)
982 Timecode::Time timecode;
990 if (lower > (spacer = (nframes64_t)(128 * Editor::get_current_zoom ()))) {
991 lower = lower - spacer;
996 pos = (nframes_t) floor (lower);
998 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * timecode_nmarks);
999 switch (timecode_ruler_scale) {
1000 case timecode_show_bits:
1002 // Find timecode time of this sample (pos) with subframe accuracy
1003 _session->sample_to_timecode(pos, timecode, true /* use_offset */, true /* use_subframes */ );
1005 for (n = 0; n < timecode_nmarks; n++) {
1006 _session->timecode_to_sample(timecode, pos, true /* use_offset */, true /* use_subframes */ );
1007 if ((timecode.subframes % timecode_mark_modulo) == 0) {
1008 if (timecode.subframes == 0) {
1009 (*marks)[n].style = GtkCustomRulerMarkMajor;
1010 snprintf (buf, sizeof(buf), "%s%02u:%02u:%02u:%02u", timecode.negative ? "-" : "", timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
1012 (*marks)[n].style = GtkCustomRulerMarkMinor;
1013 snprintf (buf, sizeof(buf), ".%02u", timecode.subframes);
1016 snprintf (buf, sizeof(buf)," ");
1017 (*marks)[n].style = GtkCustomRulerMarkMicro;
1020 (*marks)[n].label = g_strdup (buf);
1021 (*marks)[n].position = pos;
1023 // Increment subframes by one
1024 Timecode::increment_subframes( timecode, _session->config.get_subframes_per_frame() );
1027 case timecode_show_seconds:
1028 // Find timecode time of this sample (pos)
1029 _session->sample_to_timecode(pos, timecode, true /* use_offset */, false /* use_subframes */ );
1030 // Go to next whole second down
1031 Timecode::seconds_floor( timecode );
1033 for (n = 0; n < timecode_nmarks; n++) {
1034 _session->timecode_to_sample(timecode, pos, true /* use_offset */, false /* use_subframes */ );
1035 if ((timecode.seconds % timecode_mark_modulo) == 0) {
1036 if (timecode.seconds == 0) {
1037 (*marks)[n].style = GtkCustomRulerMarkMajor;
1038 (*marks)[n].position = pos;
1040 (*marks)[n].style = GtkCustomRulerMarkMinor;
1041 (*marks)[n].position = pos;
1043 snprintf (buf, sizeof(buf), "%s%02u:%02u:%02u:%02u", timecode.negative ? "-" : "", timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
1045 snprintf (buf, sizeof(buf)," ");
1046 (*marks)[n].style = GtkCustomRulerMarkMicro;
1047 (*marks)[n].position = pos;
1050 (*marks)[n].label = g_strdup (buf);
1051 Timecode::increment_seconds( timecode, _session->config.get_subframes_per_frame() );
1054 case timecode_show_minutes:
1055 // Find timecode time of this sample (pos)
1056 _session->sample_to_timecode(pos, timecode, true /* use_offset */, false /* use_subframes */ );
1057 // Go to next whole minute down
1058 Timecode::minutes_floor( timecode );
1060 for (n = 0; n < timecode_nmarks; n++) {
1061 _session->timecode_to_sample(timecode, pos, true /* use_offset */, false /* use_subframes */ );
1062 if ((timecode.minutes % timecode_mark_modulo) == 0) {
1063 if (timecode.minutes == 0) {
1064 (*marks)[n].style = GtkCustomRulerMarkMajor;
1066 (*marks)[n].style = GtkCustomRulerMarkMinor;
1068 snprintf (buf, sizeof(buf), "%s%02u:%02u:%02u:%02u", timecode.negative ? "-" : "", timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
1070 snprintf (buf, sizeof(buf)," ");
1071 (*marks)[n].style = GtkCustomRulerMarkMicro;
1074 (*marks)[n].label = g_strdup (buf);
1075 (*marks)[n].position = pos;
1076 Timecode::increment_minutes( timecode, _session->config.get_subframes_per_frame() );
1080 case timecode_show_hours:
1081 // Find timecode time of this sample (pos)
1082 _session->sample_to_timecode(pos, timecode, true /* use_offset */, false /* use_subframes */ );
1083 // Go to next whole hour down
1084 Timecode::hours_floor( timecode );
1086 for (n = 0; n < timecode_nmarks; n++) {
1087 _session->timecode_to_sample(timecode, pos, true /* use_offset */, false /* use_subframes */ );
1088 if ((timecode.hours % timecode_mark_modulo) == 0) {
1089 (*marks)[n].style = GtkCustomRulerMarkMajor;
1090 snprintf (buf, sizeof(buf), "%s%02u:%02u:%02u:%02u", timecode.negative ? "-" : "", timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
1092 snprintf (buf, sizeof(buf)," ");
1093 (*marks)[n].style = GtkCustomRulerMarkMicro;
1096 (*marks)[n].label = g_strdup (buf);
1097 (*marks)[n].position = pos;
1099 Timecode::increment_hours( timecode, _session->config.get_subframes_per_frame() );
1102 case timecode_show_frames:
1103 // Find timecode time of this sample (pos)
1104 _session->sample_to_timecode(pos, timecode, true /* use_offset */, false /* use_subframes */ );
1105 // Go to next whole frame down
1106 Timecode::frames_floor( timecode );
1108 for (n = 0; n < timecode_nmarks; n++) {
1109 _session->timecode_to_sample(timecode, pos, true /* use_offset */, false /* use_subframes */ );
1110 if ((timecode.frames % timecode_mark_modulo) == 0) {
1111 if (timecode.frames == 0) {
1112 (*marks)[n].style = GtkCustomRulerMarkMajor;
1114 (*marks)[n].style = GtkCustomRulerMarkMinor;
1116 (*marks)[n].position = pos;
1117 snprintf (buf, sizeof(buf), "%s%02u:%02u:%02u:%02u", timecode.negative ? "-" : "", timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
1119 snprintf (buf, sizeof(buf)," ");
1120 (*marks)[n].style = GtkCustomRulerMarkMicro;
1121 (*marks)[n].position = pos;
1124 (*marks)[n].label = g_strdup (buf);
1125 Timecode::increment( timecode, _session->config.get_subframes_per_frame() );
1131 return timecode_nmarks;
1136 Editor::compute_bbt_ruler_scale (nframes64_t lower, nframes64_t upper)
1138 if (_session == 0) {
1141 TempoMap::BBTPointList::iterator i;
1142 BBT_Time lower_beat, upper_beat; // the beats at each end of the ruler
1144 _session->bbt_time((jack_nframes_t) lower, lower_beat);
1145 _session->bbt_time((jack_nframes_t) upper, upper_beat);
1148 bbt_accent_modulo = 1;
1149 bbt_bar_helper_on = false;
1153 bbt_ruler_scale = bbt_over;
1155 switch (_snap_type) {
1156 case SnapToAThirdBeat:
1157 bbt_beat_subdivision = 3;
1159 case SnapToAQuarterBeat:
1160 bbt_beat_subdivision = 4;
1162 case SnapToAEighthBeat:
1163 bbt_beat_subdivision = 8;
1164 bbt_accent_modulo = 2;
1166 case SnapToASixteenthBeat:
1167 bbt_beat_subdivision = 16;
1168 bbt_accent_modulo = 4;
1170 case SnapToAThirtysecondBeat:
1171 bbt_beat_subdivision = 32;
1172 bbt_accent_modulo = 8;
1175 bbt_beat_subdivision = 4;
1179 if (current_bbt_points == 0 || current_bbt_points->empty()) {
1183 i = current_bbt_points->end();
1185 if ((*i).beat >= (*current_bbt_points->begin()).beat) {
1186 bbt_bars = (*i).bar - (*current_bbt_points->begin()).bar;
1188 bbt_bars = (*i).bar - (*current_bbt_points->begin()).bar - 1;
1190 beats = current_bbt_points->size() - bbt_bars;
1192 /*Only show the bar helper if there aren't many bars on the screen */
1193 if ((bbt_bars < 2) || (beats < 5)) {
1194 bbt_bar_helper_on = true;
1197 if (bbt_bars > 8192) {
1198 bbt_ruler_scale = bbt_over;
1199 } else if (bbt_bars > 1024) {
1200 bbt_ruler_scale = bbt_show_64;
1201 } else if (bbt_bars > 256) {
1202 bbt_ruler_scale = bbt_show_16;
1203 } else if (bbt_bars > 64) {
1204 bbt_ruler_scale = bbt_show_4;
1205 } else if (bbt_bars > 10) {
1206 bbt_ruler_scale = bbt_show_1;
1207 } else if (bbt_bars > 2) {
1208 bbt_ruler_scale = bbt_show_beats;
1209 } else if (bbt_bars > 0) {
1210 bbt_ruler_scale = bbt_show_ticks;
1212 bbt_ruler_scale = bbt_show_ticks_detail;
1215 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)) {
1216 bbt_ruler_scale = bbt_show_ticks_super_detail;
1221 Editor::metric_get_bbt (GtkCustomRulerMark **marks, gdouble lower, gdouble /*upper*/, gint /*maxchars*/)
1223 if (_session == 0) {
1227 TempoMap::BBTPointList::iterator i;
1233 nframes64_t next_beat_pos;
1239 nframes64_t frame_skip;
1240 double frame_skip_error;
1241 double bbt_position_of_helper;
1242 double accumulated_error;
1243 bool i_am_accented = false;
1244 bool helper_active = false;
1246 if (current_bbt_points == 0 || current_bbt_points->empty()) {
1250 switch (bbt_ruler_scale) {
1252 case bbt_show_beats:
1253 beats = current_bbt_points->size();
1254 bbt_nmarks = beats + 2;
1256 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1258 (*marks)[0].label = g_strdup(" ");
1259 (*marks)[0].position = lower;
1260 (*marks)[0].style = GtkCustomRulerMarkMicro;
1262 for (n = 1, i = current_bbt_points->begin(); n < bbt_nmarks && i != current_bbt_points->end(); ++i) {
1263 if ((*i).type != TempoMap::Beat) {
1266 if ((*i).frame < lower && (bbt_bar_helper_on)) {
1267 snprintf (buf, sizeof(buf), "<%" PRIu32 "|%" PRIu32, (*i).bar, (*i).beat);
1268 (*marks)[0].label = g_strdup (buf);
1269 helper_active = true;
1272 if ((*i).beat == 1) {
1273 (*marks)[n].style = GtkCustomRulerMarkMajor;
1274 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1275 } else if (((*i).beat % 2 == 1)) {
1276 (*marks)[n].style = GtkCustomRulerMarkMinor;
1277 snprintf (buf, sizeof(buf), " ");
1279 (*marks)[n].style = GtkCustomRulerMarkMicro;
1280 snprintf (buf, sizeof(buf), " ");
1282 (*marks)[n].label = g_strdup (buf);
1283 (*marks)[n].position = (*i).frame;
1289 case bbt_show_ticks:
1291 beats = current_bbt_points->size();
1292 bbt_nmarks = (beats + 2) * bbt_beat_subdivision;
1294 bbt_position_of_helper = lower + (30 * Editor::get_current_zoom ());
1295 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1297 (*marks)[0].label = g_strdup(" ");
1298 (*marks)[0].position = lower;
1299 (*marks)[0].style = GtkCustomRulerMarkMicro;
1301 for (n = 1, i = current_bbt_points->begin(); n < bbt_nmarks && i != current_bbt_points->end(); ++i) {
1302 if ((*i).type != TempoMap::Beat) {
1305 if ((*i).frame < lower && (bbt_bar_helper_on)) {
1306 snprintf (buf, sizeof(buf), "<%" PRIu32 "|%" PRIu32, (*i).bar, (*i).beat);
1307 (*marks)[0].label = g_strdup (buf);
1308 helper_active = true;
1311 if ((*i).beat == 1) {
1312 (*marks)[n].style = GtkCustomRulerMarkMajor;
1313 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1315 (*marks)[n].style = GtkCustomRulerMarkMinor;
1316 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).beat);
1318 if (((*i).frame < bbt_position_of_helper) && helper_active) {
1319 snprintf (buf, sizeof(buf), " ");
1321 (*marks)[n].label = g_strdup (buf);
1322 (*marks)[n].position = (*i).frame;
1326 /* Add the tick marks */
1328 /* Find the next beat */
1329 next_beat.beats = (*i).beat;
1330 next_beat.bars = (*i).bar;
1331 next_beat.ticks = 0;
1333 if ((*i).meter->beats_per_bar() > (next_beat.beats + 1)) {
1334 next_beat.beats += 1;
1336 next_beat.bars += 1;
1337 next_beat.beats = 1;
1340 next_beat_pos = _session->tempo_map().frame_time(next_beat);
1342 frame_skip = (nframes64_t) floor (frame_skip_error = (_session->frame_rate() * 60) / (bbt_beat_subdivision * (*i).tempo->beats_per_minute()));
1343 frame_skip_error -= frame_skip;
1344 skip = (uint32_t) (Meter::ticks_per_beat / bbt_beat_subdivision);
1346 pos = (*i).frame + frame_skip;
1347 accumulated_error = frame_skip_error;
1351 for (t = 0; (tick < Meter::ticks_per_beat) && (n < bbt_nmarks) && (pos < next_beat_pos) ; pos += frame_skip, tick += skip, ++t) {
1353 if (t % bbt_accent_modulo == (bbt_accent_modulo - 1)) {
1354 i_am_accented = true;
1357 snprintf (buf, sizeof(buf), " ");
1358 (*marks)[n].label = g_strdup (buf);
1360 /* Error compensation for float to nframes64_t*/
1361 accumulated_error += frame_skip_error;
1362 if (accumulated_error > 1) {
1364 accumulated_error -= 1.0f;
1367 (*marks)[n].position = pos;
1369 if ((bbt_beat_subdivision > 4) && i_am_accented) {
1370 (*marks)[n].style = GtkCustomRulerMarkMinor;
1372 (*marks)[n].style = GtkCustomRulerMarkMicro;
1374 i_am_accented = false;
1381 case bbt_show_ticks_detail:
1383 beats = current_bbt_points->size();
1384 bbt_nmarks = (beats + 2) * bbt_beat_subdivision;
1386 bbt_position_of_helper = lower + (30 * Editor::get_current_zoom ());
1387 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1389 (*marks)[0].label = g_strdup(" ");
1390 (*marks)[0].position = lower;
1391 (*marks)[0].style = GtkCustomRulerMarkMicro;
1393 for (n = 1, i = current_bbt_points->begin(); n < bbt_nmarks && i != current_bbt_points->end(); ++i) {
1394 if ((*i).type != TempoMap::Beat) {
1397 if ((*i).frame < lower && (bbt_bar_helper_on)) {
1398 snprintf (buf, sizeof(buf), "<%" PRIu32 "|%" PRIu32, (*i).bar, (*i).beat);
1399 (*marks)[0].label = g_strdup (buf);
1400 helper_active = true;
1403 if ((*i).beat == 1) {
1404 (*marks)[n].style = GtkCustomRulerMarkMajor;
1405 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1407 (*marks)[n].style = GtkCustomRulerMarkMinor;
1408 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).beat);
1410 if (((*i).frame < bbt_position_of_helper) && helper_active) {
1411 snprintf (buf, sizeof(buf), " ");
1413 (*marks)[n].label = g_strdup (buf);
1414 (*marks)[n].position = (*i).frame;
1418 /* Add the tick marks */
1420 /* Find the next beat */
1422 next_beat.beats = (*i).beat;
1423 next_beat.bars = (*i).bar;
1425 if ((*i).meter->beats_per_bar() > (next_beat.beats + 1)) {
1426 next_beat.beats += 1;
1428 next_beat.bars += 1;
1429 next_beat.beats = 1;
1432 next_beat_pos = _session->tempo_map().frame_time(next_beat);
1434 frame_skip = (nframes64_t) floor (frame_skip_error = (_session->frame_rate() * 60) / (bbt_beat_subdivision * (*i).tempo->beats_per_minute()));
1435 frame_skip_error -= frame_skip;
1436 skip = (uint32_t) (Meter::ticks_per_beat / bbt_beat_subdivision);
1438 pos = (*i).frame + frame_skip;
1439 accumulated_error = frame_skip_error;
1443 for (t = 0; (tick < Meter::ticks_per_beat) && (n < bbt_nmarks) && (pos < next_beat_pos) ; pos += frame_skip, tick += skip, ++t) {
1445 if (t % bbt_accent_modulo == (bbt_accent_modulo - 1)) {
1446 i_am_accented = true;
1449 if (i_am_accented && (pos > bbt_position_of_helper)){
1450 snprintf (buf, sizeof(buf), "%" PRIu32, tick);
1452 snprintf (buf, sizeof(buf), " ");
1455 (*marks)[n].label = g_strdup (buf);
1457 /* Error compensation for float to nframes64_t*/
1458 accumulated_error += frame_skip_error;
1459 if (accumulated_error > 1) {
1461 accumulated_error -= 1.0f;
1464 (*marks)[n].position = pos;
1466 if ((bbt_beat_subdivision > 4) && i_am_accented) {
1467 (*marks)[n].style = GtkCustomRulerMarkMinor;
1469 (*marks)[n].style = GtkCustomRulerMarkMicro;
1471 i_am_accented = false;
1478 case bbt_show_ticks_super_detail:
1480 beats = current_bbt_points->size();
1481 bbt_nmarks = (beats + 2) * bbt_beat_subdivision;
1483 bbt_position_of_helper = lower + (30 * Editor::get_current_zoom ());
1484 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1486 (*marks)[0].label = g_strdup(" ");
1487 (*marks)[0].position = lower;
1488 (*marks)[0].style = GtkCustomRulerMarkMicro;
1490 for (n = 1, i = current_bbt_points->begin(); n < bbt_nmarks && i != current_bbt_points->end(); ++i) {
1491 if ((*i).type != TempoMap::Beat) {
1494 if ((*i).frame < lower && (bbt_bar_helper_on)) {
1495 snprintf (buf, sizeof(buf), "<%" PRIu32 "|%" PRIu32, (*i).bar, (*i).beat);
1496 (*marks)[0].label = g_strdup (buf);
1497 helper_active = true;
1500 if ((*i).beat == 1) {
1501 (*marks)[n].style = GtkCustomRulerMarkMajor;
1502 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1504 (*marks)[n].style = GtkCustomRulerMarkMinor;
1505 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).beat);
1507 if (((*i).frame < bbt_position_of_helper) && helper_active) {
1508 snprintf (buf, sizeof(buf), " ");
1510 (*marks)[n].label = g_strdup (buf);
1511 (*marks)[n].position = (*i).frame;
1515 /* Add the tick marks */
1517 /* Find the next beat */
1519 next_beat.beats = (*i).beat;
1520 next_beat.bars = (*i).bar;
1522 if ((*i).meter->beats_per_bar() > (next_beat.beats + 1)) {
1523 next_beat.beats += 1;
1525 next_beat.bars += 1;
1526 next_beat.beats = 1;
1529 next_beat_pos = _session->tempo_map().frame_time(next_beat);
1531 frame_skip = (nframes64_t) floor (frame_skip_error = (_session->frame_rate() * 60) / (bbt_beat_subdivision * (*i).tempo->beats_per_minute()));
1532 frame_skip_error -= frame_skip;
1533 skip = (uint32_t) (Meter::ticks_per_beat / bbt_beat_subdivision);
1535 pos = (*i).frame + frame_skip;
1536 accumulated_error = frame_skip_error;
1540 for (t = 0; (tick < Meter::ticks_per_beat) && (n < bbt_nmarks) && (pos < next_beat_pos) ; pos += frame_skip, tick += skip, ++t) {
1542 if (t % bbt_accent_modulo == (bbt_accent_modulo - 1)) {
1543 i_am_accented = true;
1546 if (pos > bbt_position_of_helper) {
1547 snprintf (buf, sizeof(buf), "%" PRIu32, tick);
1549 snprintf (buf, sizeof(buf), " ");
1552 (*marks)[n].label = g_strdup (buf);
1554 /* Error compensation for float to nframes64_t*/
1555 accumulated_error += frame_skip_error;
1556 if (accumulated_error > 1) {
1558 accumulated_error -= 1.0f;
1561 (*marks)[n].position = pos;
1563 if ((bbt_beat_subdivision > 4) && i_am_accented) {
1564 (*marks)[n].style = GtkCustomRulerMarkMinor;
1566 (*marks)[n].style = GtkCustomRulerMarkMicro;
1568 i_am_accented = false;
1577 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1578 snprintf (buf, sizeof(buf), "cannot handle %" PRIu32 " bars", bbt_bars );
1579 (*marks)[0].style = GtkCustomRulerMarkMajor;
1580 (*marks)[0].label = g_strdup (buf);
1581 (*marks)[0].position = lower;
1587 bbt_nmarks = (gint) (bbt_bars / 64) + 1;
1588 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1589 for (n = 0, i = current_bbt_points->begin(); i != current_bbt_points->end() && n < bbt_nmarks; i++) {
1590 if ((*i).type == TempoMap::Bar) {
1591 if ((*i).bar % 64 == 1) {
1592 if ((*i).bar % 256 == 1) {
1593 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1594 (*marks)[n].style = GtkCustomRulerMarkMajor;
1596 snprintf (buf, sizeof(buf), " ");
1597 if ((*i).bar % 256 == 129) {
1598 (*marks)[n].style = GtkCustomRulerMarkMinor;
1600 (*marks)[n].style = GtkCustomRulerMarkMicro;
1603 (*marks)[n].label = g_strdup (buf);
1604 (*marks)[n].position = (*i).frame;
1612 bbt_nmarks = (bbt_bars / 16) + 1;
1613 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1614 for (n = 0, i = current_bbt_points->begin(); i != current_bbt_points->end() && n < bbt_nmarks; i++) {
1615 if ((*i).type == TempoMap::Bar) {
1616 if ((*i).bar % 16 == 1) {
1617 if ((*i).bar % 64 == 1) {
1618 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1619 (*marks)[n].style = GtkCustomRulerMarkMajor;
1621 snprintf (buf, sizeof(buf), " ");
1622 if ((*i).bar % 64 == 33) {
1623 (*marks)[n].style = GtkCustomRulerMarkMinor;
1625 (*marks)[n].style = GtkCustomRulerMarkMicro;
1628 (*marks)[n].label = g_strdup (buf);
1629 (*marks)[n].position = (*i).frame;
1637 bbt_nmarks = (bbt_bars / 4) + 1;
1638 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1639 for (n = 0, i = current_bbt_points->begin(); i != current_bbt_points->end() && n < bbt_nmarks; ++i) {
1640 if ((*i).type == TempoMap::Bar) {
1641 if ((*i).bar % 4 == 1) {
1642 if ((*i).bar % 16 == 1) {
1643 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1644 (*marks)[n].style = GtkCustomRulerMarkMajor;
1646 snprintf (buf, sizeof(buf), " ");
1647 if ((*i).bar % 16 == 9) {
1648 (*marks)[n].style = GtkCustomRulerMarkMinor;
1650 (*marks)[n].style = GtkCustomRulerMarkMicro;
1653 (*marks)[n].label = g_strdup (buf);
1654 (*marks)[n].position = (*i).frame;
1663 bbt_nmarks = bbt_bars + 2;
1664 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks );
1665 for (n = 0, i = current_bbt_points->begin(); i != current_bbt_points->end() && n < bbt_nmarks; i++) {
1666 if ((*i).type == TempoMap::Bar) {
1667 if ((*i).bar % 4 == 1) {
1668 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1669 (*marks)[n].style = GtkCustomRulerMarkMajor;
1671 snprintf (buf, sizeof(buf), " ");
1672 if ((*i).bar % 4 == 3) {
1673 (*marks)[n].style = GtkCustomRulerMarkMinor;
1675 (*marks)[n].style = GtkCustomRulerMarkMicro;
1678 (*marks)[n].label = g_strdup (buf);
1679 (*marks)[n].position = (*i).frame;
1688 return n; //return the actual number of marks made, since we might have skipped some from fractional time signatures
1693 Editor::metric_get_frames (GtkCustomRulerMark **marks, gdouble lower, gdouble upper, gint /*maxchars*/)
1695 nframes64_t mark_interval;
1697 nframes64_t ilower = (nframes64_t) floor (lower);
1698 nframes64_t iupper = (nframes64_t) floor (upper);
1703 if (_session == 0) {
1707 mark_interval = (iupper - ilower) / 5;
1708 if (mark_interval > _session->frame_rate()) {
1709 mark_interval -= mark_interval % _session->frame_rate();
1711 mark_interval = _session->frame_rate() / (_session->frame_rate() / mark_interval ) ;
1714 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * nmarks);
1715 for (n = 0, pos = ilower; n < nmarks; pos += mark_interval, ++n) {
1716 snprintf (buf, sizeof(buf), "%" PRIi64, pos);
1717 (*marks)[n].label = g_strdup (buf);
1718 (*marks)[n].position = pos;
1719 (*marks)[n].style = GtkCustomRulerMarkMajor;
1726 sample_to_clock_parts ( nframes64_t sample,
1727 nframes64_t sample_rate,
1741 hrs = left / (sample_rate * 60 * 60);
1742 left -= hrs * sample_rate * 60 * 60;
1743 mins = left / (sample_rate * 60);
1744 left -= mins * sample_rate * 60;
1745 secs = left / sample_rate;
1746 left -= secs * sample_rate;
1747 millisecs = left * 1000 / sample_rate;
1749 *millisecs_p = millisecs;
1758 Editor::set_minsec_ruler_scale (gdouble lower, gdouble upper)
1764 if (_session == 0) {
1768 fr = _session->frame_rate();
1770 /* to prevent 'flashing' */
1771 if (lower > (spacer = (nframes64_t)(128 * Editor::get_current_zoom ()))) {
1777 range = (nframes64_t) (upper - lower);
1779 if (range < (fr / 50)) {
1780 minsec_mark_interval = fr / 1000; /* show 1/1000 seconds */
1781 minsec_ruler_scale = minsec_show_frames;
1782 minsec_mark_modulo = 10;
1783 } else if (range <= (fr / 10)) { /* 0-0.1 second */
1784 minsec_mark_interval = fr / 1000; /* show 1/1000 seconds */
1785 minsec_ruler_scale = minsec_show_frames;
1786 minsec_mark_modulo = 10;
1787 } else if (range <= (fr / 2)) { /* 0-0.5 second */
1788 minsec_mark_interval = fr / 100; /* show 1/100 seconds */
1789 minsec_ruler_scale = minsec_show_frames;
1790 minsec_mark_modulo = 100;
1791 } else if (range <= fr) { /* 0-1 second */
1792 minsec_mark_interval = fr / 10; /* show 1/10 seconds */
1793 minsec_ruler_scale = minsec_show_frames;
1794 minsec_mark_modulo = 200;
1795 } else if (range <= 2 * fr) { /* 1-2 seconds */
1796 minsec_mark_interval = fr / 10; /* show 1/10 seconds */
1797 minsec_ruler_scale = minsec_show_frames;
1798 minsec_mark_modulo = 500;
1799 } else if (range <= 8 * fr) { /* 2-5 seconds */
1800 minsec_mark_interval = fr / 5; /* show 2 seconds */
1801 minsec_ruler_scale = minsec_show_frames;
1802 minsec_mark_modulo = 1000;
1803 } else if (range <= 16 * fr) { /* 8-16 seconds */
1804 minsec_mark_interval = fr; /* show 1 seconds */
1805 minsec_ruler_scale = minsec_show_seconds;
1806 minsec_mark_modulo = 2;
1807 } else if (range <= 30 * fr) { /* 10-30 seconds */
1808 minsec_mark_interval = fr; /* show 1 seconds */
1809 minsec_ruler_scale = minsec_show_seconds;
1810 minsec_mark_modulo = 5;
1811 } else if (range <= 60 * fr) { /* 30-60 seconds */
1812 minsec_mark_interval = fr; /* show 1 seconds */
1813 minsec_ruler_scale = minsec_show_seconds;
1814 minsec_mark_modulo = 5;
1815 } else if (range <= 2 * 60 * fr) { /* 1-2 minutes */
1816 minsec_mark_interval = 5 * fr; /* show 5 seconds */
1817 minsec_ruler_scale = minsec_show_seconds;
1818 minsec_mark_modulo = 3;
1819 } else if (range <= 4 * 60 * fr) { /* 4 minutes */
1820 minsec_mark_interval = 5 * fr; /* show 10 seconds */
1821 minsec_ruler_scale = minsec_show_seconds;
1822 minsec_mark_modulo = 30;
1823 } else if (range <= 10 * 60 * fr) { /* 10 minutes */
1824 minsec_mark_interval = 30 * fr; /* show 30 seconds */
1825 minsec_ruler_scale = minsec_show_seconds;
1826 minsec_mark_modulo = 120;
1827 } else if (range <= 30 * 60 * fr) { /* 10-30 minutes */
1828 minsec_mark_interval = 60 * fr; /* show 1 minute */
1829 minsec_ruler_scale = minsec_show_minutes;
1830 minsec_mark_modulo = 5;
1831 } else if (range <= 60 * 60 * fr) { /* 30 minutes - 1hr */
1832 minsec_mark_interval = 2 * 60 * fr; /* show 2 minutes */
1833 minsec_ruler_scale = minsec_show_minutes;
1834 minsec_mark_modulo = 10;
1835 } else if (range <= 4 * 60 * 60 * fr) { /* 1 - 4 hrs*/
1836 minsec_mark_interval = 5 * 60 * fr; /* show 10 minutes */
1837 minsec_ruler_scale = minsec_show_minutes;
1838 minsec_mark_modulo = 30;
1839 } else if (range <= 8 * 60 * 60 * fr) { /* 4 - 8 hrs*/
1840 minsec_mark_interval = 20 * 60 * fr; /* show 20 minutes */
1841 minsec_ruler_scale = minsec_show_minutes;
1842 minsec_mark_modulo = 60;
1843 } else if (range <= 16 * 60 * 60 * fr) { /* 16-24 hrs*/
1844 minsec_mark_interval = 60 * 60 * fr; /* show 60 minutes */
1845 minsec_ruler_scale = minsec_show_hours;
1846 minsec_mark_modulo = 2;
1849 /* not possible if nframes64_t is a 32 bit quantity */
1851 minsec_mark_interval = 4 * 60 * 60 * fr; /* show 4 hrs */
1853 minsec_nmarks = 2 + (range / minsec_mark_interval);
1857 Editor::metric_get_minsec (GtkCustomRulerMark **marks, gdouble lower, gdouble /*upper*/, gint /*maxchars*/)
1861 long hrs, mins, secs, millisecs;
1865 if (_session == 0) {
1869 /* to prevent 'flashing' */
1870 if (lower > (spacer = (nframes64_t)(128 * Editor::get_current_zoom ()))) {
1871 lower = lower - spacer;
1876 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * minsec_nmarks);
1877 pos = ((((nframes64_t) floor(lower)) + (minsec_mark_interval/2))/minsec_mark_interval) * minsec_mark_interval;
1878 switch (minsec_ruler_scale) {
1879 case minsec_show_seconds:
1880 for (n = 0; n < minsec_nmarks; pos += minsec_mark_interval, ++n) {
1881 sample_to_clock_parts (pos, _session->frame_rate(), &hrs, &mins, &secs, &millisecs);
1882 if (secs % minsec_mark_modulo == 0) {
1884 (*marks)[n].style = GtkCustomRulerMarkMajor;
1886 (*marks)[n].style = GtkCustomRulerMarkMinor;
1888 snprintf (buf, sizeof(buf), "%02ld:%02ld:%02ld.%03ld", hrs, mins, secs, millisecs);
1890 snprintf (buf, sizeof(buf), " ");
1891 (*marks)[n].style = GtkCustomRulerMarkMicro;
1893 (*marks)[n].label = g_strdup (buf);
1894 (*marks)[n].position = pos;
1897 case minsec_show_minutes:
1898 for (n = 0; n < minsec_nmarks; pos += minsec_mark_interval, ++n) {
1899 sample_to_clock_parts (pos, _session->frame_rate(), &hrs, &mins, &secs, &millisecs);
1900 if (mins % minsec_mark_modulo == 0) {
1902 (*marks)[n].style = GtkCustomRulerMarkMajor;
1904 (*marks)[n].style = GtkCustomRulerMarkMinor;
1906 snprintf (buf, sizeof(buf), "%02ld:%02ld:%02ld.%03ld", hrs, mins, secs, millisecs);
1908 snprintf (buf, sizeof(buf), " ");
1909 (*marks)[n].style = GtkCustomRulerMarkMicro;
1911 (*marks)[n].label = g_strdup (buf);
1912 (*marks)[n].position = pos;
1915 case minsec_show_hours:
1916 for (n = 0; n < minsec_nmarks; pos += minsec_mark_interval, ++n) {
1917 sample_to_clock_parts (pos, _session->frame_rate(), &hrs, &mins, &secs, &millisecs);
1918 if (hrs % minsec_mark_modulo == 0) {
1919 (*marks)[n].style = GtkCustomRulerMarkMajor;
1920 snprintf (buf, sizeof(buf), "%02ld:%02ld:%02ld.%03ld", hrs, mins, secs, millisecs);
1922 snprintf (buf, sizeof(buf), " ");
1923 (*marks)[n].style = GtkCustomRulerMarkMicro;
1925 (*marks)[n].label = g_strdup (buf);
1926 (*marks)[n].position = pos;
1929 case minsec_show_frames:
1930 for (n = 0; n < minsec_nmarks; pos += minsec_mark_interval, ++n) {
1931 sample_to_clock_parts (pos, _session->frame_rate(), &hrs, &mins, &secs, &millisecs);
1932 if (millisecs % minsec_mark_modulo == 0) {
1934 (*marks)[n].style = GtkCustomRulerMarkMajor;
1936 (*marks)[n].style = GtkCustomRulerMarkMinor;
1938 snprintf (buf, sizeof(buf), "%02ld:%02ld:%02ld.%03ld", hrs, mins, secs, millisecs);
1940 snprintf (buf, sizeof(buf), " ");
1941 (*marks)[n].style = GtkCustomRulerMarkMicro;
1943 (*marks)[n].label = g_strdup (buf);
1944 (*marks)[n].position = pos;
1949 return minsec_nmarks;