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 */
250 _drag = new CursorDrag (this, &playhead_cursor->canvas_item, false);
251 _drag->start_grab (reinterpret_cast<GdkEvent *> (ev));
252 _dragging_playhead = true;
259 Editor::ruler_button_release (GdkEventButton* ev)
266 Gdk::ModifierType state;
269 _drag->end_grab (reinterpret_cast<GdkEvent*> (ev));
272 _dragging_playhead = false;
275 if (ev->button == 3) {
276 /* need to use the correct x,y, the event lies */
277 time_canvas_event_box.get_window()->get_pointer (x, y, state);
279 stop_canvas_autoscroll();
281 nframes64_t where = leftmost_frame + pixel_to_frame (x);
283 popup_ruler_menu (where);
286 if (ruler_grabbed_widget) {
287 ruler_grabbed_widget->remove_modal_grab();
288 ruler_grabbed_widget = 0;
295 Editor::ruler_label_button_release (GdkEventButton* ev)
297 if (ev->button == 3) {
298 Gtk::Menu* m= dynamic_cast<Gtk::Menu*> (ActionManager::get_widget (X_("/RulerMenuPopup")));
300 m->popup (1, ev->time);
309 Editor::ruler_mouse_motion (GdkEventMotion* ev)
316 _drag->motion_handler (reinterpret_cast<GdkEvent*> (ev), false);
324 Editor::popup_ruler_menu (nframes64_t where, ItemType t)
326 using namespace Menu_Helpers;
328 if (editor_ruler_menu == 0) {
329 editor_ruler_menu = new Menu;
330 editor_ruler_menu->set_name ("ArdourContextMenu");
333 // always build from scratch
334 MenuList& ruler_items = editor_ruler_menu->items();
335 editor_ruler_menu->set_name ("ArdourContextMenu");
340 ruler_items.push_back (MenuElem (_("New location marker"), sigc::bind ( sigc::mem_fun(*this, &Editor::mouse_add_new_marker), where, false, false)));
341 ruler_items.push_back (MenuElem (_("Clear all locations"), sigc::mem_fun(*this, &Editor::clear_markers)));
342 ruler_items.push_back (MenuElem (_("Unhide locations"), sigc::mem_fun(*this, &Editor::unhide_markers)));
343 ruler_items.push_back (SeparatorElem ());
345 case RangeMarkerBarItem:
346 //ruler_items.push_back (MenuElem (_("New Range")));
347 ruler_items.push_back (MenuElem (_("Clear all ranges"), sigc::mem_fun(*this, &Editor::clear_ranges)));
348 ruler_items.push_back (MenuElem (_("Unhide ranges"), sigc::mem_fun(*this, &Editor::unhide_ranges)));
349 ruler_items.push_back (SeparatorElem ());
352 case TransportMarkerBarItem:
356 case CdMarkerBarItem:
358 ruler_items.push_back (MenuElem (_("New CD track marker"), sigc::bind ( sigc::mem_fun(*this, &Editor::mouse_add_new_marker), where, true, false)));
363 ruler_items.push_back (MenuElem (_("New Tempo"), sigc::bind ( sigc::mem_fun(*this, &Editor::mouse_add_new_tempo_event), where)));
364 ruler_items.push_back (MenuElem (_("Clear tempo")));
365 ruler_items.push_back (SeparatorElem ());
369 ruler_items.push_back (MenuElem (_("New Meter"), sigc::bind ( sigc::mem_fun(*this, &Editor::mouse_add_new_meter_event), where)));
370 ruler_items.push_back (MenuElem (_("Clear meter")));
371 ruler_items.push_back (SeparatorElem ());
378 Glib::RefPtr<Action> action;
380 action = ActionManager::get_action ("Rulers", "toggle-minsec-ruler");
382 ruler_items.push_back (MenuElem (*action->create_menu_item()));
384 if (!Profile->get_sae()) {
385 action = ActionManager::get_action ("Rulers", "toggle-timecode-ruler");
387 ruler_items.push_back (MenuElem (*action->create_menu_item()));
390 action = ActionManager::get_action ("Rulers", "toggle-samples-ruler");
392 ruler_items.push_back (MenuElem (*action->create_menu_item()));
394 action = ActionManager::get_action ("Rulers", "toggle-bbt-ruler");
396 ruler_items.push_back (MenuElem (*action->create_menu_item()));
398 action = ActionManager::get_action ("Rulers", "toggle-meter-ruler");
400 ruler_items.push_back (MenuElem (*action->create_menu_item()));
402 action = ActionManager::get_action ("Rulers", "toggle-tempo-ruler");
404 ruler_items.push_back (MenuElem (*action->create_menu_item()));
406 if (!Profile->get_sae()) {
407 action = ActionManager::get_action ("Rulers", "toggle-range-ruler");
409 ruler_items.push_back (MenuElem (*action->create_menu_item()));
412 action = ActionManager::get_action ("Rulers", "toggle-loop-punch-ruler");
414 ruler_items.push_back (MenuElem (*action->create_menu_item()));
416 action = ActionManager::get_action ("Rulers", "toggle-cd-marker-ruler");
418 ruler_items.push_back (MenuElem (*action->create_menu_item()));
420 action = ActionManager::get_action ("Rulers", "toggle-marker-ruler");
422 ruler_items.push_back (MenuElem (*action->create_menu_item()));
425 editor_ruler_menu->popup (1, gtk_get_current_event_time());
427 no_ruler_shown_update = false;
431 Editor::store_ruler_visibility ()
433 XMLNode* node = new XMLNode(X_("RulerVisibility"));
435 node->add_property (X_("timecode"), ruler_timecode_action->get_active() ? "yes": "no");
436 node->add_property (X_("bbt"), ruler_bbt_action->get_active() ? "yes": "no");
437 node->add_property (X_("frames"), ruler_samples_action->get_active() ? "yes": "no");
438 node->add_property (X_("minsec"), ruler_minsec_action->get_active() ? "yes": "no");
439 node->add_property (X_("tempo"), ruler_tempo_action->get_active() ? "yes": "no");
440 node->add_property (X_("meter"), ruler_meter_action->get_active() ? "yes": "no");
441 node->add_property (X_("marker"), ruler_marker_action->get_active() ? "yes": "no");
442 node->add_property (X_("rangemarker"), ruler_range_action->get_active() ? "yes": "no");
443 node->add_property (X_("transportmarker"), ruler_loop_punch_action->get_active() ? "yes": "no");
444 node->add_property (X_("cdmarker"), ruler_cd_marker_action->get_active() ? "yes": "no");
446 session->add_extra_xml (*node);
447 session->set_dirty ();
451 Editor::restore_ruler_visibility ()
454 XMLNode * node = session->extra_xml (X_("RulerVisibility"));
456 no_ruler_shown_update = true;
459 if ((prop = node->property ("timecode")) != 0) {
460 if (string_is_affirmative (prop->value())) {
461 ruler_timecode_action->set_active (true);
463 ruler_timecode_action->set_active (false);
466 if ((prop = node->property ("bbt")) != 0) {
467 if (string_is_affirmative (prop->value())) {
468 ruler_bbt_action->set_active (true);
470 ruler_bbt_action->set_active (false);
473 if ((prop = node->property ("frames")) != 0) {
474 if (string_is_affirmative (prop->value())) {
475 ruler_samples_action->set_active (true);
477 ruler_samples_action->set_active (false);
480 if ((prop = node->property ("minsec")) != 0) {
481 if (string_is_affirmative (prop->value())) {
482 ruler_minsec_action->set_active (true);
484 ruler_minsec_action->set_active (false);
487 if ((prop = node->property ("tempo")) != 0) {
488 if (string_is_affirmative (prop->value())) {
489 ruler_tempo_action->set_active (true);
491 ruler_tempo_action->set_active (false);
494 if ((prop = node->property ("meter")) != 0) {
495 if (string_is_affirmative (prop->value())) {
496 ruler_meter_action->set_active (true);
498 ruler_meter_action->set_active (false);
501 if ((prop = node->property ("marker")) != 0) {
502 if (string_is_affirmative (prop->value())) {
503 ruler_marker_action->set_active (true);
505 ruler_marker_action->set_active (false);
508 if ((prop = node->property ("rangemarker")) != 0) {
509 if (string_is_affirmative (prop->value())) {
510 ruler_range_action->set_active (true);
512 ruler_range_action->set_active (false);
516 if ((prop = node->property ("transportmarker")) != 0) {
517 if (string_is_affirmative (prop->value())) {
518 ruler_loop_punch_action->set_active (true);
520 ruler_loop_punch_action->set_active (false);
524 if ((prop = node->property ("cdmarker")) != 0) {
525 if (string_is_affirmative (prop->value())) {
526 ruler_cd_marker_action->set_active (true);
528 ruler_cd_marker_action->set_active (false);
532 // this session doesn't yet know about the cdmarker ruler
533 // as a benefit to the user who doesn't know the feature exists, show the ruler if
534 // any cd marks exist
535 ruler_cd_marker_action->set_active (false);
536 const Locations::LocationList & locs = session->locations()->list();
537 for (Locations::LocationList::const_iterator i = locs.begin(); i != locs.end(); ++i) {
538 if ((*i)->is_cd_marker()) {
539 ruler_cd_marker_action->set_active (true);
547 no_ruler_shown_update = false;
548 update_ruler_visibility ();
552 Editor::update_ruler_visibility ()
554 int visible_rulers = 0;
556 if (no_ruler_shown_update) {
560 visible_timebars = 0;
562 if (ruler_minsec_action->get_active()) {
564 minsec_label.show ();
565 minsec_ruler->show ();
567 minsec_label.hide ();
568 minsec_ruler->hide ();
571 if (ruler_timecode_action->get_active()) {
573 timecode_label.show ();
574 timecode_ruler->show ();
576 timecode_label.hide ();
577 timecode_ruler->hide ();
580 if (ruler_samples_action->get_active()) {
583 frames_ruler->show ();
586 frames_ruler->hide ();
589 if (ruler_bbt_action->get_active()) {
603 /* gtk update probs require this (damn) */
606 range_mark_label.hide();
607 transport_mark_label.hide();
608 cd_mark_label.hide();
611 if (ruler_meter_action->get_active()) {
612 old_unit_pos = meter_group->property_y();
613 if (tbpos != old_unit_pos) {
614 meter_group->move ( 0.0, tbpos - old_unit_pos);
616 old_unit_pos = meter_bar_group->property_y();
617 if (tbgpos != old_unit_pos) {
618 meter_bar_group->move ( 0.0, tbgpos - old_unit_pos);
620 meter_bar_group->show();
623 tbpos += timebar_height;
624 tbgpos += timebar_height;
627 meter_bar_group->hide();
632 if (ruler_tempo_action->get_active()) {
633 old_unit_pos = tempo_group->property_y();
634 if (tbpos != old_unit_pos) {
635 tempo_group->move(0.0, tbpos - old_unit_pos);
637 old_unit_pos = tempo_bar_group->property_y();
638 if (tbgpos != old_unit_pos) {
639 tempo_bar_group->move ( 0.0, tbgpos - old_unit_pos);
641 tempo_bar_group->show();
644 tbpos += timebar_height;
645 tbgpos += timebar_height;
648 tempo_bar_group->hide();
653 if (!Profile->get_sae() && ruler_range_action->get_active()) {
654 old_unit_pos = range_marker_group->property_y();
655 if (tbpos != old_unit_pos) {
656 range_marker_group->move (0.0, tbpos - old_unit_pos);
658 old_unit_pos = range_marker_bar_group->property_y();
659 if (tbgpos != old_unit_pos) {
660 range_marker_bar_group->move (0.0, tbgpos - old_unit_pos);
662 range_marker_bar_group->show();
663 range_marker_group->show();
664 range_mark_label.show();
666 tbpos += timebar_height;
667 tbgpos += timebar_height;
670 range_marker_bar_group->hide();
671 range_marker_group->hide();
672 range_mark_label.hide();
675 if (ruler_loop_punch_action->get_active()) {
676 old_unit_pos = transport_marker_group->property_y();
677 if (tbpos != old_unit_pos) {
678 transport_marker_group->move ( 0.0, tbpos - old_unit_pos);
680 old_unit_pos = transport_marker_bar_group->property_y();
681 if (tbgpos != old_unit_pos) {
682 transport_marker_bar_group->move ( 0.0, tbgpos - old_unit_pos);
684 transport_marker_bar_group->show();
685 transport_marker_group->show();
686 transport_mark_label.show();
687 tbpos += timebar_height;
688 tbgpos += timebar_height;
691 transport_marker_bar_group->hide();
692 transport_marker_group->hide();
693 transport_mark_label.hide();
696 if (ruler_cd_marker_action->get_active()) {
697 old_unit_pos = cd_marker_group->property_y();
698 if (tbpos != old_unit_pos) {
699 cd_marker_group->move (0.0, tbpos - old_unit_pos);
701 old_unit_pos = cd_marker_bar_group->property_y();
702 if (tbgpos != old_unit_pos) {
703 cd_marker_bar_group->move (0.0, tbgpos - old_unit_pos);
705 cd_marker_bar_group->show();
706 cd_marker_group->show();
707 cd_mark_label.show();
708 tbpos += timebar_height;
709 tbgpos += timebar_height;
711 // make sure all cd markers show up in their respective places
712 update_cd_marker_display();
714 cd_marker_bar_group->hide();
715 cd_marker_group->hide();
716 cd_mark_label.hide();
717 // make sure all cd markers show up in their respective places
718 update_cd_marker_display();
721 if (ruler_marker_action->get_active()) {
722 old_unit_pos = marker_group->property_y();
723 if (tbpos != old_unit_pos) {
724 marker_group->move ( 0.0, tbpos - old_unit_pos);
726 old_unit_pos = marker_bar_group->property_y();
727 if (tbgpos != old_unit_pos) {
728 marker_bar_group->move ( 0.0, tbgpos - old_unit_pos);
730 marker_bar_group->show();
731 marker_group->show();
733 tbpos += timebar_height;
734 tbgpos += timebar_height;
737 marker_bar_group->hide();
738 marker_group->hide();
742 gdouble old_canvas_timebars_vsize = canvas_timebars_vsize;
743 canvas_timebars_vsize = (timebar_height * visible_timebars) - 1;
744 gdouble vertical_pos_delta = canvas_timebars_vsize - old_canvas_timebars_vsize;
745 vertical_adjustment.set_upper(vertical_adjustment.get_upper() + vertical_pos_delta);
746 full_canvas_height += vertical_pos_delta;
748 if (vertical_adjustment.get_value() != 0 && (vertical_adjustment.get_value() + _canvas_height >= full_canvas_height)) {
749 /*if we're at the bottom of the canvas, don't move the _trackview_group*/
750 vertical_adjustment.set_value (full_canvas_height - _canvas_height + 1);
752 _trackview_group->property_y () = - get_trackview_group_vertical_offset ();
753 _background_group->property_y () = - get_trackview_group_vertical_offset ();
754 _trackview_group->move (0, 0);
755 _background_group->move (0, 0);
756 last_trackview_group_vertical_offset = get_trackview_group_vertical_offset ();
759 gdouble bottom_track_pos = vertical_adjustment.get_value() + _canvas_height - canvas_timebars_vsize;
760 std::pair<TimeAxisView*, int> const p = trackview_by_y_position (bottom_track_pos);
762 p.first->clip_to_viewport ();
765 ruler_label_vbox.set_size_request (-1, (int)(timebar_height * visible_rulers));
766 time_canvas_vbox.set_size_request (-1,-1);
768 update_fixed_rulers();
769 redisplay_tempo (false);
773 Editor::update_just_timecode ()
775 ENSURE_GUI_THREAD (*this, &Editor::update_just_timecode)
781 nframes64_t rightmost_frame = leftmost_frame + current_page_frames();
783 if (ruler_timecode_action->get_active()) {
784 gtk_custom_ruler_set_range (GTK_CUSTOM_RULER(_timecode_ruler), leftmost_frame, rightmost_frame,
785 leftmost_frame, session->current_end_frame());
790 Editor::compute_fixed_ruler_scale ()
796 if (ruler_timecode_action->get_active()) {
797 set_timecode_ruler_scale (leftmost_frame, leftmost_frame + current_page_frames() );
800 if (ruler_minsec_action->get_active()) {
801 set_minsec_ruler_scale (leftmost_frame, leftmost_frame + current_page_frames() );
806 Editor::update_fixed_rulers ()
808 nframes64_t rightmost_frame;
814 ruler_metrics[ruler_metric_timecode].units_per_pixel = frames_per_unit;
815 ruler_metrics[ruler_metric_frames].units_per_pixel = frames_per_unit;
816 ruler_metrics[ruler_metric_minsec].units_per_pixel = frames_per_unit;
818 rightmost_frame = leftmost_frame + current_page_frames();
820 /* these force a redraw, which in turn will force execution of the metric callbacks
821 to compute the relevant ticks to display.
824 if (ruler_timecode_action->get_active()) {
825 gtk_custom_ruler_set_range (GTK_CUSTOM_RULER(_timecode_ruler), leftmost_frame, rightmost_frame,
826 leftmost_frame, session->current_end_frame());
829 if (ruler_samples_action->get_active()) {
830 gtk_custom_ruler_set_range (GTK_CUSTOM_RULER(_frames_ruler), leftmost_frame, rightmost_frame,
831 leftmost_frame, session->current_end_frame());
834 if (ruler_minsec_action->get_active()) {
835 gtk_custom_ruler_set_range (GTK_CUSTOM_RULER(_minsec_ruler), leftmost_frame, rightmost_frame,
836 leftmost_frame, session->current_end_frame());
841 Editor::update_tempo_based_rulers ()
847 ruler_metrics[ruler_metric_bbt].units_per_pixel = frames_per_unit;
849 if (ruler_bbt_action->get_active()) {
850 gtk_custom_ruler_set_range (GTK_CUSTOM_RULER(_bbt_ruler), leftmost_frame, leftmost_frame+current_page_frames(),
851 leftmost_frame, session->current_end_frame());
855 /* Mark generation */
858 Editor::_metric_get_timecode (GtkCustomRulerMark **marks, gdouble lower, gdouble upper, gint maxchars)
860 return ruler_editor->metric_get_timecode (marks, lower, upper, maxchars);
864 Editor::_metric_get_bbt (GtkCustomRulerMark **marks, gdouble lower, gdouble upper, gint maxchars)
866 return ruler_editor->metric_get_bbt (marks, lower, upper, maxchars);
870 Editor::_metric_get_frames (GtkCustomRulerMark **marks, gdouble lower, gdouble upper, gint maxchars)
872 return ruler_editor->metric_get_frames (marks, lower, upper, maxchars);
876 Editor::_metric_get_minsec (GtkCustomRulerMark **marks, gdouble lower, gdouble upper, gint maxchars)
878 return ruler_editor->metric_get_minsec (marks, lower, upper, maxchars);
882 Editor::set_timecode_ruler_scale (gdouble lower, gdouble upper)
892 fr = session->frame_rate();
894 if (lower > (spacer = (nframes64_t)(128 * Editor::get_current_zoom ()))) {
895 lower = lower - spacer;
899 upper = upper + spacer;
900 range = (nframes64_t) floor (upper - lower);
902 if (range < (2 * session->frames_per_timecode_frame())) { /* 0 - 2 frames */
903 timecode_ruler_scale = timecode_show_bits;
904 timecode_mark_modulo = 20;
905 timecode_nmarks = 2 + (2 * session->config.get_subframes_per_frame());
906 } else if (range <= (fr / 4)) { /* 2 frames - 0.250 second */
907 timecode_ruler_scale = timecode_show_frames;
908 timecode_mark_modulo = 1;
909 timecode_nmarks = 2 + (range / (nframes64_t)session->frames_per_timecode_frame());
910 } else if (range <= (fr / 2)) { /* 0.25-0.5 second */
911 timecode_ruler_scale = timecode_show_frames;
912 timecode_mark_modulo = 2;
913 timecode_nmarks = 2 + (range / (nframes64_t)session->frames_per_timecode_frame());
914 } else if (range <= fr) { /* 0.5-1 second */
915 timecode_ruler_scale = timecode_show_frames;
916 timecode_mark_modulo = 5;
917 timecode_nmarks = 2 + (range / (nframes64_t)session->frames_per_timecode_frame());
918 } else if (range <= 2 * fr) { /* 1-2 seconds */
919 timecode_ruler_scale = timecode_show_frames;
920 timecode_mark_modulo = 10;
921 timecode_nmarks = 2 + (range / (nframes64_t)session->frames_per_timecode_frame());
922 } else if (range <= 8 * fr) { /* 2-8 seconds */
923 timecode_ruler_scale = timecode_show_seconds;
924 timecode_mark_modulo = 1;
925 timecode_nmarks = 2 + (range / fr);
926 } else if (range <= 16 * fr) { /* 8-16 seconds */
927 timecode_ruler_scale = timecode_show_seconds;
928 timecode_mark_modulo = 2;
929 timecode_nmarks = 2 + (range / fr);
930 } else if (range <= 30 * fr) { /* 16-30 seconds */
931 timecode_ruler_scale = timecode_show_seconds;
932 timecode_mark_modulo = 5;
933 timecode_nmarks = 2 + (range / fr);
934 } else if (range <= 60 * fr) { /* 30-60 seconds */
935 timecode_ruler_scale = timecode_show_seconds;
936 timecode_mark_modulo = 5;
937 timecode_nmarks = 2 + (range / fr);
938 } else if (range <= 2 * 60 * fr) { /* 1-2 minutes */
939 timecode_ruler_scale = timecode_show_seconds;
940 timecode_mark_modulo = 15;
941 timecode_nmarks = 2 + (range / fr);
942 } else if (range <= 4 * 60 * fr) { /* 2-4 minutes */
943 timecode_ruler_scale = timecode_show_seconds;
944 timecode_mark_modulo = 30;
945 timecode_nmarks = 2 + (range / fr);
946 } else if (range <= 10 * 60 * fr) { /* 4-10 minutes */
947 timecode_ruler_scale = timecode_show_minutes;
948 timecode_mark_modulo = 2;
949 timecode_nmarks = 2 + 10;
950 } else if (range <= 30 * 60 * fr) { /* 10-30 minutes */
951 timecode_ruler_scale = timecode_show_minutes;
952 timecode_mark_modulo = 5;
953 timecode_nmarks = 2 + 30;
954 } else if (range <= 60 * 60 * fr) { /* 30 minutes - 1hr */
955 timecode_ruler_scale = timecode_show_minutes;
956 timecode_mark_modulo = 10;
957 timecode_nmarks = 2 + 60;
958 } else if (range <= 4 * 60 * 60 * fr) { /* 1 - 4 hrs*/
959 timecode_ruler_scale = timecode_show_minutes;
960 timecode_mark_modulo = 30;
961 timecode_nmarks = 2 + (60 * 4);
962 } else if (range <= 8 * 60 * 60 * fr) { /* 4 - 8 hrs*/
963 timecode_ruler_scale = timecode_show_hours;
964 timecode_mark_modulo = 1;
965 timecode_nmarks = 2 + 8;
966 } else if (range <= 16 * 60 * 60 * fr) { /* 16-24 hrs*/
967 timecode_ruler_scale = timecode_show_hours;
968 timecode_mark_modulo = 1;
969 timecode_nmarks = 2 + 24;
972 /* not possible if nframes64_t is a 32 bit quantity */
974 timecode_ruler_scale = timecode_show_hours;
975 timecode_mark_modulo = 4;
976 timecode_nmarks = 2 + 24;
982 Editor::metric_get_timecode (GtkCustomRulerMark **marks, gdouble lower, gdouble /*upper*/, gint /*maxchars*/)
986 Timecode::Time timecode;
994 if (lower > (spacer = (nframes64_t)(128 * Editor::get_current_zoom ()))) {
995 lower = lower - spacer;
1000 pos = (nframes_t) floor (lower);
1002 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * timecode_nmarks);
1003 switch (timecode_ruler_scale) {
1004 case timecode_show_bits:
1006 // Find timecode time of this sample (pos) with subframe accuracy
1007 session->sample_to_timecode(pos, timecode, true /* use_offset */, true /* use_subframes */ );
1009 for (n = 0; n < timecode_nmarks; n++) {
1010 session->timecode_to_sample(timecode, pos, true /* use_offset */, true /* use_subframes */ );
1011 if ((timecode.subframes % timecode_mark_modulo) == 0) {
1012 if (timecode.subframes == 0) {
1013 (*marks)[n].style = GtkCustomRulerMarkMajor;
1014 snprintf (buf, sizeof(buf), "%s%02u:%02u:%02u:%02u", timecode.negative ? "-" : "", timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
1016 (*marks)[n].style = GtkCustomRulerMarkMinor;
1017 snprintf (buf, sizeof(buf), ".%02u", timecode.subframes);
1020 snprintf (buf, sizeof(buf)," ");
1021 (*marks)[n].style = GtkCustomRulerMarkMicro;
1024 (*marks)[n].label = g_strdup (buf);
1025 (*marks)[n].position = pos;
1027 // Increment subframes by one
1028 Timecode::increment_subframes( timecode, session->config.get_subframes_per_frame() );
1031 case timecode_show_seconds:
1032 // Find timecode time of this sample (pos)
1033 session->sample_to_timecode(pos, timecode, true /* use_offset */, false /* use_subframes */ );
1034 // Go to next whole second down
1035 Timecode::seconds_floor( timecode );
1037 for (n = 0; n < timecode_nmarks; n++) {
1038 session->timecode_to_sample(timecode, pos, true /* use_offset */, false /* use_subframes */ );
1039 if ((timecode.seconds % timecode_mark_modulo) == 0) {
1040 if (timecode.seconds == 0) {
1041 (*marks)[n].style = GtkCustomRulerMarkMajor;
1042 (*marks)[n].position = pos;
1044 (*marks)[n].style = GtkCustomRulerMarkMinor;
1045 (*marks)[n].position = pos;
1047 snprintf (buf, sizeof(buf), "%s%02u:%02u:%02u:%02u", timecode.negative ? "-" : "", timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
1049 snprintf (buf, sizeof(buf)," ");
1050 (*marks)[n].style = GtkCustomRulerMarkMicro;
1051 (*marks)[n].position = pos;
1054 (*marks)[n].label = g_strdup (buf);
1055 Timecode::increment_seconds( timecode, session->config.get_subframes_per_frame() );
1058 case timecode_show_minutes:
1059 // Find timecode time of this sample (pos)
1060 session->sample_to_timecode(pos, timecode, true /* use_offset */, false /* use_subframes */ );
1061 // Go to next whole minute down
1062 Timecode::minutes_floor( timecode );
1064 for (n = 0; n < timecode_nmarks; n++) {
1065 session->timecode_to_sample(timecode, pos, true /* use_offset */, false /* use_subframes */ );
1066 if ((timecode.minutes % timecode_mark_modulo) == 0) {
1067 if (timecode.minutes == 0) {
1068 (*marks)[n].style = GtkCustomRulerMarkMajor;
1070 (*marks)[n].style = GtkCustomRulerMarkMinor;
1072 snprintf (buf, sizeof(buf), "%s%02u:%02u:%02u:%02u", timecode.negative ? "-" : "", timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
1074 snprintf (buf, sizeof(buf)," ");
1075 (*marks)[n].style = GtkCustomRulerMarkMicro;
1078 (*marks)[n].label = g_strdup (buf);
1079 (*marks)[n].position = pos;
1080 Timecode::increment_minutes( timecode, session->config.get_subframes_per_frame() );
1084 case timecode_show_hours:
1085 // Find timecode time of this sample (pos)
1086 session->sample_to_timecode(pos, timecode, true /* use_offset */, false /* use_subframes */ );
1087 // Go to next whole hour down
1088 Timecode::hours_floor( timecode );
1090 for (n = 0; n < timecode_nmarks; n++) {
1091 session->timecode_to_sample(timecode, pos, true /* use_offset */, false /* use_subframes */ );
1092 if ((timecode.hours % timecode_mark_modulo) == 0) {
1093 (*marks)[n].style = GtkCustomRulerMarkMajor;
1094 snprintf (buf, sizeof(buf), "%s%02u:%02u:%02u:%02u", timecode.negative ? "-" : "", timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
1096 snprintf (buf, sizeof(buf)," ");
1097 (*marks)[n].style = GtkCustomRulerMarkMicro;
1100 (*marks)[n].label = g_strdup (buf);
1101 (*marks)[n].position = pos;
1103 Timecode::increment_hours( timecode, session->config.get_subframes_per_frame() );
1106 case timecode_show_frames:
1107 // Find timecode time of this sample (pos)
1108 session->sample_to_timecode(pos, timecode, true /* use_offset */, false /* use_subframes */ );
1109 // Go to next whole frame down
1110 Timecode::frames_floor( timecode );
1112 for (n = 0; n < timecode_nmarks; n++) {
1113 session->timecode_to_sample(timecode, pos, true /* use_offset */, false /* use_subframes */ );
1114 if ((timecode.frames % timecode_mark_modulo) == 0) {
1115 if (timecode.frames == 0) {
1116 (*marks)[n].style = GtkCustomRulerMarkMajor;
1118 (*marks)[n].style = GtkCustomRulerMarkMinor;
1120 (*marks)[n].position = pos;
1121 snprintf (buf, sizeof(buf), "%s%02u:%02u:%02u:%02u", timecode.negative ? "-" : "", timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
1123 snprintf (buf, sizeof(buf)," ");
1124 (*marks)[n].style = GtkCustomRulerMarkMicro;
1125 (*marks)[n].position = pos;
1128 (*marks)[n].label = g_strdup (buf);
1129 Timecode::increment( timecode, session->config.get_subframes_per_frame() );
1135 return timecode_nmarks;
1140 Editor::compute_bbt_ruler_scale (nframes64_t lower, nframes64_t upper)
1145 TempoMap::BBTPointList::iterator i;
1146 BBT_Time lower_beat, upper_beat; // the beats at each end of the ruler
1148 session->bbt_time((jack_nframes_t) lower, lower_beat);
1149 session->bbt_time((jack_nframes_t) upper, upper_beat);
1152 bbt_accent_modulo = 1;
1153 bbt_bar_helper_on = false;
1157 bbt_ruler_scale = bbt_over;
1159 switch (_snap_type) {
1160 case SnapToAThirdBeat:
1161 bbt_beat_subdivision = 3;
1163 case SnapToAQuarterBeat:
1164 bbt_beat_subdivision = 4;
1166 case SnapToAEighthBeat:
1167 bbt_beat_subdivision = 8;
1168 bbt_accent_modulo = 2;
1170 case SnapToASixteenthBeat:
1171 bbt_beat_subdivision = 16;
1172 bbt_accent_modulo = 4;
1174 case SnapToAThirtysecondBeat:
1175 bbt_beat_subdivision = 32;
1176 bbt_accent_modulo = 8;
1179 bbt_beat_subdivision = 4;
1183 if (current_bbt_points == 0 || current_bbt_points->empty()) {
1187 i = current_bbt_points->end();
1189 if ((*i).beat >= (*current_bbt_points->begin()).beat) {
1190 bbt_bars = (*i).bar - (*current_bbt_points->begin()).bar;
1192 bbt_bars = (*i).bar - (*current_bbt_points->begin()).bar - 1;
1194 beats = current_bbt_points->size() - bbt_bars;
1196 /*Only show the bar helper if there aren't many bars on the screen */
1197 if ((bbt_bars < 2) || (beats < 5)) {
1198 bbt_bar_helper_on = true;
1201 if (bbt_bars > 8192) {
1202 bbt_ruler_scale = bbt_over;
1203 } else if (bbt_bars > 1024) {
1204 bbt_ruler_scale = bbt_show_64;
1205 } else if (bbt_bars > 256) {
1206 bbt_ruler_scale = bbt_show_16;
1207 } else if (bbt_bars > 64) {
1208 bbt_ruler_scale = bbt_show_4;
1209 } else if (bbt_bars > 10) {
1210 bbt_ruler_scale = bbt_show_1;
1211 } else if (bbt_bars > 2) {
1212 bbt_ruler_scale = bbt_show_beats;
1213 } else if (bbt_bars > 0) {
1214 bbt_ruler_scale = bbt_show_ticks;
1216 bbt_ruler_scale = bbt_show_ticks_detail;
1219 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)) {
1220 bbt_ruler_scale = bbt_show_ticks_super_detail;
1225 Editor::metric_get_bbt (GtkCustomRulerMark **marks, gdouble lower, gdouble /*upper*/, gint /*maxchars*/)
1231 TempoMap::BBTPointList::iterator i;
1237 nframes64_t next_beat_pos;
1243 nframes64_t frame_skip;
1244 double frame_skip_error;
1245 double bbt_position_of_helper;
1246 double accumulated_error;
1247 bool i_am_accented = false;
1248 bool helper_active = false;
1250 if (current_bbt_points == 0 || current_bbt_points->empty()) {
1254 switch (bbt_ruler_scale) {
1256 case bbt_show_beats:
1257 beats = current_bbt_points->size();
1258 bbt_nmarks = beats + 2;
1260 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1262 (*marks)[0].label = g_strdup(" ");
1263 (*marks)[0].position = lower;
1264 (*marks)[0].style = GtkCustomRulerMarkMicro;
1266 for (n = 1, i = current_bbt_points->begin(); n < bbt_nmarks && i != current_bbt_points->end(); ++i) {
1267 if ((*i).type != TempoMap::Beat) {
1270 if ((*i).frame < lower && (bbt_bar_helper_on)) {
1271 snprintf (buf, sizeof(buf), "<%" PRIu32 "|%" PRIu32, (*i).bar, (*i).beat);
1272 (*marks)[0].label = g_strdup (buf);
1273 helper_active = true;
1276 if ((*i).beat == 1) {
1277 (*marks)[n].style = GtkCustomRulerMarkMajor;
1278 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1279 } else if (((*i).beat % 2 == 1)) {
1280 (*marks)[n].style = GtkCustomRulerMarkMinor;
1281 snprintf (buf, sizeof(buf), " ");
1283 (*marks)[n].style = GtkCustomRulerMarkMicro;
1284 snprintf (buf, sizeof(buf), " ");
1286 (*marks)[n].label = g_strdup (buf);
1287 (*marks)[n].position = (*i).frame;
1293 case bbt_show_ticks:
1295 beats = current_bbt_points->size();
1296 bbt_nmarks = (beats + 2) * bbt_beat_subdivision;
1298 bbt_position_of_helper = lower + (30 * Editor::get_current_zoom ());
1299 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1301 (*marks)[0].label = g_strdup(" ");
1302 (*marks)[0].position = lower;
1303 (*marks)[0].style = GtkCustomRulerMarkMicro;
1305 for (n = 1, i = current_bbt_points->begin(); n < bbt_nmarks && i != current_bbt_points->end(); ++i) {
1306 if ((*i).type != TempoMap::Beat) {
1309 if ((*i).frame < lower && (bbt_bar_helper_on)) {
1310 snprintf (buf, sizeof(buf), "<%" PRIu32 "|%" PRIu32, (*i).bar, (*i).beat);
1311 (*marks)[0].label = g_strdup (buf);
1312 helper_active = true;
1315 if ((*i).beat == 1) {
1316 (*marks)[n].style = GtkCustomRulerMarkMajor;
1317 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1319 (*marks)[n].style = GtkCustomRulerMarkMinor;
1320 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).beat);
1322 if (((*i).frame < bbt_position_of_helper) && helper_active) {
1323 snprintf (buf, sizeof(buf), " ");
1325 (*marks)[n].label = g_strdup (buf);
1326 (*marks)[n].position = (*i).frame;
1330 /* Add the tick marks */
1332 /* Find the next beat */
1333 next_beat.beats = (*i).beat;
1334 next_beat.bars = (*i).bar;
1335 next_beat.ticks = 0;
1337 if ((*i).meter->beats_per_bar() > (next_beat.beats + 1)) {
1338 next_beat.beats += 1;
1340 next_beat.bars += 1;
1341 next_beat.beats = 1;
1344 next_beat_pos = session->tempo_map().frame_time(next_beat);
1346 frame_skip = (nframes64_t) floor (frame_skip_error = (session->frame_rate() * 60) / (bbt_beat_subdivision * (*i).tempo->beats_per_minute()));
1347 frame_skip_error -= frame_skip;
1348 skip = (uint32_t) (Meter::ticks_per_beat / bbt_beat_subdivision);
1350 pos = (*i).frame + frame_skip;
1351 accumulated_error = frame_skip_error;
1355 for (t = 0; (tick < Meter::ticks_per_beat) && (n < bbt_nmarks) && (pos < next_beat_pos) ; pos += frame_skip, tick += skip, ++t) {
1357 if (t % bbt_accent_modulo == (bbt_accent_modulo - 1)) {
1358 i_am_accented = true;
1361 snprintf (buf, sizeof(buf), " ");
1362 (*marks)[n].label = g_strdup (buf);
1364 /* Error compensation for float to nframes64_t*/
1365 accumulated_error += frame_skip_error;
1366 if (accumulated_error > 1) {
1368 accumulated_error -= 1.0f;
1371 (*marks)[n].position = pos;
1373 if ((bbt_beat_subdivision > 4) && i_am_accented) {
1374 (*marks)[n].style = GtkCustomRulerMarkMinor;
1376 (*marks)[n].style = GtkCustomRulerMarkMicro;
1378 i_am_accented = false;
1385 case bbt_show_ticks_detail:
1387 beats = current_bbt_points->size();
1388 bbt_nmarks = (beats + 2) * bbt_beat_subdivision;
1390 bbt_position_of_helper = lower + (30 * Editor::get_current_zoom ());
1391 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1393 (*marks)[0].label = g_strdup(" ");
1394 (*marks)[0].position = lower;
1395 (*marks)[0].style = GtkCustomRulerMarkMicro;
1397 for (n = 1, i = current_bbt_points->begin(); n < bbt_nmarks && i != current_bbt_points->end(); ++i) {
1398 if ((*i).type != TempoMap::Beat) {
1401 if ((*i).frame < lower && (bbt_bar_helper_on)) {
1402 snprintf (buf, sizeof(buf), "<%" PRIu32 "|%" PRIu32, (*i).bar, (*i).beat);
1403 (*marks)[0].label = g_strdup (buf);
1404 helper_active = true;
1407 if ((*i).beat == 1) {
1408 (*marks)[n].style = GtkCustomRulerMarkMajor;
1409 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1411 (*marks)[n].style = GtkCustomRulerMarkMinor;
1412 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).beat);
1414 if (((*i).frame < bbt_position_of_helper) && helper_active) {
1415 snprintf (buf, sizeof(buf), " ");
1417 (*marks)[n].label = g_strdup (buf);
1418 (*marks)[n].position = (*i).frame;
1422 /* Add the tick marks */
1424 /* Find the next beat */
1426 next_beat.beats = (*i).beat;
1427 next_beat.bars = (*i).bar;
1429 if ((*i).meter->beats_per_bar() > (next_beat.beats + 1)) {
1430 next_beat.beats += 1;
1432 next_beat.bars += 1;
1433 next_beat.beats = 1;
1436 next_beat_pos = session->tempo_map().frame_time(next_beat);
1438 frame_skip = (nframes64_t) floor (frame_skip_error = (session->frame_rate() * 60) / (bbt_beat_subdivision * (*i).tempo->beats_per_minute()));
1439 frame_skip_error -= frame_skip;
1440 skip = (uint32_t) (Meter::ticks_per_beat / bbt_beat_subdivision);
1442 pos = (*i).frame + frame_skip;
1443 accumulated_error = frame_skip_error;
1447 for (t = 0; (tick < Meter::ticks_per_beat) && (n < bbt_nmarks) && (pos < next_beat_pos) ; pos += frame_skip, tick += skip, ++t) {
1449 if (t % bbt_accent_modulo == (bbt_accent_modulo - 1)) {
1450 i_am_accented = true;
1453 if (i_am_accented && (pos > bbt_position_of_helper)){
1454 snprintf (buf, sizeof(buf), "%" PRIu32, tick);
1456 snprintf (buf, sizeof(buf), " ");
1459 (*marks)[n].label = g_strdup (buf);
1461 /* Error compensation for float to nframes64_t*/
1462 accumulated_error += frame_skip_error;
1463 if (accumulated_error > 1) {
1465 accumulated_error -= 1.0f;
1468 (*marks)[n].position = pos;
1470 if ((bbt_beat_subdivision > 4) && i_am_accented) {
1471 (*marks)[n].style = GtkCustomRulerMarkMinor;
1473 (*marks)[n].style = GtkCustomRulerMarkMicro;
1475 i_am_accented = false;
1482 case bbt_show_ticks_super_detail:
1484 beats = current_bbt_points->size();
1485 bbt_nmarks = (beats + 2) * bbt_beat_subdivision;
1487 bbt_position_of_helper = lower + (30 * Editor::get_current_zoom ());
1488 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1490 (*marks)[0].label = g_strdup(" ");
1491 (*marks)[0].position = lower;
1492 (*marks)[0].style = GtkCustomRulerMarkMicro;
1494 for (n = 1, i = current_bbt_points->begin(); n < bbt_nmarks && i != current_bbt_points->end(); ++i) {
1495 if ((*i).type != TempoMap::Beat) {
1498 if ((*i).frame < lower && (bbt_bar_helper_on)) {
1499 snprintf (buf, sizeof(buf), "<%" PRIu32 "|%" PRIu32, (*i).bar, (*i).beat);
1500 (*marks)[0].label = g_strdup (buf);
1501 helper_active = true;
1504 if ((*i).beat == 1) {
1505 (*marks)[n].style = GtkCustomRulerMarkMajor;
1506 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1508 (*marks)[n].style = GtkCustomRulerMarkMinor;
1509 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).beat);
1511 if (((*i).frame < bbt_position_of_helper) && helper_active) {
1512 snprintf (buf, sizeof(buf), " ");
1514 (*marks)[n].label = g_strdup (buf);
1515 (*marks)[n].position = (*i).frame;
1519 /* Add the tick marks */
1521 /* Find the next beat */
1523 next_beat.beats = (*i).beat;
1524 next_beat.bars = (*i).bar;
1526 if ((*i).meter->beats_per_bar() > (next_beat.beats + 1)) {
1527 next_beat.beats += 1;
1529 next_beat.bars += 1;
1530 next_beat.beats = 1;
1533 next_beat_pos = session->tempo_map().frame_time(next_beat);
1535 frame_skip = (nframes64_t) floor (frame_skip_error = (session->frame_rate() * 60) / (bbt_beat_subdivision * (*i).tempo->beats_per_minute()));
1536 frame_skip_error -= frame_skip;
1537 skip = (uint32_t) (Meter::ticks_per_beat / bbt_beat_subdivision);
1539 pos = (*i).frame + frame_skip;
1540 accumulated_error = frame_skip_error;
1544 for (t = 0; (tick < Meter::ticks_per_beat) && (n < bbt_nmarks) && (pos < next_beat_pos) ; pos += frame_skip, tick += skip, ++t) {
1546 if (t % bbt_accent_modulo == (bbt_accent_modulo - 1)) {
1547 i_am_accented = true;
1550 if (pos > bbt_position_of_helper) {
1551 snprintf (buf, sizeof(buf), "%" PRIu32, tick);
1553 snprintf (buf, sizeof(buf), " ");
1556 (*marks)[n].label = g_strdup (buf);
1558 /* Error compensation for float to nframes64_t*/
1559 accumulated_error += frame_skip_error;
1560 if (accumulated_error > 1) {
1562 accumulated_error -= 1.0f;
1565 (*marks)[n].position = pos;
1567 if ((bbt_beat_subdivision > 4) && i_am_accented) {
1568 (*marks)[n].style = GtkCustomRulerMarkMinor;
1570 (*marks)[n].style = GtkCustomRulerMarkMicro;
1572 i_am_accented = false;
1581 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1582 snprintf (buf, sizeof(buf), "cannot handle %" PRIu32 " bars", bbt_bars );
1583 (*marks)[0].style = GtkCustomRulerMarkMajor;
1584 (*marks)[0].label = g_strdup (buf);
1585 (*marks)[0].position = lower;
1591 bbt_nmarks = (gint) (bbt_bars / 64) + 1;
1592 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1593 for (n = 0, i = current_bbt_points->begin(); i != current_bbt_points->end() && n < bbt_nmarks; i++) {
1594 if ((*i).type == TempoMap::Bar) {
1595 if ((*i).bar % 64 == 1) {
1596 if ((*i).bar % 256 == 1) {
1597 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1598 (*marks)[n].style = GtkCustomRulerMarkMajor;
1600 snprintf (buf, sizeof(buf), " ");
1601 if ((*i).bar % 256 == 129) {
1602 (*marks)[n].style = GtkCustomRulerMarkMinor;
1604 (*marks)[n].style = GtkCustomRulerMarkMicro;
1607 (*marks)[n].label = g_strdup (buf);
1608 (*marks)[n].position = (*i).frame;
1616 bbt_nmarks = (bbt_bars / 16) + 1;
1617 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1618 for (n = 0, i = current_bbt_points->begin(); i != current_bbt_points->end() && n < bbt_nmarks; i++) {
1619 if ((*i).type == TempoMap::Bar) {
1620 if ((*i).bar % 16 == 1) {
1621 if ((*i).bar % 64 == 1) {
1622 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1623 (*marks)[n].style = GtkCustomRulerMarkMajor;
1625 snprintf (buf, sizeof(buf), " ");
1626 if ((*i).bar % 64 == 33) {
1627 (*marks)[n].style = GtkCustomRulerMarkMinor;
1629 (*marks)[n].style = GtkCustomRulerMarkMicro;
1632 (*marks)[n].label = g_strdup (buf);
1633 (*marks)[n].position = (*i).frame;
1641 bbt_nmarks = (bbt_bars / 4) + 1;
1642 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1643 for (n = 0, i = current_bbt_points->begin(); i != current_bbt_points->end() && n < bbt_nmarks; ++i) {
1644 if ((*i).type == TempoMap::Bar) {
1645 if ((*i).bar % 4 == 1) {
1646 if ((*i).bar % 16 == 1) {
1647 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1648 (*marks)[n].style = GtkCustomRulerMarkMajor;
1650 snprintf (buf, sizeof(buf), " ");
1651 if ((*i).bar % 16 == 9) {
1652 (*marks)[n].style = GtkCustomRulerMarkMinor;
1654 (*marks)[n].style = GtkCustomRulerMarkMicro;
1657 (*marks)[n].label = g_strdup (buf);
1658 (*marks)[n].position = (*i).frame;
1667 bbt_nmarks = bbt_bars + 2;
1668 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks );
1669 for (n = 0, i = current_bbt_points->begin(); i != current_bbt_points->end() && n < bbt_nmarks; i++) {
1670 if ((*i).type == TempoMap::Bar) {
1671 if ((*i).bar % 4 == 1) {
1672 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1673 (*marks)[n].style = GtkCustomRulerMarkMajor;
1675 snprintf (buf, sizeof(buf), " ");
1676 if ((*i).bar % 4 == 3) {
1677 (*marks)[n].style = GtkCustomRulerMarkMinor;
1679 (*marks)[n].style = GtkCustomRulerMarkMicro;
1682 (*marks)[n].label = g_strdup (buf);
1683 (*marks)[n].position = (*i).frame;
1692 return n; //return the actual number of marks made, since we might have skipped some from fractional time signatures
1697 Editor::metric_get_frames (GtkCustomRulerMark **marks, gdouble lower, gdouble upper, gint /*maxchars*/)
1699 nframes64_t mark_interval;
1701 nframes64_t ilower = (nframes64_t) floor (lower);
1702 nframes64_t iupper = (nframes64_t) floor (upper);
1711 mark_interval = (iupper - ilower) / 5;
1712 if (mark_interval > session->frame_rate()) {
1713 mark_interval -= mark_interval % session->frame_rate();
1715 mark_interval = session->frame_rate() / (session->frame_rate() / mark_interval ) ;
1718 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * nmarks);
1719 for (n = 0, pos = ilower; n < nmarks; pos += mark_interval, ++n) {
1720 snprintf (buf, sizeof(buf), "%" PRIi64, pos);
1721 (*marks)[n].label = g_strdup (buf);
1722 (*marks)[n].position = pos;
1723 (*marks)[n].style = GtkCustomRulerMarkMajor;
1730 sample_to_clock_parts ( nframes64_t sample,
1731 nframes64_t sample_rate,
1745 hrs = left / (sample_rate * 60 * 60);
1746 left -= hrs * sample_rate * 60 * 60;
1747 mins = left / (sample_rate * 60);
1748 left -= mins * sample_rate * 60;
1749 secs = left / sample_rate;
1750 left -= secs * sample_rate;
1751 millisecs = left * 1000 / sample_rate;
1753 *millisecs_p = millisecs;
1762 Editor::set_minsec_ruler_scale (gdouble lower, gdouble upper)
1772 fr = session->frame_rate();
1774 /* to prevent 'flashing' */
1775 if (lower > (spacer = (nframes64_t)(128 * Editor::get_current_zoom ()))) {
1781 range = (nframes64_t) (upper - lower);
1783 if (range < (fr / 50)) {
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 / 10)) { /* 0-0.1 second */
1788 minsec_mark_interval = fr / 1000; /* show 1/1000 seconds */
1789 minsec_ruler_scale = minsec_show_frames;
1790 minsec_mark_modulo = 10;
1791 } else if (range <= (fr / 2)) { /* 0-0.5 second */
1792 minsec_mark_interval = fr / 100; /* show 1/100 seconds */
1793 minsec_ruler_scale = minsec_show_frames;
1794 minsec_mark_modulo = 100;
1795 } else if (range <= fr) { /* 0-1 second */
1796 minsec_mark_interval = fr / 10; /* show 1/10 seconds */
1797 minsec_ruler_scale = minsec_show_frames;
1798 minsec_mark_modulo = 200;
1799 } else if (range <= 2 * fr) { /* 1-2 seconds */
1800 minsec_mark_interval = fr / 10; /* show 1/10 seconds */
1801 minsec_ruler_scale = minsec_show_frames;
1802 minsec_mark_modulo = 500;
1803 } else if (range <= 8 * fr) { /* 2-5 seconds */
1804 minsec_mark_interval = fr / 5; /* show 2 seconds */
1805 minsec_ruler_scale = minsec_show_frames;
1806 minsec_mark_modulo = 1000;
1807 } else if (range <= 16 * fr) { /* 8-16 seconds */
1808 minsec_mark_interval = fr; /* show 1 seconds */
1809 minsec_ruler_scale = minsec_show_seconds;
1810 minsec_mark_modulo = 2;
1811 } else if (range <= 30 * fr) { /* 10-30 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 <= 60 * fr) { /* 30-60 seconds */
1816 minsec_mark_interval = fr; /* show 1 seconds */
1817 minsec_ruler_scale = minsec_show_seconds;
1818 minsec_mark_modulo = 5;
1819 } else if (range <= 2 * 60 * fr) { /* 1-2 minutes */
1820 minsec_mark_interval = 5 * fr; /* show 5 seconds */
1821 minsec_ruler_scale = minsec_show_seconds;
1822 minsec_mark_modulo = 3;
1823 } else if (range <= 4 * 60 * fr) { /* 4 minutes */
1824 minsec_mark_interval = 5 * fr; /* show 10 seconds */
1825 minsec_ruler_scale = minsec_show_seconds;
1826 minsec_mark_modulo = 30;
1827 } else if (range <= 10 * 60 * fr) { /* 10 minutes */
1828 minsec_mark_interval = 30 * fr; /* show 30 seconds */
1829 minsec_ruler_scale = minsec_show_seconds;
1830 minsec_mark_modulo = 120;
1831 } else if (range <= 30 * 60 * fr) { /* 10-30 minutes */
1832 minsec_mark_interval = 60 * fr; /* show 1 minute */
1833 minsec_ruler_scale = minsec_show_minutes;
1834 minsec_mark_modulo = 5;
1835 } else if (range <= 60 * 60 * fr) { /* 30 minutes - 1hr */
1836 minsec_mark_interval = 2 * 60 * fr; /* show 2 minutes */
1837 minsec_ruler_scale = minsec_show_minutes;
1838 minsec_mark_modulo = 10;
1839 } else if (range <= 4 * 60 * 60 * fr) { /* 1 - 4 hrs*/
1840 minsec_mark_interval = 5 * 60 * fr; /* show 10 minutes */
1841 minsec_ruler_scale = minsec_show_minutes;
1842 minsec_mark_modulo = 30;
1843 } else if (range <= 8 * 60 * 60 * fr) { /* 4 - 8 hrs*/
1844 minsec_mark_interval = 20 * 60 * fr; /* show 20 minutes */
1845 minsec_ruler_scale = minsec_show_minutes;
1846 minsec_mark_modulo = 60;
1847 } else if (range <= 16 * 60 * 60 * fr) { /* 16-24 hrs*/
1848 minsec_mark_interval = 60 * 60 * fr; /* show 60 minutes */
1849 minsec_ruler_scale = minsec_show_hours;
1850 minsec_mark_modulo = 2;
1853 /* not possible if nframes64_t is a 32 bit quantity */
1855 minsec_mark_interval = 4 * 60 * 60 * fr; /* show 4 hrs */
1857 minsec_nmarks = 2 + (range / minsec_mark_interval);
1861 Editor::metric_get_minsec (GtkCustomRulerMark **marks, gdouble lower, gdouble /*upper*/, gint /*maxchars*/)
1865 long hrs, mins, secs, millisecs;
1873 /* to prevent 'flashing' */
1874 if (lower > (spacer = (nframes64_t)(128 * Editor::get_current_zoom ()))) {
1875 lower = lower - spacer;
1880 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * minsec_nmarks);
1881 pos = ((((nframes64_t) floor(lower)) + (minsec_mark_interval/2))/minsec_mark_interval) * minsec_mark_interval;
1882 switch (minsec_ruler_scale) {
1883 case minsec_show_seconds:
1884 for (n = 0; n < minsec_nmarks; pos += minsec_mark_interval, ++n) {
1885 sample_to_clock_parts (pos, session->frame_rate(), &hrs, &mins, &secs, &millisecs);
1886 if (secs % minsec_mark_modulo == 0) {
1888 (*marks)[n].style = GtkCustomRulerMarkMajor;
1890 (*marks)[n].style = GtkCustomRulerMarkMinor;
1892 snprintf (buf, sizeof(buf), "%02ld:%02ld:%02ld.%03ld", hrs, mins, secs, millisecs);
1894 snprintf (buf, sizeof(buf), " ");
1895 (*marks)[n].style = GtkCustomRulerMarkMicro;
1897 (*marks)[n].label = g_strdup (buf);
1898 (*marks)[n].position = pos;
1901 case minsec_show_minutes:
1902 for (n = 0; n < minsec_nmarks; pos += minsec_mark_interval, ++n) {
1903 sample_to_clock_parts (pos, session->frame_rate(), &hrs, &mins, &secs, &millisecs);
1904 if (mins % minsec_mark_modulo == 0) {
1906 (*marks)[n].style = GtkCustomRulerMarkMajor;
1908 (*marks)[n].style = GtkCustomRulerMarkMinor;
1910 snprintf (buf, sizeof(buf), "%02ld:%02ld:%02ld.%03ld", hrs, mins, secs, millisecs);
1912 snprintf (buf, sizeof(buf), " ");
1913 (*marks)[n].style = GtkCustomRulerMarkMicro;
1915 (*marks)[n].label = g_strdup (buf);
1916 (*marks)[n].position = pos;
1919 case minsec_show_hours:
1920 for (n = 0; n < minsec_nmarks; pos += minsec_mark_interval, ++n) {
1921 sample_to_clock_parts (pos, session->frame_rate(), &hrs, &mins, &secs, &millisecs);
1922 if (hrs % minsec_mark_modulo == 0) {
1923 (*marks)[n].style = GtkCustomRulerMarkMajor;
1924 snprintf (buf, sizeof(buf), "%02ld:%02ld:%02ld.%03ld", hrs, mins, secs, millisecs);
1926 snprintf (buf, sizeof(buf), " ");
1927 (*marks)[n].style = GtkCustomRulerMarkMicro;
1929 (*marks)[n].label = g_strdup (buf);
1930 (*marks)[n].position = pos;
1933 case minsec_show_frames:
1934 for (n = 0; n < minsec_nmarks; pos += minsec_mark_interval, ++n) {
1935 sample_to_clock_parts (pos, session->frame_rate(), &hrs, &mins, &secs, &millisecs);
1936 if (millisecs % minsec_mark_modulo == 0) {
1938 (*marks)[n].style = GtkCustomRulerMarkMajor;
1940 (*marks)[n].style = GtkCustomRulerMarkMinor;
1942 snprintf (buf, sizeof(buf), "%02ld:%02ld:%02ld.%03ld", hrs, mins, secs, millisecs);
1944 snprintf (buf, sizeof(buf), " ");
1945 (*marks)[n].style = GtkCustomRulerMarkMicro;
1947 (*marks)[n].label = g_strdup (buf);
1948 (*marks)[n].position = pos;
1953 return minsec_nmarks;