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 "canvas/layout.h"
33 #include "canvas/canvas.h"
34 #include "canvas/ruler.h"
35 #include "canvas/debug.h"
36 #include "canvas/scroll_group.h"
38 #include "ardour/session.h"
39 #include "ardour/tempo.h"
40 #include "ardour/profile.h"
42 #include "gtkmm2ext/gtk_ui.h"
43 #include "gtkmm2ext/keyboard.h"
45 #include "ardour_ui.h"
49 #include "gui_thread.h"
50 #include "time_axis_view.h"
51 #include "editor_drag.h"
52 #include "editor_cursors.h"
57 using namespace ARDOUR;
60 using namespace Editing;
62 /* the order here must match the "metric" enums in editor.h */
64 class TimecodeMetric : public ArdourCanvas::Ruler::Metric
67 TimecodeMetric (Editor* e) : _editor (e) {}
69 void get_marks (std::vector<ArdourCanvas::Ruler::Mark>& marks, double lower, double upper, int maxchars) const {
70 _editor->metric_get_timecode (marks, lower, upper, maxchars);
77 class SamplesMetric : public ArdourCanvas::Ruler::Metric
80 SamplesMetric (Editor* e) : _editor (e) {}
82 void get_marks (std::vector<ArdourCanvas::Ruler::Mark>& marks, double lower, double upper, int maxchars) const {
83 _editor->metric_get_samples (marks, lower, upper, maxchars);
90 class BBTMetric : public ArdourCanvas::Ruler::Metric
93 BBTMetric (Editor* e) : _editor (e) {}
95 void get_marks (std::vector<ArdourCanvas::Ruler::Mark>& marks, double lower, double upper, int maxchars) const {
96 _editor->metric_get_bbt (marks, lower, upper, maxchars);
103 class MinsecMetric : public ArdourCanvas::Ruler::Metric
106 MinsecMetric (Editor* e) : _editor (e) {}
108 void get_marks (std::vector<ArdourCanvas::Ruler::Mark>& marks, double lower, double upper, int maxchars) const {
109 _editor->metric_get_minsec (marks, lower, upper, maxchars);
116 static ArdourCanvas::Ruler::Metric* _bbt_metric;
117 static ArdourCanvas::Ruler::Metric* _timecode_metric;
118 static ArdourCanvas::Ruler::Metric* _samples_metric;
119 static ArdourCanvas::Ruler::Metric* _minsec_metric;
122 Editor::initialize_rulers ()
124 ruler_grabbed_widget = 0;
125 Pango::FontDescription font (ARDOUR_UI::config()->get_canvasvar_SmallFont());
127 _timecode_metric = new TimecodeMetric (this);
128 _bbt_metric = new BBTMetric (this);
129 _minsec_metric = new MinsecMetric (this);
130 _samples_metric = new SamplesMetric (this);
132 timecode_ruler = new ArdourCanvas::Ruler (_time_markers_group, *_timecode_metric,
133 ArdourCanvas::Rect (0, 0, ArdourCanvas::COORD_MAX, timebar_height));
134 timecode_ruler->set_font_description (font);
135 CANVAS_DEBUG_NAME (timecode_ruler, "timecode ruler");
138 samples_ruler = new ArdourCanvas::Ruler (_time_markers_group, *_samples_metric,
139 ArdourCanvas::Rect (0, 0, ArdourCanvas::COORD_MAX, timebar_height));
140 samples_ruler->set_font_description (font);
141 CANVAS_DEBUG_NAME (samples_ruler, "samples ruler");
143 minsec_ruler = new ArdourCanvas::Ruler (_time_markers_group, *_minsec_metric,
144 ArdourCanvas::Rect (0, 0, ArdourCanvas::COORD_MAX, timebar_height));
145 minsec_ruler->set_font_description (font);
146 CANVAS_DEBUG_NAME (minsec_ruler, "minsec ruler");
149 bbt_ruler = new ArdourCanvas::Ruler (_time_markers_group, *_bbt_metric,
150 ArdourCanvas::Rect (0, 0, ArdourCanvas::COORD_MAX, timebar_height));
151 bbt_ruler->set_font_description (font);
152 CANVAS_DEBUG_NAME (bbt_ruler, "bbt ruler");
155 using namespace Box_Helpers;
156 BoxList & lab_children = time_bars_vbox.children();
158 lab_children.push_back (Element(minsec_label, PACK_SHRINK, PACK_START));
159 lab_children.push_back (Element(timecode_label, PACK_SHRINK, PACK_START));
160 lab_children.push_back (Element(samples_label, PACK_SHRINK, PACK_START));
161 lab_children.push_back (Element(bbt_label, PACK_SHRINK, PACK_START));
162 lab_children.push_back (Element(meter_label, PACK_SHRINK, PACK_START));
163 lab_children.push_back (Element(tempo_label, PACK_SHRINK, PACK_START));
164 lab_children.push_back (Element(range_mark_label, PACK_SHRINK, PACK_START));
165 lab_children.push_back (Element(transport_mark_label, PACK_SHRINK, PACK_START));
166 lab_children.push_back (Element(cd_mark_label, PACK_SHRINK, PACK_START));
167 lab_children.push_back (Element(mark_label, PACK_SHRINK, PACK_START));
168 lab_children.push_back (Element(videotl_label, PACK_SHRINK, PACK_START));
170 /* 1 event handler to bind them all ... */
172 timecode_ruler->Event.connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_ruler_event), timecode_ruler, TimecodeRulerItem));
173 minsec_ruler->Event.connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_ruler_event), minsec_ruler, MinsecRulerItem));
174 bbt_ruler->Event.connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_ruler_event), bbt_ruler, BBTRulerItem));
175 samples_ruler->Event.connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_ruler_event), samples_ruler, SamplesRulerItem));
177 visible_timebars = 0; /*this will be changed below */
181 Editor::ruler_label_button_release (GdkEventButton* ev)
183 if (Gtkmm2ext::Keyboard::is_context_menu_event (ev)) {
184 Gtk::Menu* m = dynamic_cast<Gtk::Menu*> (ActionManager::get_widget (X_("/RulerMenuPopup")));
186 m->popup (1, ev->time);
194 Editor::popup_ruler_menu (framepos_t where, ItemType t)
196 using namespace Menu_Helpers;
198 if (editor_ruler_menu == 0) {
199 editor_ruler_menu = new Menu;
200 editor_ruler_menu->set_name ("ArdourContextMenu");
203 // always build from scratch
204 MenuList& ruler_items = editor_ruler_menu->items();
205 editor_ruler_menu->set_name ("ArdourContextMenu");
210 ruler_items.push_back (MenuElem (_("New location marker"), sigc::bind ( sigc::mem_fun(*this, &Editor::mouse_add_new_marker), where, false, false)));
211 ruler_items.push_back (MenuElem (_("Clear all locations"), sigc::mem_fun(*this, &Editor::clear_markers)));
212 ruler_items.push_back (MenuElem (_("Unhide locations"), sigc::mem_fun(*this, &Editor::unhide_markers)));
213 ruler_items.push_back (SeparatorElem ());
215 case RangeMarkerBarItem:
216 ruler_items.push_back (MenuElem (_("New range"), sigc::bind (sigc::mem_fun (*this, &Editor::mouse_add_new_range), where)));
217 ruler_items.push_back (MenuElem (_("Clear all ranges"), sigc::mem_fun(*this, &Editor::clear_ranges)));
218 ruler_items.push_back (MenuElem (_("Unhide ranges"), sigc::mem_fun(*this, &Editor::unhide_ranges)));
219 ruler_items.push_back (SeparatorElem ());
222 case TransportMarkerBarItem:
226 case CdMarkerBarItem:
228 ruler_items.push_back (MenuElem (_("New CD track marker"), sigc::bind ( sigc::mem_fun(*this, &Editor::mouse_add_new_marker), where, true, false)));
233 ruler_items.push_back (MenuElem (_("New Tempo"), sigc::bind ( sigc::mem_fun(*this, &Editor::mouse_add_new_tempo_event), where)));
234 ruler_items.push_back (SeparatorElem ());
238 ruler_items.push_back (MenuElem (_("New Meter"), sigc::bind ( sigc::mem_fun(*this, &Editor::mouse_add_new_meter_event), where)));
239 ruler_items.push_back (SeparatorElem ());
243 ruler_items.push_back (MenuElem (_("Timeline height")));
244 static_cast<MenuItem*>(&ruler_items.back())->set_sensitive(false);
245 ruler_items.push_back (CheckMenuElem (_("Large"), sigc::bind ( sigc::mem_fun(*this, &Editor::set_video_timeline_height), 6)));
246 if (videotl_bar_height == 6) { static_cast<Gtk::CheckMenuItem*>(&ruler_items.back())->set_active(true);}
247 ruler_items.push_back (CheckMenuElem (_("Normal"), sigc::bind ( sigc::mem_fun(*this, &Editor::set_video_timeline_height), 4)));
248 if (videotl_bar_height == 4) { static_cast<Gtk::CheckMenuItem*>(&ruler_items.back())->set_active(true);}
249 ruler_items.push_back (CheckMenuElem (_("Small"), sigc::bind ( sigc::mem_fun(*this, &Editor::set_video_timeline_height), 3)));
250 if (videotl_bar_height == 3) { static_cast<Gtk::CheckMenuItem*>(&ruler_items.back())->set_active(true);}
251 ruler_items.push_back (SeparatorElem ());
253 ruler_items.push_back (MenuElem (_("Align Video Track")));
254 static_cast<MenuItem*>(&ruler_items.back())->set_sensitive(false);
256 ruler_items.push_back (CheckMenuElem (_("Lock")));
258 Gtk::CheckMenuItem* vtl_lock = static_cast<Gtk::CheckMenuItem*>(&ruler_items.back());
259 vtl_lock->set_active(is_video_timeline_locked());
260 vtl_lock->signal_activate().connect (sigc::mem_fun(*this, &Editor::toggle_video_timeline_locked));
263 ruler_items.push_back (SeparatorElem ());
270 Glib::RefPtr<Action> action;
272 action = ActionManager::get_action ("Rulers", "toggle-minsec-ruler");
274 ruler_items.push_back (MenuElem (*action->create_menu_item()));
276 if (!Profile->get_sae()) {
277 action = ActionManager::get_action ("Rulers", "toggle-timecode-ruler");
279 ruler_items.push_back (MenuElem (*action->create_menu_item()));
282 action = ActionManager::get_action ("Rulers", "toggle-samples-ruler");
284 ruler_items.push_back (MenuElem (*action->create_menu_item()));
286 action = ActionManager::get_action ("Rulers", "toggle-bbt-ruler");
288 ruler_items.push_back (MenuElem (*action->create_menu_item()));
290 action = ActionManager::get_action ("Rulers", "toggle-meter-ruler");
292 ruler_items.push_back (MenuElem (*action->create_menu_item()));
294 action = ActionManager::get_action ("Rulers", "toggle-tempo-ruler");
296 ruler_items.push_back (MenuElem (*action->create_menu_item()));
298 if (!Profile->get_sae()) {
299 action = ActionManager::get_action ("Rulers", "toggle-range-ruler");
301 ruler_items.push_back (MenuElem (*action->create_menu_item()));
304 action = ActionManager::get_action ("Rulers", "toggle-loop-punch-ruler");
306 ruler_items.push_back (MenuElem (*action->create_menu_item()));
308 action = ActionManager::get_action ("Rulers", "toggle-cd-marker-ruler");
310 ruler_items.push_back (MenuElem (*action->create_menu_item()));
312 action = ActionManager::get_action ("Rulers", "toggle-marker-ruler");
314 ruler_items.push_back (MenuElem (*action->create_menu_item()));
316 action = ActionManager::get_action ("Rulers", "toggle-video-ruler");
318 ruler_items.push_back (MenuElem (*action->create_menu_item()));
321 editor_ruler_menu->popup (1, gtk_get_current_event_time());
323 no_ruler_shown_update = false;
327 Editor::store_ruler_visibility ()
329 XMLNode* node = new XMLNode(X_("RulerVisibility"));
331 node->add_property (X_("timecode"), ruler_timecode_action->get_active() ? "yes": "no");
332 node->add_property (X_("bbt"), ruler_bbt_action->get_active() ? "yes": "no");
333 node->add_property (X_("samples"), ruler_samples_action->get_active() ? "yes": "no");
334 node->add_property (X_("minsec"), ruler_minsec_action->get_active() ? "yes": "no");
335 node->add_property (X_("tempo"), ruler_tempo_action->get_active() ? "yes": "no");
336 node->add_property (X_("meter"), ruler_meter_action->get_active() ? "yes": "no");
337 node->add_property (X_("marker"), ruler_marker_action->get_active() ? "yes": "no");
338 node->add_property (X_("rangemarker"), ruler_range_action->get_active() ? "yes": "no");
339 node->add_property (X_("transportmarker"), ruler_loop_punch_action->get_active() ? "yes": "no");
340 node->add_property (X_("cdmarker"), ruler_cd_marker_action->get_active() ? "yes": "no");
341 node->add_property (X_("videotl"), ruler_video_action->get_active() ? "yes": "no");
343 _session->add_extra_xml (*node);
344 _session->set_dirty ();
348 Editor::restore_ruler_visibility ()
351 XMLNode * node = _session->extra_xml (X_("RulerVisibility"));
353 no_ruler_shown_update = true;
356 if ((prop = node->property ("timecode")) != 0) {
357 if (string_is_affirmative (prop->value())) {
358 ruler_timecode_action->set_active (true);
360 ruler_timecode_action->set_active (false);
363 if ((prop = node->property ("bbt")) != 0) {
364 if (string_is_affirmative (prop->value())) {
365 ruler_bbt_action->set_active (true);
367 ruler_bbt_action->set_active (false);
370 if ((prop = node->property ("samples")) != 0) {
371 if (string_is_affirmative (prop->value())) {
372 ruler_samples_action->set_active (true);
374 ruler_samples_action->set_active (false);
377 if ((prop = node->property ("minsec")) != 0) {
378 if (string_is_affirmative (prop->value())) {
379 ruler_minsec_action->set_active (true);
381 ruler_minsec_action->set_active (false);
384 if ((prop = node->property ("tempo")) != 0) {
385 if (string_is_affirmative (prop->value())) {
386 ruler_tempo_action->set_active (true);
388 ruler_tempo_action->set_active (false);
391 if ((prop = node->property ("meter")) != 0) {
392 if (string_is_affirmative (prop->value())) {
393 ruler_meter_action->set_active (true);
395 ruler_meter_action->set_active (false);
398 if ((prop = node->property ("marker")) != 0) {
399 if (string_is_affirmative (prop->value())) {
400 ruler_marker_action->set_active (true);
402 ruler_marker_action->set_active (false);
405 if ((prop = node->property ("rangemarker")) != 0) {
406 if (string_is_affirmative (prop->value())) {
407 ruler_range_action->set_active (true);
409 ruler_range_action->set_active (false);
413 if ((prop = node->property ("transportmarker")) != 0) {
414 if (string_is_affirmative (prop->value())) {
415 ruler_loop_punch_action->set_active (true);
417 ruler_loop_punch_action->set_active (false);
421 if ((prop = node->property ("cdmarker")) != 0) {
422 if (string_is_affirmative (prop->value())) {
423 ruler_cd_marker_action->set_active (true);
425 ruler_cd_marker_action->set_active (false);
429 // this _session doesn't yet know about the cdmarker ruler
430 // as a benefit to the user who doesn't know the feature exists, show the ruler if
431 // any cd marks exist
432 ruler_cd_marker_action->set_active (false);
433 const Locations::LocationList & locs = _session->locations()->list();
434 for (Locations::LocationList::const_iterator i = locs.begin(); i != locs.end(); ++i) {
435 if ((*i)->is_cd_marker()) {
436 ruler_cd_marker_action->set_active (true);
442 if ((prop = node->property ("videotl")) != 0) {
443 if (string_is_affirmative (prop->value())) {
444 ruler_video_action->set_active (true);
446 ruler_video_action->set_active (false);
452 no_ruler_shown_update = false;
453 update_ruler_visibility ();
457 Editor::update_ruler_visibility ()
459 int visible_timebars = 0;
461 if (no_ruler_shown_update) {
465 /* the order of the timebars is fixed, so we have to go through each one
466 * and adjust its position depending on what is shown.
468 * Order: minsec, timecode, samples, bbt, meter, tempo, ranges,
469 * loop/punch, cd markers, location markers
477 /* gtk update probs require this (damn) */
480 range_mark_label.hide();
481 transport_mark_label.hide();
482 cd_mark_label.hide();
484 videotl_label.hide();
487 if (ruler_minsec_action->get_active()) {
488 old_unit_pos = minsec_ruler->position().y;
489 if (tbpos != old_unit_pos) {
490 minsec_ruler->move (ArdourCanvas::Duple (0.0, tbpos - old_unit_pos));
492 minsec_ruler->show();
494 tbpos += timebar_height;
495 tbgpos += timebar_height;
498 minsec_ruler->hide();
502 if (ruler_timecode_action->get_active()) {
503 old_unit_pos = timecode_ruler->position().y;
504 if (tbpos != old_unit_pos) {
505 timecode_ruler->move (ArdourCanvas::Duple (0.0, tbpos - old_unit_pos));
507 timecode_ruler->show();
508 timecode_label.show();
509 tbpos += timebar_height;
510 tbgpos += timebar_height;
513 timecode_ruler->hide();
514 timecode_label.hide();
517 if (ruler_samples_action->get_active()) {
518 old_unit_pos = samples_ruler->position().y;
519 if (tbpos != old_unit_pos) {
520 samples_ruler->move (ArdourCanvas::Duple (0.0, tbpos - old_unit_pos));
522 samples_ruler->show();
523 samples_label.show();
524 tbpos += timebar_height;
525 tbgpos += timebar_height;
528 samples_ruler->hide();
529 samples_label.hide();
532 if (ruler_bbt_action->get_active()) {
533 old_unit_pos = bbt_ruler->position().y;
534 if (tbpos != old_unit_pos) {
535 bbt_ruler->move (ArdourCanvas::Duple (0.0, tbpos - old_unit_pos));
539 tbpos += timebar_height;
540 tbgpos += timebar_height;
547 if (ruler_meter_action->get_active()) {
548 old_unit_pos = meter_group->position().y;
549 if (tbpos != old_unit_pos) {
550 meter_group->move (ArdourCanvas::Duple (0.0, tbpos - old_unit_pos));
554 tbpos += timebar_height;
555 tbgpos += timebar_height;
562 if (ruler_tempo_action->get_active()) {
563 old_unit_pos = tempo_group->position().y;
564 if (tbpos != old_unit_pos) {
565 tempo_group->move (ArdourCanvas::Duple (0.0, tbpos - old_unit_pos));
569 tbpos += timebar_height;
570 tbgpos += timebar_height;
577 if (!Profile->get_sae() && ruler_range_action->get_active()) {
578 old_unit_pos = range_marker_group->position().y;
579 if (tbpos != old_unit_pos) {
580 range_marker_group->move (ArdourCanvas::Duple (0.0, tbpos - old_unit_pos));
582 range_marker_group->show();
583 range_mark_label.show();
585 tbpos += timebar_height;
586 tbgpos += timebar_height;
589 range_marker_group->hide();
590 range_mark_label.hide();
593 if (ruler_loop_punch_action->get_active()) {
594 old_unit_pos = transport_marker_group->position().y;
595 if (tbpos != old_unit_pos) {
596 transport_marker_group->move (ArdourCanvas::Duple (0.0, tbpos - old_unit_pos));
598 transport_marker_group->show();
599 transport_mark_label.show();
600 tbpos += timebar_height;
601 tbgpos += timebar_height;
604 transport_marker_group->hide();
605 transport_mark_label.hide();
608 if (ruler_cd_marker_action->get_active()) {
609 old_unit_pos = cd_marker_group->position().y;
610 if (tbpos != old_unit_pos) {
611 cd_marker_group->move (ArdourCanvas::Duple (0.0, tbpos - old_unit_pos));
613 cd_marker_group->show();
614 cd_mark_label.show();
615 tbpos += timebar_height;
616 tbgpos += timebar_height;
618 // make sure all cd markers show up in their respective places
619 update_cd_marker_display();
621 cd_marker_group->hide();
622 cd_mark_label.hide();
623 // make sure all cd markers show up in their respective places
624 update_cd_marker_display();
627 if (ruler_marker_action->get_active()) {
628 old_unit_pos = marker_group->position().y;
629 if (tbpos != old_unit_pos) {
630 marker_group->move (ArdourCanvas::Duple (0.0, tbpos - old_unit_pos));
632 marker_group->show();
634 tbpos += timebar_height;
635 tbgpos += timebar_height;
638 marker_group->hide();
642 if (ruler_video_action->get_active()) {
643 old_unit_pos = videotl_group->position().y;
644 if (tbpos != old_unit_pos) {
645 videotl_group->move (ArdourCanvas::Duple (0.0, tbpos - old_unit_pos));
647 videotl_group->show();
648 videotl_label.show();
649 tbpos += timebar_height * videotl_bar_height;
650 tbgpos += timebar_height * videotl_bar_height;
651 visible_timebars+=videotl_bar_height;
652 queue_visual_videotimeline_update();
654 videotl_group->hide();
655 videotl_label.hide();
656 update_video_timeline(true);
659 time_bars_vbox.set_size_request (-1, (int)(timebar_height * visible_timebars));
661 /* move hv_scroll_group (trackviews) to the end of the timebars
664 hv_scroll_group->set_y_position (timebar_height * visible_timebars);
666 compute_fixed_ruler_scale ();
667 update_fixed_rulers();
668 redisplay_tempo (false);
670 /* Changing ruler visibility means that any lines on markers might need updating */
671 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
672 i->second->setup_lines ();
677 Editor::update_just_timecode ()
679 ENSURE_GUI_THREAD (*this, &Editor::update_just_timecode)
685 framepos_t rightmost_frame = leftmost_frame + current_page_samples();
687 if (ruler_timecode_action->get_active()) {
688 timecode_ruler->set_range (leftmost_frame, rightmost_frame);
693 Editor::compute_fixed_ruler_scale ()
699 if (ruler_timecode_action->get_active()) {
700 set_timecode_ruler_scale (leftmost_frame, leftmost_frame + current_page_samples());
703 if (ruler_minsec_action->get_active()) {
704 set_minsec_ruler_scale (leftmost_frame, leftmost_frame + current_page_samples());
707 if (ruler_samples_action->get_active()) {
708 set_samples_ruler_scale (leftmost_frame, leftmost_frame + current_page_samples());
713 Editor::update_fixed_rulers ()
715 framepos_t rightmost_frame;
721 compute_fixed_ruler_scale ();
723 _timecode_metric->units_per_pixel = samples_per_pixel;
724 _samples_metric->units_per_pixel = samples_per_pixel;
725 _minsec_metric->units_per_pixel = samples_per_pixel;
727 rightmost_frame = leftmost_frame + current_page_samples();
729 /* these force a redraw, which in turn will force execution of the metric callbacks
730 to compute the relevant ticks to display.
733 if (ruler_timecode_action->get_active()) {
734 timecode_ruler->set_range (leftmost_frame, rightmost_frame);
737 if (ruler_samples_action->get_active()) {
738 samples_ruler->set_range (leftmost_frame, rightmost_frame);
741 if (ruler_minsec_action->get_active()) {
742 minsec_ruler->set_range (leftmost_frame, rightmost_frame);
747 Editor::update_tempo_based_rulers (ARDOUR::TempoMap::BBTPointList::const_iterator& begin,
748 ARDOUR::TempoMap::BBTPointList::const_iterator& end)
754 compute_bbt_ruler_scale (leftmost_frame, leftmost_frame+current_page_samples(),
757 _bbt_metric->units_per_pixel = samples_per_pixel;
759 if (ruler_bbt_action->get_active()) {
760 bbt_ruler->set_range (leftmost_frame, leftmost_frame+current_page_samples());
765 Editor::set_timecode_ruler_scale (framepos_t lower, framepos_t upper)
774 fr = _session->frame_rate();
776 if (lower > (spacer = (framepos_t) (128 * Editor::get_current_zoom ()))) {
777 lower = lower - spacer;
781 upper = upper + spacer;
782 framecnt_t const range = upper - lower;
784 if (range < (2 * _session->frames_per_timecode_frame())) { /* 0 - 2 frames */
785 timecode_ruler_scale = timecode_show_bits;
786 timecode_mark_modulo = 20;
787 timecode_nmarks = 2 + (2 * _session->config.get_subframes_per_frame());
788 } else if (range <= (fr / 4)) { /* 2 frames - 0.250 second */
789 timecode_ruler_scale = timecode_show_frames;
790 timecode_mark_modulo = 1;
791 timecode_nmarks = 2 + (range / (framepos_t)_session->frames_per_timecode_frame());
792 } else if (range <= (fr / 2)) { /* 0.25-0.5 second */
793 timecode_ruler_scale = timecode_show_frames;
794 timecode_mark_modulo = 2;
795 timecode_nmarks = 2 + (range / (framepos_t)_session->frames_per_timecode_frame());
796 } else if (range <= fr) { /* 0.5-1 second */
797 timecode_ruler_scale = timecode_show_frames;
798 timecode_mark_modulo = 5;
799 timecode_nmarks = 2 + (range / (framepos_t)_session->frames_per_timecode_frame());
800 } else if (range <= 2 * fr) { /* 1-2 seconds */
801 timecode_ruler_scale = timecode_show_frames;
802 timecode_mark_modulo = 10;
803 timecode_nmarks = 2 + (range / (framepos_t)_session->frames_per_timecode_frame());
804 } else if (range <= 8 * fr) { /* 2-8 seconds */
805 timecode_ruler_scale = timecode_show_seconds;
806 timecode_mark_modulo = 1;
807 timecode_nmarks = 2 + (range / fr);
808 } else if (range <= 16 * fr) { /* 8-16 seconds */
809 timecode_ruler_scale = timecode_show_seconds;
810 timecode_mark_modulo = 2;
811 timecode_nmarks = 2 + (range / fr);
812 } else if (range <= 30 * fr) { /* 16-30 seconds */
813 timecode_ruler_scale = timecode_show_seconds;
814 timecode_mark_modulo = 5;
815 timecode_nmarks = 2 + (range / fr);
816 } else if (range <= 60 * fr) { /* 30-60 seconds */
817 timecode_ruler_scale = timecode_show_seconds;
818 timecode_mark_modulo = 5;
819 timecode_nmarks = 2 + (range / fr);
820 } else if (range <= 2 * 60 * fr) { /* 1-2 minutes */
821 timecode_ruler_scale = timecode_show_seconds;
822 timecode_mark_modulo = 15;
823 timecode_nmarks = 2 + (range / fr);
824 } else if (range <= 4 * 60 * fr) { /* 2-4 minutes */
825 timecode_ruler_scale = timecode_show_seconds;
826 timecode_mark_modulo = 30;
827 timecode_nmarks = 2 + (range / fr);
828 } else if (range <= 10 * 60 * fr) { /* 4-10 minutes */
829 timecode_ruler_scale = timecode_show_minutes;
830 timecode_mark_modulo = 2;
831 timecode_nmarks = 2 + 10;
832 } else if (range <= 30 * 60 * fr) { /* 10-30 minutes */
833 timecode_ruler_scale = timecode_show_minutes;
834 timecode_mark_modulo = 5;
835 timecode_nmarks = 2 + 30;
836 } else if (range <= 60 * 60 * fr) { /* 30 minutes - 1hr */
837 timecode_ruler_scale = timecode_show_minutes;
838 timecode_mark_modulo = 10;
839 timecode_nmarks = 2 + 60;
840 } else if (range <= 4 * 60 * 60 * fr) { /* 1 - 4 hrs*/
841 timecode_ruler_scale = timecode_show_minutes;
842 timecode_mark_modulo = 30;
843 timecode_nmarks = 2 + (60 * 4);
844 } else if (range <= 8 * 60 * 60 * fr) { /* 4 - 8 hrs*/
845 timecode_ruler_scale = timecode_show_hours;
846 timecode_mark_modulo = 1;
847 timecode_nmarks = 2 + 8;
848 } else if (range <= 16 * 60 * 60 * fr) { /* 16-24 hrs*/
849 timecode_ruler_scale = timecode_show_hours;
850 timecode_mark_modulo = 1;
851 timecode_nmarks = 2 + 24;
854 /* not possible if framepos_t is a 32 bit quantity */
856 timecode_ruler_scale = timecode_show_hours;
857 timecode_mark_modulo = 4;
858 timecode_nmarks = 2 + 24;
864 Editor::metric_get_timecode (std::vector<ArdourCanvas::Ruler::Mark>& marks, gdouble lower, gdouble /*upper*/, gint /*maxchars*/)
868 Timecode::Time timecode;
871 ArdourCanvas::Ruler::Mark mark;
877 if (lower > (spacer = (framecnt_t)(128 * Editor::get_current_zoom ()))) {
878 lower = lower - spacer;
883 pos = (framecnt_t) floor (lower);
885 switch (timecode_ruler_scale) {
886 case timecode_show_bits:
888 // Find timecode time of this sample (pos) with subframe accuracy
889 _session->sample_to_timecode(pos, timecode, true /* use_offset */, true /* use_subframes */ );
891 for (n = 0; n < timecode_nmarks; n++) {
892 _session->timecode_to_sample(timecode, pos, true /* use_offset */, true /* use_subframes */ );
893 if ((timecode.subframes % timecode_mark_modulo) == 0) {
894 if (timecode.subframes == 0) {
895 mark.style = ArdourCanvas::Ruler::Mark::Major;
896 snprintf (buf, sizeof(buf), "%s%02u:%02u:%02u:%02u", timecode.negative ? "-" : "", timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
898 mark.style = ArdourCanvas::Ruler::Mark::Minor;
899 snprintf (buf, sizeof(buf), ".%02u", timecode.subframes);
902 snprintf (buf, sizeof(buf)," ");
903 mark.style = ArdourCanvas::Ruler::Mark::Micro;
909 marks.push_back (mark);
911 // Increment subframes by one
912 Timecode::increment_subframes( timecode, _session->config.get_subframes_per_frame() );
915 case timecode_show_seconds:
916 // Find timecode time of this sample (pos)
917 _session->sample_to_timecode(pos, timecode, true /* use_offset */, false /* use_subframes */ );
918 // Go to next whole second down
919 Timecode::seconds_floor( timecode );
921 for (n = 0; n < timecode_nmarks; n++) {
922 _session->timecode_to_sample(timecode, pos, true /* use_offset */, false /* use_subframes */ );
923 if ((timecode.seconds % timecode_mark_modulo) == 0) {
924 if (timecode.seconds == 0) {
925 mark.style = ArdourCanvas::Ruler::Mark::Major;
928 mark.style = ArdourCanvas::Ruler::Mark::Minor;
931 snprintf (buf, sizeof(buf), "%s%02u:%02u:%02u:%02u", timecode.negative ? "-" : "", timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
933 snprintf (buf, sizeof(buf)," ");
934 mark.style = ArdourCanvas::Ruler::Mark::Micro;
939 marks.push_back (mark);
941 Timecode::increment_seconds( timecode, _session->config.get_subframes_per_frame() );
944 case timecode_show_minutes:
945 // Find timecode time of this sample (pos)
946 _session->sample_to_timecode(pos, timecode, true /* use_offset */, false /* use_subframes */ );
947 // Go to next whole minute down
948 Timecode::minutes_floor( timecode );
950 for (n = 0; n < timecode_nmarks; n++) {
951 _session->timecode_to_sample(timecode, pos, true /* use_offset */, false /* use_subframes */ );
952 if ((timecode.minutes % timecode_mark_modulo) == 0) {
953 if (timecode.minutes == 0) {
954 mark.style = ArdourCanvas::Ruler::Mark::Major;
956 mark.style = ArdourCanvas::Ruler::Mark::Minor;
958 snprintf (buf, sizeof(buf), "%s%02u:%02u:%02u:%02u", timecode.negative ? "-" : "", timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
960 snprintf (buf, sizeof(buf)," ");
961 mark.style = ArdourCanvas::Ruler::Mark::Micro;
966 marks.push_back (mark);
967 Timecode::increment_minutes( timecode, _session->config.get_subframes_per_frame() );
971 case timecode_show_hours:
972 // Find timecode time of this sample (pos)
973 _session->sample_to_timecode(pos, timecode, true /* use_offset */, false /* use_subframes */ );
974 // Go to next whole hour down
975 Timecode::hours_floor( timecode );
977 for (n = 0; n < timecode_nmarks; n++) {
978 _session->timecode_to_sample(timecode, pos, true /* use_offset */, false /* use_subframes */ );
979 if ((timecode.hours % timecode_mark_modulo) == 0) {
980 mark.style = ArdourCanvas::Ruler::Mark::Major;
981 snprintf (buf, sizeof(buf), "%s%02u:%02u:%02u:%02u", timecode.negative ? "-" : "", timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
983 snprintf (buf, sizeof(buf)," ");
984 mark.style = ArdourCanvas::Ruler::Mark::Micro;
989 marks.push_back (mark);
990 Timecode::increment_hours( timecode, _session->config.get_subframes_per_frame() );
993 case timecode_show_frames:
994 // Find timecode time of this sample (pos)
995 _session->sample_to_timecode(pos, timecode, true /* use_offset */, false /* use_subframes */ );
996 // Go to next whole frame down
997 Timecode::frames_floor( timecode );
999 for (n = 0; n < timecode_nmarks; n++) {
1000 _session->timecode_to_sample(timecode, pos, true /* use_offset */, false /* use_subframes */ );
1001 if ((timecode.frames % timecode_mark_modulo) == 0) {
1002 if (timecode.frames == 0) {
1003 mark.style = ArdourCanvas::Ruler::Mark::Major;
1005 mark.style = ArdourCanvas::Ruler::Mark::Minor;
1007 mark.position = pos;
1008 snprintf (buf, sizeof(buf), "%s%02u:%02u:%02u:%02u", timecode.negative ? "-" : "", timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
1010 snprintf (buf, sizeof(buf)," ");
1011 mark.style = ArdourCanvas::Ruler::Mark::Micro;
1012 mark.position = pos;
1016 marks.push_back (mark);
1017 Timecode::increment( timecode, _session->config.get_subframes_per_frame() );
1027 Editor::compute_bbt_ruler_scale (framepos_t lower, framepos_t upper,
1028 ARDOUR::TempoMap::BBTPointList::const_iterator begin,
1029 ARDOUR::TempoMap::BBTPointList::const_iterator end)
1031 if (_session == 0) {
1035 TempoMap::BBTPointList::const_iterator i;
1036 Timecode::BBT_Time lower_beat, upper_beat; // the beats at each end of the ruler
1038 _session->bbt_time (lower, lower_beat);
1039 _session->bbt_time (upper, upper_beat);
1042 bbt_accent_modulo = 1;
1043 bbt_bar_helper_on = false;
1047 bbt_ruler_scale = bbt_over;
1049 switch (_snap_type) {
1050 case SnapToBeatDiv2:
1051 bbt_beat_subdivision = 2;
1053 case SnapToBeatDiv3:
1054 bbt_beat_subdivision = 3;
1056 case SnapToBeatDiv4:
1057 bbt_beat_subdivision = 4;
1059 case SnapToBeatDiv5:
1060 bbt_beat_subdivision = 5;
1061 bbt_accent_modulo = 2; // XXX YIKES
1063 case SnapToBeatDiv6:
1064 bbt_beat_subdivision = 6;
1065 bbt_accent_modulo = 2; // XXX YIKES
1067 case SnapToBeatDiv7:
1068 bbt_beat_subdivision = 7;
1069 bbt_accent_modulo = 2; // XXX YIKES
1071 case SnapToBeatDiv8:
1072 bbt_beat_subdivision = 8;
1073 bbt_accent_modulo = 2;
1075 case SnapToBeatDiv10:
1076 bbt_beat_subdivision = 10;
1077 bbt_accent_modulo = 2; // XXX YIKES
1079 case SnapToBeatDiv12:
1080 bbt_beat_subdivision = 12;
1081 bbt_accent_modulo = 3;
1083 case SnapToBeatDiv14:
1084 bbt_beat_subdivision = 14;
1085 bbt_accent_modulo = 3; // XXX YIKES!
1087 case SnapToBeatDiv16:
1088 bbt_beat_subdivision = 16;
1089 bbt_accent_modulo = 4;
1091 case SnapToBeatDiv20:
1092 bbt_beat_subdivision = 20;
1093 bbt_accent_modulo = 5;
1095 case SnapToBeatDiv24:
1096 bbt_beat_subdivision = 24;
1097 bbt_accent_modulo = 6;
1099 case SnapToBeatDiv28:
1100 bbt_beat_subdivision = 28;
1101 bbt_accent_modulo = 7;
1103 case SnapToBeatDiv32:
1104 bbt_beat_subdivision = 32;
1105 bbt_accent_modulo = 8;
1107 case SnapToBeatDiv64:
1108 bbt_beat_subdivision = 64;
1109 bbt_accent_modulo = 8;
1111 case SnapToBeatDiv128:
1112 bbt_beat_subdivision = 128;
1113 bbt_accent_modulo = 8;
1116 bbt_beat_subdivision = 4;
1120 if (distance (begin, end) == 0) {
1126 if ((*i).beat >= (*begin).beat) {
1127 bbt_bars = (*i).bar - (*begin).bar;
1129 bbt_bars = (*i).bar - (*begin).bar - 1;
1131 beats = distance (begin, end) - bbt_bars;
1133 /* Only show the bar helper if there aren't many bars on the screen */
1134 if ((bbt_bars < 2) || (beats < 5)) {
1135 bbt_bar_helper_on = true;
1138 if (bbt_bars > 8192) {
1139 bbt_ruler_scale = bbt_over;
1140 } else if (bbt_bars > 1024) {
1141 bbt_ruler_scale = bbt_show_64;
1142 } else if (bbt_bars > 256) {
1143 bbt_ruler_scale = bbt_show_16;
1144 } else if (bbt_bars > 64) {
1145 bbt_ruler_scale = bbt_show_4;
1146 } else if (bbt_bars > 10) {
1147 bbt_ruler_scale = bbt_show_1;
1148 } else if (bbt_bars > 2) {
1149 bbt_ruler_scale = bbt_show_beats;
1150 } else if (bbt_bars > 0) {
1151 bbt_ruler_scale = bbt_show_ticks;
1153 bbt_ruler_scale = bbt_show_ticks_detail;
1156 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)) {
1157 bbt_ruler_scale = bbt_show_ticks_super_detail;
1162 edit_last_mark_label (std::vector<ArdourCanvas::Ruler::Mark>& marks, const std::string& newlabel)
1164 ArdourCanvas::Ruler::Mark copy = marks.back();
1165 copy.label = newlabel;
1167 marks.push_back (copy);
1171 Editor::metric_get_bbt (std::vector<ArdourCanvas::Ruler::Mark>& marks, gdouble lower, gdouble upper, gint /*maxchars*/)
1173 if (_session == 0) {
1177 TempoMap::BBTPointList::const_iterator i;
1182 Timecode::BBT_Time next_beat;
1183 framepos_t next_beat_pos;
1188 framepos_t frame_skip;
1189 double frame_skip_error;
1190 double bbt_position_of_helper;
1191 double accumulated_error;
1192 bool i_am_accented = false;
1193 bool helper_active = false;
1194 ArdourCanvas::Ruler::Mark mark;
1196 ARDOUR::TempoMap::BBTPointList::const_iterator begin;
1197 ARDOUR::TempoMap::BBTPointList::const_iterator end;
1199 compute_current_bbt_points (lower, upper, begin, end);
1201 if (distance (begin, end) == 0) {
1205 switch (bbt_ruler_scale) {
1207 case bbt_show_beats:
1208 beats = distance (begin, end);
1209 bbt_nmarks = beats + 2;
1212 mark.position = lower;
1213 mark.style = ArdourCanvas::Ruler::Mark::Micro;
1214 marks.push_back (mark);
1216 for (n = 1, i = begin; n < bbt_nmarks && i != end; ++i) {
1218 if ((*i).frame < lower && (bbt_bar_helper_on)) {
1219 snprintf (buf, sizeof(buf), "<%" PRIu32 "|%" PRIu32, (*i).bar, (*i).beat);
1220 edit_last_mark_label (marks, buf);
1221 helper_active = true;
1224 if ((*i).is_bar()) {
1225 mark.style = ArdourCanvas::Ruler::Mark::Major;
1226 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1227 } else if (((*i).beat % 2 == 1)) {
1228 mark.style = ArdourCanvas::Ruler::Mark::Minor;
1231 mark.style = ArdourCanvas::Ruler::Mark::Micro;
1235 mark.position = (*i).frame;
1236 marks.push_back (mark);
1242 case bbt_show_ticks:
1244 beats = distance (begin, end);
1245 bbt_nmarks = (beats + 2) * bbt_beat_subdivision;
1247 bbt_position_of_helper = lower + (30 * Editor::get_current_zoom ());
1249 // could do marks.assign() here to preallocate
1252 mark.position = lower;
1253 mark.style = ArdourCanvas::Ruler::Mark::Micro;
1254 marks.push_back (mark);
1256 for (n = 1, i = begin; n < bbt_nmarks && i != end; ++i) {
1258 if ((*i).frame < lower && (bbt_bar_helper_on)) {
1259 snprintf (buf, sizeof(buf), "<%" PRIu32 "|%" PRIu32, (*i).bar, (*i).beat);
1260 edit_last_mark_label (marks, buf);
1261 helper_active = true;
1264 if ((*i).is_bar()) {
1265 mark.style = ArdourCanvas::Ruler::Mark::Major;
1266 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1268 mark.style = ArdourCanvas::Ruler::Mark::Minor;
1269 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).beat);
1271 if (((*i).frame < bbt_position_of_helper) && helper_active) {
1275 mark.position = (*i).frame;
1276 marks.push_back (mark);
1280 /* Add the tick marks */
1282 /* Find the next beat */
1283 next_beat.beats = (*i).beat;
1284 next_beat.bars = (*i).bar;
1285 next_beat.ticks = 0;
1287 if ((*i).meter->divisions_per_bar() > (next_beat.beats + 1)) {
1288 next_beat.beats += 1;
1290 next_beat.bars += 1;
1291 next_beat.beats = 1;
1294 next_beat_pos = _session->tempo_map().frame_time(next_beat);
1296 frame_skip = (framepos_t) floor (frame_skip_error = (_session->frame_rate() * 60) / (bbt_beat_subdivision * (*i).tempo->beats_per_minute()));
1297 frame_skip_error -= frame_skip;
1298 skip = (uint32_t) (Timecode::BBT_Time::ticks_per_beat / bbt_beat_subdivision);
1300 pos = (*i).frame + frame_skip;
1301 accumulated_error = frame_skip_error;
1305 for (t = 0; (tick < Timecode::BBT_Time::ticks_per_beat) && (n < bbt_nmarks) && (pos < next_beat_pos) ; pos += frame_skip, tick += skip, ++t) {
1307 if (t % bbt_accent_modulo == (bbt_accent_modulo - 1)) {
1308 i_am_accented = true;
1313 /* Error compensation for float to framepos_t*/
1314 accumulated_error += frame_skip_error;
1315 if (accumulated_error > 1) {
1317 accumulated_error -= 1.0f;
1320 mark.position = pos;
1322 if ((bbt_beat_subdivision > 4) && i_am_accented) {
1323 mark.style = ArdourCanvas::Ruler::Mark::Minor;
1325 mark.style = ArdourCanvas::Ruler::Mark::Micro;
1327 i_am_accented = false;
1328 marks.push_back (mark);
1335 case bbt_show_ticks_detail:
1337 beats = distance (begin, end);
1338 bbt_nmarks = (beats + 2) * bbt_beat_subdivision;
1340 bbt_position_of_helper = lower + (30 * Editor::get_current_zoom ());
1343 mark.position = lower;
1344 mark.style = ArdourCanvas::Ruler::Mark::Micro;
1345 marks.push_back (mark);
1347 for (n = 1, i = begin; n < bbt_nmarks && i != end; ++i) {
1349 if ((*i).frame < lower && (bbt_bar_helper_on)) {
1350 snprintf (buf, sizeof(buf), "<%" PRIu32 "|%" PRIu32, (*i).bar, (*i).beat);
1351 edit_last_mark_label (marks, buf);
1352 helper_active = true;
1355 if ((*i).is_bar()) {
1356 mark.style = ArdourCanvas::Ruler::Mark::Major;
1357 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1359 mark.style = ArdourCanvas::Ruler::Mark::Minor;
1360 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).beat);
1362 if (((*i).frame < bbt_position_of_helper) && helper_active) {
1366 mark.position = (*i).frame;
1367 marks.push_back (mark);
1371 /* Add the tick marks */
1373 /* Find the next beat */
1375 next_beat.beats = (*i).beat;
1376 next_beat.bars = (*i).bar;
1378 if ((*i).meter->divisions_per_bar() > (next_beat.beats + 1)) {
1379 next_beat.beats += 1;
1381 next_beat.bars += 1;
1382 next_beat.beats = 1;
1385 next_beat_pos = _session->tempo_map().frame_time(next_beat);
1387 frame_skip = (framepos_t) floor (frame_skip_error = (_session->frame_rate() * 60) / (bbt_beat_subdivision * (*i).tempo->beats_per_minute()));
1388 frame_skip_error -= frame_skip;
1389 skip = (uint32_t) (Timecode::BBT_Time::ticks_per_beat / bbt_beat_subdivision);
1391 pos = (*i).frame + frame_skip;
1392 accumulated_error = frame_skip_error;
1396 for (t = 0; (tick < Timecode::BBT_Time::ticks_per_beat) && (n < bbt_nmarks) && (pos < next_beat_pos) ; pos += frame_skip, tick += skip, ++t) {
1398 if (t % bbt_accent_modulo == (bbt_accent_modulo - 1)) {
1399 i_am_accented = true;
1402 if (i_am_accented && (pos > bbt_position_of_helper)){
1403 snprintf (buf, sizeof(buf), "%" PRIu32, tick);
1410 /* Error compensation for float to framepos_t*/
1411 accumulated_error += frame_skip_error;
1412 if (accumulated_error > 1) {
1414 accumulated_error -= 1.0f;
1417 mark.position = pos;
1419 if ((bbt_beat_subdivision > 4) && i_am_accented) {
1420 mark.style = ArdourCanvas::Ruler::Mark::Minor;
1422 mark.style = ArdourCanvas::Ruler::Mark::Micro;
1424 i_am_accented = false;
1431 case bbt_show_ticks_super_detail:
1433 beats = distance (begin, end);
1434 bbt_nmarks = (beats + 2) * bbt_beat_subdivision;
1436 bbt_position_of_helper = lower + (30 * Editor::get_current_zoom ());
1439 mark.position = lower;
1440 mark.style = ArdourCanvas::Ruler::Mark::Micro;
1441 marks.push_back (mark);
1443 for (n = 1, i = begin; n < bbt_nmarks && i != end; ++i) {
1445 if ((*i).frame < lower && (bbt_bar_helper_on)) {
1446 snprintf (buf, sizeof(buf), "<%" PRIu32 "|%" PRIu32, (*i).bar, (*i).beat);
1447 edit_last_mark_label (marks, buf);
1448 helper_active = true;
1451 if ((*i).is_bar()) {
1452 mark.style = ArdourCanvas::Ruler::Mark::Major;
1453 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1455 mark.style = ArdourCanvas::Ruler::Mark::Minor;
1456 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).beat);
1458 if (((*i).frame < bbt_position_of_helper) && helper_active) {
1462 mark.position = (*i).frame;
1463 marks.push_back (mark);
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->divisions_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 (pos > bbt_position_of_helper) {
1499 snprintf (buf, sizeof(buf), "%" PRIu32, tick);
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 mark.position = pos;
1515 if ((bbt_beat_subdivision > 4) && i_am_accented) {
1516 mark.style = ArdourCanvas::Ruler::Mark::Minor;
1518 mark.style = ArdourCanvas::Ruler::Mark::Micro;
1520 i_am_accented = false;
1521 marks.push_back (mark);
1530 snprintf (buf, sizeof(buf), "cannot handle %" PRIu32 " bars", bbt_bars );
1531 mark.style = ArdourCanvas::Ruler::Mark::Major;
1533 mark.position = lower;
1534 marks.push_back (mark);
1539 bbt_nmarks = (gint) (bbt_bars / 64) + 1;
1540 for (n = 0, i = begin; i != end && n < bbt_nmarks; i++) {
1541 if ((*i).is_bar()) {
1542 if ((*i).bar % 64 == 1) {
1543 if ((*i).bar % 256 == 1) {
1544 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1545 mark.style = ArdourCanvas::Ruler::Mark::Major;
1548 if ((*i).bar % 256 == 129) {
1549 mark.style = ArdourCanvas::Ruler::Mark::Minor;
1551 mark.style = ArdourCanvas::Ruler::Mark::Micro;
1555 mark.position = (*i).frame;
1556 marks.push_back (mark);
1564 bbt_nmarks = (bbt_bars / 16) + 1;
1565 for (n = 0, i = begin; i != end && n < bbt_nmarks; i++) {
1566 if ((*i).is_bar()) {
1567 if ((*i).bar % 16 == 1) {
1568 if ((*i).bar % 64 == 1) {
1569 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1570 mark.style = ArdourCanvas::Ruler::Mark::Major;
1573 if ((*i).bar % 64 == 33) {
1574 mark.style = ArdourCanvas::Ruler::Mark::Minor;
1576 mark.style = ArdourCanvas::Ruler::Mark::Micro;
1580 mark.position = (*i).frame;
1581 marks.push_back (mark);
1589 bbt_nmarks = (bbt_bars / 4) + 1;
1590 for (n = 0, i = begin; i != end && n < bbt_nmarks; ++i) {
1591 if ((*i).is_bar()) {
1592 if ((*i).bar % 4 == 1) {
1593 if ((*i).bar % 16 == 1) {
1594 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1595 mark.style = ArdourCanvas::Ruler::Mark::Major;
1598 if ((*i).bar % 16 == 9) {
1599 mark.style = ArdourCanvas::Ruler::Mark::Minor;
1601 mark.style = ArdourCanvas::Ruler::Mark::Micro;
1605 mark.position = (*i).frame;
1606 marks.push_back (mark);
1615 bbt_nmarks = bbt_bars + 2;
1616 for (n = 0, i = begin; i != end && n < bbt_nmarks; ++i) {
1617 if ((*i).is_bar()) {
1618 if ((*i).bar % 4 == 1) {
1619 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1620 mark.style = ArdourCanvas::Ruler::Mark::Major;
1623 if ((*i).bar % 4 == 3) {
1624 mark.style = ArdourCanvas::Ruler::Mark::Minor;
1626 mark.style = ArdourCanvas::Ruler::Mark::Micro;
1630 mark.position = (*i).frame;
1631 marks.push_back (mark);
1641 Editor::set_samples_ruler_scale (framepos_t lower, framepos_t upper)
1643 _samples_ruler_interval = (upper - lower) / 5;
1647 Editor::metric_get_samples (std::vector<ArdourCanvas::Ruler::Mark>& marks, gdouble lower, gdouble /*upper*/, gint /*maxchars*/)
1650 framepos_t const ilower = (framepos_t) floor (lower);
1654 ArdourCanvas::Ruler::Mark mark;
1656 if (_session == 0) {
1661 for (n = 0, pos = ilower; n < nmarks; pos += _samples_ruler_interval, ++n) {
1662 snprintf (buf, sizeof(buf), "%" PRIi64, pos);
1664 mark.position = pos;
1665 mark.style = ArdourCanvas::Ruler::Mark::Major;
1666 marks.push_back (mark);
1671 sample_to_clock_parts ( framepos_t sample,
1672 framepos_t sample_rate,
1686 hrs = left / (sample_rate * 60 * 60 * 1000);
1687 left -= hrs * sample_rate * 60 * 60 * 1000;
1688 mins = left / (sample_rate * 60 * 1000);
1689 left -= mins * sample_rate * 60 * 1000;
1690 secs = left / (sample_rate * 1000);
1691 left -= secs * sample_rate * 1000;
1692 millisecs = left / sample_rate;
1694 *millisecs_p = millisecs;
1703 Editor::set_minsec_ruler_scale (framepos_t lower, framepos_t upper)
1708 if (_session == 0) {
1712 fr = _session->frame_rate() * 1000;
1714 /* to prevent 'flashing' */
1715 if (lower > (spacer = (framepos_t)(128 * Editor::get_current_zoom ()))) {
1721 framecnt_t const range = (upper - lower) * 1000;
1723 if (range < (fr / 50)) {
1724 minsec_mark_interval = fr / 1000; /* show 1/1000 seconds */
1725 minsec_ruler_scale = minsec_show_frames;
1726 minsec_mark_modulo = 10;
1727 } else if (range <= (fr / 10)) { /* 0-0.1 second */
1728 minsec_mark_interval = fr / 1000; /* show 1/1000 seconds */
1729 minsec_ruler_scale = minsec_show_frames;
1730 minsec_mark_modulo = 10;
1731 } else if (range <= (fr / 2)) { /* 0-0.5 second */
1732 minsec_mark_interval = fr / 100; /* show 1/100 seconds */
1733 minsec_ruler_scale = minsec_show_frames;
1734 minsec_mark_modulo = 100;
1735 } else if (range <= fr) { /* 0-1 second */
1736 minsec_mark_interval = fr / 10; /* show 1/10 seconds */
1737 minsec_ruler_scale = minsec_show_frames;
1738 minsec_mark_modulo = 200;
1739 } else if (range <= 2 * fr) { /* 1-2 seconds */
1740 minsec_mark_interval = fr / 10; /* show 1/10 seconds */
1741 minsec_ruler_scale = minsec_show_frames;
1742 minsec_mark_modulo = 500;
1743 } else if (range <= 8 * fr) { /* 2-5 seconds */
1744 minsec_mark_interval = fr / 5; /* show 2 seconds */
1745 minsec_ruler_scale = minsec_show_frames;
1746 minsec_mark_modulo = 1000;
1747 } else if (range <= 16 * fr) { /* 8-16 seconds */
1748 minsec_mark_interval = fr; /* show 1 seconds */
1749 minsec_ruler_scale = minsec_show_seconds;
1750 minsec_mark_modulo = 2;
1751 } else if (range <= 30 * fr) { /* 10-30 seconds */
1752 minsec_mark_interval = fr; /* show 1 seconds */
1753 minsec_ruler_scale = minsec_show_seconds;
1754 minsec_mark_modulo = 5;
1755 } else if (range <= 60 * fr) { /* 30-60 seconds */
1756 minsec_mark_interval = fr; /* show 1 seconds */
1757 minsec_ruler_scale = minsec_show_seconds;
1758 minsec_mark_modulo = 5;
1759 } else if (range <= 2 * 60 * fr) { /* 1-2 minutes */
1760 minsec_mark_interval = 5 * fr; /* show 5 seconds */
1761 minsec_ruler_scale = minsec_show_seconds;
1762 minsec_mark_modulo = 3;
1763 } else if (range <= 4 * 60 * fr) { /* 4 minutes */
1764 minsec_mark_interval = 5 * fr; /* show 10 seconds */
1765 minsec_ruler_scale = minsec_show_seconds;
1766 minsec_mark_modulo = 30;
1767 } else if (range <= 10 * 60 * fr) { /* 10 minutes */
1768 minsec_mark_interval = 30 * fr; /* show 30 seconds */
1769 minsec_ruler_scale = minsec_show_seconds;
1770 minsec_mark_modulo = 120;
1771 } else if (range <= 30 * 60 * fr) { /* 10-30 minutes */
1772 minsec_mark_interval = 60 * fr; /* show 1 minute */
1773 minsec_ruler_scale = minsec_show_minutes;
1774 minsec_mark_modulo = 5;
1775 } else if (range <= 60 * 60 * fr) { /* 30 minutes - 1hr */
1776 minsec_mark_interval = 2 * 60 * fr; /* show 2 minutes */
1777 minsec_ruler_scale = minsec_show_minutes;
1778 minsec_mark_modulo = 10;
1779 } else if (range <= 4 * 60 * 60 * fr) { /* 1 - 4 hrs*/
1780 minsec_mark_interval = 5 * 60 * fr; /* show 10 minutes */
1781 minsec_ruler_scale = minsec_show_minutes;
1782 minsec_mark_modulo = 30;
1783 } else if (range <= 8 * 60 * 60 * fr) { /* 4 - 8 hrs*/
1784 minsec_mark_interval = 20 * 60 * fr; /* show 20 minutes */
1785 minsec_ruler_scale = minsec_show_minutes;
1786 minsec_mark_modulo = 60;
1787 } else if (range <= 16 * 60 * 60 * fr) { /* 16-24 hrs*/
1788 minsec_mark_interval = 60 * 60 * fr; /* show 60 minutes */
1789 minsec_ruler_scale = minsec_show_hours;
1790 minsec_mark_modulo = 2;
1793 /* not possible if framepos_t is a 32 bit quantity */
1795 minsec_mark_interval = 4 * 60 * 60 * fr; /* show 4 hrs */
1797 minsec_nmarks = 2 + (range / minsec_mark_interval);
1801 Editor::metric_get_minsec (std::vector<ArdourCanvas::Ruler::Mark>& marks, gdouble lower, gdouble /*upper*/, gint /*maxchars*/)
1805 long hrs, mins, secs, millisecs;
1808 ArdourCanvas::Ruler::Mark mark;
1810 if (_session == 0) {
1814 /* to prevent 'flashing' */
1815 if (lower > (spacer = (framepos_t) (128 * Editor::get_current_zoom ()))) {
1816 lower = lower - spacer;
1821 pos = (((1000 * (framepos_t) floor(lower)) + (minsec_mark_interval/2))/minsec_mark_interval) * minsec_mark_interval;
1822 switch (minsec_ruler_scale) {
1823 case minsec_show_seconds:
1824 for (n = 0; n < minsec_nmarks; pos += minsec_mark_interval, ++n) {
1825 sample_to_clock_parts (pos, _session->frame_rate(), &hrs, &mins, &secs, &millisecs);
1826 if (secs % minsec_mark_modulo == 0) {
1828 mark.style = ArdourCanvas::Ruler::Mark::Major;
1830 mark.style = ArdourCanvas::Ruler::Mark::Minor;
1832 snprintf (buf, sizeof(buf), "%02ld:%02ld:%02ld.%03ld", hrs, mins, secs, millisecs);
1835 mark.style = ArdourCanvas::Ruler::Mark::Micro;
1838 mark.position = pos/1000.0;
1839 marks.push_back (mark);
1842 case minsec_show_minutes:
1843 for (n = 0; n < minsec_nmarks; pos += minsec_mark_interval, ++n) {
1844 sample_to_clock_parts (pos, _session->frame_rate(), &hrs, &mins, &secs, &millisecs);
1845 if (mins % minsec_mark_modulo == 0) {
1847 mark.style = ArdourCanvas::Ruler::Mark::Major;
1849 mark.style = ArdourCanvas::Ruler::Mark::Minor;
1851 snprintf (buf, sizeof(buf), "%02ld:%02ld:%02ld.%03ld", hrs, mins, secs, millisecs);
1854 mark.style = ArdourCanvas::Ruler::Mark::Micro;
1857 mark.position = pos/1000.0;
1858 marks.push_back (mark);
1861 case minsec_show_hours:
1862 for (n = 0; n < minsec_nmarks; pos += minsec_mark_interval, ++n) {
1863 sample_to_clock_parts (pos, _session->frame_rate(), &hrs, &mins, &secs, &millisecs);
1864 if (hrs % minsec_mark_modulo == 0) {
1865 mark.style = ArdourCanvas::Ruler::Mark::Major;
1866 snprintf (buf, sizeof(buf), "%02ld:%02ld:%02ld.%03ld", hrs, mins, secs, millisecs);
1869 mark.style = ArdourCanvas::Ruler::Mark::Micro;
1872 mark.position = pos/1000.0;
1873 marks.push_back (mark);
1876 case minsec_show_frames:
1877 for (n = 0; n < minsec_nmarks; pos += minsec_mark_interval, ++n) {
1878 sample_to_clock_parts (pos, _session->frame_rate(), &hrs, &mins, &secs, &millisecs);
1879 if (millisecs % minsec_mark_modulo == 0) {
1880 if (millisecs == 0) {
1881 mark.style = ArdourCanvas::Ruler::Mark::Major;
1883 mark.style = ArdourCanvas::Ruler::Mark::Minor;
1885 snprintf (buf, sizeof(buf), "%02ld:%02ld:%02ld.%03ld", hrs, mins, secs, millisecs);
1888 mark.style = ArdourCanvas::Ruler::Mark::Micro;
1891 mark.position = pos/1000.0;
1892 marks.push_back (mark);