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 SnapToBeatDiv2:
1157 bbt_beat_subdivision = 2;
1159 case SnapToBeatDiv3:
1160 bbt_beat_subdivision = 3;
1162 case SnapToBeatDiv4:
1163 bbt_beat_subdivision = 4;
1165 case SnapToBeatDiv5:
1166 bbt_beat_subdivision = 5;
1167 bbt_accent_modulo = 2; // XXX YIKES
1169 case SnapToBeatDiv6:
1170 bbt_beat_subdivision = 6;
1171 bbt_accent_modulo = 2; // XXX YIKES
1173 case SnapToBeatDiv7:
1174 bbt_beat_subdivision = 7;
1175 bbt_accent_modulo = 2; // XXX YIKES
1177 case SnapToBeatDiv8:
1178 bbt_beat_subdivision = 8;
1179 bbt_accent_modulo = 2;
1181 case SnapToBeatDiv10:
1182 bbt_beat_subdivision = 10;
1183 bbt_accent_modulo = 2; // XXX YIKES
1185 case SnapToBeatDiv12:
1186 bbt_beat_subdivision = 12;
1187 bbt_accent_modulo = 3;
1189 case SnapToBeatDiv14:
1190 bbt_beat_subdivision = 14;
1191 bbt_accent_modulo = 3; // XXX YIKES!
1193 case SnapToBeatDiv16:
1194 bbt_beat_subdivision = 16;
1195 bbt_accent_modulo = 4;
1197 case SnapToBeatDiv20:
1198 bbt_beat_subdivision = 20;
1199 bbt_accent_modulo = 5;
1201 case SnapToBeatDiv24:
1202 bbt_beat_subdivision = 24;
1203 bbt_accent_modulo = 6;
1205 case SnapToBeatDiv28:
1206 bbt_beat_subdivision = 28;
1207 bbt_accent_modulo = 7;
1209 case SnapToBeatDiv32:
1210 bbt_beat_subdivision = 32;
1211 bbt_accent_modulo = 8;
1214 bbt_beat_subdivision = 4;
1218 if (current_bbt_points == 0 || current_bbt_points->empty()) {
1222 i = current_bbt_points->end();
1224 if ((*i).beat >= (*current_bbt_points->begin()).beat) {
1225 bbt_bars = (*i).bar - (*current_bbt_points->begin()).bar;
1227 bbt_bars = (*i).bar - (*current_bbt_points->begin()).bar - 1;
1229 beats = current_bbt_points->size() - bbt_bars;
1231 /*Only show the bar helper if there aren't many bars on the screen */
1232 if ((bbt_bars < 2) || (beats < 5)) {
1233 bbt_bar_helper_on = true;
1236 if (bbt_bars > 8192) {
1237 bbt_ruler_scale = bbt_over;
1238 } else if (bbt_bars > 1024) {
1239 bbt_ruler_scale = bbt_show_64;
1240 } else if (bbt_bars > 256) {
1241 bbt_ruler_scale = bbt_show_16;
1242 } else if (bbt_bars > 64) {
1243 bbt_ruler_scale = bbt_show_4;
1244 } else if (bbt_bars > 10) {
1245 bbt_ruler_scale = bbt_show_1;
1246 } else if (bbt_bars > 2) {
1247 bbt_ruler_scale = bbt_show_beats;
1248 } else if (bbt_bars > 0) {
1249 bbt_ruler_scale = bbt_show_ticks;
1251 bbt_ruler_scale = bbt_show_ticks_detail;
1254 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)) {
1255 bbt_ruler_scale = bbt_show_ticks_super_detail;
1260 Editor::metric_get_bbt (GtkCustomRulerMark **marks, gdouble lower, gdouble /*upper*/, gint /*maxchars*/)
1262 if (_session == 0) {
1266 TempoMap::BBTPointList::iterator i;
1272 nframes64_t next_beat_pos;
1278 nframes64_t frame_skip;
1279 double frame_skip_error;
1280 double bbt_position_of_helper;
1281 double accumulated_error;
1282 bool i_am_accented = false;
1283 bool helper_active = false;
1285 if (current_bbt_points == 0 || current_bbt_points->empty()) {
1289 switch (bbt_ruler_scale) {
1291 case bbt_show_beats:
1292 beats = current_bbt_points->size();
1293 bbt_nmarks = beats + 2;
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);
1314 } else if (((*i).beat % 2 == 1)) {
1315 (*marks)[n].style = GtkCustomRulerMarkMinor;
1316 snprintf (buf, sizeof(buf), " ");
1318 (*marks)[n].style = GtkCustomRulerMarkMicro;
1319 snprintf (buf, sizeof(buf), " ");
1321 (*marks)[n].label = g_strdup (buf);
1322 (*marks)[n].position = (*i).frame;
1328 case bbt_show_ticks:
1330 beats = current_bbt_points->size();
1331 bbt_nmarks = (beats + 2) * bbt_beat_subdivision;
1333 bbt_position_of_helper = lower + (30 * Editor::get_current_zoom ());
1334 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1336 (*marks)[0].label = g_strdup(" ");
1337 (*marks)[0].position = lower;
1338 (*marks)[0].style = GtkCustomRulerMarkMicro;
1340 for (n = 1, i = current_bbt_points->begin(); n < bbt_nmarks && i != current_bbt_points->end(); ++i) {
1341 if ((*i).type != TempoMap::Beat) {
1344 if ((*i).frame < lower && (bbt_bar_helper_on)) {
1345 snprintf (buf, sizeof(buf), "<%" PRIu32 "|%" PRIu32, (*i).bar, (*i).beat);
1346 (*marks)[0].label = g_strdup (buf);
1347 helper_active = true;
1350 if ((*i).beat == 1) {
1351 (*marks)[n].style = GtkCustomRulerMarkMajor;
1352 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1354 (*marks)[n].style = GtkCustomRulerMarkMinor;
1355 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).beat);
1357 if (((*i).frame < bbt_position_of_helper) && helper_active) {
1358 snprintf (buf, sizeof(buf), " ");
1360 (*marks)[n].label = g_strdup (buf);
1361 (*marks)[n].position = (*i).frame;
1365 /* Add the tick marks */
1367 /* Find the next beat */
1368 next_beat.beats = (*i).beat;
1369 next_beat.bars = (*i).bar;
1370 next_beat.ticks = 0;
1372 if ((*i).meter->beats_per_bar() > (next_beat.beats + 1)) {
1373 next_beat.beats += 1;
1375 next_beat.bars += 1;
1376 next_beat.beats = 1;
1379 next_beat_pos = _session->tempo_map().frame_time(next_beat);
1381 frame_skip = (nframes64_t) floor (frame_skip_error = (_session->frame_rate() * 60) / (bbt_beat_subdivision * (*i).tempo->beats_per_minute()));
1382 frame_skip_error -= frame_skip;
1383 skip = (uint32_t) (Meter::ticks_per_beat / bbt_beat_subdivision);
1385 pos = (*i).frame + frame_skip;
1386 accumulated_error = frame_skip_error;
1390 for (t = 0; (tick < Meter::ticks_per_beat) && (n < bbt_nmarks) && (pos < next_beat_pos) ; pos += frame_skip, tick += skip, ++t) {
1392 if (t % bbt_accent_modulo == (bbt_accent_modulo - 1)) {
1393 i_am_accented = true;
1396 snprintf (buf, sizeof(buf), " ");
1397 (*marks)[n].label = g_strdup (buf);
1399 /* Error compensation for float to nframes64_t*/
1400 accumulated_error += frame_skip_error;
1401 if (accumulated_error > 1) {
1403 accumulated_error -= 1.0f;
1406 (*marks)[n].position = pos;
1408 if ((bbt_beat_subdivision > 4) && i_am_accented) {
1409 (*marks)[n].style = GtkCustomRulerMarkMinor;
1411 (*marks)[n].style = GtkCustomRulerMarkMicro;
1413 i_am_accented = false;
1420 case bbt_show_ticks_detail:
1422 beats = current_bbt_points->size();
1423 bbt_nmarks = (beats + 2) * bbt_beat_subdivision;
1425 bbt_position_of_helper = lower + (30 * Editor::get_current_zoom ());
1426 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1428 (*marks)[0].label = g_strdup(" ");
1429 (*marks)[0].position = lower;
1430 (*marks)[0].style = GtkCustomRulerMarkMicro;
1432 for (n = 1, i = current_bbt_points->begin(); n < bbt_nmarks && i != current_bbt_points->end(); ++i) {
1433 if ((*i).type != TempoMap::Beat) {
1436 if ((*i).frame < lower && (bbt_bar_helper_on)) {
1437 snprintf (buf, sizeof(buf), "<%" PRIu32 "|%" PRIu32, (*i).bar, (*i).beat);
1438 (*marks)[0].label = g_strdup (buf);
1439 helper_active = true;
1442 if ((*i).beat == 1) {
1443 (*marks)[n].style = GtkCustomRulerMarkMajor;
1444 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1446 (*marks)[n].style = GtkCustomRulerMarkMinor;
1447 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).beat);
1449 if (((*i).frame < bbt_position_of_helper) && helper_active) {
1450 snprintf (buf, sizeof(buf), " ");
1452 (*marks)[n].label = g_strdup (buf);
1453 (*marks)[n].position = (*i).frame;
1457 /* Add the tick marks */
1459 /* Find the next beat */
1461 next_beat.beats = (*i).beat;
1462 next_beat.bars = (*i).bar;
1464 if ((*i).meter->beats_per_bar() > (next_beat.beats + 1)) {
1465 next_beat.beats += 1;
1467 next_beat.bars += 1;
1468 next_beat.beats = 1;
1471 next_beat_pos = _session->tempo_map().frame_time(next_beat);
1473 frame_skip = (nframes64_t) floor (frame_skip_error = (_session->frame_rate() * 60) / (bbt_beat_subdivision * (*i).tempo->beats_per_minute()));
1474 frame_skip_error -= frame_skip;
1475 skip = (uint32_t) (Meter::ticks_per_beat / bbt_beat_subdivision);
1477 pos = (*i).frame + frame_skip;
1478 accumulated_error = frame_skip_error;
1482 for (t = 0; (tick < Meter::ticks_per_beat) && (n < bbt_nmarks) && (pos < next_beat_pos) ; pos += frame_skip, tick += skip, ++t) {
1484 if (t % bbt_accent_modulo == (bbt_accent_modulo - 1)) {
1485 i_am_accented = true;
1488 if (i_am_accented && (pos > bbt_position_of_helper)){
1489 snprintf (buf, sizeof(buf), "%" PRIu32, tick);
1491 snprintf (buf, sizeof(buf), " ");
1494 (*marks)[n].label = g_strdup (buf);
1496 /* Error compensation for float to nframes64_t*/
1497 accumulated_error += frame_skip_error;
1498 if (accumulated_error > 1) {
1500 accumulated_error -= 1.0f;
1503 (*marks)[n].position = pos;
1505 if ((bbt_beat_subdivision > 4) && i_am_accented) {
1506 (*marks)[n].style = GtkCustomRulerMarkMinor;
1508 (*marks)[n].style = GtkCustomRulerMarkMicro;
1510 i_am_accented = false;
1517 case bbt_show_ticks_super_detail:
1519 beats = current_bbt_points->size();
1520 bbt_nmarks = (beats + 2) * bbt_beat_subdivision;
1522 bbt_position_of_helper = lower + (30 * Editor::get_current_zoom ());
1523 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1525 (*marks)[0].label = g_strdup(" ");
1526 (*marks)[0].position = lower;
1527 (*marks)[0].style = GtkCustomRulerMarkMicro;
1529 for (n = 1, i = current_bbt_points->begin(); n < bbt_nmarks && i != current_bbt_points->end(); ++i) {
1530 if ((*i).type != TempoMap::Beat) {
1533 if ((*i).frame < lower && (bbt_bar_helper_on)) {
1534 snprintf (buf, sizeof(buf), "<%" PRIu32 "|%" PRIu32, (*i).bar, (*i).beat);
1535 (*marks)[0].label = g_strdup (buf);
1536 helper_active = true;
1539 if ((*i).beat == 1) {
1540 (*marks)[n].style = GtkCustomRulerMarkMajor;
1541 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1543 (*marks)[n].style = GtkCustomRulerMarkMinor;
1544 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).beat);
1546 if (((*i).frame < bbt_position_of_helper) && helper_active) {
1547 snprintf (buf, sizeof(buf), " ");
1549 (*marks)[n].label = g_strdup (buf);
1550 (*marks)[n].position = (*i).frame;
1554 /* Add the tick marks */
1556 /* Find the next beat */
1558 next_beat.beats = (*i).beat;
1559 next_beat.bars = (*i).bar;
1561 if ((*i).meter->beats_per_bar() > (next_beat.beats + 1)) {
1562 next_beat.beats += 1;
1564 next_beat.bars += 1;
1565 next_beat.beats = 1;
1568 next_beat_pos = _session->tempo_map().frame_time(next_beat);
1570 frame_skip = (nframes64_t) floor (frame_skip_error = (_session->frame_rate() * 60) / (bbt_beat_subdivision * (*i).tempo->beats_per_minute()));
1571 frame_skip_error -= frame_skip;
1572 skip = (uint32_t) (Meter::ticks_per_beat / bbt_beat_subdivision);
1574 pos = (*i).frame + frame_skip;
1575 accumulated_error = frame_skip_error;
1579 for (t = 0; (tick < Meter::ticks_per_beat) && (n < bbt_nmarks) && (pos < next_beat_pos) ; pos += frame_skip, tick += skip, ++t) {
1581 if (t % bbt_accent_modulo == (bbt_accent_modulo - 1)) {
1582 i_am_accented = true;
1585 if (pos > bbt_position_of_helper) {
1586 snprintf (buf, sizeof(buf), "%" PRIu32, tick);
1588 snprintf (buf, sizeof(buf), " ");
1591 (*marks)[n].label = g_strdup (buf);
1593 /* Error compensation for float to nframes64_t*/
1594 accumulated_error += frame_skip_error;
1595 if (accumulated_error > 1) {
1597 accumulated_error -= 1.0f;
1600 (*marks)[n].position = pos;
1602 if ((bbt_beat_subdivision > 4) && i_am_accented) {
1603 (*marks)[n].style = GtkCustomRulerMarkMinor;
1605 (*marks)[n].style = GtkCustomRulerMarkMicro;
1607 i_am_accented = false;
1616 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1617 snprintf (buf, sizeof(buf), "cannot handle %" PRIu32 " bars", bbt_bars );
1618 (*marks)[0].style = GtkCustomRulerMarkMajor;
1619 (*marks)[0].label = g_strdup (buf);
1620 (*marks)[0].position = lower;
1626 bbt_nmarks = (gint) (bbt_bars / 64) + 1;
1627 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1628 for (n = 0, i = current_bbt_points->begin(); i != current_bbt_points->end() && n < bbt_nmarks; i++) {
1629 if ((*i).type == TempoMap::Bar) {
1630 if ((*i).bar % 64 == 1) {
1631 if ((*i).bar % 256 == 1) {
1632 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1633 (*marks)[n].style = GtkCustomRulerMarkMajor;
1635 snprintf (buf, sizeof(buf), " ");
1636 if ((*i).bar % 256 == 129) {
1637 (*marks)[n].style = GtkCustomRulerMarkMinor;
1639 (*marks)[n].style = GtkCustomRulerMarkMicro;
1642 (*marks)[n].label = g_strdup (buf);
1643 (*marks)[n].position = (*i).frame;
1651 bbt_nmarks = (bbt_bars / 16) + 1;
1652 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1653 for (n = 0, i = current_bbt_points->begin(); i != current_bbt_points->end() && n < bbt_nmarks; i++) {
1654 if ((*i).type == TempoMap::Bar) {
1655 if ((*i).bar % 16 == 1) {
1656 if ((*i).bar % 64 == 1) {
1657 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1658 (*marks)[n].style = GtkCustomRulerMarkMajor;
1660 snprintf (buf, sizeof(buf), " ");
1661 if ((*i).bar % 64 == 33) {
1662 (*marks)[n].style = GtkCustomRulerMarkMinor;
1664 (*marks)[n].style = GtkCustomRulerMarkMicro;
1667 (*marks)[n].label = g_strdup (buf);
1668 (*marks)[n].position = (*i).frame;
1676 bbt_nmarks = (bbt_bars / 4) + 1;
1677 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1678 for (n = 0, i = current_bbt_points->begin(); i != current_bbt_points->end() && n < bbt_nmarks; ++i) {
1679 if ((*i).type == TempoMap::Bar) {
1680 if ((*i).bar % 4 == 1) {
1681 if ((*i).bar % 16 == 1) {
1682 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1683 (*marks)[n].style = GtkCustomRulerMarkMajor;
1685 snprintf (buf, sizeof(buf), " ");
1686 if ((*i).bar % 16 == 9) {
1687 (*marks)[n].style = GtkCustomRulerMarkMinor;
1689 (*marks)[n].style = GtkCustomRulerMarkMicro;
1692 (*marks)[n].label = g_strdup (buf);
1693 (*marks)[n].position = (*i).frame;
1702 bbt_nmarks = bbt_bars + 2;
1703 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks );
1704 for (n = 0, i = current_bbt_points->begin(); i != current_bbt_points->end() && n < bbt_nmarks; i++) {
1705 if ((*i).type == TempoMap::Bar) {
1706 if ((*i).bar % 4 == 1) {
1707 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1708 (*marks)[n].style = GtkCustomRulerMarkMajor;
1710 snprintf (buf, sizeof(buf), " ");
1711 if ((*i).bar % 4 == 3) {
1712 (*marks)[n].style = GtkCustomRulerMarkMinor;
1714 (*marks)[n].style = GtkCustomRulerMarkMicro;
1717 (*marks)[n].label = g_strdup (buf);
1718 (*marks)[n].position = (*i).frame;
1727 return n; //return the actual number of marks made, since we might have skipped some from fractional time signatures
1732 Editor::metric_get_frames (GtkCustomRulerMark **marks, gdouble lower, gdouble upper, gint /*maxchars*/)
1734 nframes64_t mark_interval;
1736 nframes64_t ilower = (nframes64_t) floor (lower);
1737 nframes64_t iupper = (nframes64_t) floor (upper);
1742 if (_session == 0) {
1746 mark_interval = (iupper - ilower) / 5;
1747 if (mark_interval > _session->frame_rate()) {
1748 mark_interval -= mark_interval % _session->frame_rate();
1750 mark_interval = _session->frame_rate() / (_session->frame_rate() / mark_interval ) ;
1753 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * nmarks);
1754 for (n = 0, pos = ilower; n < nmarks; pos += mark_interval, ++n) {
1755 snprintf (buf, sizeof(buf), "%" PRIi64, pos);
1756 (*marks)[n].label = g_strdup (buf);
1757 (*marks)[n].position = pos;
1758 (*marks)[n].style = GtkCustomRulerMarkMajor;
1765 sample_to_clock_parts ( nframes64_t sample,
1766 nframes64_t sample_rate,
1780 hrs = left / (sample_rate * 60 * 60);
1781 left -= hrs * sample_rate * 60 * 60;
1782 mins = left / (sample_rate * 60);
1783 left -= mins * sample_rate * 60;
1784 secs = left / sample_rate;
1785 left -= secs * sample_rate;
1786 millisecs = left * 1000 / sample_rate;
1788 *millisecs_p = millisecs;
1797 Editor::set_minsec_ruler_scale (gdouble lower, gdouble upper)
1803 if (_session == 0) {
1807 fr = _session->frame_rate();
1809 /* to prevent 'flashing' */
1810 if (lower > (spacer = (nframes64_t)(128 * Editor::get_current_zoom ()))) {
1816 range = (nframes64_t) (upper - lower);
1818 if (range < (fr / 50)) {
1819 minsec_mark_interval = fr / 1000; /* show 1/1000 seconds */
1820 minsec_ruler_scale = minsec_show_frames;
1821 minsec_mark_modulo = 10;
1822 } else if (range <= (fr / 10)) { /* 0-0.1 second */
1823 minsec_mark_interval = fr / 1000; /* show 1/1000 seconds */
1824 minsec_ruler_scale = minsec_show_frames;
1825 minsec_mark_modulo = 10;
1826 } else if (range <= (fr / 2)) { /* 0-0.5 second */
1827 minsec_mark_interval = fr / 100; /* show 1/100 seconds */
1828 minsec_ruler_scale = minsec_show_frames;
1829 minsec_mark_modulo = 100;
1830 } else if (range <= fr) { /* 0-1 second */
1831 minsec_mark_interval = fr / 10; /* show 1/10 seconds */
1832 minsec_ruler_scale = minsec_show_frames;
1833 minsec_mark_modulo = 200;
1834 } else if (range <= 2 * fr) { /* 1-2 seconds */
1835 minsec_mark_interval = fr / 10; /* show 1/10 seconds */
1836 minsec_ruler_scale = minsec_show_frames;
1837 minsec_mark_modulo = 500;
1838 } else if (range <= 8 * fr) { /* 2-5 seconds */
1839 minsec_mark_interval = fr / 5; /* show 2 seconds */
1840 minsec_ruler_scale = minsec_show_frames;
1841 minsec_mark_modulo = 1000;
1842 } else if (range <= 16 * fr) { /* 8-16 seconds */
1843 minsec_mark_interval = fr; /* show 1 seconds */
1844 minsec_ruler_scale = minsec_show_seconds;
1845 minsec_mark_modulo = 2;
1846 } else if (range <= 30 * fr) { /* 10-30 seconds */
1847 minsec_mark_interval = fr; /* show 1 seconds */
1848 minsec_ruler_scale = minsec_show_seconds;
1849 minsec_mark_modulo = 5;
1850 } else if (range <= 60 * fr) { /* 30-60 seconds */
1851 minsec_mark_interval = fr; /* show 1 seconds */
1852 minsec_ruler_scale = minsec_show_seconds;
1853 minsec_mark_modulo = 5;
1854 } else if (range <= 2 * 60 * fr) { /* 1-2 minutes */
1855 minsec_mark_interval = 5 * fr; /* show 5 seconds */
1856 minsec_ruler_scale = minsec_show_seconds;
1857 minsec_mark_modulo = 3;
1858 } else if (range <= 4 * 60 * fr) { /* 4 minutes */
1859 minsec_mark_interval = 5 * fr; /* show 10 seconds */
1860 minsec_ruler_scale = minsec_show_seconds;
1861 minsec_mark_modulo = 30;
1862 } else if (range <= 10 * 60 * fr) { /* 10 minutes */
1863 minsec_mark_interval = 30 * fr; /* show 30 seconds */
1864 minsec_ruler_scale = minsec_show_seconds;
1865 minsec_mark_modulo = 120;
1866 } else if (range <= 30 * 60 * fr) { /* 10-30 minutes */
1867 minsec_mark_interval = 60 * fr; /* show 1 minute */
1868 minsec_ruler_scale = minsec_show_minutes;
1869 minsec_mark_modulo = 5;
1870 } else if (range <= 60 * 60 * fr) { /* 30 minutes - 1hr */
1871 minsec_mark_interval = 2 * 60 * fr; /* show 2 minutes */
1872 minsec_ruler_scale = minsec_show_minutes;
1873 minsec_mark_modulo = 10;
1874 } else if (range <= 4 * 60 * 60 * fr) { /* 1 - 4 hrs*/
1875 minsec_mark_interval = 5 * 60 * fr; /* show 10 minutes */
1876 minsec_ruler_scale = minsec_show_minutes;
1877 minsec_mark_modulo = 30;
1878 } else if (range <= 8 * 60 * 60 * fr) { /* 4 - 8 hrs*/
1879 minsec_mark_interval = 20 * 60 * fr; /* show 20 minutes */
1880 minsec_ruler_scale = minsec_show_minutes;
1881 minsec_mark_modulo = 60;
1882 } else if (range <= 16 * 60 * 60 * fr) { /* 16-24 hrs*/
1883 minsec_mark_interval = 60 * 60 * fr; /* show 60 minutes */
1884 minsec_ruler_scale = minsec_show_hours;
1885 minsec_mark_modulo = 2;
1888 /* not possible if nframes64_t is a 32 bit quantity */
1890 minsec_mark_interval = 4 * 60 * 60 * fr; /* show 4 hrs */
1892 minsec_nmarks = 2 + (range / minsec_mark_interval);
1896 Editor::metric_get_minsec (GtkCustomRulerMark **marks, gdouble lower, gdouble /*upper*/, gint /*maxchars*/)
1900 long hrs, mins, secs, millisecs;
1904 if (_session == 0) {
1908 /* to prevent 'flashing' */
1909 if (lower > (spacer = (nframes64_t)(128 * Editor::get_current_zoom ()))) {
1910 lower = lower - spacer;
1915 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * minsec_nmarks);
1916 pos = ((((nframes64_t) floor(lower)) + (minsec_mark_interval/2))/minsec_mark_interval) * minsec_mark_interval;
1917 switch (minsec_ruler_scale) {
1918 case minsec_show_seconds:
1919 for (n = 0; n < minsec_nmarks; pos += minsec_mark_interval, ++n) {
1920 sample_to_clock_parts (pos, _session->frame_rate(), &hrs, &mins, &secs, &millisecs);
1921 if (secs % minsec_mark_modulo == 0) {
1923 (*marks)[n].style = GtkCustomRulerMarkMajor;
1925 (*marks)[n].style = GtkCustomRulerMarkMinor;
1927 snprintf (buf, sizeof(buf), "%02ld:%02ld:%02ld.%03ld", hrs, mins, secs, millisecs);
1929 snprintf (buf, sizeof(buf), " ");
1930 (*marks)[n].style = GtkCustomRulerMarkMicro;
1932 (*marks)[n].label = g_strdup (buf);
1933 (*marks)[n].position = pos;
1936 case minsec_show_minutes:
1937 for (n = 0; n < minsec_nmarks; pos += minsec_mark_interval, ++n) {
1938 sample_to_clock_parts (pos, _session->frame_rate(), &hrs, &mins, &secs, &millisecs);
1939 if (mins % minsec_mark_modulo == 0) {
1941 (*marks)[n].style = GtkCustomRulerMarkMajor;
1943 (*marks)[n].style = GtkCustomRulerMarkMinor;
1945 snprintf (buf, sizeof(buf), "%02ld:%02ld:%02ld.%03ld", hrs, mins, secs, millisecs);
1947 snprintf (buf, sizeof(buf), " ");
1948 (*marks)[n].style = GtkCustomRulerMarkMicro;
1950 (*marks)[n].label = g_strdup (buf);
1951 (*marks)[n].position = pos;
1954 case minsec_show_hours:
1955 for (n = 0; n < minsec_nmarks; pos += minsec_mark_interval, ++n) {
1956 sample_to_clock_parts (pos, _session->frame_rate(), &hrs, &mins, &secs, &millisecs);
1957 if (hrs % minsec_mark_modulo == 0) {
1958 (*marks)[n].style = GtkCustomRulerMarkMajor;
1959 snprintf (buf, sizeof(buf), "%02ld:%02ld:%02ld.%03ld", hrs, mins, secs, millisecs);
1961 snprintf (buf, sizeof(buf), " ");
1962 (*marks)[n].style = GtkCustomRulerMarkMicro;
1964 (*marks)[n].label = g_strdup (buf);
1965 (*marks)[n].position = pos;
1968 case minsec_show_frames:
1969 for (n = 0; n < minsec_nmarks; pos += minsec_mark_interval, ++n) {
1970 sample_to_clock_parts (pos, _session->frame_rate(), &hrs, &mins, &secs, &millisecs);
1971 if (millisecs % minsec_mark_modulo == 0) {
1973 (*marks)[n].style = GtkCustomRulerMarkMajor;
1975 (*marks)[n].style = GtkCustomRulerMarkMinor;
1977 snprintf (buf, sizeof(buf), "%02ld:%02ld:%02ld.%03ld", hrs, mins, secs, millisecs);
1979 snprintf (buf, sizeof(buf), " ");
1980 (*marks)[n].style = GtkCustomRulerMarkMicro;
1982 (*marks)[n].label = g_strdup (buf);
1983 (*marks)[n].position = pos;
1988 return minsec_nmarks;