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-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 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() );
812 Editor::update_fixed_rulers ()
814 framepos_t rightmost_frame;
820 ruler_metrics[ruler_metric_timecode].units_per_pixel = frames_per_unit;
821 ruler_metrics[ruler_metric_frames].units_per_pixel = frames_per_unit;
822 ruler_metrics[ruler_metric_minsec].units_per_pixel = frames_per_unit;
824 rightmost_frame = leftmost_frame + current_page_frames();
826 /* these force a redraw, which in turn will force execution of the metric callbacks
827 to compute the relevant ticks to display.
830 if (ruler_timecode_action->get_active()) {
831 gtk_custom_ruler_set_range (GTK_CUSTOM_RULER(_timecode_ruler), leftmost_frame, rightmost_frame,
832 leftmost_frame, _session->current_end_frame());
835 if (ruler_samples_action->get_active()) {
836 gtk_custom_ruler_set_range (GTK_CUSTOM_RULER(_frames_ruler), leftmost_frame, rightmost_frame,
837 leftmost_frame, _session->current_end_frame());
840 if (ruler_minsec_action->get_active()) {
841 gtk_custom_ruler_set_range (GTK_CUSTOM_RULER(_minsec_ruler), leftmost_frame, rightmost_frame,
842 leftmost_frame, _session->current_end_frame());
847 Editor::update_tempo_based_rulers ()
853 ruler_metrics[ruler_metric_bbt].units_per_pixel = frames_per_unit;
855 if (ruler_bbt_action->get_active()) {
856 gtk_custom_ruler_set_range (GTK_CUSTOM_RULER(_bbt_ruler), leftmost_frame, leftmost_frame+current_page_frames(),
857 leftmost_frame, _session->current_end_frame());
861 /* Mark generation */
864 Editor::_metric_get_timecode (GtkCustomRulerMark **marks, gdouble lower, gdouble upper, gint maxchars)
866 return ruler_editor->metric_get_timecode (marks, lower, upper, maxchars);
870 Editor::_metric_get_bbt (GtkCustomRulerMark **marks, gdouble lower, gdouble upper, gint maxchars)
872 return ruler_editor->metric_get_bbt (marks, lower, upper, maxchars);
876 Editor::_metric_get_frames (GtkCustomRulerMark **marks, gdouble lower, gdouble upper, gint maxchars)
878 return ruler_editor->metric_get_frames (marks, lower, upper, maxchars);
882 Editor::_metric_get_minsec (GtkCustomRulerMark **marks, gdouble lower, gdouble upper, gint maxchars)
884 return ruler_editor->metric_get_minsec (marks, lower, upper, maxchars);
888 Editor::set_timecode_ruler_scale (gdouble lower, gdouble upper)
898 fr = _session->frame_rate();
900 if (lower > (spacer = (framepos_t)(128 * Editor::get_current_zoom ()))) {
901 lower = lower - spacer;
905 upper = upper + spacer;
906 range = (framepos_t) floor (upper - lower);
908 if (range < (2 * _session->frames_per_timecode_frame())) { /* 0 - 2 frames */
909 timecode_ruler_scale = timecode_show_bits;
910 timecode_mark_modulo = 20;
911 timecode_nmarks = 2 + (2 * _session->config.get_subframes_per_frame());
912 } else if (range <= (fr / 4)) { /* 2 frames - 0.250 second */
913 timecode_ruler_scale = timecode_show_frames;
914 timecode_mark_modulo = 1;
915 timecode_nmarks = 2 + (range / (framepos_t)_session->frames_per_timecode_frame());
916 } else if (range <= (fr / 2)) { /* 0.25-0.5 second */
917 timecode_ruler_scale = timecode_show_frames;
918 timecode_mark_modulo = 2;
919 timecode_nmarks = 2 + (range / (framepos_t)_session->frames_per_timecode_frame());
920 } else if (range <= fr) { /* 0.5-1 second */
921 timecode_ruler_scale = timecode_show_frames;
922 timecode_mark_modulo = 5;
923 timecode_nmarks = 2 + (range / (framepos_t)_session->frames_per_timecode_frame());
924 } else if (range <= 2 * fr) { /* 1-2 seconds */
925 timecode_ruler_scale = timecode_show_frames;
926 timecode_mark_modulo = 10;
927 timecode_nmarks = 2 + (range / (framepos_t)_session->frames_per_timecode_frame());
928 } else if (range <= 8 * fr) { /* 2-8 seconds */
929 timecode_ruler_scale = timecode_show_seconds;
930 timecode_mark_modulo = 1;
931 timecode_nmarks = 2 + (range / fr);
932 } else if (range <= 16 * fr) { /* 8-16 seconds */
933 timecode_ruler_scale = timecode_show_seconds;
934 timecode_mark_modulo = 2;
935 timecode_nmarks = 2 + (range / fr);
936 } else if (range <= 30 * fr) { /* 16-30 seconds */
937 timecode_ruler_scale = timecode_show_seconds;
938 timecode_mark_modulo = 5;
939 timecode_nmarks = 2 + (range / fr);
940 } else if (range <= 60 * fr) { /* 30-60 seconds */
941 timecode_ruler_scale = timecode_show_seconds;
942 timecode_mark_modulo = 5;
943 timecode_nmarks = 2 + (range / fr);
944 } else if (range <= 2 * 60 * fr) { /* 1-2 minutes */
945 timecode_ruler_scale = timecode_show_seconds;
946 timecode_mark_modulo = 15;
947 timecode_nmarks = 2 + (range / fr);
948 } else if (range <= 4 * 60 * fr) { /* 2-4 minutes */
949 timecode_ruler_scale = timecode_show_seconds;
950 timecode_mark_modulo = 30;
951 timecode_nmarks = 2 + (range / fr);
952 } else if (range <= 10 * 60 * fr) { /* 4-10 minutes */
953 timecode_ruler_scale = timecode_show_minutes;
954 timecode_mark_modulo = 2;
955 timecode_nmarks = 2 + 10;
956 } else if (range <= 30 * 60 * fr) { /* 10-30 minutes */
957 timecode_ruler_scale = timecode_show_minutes;
958 timecode_mark_modulo = 5;
959 timecode_nmarks = 2 + 30;
960 } else if (range <= 60 * 60 * fr) { /* 30 minutes - 1hr */
961 timecode_ruler_scale = timecode_show_minutes;
962 timecode_mark_modulo = 10;
963 timecode_nmarks = 2 + 60;
964 } else if (range <= 4 * 60 * 60 * fr) { /* 1 - 4 hrs*/
965 timecode_ruler_scale = timecode_show_minutes;
966 timecode_mark_modulo = 30;
967 timecode_nmarks = 2 + (60 * 4);
968 } else if (range <= 8 * 60 * 60 * fr) { /* 4 - 8 hrs*/
969 timecode_ruler_scale = timecode_show_hours;
970 timecode_mark_modulo = 1;
971 timecode_nmarks = 2 + 8;
972 } else if (range <= 16 * 60 * 60 * fr) { /* 16-24 hrs*/
973 timecode_ruler_scale = timecode_show_hours;
974 timecode_mark_modulo = 1;
975 timecode_nmarks = 2 + 24;
978 /* not possible if framepos_t is a 32 bit quantity */
980 timecode_ruler_scale = timecode_show_hours;
981 timecode_mark_modulo = 4;
982 timecode_nmarks = 2 + 24;
988 Editor::metric_get_timecode (GtkCustomRulerMark **marks, gdouble lower, gdouble /*upper*/, gint /*maxchars*/)
992 Timecode::Time timecode;
1000 if (lower > (spacer = (framecnt_t)(128 * Editor::get_current_zoom ()))) {
1001 lower = lower - spacer;
1006 pos = (framecnt_t) floor (lower);
1008 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * timecode_nmarks);
1009 switch (timecode_ruler_scale) {
1010 case timecode_show_bits:
1012 // Find timecode time of this sample (pos) with subframe accuracy
1013 _session->sample_to_timecode(pos, timecode, true /* use_offset */, true /* use_subframes */ );
1015 for (n = 0; n < timecode_nmarks; n++) {
1016 _session->timecode_to_sample(timecode, pos, true /* use_offset */, true /* use_subframes */ );
1017 if ((timecode.subframes % timecode_mark_modulo) == 0) {
1018 if (timecode.subframes == 0) {
1019 (*marks)[n].style = GtkCustomRulerMarkMajor;
1020 snprintf (buf, sizeof(buf), "%s%02u:%02u:%02u:%02u", timecode.negative ? "-" : "", timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
1022 (*marks)[n].style = GtkCustomRulerMarkMinor;
1023 snprintf (buf, sizeof(buf), ".%02u", timecode.subframes);
1026 snprintf (buf, sizeof(buf)," ");
1027 (*marks)[n].style = GtkCustomRulerMarkMicro;
1030 (*marks)[n].label = g_strdup (buf);
1031 (*marks)[n].position = pos;
1033 // Increment subframes by one
1034 Timecode::increment_subframes( timecode, _session->config.get_subframes_per_frame() );
1037 case timecode_show_seconds:
1038 // Find timecode time of this sample (pos)
1039 _session->sample_to_timecode(pos, timecode, true /* use_offset */, false /* use_subframes */ );
1040 // Go to next whole second down
1041 Timecode::seconds_floor( timecode );
1043 for (n = 0; n < timecode_nmarks; n++) {
1044 _session->timecode_to_sample(timecode, pos, true /* use_offset */, false /* use_subframes */ );
1045 if ((timecode.seconds % timecode_mark_modulo) == 0) {
1046 if (timecode.seconds == 0) {
1047 (*marks)[n].style = GtkCustomRulerMarkMajor;
1048 (*marks)[n].position = pos;
1050 (*marks)[n].style = GtkCustomRulerMarkMinor;
1051 (*marks)[n].position = pos;
1053 snprintf (buf, sizeof(buf), "%s%02u:%02u:%02u:%02u", timecode.negative ? "-" : "", timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
1055 snprintf (buf, sizeof(buf)," ");
1056 (*marks)[n].style = GtkCustomRulerMarkMicro;
1057 (*marks)[n].position = pos;
1060 (*marks)[n].label = g_strdup (buf);
1061 Timecode::increment_seconds( timecode, _session->config.get_subframes_per_frame() );
1064 case timecode_show_minutes:
1065 // Find timecode time of this sample (pos)
1066 _session->sample_to_timecode(pos, timecode, true /* use_offset */, false /* use_subframes */ );
1067 // Go to next whole minute down
1068 Timecode::minutes_floor( timecode );
1070 for (n = 0; n < timecode_nmarks; n++) {
1071 _session->timecode_to_sample(timecode, pos, true /* use_offset */, false /* use_subframes */ );
1072 if ((timecode.minutes % timecode_mark_modulo) == 0) {
1073 if (timecode.minutes == 0) {
1074 (*marks)[n].style = GtkCustomRulerMarkMajor;
1076 (*marks)[n].style = GtkCustomRulerMarkMinor;
1078 snprintf (buf, sizeof(buf), "%s%02u:%02u:%02u:%02u", timecode.negative ? "-" : "", timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
1080 snprintf (buf, sizeof(buf)," ");
1081 (*marks)[n].style = GtkCustomRulerMarkMicro;
1084 (*marks)[n].label = g_strdup (buf);
1085 (*marks)[n].position = pos;
1086 Timecode::increment_minutes( timecode, _session->config.get_subframes_per_frame() );
1090 case timecode_show_hours:
1091 // Find timecode time of this sample (pos)
1092 _session->sample_to_timecode(pos, timecode, true /* use_offset */, false /* use_subframes */ );
1093 // Go to next whole hour down
1094 Timecode::hours_floor( timecode );
1096 for (n = 0; n < timecode_nmarks; n++) {
1097 _session->timecode_to_sample(timecode, pos, true /* use_offset */, false /* use_subframes */ );
1098 if ((timecode.hours % timecode_mark_modulo) == 0) {
1099 (*marks)[n].style = GtkCustomRulerMarkMajor;
1100 snprintf (buf, sizeof(buf), "%s%02u:%02u:%02u:%02u", timecode.negative ? "-" : "", timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
1102 snprintf (buf, sizeof(buf)," ");
1103 (*marks)[n].style = GtkCustomRulerMarkMicro;
1106 (*marks)[n].label = g_strdup (buf);
1107 (*marks)[n].position = pos;
1109 Timecode::increment_hours( timecode, _session->config.get_subframes_per_frame() );
1112 case timecode_show_frames:
1113 // Find timecode time of this sample (pos)
1114 _session->sample_to_timecode(pos, timecode, true /* use_offset */, false /* use_subframes */ );
1115 // Go to next whole frame down
1116 Timecode::frames_floor( timecode );
1118 for (n = 0; n < timecode_nmarks; n++) {
1119 _session->timecode_to_sample(timecode, pos, true /* use_offset */, false /* use_subframes */ );
1120 if ((timecode.frames % timecode_mark_modulo) == 0) {
1121 if (timecode.frames == 0) {
1122 (*marks)[n].style = GtkCustomRulerMarkMajor;
1124 (*marks)[n].style = GtkCustomRulerMarkMinor;
1126 (*marks)[n].position = pos;
1127 snprintf (buf, sizeof(buf), "%s%02u:%02u:%02u:%02u", timecode.negative ? "-" : "", timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
1129 snprintf (buf, sizeof(buf)," ");
1130 (*marks)[n].style = GtkCustomRulerMarkMicro;
1131 (*marks)[n].position = pos;
1134 (*marks)[n].label = g_strdup (buf);
1135 Timecode::increment( timecode, _session->config.get_subframes_per_frame() );
1141 return timecode_nmarks;
1146 Editor::compute_bbt_ruler_scale (framepos_t lower, framepos_t upper)
1148 if (_session == 0) {
1151 TempoMap::BBTPointList::iterator i;
1152 Timecode::BBT_Time lower_beat, upper_beat; // the beats at each end of the ruler
1154 _session->bbt_time (lower, lower_beat);
1155 _session->bbt_time (upper, upper_beat);
1158 bbt_accent_modulo = 1;
1159 bbt_bar_helper_on = false;
1163 bbt_ruler_scale = bbt_over;
1165 switch (_snap_type) {
1166 case SnapToBeatDiv2:
1167 bbt_beat_subdivision = 2;
1169 case SnapToBeatDiv3:
1170 bbt_beat_subdivision = 3;
1172 case SnapToBeatDiv4:
1173 bbt_beat_subdivision = 4;
1175 case SnapToBeatDiv5:
1176 bbt_beat_subdivision = 5;
1177 bbt_accent_modulo = 2; // XXX YIKES
1179 case SnapToBeatDiv6:
1180 bbt_beat_subdivision = 6;
1181 bbt_accent_modulo = 2; // XXX YIKES
1183 case SnapToBeatDiv7:
1184 bbt_beat_subdivision = 7;
1185 bbt_accent_modulo = 2; // XXX YIKES
1187 case SnapToBeatDiv8:
1188 bbt_beat_subdivision = 8;
1189 bbt_accent_modulo = 2;
1191 case SnapToBeatDiv10:
1192 bbt_beat_subdivision = 10;
1193 bbt_accent_modulo = 2; // XXX YIKES
1195 case SnapToBeatDiv12:
1196 bbt_beat_subdivision = 12;
1197 bbt_accent_modulo = 3;
1199 case SnapToBeatDiv14:
1200 bbt_beat_subdivision = 14;
1201 bbt_accent_modulo = 3; // XXX YIKES!
1203 case SnapToBeatDiv16:
1204 bbt_beat_subdivision = 16;
1205 bbt_accent_modulo = 4;
1207 case SnapToBeatDiv20:
1208 bbt_beat_subdivision = 20;
1209 bbt_accent_modulo = 5;
1211 case SnapToBeatDiv24:
1212 bbt_beat_subdivision = 24;
1213 bbt_accent_modulo = 6;
1215 case SnapToBeatDiv28:
1216 bbt_beat_subdivision = 28;
1217 bbt_accent_modulo = 7;
1219 case SnapToBeatDiv32:
1220 bbt_beat_subdivision = 32;
1221 bbt_accent_modulo = 8;
1224 bbt_beat_subdivision = 4;
1228 if (current_bbt_points == 0 || current_bbt_points->empty()) {
1232 i = current_bbt_points->end();
1234 if ((*i).beat >= (*current_bbt_points->begin()).beat) {
1235 bbt_bars = (*i).bar - (*current_bbt_points->begin()).bar;
1237 bbt_bars = (*i).bar - (*current_bbt_points->begin()).bar - 1;
1239 beats = current_bbt_points->size() - bbt_bars;
1241 /*Only show the bar helper if there aren't many bars on the screen */
1242 if ((bbt_bars < 2) || (beats < 5)) {
1243 bbt_bar_helper_on = true;
1246 if (bbt_bars > 8192) {
1247 bbt_ruler_scale = bbt_over;
1248 } else if (bbt_bars > 1024) {
1249 bbt_ruler_scale = bbt_show_64;
1250 } else if (bbt_bars > 256) {
1251 bbt_ruler_scale = bbt_show_16;
1252 } else if (bbt_bars > 64) {
1253 bbt_ruler_scale = bbt_show_4;
1254 } else if (bbt_bars > 10) {
1255 bbt_ruler_scale = bbt_show_1;
1256 } else if (bbt_bars > 2) {
1257 bbt_ruler_scale = bbt_show_beats;
1258 } else if (bbt_bars > 0) {
1259 bbt_ruler_scale = bbt_show_ticks;
1261 bbt_ruler_scale = bbt_show_ticks_detail;
1264 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)) {
1265 bbt_ruler_scale = bbt_show_ticks_super_detail;
1270 Editor::metric_get_bbt (GtkCustomRulerMark **marks, gdouble lower, gdouble /*upper*/, gint /*maxchars*/)
1272 if (_session == 0) {
1276 TempoMap::BBTPointList::iterator i;
1281 Timecode::BBT_Time next_beat;
1282 framepos_t next_beat_pos;
1288 framepos_t frame_skip;
1289 double frame_skip_error;
1290 double bbt_position_of_helper;
1291 double accumulated_error;
1292 bool i_am_accented = false;
1293 bool helper_active = false;
1295 if (current_bbt_points == 0 || current_bbt_points->empty()) {
1299 switch (bbt_ruler_scale) {
1301 case bbt_show_beats:
1302 beats = current_bbt_points->size();
1303 bbt_nmarks = beats + 2;
1305 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1307 (*marks)[0].label = g_strdup(" ");
1308 (*marks)[0].position = lower;
1309 (*marks)[0].style = GtkCustomRulerMarkMicro;
1311 for (n = 1, i = current_bbt_points->begin(); n < bbt_nmarks && i != current_bbt_points->end(); ++i) {
1312 if ((*i).type != TempoMap::Beat) {
1315 if ((*i).frame < lower && (bbt_bar_helper_on)) {
1316 snprintf (buf, sizeof(buf), "<%" PRIu32 "|%" PRIu32, (*i).bar, (*i).beat);
1317 (*marks)[0].label = g_strdup (buf);
1318 helper_active = true;
1321 if ((*i).beat == 1) {
1322 (*marks)[n].style = GtkCustomRulerMarkMajor;
1323 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1324 } else if (((*i).beat % 2 == 1)) {
1325 (*marks)[n].style = GtkCustomRulerMarkMinor;
1326 snprintf (buf, sizeof(buf), " ");
1328 (*marks)[n].style = GtkCustomRulerMarkMicro;
1329 snprintf (buf, sizeof(buf), " ");
1331 (*marks)[n].label = g_strdup (buf);
1332 (*marks)[n].position = (*i).frame;
1338 case bbt_show_ticks:
1340 beats = current_bbt_points->size();
1341 bbt_nmarks = (beats + 2) * bbt_beat_subdivision;
1343 bbt_position_of_helper = lower + (30 * Editor::get_current_zoom ());
1344 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1346 (*marks)[0].label = g_strdup(" ");
1347 (*marks)[0].position = lower;
1348 (*marks)[0].style = GtkCustomRulerMarkMicro;
1350 for (n = 1, i = current_bbt_points->begin(); n < bbt_nmarks && i != current_bbt_points->end(); ++i) {
1351 if ((*i).type != TempoMap::Beat) {
1354 if ((*i).frame < lower && (bbt_bar_helper_on)) {
1355 snprintf (buf, sizeof(buf), "<%" PRIu32 "|%" PRIu32, (*i).bar, (*i).beat);
1356 (*marks)[0].label = g_strdup (buf);
1357 helper_active = true;
1360 if ((*i).beat == 1) {
1361 (*marks)[n].style = GtkCustomRulerMarkMajor;
1362 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1364 (*marks)[n].style = GtkCustomRulerMarkMinor;
1365 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).beat);
1367 if (((*i).frame < bbt_position_of_helper) && helper_active) {
1368 snprintf (buf, sizeof(buf), " ");
1370 (*marks)[n].label = g_strdup (buf);
1371 (*marks)[n].position = (*i).frame;
1375 /* Add the tick marks */
1377 /* Find the next beat */
1378 next_beat.beats = (*i).beat;
1379 next_beat.bars = (*i).bar;
1380 next_beat.ticks = 0;
1382 if ((*i).meter->beats_per_bar() > (next_beat.beats + 1)) {
1383 next_beat.beats += 1;
1385 next_beat.bars += 1;
1386 next_beat.beats = 1;
1389 next_beat_pos = _session->tempo_map().frame_time(next_beat);
1391 frame_skip = (framepos_t) floor (frame_skip_error = (_session->frame_rate() * 60) / (bbt_beat_subdivision * (*i).tempo->beats_per_minute()));
1392 frame_skip_error -= frame_skip;
1393 skip = (uint32_t) (Timecode::BBT_Time::ticks_per_beat / bbt_beat_subdivision);
1395 pos = (*i).frame + frame_skip;
1396 accumulated_error = frame_skip_error;
1400 for (t = 0; (tick < Timecode::BBT_Time::ticks_per_beat) && (n < bbt_nmarks) && (pos < next_beat_pos) ; pos += frame_skip, tick += skip, ++t) {
1402 if (t % bbt_accent_modulo == (bbt_accent_modulo - 1)) {
1403 i_am_accented = true;
1406 snprintf (buf, sizeof(buf), " ");
1407 (*marks)[n].label = g_strdup (buf);
1409 /* Error compensation for float to framepos_t*/
1410 accumulated_error += frame_skip_error;
1411 if (accumulated_error > 1) {
1413 accumulated_error -= 1.0f;
1416 (*marks)[n].position = pos;
1418 if ((bbt_beat_subdivision > 4) && i_am_accented) {
1419 (*marks)[n].style = GtkCustomRulerMarkMinor;
1421 (*marks)[n].style = GtkCustomRulerMarkMicro;
1423 i_am_accented = false;
1430 case bbt_show_ticks_detail:
1432 beats = current_bbt_points->size();
1433 bbt_nmarks = (beats + 2) * bbt_beat_subdivision;
1435 bbt_position_of_helper = lower + (30 * Editor::get_current_zoom ());
1436 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1438 (*marks)[0].label = g_strdup(" ");
1439 (*marks)[0].position = lower;
1440 (*marks)[0].style = GtkCustomRulerMarkMicro;
1442 for (n = 1, i = current_bbt_points->begin(); n < bbt_nmarks && i != current_bbt_points->end(); ++i) {
1443 if ((*i).type != TempoMap::Beat) {
1446 if ((*i).frame < lower && (bbt_bar_helper_on)) {
1447 snprintf (buf, sizeof(buf), "<%" PRIu32 "|%" PRIu32, (*i).bar, (*i).beat);
1448 (*marks)[0].label = g_strdup (buf);
1449 helper_active = true;
1452 if ((*i).beat == 1) {
1453 (*marks)[n].style = GtkCustomRulerMarkMajor;
1454 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1456 (*marks)[n].style = GtkCustomRulerMarkMinor;
1457 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).beat);
1459 if (((*i).frame < bbt_position_of_helper) && helper_active) {
1460 snprintf (buf, sizeof(buf), " ");
1462 (*marks)[n].label = g_strdup (buf);
1463 (*marks)[n].position = (*i).frame;
1467 /* Add the tick marks */
1469 /* Find the next beat */
1471 next_beat.beats = (*i).beat;
1472 next_beat.bars = (*i).bar;
1474 if ((*i).meter->beats_per_bar() > (next_beat.beats + 1)) {
1475 next_beat.beats += 1;
1477 next_beat.bars += 1;
1478 next_beat.beats = 1;
1481 next_beat_pos = _session->tempo_map().frame_time(next_beat);
1483 frame_skip = (framepos_t) floor (frame_skip_error = (_session->frame_rate() * 60) / (bbt_beat_subdivision * (*i).tempo->beats_per_minute()));
1484 frame_skip_error -= frame_skip;
1485 skip = (uint32_t) (Timecode::BBT_Time::ticks_per_beat / bbt_beat_subdivision);
1487 pos = (*i).frame + frame_skip;
1488 accumulated_error = frame_skip_error;
1492 for (t = 0; (tick < Timecode::BBT_Time::ticks_per_beat) && (n < bbt_nmarks) && (pos < next_beat_pos) ; pos += frame_skip, tick += skip, ++t) {
1494 if (t % bbt_accent_modulo == (bbt_accent_modulo - 1)) {
1495 i_am_accented = true;
1498 if (i_am_accented && (pos > bbt_position_of_helper)){
1499 snprintf (buf, sizeof(buf), "%" PRIu32, tick);
1501 snprintf (buf, sizeof(buf), " ");
1504 (*marks)[n].label = g_strdup (buf);
1506 /* Error compensation for float to framepos_t*/
1507 accumulated_error += frame_skip_error;
1508 if (accumulated_error > 1) {
1510 accumulated_error -= 1.0f;
1513 (*marks)[n].position = pos;
1515 if ((bbt_beat_subdivision > 4) && i_am_accented) {
1516 (*marks)[n].style = GtkCustomRulerMarkMinor;
1518 (*marks)[n].style = GtkCustomRulerMarkMicro;
1520 i_am_accented = false;
1527 case bbt_show_ticks_super_detail:
1529 beats = current_bbt_points->size();
1530 bbt_nmarks = (beats + 2) * bbt_beat_subdivision;
1532 bbt_position_of_helper = lower + (30 * Editor::get_current_zoom ());
1533 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1535 (*marks)[0].label = g_strdup(" ");
1536 (*marks)[0].position = lower;
1537 (*marks)[0].style = GtkCustomRulerMarkMicro;
1539 for (n = 1, i = current_bbt_points->begin(); n < bbt_nmarks && i != current_bbt_points->end(); ++i) {
1540 if ((*i).type != TempoMap::Beat) {
1543 if ((*i).frame < lower && (bbt_bar_helper_on)) {
1544 snprintf (buf, sizeof(buf), "<%" PRIu32 "|%" PRIu32, (*i).bar, (*i).beat);
1545 (*marks)[0].label = g_strdup (buf);
1546 helper_active = true;
1549 if ((*i).beat == 1) {
1550 (*marks)[n].style = GtkCustomRulerMarkMajor;
1551 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1553 (*marks)[n].style = GtkCustomRulerMarkMinor;
1554 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).beat);
1556 if (((*i).frame < bbt_position_of_helper) && helper_active) {
1557 snprintf (buf, sizeof(buf), " ");
1559 (*marks)[n].label = g_strdup (buf);
1560 (*marks)[n].position = (*i).frame;
1564 /* Add the tick marks */
1566 /* Find the next beat */
1568 next_beat.beats = (*i).beat;
1569 next_beat.bars = (*i).bar;
1571 if ((*i).meter->beats_per_bar() > (next_beat.beats + 1)) {
1572 next_beat.beats += 1;
1574 next_beat.bars += 1;
1575 next_beat.beats = 1;
1578 next_beat_pos = _session->tempo_map().frame_time(next_beat);
1580 frame_skip = (framepos_t) floor (frame_skip_error = (_session->frame_rate() * 60) / (bbt_beat_subdivision * (*i).tempo->beats_per_minute()));
1581 frame_skip_error -= frame_skip;
1582 skip = (uint32_t) (Timecode::BBT_Time::ticks_per_beat / bbt_beat_subdivision);
1584 pos = (*i).frame + frame_skip;
1585 accumulated_error = frame_skip_error;
1589 for (t = 0; (tick < Timecode::BBT_Time::ticks_per_beat) && (n < bbt_nmarks) && (pos < next_beat_pos) ; pos += frame_skip, tick += skip, ++t) {
1591 if (t % bbt_accent_modulo == (bbt_accent_modulo - 1)) {
1592 i_am_accented = true;
1595 if (pos > bbt_position_of_helper) {
1596 snprintf (buf, sizeof(buf), "%" PRIu32, tick);
1598 snprintf (buf, sizeof(buf), " ");
1601 (*marks)[n].label = g_strdup (buf);
1603 /* Error compensation for float to framepos_t*/
1604 accumulated_error += frame_skip_error;
1605 if (accumulated_error > 1) {
1607 accumulated_error -= 1.0f;
1610 (*marks)[n].position = pos;
1612 if ((bbt_beat_subdivision > 4) && i_am_accented) {
1613 (*marks)[n].style = GtkCustomRulerMarkMinor;
1615 (*marks)[n].style = GtkCustomRulerMarkMicro;
1617 i_am_accented = false;
1626 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1627 snprintf (buf, sizeof(buf), "cannot handle %" PRIu32 " bars", bbt_bars );
1628 (*marks)[0].style = GtkCustomRulerMarkMajor;
1629 (*marks)[0].label = g_strdup (buf);
1630 (*marks)[0].position = lower;
1636 bbt_nmarks = (gint) (bbt_bars / 64) + 1;
1637 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1638 for (n = 0, i = current_bbt_points->begin(); i != current_bbt_points->end() && n < bbt_nmarks; i++) {
1639 if ((*i).type == TempoMap::Bar) {
1640 if ((*i).bar % 64 == 1) {
1641 if ((*i).bar % 256 == 1) {
1642 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1643 (*marks)[n].style = GtkCustomRulerMarkMajor;
1645 snprintf (buf, sizeof(buf), " ");
1646 if ((*i).bar % 256 == 129) {
1647 (*marks)[n].style = GtkCustomRulerMarkMinor;
1649 (*marks)[n].style = GtkCustomRulerMarkMicro;
1652 (*marks)[n].label = g_strdup (buf);
1653 (*marks)[n].position = (*i).frame;
1661 bbt_nmarks = (bbt_bars / 16) + 1;
1662 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1663 for (n = 0, i = current_bbt_points->begin(); i != current_bbt_points->end() && n < bbt_nmarks; i++) {
1664 if ((*i).type == TempoMap::Bar) {
1665 if ((*i).bar % 16 == 1) {
1666 if ((*i).bar % 64 == 1) {
1667 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1668 (*marks)[n].style = GtkCustomRulerMarkMajor;
1670 snprintf (buf, sizeof(buf), " ");
1671 if ((*i).bar % 64 == 33) {
1672 (*marks)[n].style = GtkCustomRulerMarkMinor;
1674 (*marks)[n].style = GtkCustomRulerMarkMicro;
1677 (*marks)[n].label = g_strdup (buf);
1678 (*marks)[n].position = (*i).frame;
1686 bbt_nmarks = (bbt_bars / 4) + 1;
1687 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1688 for (n = 0, i = current_bbt_points->begin(); i != current_bbt_points->end() && n < bbt_nmarks; ++i) {
1689 if ((*i).type == TempoMap::Bar) {
1690 if ((*i).bar % 4 == 1) {
1691 if ((*i).bar % 16 == 1) {
1692 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1693 (*marks)[n].style = GtkCustomRulerMarkMajor;
1695 snprintf (buf, sizeof(buf), " ");
1696 if ((*i).bar % 16 == 9) {
1697 (*marks)[n].style = GtkCustomRulerMarkMinor;
1699 (*marks)[n].style = GtkCustomRulerMarkMicro;
1702 (*marks)[n].label = g_strdup (buf);
1703 (*marks)[n].position = (*i).frame;
1712 bbt_nmarks = bbt_bars + 2;
1713 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks );
1714 for (n = 0, i = current_bbt_points->begin(); i != current_bbt_points->end() && n < bbt_nmarks; i++) {
1715 if ((*i).type == TempoMap::Bar) {
1716 if ((*i).bar % 4 == 1) {
1717 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1718 (*marks)[n].style = GtkCustomRulerMarkMajor;
1720 snprintf (buf, sizeof(buf), " ");
1721 if ((*i).bar % 4 == 3) {
1722 (*marks)[n].style = GtkCustomRulerMarkMinor;
1724 (*marks)[n].style = GtkCustomRulerMarkMicro;
1727 (*marks)[n].label = g_strdup (buf);
1728 (*marks)[n].position = (*i).frame;
1737 return n; //return the actual number of marks made, since we might have skipped some from fractional time signatures
1742 Editor::metric_get_frames (GtkCustomRulerMark **marks, gdouble lower, gdouble upper, gint /*maxchars*/)
1744 framepos_t mark_interval;
1746 framepos_t ilower = (framepos_t) floor (lower);
1747 framepos_t iupper = (framepos_t) floor (upper);
1752 if (_session == 0) {
1756 mark_interval = (iupper - ilower) / 5;
1757 if (mark_interval > _session->frame_rate()) {
1758 mark_interval -= mark_interval % _session->frame_rate();
1760 mark_interval = _session->frame_rate() / (_session->frame_rate() / mark_interval ) ;
1763 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * nmarks);
1764 for (n = 0, pos = ilower; n < nmarks; pos += mark_interval, ++n) {
1765 snprintf (buf, sizeof(buf), "%" PRIi64, pos);
1766 (*marks)[n].label = g_strdup (buf);
1767 (*marks)[n].position = pos;
1768 (*marks)[n].style = GtkCustomRulerMarkMajor;
1775 sample_to_clock_parts ( framepos_t sample,
1776 framepos_t sample_rate,
1790 hrs = left / (sample_rate * 60 * 60);
1791 left -= hrs * sample_rate * 60 * 60;
1792 mins = left / (sample_rate * 60);
1793 left -= mins * sample_rate * 60;
1794 secs = left / sample_rate;
1795 left -= secs * sample_rate;
1796 millisecs = left * 1000 / sample_rate;
1798 *millisecs_p = millisecs;
1807 Editor::set_minsec_ruler_scale (gdouble lower, gdouble 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 range = (framepos_t) (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;