fix math bug with numthreads computation
[ardour2.git] / gtk2_ardour / editor_rulers.cc
blob873e4919583a893962a43ce9bc46892d16eac154
1 /*
2 Copyright (C) 2000 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #define __STDC_FORMAT_MACROS 1
21 #include <cstdio> // for sprintf, grrr
22 #include <cmath>
23 #include <inttypes.h>
25 #include <string>
27 #include <gtk/gtkaction.h>
29 #include "ardour/session.h"
30 #include "ardour/tempo.h"
31 #include "ardour/profile.h"
32 #include <gtkmm2ext/gtk_ui.h>
34 #include "editor.h"
35 #include "editing.h"
36 #include "actions.h"
37 #include "gtk-custom-hruler.h"
38 #include "gui_thread.h"
39 #include "time_axis_view.h"
40 #include "editor_drag.h"
42 #include "i18n.h"
44 using namespace ARDOUR;
45 using namespace PBD;
46 using namespace Gtk;
47 using namespace Editing;
49 Editor *Editor::ruler_editor;
51 /* the order here must match the "metric" enums in editor.h */
53 GtkCustomMetric Editor::ruler_metrics[4] = {
54 {1, Editor::_metric_get_timecode },
55 {1, Editor::_metric_get_bbt },
56 {1, Editor::_metric_get_frames },
57 {1, Editor::_metric_get_minsec }
60 void
61 Editor::initialize_rulers ()
63 ruler_editor = this;
64 ruler_grabbed_widget = 0;
66 _ruler_separator = new Gtk::HSeparator();
67 _ruler_separator->set_size_request(-1, 2);
68 _ruler_separator->set_name("TimebarPadding");
69 _ruler_separator->show();
71 _minsec_ruler = gtk_custom_hruler_new ();
72 minsec_ruler = Glib::wrap (_minsec_ruler);
73 minsec_ruler->set_name ("MinSecRuler");
74 minsec_ruler->set_size_request (-1, (int)timebar_height);
75 gtk_custom_ruler_set_metric (GTK_CUSTOM_RULER(_minsec_ruler), &ruler_metrics[ruler_metric_minsec]);
76 minsec_ruler->hide ();
77 minsec_ruler->set_no_show_all();
79 _timecode_ruler = gtk_custom_hruler_new ();
80 timecode_ruler = Glib::wrap (_timecode_ruler);
81 timecode_ruler->set_name ("TimecodeRuler");
82 timecode_ruler->set_size_request (-1, (int)timebar_height);
83 gtk_custom_ruler_set_metric (GTK_CUSTOM_RULER(_timecode_ruler), &ruler_metrics[ruler_metric_timecode]);
84 timecode_ruler->hide ();
85 timecode_ruler->set_no_show_all();
86 timecode_nmarks = 0;
88 _bbt_ruler = gtk_custom_hruler_new ();
89 bbt_ruler = Glib::wrap (_bbt_ruler);
90 bbt_ruler->set_name ("BBTRuler");
91 bbt_ruler->set_size_request (-1, (int)timebar_height);
92 gtk_custom_ruler_set_metric (GTK_CUSTOM_RULER(_bbt_ruler), &ruler_metrics[ruler_metric_bbt]);
93 bbt_ruler->hide ();
94 bbt_ruler->set_no_show_all();
95 bbt_nmarks = 0;
97 _frames_ruler = gtk_custom_hruler_new ();
98 frames_ruler = Glib::wrap (_frames_ruler);
99 frames_ruler->set_name ("FramesRuler");
100 frames_ruler->set_size_request (-1, (int)timebar_height);
101 gtk_custom_ruler_set_metric (GTK_CUSTOM_RULER(_frames_ruler), &ruler_metrics[ruler_metric_frames]);
102 frames_ruler->hide ();
103 frames_ruler->set_no_show_all();
105 _bbt_ruler = gtk_custom_hruler_new ();
106 bbt_ruler = Glib::wrap (_bbt_ruler);
107 bbt_ruler->set_name ("BBTRuler");
108 bbt_ruler->set_size_request (-1, (int)timebar_height);
109 gtk_custom_ruler_set_metric (GTK_CUSTOM_RULER(_bbt_ruler), &ruler_metrics[ruler_metric_bbt]);
110 bbt_ruler->hide ();
111 bbt_ruler->set_no_show_all();
112 minsec_ruler->hide ();
113 minsec_ruler->set_no_show_all();
114 minsec_nmarks = 0;
116 using namespace Box_Helpers;
117 BoxList & ruler_lab_children = ruler_label_vbox.children();
118 BoxList & ruler_children = time_canvas_vbox.children();
119 BoxList & lab_children = time_button_vbox.children();
121 BoxList::iterator canvaspos = ruler_children.begin();
123 lab_children.push_back (Element(meter_label, PACK_SHRINK, PACK_START));
124 lab_children.push_back (Element(tempo_label, PACK_SHRINK, PACK_START));
125 lab_children.push_back (Element(range_mark_label, PACK_SHRINK, PACK_START));
126 lab_children.push_back (Element(transport_mark_label, PACK_SHRINK, PACK_START));
127 lab_children.push_back (Element(cd_mark_label, PACK_SHRINK, PACK_START));
128 lab_children.push_back (Element(mark_label, PACK_SHRINK, PACK_START));
130 ruler_lab_children.push_back (Element(minsec_label, PACK_SHRINK, PACK_START));
131 ruler_children.insert (canvaspos, Element(*minsec_ruler, PACK_SHRINK, PACK_START));
132 ruler_lab_children.push_back (Element(timecode_label, PACK_SHRINK, PACK_START));
133 ruler_children.insert (canvaspos, Element(*timecode_ruler, PACK_SHRINK, PACK_START));
134 ruler_lab_children.push_back (Element(frame_label, PACK_SHRINK, PACK_START));
135 ruler_children.insert (canvaspos, Element(*frames_ruler, PACK_SHRINK, PACK_START));
136 ruler_lab_children.push_back (Element(bbt_label, PACK_SHRINK, PACK_START));
137 ruler_children.insert (canvaspos, Element(*bbt_ruler, PACK_SHRINK, PACK_START));
139 timecode_ruler->add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::SCROLL_MASK);
140 bbt_ruler->add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::SCROLL_MASK);
141 frames_ruler->add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::SCROLL_MASK);
142 minsec_ruler->add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::SCROLL_MASK);
144 timecode_ruler->signal_button_release_event().connect (sigc::mem_fun(*this, &Editor::ruler_button_release));
145 bbt_ruler->signal_button_release_event().connect (sigc::mem_fun(*this, &Editor::ruler_button_release));
146 frames_ruler->signal_button_release_event().connect (sigc::mem_fun(*this, &Editor::ruler_button_release));
147 minsec_ruler->signal_button_release_event().connect (sigc::mem_fun(*this, &Editor::ruler_button_release));
149 timecode_ruler->signal_button_press_event().connect (sigc::mem_fun(*this, &Editor::ruler_button_press));
150 bbt_ruler->signal_button_press_event().connect (sigc::mem_fun(*this, &Editor::ruler_button_press));
151 frames_ruler->signal_button_press_event().connect (sigc::mem_fun(*this, &Editor::ruler_button_press));
152 minsec_ruler->signal_button_press_event().connect (sigc::mem_fun(*this, &Editor::ruler_button_press));
154 timecode_ruler->signal_motion_notify_event().connect (sigc::mem_fun(*this, &Editor::ruler_mouse_motion));
155 bbt_ruler->signal_motion_notify_event().connect (sigc::mem_fun(*this, &Editor::ruler_mouse_motion));
156 frames_ruler->signal_motion_notify_event().connect (sigc::mem_fun(*this, &Editor::ruler_mouse_motion));
157 minsec_ruler->signal_motion_notify_event().connect (sigc::mem_fun(*this, &Editor::ruler_mouse_motion));
159 timecode_ruler->signal_scroll_event().connect (sigc::mem_fun(*this, &Editor::ruler_scroll));
160 bbt_ruler->signal_scroll_event().connect (sigc::mem_fun(*this, &Editor::ruler_scroll));
161 frames_ruler->signal_scroll_event().connect (sigc::mem_fun(*this, &Editor::ruler_scroll));
162 minsec_ruler->signal_scroll_event().connect (sigc::mem_fun(*this, &Editor::ruler_scroll));
164 visible_timebars = 0; /*this will be changed below */
165 canvas_timebars_vsize = 0;
168 bool
169 Editor::ruler_scroll (GdkEventScroll* event)
171 nframes64_t xdelta;
172 int direction = event->direction;
173 bool handled = false;
175 switch (direction) {
176 case GDK_SCROLL_UP:
177 temporal_zoom_step (true);
178 handled = true;
179 break;
181 case GDK_SCROLL_DOWN:
182 temporal_zoom_step (false);
183 handled = true;
184 break;
186 case GDK_SCROLL_LEFT:
187 xdelta = (current_page_frames() / 2);
188 if (leftmost_frame > xdelta) {
189 reset_x_origin (leftmost_frame - xdelta);
190 } else {
191 reset_x_origin (0);
193 handled = true;
194 break;
196 case GDK_SCROLL_RIGHT:
197 xdelta = (current_page_frames() / 2);
198 if (max_frames - xdelta > leftmost_frame) {
199 reset_x_origin (leftmost_frame + xdelta);
200 } else {
201 reset_x_origin (max_frames - current_page_frames());
203 handled = true;
204 break;
206 default:
207 /* what? */
208 break;
211 return handled;
215 gint
216 Editor::ruler_button_press (GdkEventButton* ev)
218 if (_session == 0) {
219 return FALSE;
222 // jlc: grab ev->window ?
223 //Gtk::Main::grab_add (*minsec_ruler);
224 Widget * grab_widget = 0;
226 if (timecode_ruler->is_realized() && ev->window == timecode_ruler->get_window()->gobj()) {
227 grab_widget = timecode_ruler;
228 } else if (bbt_ruler->is_realized() && ev->window == bbt_ruler->get_window()->gobj()) {
229 grab_widget = bbt_ruler;
230 } else if (frames_ruler->is_realized() && ev->window == frames_ruler->get_window()->gobj()) {
231 grab_widget = frames_ruler;
232 } else if (minsec_ruler->is_realized() && ev->window == minsec_ruler->get_window()->gobj()) {
233 grab_widget = minsec_ruler;
236 if (grab_widget) {
237 grab_widget->add_modal_grab ();
238 ruler_grabbed_widget = grab_widget;
241 if (ev->button == 1) {
242 // Since we will locate the playhead on button release, cancel any running
243 // auditions.
244 if (_session->is_auditioning()) {
245 _session->cancel_audition ();
248 /* playhead cursor */
249 _drags->set (new CursorDrag (this, &playhead_cursor->canvas_item, false), reinterpret_cast<GdkEvent *> (ev));
250 _dragging_playhead = true;
253 return TRUE;
256 gint
257 Editor::ruler_button_release (GdkEventButton* ev)
259 if (_session == 0) {
260 return FALSE;
263 gint x,y;
264 Gdk::ModifierType state;
266 if (_drags->active ()) {
267 _drags->end_grab (reinterpret_cast<GdkEvent*> (ev));
268 _dragging_playhead = false;
271 if (ev->button == 3) {
272 /* need to use the correct x,y, the event lies */
273 time_canvas_event_box.get_window()->get_pointer (x, y, state);
275 stop_canvas_autoscroll();
277 nframes64_t where = leftmost_frame + pixel_to_frame (x);
278 snap_to (where);
279 popup_ruler_menu (where);
282 if (ruler_grabbed_widget) {
283 ruler_grabbed_widget->remove_modal_grab();
284 ruler_grabbed_widget = 0;
287 return TRUE;
290 gint
291 Editor::ruler_label_button_release (GdkEventButton* ev)
293 if (ev->button == 3) {
294 Gtk::Menu* m= dynamic_cast<Gtk::Menu*> (ActionManager::get_widget (X_("/RulerMenuPopup")));
295 if (m) {
296 m->popup (1, ev->time);
300 return TRUE;
304 gint
305 Editor::ruler_mouse_motion (GdkEventMotion* ev)
307 if (_session == 0) {
308 return FALSE;
311 if (_drags->active ()) {
312 _drags->motion_handler (reinterpret_cast<GdkEvent*> (ev), false);
315 return TRUE;
319 void
320 Editor::popup_ruler_menu (nframes64_t where, ItemType t)
322 using namespace Menu_Helpers;
324 if (editor_ruler_menu == 0) {
325 editor_ruler_menu = new Menu;
326 editor_ruler_menu->set_name ("ArdourContextMenu");
329 // always build from scratch
330 MenuList& ruler_items = editor_ruler_menu->items();
331 editor_ruler_menu->set_name ("ArdourContextMenu");
332 ruler_items.clear();
334 switch (t) {
335 case MarkerBarItem:
336 ruler_items.push_back (MenuElem (_("New location marker"), sigc::bind ( sigc::mem_fun(*this, &Editor::mouse_add_new_marker), where, false, false)));
337 ruler_items.push_back (MenuElem (_("Clear all locations"), sigc::mem_fun(*this, &Editor::clear_markers)));
338 ruler_items.push_back (MenuElem (_("Unhide locations"), sigc::mem_fun(*this, &Editor::unhide_markers)));
339 ruler_items.push_back (SeparatorElem ());
340 break;
341 case RangeMarkerBarItem:
342 //ruler_items.push_back (MenuElem (_("New Range")));
343 ruler_items.push_back (MenuElem (_("Clear all ranges"), sigc::mem_fun(*this, &Editor::clear_ranges)));
344 ruler_items.push_back (MenuElem (_("Unhide ranges"), sigc::mem_fun(*this, &Editor::unhide_ranges)));
345 ruler_items.push_back (SeparatorElem ());
347 break;
348 case TransportMarkerBarItem:
350 break;
352 case CdMarkerBarItem:
353 // TODO
354 ruler_items.push_back (MenuElem (_("New CD track marker"), sigc::bind ( sigc::mem_fun(*this, &Editor::mouse_add_new_marker), where, true, false)));
355 break;
358 case TempoBarItem:
359 ruler_items.push_back (MenuElem (_("New Tempo"), sigc::bind ( sigc::mem_fun(*this, &Editor::mouse_add_new_tempo_event), where)));
360 ruler_items.push_back (MenuElem (_("Clear tempo")));
361 ruler_items.push_back (SeparatorElem ());
362 break;
364 case MeterBarItem:
365 ruler_items.push_back (MenuElem (_("New Meter"), sigc::bind ( sigc::mem_fun(*this, &Editor::mouse_add_new_meter_event), where)));
366 ruler_items.push_back (MenuElem (_("Clear meter")));
367 ruler_items.push_back (SeparatorElem ());
368 break;
370 default:
371 break;
374 Glib::RefPtr<Action> action;
376 action = ActionManager::get_action ("Rulers", "toggle-minsec-ruler");
377 if (action) {
378 ruler_items.push_back (MenuElem (*action->create_menu_item()));
380 if (!Profile->get_sae()) {
381 action = ActionManager::get_action ("Rulers", "toggle-timecode-ruler");
382 if (action) {
383 ruler_items.push_back (MenuElem (*action->create_menu_item()));
386 action = ActionManager::get_action ("Rulers", "toggle-samples-ruler");
387 if (action) {
388 ruler_items.push_back (MenuElem (*action->create_menu_item()));
390 action = ActionManager::get_action ("Rulers", "toggle-bbt-ruler");
391 if (action) {
392 ruler_items.push_back (MenuElem (*action->create_menu_item()));
394 action = ActionManager::get_action ("Rulers", "toggle-meter-ruler");
395 if (action) {
396 ruler_items.push_back (MenuElem (*action->create_menu_item()));
398 action = ActionManager::get_action ("Rulers", "toggle-tempo-ruler");
399 if (action) {
400 ruler_items.push_back (MenuElem (*action->create_menu_item()));
402 if (!Profile->get_sae()) {
403 action = ActionManager::get_action ("Rulers", "toggle-range-ruler");
404 if (action) {
405 ruler_items.push_back (MenuElem (*action->create_menu_item()));
408 action = ActionManager::get_action ("Rulers", "toggle-loop-punch-ruler");
409 if (action) {
410 ruler_items.push_back (MenuElem (*action->create_menu_item()));
412 action = ActionManager::get_action ("Rulers", "toggle-cd-marker-ruler");
413 if (action) {
414 ruler_items.push_back (MenuElem (*action->create_menu_item()));
416 action = ActionManager::get_action ("Rulers", "toggle-marker-ruler");
417 if (action) {
418 ruler_items.push_back (MenuElem (*action->create_menu_item()));
421 editor_ruler_menu->popup (1, gtk_get_current_event_time());
423 no_ruler_shown_update = false;
426 void
427 Editor::store_ruler_visibility ()
429 XMLNode* node = new XMLNode(X_("RulerVisibility"));
431 node->add_property (X_("timecode"), ruler_timecode_action->get_active() ? "yes": "no");
432 node->add_property (X_("bbt"), ruler_bbt_action->get_active() ? "yes": "no");
433 node->add_property (X_("frames"), ruler_samples_action->get_active() ? "yes": "no");
434 node->add_property (X_("minsec"), ruler_minsec_action->get_active() ? "yes": "no");
435 node->add_property (X_("tempo"), ruler_tempo_action->get_active() ? "yes": "no");
436 node->add_property (X_("meter"), ruler_meter_action->get_active() ? "yes": "no");
437 node->add_property (X_("marker"), ruler_marker_action->get_active() ? "yes": "no");
438 node->add_property (X_("rangemarker"), ruler_range_action->get_active() ? "yes": "no");
439 node->add_property (X_("transportmarker"), ruler_loop_punch_action->get_active() ? "yes": "no");
440 node->add_property (X_("cdmarker"), ruler_cd_marker_action->get_active() ? "yes": "no");
442 _session->add_extra_xml (*node);
443 _session->set_dirty ();
446 void
447 Editor::restore_ruler_visibility ()
449 XMLProperty* prop;
450 XMLNode * node = _session->extra_xml (X_("RulerVisibility"));
452 no_ruler_shown_update = true;
454 if (node) {
455 if ((prop = node->property ("timecode")) != 0) {
456 if (string_is_affirmative (prop->value())) {
457 ruler_timecode_action->set_active (true);
458 } else {
459 ruler_timecode_action->set_active (false);
462 if ((prop = node->property ("bbt")) != 0) {
463 if (string_is_affirmative (prop->value())) {
464 ruler_bbt_action->set_active (true);
465 } else {
466 ruler_bbt_action->set_active (false);
469 if ((prop = node->property ("frames")) != 0) {
470 if (string_is_affirmative (prop->value())) {
471 ruler_samples_action->set_active (true);
472 } else {
473 ruler_samples_action->set_active (false);
476 if ((prop = node->property ("minsec")) != 0) {
477 if (string_is_affirmative (prop->value())) {
478 ruler_minsec_action->set_active (true);
479 } else {
480 ruler_minsec_action->set_active (false);
483 if ((prop = node->property ("tempo")) != 0) {
484 if (string_is_affirmative (prop->value())) {
485 ruler_tempo_action->set_active (true);
486 } else {
487 ruler_tempo_action->set_active (false);
490 if ((prop = node->property ("meter")) != 0) {
491 if (string_is_affirmative (prop->value())) {
492 ruler_meter_action->set_active (true);
493 } else {
494 ruler_meter_action->set_active (false);
497 if ((prop = node->property ("marker")) != 0) {
498 if (string_is_affirmative (prop->value())) {
499 ruler_marker_action->set_active (true);
500 } else {
501 ruler_marker_action->set_active (false);
504 if ((prop = node->property ("rangemarker")) != 0) {
505 if (string_is_affirmative (prop->value())) {
506 ruler_range_action->set_active (true);
507 } else {
508 ruler_range_action->set_active (false);
512 if ((prop = node->property ("transportmarker")) != 0) {
513 if (string_is_affirmative (prop->value())) {
514 ruler_loop_punch_action->set_active (true);
515 } else {
516 ruler_loop_punch_action->set_active (false);
520 if ((prop = node->property ("cdmarker")) != 0) {
521 if (string_is_affirmative (prop->value())) {
522 ruler_cd_marker_action->set_active (true);
523 } else {
524 ruler_cd_marker_action->set_active (false);
527 } else {
528 // this _session doesn't yet know about the cdmarker ruler
529 // as a benefit to the user who doesn't know the feature exists, show the ruler if
530 // any cd marks exist
531 ruler_cd_marker_action->set_active (false);
532 const Locations::LocationList & locs = _session->locations()->list();
533 for (Locations::LocationList::const_iterator i = locs.begin(); i != locs.end(); ++i) {
534 if ((*i)->is_cd_marker()) {
535 ruler_cd_marker_action->set_active (true);
536 break;
543 no_ruler_shown_update = false;
544 update_ruler_visibility ();
547 void
548 Editor::update_ruler_visibility ()
550 int visible_rulers = 0;
552 if (no_ruler_shown_update) {
553 return;
556 visible_timebars = 0;
558 if (ruler_minsec_action->get_active()) {
559 visible_rulers++;
560 minsec_label.show ();
561 minsec_ruler->show ();
562 } else {
563 minsec_label.hide ();
564 minsec_ruler->hide ();
567 if (ruler_timecode_action->get_active()) {
568 visible_rulers++;
569 timecode_label.show ();
570 timecode_ruler->show ();
571 } else {
572 timecode_label.hide ();
573 timecode_ruler->hide ();
576 if (ruler_samples_action->get_active()) {
577 visible_rulers++;
578 frame_label.show ();
579 frames_ruler->show ();
580 } else {
581 frame_label.hide ();
582 frames_ruler->hide ();
585 if (ruler_bbt_action->get_active()) {
586 visible_rulers++;
587 bbt_label.show ();
588 bbt_ruler->show ();
589 } else {
590 bbt_label.hide ();
591 bbt_ruler->hide ();
594 double tbpos = 0.0;
595 double tbgpos = 0.0;
596 double old_unit_pos;
598 #ifdef GTKOSX
599 /* gtk update probs require this (damn) */
600 meter_label.hide();
601 tempo_label.hide();
602 range_mark_label.hide();
603 transport_mark_label.hide();
604 cd_mark_label.hide();
605 mark_label.hide();
606 #endif
607 if (ruler_meter_action->get_active()) {
608 old_unit_pos = meter_group->property_y();
609 if (tbpos != old_unit_pos) {
610 meter_group->move ( 0.0, tbpos - old_unit_pos);
612 old_unit_pos = meter_bar_group->property_y();
613 if (tbgpos != old_unit_pos) {
614 meter_bar_group->move ( 0.0, tbgpos - old_unit_pos);
616 meter_bar_group->show();
617 meter_group->show();
618 meter_label.show();
619 tbpos += timebar_height;
620 tbgpos += timebar_height;
621 visible_timebars++;
622 } else {
623 meter_bar_group->hide();
624 meter_group->hide();
625 meter_label.hide();
628 if (ruler_tempo_action->get_active()) {
629 old_unit_pos = tempo_group->property_y();
630 if (tbpos != old_unit_pos) {
631 tempo_group->move(0.0, tbpos - old_unit_pos);
633 old_unit_pos = tempo_bar_group->property_y();
634 if (tbgpos != old_unit_pos) {
635 tempo_bar_group->move ( 0.0, tbgpos - old_unit_pos);
637 tempo_bar_group->show();
638 tempo_group->show();
639 tempo_label.show();
640 tbpos += timebar_height;
641 tbgpos += timebar_height;
642 visible_timebars++;
643 } else {
644 tempo_bar_group->hide();
645 tempo_group->hide();
646 tempo_label.hide();
649 if (!Profile->get_sae() && ruler_range_action->get_active()) {
650 old_unit_pos = range_marker_group->property_y();
651 if (tbpos != old_unit_pos) {
652 range_marker_group->move (0.0, tbpos - old_unit_pos);
654 old_unit_pos = range_marker_bar_group->property_y();
655 if (tbgpos != old_unit_pos) {
656 range_marker_bar_group->move (0.0, tbgpos - old_unit_pos);
658 range_marker_bar_group->show();
659 range_marker_group->show();
660 range_mark_label.show();
662 tbpos += timebar_height;
663 tbgpos += timebar_height;
664 visible_timebars++;
665 } else {
666 range_marker_bar_group->hide();
667 range_marker_group->hide();
668 range_mark_label.hide();
671 if (ruler_loop_punch_action->get_active()) {
672 old_unit_pos = transport_marker_group->property_y();
673 if (tbpos != old_unit_pos) {
674 transport_marker_group->move ( 0.0, tbpos - old_unit_pos);
676 old_unit_pos = transport_marker_bar_group->property_y();
677 if (tbgpos != old_unit_pos) {
678 transport_marker_bar_group->move ( 0.0, tbgpos - old_unit_pos);
680 transport_marker_bar_group->show();
681 transport_marker_group->show();
682 transport_mark_label.show();
683 tbpos += timebar_height;
684 tbgpos += timebar_height;
685 visible_timebars++;
686 } else {
687 transport_marker_bar_group->hide();
688 transport_marker_group->hide();
689 transport_mark_label.hide();
692 if (ruler_cd_marker_action->get_active()) {
693 old_unit_pos = cd_marker_group->property_y();
694 if (tbpos != old_unit_pos) {
695 cd_marker_group->move (0.0, tbpos - old_unit_pos);
697 old_unit_pos = cd_marker_bar_group->property_y();
698 if (tbgpos != old_unit_pos) {
699 cd_marker_bar_group->move (0.0, tbgpos - old_unit_pos);
701 cd_marker_bar_group->show();
702 cd_marker_group->show();
703 cd_mark_label.show();
704 tbpos += timebar_height;
705 tbgpos += timebar_height;
706 visible_timebars++;
707 // make sure all cd markers show up in their respective places
708 update_cd_marker_display();
709 } else {
710 cd_marker_bar_group->hide();
711 cd_marker_group->hide();
712 cd_mark_label.hide();
713 // make sure all cd markers show up in their respective places
714 update_cd_marker_display();
717 if (ruler_marker_action->get_active()) {
718 old_unit_pos = marker_group->property_y();
719 if (tbpos != old_unit_pos) {
720 marker_group->move ( 0.0, tbpos - old_unit_pos);
722 old_unit_pos = marker_bar_group->property_y();
723 if (tbgpos != old_unit_pos) {
724 marker_bar_group->move ( 0.0, tbgpos - old_unit_pos);
726 marker_bar_group->show();
727 marker_group->show();
728 mark_label.show();
729 tbpos += timebar_height;
730 tbgpos += timebar_height;
731 visible_timebars++;
732 } else {
733 marker_bar_group->hide();
734 marker_group->hide();
735 mark_label.hide();
738 gdouble old_canvas_timebars_vsize = canvas_timebars_vsize;
739 canvas_timebars_vsize = (timebar_height * visible_timebars) - 1;
740 gdouble vertical_pos_delta = canvas_timebars_vsize - old_canvas_timebars_vsize;
741 vertical_adjustment.set_upper(vertical_adjustment.get_upper() + vertical_pos_delta);
742 full_canvas_height += vertical_pos_delta;
744 if (vertical_adjustment.get_value() != 0 && (vertical_adjustment.get_value() + _canvas_height >= full_canvas_height)) {
745 /*if we're at the bottom of the canvas, don't move the _trackview_group*/
746 vertical_adjustment.set_value (full_canvas_height - _canvas_height + 1);
747 } else {
748 _trackview_group->property_y () = - get_trackview_group_vertical_offset ();
749 _background_group->property_y () = - get_trackview_group_vertical_offset ();
750 _trackview_group->move (0, 0);
751 _background_group->move (0, 0);
752 last_trackview_group_vertical_offset = get_trackview_group_vertical_offset ();
755 gdouble bottom_track_pos = vertical_adjustment.get_value() + _canvas_height - canvas_timebars_vsize;
756 std::pair<TimeAxisView*, int> const p = trackview_by_y_position (bottom_track_pos);
757 if (p.first) {
758 p.first->clip_to_viewport ();
761 ruler_label_vbox.set_size_request (-1, (int)(timebar_height * visible_rulers));
762 time_canvas_vbox.set_size_request (-1,-1);
764 update_fixed_rulers();
765 redisplay_tempo (false);
768 void
769 Editor::update_just_timecode ()
771 ENSURE_GUI_THREAD (*this, &Editor::update_just_timecode)
773 if (_session == 0) {
774 return;
777 nframes64_t rightmost_frame = leftmost_frame + current_page_frames();
779 if (ruler_timecode_action->get_active()) {
780 gtk_custom_ruler_set_range (GTK_CUSTOM_RULER(_timecode_ruler), leftmost_frame, rightmost_frame,
781 leftmost_frame, _session->current_end_frame());
785 void
786 Editor::compute_fixed_ruler_scale ()
788 if (_session == 0) {
789 return;
792 if (ruler_timecode_action->get_active()) {
793 set_timecode_ruler_scale (leftmost_frame, leftmost_frame + current_page_frames() );
796 if (ruler_minsec_action->get_active()) {
797 set_minsec_ruler_scale (leftmost_frame, leftmost_frame + current_page_frames() );
801 void
802 Editor::update_fixed_rulers ()
804 nframes64_t rightmost_frame;
806 if (_session == 0) {
807 return;
810 ruler_metrics[ruler_metric_timecode].units_per_pixel = frames_per_unit;
811 ruler_metrics[ruler_metric_frames].units_per_pixel = frames_per_unit;
812 ruler_metrics[ruler_metric_minsec].units_per_pixel = frames_per_unit;
814 rightmost_frame = leftmost_frame + current_page_frames();
816 /* these force a redraw, which in turn will force execution of the metric callbacks
817 to compute the relevant ticks to display.
820 if (ruler_timecode_action->get_active()) {
821 gtk_custom_ruler_set_range (GTK_CUSTOM_RULER(_timecode_ruler), leftmost_frame, rightmost_frame,
822 leftmost_frame, _session->current_end_frame());
825 if (ruler_samples_action->get_active()) {
826 gtk_custom_ruler_set_range (GTK_CUSTOM_RULER(_frames_ruler), leftmost_frame, rightmost_frame,
827 leftmost_frame, _session->current_end_frame());
830 if (ruler_minsec_action->get_active()) {
831 gtk_custom_ruler_set_range (GTK_CUSTOM_RULER(_minsec_ruler), leftmost_frame, rightmost_frame,
832 leftmost_frame, _session->current_end_frame());
836 void
837 Editor::update_tempo_based_rulers ()
839 if (_session == 0) {
840 return;
843 ruler_metrics[ruler_metric_bbt].units_per_pixel = frames_per_unit;
845 if (ruler_bbt_action->get_active()) {
846 gtk_custom_ruler_set_range (GTK_CUSTOM_RULER(_bbt_ruler), leftmost_frame, leftmost_frame+current_page_frames(),
847 leftmost_frame, _session->current_end_frame());
851 /* Mark generation */
853 gint
854 Editor::_metric_get_timecode (GtkCustomRulerMark **marks, gdouble lower, gdouble upper, gint maxchars)
856 return ruler_editor->metric_get_timecode (marks, lower, upper, maxchars);
859 gint
860 Editor::_metric_get_bbt (GtkCustomRulerMark **marks, gdouble lower, gdouble upper, gint maxchars)
862 return ruler_editor->metric_get_bbt (marks, lower, upper, maxchars);
865 gint
866 Editor::_metric_get_frames (GtkCustomRulerMark **marks, gdouble lower, gdouble upper, gint maxchars)
868 return ruler_editor->metric_get_frames (marks, lower, upper, maxchars);
871 gint
872 Editor::_metric_get_minsec (GtkCustomRulerMark **marks, gdouble lower, gdouble upper, gint maxchars)
874 return ruler_editor->metric_get_minsec (marks, lower, upper, maxchars);
877 void
878 Editor::set_timecode_ruler_scale (gdouble lower, gdouble upper)
880 nframes64_t range;
881 nframes64_t spacer;
882 nframes64_t fr;
884 if (_session == 0) {
885 return;
888 fr = _session->frame_rate();
890 if (lower > (spacer = (nframes64_t)(128 * Editor::get_current_zoom ()))) {
891 lower = lower - spacer;
892 } else {
893 lower = 0;
895 upper = upper + spacer;
896 range = (nframes64_t) floor (upper - lower);
898 if (range < (2 * _session->frames_per_timecode_frame())) { /* 0 - 2 frames */
899 timecode_ruler_scale = timecode_show_bits;
900 timecode_mark_modulo = 20;
901 timecode_nmarks = 2 + (2 * _session->config.get_subframes_per_frame());
902 } else if (range <= (fr / 4)) { /* 2 frames - 0.250 second */
903 timecode_ruler_scale = timecode_show_frames;
904 timecode_mark_modulo = 1;
905 timecode_nmarks = 2 + (range / (nframes64_t)_session->frames_per_timecode_frame());
906 } else if (range <= (fr / 2)) { /* 0.25-0.5 second */
907 timecode_ruler_scale = timecode_show_frames;
908 timecode_mark_modulo = 2;
909 timecode_nmarks = 2 + (range / (nframes64_t)_session->frames_per_timecode_frame());
910 } else if (range <= fr) { /* 0.5-1 second */
911 timecode_ruler_scale = timecode_show_frames;
912 timecode_mark_modulo = 5;
913 timecode_nmarks = 2 + (range / (nframes64_t)_session->frames_per_timecode_frame());
914 } else if (range <= 2 * fr) { /* 1-2 seconds */
915 timecode_ruler_scale = timecode_show_frames;
916 timecode_mark_modulo = 10;
917 timecode_nmarks = 2 + (range / (nframes64_t)_session->frames_per_timecode_frame());
918 } else if (range <= 8 * fr) { /* 2-8 seconds */
919 timecode_ruler_scale = timecode_show_seconds;
920 timecode_mark_modulo = 1;
921 timecode_nmarks = 2 + (range / fr);
922 } else if (range <= 16 * fr) { /* 8-16 seconds */
923 timecode_ruler_scale = timecode_show_seconds;
924 timecode_mark_modulo = 2;
925 timecode_nmarks = 2 + (range / fr);
926 } else if (range <= 30 * fr) { /* 16-30 seconds */
927 timecode_ruler_scale = timecode_show_seconds;
928 timecode_mark_modulo = 5;
929 timecode_nmarks = 2 + (range / fr);
930 } else if (range <= 60 * fr) { /* 30-60 seconds */
931 timecode_ruler_scale = timecode_show_seconds;
932 timecode_mark_modulo = 5;
933 timecode_nmarks = 2 + (range / fr);
934 } else if (range <= 2 * 60 * fr) { /* 1-2 minutes */
935 timecode_ruler_scale = timecode_show_seconds;
936 timecode_mark_modulo = 15;
937 timecode_nmarks = 2 + (range / fr);
938 } else if (range <= 4 * 60 * fr) { /* 2-4 minutes */
939 timecode_ruler_scale = timecode_show_seconds;
940 timecode_mark_modulo = 30;
941 timecode_nmarks = 2 + (range / fr);
942 } else if (range <= 10 * 60 * fr) { /* 4-10 minutes */
943 timecode_ruler_scale = timecode_show_minutes;
944 timecode_mark_modulo = 2;
945 timecode_nmarks = 2 + 10;
946 } else if (range <= 30 * 60 * fr) { /* 10-30 minutes */
947 timecode_ruler_scale = timecode_show_minutes;
948 timecode_mark_modulo = 5;
949 timecode_nmarks = 2 + 30;
950 } else if (range <= 60 * 60 * fr) { /* 30 minutes - 1hr */
951 timecode_ruler_scale = timecode_show_minutes;
952 timecode_mark_modulo = 10;
953 timecode_nmarks = 2 + 60;
954 } else if (range <= 4 * 60 * 60 * fr) { /* 1 - 4 hrs*/
955 timecode_ruler_scale = timecode_show_minutes;
956 timecode_mark_modulo = 30;
957 timecode_nmarks = 2 + (60 * 4);
958 } else if (range <= 8 * 60 * 60 * fr) { /* 4 - 8 hrs*/
959 timecode_ruler_scale = timecode_show_hours;
960 timecode_mark_modulo = 1;
961 timecode_nmarks = 2 + 8;
962 } else if (range <= 16 * 60 * 60 * fr) { /* 16-24 hrs*/
963 timecode_ruler_scale = timecode_show_hours;
964 timecode_mark_modulo = 1;
965 timecode_nmarks = 2 + 24;
966 } else {
968 /* not possible if nframes64_t is a 32 bit quantity */
970 timecode_ruler_scale = timecode_show_hours;
971 timecode_mark_modulo = 4;
972 timecode_nmarks = 2 + 24;
977 gint
978 Editor::metric_get_timecode (GtkCustomRulerMark **marks, gdouble lower, gdouble /*upper*/, gint /*maxchars*/)
980 nframes_t pos;
981 nframes64_t spacer;
982 Timecode::Time timecode;
983 gchar buf[16];
984 gint n;
986 if (_session == 0) {
987 return 0;
990 if (lower > (spacer = (nframes64_t)(128 * Editor::get_current_zoom ()))) {
991 lower = lower - spacer;
992 } else {
993 lower = 0;
996 pos = (nframes_t) floor (lower);
998 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * timecode_nmarks);
999 switch (timecode_ruler_scale) {
1000 case timecode_show_bits:
1002 // Find timecode time of this sample (pos) with subframe accuracy
1003 _session->sample_to_timecode(pos, timecode, true /* use_offset */, true /* use_subframes */ );
1005 for (n = 0; n < timecode_nmarks; n++) {
1006 _session->timecode_to_sample(timecode, pos, true /* use_offset */, true /* use_subframes */ );
1007 if ((timecode.subframes % timecode_mark_modulo) == 0) {
1008 if (timecode.subframes == 0) {
1009 (*marks)[n].style = GtkCustomRulerMarkMajor;
1010 snprintf (buf, sizeof(buf), "%s%02u:%02u:%02u:%02u", timecode.negative ? "-" : "", timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
1011 } else {
1012 (*marks)[n].style = GtkCustomRulerMarkMinor;
1013 snprintf (buf, sizeof(buf), ".%02u", timecode.subframes);
1015 } else {
1016 snprintf (buf, sizeof(buf)," ");
1017 (*marks)[n].style = GtkCustomRulerMarkMicro;
1020 (*marks)[n].label = g_strdup (buf);
1021 (*marks)[n].position = pos;
1023 // Increment subframes by one
1024 Timecode::increment_subframes( timecode, _session->config.get_subframes_per_frame() );
1026 break;
1027 case timecode_show_seconds:
1028 // Find timecode time of this sample (pos)
1029 _session->sample_to_timecode(pos, timecode, true /* use_offset */, false /* use_subframes */ );
1030 // Go to next whole second down
1031 Timecode::seconds_floor( timecode );
1033 for (n = 0; n < timecode_nmarks; n++) {
1034 _session->timecode_to_sample(timecode, pos, true /* use_offset */, false /* use_subframes */ );
1035 if ((timecode.seconds % timecode_mark_modulo) == 0) {
1036 if (timecode.seconds == 0) {
1037 (*marks)[n].style = GtkCustomRulerMarkMajor;
1038 (*marks)[n].position = pos;
1039 } else {
1040 (*marks)[n].style = GtkCustomRulerMarkMinor;
1041 (*marks)[n].position = pos;
1043 snprintf (buf, sizeof(buf), "%s%02u:%02u:%02u:%02u", timecode.negative ? "-" : "", timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
1044 } else {
1045 snprintf (buf, sizeof(buf)," ");
1046 (*marks)[n].style = GtkCustomRulerMarkMicro;
1047 (*marks)[n].position = pos;
1050 (*marks)[n].label = g_strdup (buf);
1051 Timecode::increment_seconds( timecode, _session->config.get_subframes_per_frame() );
1053 break;
1054 case timecode_show_minutes:
1055 // Find timecode time of this sample (pos)
1056 _session->sample_to_timecode(pos, timecode, true /* use_offset */, false /* use_subframes */ );
1057 // Go to next whole minute down
1058 Timecode::minutes_floor( timecode );
1060 for (n = 0; n < timecode_nmarks; n++) {
1061 _session->timecode_to_sample(timecode, pos, true /* use_offset */, false /* use_subframes */ );
1062 if ((timecode.minutes % timecode_mark_modulo) == 0) {
1063 if (timecode.minutes == 0) {
1064 (*marks)[n].style = GtkCustomRulerMarkMajor;
1065 } else {
1066 (*marks)[n].style = GtkCustomRulerMarkMinor;
1068 snprintf (buf, sizeof(buf), "%s%02u:%02u:%02u:%02u", timecode.negative ? "-" : "", timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
1069 } else {
1070 snprintf (buf, sizeof(buf)," ");
1071 (*marks)[n].style = GtkCustomRulerMarkMicro;
1074 (*marks)[n].label = g_strdup (buf);
1075 (*marks)[n].position = pos;
1076 Timecode::increment_minutes( timecode, _session->config.get_subframes_per_frame() );
1079 break;
1080 case timecode_show_hours:
1081 // Find timecode time of this sample (pos)
1082 _session->sample_to_timecode(pos, timecode, true /* use_offset */, false /* use_subframes */ );
1083 // Go to next whole hour down
1084 Timecode::hours_floor( timecode );
1086 for (n = 0; n < timecode_nmarks; n++) {
1087 _session->timecode_to_sample(timecode, pos, true /* use_offset */, false /* use_subframes */ );
1088 if ((timecode.hours % timecode_mark_modulo) == 0) {
1089 (*marks)[n].style = GtkCustomRulerMarkMajor;
1090 snprintf (buf, sizeof(buf), "%s%02u:%02u:%02u:%02u", timecode.negative ? "-" : "", timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
1091 } else {
1092 snprintf (buf, sizeof(buf)," ");
1093 (*marks)[n].style = GtkCustomRulerMarkMicro;
1096 (*marks)[n].label = g_strdup (buf);
1097 (*marks)[n].position = pos;
1099 Timecode::increment_hours( timecode, _session->config.get_subframes_per_frame() );
1101 break;
1102 case timecode_show_frames:
1103 // Find timecode time of this sample (pos)
1104 _session->sample_to_timecode(pos, timecode, true /* use_offset */, false /* use_subframes */ );
1105 // Go to next whole frame down
1106 Timecode::frames_floor( timecode );
1108 for (n = 0; n < timecode_nmarks; n++) {
1109 _session->timecode_to_sample(timecode, pos, true /* use_offset */, false /* use_subframes */ );
1110 if ((timecode.frames % timecode_mark_modulo) == 0) {
1111 if (timecode.frames == 0) {
1112 (*marks)[n].style = GtkCustomRulerMarkMajor;
1113 } else {
1114 (*marks)[n].style = GtkCustomRulerMarkMinor;
1116 (*marks)[n].position = pos;
1117 snprintf (buf, sizeof(buf), "%s%02u:%02u:%02u:%02u", timecode.negative ? "-" : "", timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
1118 } else {
1119 snprintf (buf, sizeof(buf)," ");
1120 (*marks)[n].style = GtkCustomRulerMarkMicro;
1121 (*marks)[n].position = pos;
1124 (*marks)[n].label = g_strdup (buf);
1125 Timecode::increment( timecode, _session->config.get_subframes_per_frame() );
1128 break;
1131 return timecode_nmarks;
1135 void
1136 Editor::compute_bbt_ruler_scale (nframes64_t lower, nframes64_t upper)
1138 if (_session == 0) {
1139 return;
1141 TempoMap::BBTPointList::iterator i;
1142 BBT_Time lower_beat, upper_beat; // the beats at each end of the ruler
1144 _session->bbt_time((jack_nframes_t) lower, lower_beat);
1145 _session->bbt_time((jack_nframes_t) upper, upper_beat);
1146 uint32_t beats = 0;
1148 bbt_accent_modulo = 1;
1149 bbt_bar_helper_on = false;
1150 bbt_bars = 0;
1151 bbt_nmarks = 1;
1153 bbt_ruler_scale = bbt_over;
1155 switch (_snap_type) {
1156 case SnapToBeatDiv2:
1157 bbt_beat_subdivision = 2;
1158 break;
1159 case SnapToBeatDiv3:
1160 bbt_beat_subdivision = 3;
1161 break;
1162 case SnapToBeatDiv4:
1163 bbt_beat_subdivision = 4;
1164 break;
1165 case SnapToBeatDiv5:
1166 bbt_beat_subdivision = 5;
1167 bbt_accent_modulo = 2; // XXX YIKES
1168 break;
1169 case SnapToBeatDiv6:
1170 bbt_beat_subdivision = 6;
1171 bbt_accent_modulo = 2; // XXX YIKES
1172 break;
1173 case SnapToBeatDiv7:
1174 bbt_beat_subdivision = 7;
1175 bbt_accent_modulo = 2; // XXX YIKES
1176 break;
1177 case SnapToBeatDiv8:
1178 bbt_beat_subdivision = 8;
1179 bbt_accent_modulo = 2;
1180 break;
1181 case SnapToBeatDiv10:
1182 bbt_beat_subdivision = 10;
1183 bbt_accent_modulo = 2; // XXX YIKES
1184 break;
1185 case SnapToBeatDiv12:
1186 bbt_beat_subdivision = 12;
1187 bbt_accent_modulo = 3;
1188 break;
1189 case SnapToBeatDiv14:
1190 bbt_beat_subdivision = 14;
1191 bbt_accent_modulo = 3; // XXX YIKES!
1192 break;
1193 case SnapToBeatDiv16:
1194 bbt_beat_subdivision = 16;
1195 bbt_accent_modulo = 4;
1196 break;
1197 case SnapToBeatDiv24:
1198 bbt_beat_subdivision = 24;
1199 bbt_accent_modulo = 6;
1200 break;
1201 case SnapToBeatDiv28:
1202 bbt_beat_subdivision = 28;
1203 bbt_accent_modulo = 7;
1204 break;
1205 case SnapToBeatDiv32:
1206 bbt_beat_subdivision = 32;
1207 bbt_accent_modulo = 8;
1208 break;
1209 default:
1210 bbt_beat_subdivision = 4;
1211 break;
1214 if (current_bbt_points == 0 || current_bbt_points->empty()) {
1215 return;
1218 i = current_bbt_points->end();
1219 i--;
1220 if ((*i).beat >= (*current_bbt_points->begin()).beat) {
1221 bbt_bars = (*i).bar - (*current_bbt_points->begin()).bar;
1222 } else {
1223 bbt_bars = (*i).bar - (*current_bbt_points->begin()).bar - 1;
1225 beats = current_bbt_points->size() - bbt_bars;
1227 /*Only show the bar helper if there aren't many bars on the screen */
1228 if ((bbt_bars < 2) || (beats < 5)) {
1229 bbt_bar_helper_on = true;
1232 if (bbt_bars > 8192) {
1233 bbt_ruler_scale = bbt_over;
1234 } else if (bbt_bars > 1024) {
1235 bbt_ruler_scale = bbt_show_64;
1236 } else if (bbt_bars > 256) {
1237 bbt_ruler_scale = bbt_show_16;
1238 } else if (bbt_bars > 64) {
1239 bbt_ruler_scale = bbt_show_4;
1240 } else if (bbt_bars > 10) {
1241 bbt_ruler_scale = bbt_show_1;
1242 } else if (bbt_bars > 2) {
1243 bbt_ruler_scale = bbt_show_beats;
1244 } else if (bbt_bars > 0) {
1245 bbt_ruler_scale = bbt_show_ticks;
1246 } else {
1247 bbt_ruler_scale = bbt_show_ticks_detail;
1250 if ((bbt_ruler_scale == bbt_show_ticks_detail) && (lower_beat.beats == upper_beat.beats) && (upper_beat.ticks - lower_beat.ticks <= Meter::ticks_per_beat / 4)) {
1251 bbt_ruler_scale = bbt_show_ticks_super_detail;
1255 gint
1256 Editor::metric_get_bbt (GtkCustomRulerMark **marks, gdouble lower, gdouble /*upper*/, gint /*maxchars*/)
1258 if (_session == 0) {
1259 return 0;
1262 TempoMap::BBTPointList::iterator i;
1264 char buf[64];
1265 gint n = 0;
1266 nframes64_t pos;
1267 BBT_Time next_beat;
1268 nframes64_t next_beat_pos;
1269 uint32_t beats = 0;
1271 uint32_t tick = 0;
1272 uint32_t skip;
1273 uint32_t t;
1274 nframes64_t frame_skip;
1275 double frame_skip_error;
1276 double bbt_position_of_helper;
1277 double accumulated_error;
1278 bool i_am_accented = false;
1279 bool helper_active = false;
1281 if (current_bbt_points == 0 || current_bbt_points->empty()) {
1282 return 0;
1285 switch (bbt_ruler_scale) {
1287 case bbt_show_beats:
1288 beats = current_bbt_points->size();
1289 bbt_nmarks = beats + 2;
1291 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1293 (*marks)[0].label = g_strdup(" ");
1294 (*marks)[0].position = lower;
1295 (*marks)[0].style = GtkCustomRulerMarkMicro;
1297 for (n = 1, i = current_bbt_points->begin(); n < bbt_nmarks && i != current_bbt_points->end(); ++i) {
1298 if ((*i).type != TempoMap::Beat) {
1299 continue;
1301 if ((*i).frame < lower && (bbt_bar_helper_on)) {
1302 snprintf (buf, sizeof(buf), "<%" PRIu32 "|%" PRIu32, (*i).bar, (*i).beat);
1303 (*marks)[0].label = g_strdup (buf);
1304 helper_active = true;
1305 } else {
1307 if ((*i).beat == 1) {
1308 (*marks)[n].style = GtkCustomRulerMarkMajor;
1309 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1310 } else if (((*i).beat % 2 == 1)) {
1311 (*marks)[n].style = GtkCustomRulerMarkMinor;
1312 snprintf (buf, sizeof(buf), " ");
1313 } else {
1314 (*marks)[n].style = GtkCustomRulerMarkMicro;
1315 snprintf (buf, sizeof(buf), " ");
1317 (*marks)[n].label = g_strdup (buf);
1318 (*marks)[n].position = (*i).frame;
1319 n++;
1322 break;
1324 case bbt_show_ticks:
1326 beats = current_bbt_points->size();
1327 bbt_nmarks = (beats + 2) * bbt_beat_subdivision;
1329 bbt_position_of_helper = lower + (30 * Editor::get_current_zoom ());
1330 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1332 (*marks)[0].label = g_strdup(" ");
1333 (*marks)[0].position = lower;
1334 (*marks)[0].style = GtkCustomRulerMarkMicro;
1336 for (n = 1, i = current_bbt_points->begin(); n < bbt_nmarks && i != current_bbt_points->end(); ++i) {
1337 if ((*i).type != TempoMap::Beat) {
1338 continue;
1340 if ((*i).frame < lower && (bbt_bar_helper_on)) {
1341 snprintf (buf, sizeof(buf), "<%" PRIu32 "|%" PRIu32, (*i).bar, (*i).beat);
1342 (*marks)[0].label = g_strdup (buf);
1343 helper_active = true;
1344 } else {
1346 if ((*i).beat == 1) {
1347 (*marks)[n].style = GtkCustomRulerMarkMajor;
1348 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1349 } else {
1350 (*marks)[n].style = GtkCustomRulerMarkMinor;
1351 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).beat);
1353 if (((*i).frame < bbt_position_of_helper) && helper_active) {
1354 snprintf (buf, sizeof(buf), " ");
1356 (*marks)[n].label = g_strdup (buf);
1357 (*marks)[n].position = (*i).frame;
1358 n++;
1361 /* Add the tick marks */
1363 /* Find the next beat */
1364 next_beat.beats = (*i).beat;
1365 next_beat.bars = (*i).bar;
1366 next_beat.ticks = 0;
1368 if ((*i).meter->beats_per_bar() > (next_beat.beats + 1)) {
1369 next_beat.beats += 1;
1370 } else {
1371 next_beat.bars += 1;
1372 next_beat.beats = 1;
1375 next_beat_pos = _session->tempo_map().frame_time(next_beat);
1377 frame_skip = (nframes64_t) floor (frame_skip_error = (_session->frame_rate() * 60) / (bbt_beat_subdivision * (*i).tempo->beats_per_minute()));
1378 frame_skip_error -= frame_skip;
1379 skip = (uint32_t) (Meter::ticks_per_beat / bbt_beat_subdivision);
1381 pos = (*i).frame + frame_skip;
1382 accumulated_error = frame_skip_error;
1384 tick = skip;
1386 for (t = 0; (tick < Meter::ticks_per_beat) && (n < bbt_nmarks) && (pos < next_beat_pos) ; pos += frame_skip, tick += skip, ++t) {
1388 if (t % bbt_accent_modulo == (bbt_accent_modulo - 1)) {
1389 i_am_accented = true;
1392 snprintf (buf, sizeof(buf), " ");
1393 (*marks)[n].label = g_strdup (buf);
1395 /* Error compensation for float to nframes64_t*/
1396 accumulated_error += frame_skip_error;
1397 if (accumulated_error > 1) {
1398 pos += 1;
1399 accumulated_error -= 1.0f;
1402 (*marks)[n].position = pos;
1404 if ((bbt_beat_subdivision > 4) && i_am_accented) {
1405 (*marks)[n].style = GtkCustomRulerMarkMinor;
1406 } else {
1407 (*marks)[n].style = GtkCustomRulerMarkMicro;
1409 i_am_accented = false;
1410 n++;
1414 break;
1416 case bbt_show_ticks_detail:
1418 beats = current_bbt_points->size();
1419 bbt_nmarks = (beats + 2) * bbt_beat_subdivision;
1421 bbt_position_of_helper = lower + (30 * Editor::get_current_zoom ());
1422 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1424 (*marks)[0].label = g_strdup(" ");
1425 (*marks)[0].position = lower;
1426 (*marks)[0].style = GtkCustomRulerMarkMicro;
1428 for (n = 1, i = current_bbt_points->begin(); n < bbt_nmarks && i != current_bbt_points->end(); ++i) {
1429 if ((*i).type != TempoMap::Beat) {
1430 continue;
1432 if ((*i).frame < lower && (bbt_bar_helper_on)) {
1433 snprintf (buf, sizeof(buf), "<%" PRIu32 "|%" PRIu32, (*i).bar, (*i).beat);
1434 (*marks)[0].label = g_strdup (buf);
1435 helper_active = true;
1436 } else {
1438 if ((*i).beat == 1) {
1439 (*marks)[n].style = GtkCustomRulerMarkMajor;
1440 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1441 } else {
1442 (*marks)[n].style = GtkCustomRulerMarkMinor;
1443 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).beat);
1445 if (((*i).frame < bbt_position_of_helper) && helper_active) {
1446 snprintf (buf, sizeof(buf), " ");
1448 (*marks)[n].label = g_strdup (buf);
1449 (*marks)[n].position = (*i).frame;
1450 n++;
1453 /* Add the tick marks */
1455 /* Find the next beat */
1457 next_beat.beats = (*i).beat;
1458 next_beat.bars = (*i).bar;
1460 if ((*i).meter->beats_per_bar() > (next_beat.beats + 1)) {
1461 next_beat.beats += 1;
1462 } else {
1463 next_beat.bars += 1;
1464 next_beat.beats = 1;
1467 next_beat_pos = _session->tempo_map().frame_time(next_beat);
1469 frame_skip = (nframes64_t) floor (frame_skip_error = (_session->frame_rate() * 60) / (bbt_beat_subdivision * (*i).tempo->beats_per_minute()));
1470 frame_skip_error -= frame_skip;
1471 skip = (uint32_t) (Meter::ticks_per_beat / bbt_beat_subdivision);
1473 pos = (*i).frame + frame_skip;
1474 accumulated_error = frame_skip_error;
1476 tick = skip;
1478 for (t = 0; (tick < Meter::ticks_per_beat) && (n < bbt_nmarks) && (pos < next_beat_pos) ; pos += frame_skip, tick += skip, ++t) {
1480 if (t % bbt_accent_modulo == (bbt_accent_modulo - 1)) {
1481 i_am_accented = true;
1484 if (i_am_accented && (pos > bbt_position_of_helper)){
1485 snprintf (buf, sizeof(buf), "%" PRIu32, tick);
1486 } else {
1487 snprintf (buf, sizeof(buf), " ");
1490 (*marks)[n].label = g_strdup (buf);
1492 /* Error compensation for float to nframes64_t*/
1493 accumulated_error += frame_skip_error;
1494 if (accumulated_error > 1) {
1495 pos += 1;
1496 accumulated_error -= 1.0f;
1499 (*marks)[n].position = pos;
1501 if ((bbt_beat_subdivision > 4) && i_am_accented) {
1502 (*marks)[n].style = GtkCustomRulerMarkMinor;
1503 } else {
1504 (*marks)[n].style = GtkCustomRulerMarkMicro;
1506 i_am_accented = false;
1507 n++;
1511 break;
1513 case bbt_show_ticks_super_detail:
1515 beats = current_bbt_points->size();
1516 bbt_nmarks = (beats + 2) * bbt_beat_subdivision;
1518 bbt_position_of_helper = lower + (30 * Editor::get_current_zoom ());
1519 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1521 (*marks)[0].label = g_strdup(" ");
1522 (*marks)[0].position = lower;
1523 (*marks)[0].style = GtkCustomRulerMarkMicro;
1525 for (n = 1, i = current_bbt_points->begin(); n < bbt_nmarks && i != current_bbt_points->end(); ++i) {
1526 if ((*i).type != TempoMap::Beat) {
1527 continue;
1529 if ((*i).frame < lower && (bbt_bar_helper_on)) {
1530 snprintf (buf, sizeof(buf), "<%" PRIu32 "|%" PRIu32, (*i).bar, (*i).beat);
1531 (*marks)[0].label = g_strdup (buf);
1532 helper_active = true;
1533 } else {
1535 if ((*i).beat == 1) {
1536 (*marks)[n].style = GtkCustomRulerMarkMajor;
1537 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1538 } else {
1539 (*marks)[n].style = GtkCustomRulerMarkMinor;
1540 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).beat);
1542 if (((*i).frame < bbt_position_of_helper) && helper_active) {
1543 snprintf (buf, sizeof(buf), " ");
1545 (*marks)[n].label = g_strdup (buf);
1546 (*marks)[n].position = (*i).frame;
1547 n++;
1550 /* Add the tick marks */
1552 /* Find the next beat */
1554 next_beat.beats = (*i).beat;
1555 next_beat.bars = (*i).bar;
1557 if ((*i).meter->beats_per_bar() > (next_beat.beats + 1)) {
1558 next_beat.beats += 1;
1559 } else {
1560 next_beat.bars += 1;
1561 next_beat.beats = 1;
1564 next_beat_pos = _session->tempo_map().frame_time(next_beat);
1566 frame_skip = (nframes64_t) floor (frame_skip_error = (_session->frame_rate() * 60) / (bbt_beat_subdivision * (*i).tempo->beats_per_minute()));
1567 frame_skip_error -= frame_skip;
1568 skip = (uint32_t) (Meter::ticks_per_beat / bbt_beat_subdivision);
1570 pos = (*i).frame + frame_skip;
1571 accumulated_error = frame_skip_error;
1573 tick = skip;
1575 for (t = 0; (tick < Meter::ticks_per_beat) && (n < bbt_nmarks) && (pos < next_beat_pos) ; pos += frame_skip, tick += skip, ++t) {
1577 if (t % bbt_accent_modulo == (bbt_accent_modulo - 1)) {
1578 i_am_accented = true;
1581 if (pos > bbt_position_of_helper) {
1582 snprintf (buf, sizeof(buf), "%" PRIu32, tick);
1583 } else {
1584 snprintf (buf, sizeof(buf), " ");
1587 (*marks)[n].label = g_strdup (buf);
1589 /* Error compensation for float to nframes64_t*/
1590 accumulated_error += frame_skip_error;
1591 if (accumulated_error > 1) {
1592 pos += 1;
1593 accumulated_error -= 1.0f;
1596 (*marks)[n].position = pos;
1598 if ((bbt_beat_subdivision > 4) && i_am_accented) {
1599 (*marks)[n].style = GtkCustomRulerMarkMinor;
1600 } else {
1601 (*marks)[n].style = GtkCustomRulerMarkMicro;
1603 i_am_accented = false;
1604 n++;
1608 break;
1610 case bbt_over:
1611 bbt_nmarks = 1;
1612 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1613 snprintf (buf, sizeof(buf), "cannot handle %" PRIu32 " bars", bbt_bars );
1614 (*marks)[0].style = GtkCustomRulerMarkMajor;
1615 (*marks)[0].label = g_strdup (buf);
1616 (*marks)[0].position = lower;
1617 n = 1;
1619 break;
1621 case bbt_show_64:
1622 bbt_nmarks = (gint) (bbt_bars / 64) + 1;
1623 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1624 for (n = 0, i = current_bbt_points->begin(); i != current_bbt_points->end() && n < bbt_nmarks; i++) {
1625 if ((*i).type == TempoMap::Bar) {
1626 if ((*i).bar % 64 == 1) {
1627 if ((*i).bar % 256 == 1) {
1628 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1629 (*marks)[n].style = GtkCustomRulerMarkMajor;
1630 } else {
1631 snprintf (buf, sizeof(buf), " ");
1632 if ((*i).bar % 256 == 129) {
1633 (*marks)[n].style = GtkCustomRulerMarkMinor;
1634 } else {
1635 (*marks)[n].style = GtkCustomRulerMarkMicro;
1638 (*marks)[n].label = g_strdup (buf);
1639 (*marks)[n].position = (*i).frame;
1640 n++;
1644 break;
1646 case bbt_show_16:
1647 bbt_nmarks = (bbt_bars / 16) + 1;
1648 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1649 for (n = 0, i = current_bbt_points->begin(); i != current_bbt_points->end() && n < bbt_nmarks; i++) {
1650 if ((*i).type == TempoMap::Bar) {
1651 if ((*i).bar % 16 == 1) {
1652 if ((*i).bar % 64 == 1) {
1653 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1654 (*marks)[n].style = GtkCustomRulerMarkMajor;
1655 } else {
1656 snprintf (buf, sizeof(buf), " ");
1657 if ((*i).bar % 64 == 33) {
1658 (*marks)[n].style = GtkCustomRulerMarkMinor;
1659 } else {
1660 (*marks)[n].style = GtkCustomRulerMarkMicro;
1663 (*marks)[n].label = g_strdup (buf);
1664 (*marks)[n].position = (*i).frame;
1665 n++;
1669 break;
1671 case bbt_show_4:
1672 bbt_nmarks = (bbt_bars / 4) + 1;
1673 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
1674 for (n = 0, i = current_bbt_points->begin(); i != current_bbt_points->end() && n < bbt_nmarks; ++i) {
1675 if ((*i).type == TempoMap::Bar) {
1676 if ((*i).bar % 4 == 1) {
1677 if ((*i).bar % 16 == 1) {
1678 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1679 (*marks)[n].style = GtkCustomRulerMarkMajor;
1680 } else {
1681 snprintf (buf, sizeof(buf), " ");
1682 if ((*i).bar % 16 == 9) {
1683 (*marks)[n].style = GtkCustomRulerMarkMinor;
1684 } else {
1685 (*marks)[n].style = GtkCustomRulerMarkMicro;
1688 (*marks)[n].label = g_strdup (buf);
1689 (*marks)[n].position = (*i).frame;
1690 n++;
1694 break;
1696 case bbt_show_1:
1697 // default:
1698 bbt_nmarks = bbt_bars + 2;
1699 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks );
1700 for (n = 0, i = current_bbt_points->begin(); i != current_bbt_points->end() && n < bbt_nmarks; i++) {
1701 if ((*i).type == TempoMap::Bar) {
1702 if ((*i).bar % 4 == 1) {
1703 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1704 (*marks)[n].style = GtkCustomRulerMarkMajor;
1705 } else {
1706 snprintf (buf, sizeof(buf), " ");
1707 if ((*i).bar % 4 == 3) {
1708 (*marks)[n].style = GtkCustomRulerMarkMinor;
1709 } else {
1710 (*marks)[n].style = GtkCustomRulerMarkMicro;
1713 (*marks)[n].label = g_strdup (buf);
1714 (*marks)[n].position = (*i).frame;
1715 n++;
1719 break;
1723 return n; //return the actual number of marks made, since we might have skipped some from fractional time signatures
1727 gint
1728 Editor::metric_get_frames (GtkCustomRulerMark **marks, gdouble lower, gdouble upper, gint /*maxchars*/)
1730 nframes64_t mark_interval;
1731 nframes64_t pos;
1732 nframes64_t ilower = (nframes64_t) floor (lower);
1733 nframes64_t iupper = (nframes64_t) floor (upper);
1734 gchar buf[16];
1735 gint nmarks;
1736 gint n;
1738 if (_session == 0) {
1739 return 0;
1742 mark_interval = (iupper - ilower) / 5;
1743 if (mark_interval > _session->frame_rate()) {
1744 mark_interval -= mark_interval % _session->frame_rate();
1745 } else {
1746 mark_interval = _session->frame_rate() / (_session->frame_rate() / mark_interval ) ;
1748 nmarks = 5;
1749 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * nmarks);
1750 for (n = 0, pos = ilower; n < nmarks; pos += mark_interval, ++n) {
1751 snprintf (buf, sizeof(buf), "%" PRIi64, pos);
1752 (*marks)[n].label = g_strdup (buf);
1753 (*marks)[n].position = pos;
1754 (*marks)[n].style = GtkCustomRulerMarkMajor;
1757 return nmarks;
1760 static void
1761 sample_to_clock_parts ( nframes64_t sample,
1762 nframes64_t sample_rate,
1763 long *hrs_p,
1764 long *mins_p,
1765 long *secs_p,
1766 long *millisecs_p)
1769 nframes64_t left;
1770 long hrs;
1771 long mins;
1772 long secs;
1773 long millisecs;
1775 left = sample;
1776 hrs = left / (sample_rate * 60 * 60);
1777 left -= hrs * sample_rate * 60 * 60;
1778 mins = left / (sample_rate * 60);
1779 left -= mins * sample_rate * 60;
1780 secs = left / sample_rate;
1781 left -= secs * sample_rate;
1782 millisecs = left * 1000 / sample_rate;
1784 *millisecs_p = millisecs;
1785 *secs_p = secs;
1786 *mins_p = mins;
1787 *hrs_p = hrs;
1789 return;
1792 void
1793 Editor::set_minsec_ruler_scale (gdouble lower, gdouble upper)
1795 nframes64_t range;
1796 nframes64_t fr;
1797 nframes64_t spacer;
1799 if (_session == 0) {
1800 return;
1803 fr = _session->frame_rate();
1805 /* to prevent 'flashing' */
1806 if (lower > (spacer = (nframes64_t)(128 * Editor::get_current_zoom ()))) {
1807 lower -= spacer;
1808 } else {
1809 lower = 0;
1811 upper += spacer;
1812 range = (nframes64_t) (upper - lower);
1814 if (range < (fr / 50)) {
1815 minsec_mark_interval = fr / 1000; /* show 1/1000 seconds */
1816 minsec_ruler_scale = minsec_show_frames;
1817 minsec_mark_modulo = 10;
1818 } else if (range <= (fr / 10)) { /* 0-0.1 second */
1819 minsec_mark_interval = fr / 1000; /* show 1/1000 seconds */
1820 minsec_ruler_scale = minsec_show_frames;
1821 minsec_mark_modulo = 10;
1822 } else if (range <= (fr / 2)) { /* 0-0.5 second */
1823 minsec_mark_interval = fr / 100; /* show 1/100 seconds */
1824 minsec_ruler_scale = minsec_show_frames;
1825 minsec_mark_modulo = 100;
1826 } else if (range <= fr) { /* 0-1 second */
1827 minsec_mark_interval = fr / 10; /* show 1/10 seconds */
1828 minsec_ruler_scale = minsec_show_frames;
1829 minsec_mark_modulo = 200;
1830 } else if (range <= 2 * fr) { /* 1-2 seconds */
1831 minsec_mark_interval = fr / 10; /* show 1/10 seconds */
1832 minsec_ruler_scale = minsec_show_frames;
1833 minsec_mark_modulo = 500;
1834 } else if (range <= 8 * fr) { /* 2-5 seconds */
1835 minsec_mark_interval = fr / 5; /* show 2 seconds */
1836 minsec_ruler_scale = minsec_show_frames;
1837 minsec_mark_modulo = 1000;
1838 } else if (range <= 16 * fr) { /* 8-16 seconds */
1839 minsec_mark_interval = fr; /* show 1 seconds */
1840 minsec_ruler_scale = minsec_show_seconds;
1841 minsec_mark_modulo = 2;
1842 } else if (range <= 30 * fr) { /* 10-30 seconds */
1843 minsec_mark_interval = fr; /* show 1 seconds */
1844 minsec_ruler_scale = minsec_show_seconds;
1845 minsec_mark_modulo = 5;
1846 } else if (range <= 60 * fr) { /* 30-60 seconds */
1847 minsec_mark_interval = fr; /* show 1 seconds */
1848 minsec_ruler_scale = minsec_show_seconds;
1849 minsec_mark_modulo = 5;
1850 } else if (range <= 2 * 60 * fr) { /* 1-2 minutes */
1851 minsec_mark_interval = 5 * fr; /* show 5 seconds */
1852 minsec_ruler_scale = minsec_show_seconds;
1853 minsec_mark_modulo = 3;
1854 } else if (range <= 4 * 60 * fr) { /* 4 minutes */
1855 minsec_mark_interval = 5 * fr; /* show 10 seconds */
1856 minsec_ruler_scale = minsec_show_seconds;
1857 minsec_mark_modulo = 30;
1858 } else if (range <= 10 * 60 * fr) { /* 10 minutes */
1859 minsec_mark_interval = 30 * fr; /* show 30 seconds */
1860 minsec_ruler_scale = minsec_show_seconds;
1861 minsec_mark_modulo = 120;
1862 } else if (range <= 30 * 60 * fr) { /* 10-30 minutes */
1863 minsec_mark_interval = 60 * fr; /* show 1 minute */
1864 minsec_ruler_scale = minsec_show_minutes;
1865 minsec_mark_modulo = 5;
1866 } else if (range <= 60 * 60 * fr) { /* 30 minutes - 1hr */
1867 minsec_mark_interval = 2 * 60 * fr; /* show 2 minutes */
1868 minsec_ruler_scale = minsec_show_minutes;
1869 minsec_mark_modulo = 10;
1870 } else if (range <= 4 * 60 * 60 * fr) { /* 1 - 4 hrs*/
1871 minsec_mark_interval = 5 * 60 * fr; /* show 10 minutes */
1872 minsec_ruler_scale = minsec_show_minutes;
1873 minsec_mark_modulo = 30;
1874 } else if (range <= 8 * 60 * 60 * fr) { /* 4 - 8 hrs*/
1875 minsec_mark_interval = 20 * 60 * fr; /* show 20 minutes */
1876 minsec_ruler_scale = minsec_show_minutes;
1877 minsec_mark_modulo = 60;
1878 } else if (range <= 16 * 60 * 60 * fr) { /* 16-24 hrs*/
1879 minsec_mark_interval = 60 * 60 * fr; /* show 60 minutes */
1880 minsec_ruler_scale = minsec_show_hours;
1881 minsec_mark_modulo = 2;
1882 } else {
1884 /* not possible if nframes64_t is a 32 bit quantity */
1886 minsec_mark_interval = 4 * 60 * 60 * fr; /* show 4 hrs */
1888 minsec_nmarks = 2 + (range / minsec_mark_interval);
1891 gint
1892 Editor::metric_get_minsec (GtkCustomRulerMark **marks, gdouble lower, gdouble /*upper*/, gint /*maxchars*/)
1894 nframes64_t pos;
1895 nframes64_t spacer;
1896 long hrs, mins, secs, millisecs;
1897 gchar buf[16];
1898 gint n;
1900 if (_session == 0) {
1901 return 0;
1904 /* to prevent 'flashing' */
1905 if (lower > (spacer = (nframes64_t)(128 * Editor::get_current_zoom ()))) {
1906 lower = lower - spacer;
1907 } else {
1908 lower = 0;
1911 *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * minsec_nmarks);
1912 pos = ((((nframes64_t) floor(lower)) + (minsec_mark_interval/2))/minsec_mark_interval) * minsec_mark_interval;
1913 switch (minsec_ruler_scale) {
1914 case minsec_show_seconds:
1915 for (n = 0; n < minsec_nmarks; pos += minsec_mark_interval, ++n) {
1916 sample_to_clock_parts (pos, _session->frame_rate(), &hrs, &mins, &secs, &millisecs);
1917 if (secs % minsec_mark_modulo == 0) {
1918 if (secs == 0) {
1919 (*marks)[n].style = GtkCustomRulerMarkMajor;
1920 } else {
1921 (*marks)[n].style = GtkCustomRulerMarkMinor;
1923 snprintf (buf, sizeof(buf), "%02ld:%02ld:%02ld.%03ld", hrs, mins, secs, millisecs);
1924 } else {
1925 snprintf (buf, sizeof(buf), " ");
1926 (*marks)[n].style = GtkCustomRulerMarkMicro;
1928 (*marks)[n].label = g_strdup (buf);
1929 (*marks)[n].position = pos;
1931 break;
1932 case minsec_show_minutes:
1933 for (n = 0; n < minsec_nmarks; pos += minsec_mark_interval, ++n) {
1934 sample_to_clock_parts (pos, _session->frame_rate(), &hrs, &mins, &secs, &millisecs);
1935 if (mins % minsec_mark_modulo == 0) {
1936 if (mins == 0) {
1937 (*marks)[n].style = GtkCustomRulerMarkMajor;
1938 } else {
1939 (*marks)[n].style = GtkCustomRulerMarkMinor;
1941 snprintf (buf, sizeof(buf), "%02ld:%02ld:%02ld.%03ld", hrs, mins, secs, millisecs);
1942 } else {
1943 snprintf (buf, sizeof(buf), " ");
1944 (*marks)[n].style = GtkCustomRulerMarkMicro;
1946 (*marks)[n].label = g_strdup (buf);
1947 (*marks)[n].position = pos;
1949 break;
1950 case minsec_show_hours:
1951 for (n = 0; n < minsec_nmarks; pos += minsec_mark_interval, ++n) {
1952 sample_to_clock_parts (pos, _session->frame_rate(), &hrs, &mins, &secs, &millisecs);
1953 if (hrs % minsec_mark_modulo == 0) {
1954 (*marks)[n].style = GtkCustomRulerMarkMajor;
1955 snprintf (buf, sizeof(buf), "%02ld:%02ld:%02ld.%03ld", hrs, mins, secs, millisecs);
1956 } else {
1957 snprintf (buf, sizeof(buf), " ");
1958 (*marks)[n].style = GtkCustomRulerMarkMicro;
1960 (*marks)[n].label = g_strdup (buf);
1961 (*marks)[n].position = pos;
1963 break;
1964 case minsec_show_frames:
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 (millisecs % minsec_mark_modulo == 0) {
1968 if (secs == 0) {
1969 (*marks)[n].style = GtkCustomRulerMarkMajor;
1970 } else {
1971 (*marks)[n].style = GtkCustomRulerMarkMinor;
1973 snprintf (buf, sizeof(buf), "%02ld:%02ld:%02ld.%03ld", hrs, mins, secs, millisecs);
1974 } else {
1975 snprintf (buf, sizeof(buf), " ");
1976 (*marks)[n].style = GtkCustomRulerMarkMicro;
1978 (*marks)[n].label = g_strdup (buf);
1979 (*marks)[n].position = pos;
1981 break;
1984 return minsec_nmarks;