2 Copyright (C) 2000 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "gtk2ardour-config.h"
24 #include <cstdio> // for sprintf, grrr
30 #include <gtk/gtkaction.h>
32 #include "ardour/session.h"
33 #include "ardour/tempo.h"
34 #include "ardour/profile.h"
35 #include <gtkmm2ext/gtk_ui.h>
40 #include "gtk-custom-hruler.h"
41 #include "gui_thread.h"
42 #include "time_axis_view.h"
43 #include "editor_drag.h"
44 #include "editor_cursors.h"
48 using namespace ARDOUR;
51 using namespace Editing;
53 Editor *Editor::ruler_editor;
55 /* the order here must match the "metric" enums in editor.h */
57 GtkCustomMetric Editor::ruler_metrics[4] = {
58 {1, Editor::_metric_get_timecode },
59 {1, Editor::_metric_get_bbt },
60 {1, Editor::_metric_get_frames },
61 {1, Editor::_metric_get_minsec }
65 Editor::initialize_rulers ()
68 ruler_grabbed_widget = 0;
70 _ruler_separator = new Gtk::HSeparator();
71 _ruler_separator->set_size_request(-1, 2);
72 _ruler_separator->set_name("TimebarPadding");
73 _ruler_separator->show();
75 _minsec_ruler = gtk_custom_hruler_new ();
76 minsec_ruler = Glib::wrap (_minsec_ruler);
77 minsec_ruler->set_name ("MinSecRuler");
78 minsec_ruler->set_size_request (-1, (int)timebar_height);
79 gtk_custom_ruler_set_metric (GTK_CUSTOM_RULER(_minsec_ruler), &ruler_metrics[ruler_metric_minsec]);
80 minsec_ruler->hide ();
81 minsec_ruler->set_no_show_all();
83 _timecode_ruler = gtk_custom_hruler_new ();
84 timecode_ruler = Glib::wrap (_timecode_ruler);
85 timecode_ruler->set_name ("TimecodeRuler");
86 timecode_ruler->set_size_request (-1, (int)timebar_height);
87 gtk_custom_ruler_set_metric (GTK_CUSTOM_RULER(_timecode_ruler), &ruler_metrics[ruler_metric_timecode]);
88 timecode_ruler->hide ();
89 timecode_ruler->set_no_show_all();
92 _bbt_ruler = gtk_custom_hruler_new ();
93 bbt_ruler = Glib::wrap (_bbt_ruler);
94 bbt_ruler->set_name ("BBTRuler");
95 bbt_ruler->set_size_request (-1, (int)timebar_height);
96 gtk_custom_ruler_set_metric (GTK_CUSTOM_RULER(_bbt_ruler), &ruler_metrics[ruler_metric_bbt]);
98 bbt_ruler->set_no_show_all();
101 _frames_ruler = gtk_custom_hruler_new ();
102 frames_ruler = Glib::wrap (_frames_ruler);
103 frames_ruler->set_name ("FramesRuler");
104 frames_ruler->set_size_request (-1, (int)timebar_height);
105 gtk_custom_ruler_set_metric (GTK_CUSTOM_RULER(_frames_ruler), &ruler_metrics[ruler_metric_frames]);
106 frames_ruler->hide ();
107 frames_ruler->set_no_show_all();
109 _bbt_ruler = gtk_custom_hruler_new ();
110 bbt_ruler = Glib::wrap (_bbt_ruler);
111 bbt_ruler->set_name ("BBTRuler");
112 bbt_ruler->set_size_request (-1, (int)timebar_height);
113 gtk_custom_ruler_set_metric (GTK_CUSTOM_RULER(_bbt_ruler), &ruler_metrics[ruler_metric_bbt]);
115 bbt_ruler->set_no_show_all();
116 minsec_ruler->hide ();
117 minsec_ruler->set_no_show_all();
120 using namespace Box_Helpers;
121 BoxList & ruler_lab_children = ruler_label_vbox.children();
122 BoxList & ruler_children = time_canvas_vbox.children();
123 BoxList & lab_children = time_button_vbox.children();
125 BoxList::iterator canvaspos = ruler_children.begin();
127 lab_children.push_back (Element(meter_label, PACK_SHRINK, PACK_START));
128 lab_children.push_back (Element(tempo_label, PACK_SHRINK, PACK_START));
129 lab_children.push_back (Element(range_mark_label, PACK_SHRINK, PACK_START));
130 lab_children.push_back (Element(transport_mark_label, PACK_SHRINK, PACK_START));
131 lab_children.push_back (Element(cd_mark_label, PACK_SHRINK, PACK_START));
132 lab_children.push_back (Element(mark_label, PACK_SHRINK, PACK_START));
134 ruler_lab_children.push_back (Element(minsec_label, PACK_SHRINK, PACK_START));
135 ruler_children.insert (canvaspos, Element(*minsec_ruler, PACK_SHRINK, PACK_START));
136 ruler_lab_children.push_back (Element(timecode_label, PACK_SHRINK, PACK_START));
137 ruler_children.insert (canvaspos, Element(*timecode_ruler, PACK_SHRINK, PACK_START));
138 ruler_lab_children.push_back (Element(frame_label, PACK_SHRINK, PACK_START));
139 ruler_children.insert (canvaspos, Element(*frames_ruler, PACK_SHRINK, PACK_START));
140 ruler_lab_children.push_back (Element(bbt_label, PACK_SHRINK, PACK_START));
141 ruler_children.insert (canvaspos, Element(*bbt_ruler, PACK_SHRINK, PACK_START));
143 timecode_ruler->add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::SCROLL_MASK);
144 bbt_ruler->add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::SCROLL_MASK);
145 frames_ruler->add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::SCROLL_MASK);
146 minsec_ruler->add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::SCROLL_MASK);
148 timecode_ruler->signal_button_release_event().connect (sigc::mem_fun(*this, &Editor::ruler_button_release));
149 bbt_ruler->signal_button_release_event().connect (sigc::mem_fun(*this, &Editor::ruler_button_release));
150 frames_ruler->signal_button_release_event().connect (sigc::mem_fun(*this, &Editor::ruler_button_release));
151 minsec_ruler->signal_button_release_event().connect (sigc::mem_fun(*this, &Editor::ruler_button_release));
153 timecode_ruler->signal_button_press_event().connect (sigc::mem_fun(*this, &Editor::ruler_button_press));
154 bbt_ruler->signal_button_press_event().connect (sigc::mem_fun(*this, &Editor::ruler_button_press));
155 frames_ruler->signal_button_press_event().connect (sigc::mem_fun(*this, &Editor::ruler_button_press));
156 minsec_ruler->signal_button_press_event().connect (sigc::mem_fun(*this, &Editor::ruler_button_press));
158 timecode_ruler->signal_motion_notify_event().connect (sigc::mem_fun(*this, &Editor::ruler_mouse_motion));
159 bbt_ruler->signal_motion_notify_event().connect (sigc::mem_fun(*this, &Editor::ruler_mouse_motion));
160 frames_ruler->signal_motion_notify_event().connect (sigc::mem_fun(*this, &Editor::ruler_mouse_motion));
161 minsec_ruler->signal_motion_notify_event().connect (sigc::mem_fun(*this, &Editor::ruler_mouse_motion));
163 timecode_ruler->signal_scroll_event().connect (sigc::mem_fun(*this, &Editor::ruler_scroll));
164 bbt_ruler->signal_scroll_event().connect (sigc::mem_fun(*this, &Editor::ruler_scroll));
165 frames_ruler->signal_scroll_event().connect (sigc::mem_fun(*this, &Editor::ruler_scroll));
166 minsec_ruler->signal_scroll_event().connect (sigc::mem_fun(*this, &Editor::ruler_scroll));
168 visible_timebars = 0; /*this will be changed below */
169 canvas_timebars_vsize = 0;
173 Editor::ruler_scroll (GdkEventScroll* event)
176 int direction = event->direction;
177 bool handled = false;
181 temporal_zoom_step (true);
185 case GDK_SCROLL_DOWN:
186 temporal_zoom_step (false);
190 case GDK_SCROLL_LEFT:
191 xdelta = (current_page_frames() / 2);
192 if (leftmost_frame > xdelta) {
193 reset_x_origin (leftmost_frame - xdelta);
200 case GDK_SCROLL_RIGHT:
201 xdelta = (current_page_frames() / 2);
202 if (max_framepos - xdelta > leftmost_frame) {
203 reset_x_origin (leftmost_frame + xdelta);
205 reset_x_origin (max_framepos - current_page_frames());
220 Editor::ruler_button_press (GdkEventButton* ev)
226 // jlc: grab ev->window ?
227 //Gtk::Main::grab_add (*minsec_ruler);
228 Widget * grab_widget = 0;
230 if (timecode_ruler->is_realized() && ev->window == timecode_ruler->get_window()->gobj()) {
231 grab_widget = timecode_ruler;
232 } else if (bbt_ruler->is_realized() && ev->window == bbt_ruler->get_window()->gobj()) {
233 grab_widget = bbt_ruler;
234 } else if (frames_ruler->is_realized() && ev->window == frames_ruler->get_window()->gobj()) {
235 grab_widget = frames_ruler;
236 } else if (minsec_ruler->is_realized() && ev->window == minsec_ruler->get_window()->gobj()) {
237 grab_widget = minsec_ruler;
241 grab_widget->add_modal_grab ();
242 ruler_grabbed_widget = grab_widget;
245 if (ev->button == 1) {
246 // Since we will locate the playhead on button release, cancel any running
248 if (_session->is_auditioning()) {
249 _session->cancel_audition ();
252 /* playhead cursor */
253 _drags->set (new CursorDrag (this, &playhead_cursor->canvas_item, false), reinterpret_cast<GdkEvent *> (ev));
254 _dragging_playhead = true;
261 Editor::ruler_button_release (GdkEventButton* ev)
268 Gdk::ModifierType state;
270 if (_drags->active ()) {
271 _drags->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 framepos_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)
315 if (_drags->active ()) {
316 _drags->motion_handler (reinterpret_cast<GdkEvent*> (ev), false);
324 Editor::popup_ruler_menu (framepos_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-frames-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_frames_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_frames_action->set_active (true);
477 ruler_frames_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_frames_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 compute_fixed_ruler_scale ();
769 update_fixed_rulers();
770 redisplay_tempo (false);
772 /* Changing ruler visibility means that any lines on markers might need updating */
773 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
774 i->second->setup_lines ();
779 Editor::update_just_timecode ()
781 ENSURE_GUI_THREAD (*this, &Editor::update_just_timecode)
787 framepos_t rightmost_frame = leftmost_frame + current_page_frames();
789 if (ruler_timecode_action->get_active()) {
790 gtk_custom_ruler_set_range (GTK_CUSTOM_RULER(_timecode_ruler), leftmost_frame, rightmost_frame,
791 leftmost_frame, _session->current_end_frame());
796 Editor::compute_fixed_ruler_scale ()
802 if (ruler_timecode_action->get_active()) {
803 set_timecode_ruler_scale (leftmost_frame, leftmost_frame + current_page_frames());
806 if (ruler_minsec_action->get_active()) {
807 set_minsec_ruler_scale (leftmost_frame, leftmost_frame + current_page_frames());
810 if (ruler_frames_action->get_active()) {
811 set_frames_ruler_scale (leftmost_frame, leftmost_frame + current_page_frames());
816 Editor::update_fixed_rulers ()
818 framepos_t rightmost_frame;
824 ruler_metrics[ruler_metric_timecode].units_per_pixel = frames_per_unit;
825 ruler_metrics[ruler_metric_frames].units_per_pixel = frames_per_unit;
826 ruler_metrics[ruler_metric_minsec].units_per_pixel = frames_per_unit;
828 rightmost_frame = leftmost_frame + current_page_frames();
830 /* these force a redraw, which in turn will force execution of the metric callbacks
831 to compute the relevant ticks to display.
834 if (ruler_timecode_action->get_active()) {
835 gtk_custom_ruler_set_range (GTK_CUSTOM_RULER(_timecode_ruler), leftmost_frame, rightmost_frame,
836 leftmost_frame, _session->current_end_frame());
839 if (ruler_frames_action->get_active()) {
840 gtk_custom_ruler_set_range (GTK_CUSTOM_RULER(_frames_ruler), leftmost_frame, rightmost_frame,
841 leftmost_frame, _session->current_end_frame());
844 if (ruler_minsec_action->get_active()) {
845 gtk_custom_ruler_set_range (GTK_CUSTOM_RULER(_minsec_ruler), leftmost_frame, rightmost_frame,
846 leftmost_frame, _session->current_end_frame());
851 Editor::update_tempo_based_rulers ()
857 ruler_metrics[ruler_metric_bbt].units_per_pixel = frames_per_unit;
859 if (ruler_bbt_action->get_active()) {
860 gtk_custom_ruler_set_range (GTK_CUSTOM_RULER(_bbt_ruler), leftmost_frame, leftmost_frame+current_page_frames(),
861 leftmost_frame, _session->current_end_frame());
865 /* Mark generation */
868 Editor::_metric_get_timecode (GtkCustomRulerMark **marks, gdouble lower, gdouble upper, gint maxchars)
870 return ruler_editor->metric_get_timecode (marks, lower, upper, maxchars);
874 Editor::_metric_get_bbt (GtkCustomRulerMark **marks, gdouble lower, gdouble upper, gint maxchars)
876 return ruler_editor->metric_get_bbt (marks, lower, upper, maxchars);
880 Editor::_metric_get_frames (GtkCustomRulerMark **marks, gdouble lower, gdouble upper, gint maxchars)
882 return ruler_editor->metric_get_frames (marks, lower, upper, maxchars);
886 Editor::_metric_get_minsec (GtkCustomRulerMark **marks, gdouble lower, gdouble upper, gint maxchars)
888 return ruler_editor->metric_get_minsec (marks, lower, upper, maxchars);
892 Editor::set_timecode_ruler_scale (framepos_t lower, framepos_t upper)
901 fr = _session->frame_rate();
903 if (lower > (spacer = (framepos_t) (128 * Editor::get_current_zoom ()))) {
904 lower = lower - spacer;
908 upper = upper + spacer;
909 framecnt_t const range = upper - lower;
911 if (range < (2 * _session->frames_per_timecode_frame())) { /* 0 - 2 frames */
912 timecode_ruler_scale = timecode_show_bits;
913 timecode_mark_modulo = 20;
914 timecode_nmarks = 2 + (2 * _session->config.get_subframes_per_frame());
915 } else if (range <= (fr / 4)) { /* 2 frames - 0.250 second */
916 timecode_ruler_scale = timecode_show_frames;
917 timecode_mark_modulo = 1;
918 timecode_nmarks = 2 + (range / (framepos_t)_session->frames_per_timecode_frame());
919 } else if (range <= (fr / 2)) { /* 0.25-0.5 second */
920 timecode_ruler_scale = timecode_show_frames;
921 timecode_mark_modulo = 2;
922 timecode_nmarks = 2 + (range / (framepos_t)_session->frames_per_timecode_frame());
923 } else if (range <= fr) { /* 0.5-1 second */
924 timecode_ruler_scale = timecode_show_frames;
925 timecode_mark_modulo = 5;
926 timecode_nmarks = 2 + (range / (framepos_t)_session->frames_per_timecode_frame());
927 } else if (range <= 2 * fr) { /* 1-2 seconds */
928 timecode_ruler_scale = timecode_show_frames;
929 timecode_mark_modulo = 10;
930 timecode_nmarks = 2 + (range / (framepos_t)_session->frames_per_timecode_frame());
931 } else if (range <= 8 * fr) { /* 2-8 seconds */
932 timecode_ruler_scale = timecode_show_seconds;
933 timecode_mark_modulo = 1;
934 timecode_nmarks = 2 + (range / fr);
935 } else if (range <= 16 * fr) { /* 8-16 seconds */
936 timecode_ruler_scale = timecode_show_seconds;
937 timecode_mark_modulo = 2;
938 timecode_nmarks = 2 + (range / fr);
939 } else if (range <= 30 * fr) { /* 16-30 seconds */
940 timecode_ruler_scale = timecode_show_seconds;
941 timecode_mark_modulo = 5;
942 timecode_nmarks = 2 + (range / fr);
943 } else if (range <= 60 * fr) { /* 30-60 seconds */
944 timecode_ruler_scale = timecode_show_seconds;
945 timecode_mark_modulo = 5;
946 timecode_nmarks = 2 + (range / fr);
947 } else if (range <= 2 * 60 * fr) { /* 1-2 minutes */
948 timecode_ruler_scale = timecode_show_seconds;
949 timecode_mark_modulo = 15;
950 timecode_nmarks = 2 + (range / fr);
951 } else if (range <= 4 * 60 * fr) { /* 2-4 minutes */
952 timecode_ruler_scale = timecode_show_seconds;
953 timecode_mark_modulo = 30;
954 timecode_nmarks = 2 + (range / fr);
955 } else if (range <= 10 * 60 * fr) { /* 4-10 minutes */
956 timecode_ruler_scale = timecode_show_minutes;
957 timecode_mark_modulo = 2;
958 timecode_nmarks = 2 + 10;
959 } else if (range <= 30 * 60 * fr) { /* 10-30 minutes */
960 timecode_ruler_scale = timecode_show_minutes;
961 timecode_mark_modulo = 5;
962 timecode_nmarks = 2 + 30;
963 } else if (range <= 60 * 60 * fr) { /* 30 minutes - 1hr */
964 timecode_ruler_scale = timecode_show_minutes;
965 timecode_mark_modulo = 10;
966 timecode_nmarks = 2 + 60;
967 } else if (range <= 4 * 60 * 60 * fr) { /* 1 - 4 hrs*/
968 timecode_ruler_scale = timecode_show_minutes;
969 timecode_mark_modulo = 30;
970 timecode_nmarks = 2 + (60 * 4);
971 } else if (range <= 8 * 60 * 60 * fr) { /* 4 - 8 hrs*/
972 timecode_ruler_scale = timecode_show_hours;
973 timecode_mark_modulo = 1;
974 timecode_nmarks = 2 + 8;
975 } else if (range <= 16 * 60 * 60 * fr) { /* 16-24 hrs*/
976 timecode_ruler_scale = timecode_show_hours;
977 timecode_mark_modulo = 1;
978 timecode_nmarks = 2 + 24;
981 /* not possible if framepos_t is a 32 bit quantity */
983 timecode_ruler_scale = timecode_show_hours;
984 timecode_mark_modulo = 4;
985 timecode_nmarks = 2 + 24;
991 Editor::metric_get_timecode (GtkCustomRulerMark **marks, gdouble lower, gdouble /*upper*/, gint /*maxchars*/)
995 Timecode::Time timecode;
1003 if (lower > (spacer = (framecnt_t)(128 * Editor::get_current_zoom ()))) {
1004 lower = lower - spacer;
1009 pos = (framecnt_t) floor (lower);
1011 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * timecode_nmarks);
1012 switch (timecode_ruler_scale) {
1013 case timecode_show_bits:
1015 // Find timecode time of this sample (pos) with subframe accuracy
1016 _session->sample_to_timecode(pos, timecode, true /* use_offset */, true /* use_subframes */ );
1018 for (n = 0; n < timecode_nmarks; n++) {
1019 _session->timecode_to_sample(timecode, pos, true /* use_offset */, true /* use_subframes */ );
1020 if ((timecode.subframes % timecode_mark_modulo) == 0) {
1021 if (timecode.subframes == 0) {
1022 (*marks)[n].style = GtkCustomRulerMarkMajor;
1023 snprintf (buf, sizeof(buf), "%s%02u:%02u:%02u:%02u", timecode.negative ? "-" : "", timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
1025 (*marks)[n].style = GtkCustomRulerMarkMinor;
1026 snprintf (buf, sizeof(buf), ".%02u", timecode.subframes);
1029 snprintf (buf, sizeof(buf)," ");
1030 (*marks)[n].style = GtkCustomRulerMarkMicro;
1033 (*marks)[n].label = g_strdup (buf);
1034 (*marks)[n].position = pos;
1036 // Increment subframes by one
1037 Timecode::increment_subframes( timecode, _session->config.get_subframes_per_frame() );
1040 case timecode_show_seconds:
1041 // Find timecode time of this sample (pos)
1042 _session->sample_to_timecode(pos, timecode, true /* use_offset */, false /* use_subframes */ );
1043 // Go to next whole second down
1044 Timecode::seconds_floor( timecode );
1046 for (n = 0; n < timecode_nmarks; n++) {
1047 _session->timecode_to_sample(timecode, pos, true /* use_offset */, false /* use_subframes */ );
1048 if ((timecode.seconds % timecode_mark_modulo) == 0) {
1049 if (timecode.seconds == 0) {
1050 (*marks)[n].style = GtkCustomRulerMarkMajor;
1051 (*marks)[n].position = pos;
1053 (*marks)[n].style = GtkCustomRulerMarkMinor;
1054 (*marks)[n].position = pos;
1056 snprintf (buf, sizeof(buf), "%s%02u:%02u:%02u:%02u", timecode.negative ? "-" : "", timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
1058 snprintf (buf, sizeof(buf)," ");
1059 (*marks)[n].style = GtkCustomRulerMarkMicro;
1060 (*marks)[n].position = pos;
1063 (*marks)[n].label = g_strdup (buf);
1064 Timecode::increment_seconds( timecode, _session->config.get_subframes_per_frame() );
1067 case timecode_show_minutes:
1068 // Find timecode time of this sample (pos)
1069 _session->sample_to_timecode(pos, timecode, true /* use_offset */, false /* use_subframes */ );
1070 // Go to next whole minute down
1071 Timecode::minutes_floor( timecode );
1073 for (n = 0; n < timecode_nmarks; n++) {
1074 _session->timecode_to_sample(timecode, pos, true /* use_offset */, false /* use_subframes */ );
1075 if ((timecode.minutes % timecode_mark_modulo) == 0) {
1076 if (timecode.minutes == 0) {
1077 (*marks)[n].style = GtkCustomRulerMarkMajor;
1079 (*marks)[n].style = GtkCustomRulerMarkMinor;
1081 snprintf (buf, sizeof(buf), "%s%02u:%02u:%02u:%02u", timecode.negative ? "-" : "", timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
1083 snprintf (buf, sizeof(buf)," ");
1084 (*marks)[n].style = GtkCustomRulerMarkMicro;
1087 (*marks)[n].label = g_strdup (buf);
1088 (*marks)[n].position = pos;
1089 Timecode::increment_minutes( timecode, _session->config.get_subframes_per_frame() );
1093 case timecode_show_hours:
1094 // Find timecode time of this sample (pos)
1095 _session->sample_to_timecode(pos, timecode, true /* use_offset */, false /* use_subframes */ );
1096 // Go to next whole hour down
1097 Timecode::hours_floor( timecode );
1099 for (n = 0; n < timecode_nmarks; n++) {
1100 _session->timecode_to_sample(timecode, pos, true /* use_offset */, false /* use_subframes */ );
1101 if ((timecode.hours % timecode_mark_modulo) == 0) {
1102 (*marks)[n].style = GtkCustomRulerMarkMajor;
1103 snprintf (buf, sizeof(buf), "%s%02u:%02u:%02u:%02u", timecode.negative ? "-" : "", timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
1105 snprintf (buf, sizeof(buf)," ");
1106 (*marks)[n].style = GtkCustomRulerMarkMicro;
1109 (*marks)[n].label = g_strdup (buf);
1110 (*marks)[n].position = pos;
1112 Timecode::increment_hours( timecode, _session->config.get_subframes_per_frame() );
1115 case timecode_show_frames:
1116 // Find timecode time of this sample (pos)
1117 _session->sample_to_timecode(pos, timecode, true /* use_offset */, false /* use_subframes */ );
1118 // Go to next whole frame down
1119 Timecode::frames_floor( timecode );
1121 for (n = 0; n < timecode_nmarks; n++) {
1122 _session->timecode_to_sample(timecode, pos, true /* use_offset */, false /* use_subframes */ );
1123 if ((timecode.frames % timecode_mark_modulo) == 0) {
1124 if (timecode.frames == 0) {
1125 (*marks)[n].style = GtkCustomRulerMarkMajor;
1127 (*marks)[n].style = GtkCustomRulerMarkMinor;
1129 (*marks)[n].position = pos;
1130 snprintf (buf, sizeof(buf), "%s%02u:%02u:%02u:%02u", timecode.negative ? "-" : "", timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
1132 snprintf (buf, sizeof(buf)," ");
1133 (*marks)[n].style = GtkCustomRulerMarkMicro;
1134 (*marks)[n].position = pos;
1137 (*marks)[n].label = g_strdup (buf);
1138 Timecode::increment( timecode, _session->config.get_subframes_per_frame() );
1144 return timecode_nmarks;
1149 Editor::compute_bbt_ruler_scale (framepos_t lower, framepos_t upper)
1151 if (_session == 0) {
1154 TempoMap::BBTPointList::iterator i;
1155 Timecode::BBT_Time lower_beat, upper_beat; // the beats at each end of the ruler
1157 _session->bbt_time (lower, lower_beat);
1158 _session->bbt_time (upper, upper_beat);
1161 bbt_accent_modulo = 1;
1162 bbt_bar_helper_on = false;
1166 bbt_ruler_scale = bbt_over;
1168 switch (_snap_type) {
1169 case SnapToBeatDiv2:
1170 bbt_beat_subdivision = 2;
1172 case SnapToBeatDiv3:
1173 bbt_beat_subdivision = 3;
1175 case SnapToBeatDiv4:
1176 bbt_beat_subdivision = 4;
1178 case SnapToBeatDiv5:
1179 bbt_beat_subdivision = 5;
1180 bbt_accent_modulo = 2; // XXX YIKES
1182 case SnapToBeatDiv6:
1183 bbt_beat_subdivision = 6;
1184 bbt_accent_modulo = 2; // XXX YIKES
1186 case SnapToBeatDiv7:
1187 bbt_beat_subdivision = 7;
1188 bbt_accent_modulo = 2; // XXX YIKES
1190 case SnapToBeatDiv8:
1191 bbt_beat_subdivision = 8;
1192 bbt_accent_modulo = 2;
1194 case SnapToBeatDiv10:
1195 bbt_beat_subdivision = 10;
1196 bbt_accent_modulo = 2; // XXX YIKES
1198 case SnapToBeatDiv12:
1199 bbt_beat_subdivision = 12;
1200 bbt_accent_modulo = 3;
1202 case SnapToBeatDiv14:
1203 bbt_beat_subdivision = 14;
1204 bbt_accent_modulo = 3; // XXX YIKES!
1206 case SnapToBeatDiv16:
1207 bbt_beat_subdivision = 16;
1208 bbt_accent_modulo = 4;
1210 case SnapToBeatDiv20:
1211 bbt_beat_subdivision = 20;
1212 bbt_accent_modulo = 5;
1214 case SnapToBeatDiv24:
1215 bbt_beat_subdivision = 24;
1216 bbt_accent_modulo = 6;
1218 case SnapToBeatDiv28:
1219 bbt_beat_subdivision = 28;
1220 bbt_accent_modulo = 7;
1222 case SnapToBeatDiv32:
1223 bbt_beat_subdivision = 32;
1224 bbt_accent_modulo = 8;
1227 bbt_beat_subdivision = 4;
1231 if (current_bbt_points == 0 || current_bbt_points->empty()) {
1235 i = current_bbt_points->end();
1237 if ((*i).beat >= (*current_bbt_points->begin()).beat) {
1238 bbt_bars = (*i).bar - (*current_bbt_points->begin()).bar;
1240 bbt_bars = (*i).bar - (*current_bbt_points->begin()).bar - 1;
1242 beats = current_bbt_points->size() - bbt_bars;
1244 /* Only show the bar helper if there aren't many bars on the screen */
1245 if ((bbt_bars < 2) || (beats < 5)) {
1246 bbt_bar_helper_on = true;
1249 if (bbt_bars > 8192) {
1250 bbt_ruler_scale = bbt_over;
1251 } else if (bbt_bars > 1024) {
1252 bbt_ruler_scale = bbt_show_64;
1253 } else if (bbt_bars > 256) {
1254 bbt_ruler_scale = bbt_show_16;
1255 } else if (bbt_bars > 64) {
1256 bbt_ruler_scale = bbt_show_4;
1257 } else if (bbt_bars > 10) {
1258 bbt_ruler_scale = bbt_show_1;
1259 } else if (bbt_bars > 2) {
1260 bbt_ruler_scale = bbt_show_beats;
1261 } else if (bbt_bars > 0) {
1262 bbt_ruler_scale = bbt_show_ticks;
1264 bbt_ruler_scale = bbt_show_ticks_detail;
1267 if ((bbt_ruler_scale == bbt_show_ticks_detail) && (lower_beat.beats == upper_beat.beats) && (upper_beat.ticks - lower_beat.ticks <= Timecode::BBT_Time::ticks_per_beat / 4)) {
1268 bbt_ruler_scale = bbt_show_ticks_super_detail;
1273 Editor::metric_get_bbt (GtkCustomRulerMark **marks, gdouble lower, gdouble /*upper*/, gint /*maxchars*/)
1275 if (_session == 0) {
1279 TempoMap::BBTPointList::iterator i;
1284 Timecode::BBT_Time next_beat;
1285 framepos_t next_beat_pos;
1291 framepos_t frame_skip;
1292 double frame_skip_error;
1293 double bbt_position_of_helper;
1294 double accumulated_error;
1295 bool i_am_accented = false;
1296 bool helper_active = false;
1298 if (current_bbt_points == 0 || current_bbt_points->empty()) {
1302 switch (bbt_ruler_scale) {
1304 case bbt_show_beats:
1305 beats = current_bbt_points->size();
1306 bbt_nmarks = beats + 2;
1308 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1310 (*marks)[0].label = g_strdup(" ");
1311 (*marks)[0].position = lower;
1312 (*marks)[0].style = GtkCustomRulerMarkMicro;
1314 for (n = 1, i = current_bbt_points->begin(); n < bbt_nmarks && i != current_bbt_points->end(); ++i) {
1315 if ((*i).type != TempoMap::Beat) {
1318 if ((*i).frame < lower && (bbt_bar_helper_on)) {
1319 snprintf (buf, sizeof(buf), "<%" PRIu32 "|%" PRIu32, (*i).bar, (*i).beat);
1320 (*marks)[0].label = g_strdup (buf);
1321 helper_active = true;
1324 if ((*i).beat == 1) {
1325 (*marks)[n].style = GtkCustomRulerMarkMajor;
1326 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1327 } else if (((*i).beat % 2 == 1)) {
1328 (*marks)[n].style = GtkCustomRulerMarkMinor;
1329 snprintf (buf, sizeof(buf), " ");
1331 (*marks)[n].style = GtkCustomRulerMarkMicro;
1332 snprintf (buf, sizeof(buf), " ");
1334 (*marks)[n].label = g_strdup (buf);
1335 (*marks)[n].position = (*i).frame;
1341 case bbt_show_ticks:
1343 beats = current_bbt_points->size();
1344 bbt_nmarks = (beats + 2) * bbt_beat_subdivision;
1346 bbt_position_of_helper = lower + (30 * Editor::get_current_zoom ());
1347 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1349 (*marks)[0].label = g_strdup(" ");
1350 (*marks)[0].position = lower;
1351 (*marks)[0].style = GtkCustomRulerMarkMicro;
1353 for (n = 1, i = current_bbt_points->begin(); n < bbt_nmarks && i != current_bbt_points->end(); ++i) {
1354 if ((*i).type != TempoMap::Beat) {
1357 if ((*i).frame < lower && (bbt_bar_helper_on)) {
1358 snprintf (buf, sizeof(buf), "<%" PRIu32 "|%" PRIu32, (*i).bar, (*i).beat);
1359 (*marks)[0].label = g_strdup (buf);
1360 helper_active = true;
1363 if ((*i).beat == 1) {
1364 (*marks)[n].style = GtkCustomRulerMarkMajor;
1365 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1367 (*marks)[n].style = GtkCustomRulerMarkMinor;
1368 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).beat);
1370 if (((*i).frame < bbt_position_of_helper) && helper_active) {
1371 snprintf (buf, sizeof(buf), " ");
1373 (*marks)[n].label = g_strdup (buf);
1374 (*marks)[n].position = (*i).frame;
1378 /* Add the tick marks */
1380 /* Find the next beat */
1381 next_beat.beats = (*i).beat;
1382 next_beat.bars = (*i).bar;
1383 next_beat.ticks = 0;
1385 if ((*i).meter->beats_per_bar() > (next_beat.beats + 1)) {
1386 next_beat.beats += 1;
1388 next_beat.bars += 1;
1389 next_beat.beats = 1;
1392 next_beat_pos = _session->tempo_map().frame_time(next_beat);
1394 frame_skip = (framepos_t) floor (frame_skip_error = (_session->frame_rate() * 60) / (bbt_beat_subdivision * (*i).tempo->beats_per_minute()));
1395 frame_skip_error -= frame_skip;
1396 skip = (uint32_t) (Timecode::BBT_Time::ticks_per_beat / bbt_beat_subdivision);
1398 pos = (*i).frame + frame_skip;
1399 accumulated_error = frame_skip_error;
1403 for (t = 0; (tick < Timecode::BBT_Time::ticks_per_beat) && (n < bbt_nmarks) && (pos < next_beat_pos) ; pos += frame_skip, tick += skip, ++t) {
1405 if (t % bbt_accent_modulo == (bbt_accent_modulo - 1)) {
1406 i_am_accented = true;
1409 snprintf (buf, sizeof(buf), " ");
1410 (*marks)[n].label = g_strdup (buf);
1412 /* Error compensation for float to framepos_t*/
1413 accumulated_error += frame_skip_error;
1414 if (accumulated_error > 1) {
1416 accumulated_error -= 1.0f;
1419 (*marks)[n].position = pos;
1421 if ((bbt_beat_subdivision > 4) && i_am_accented) {
1422 (*marks)[n].style = GtkCustomRulerMarkMinor;
1424 (*marks)[n].style = GtkCustomRulerMarkMicro;
1426 i_am_accented = false;
1433 case bbt_show_ticks_detail:
1435 beats = current_bbt_points->size();
1436 bbt_nmarks = (beats + 2) * bbt_beat_subdivision;
1438 bbt_position_of_helper = lower + (30 * Editor::get_current_zoom ());
1439 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1441 (*marks)[0].label = g_strdup(" ");
1442 (*marks)[0].position = lower;
1443 (*marks)[0].style = GtkCustomRulerMarkMicro;
1445 for (n = 1, i = current_bbt_points->begin(); n < bbt_nmarks && i != current_bbt_points->end(); ++i) {
1446 if ((*i).type != TempoMap::Beat) {
1449 if ((*i).frame < lower && (bbt_bar_helper_on)) {
1450 snprintf (buf, sizeof(buf), "<%" PRIu32 "|%" PRIu32, (*i).bar, (*i).beat);
1451 (*marks)[0].label = g_strdup (buf);
1452 helper_active = true;
1455 if ((*i).beat == 1) {
1456 (*marks)[n].style = GtkCustomRulerMarkMajor;
1457 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1459 (*marks)[n].style = GtkCustomRulerMarkMinor;
1460 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).beat);
1462 if (((*i).frame < bbt_position_of_helper) && helper_active) {
1463 snprintf (buf, sizeof(buf), " ");
1465 (*marks)[n].label = g_strdup (buf);
1466 (*marks)[n].position = (*i).frame;
1470 /* Add the tick marks */
1472 /* Find the next beat */
1474 next_beat.beats = (*i).beat;
1475 next_beat.bars = (*i).bar;
1477 if ((*i).meter->beats_per_bar() > (next_beat.beats + 1)) {
1478 next_beat.beats += 1;
1480 next_beat.bars += 1;
1481 next_beat.beats = 1;
1484 next_beat_pos = _session->tempo_map().frame_time(next_beat);
1486 frame_skip = (framepos_t) floor (frame_skip_error = (_session->frame_rate() * 60) / (bbt_beat_subdivision * (*i).tempo->beats_per_minute()));
1487 frame_skip_error -= frame_skip;
1488 skip = (uint32_t) (Timecode::BBT_Time::ticks_per_beat / bbt_beat_subdivision);
1490 pos = (*i).frame + frame_skip;
1491 accumulated_error = frame_skip_error;
1495 for (t = 0; (tick < Timecode::BBT_Time::ticks_per_beat) && (n < bbt_nmarks) && (pos < next_beat_pos) ; pos += frame_skip, tick += skip, ++t) {
1497 if (t % bbt_accent_modulo == (bbt_accent_modulo - 1)) {
1498 i_am_accented = true;
1501 if (i_am_accented && (pos > bbt_position_of_helper)){
1502 snprintf (buf, sizeof(buf), "%" PRIu32, tick);
1504 snprintf (buf, sizeof(buf), " ");
1507 (*marks)[n].label = g_strdup (buf);
1509 /* Error compensation for float to framepos_t*/
1510 accumulated_error += frame_skip_error;
1511 if (accumulated_error > 1) {
1513 accumulated_error -= 1.0f;
1516 (*marks)[n].position = pos;
1518 if ((bbt_beat_subdivision > 4) && i_am_accented) {
1519 (*marks)[n].style = GtkCustomRulerMarkMinor;
1521 (*marks)[n].style = GtkCustomRulerMarkMicro;
1523 i_am_accented = false;
1530 case bbt_show_ticks_super_detail:
1532 beats = current_bbt_points->size();
1533 bbt_nmarks = (beats + 2) * bbt_beat_subdivision;
1535 bbt_position_of_helper = lower + (30 * Editor::get_current_zoom ());
1536 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1538 (*marks)[0].label = g_strdup(" ");
1539 (*marks)[0].position = lower;
1540 (*marks)[0].style = GtkCustomRulerMarkMicro;
1542 for (n = 1, i = current_bbt_points->begin(); n < bbt_nmarks && i != current_bbt_points->end(); ++i) {
1543 if ((*i).type != TempoMap::Beat) {
1546 if ((*i).frame < lower && (bbt_bar_helper_on)) {
1547 snprintf (buf, sizeof(buf), "<%" PRIu32 "|%" PRIu32, (*i).bar, (*i).beat);
1548 (*marks)[0].label = g_strdup (buf);
1549 helper_active = true;
1552 if ((*i).beat == 1) {
1553 (*marks)[n].style = GtkCustomRulerMarkMajor;
1554 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1556 (*marks)[n].style = GtkCustomRulerMarkMinor;
1557 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).beat);
1559 if (((*i).frame < bbt_position_of_helper) && helper_active) {
1560 snprintf (buf, sizeof(buf), " ");
1562 (*marks)[n].label = g_strdup (buf);
1563 (*marks)[n].position = (*i).frame;
1567 /* Add the tick marks */
1569 /* Find the next beat */
1571 next_beat.beats = (*i).beat;
1572 next_beat.bars = (*i).bar;
1574 if ((*i).meter->beats_per_bar() > (next_beat.beats + 1)) {
1575 next_beat.beats += 1;
1577 next_beat.bars += 1;
1578 next_beat.beats = 1;
1581 next_beat_pos = _session->tempo_map().frame_time(next_beat);
1583 frame_skip = (framepos_t) floor (frame_skip_error = (_session->frame_rate() * 60) / (bbt_beat_subdivision * (*i).tempo->beats_per_minute()));
1584 frame_skip_error -= frame_skip;
1585 skip = (uint32_t) (Timecode::BBT_Time::ticks_per_beat / bbt_beat_subdivision);
1587 pos = (*i).frame + frame_skip;
1588 accumulated_error = frame_skip_error;
1592 for (t = 0; (tick < Timecode::BBT_Time::ticks_per_beat) && (n < bbt_nmarks) && (pos < next_beat_pos) ; pos += frame_skip, tick += skip, ++t) {
1594 if (t % bbt_accent_modulo == (bbt_accent_modulo - 1)) {
1595 i_am_accented = true;
1598 if (pos > bbt_position_of_helper) {
1599 snprintf (buf, sizeof(buf), "%" PRIu32, tick);
1601 snprintf (buf, sizeof(buf), " ");
1604 (*marks)[n].label = g_strdup (buf);
1606 /* Error compensation for float to framepos_t*/
1607 accumulated_error += frame_skip_error;
1608 if (accumulated_error > 1) {
1610 accumulated_error -= 1.0f;
1613 (*marks)[n].position = pos;
1615 if ((bbt_beat_subdivision > 4) && i_am_accented) {
1616 (*marks)[n].style = GtkCustomRulerMarkMinor;
1618 (*marks)[n].style = GtkCustomRulerMarkMicro;
1620 i_am_accented = false;
1629 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1630 snprintf (buf, sizeof(buf), "cannot handle %" PRIu32 " bars", bbt_bars );
1631 (*marks)[0].style = GtkCustomRulerMarkMajor;
1632 (*marks)[0].label = g_strdup (buf);
1633 (*marks)[0].position = lower;
1639 bbt_nmarks = (gint) (bbt_bars / 64) + 1;
1640 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1641 for (n = 0, i = current_bbt_points->begin(); i != current_bbt_points->end() && n < bbt_nmarks; i++) {
1642 if ((*i).type == TempoMap::Bar) {
1643 if ((*i).bar % 64 == 1) {
1644 if ((*i).bar % 256 == 1) {
1645 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1646 (*marks)[n].style = GtkCustomRulerMarkMajor;
1648 snprintf (buf, sizeof(buf), " ");
1649 if ((*i).bar % 256 == 129) {
1650 (*marks)[n].style = GtkCustomRulerMarkMinor;
1652 (*marks)[n].style = GtkCustomRulerMarkMicro;
1655 (*marks)[n].label = g_strdup (buf);
1656 (*marks)[n].position = (*i).frame;
1664 bbt_nmarks = (bbt_bars / 16) + 1;
1665 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1666 for (n = 0, i = current_bbt_points->begin(); i != current_bbt_points->end() && n < bbt_nmarks; i++) {
1667 if ((*i).type == TempoMap::Bar) {
1668 if ((*i).bar % 16 == 1) {
1669 if ((*i).bar % 64 == 1) {
1670 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1671 (*marks)[n].style = GtkCustomRulerMarkMajor;
1673 snprintf (buf, sizeof(buf), " ");
1674 if ((*i).bar % 64 == 33) {
1675 (*marks)[n].style = GtkCustomRulerMarkMinor;
1677 (*marks)[n].style = GtkCustomRulerMarkMicro;
1680 (*marks)[n].label = g_strdup (buf);
1681 (*marks)[n].position = (*i).frame;
1689 bbt_nmarks = (bbt_bars / 4) + 1;
1690 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1691 for (n = 0, i = current_bbt_points->begin(); i != current_bbt_points->end() && n < bbt_nmarks; ++i) {
1692 if ((*i).type == TempoMap::Bar) {
1693 if ((*i).bar % 4 == 1) {
1694 if ((*i).bar % 16 == 1) {
1695 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1696 (*marks)[n].style = GtkCustomRulerMarkMajor;
1698 snprintf (buf, sizeof(buf), " ");
1699 if ((*i).bar % 16 == 9) {
1700 (*marks)[n].style = GtkCustomRulerMarkMinor;
1702 (*marks)[n].style = GtkCustomRulerMarkMicro;
1705 (*marks)[n].label = g_strdup (buf);
1706 (*marks)[n].position = (*i).frame;
1715 bbt_nmarks = bbt_bars + 2;
1716 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks );
1717 for (n = 0, i = current_bbt_points->begin(); i != current_bbt_points->end() && n < bbt_nmarks; i++) {
1718 if ((*i).type == TempoMap::Bar) {
1719 if ((*i).bar % 4 == 1) {
1720 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1721 (*marks)[n].style = GtkCustomRulerMarkMajor;
1723 snprintf (buf, sizeof(buf), " ");
1724 if ((*i).bar % 4 == 3) {
1725 (*marks)[n].style = GtkCustomRulerMarkMinor;
1727 (*marks)[n].style = GtkCustomRulerMarkMicro;
1730 (*marks)[n].label = g_strdup (buf);
1731 (*marks)[n].position = (*i).frame;
1740 return n; //return the actual number of marks made, since we might have skipped some from fractional time signatures
1745 Editor::set_frames_ruler_scale (framepos_t lower, framepos_t upper)
1747 _frames_ruler_interval = (upper - lower) / 5;
1751 Editor::metric_get_frames (GtkCustomRulerMark **marks, gdouble lower, gdouble upper, gint /*maxchars*/)
1754 framepos_t const ilower = (framepos_t) floor (lower);
1759 if (_session == 0) {
1764 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * nmarks);
1765 for (n = 0, pos = ilower; n < nmarks; pos += _frames_ruler_interval, ++n) {
1766 snprintf (buf, sizeof(buf), "%" PRIi64, pos);
1767 (*marks)[n].label = g_strdup (buf);
1768 (*marks)[n].position = pos;
1769 (*marks)[n].style = GtkCustomRulerMarkMajor;
1776 sample_to_clock_parts ( framepos_t sample,
1777 framepos_t sample_rate,
1791 hrs = left / (sample_rate * 60 * 60);
1792 left -= hrs * sample_rate * 60 * 60;
1793 mins = left / (sample_rate * 60);
1794 left -= mins * sample_rate * 60;
1795 secs = left / sample_rate;
1796 left -= secs * sample_rate;
1797 millisecs = left * 1000 / sample_rate;
1799 *millisecs_p = millisecs;
1808 Editor::set_minsec_ruler_scale (framepos_t lower, framepos_t upper)
1813 if (_session == 0) {
1817 fr = _session->frame_rate();
1819 /* to prevent 'flashing' */
1820 if (lower > (spacer = (framepos_t)(128 * Editor::get_current_zoom ()))) {
1826 framecnt_t const range = upper - lower;
1828 if (range < (fr / 50)) {
1829 minsec_mark_interval = fr / 1000; /* show 1/1000 seconds */
1830 minsec_ruler_scale = minsec_show_frames;
1831 minsec_mark_modulo = 10;
1832 } else if (range <= (fr / 10)) { /* 0-0.1 second */
1833 minsec_mark_interval = fr / 1000; /* show 1/1000 seconds */
1834 minsec_ruler_scale = minsec_show_frames;
1835 minsec_mark_modulo = 10;
1836 } else if (range <= (fr / 2)) { /* 0-0.5 second */
1837 minsec_mark_interval = fr / 100; /* show 1/100 seconds */
1838 minsec_ruler_scale = minsec_show_frames;
1839 minsec_mark_modulo = 100;
1840 } else if (range <= fr) { /* 0-1 second */
1841 minsec_mark_interval = fr / 10; /* show 1/10 seconds */
1842 minsec_ruler_scale = minsec_show_frames;
1843 minsec_mark_modulo = 200;
1844 } else if (range <= 2 * fr) { /* 1-2 seconds */
1845 minsec_mark_interval = fr / 10; /* show 1/10 seconds */
1846 minsec_ruler_scale = minsec_show_frames;
1847 minsec_mark_modulo = 500;
1848 } else if (range <= 8 * fr) { /* 2-5 seconds */
1849 minsec_mark_interval = fr / 5; /* show 2 seconds */
1850 minsec_ruler_scale = minsec_show_frames;
1851 minsec_mark_modulo = 1000;
1852 } else if (range <= 16 * fr) { /* 8-16 seconds */
1853 minsec_mark_interval = fr; /* show 1 seconds */
1854 minsec_ruler_scale = minsec_show_seconds;
1855 minsec_mark_modulo = 2;
1856 } else if (range <= 30 * fr) { /* 10-30 seconds */
1857 minsec_mark_interval = fr; /* show 1 seconds */
1858 minsec_ruler_scale = minsec_show_seconds;
1859 minsec_mark_modulo = 5;
1860 } else if (range <= 60 * fr) { /* 30-60 seconds */
1861 minsec_mark_interval = fr; /* show 1 seconds */
1862 minsec_ruler_scale = minsec_show_seconds;
1863 minsec_mark_modulo = 5;
1864 } else if (range <= 2 * 60 * fr) { /* 1-2 minutes */
1865 minsec_mark_interval = 5 * fr; /* show 5 seconds */
1866 minsec_ruler_scale = minsec_show_seconds;
1867 minsec_mark_modulo = 3;
1868 } else if (range <= 4 * 60 * fr) { /* 4 minutes */
1869 minsec_mark_interval = 5 * fr; /* show 10 seconds */
1870 minsec_ruler_scale = minsec_show_seconds;
1871 minsec_mark_modulo = 30;
1872 } else if (range <= 10 * 60 * fr) { /* 10 minutes */
1873 minsec_mark_interval = 30 * fr; /* show 30 seconds */
1874 minsec_ruler_scale = minsec_show_seconds;
1875 minsec_mark_modulo = 120;
1876 } else if (range <= 30 * 60 * fr) { /* 10-30 minutes */
1877 minsec_mark_interval = 60 * fr; /* show 1 minute */
1878 minsec_ruler_scale = minsec_show_minutes;
1879 minsec_mark_modulo = 5;
1880 } else if (range <= 60 * 60 * fr) { /* 30 minutes - 1hr */
1881 minsec_mark_interval = 2 * 60 * fr; /* show 2 minutes */
1882 minsec_ruler_scale = minsec_show_minutes;
1883 minsec_mark_modulo = 10;
1884 } else if (range <= 4 * 60 * 60 * fr) { /* 1 - 4 hrs*/
1885 minsec_mark_interval = 5 * 60 * fr; /* show 10 minutes */
1886 minsec_ruler_scale = minsec_show_minutes;
1887 minsec_mark_modulo = 30;
1888 } else if (range <= 8 * 60 * 60 * fr) { /* 4 - 8 hrs*/
1889 minsec_mark_interval = 20 * 60 * fr; /* show 20 minutes */
1890 minsec_ruler_scale = minsec_show_minutes;
1891 minsec_mark_modulo = 60;
1892 } else if (range <= 16 * 60 * 60 * fr) { /* 16-24 hrs*/
1893 minsec_mark_interval = 60 * 60 * fr; /* show 60 minutes */
1894 minsec_ruler_scale = minsec_show_hours;
1895 minsec_mark_modulo = 2;
1898 /* not possible if framepos_t is a 32 bit quantity */
1900 minsec_mark_interval = 4 * 60 * 60 * fr; /* show 4 hrs */
1902 minsec_nmarks = 2 + (range / minsec_mark_interval);
1906 Editor::metric_get_minsec (GtkCustomRulerMark **marks, gdouble lower, gdouble /*upper*/, gint /*maxchars*/)
1910 long hrs, mins, secs, millisecs;
1914 if (_session == 0) {
1918 /* to prevent 'flashing' */
1919 if (lower > (spacer = (framepos_t) (128 * Editor::get_current_zoom ()))) {
1920 lower = lower - spacer;
1925 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * minsec_nmarks);
1926 pos = ((((framepos_t) floor(lower)) + (minsec_mark_interval/2))/minsec_mark_interval) * minsec_mark_interval;
1927 switch (minsec_ruler_scale) {
1928 case minsec_show_seconds:
1929 for (n = 0; n < minsec_nmarks; pos += minsec_mark_interval, ++n) {
1930 sample_to_clock_parts (pos, _session->frame_rate(), &hrs, &mins, &secs, &millisecs);
1931 if (secs % minsec_mark_modulo == 0) {
1933 (*marks)[n].style = GtkCustomRulerMarkMajor;
1935 (*marks)[n].style = GtkCustomRulerMarkMinor;
1937 snprintf (buf, sizeof(buf), "%02ld:%02ld:%02ld.%03ld", hrs, mins, secs, millisecs);
1939 snprintf (buf, sizeof(buf), " ");
1940 (*marks)[n].style = GtkCustomRulerMarkMicro;
1942 (*marks)[n].label = g_strdup (buf);
1943 (*marks)[n].position = pos;
1946 case minsec_show_minutes:
1947 for (n = 0; n < minsec_nmarks; pos += minsec_mark_interval, ++n) {
1948 sample_to_clock_parts (pos, _session->frame_rate(), &hrs, &mins, &secs, &millisecs);
1949 if (mins % minsec_mark_modulo == 0) {
1951 (*marks)[n].style = GtkCustomRulerMarkMajor;
1953 (*marks)[n].style = GtkCustomRulerMarkMinor;
1955 snprintf (buf, sizeof(buf), "%02ld:%02ld:%02ld.%03ld", hrs, mins, secs, millisecs);
1957 snprintf (buf, sizeof(buf), " ");
1958 (*marks)[n].style = GtkCustomRulerMarkMicro;
1960 (*marks)[n].label = g_strdup (buf);
1961 (*marks)[n].position = pos;
1964 case minsec_show_hours:
1965 for (n = 0; n < minsec_nmarks; pos += minsec_mark_interval, ++n) {
1966 sample_to_clock_parts (pos, _session->frame_rate(), &hrs, &mins, &secs, &millisecs);
1967 if (hrs % minsec_mark_modulo == 0) {
1968 (*marks)[n].style = GtkCustomRulerMarkMajor;
1969 snprintf (buf, sizeof(buf), "%02ld:%02ld:%02ld.%03ld", hrs, mins, secs, millisecs);
1971 snprintf (buf, sizeof(buf), " ");
1972 (*marks)[n].style = GtkCustomRulerMarkMicro;
1974 (*marks)[n].label = g_strdup (buf);
1975 (*marks)[n].position = pos;
1978 case minsec_show_frames:
1979 for (n = 0; n < minsec_nmarks; pos += minsec_mark_interval, ++n) {
1980 sample_to_clock_parts (pos, _session->frame_rate(), &hrs, &mins, &secs, &millisecs);
1981 if (millisecs % minsec_mark_modulo == 0) {
1983 (*marks)[n].style = GtkCustomRulerMarkMajor;
1985 (*marks)[n].style = GtkCustomRulerMarkMinor;
1987 snprintf (buf, sizeof(buf), "%02ld:%02ld:%02ld.%03ld", hrs, mins, secs, millisecs);
1989 snprintf (buf, sizeof(buf), " ");
1990 (*marks)[n].style = GtkCustomRulerMarkMicro;
1992 (*marks)[n].label = g_strdup (buf);
1993 (*marks)[n].position = pos;
1998 return minsec_nmarks;