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/group.h"
33 #include "canvas/canvas.h"
34 #include "canvas/ruler.h"
35 #include "canvas/debug.h"
37 #include "ardour/session.h"
38 #include "ardour/tempo.h"
39 #include "ardour/profile.h"
41 #include "gtkmm2ext/gtk_ui.h"
42 #include "gtkmm2ext/keyboard.h"
44 #include "ardour_ui.h"
48 #include "gui_thread.h"
49 #include "time_axis_view.h"
50 #include "editor_drag.h"
51 #include "editor_cursors.h"
56 using namespace ARDOUR;
59 using namespace Editing;
61 /* the order here must match the "metric" enums in editor.h */
63 class TimecodeMetric : public ArdourCanvas::Ruler::Metric
66 TimecodeMetric (Editor* e) : _editor (e) {}
68 void get_marks (std::vector<ArdourCanvas::Ruler::Mark>& marks, double lower, double upper, int maxchars) const {
69 _editor->metric_get_timecode (marks, lower, upper, maxchars);
76 class SamplesMetric : public ArdourCanvas::Ruler::Metric
79 SamplesMetric (Editor* e) : _editor (e) {}
81 void get_marks (std::vector<ArdourCanvas::Ruler::Mark>& marks, double lower, double upper, int maxchars) const {
82 _editor->metric_get_samples (marks, lower, upper, maxchars);
89 class BBTMetric : public ArdourCanvas::Ruler::Metric
92 BBTMetric (Editor* e) : _editor (e) {}
94 void get_marks (std::vector<ArdourCanvas::Ruler::Mark>& marks, double lower, double upper, int maxchars) const {
95 _editor->metric_get_bbt (marks, lower, upper, maxchars);
102 class MinsecMetric : public ArdourCanvas::Ruler::Metric
105 MinsecMetric (Editor* e) : _editor (e) {}
107 void get_marks (std::vector<ArdourCanvas::Ruler::Mark>& marks, double lower, double upper, int maxchars) const {
108 _editor->metric_get_minsec (marks, lower, upper, maxchars);
115 static ArdourCanvas::Ruler::Metric* _bbt_metric;
116 static ArdourCanvas::Ruler::Metric* _timecode_metric;
117 static ArdourCanvas::Ruler::Metric* _samples_metric;
118 static ArdourCanvas::Ruler::Metric* _minsec_metric;
121 Editor::initialize_rulers ()
123 ruler_grabbed_widget = 0;
124 Pango::FontDescription font (ARDOUR_UI::config()->get_canvasvar_SmallFont());
126 _timecode_metric = new TimecodeMetric (this);
127 _bbt_metric = new BBTMetric (this);
128 _minsec_metric = new MinsecMetric (this);
129 _samples_metric = new SamplesMetric (this);
131 timecode_ruler = new ArdourCanvas::Ruler (_time_markers_group, *_timecode_metric,
132 ArdourCanvas::Rect (0, 0, ArdourCanvas::COORD_MAX, timebar_height));
133 timecode_ruler->set_font_description (font);
134 CANVAS_DEBUG_NAME (timecode_ruler, "timecode ruler");
137 samples_ruler = new ArdourCanvas::Ruler (_time_markers_group, *_samples_metric,
138 ArdourCanvas::Rect (0, 0, ArdourCanvas::COORD_MAX, timebar_height));
139 samples_ruler->set_font_description (font);
140 CANVAS_DEBUG_NAME (samples_ruler, "samples ruler");
142 minsec_ruler = new ArdourCanvas::Ruler (_time_markers_group, *_minsec_metric,
143 ArdourCanvas::Rect (0, 0, ArdourCanvas::COORD_MAX, timebar_height));
144 minsec_ruler->set_font_description (font);
145 CANVAS_DEBUG_NAME (minsec_ruler, "minsec ruler");
148 bbt_ruler = new ArdourCanvas::Ruler (_time_markers_group, *_bbt_metric,
149 ArdourCanvas::Rect (0, 0, ArdourCanvas::COORD_MAX, timebar_height));
150 bbt_ruler->set_font_description (font);
151 CANVAS_DEBUG_NAME (bbt_ruler, "bbt ruler");
154 using namespace Box_Helpers;
155 BoxList & lab_children = time_bars_vbox.children();
157 lab_children.push_back (Element(minsec_label, PACK_SHRINK, PACK_START));
158 lab_children.push_back (Element(timecode_label, PACK_SHRINK, PACK_START));
159 lab_children.push_back (Element(samples_label, PACK_SHRINK, PACK_START));
160 lab_children.push_back (Element(bbt_label, PACK_SHRINK, PACK_START));
161 lab_children.push_back (Element(meter_label, PACK_SHRINK, PACK_START));
162 lab_children.push_back (Element(tempo_label, PACK_SHRINK, PACK_START));
163 lab_children.push_back (Element(range_mark_label, PACK_SHRINK, PACK_START));
164 lab_children.push_back (Element(transport_mark_label, PACK_SHRINK, PACK_START));
165 lab_children.push_back (Element(cd_mark_label, PACK_SHRINK, PACK_START));
166 lab_children.push_back (Element(mark_label, PACK_SHRINK, PACK_START));
167 lab_children.push_back (Element(videotl_label, PACK_SHRINK, PACK_START));
169 /* 1 event handler to bind them all ... */
171 timecode_ruler->Event.connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_ruler_event), timecode_ruler, TimecodeRulerItem));
172 minsec_ruler->Event.connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_ruler_event), minsec_ruler, MinsecRulerItem));
173 bbt_ruler->Event.connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_ruler_event), bbt_ruler, BBTRulerItem));
174 samples_ruler->Event.connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_ruler_event), samples_ruler, SamplesRulerItem));
176 visible_timebars = 0; /*this will be changed below */
180 Editor::ruler_label_button_release (GdkEventButton* ev)
182 if (Gtkmm2ext::Keyboard::is_context_menu_event (ev)) {
183 Gtk::Menu* m = dynamic_cast<Gtk::Menu*> (ActionManager::get_widget (X_("/RulerMenuPopup")));
185 m->popup (1, ev->time);
193 Editor::popup_ruler_menu (framepos_t where, ItemType t)
195 using namespace Menu_Helpers;
197 if (editor_ruler_menu == 0) {
198 editor_ruler_menu = new Menu;
199 editor_ruler_menu->set_name ("ArdourContextMenu");
202 // always build from scratch
203 MenuList& ruler_items = editor_ruler_menu->items();
204 editor_ruler_menu->set_name ("ArdourContextMenu");
209 ruler_items.push_back (MenuElem (_("New location marker"), sigc::bind ( sigc::mem_fun(*this, &Editor::mouse_add_new_marker), where, false, false)));
210 ruler_items.push_back (MenuElem (_("Clear all locations"), sigc::mem_fun(*this, &Editor::clear_markers)));
211 ruler_items.push_back (MenuElem (_("Unhide locations"), sigc::mem_fun(*this, &Editor::unhide_markers)));
212 ruler_items.push_back (SeparatorElem ());
214 case RangeMarkerBarItem:
215 ruler_items.push_back (MenuElem (_("New range"), sigc::bind (sigc::mem_fun (*this, &Editor::mouse_add_new_range), where)));
216 ruler_items.push_back (MenuElem (_("Clear all ranges"), sigc::mem_fun(*this, &Editor::clear_ranges)));
217 ruler_items.push_back (MenuElem (_("Unhide ranges"), sigc::mem_fun(*this, &Editor::unhide_ranges)));
218 ruler_items.push_back (SeparatorElem ());
221 case TransportMarkerBarItem:
225 case CdMarkerBarItem:
227 ruler_items.push_back (MenuElem (_("New CD track marker"), sigc::bind ( sigc::mem_fun(*this, &Editor::mouse_add_new_marker), where, true, false)));
232 ruler_items.push_back (MenuElem (_("New Tempo"), sigc::bind ( sigc::mem_fun(*this, &Editor::mouse_add_new_tempo_event), where)));
233 ruler_items.push_back (SeparatorElem ());
237 ruler_items.push_back (MenuElem (_("New Meter"), sigc::bind ( sigc::mem_fun(*this, &Editor::mouse_add_new_meter_event), where)));
238 ruler_items.push_back (SeparatorElem ());
242 ruler_items.push_back (MenuElem (_("Timeline height")));
243 static_cast<MenuItem*>(&ruler_items.back())->set_sensitive(false);
244 ruler_items.push_back (CheckMenuElem (_("Large"), sigc::bind ( sigc::mem_fun(*this, &Editor::set_video_timeline_height), 6)));
245 if (videotl_bar_height == 6) { static_cast<Gtk::CheckMenuItem*>(&ruler_items.back())->set_active(true);}
246 ruler_items.push_back (CheckMenuElem (_("Normal"), sigc::bind ( sigc::mem_fun(*this, &Editor::set_video_timeline_height), 4)));
247 if (videotl_bar_height == 4) { static_cast<Gtk::CheckMenuItem*>(&ruler_items.back())->set_active(true);}
248 ruler_items.push_back (CheckMenuElem (_("Small"), sigc::bind ( sigc::mem_fun(*this, &Editor::set_video_timeline_height), 3)));
249 if (videotl_bar_height == 3) { static_cast<Gtk::CheckMenuItem*>(&ruler_items.back())->set_active(true);}
250 ruler_items.push_back (SeparatorElem ());
252 ruler_items.push_back (MenuElem (_("Align Video Track")));
253 static_cast<MenuItem*>(&ruler_items.back())->set_sensitive(false);
255 ruler_items.push_back (CheckMenuElem (_("Lock")));
257 Gtk::CheckMenuItem* vtl_lock = static_cast<Gtk::CheckMenuItem*>(&ruler_items.back());
258 vtl_lock->set_active(is_video_timeline_locked());
259 vtl_lock->signal_activate().connect (sigc::mem_fun(*this, &Editor::toggle_video_timeline_locked));
262 ruler_items.push_back (SeparatorElem ());
269 Glib::RefPtr<Action> action;
271 action = ActionManager::get_action ("Rulers", "toggle-minsec-ruler");
273 ruler_items.push_back (MenuElem (*action->create_menu_item()));
275 if (!Profile->get_sae()) {
276 action = ActionManager::get_action ("Rulers", "toggle-timecode-ruler");
278 ruler_items.push_back (MenuElem (*action->create_menu_item()));
281 action = ActionManager::get_action ("Rulers", "toggle-samples-ruler");
283 ruler_items.push_back (MenuElem (*action->create_menu_item()));
285 action = ActionManager::get_action ("Rulers", "toggle-bbt-ruler");
287 ruler_items.push_back (MenuElem (*action->create_menu_item()));
289 action = ActionManager::get_action ("Rulers", "toggle-meter-ruler");
291 ruler_items.push_back (MenuElem (*action->create_menu_item()));
293 action = ActionManager::get_action ("Rulers", "toggle-tempo-ruler");
295 ruler_items.push_back (MenuElem (*action->create_menu_item()));
297 if (!Profile->get_sae()) {
298 action = ActionManager::get_action ("Rulers", "toggle-range-ruler");
300 ruler_items.push_back (MenuElem (*action->create_menu_item()));
303 action = ActionManager::get_action ("Rulers", "toggle-loop-punch-ruler");
305 ruler_items.push_back (MenuElem (*action->create_menu_item()));
307 action = ActionManager::get_action ("Rulers", "toggle-cd-marker-ruler");
309 ruler_items.push_back (MenuElem (*action->create_menu_item()));
311 action = ActionManager::get_action ("Rulers", "toggle-marker-ruler");
313 ruler_items.push_back (MenuElem (*action->create_menu_item()));
315 action = ActionManager::get_action ("Rulers", "toggle-video-ruler");
317 ruler_items.push_back (MenuElem (*action->create_menu_item()));
320 editor_ruler_menu->popup (1, gtk_get_current_event_time());
322 no_ruler_shown_update = false;
326 Editor::store_ruler_visibility ()
328 XMLNode* node = new XMLNode(X_("RulerVisibility"));
330 node->add_property (X_("timecode"), ruler_timecode_action->get_active() ? "yes": "no");
331 node->add_property (X_("bbt"), ruler_bbt_action->get_active() ? "yes": "no");
332 node->add_property (X_("samples"), ruler_samples_action->get_active() ? "yes": "no");
333 node->add_property (X_("minsec"), ruler_minsec_action->get_active() ? "yes": "no");
334 node->add_property (X_("tempo"), ruler_tempo_action->get_active() ? "yes": "no");
335 node->add_property (X_("meter"), ruler_meter_action->get_active() ? "yes": "no");
336 node->add_property (X_("marker"), ruler_marker_action->get_active() ? "yes": "no");
337 node->add_property (X_("rangemarker"), ruler_range_action->get_active() ? "yes": "no");
338 node->add_property (X_("transportmarker"), ruler_loop_punch_action->get_active() ? "yes": "no");
339 node->add_property (X_("cdmarker"), ruler_cd_marker_action->get_active() ? "yes": "no");
340 node->add_property (X_("videotl"), ruler_video_action->get_active() ? "yes": "no");
342 _session->add_extra_xml (*node);
343 _session->set_dirty ();
347 Editor::restore_ruler_visibility ()
350 XMLNode * node = _session->extra_xml (X_("RulerVisibility"));
352 no_ruler_shown_update = true;
355 if ((prop = node->property ("timecode")) != 0) {
356 if (string_is_affirmative (prop->value())) {
357 ruler_timecode_action->set_active (true);
359 ruler_timecode_action->set_active (false);
362 if ((prop = node->property ("bbt")) != 0) {
363 if (string_is_affirmative (prop->value())) {
364 ruler_bbt_action->set_active (true);
366 ruler_bbt_action->set_active (false);
369 if ((prop = node->property ("samples")) != 0) {
370 if (string_is_affirmative (prop->value())) {
371 ruler_samples_action->set_active (true);
373 ruler_samples_action->set_active (false);
376 if ((prop = node->property ("minsec")) != 0) {
377 if (string_is_affirmative (prop->value())) {
378 ruler_minsec_action->set_active (true);
380 ruler_minsec_action->set_active (false);
383 if ((prop = node->property ("tempo")) != 0) {
384 if (string_is_affirmative (prop->value())) {
385 ruler_tempo_action->set_active (true);
387 ruler_tempo_action->set_active (false);
390 if ((prop = node->property ("meter")) != 0) {
391 if (string_is_affirmative (prop->value())) {
392 ruler_meter_action->set_active (true);
394 ruler_meter_action->set_active (false);
397 if ((prop = node->property ("marker")) != 0) {
398 if (string_is_affirmative (prop->value())) {
399 ruler_marker_action->set_active (true);
401 ruler_marker_action->set_active (false);
404 if ((prop = node->property ("rangemarker")) != 0) {
405 if (string_is_affirmative (prop->value())) {
406 ruler_range_action->set_active (true);
408 ruler_range_action->set_active (false);
412 if ((prop = node->property ("transportmarker")) != 0) {
413 if (string_is_affirmative (prop->value())) {
414 ruler_loop_punch_action->set_active (true);
416 ruler_loop_punch_action->set_active (false);
420 if ((prop = node->property ("cdmarker")) != 0) {
421 if (string_is_affirmative (prop->value())) {
422 ruler_cd_marker_action->set_active (true);
424 ruler_cd_marker_action->set_active (false);
428 // this _session doesn't yet know about the cdmarker ruler
429 // as a benefit to the user who doesn't know the feature exists, show the ruler if
430 // any cd marks exist
431 ruler_cd_marker_action->set_active (false);
432 const Locations::LocationList & locs = _session->locations()->list();
433 for (Locations::LocationList::const_iterator i = locs.begin(); i != locs.end(); ++i) {
434 if ((*i)->is_cd_marker()) {
435 ruler_cd_marker_action->set_active (true);
441 if ((prop = node->property ("videotl")) != 0) {
442 if (string_is_affirmative (prop->value())) {
443 ruler_video_action->set_active (true);
445 ruler_video_action->set_active (false);
451 no_ruler_shown_update = false;
452 update_ruler_visibility ();
456 Editor::update_ruler_visibility ()
458 int visible_timebars = 0;
460 if (no_ruler_shown_update) {
464 /* the order of the timebars is fixed, so we have to go through each one
465 * and adjust its position depending on what is shown.
467 * Order: minsec, timecode, samples, bbt, meter, tempo, ranges,
468 * loop/punch, cd markers, location markers
476 /* gtk update probs require this (damn) */
479 range_mark_label.hide();
480 transport_mark_label.hide();
481 cd_mark_label.hide();
483 videotl_label.hide();
486 if (ruler_minsec_action->get_active()) {
487 old_unit_pos = minsec_ruler->position().y;
488 if (tbpos != old_unit_pos) {
489 minsec_ruler->move (ArdourCanvas::Duple (0.0, tbpos - old_unit_pos));
491 minsec_ruler->show();
493 tbpos += timebar_height;
494 tbgpos += timebar_height;
497 minsec_ruler->hide();
501 if (ruler_timecode_action->get_active()) {
502 old_unit_pos = timecode_ruler->position().y;
503 if (tbpos != old_unit_pos) {
504 timecode_ruler->move (ArdourCanvas::Duple (0.0, tbpos - old_unit_pos));
506 timecode_ruler->show();
507 timecode_label.show();
508 tbpos += timebar_height;
509 tbgpos += timebar_height;
512 timecode_ruler->hide();
513 timecode_label.hide();
516 if (ruler_samples_action->get_active()) {
517 old_unit_pos = samples_ruler->position().y;
518 if (tbpos != old_unit_pos) {
519 samples_ruler->move (ArdourCanvas::Duple (0.0, tbpos - old_unit_pos));
521 samples_ruler->show();
522 samples_label.show();
523 tbpos += timebar_height;
524 tbgpos += timebar_height;
527 samples_ruler->hide();
528 samples_label.hide();
531 if (ruler_bbt_action->get_active()) {
532 old_unit_pos = bbt_ruler->position().y;
533 if (tbpos != old_unit_pos) {
534 bbt_ruler->move (ArdourCanvas::Duple (0.0, tbpos - old_unit_pos));
538 tbpos += timebar_height;
539 tbgpos += timebar_height;
546 if (ruler_meter_action->get_active()) {
547 old_unit_pos = meter_group->position().y;
548 if (tbpos != old_unit_pos) {
549 meter_group->move (ArdourCanvas::Duple (0.0, tbpos - old_unit_pos));
553 tbpos += timebar_height;
554 tbgpos += timebar_height;
561 if (ruler_tempo_action->get_active()) {
562 old_unit_pos = tempo_group->position().y;
563 if (tbpos != old_unit_pos) {
564 tempo_group->move (ArdourCanvas::Duple (0.0, tbpos - old_unit_pos));
568 tbpos += timebar_height;
569 tbgpos += timebar_height;
576 if (!Profile->get_sae() && ruler_range_action->get_active()) {
577 old_unit_pos = range_marker_group->position().y;
578 if (tbpos != old_unit_pos) {
579 range_marker_group->move (ArdourCanvas::Duple (0.0, tbpos - old_unit_pos));
581 range_marker_group->show();
582 range_mark_label.show();
584 tbpos += timebar_height;
585 tbgpos += timebar_height;
588 range_marker_group->hide();
589 range_mark_label.hide();
592 if (ruler_loop_punch_action->get_active()) {
593 old_unit_pos = transport_marker_group->position().y;
594 if (tbpos != old_unit_pos) {
595 transport_marker_group->move (ArdourCanvas::Duple (0.0, tbpos - old_unit_pos));
597 transport_marker_group->show();
598 transport_mark_label.show();
599 tbpos += timebar_height;
600 tbgpos += timebar_height;
603 transport_marker_group->hide();
604 transport_mark_label.hide();
607 if (ruler_cd_marker_action->get_active()) {
608 old_unit_pos = cd_marker_group->position().y;
609 if (tbpos != old_unit_pos) {
610 cd_marker_group->move (ArdourCanvas::Duple (0.0, tbpos - old_unit_pos));
612 cd_marker_group->show();
613 cd_mark_label.show();
614 tbpos += timebar_height;
615 tbgpos += timebar_height;
617 // make sure all cd markers show up in their respective places
618 update_cd_marker_display();
620 cd_marker_group->hide();
621 cd_mark_label.hide();
622 // make sure all cd markers show up in their respective places
623 update_cd_marker_display();
626 if (ruler_marker_action->get_active()) {
627 old_unit_pos = marker_group->position().y;
628 if (tbpos != old_unit_pos) {
629 marker_group->move (ArdourCanvas::Duple (0.0, tbpos - old_unit_pos));
631 marker_group->show();
633 tbpos += timebar_height;
634 tbgpos += timebar_height;
637 marker_group->hide();
641 if (ruler_video_action->get_active()) {
642 old_unit_pos = videotl_group->position().y;
643 if (tbpos != old_unit_pos) {
644 videotl_group->move (ArdourCanvas::Duple (0.0, tbpos - old_unit_pos));
646 videotl_group->show();
647 videotl_label.show();
648 tbpos += timebar_height * videotl_bar_height;
649 tbgpos += timebar_height * videotl_bar_height;
650 visible_timebars+=videotl_bar_height;
651 queue_visual_videotimeline_update();
653 videotl_group->hide();
654 videotl_label.hide();
655 update_video_timeline(true);
658 time_bars_vbox.set_size_request (-1, (int)(timebar_height * visible_timebars));
660 /* move hv_scroll_group (trackviews) to the end of the timebars
663 hv_scroll_group->set_y_position (timebar_height * visible_timebars);
665 compute_fixed_ruler_scale ();
666 update_fixed_rulers();
667 redisplay_tempo (false);
669 /* Changing ruler visibility means that any lines on markers might need updating */
670 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
671 i->second->setup_lines ();
676 Editor::update_just_timecode ()
678 ENSURE_GUI_THREAD (*this, &Editor::update_just_timecode)
684 framepos_t rightmost_frame = leftmost_frame + current_page_samples();
686 if (ruler_timecode_action->get_active()) {
687 timecode_ruler->set_range (leftmost_frame, rightmost_frame);
692 Editor::compute_fixed_ruler_scale ()
698 if (ruler_timecode_action->get_active()) {
699 set_timecode_ruler_scale (leftmost_frame, leftmost_frame + current_page_samples());
702 if (ruler_minsec_action->get_active()) {
703 set_minsec_ruler_scale (leftmost_frame, leftmost_frame + current_page_samples());
706 if (ruler_samples_action->get_active()) {
707 set_samples_ruler_scale (leftmost_frame, leftmost_frame + current_page_samples());
712 Editor::update_fixed_rulers ()
714 framepos_t rightmost_frame;
720 compute_fixed_ruler_scale ();
722 _timecode_metric->units_per_pixel = samples_per_pixel;
723 _samples_metric->units_per_pixel = samples_per_pixel;
724 _minsec_metric->units_per_pixel = samples_per_pixel;
726 rightmost_frame = leftmost_frame + current_page_samples();
728 /* these force a redraw, which in turn will force execution of the metric callbacks
729 to compute the relevant ticks to display.
732 if (ruler_timecode_action->get_active()) {
733 timecode_ruler->set_range (leftmost_frame, rightmost_frame);
736 if (ruler_samples_action->get_active()) {
737 samples_ruler->set_range (leftmost_frame, rightmost_frame);
740 if (ruler_minsec_action->get_active()) {
741 minsec_ruler->set_range (leftmost_frame, rightmost_frame);
746 Editor::update_tempo_based_rulers (ARDOUR::TempoMap::BBTPointList::const_iterator& begin,
747 ARDOUR::TempoMap::BBTPointList::const_iterator& end)
753 compute_bbt_ruler_scale (leftmost_frame, leftmost_frame+current_page_samples(),
756 _bbt_metric->units_per_pixel = samples_per_pixel;
758 if (ruler_bbt_action->get_active()) {
759 bbt_ruler->set_range (leftmost_frame, leftmost_frame+current_page_samples());
764 Editor::set_timecode_ruler_scale (framepos_t lower, framepos_t upper)
773 fr = _session->frame_rate();
775 if (lower > (spacer = (framepos_t) (128 * Editor::get_current_zoom ()))) {
776 lower = lower - spacer;
780 upper = upper + spacer;
781 framecnt_t const range = upper - lower;
783 if (range < (2 * _session->frames_per_timecode_frame())) { /* 0 - 2 frames */
784 timecode_ruler_scale = timecode_show_bits;
785 timecode_mark_modulo = 20;
786 timecode_nmarks = 2 + (2 * _session->config.get_subframes_per_frame());
787 } else if (range <= (fr / 4)) { /* 2 frames - 0.250 second */
788 timecode_ruler_scale = timecode_show_frames;
789 timecode_mark_modulo = 1;
790 timecode_nmarks = 2 + (range / (framepos_t)_session->frames_per_timecode_frame());
791 } else if (range <= (fr / 2)) { /* 0.25-0.5 second */
792 timecode_ruler_scale = timecode_show_frames;
793 timecode_mark_modulo = 2;
794 timecode_nmarks = 2 + (range / (framepos_t)_session->frames_per_timecode_frame());
795 } else if (range <= fr) { /* 0.5-1 second */
796 timecode_ruler_scale = timecode_show_frames;
797 timecode_mark_modulo = 5;
798 timecode_nmarks = 2 + (range / (framepos_t)_session->frames_per_timecode_frame());
799 } else if (range <= 2 * fr) { /* 1-2 seconds */
800 timecode_ruler_scale = timecode_show_frames;
801 timecode_mark_modulo = 10;
802 timecode_nmarks = 2 + (range / (framepos_t)_session->frames_per_timecode_frame());
803 } else if (range <= 8 * fr) { /* 2-8 seconds */
804 timecode_ruler_scale = timecode_show_seconds;
805 timecode_mark_modulo = 1;
806 timecode_nmarks = 2 + (range / fr);
807 } else if (range <= 16 * fr) { /* 8-16 seconds */
808 timecode_ruler_scale = timecode_show_seconds;
809 timecode_mark_modulo = 2;
810 timecode_nmarks = 2 + (range / fr);
811 } else if (range <= 30 * fr) { /* 16-30 seconds */
812 timecode_ruler_scale = timecode_show_seconds;
813 timecode_mark_modulo = 5;
814 timecode_nmarks = 2 + (range / fr);
815 } else if (range <= 60 * fr) { /* 30-60 seconds */
816 timecode_ruler_scale = timecode_show_seconds;
817 timecode_mark_modulo = 5;
818 timecode_nmarks = 2 + (range / fr);
819 } else if (range <= 2 * 60 * fr) { /* 1-2 minutes */
820 timecode_ruler_scale = timecode_show_seconds;
821 timecode_mark_modulo = 15;
822 timecode_nmarks = 2 + (range / fr);
823 } else if (range <= 4 * 60 * fr) { /* 2-4 minutes */
824 timecode_ruler_scale = timecode_show_seconds;
825 timecode_mark_modulo = 30;
826 timecode_nmarks = 2 + (range / fr);
827 } else if (range <= 10 * 60 * fr) { /* 4-10 minutes */
828 timecode_ruler_scale = timecode_show_minutes;
829 timecode_mark_modulo = 2;
830 timecode_nmarks = 2 + 10;
831 } else if (range <= 30 * 60 * fr) { /* 10-30 minutes */
832 timecode_ruler_scale = timecode_show_minutes;
833 timecode_mark_modulo = 5;
834 timecode_nmarks = 2 + 30;
835 } else if (range <= 60 * 60 * fr) { /* 30 minutes - 1hr */
836 timecode_ruler_scale = timecode_show_minutes;
837 timecode_mark_modulo = 10;
838 timecode_nmarks = 2 + 60;
839 } else if (range <= 4 * 60 * 60 * fr) { /* 1 - 4 hrs*/
840 timecode_ruler_scale = timecode_show_minutes;
841 timecode_mark_modulo = 30;
842 timecode_nmarks = 2 + (60 * 4);
843 } else if (range <= 8 * 60 * 60 * fr) { /* 4 - 8 hrs*/
844 timecode_ruler_scale = timecode_show_hours;
845 timecode_mark_modulo = 1;
846 timecode_nmarks = 2 + 8;
847 } else if (range <= 16 * 60 * 60 * fr) { /* 16-24 hrs*/
848 timecode_ruler_scale = timecode_show_hours;
849 timecode_mark_modulo = 1;
850 timecode_nmarks = 2 + 24;
853 /* not possible if framepos_t is a 32 bit quantity */
855 timecode_ruler_scale = timecode_show_hours;
856 timecode_mark_modulo = 4;
857 timecode_nmarks = 2 + 24;
863 Editor::metric_get_timecode (std::vector<ArdourCanvas::Ruler::Mark>& marks, gdouble lower, gdouble /*upper*/, gint /*maxchars*/)
867 Timecode::Time timecode;
870 ArdourCanvas::Ruler::Mark mark;
876 if (lower > (spacer = (framecnt_t)(128 * Editor::get_current_zoom ()))) {
877 lower = lower - spacer;
882 pos = (framecnt_t) floor (lower);
884 switch (timecode_ruler_scale) {
885 case timecode_show_bits:
887 // Find timecode time of this sample (pos) with subframe accuracy
888 _session->sample_to_timecode(pos, timecode, true /* use_offset */, true /* use_subframes */ );
890 for (n = 0; n < timecode_nmarks; n++) {
891 _session->timecode_to_sample(timecode, pos, true /* use_offset */, true /* use_subframes */ );
892 if ((timecode.subframes % timecode_mark_modulo) == 0) {
893 if (timecode.subframes == 0) {
894 mark.style = ArdourCanvas::Ruler::Mark::Major;
895 snprintf (buf, sizeof(buf), "%s%02u:%02u:%02u:%02u", timecode.negative ? "-" : "", timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
897 mark.style = ArdourCanvas::Ruler::Mark::Minor;
898 snprintf (buf, sizeof(buf), ".%02u", timecode.subframes);
901 snprintf (buf, sizeof(buf)," ");
902 mark.style = ArdourCanvas::Ruler::Mark::Micro;
908 marks.push_back (mark);
910 // Increment subframes by one
911 Timecode::increment_subframes( timecode, _session->config.get_subframes_per_frame() );
914 case timecode_show_seconds:
915 // Find timecode time of this sample (pos)
916 _session->sample_to_timecode(pos, timecode, true /* use_offset */, false /* use_subframes */ );
917 // Go to next whole second down
918 Timecode::seconds_floor( timecode );
920 for (n = 0; n < timecode_nmarks; n++) {
921 _session->timecode_to_sample(timecode, pos, true /* use_offset */, false /* use_subframes */ );
922 if ((timecode.seconds % timecode_mark_modulo) == 0) {
923 if (timecode.seconds == 0) {
924 mark.style = ArdourCanvas::Ruler::Mark::Major;
927 mark.style = ArdourCanvas::Ruler::Mark::Minor;
930 snprintf (buf, sizeof(buf), "%s%02u:%02u:%02u:%02u", timecode.negative ? "-" : "", timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
932 snprintf (buf, sizeof(buf)," ");
933 mark.style = ArdourCanvas::Ruler::Mark::Micro;
938 marks.push_back (mark);
940 Timecode::increment_seconds( timecode, _session->config.get_subframes_per_frame() );
943 case timecode_show_minutes:
944 // Find timecode time of this sample (pos)
945 _session->sample_to_timecode(pos, timecode, true /* use_offset */, false /* use_subframes */ );
946 // Go to next whole minute down
947 Timecode::minutes_floor( timecode );
949 for (n = 0; n < timecode_nmarks; n++) {
950 _session->timecode_to_sample(timecode, pos, true /* use_offset */, false /* use_subframes */ );
951 if ((timecode.minutes % timecode_mark_modulo) == 0) {
952 if (timecode.minutes == 0) {
953 mark.style = ArdourCanvas::Ruler::Mark::Major;
955 mark.style = ArdourCanvas::Ruler::Mark::Minor;
957 snprintf (buf, sizeof(buf), "%s%02u:%02u:%02u:%02u", timecode.negative ? "-" : "", timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
959 snprintf (buf, sizeof(buf)," ");
960 mark.style = ArdourCanvas::Ruler::Mark::Micro;
965 marks.push_back (mark);
966 Timecode::increment_minutes( timecode, _session->config.get_subframes_per_frame() );
970 case timecode_show_hours:
971 // Find timecode time of this sample (pos)
972 _session->sample_to_timecode(pos, timecode, true /* use_offset */, false /* use_subframes */ );
973 // Go to next whole hour down
974 Timecode::hours_floor( timecode );
976 for (n = 0; n < timecode_nmarks; n++) {
977 _session->timecode_to_sample(timecode, pos, true /* use_offset */, false /* use_subframes */ );
978 if ((timecode.hours % timecode_mark_modulo) == 0) {
979 mark.style = ArdourCanvas::Ruler::Mark::Major;
980 snprintf (buf, sizeof(buf), "%s%02u:%02u:%02u:%02u", timecode.negative ? "-" : "", timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
982 snprintf (buf, sizeof(buf)," ");
983 mark.style = ArdourCanvas::Ruler::Mark::Micro;
988 marks.push_back (mark);
989 Timecode::increment_hours( timecode, _session->config.get_subframes_per_frame() );
992 case timecode_show_frames:
993 // Find timecode time of this sample (pos)
994 _session->sample_to_timecode(pos, timecode, true /* use_offset */, false /* use_subframes */ );
995 // Go to next whole frame down
996 Timecode::frames_floor( timecode );
998 for (n = 0; n < timecode_nmarks; n++) {
999 _session->timecode_to_sample(timecode, pos, true /* use_offset */, false /* use_subframes */ );
1000 if ((timecode.frames % timecode_mark_modulo) == 0) {
1001 if (timecode.frames == 0) {
1002 mark.style = ArdourCanvas::Ruler::Mark::Major;
1004 mark.style = ArdourCanvas::Ruler::Mark::Minor;
1006 mark.position = pos;
1007 snprintf (buf, sizeof(buf), "%s%02u:%02u:%02u:%02u", timecode.negative ? "-" : "", timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
1009 snprintf (buf, sizeof(buf)," ");
1010 mark.style = ArdourCanvas::Ruler::Mark::Micro;
1011 mark.position = pos;
1015 marks.push_back (mark);
1016 Timecode::increment( timecode, _session->config.get_subframes_per_frame() );
1026 Editor::compute_bbt_ruler_scale (framepos_t lower, framepos_t upper,
1027 ARDOUR::TempoMap::BBTPointList::const_iterator begin,
1028 ARDOUR::TempoMap::BBTPointList::const_iterator end)
1030 if (_session == 0) {
1034 TempoMap::BBTPointList::const_iterator i;
1035 Timecode::BBT_Time lower_beat, upper_beat; // the beats at each end of the ruler
1037 _session->bbt_time (lower, lower_beat);
1038 _session->bbt_time (upper, upper_beat);
1041 bbt_accent_modulo = 1;
1042 bbt_bar_helper_on = false;
1046 bbt_ruler_scale = bbt_over;
1048 switch (_snap_type) {
1049 case SnapToBeatDiv2:
1050 bbt_beat_subdivision = 2;
1052 case SnapToBeatDiv3:
1053 bbt_beat_subdivision = 3;
1055 case SnapToBeatDiv4:
1056 bbt_beat_subdivision = 4;
1058 case SnapToBeatDiv5:
1059 bbt_beat_subdivision = 5;
1060 bbt_accent_modulo = 2; // XXX YIKES
1062 case SnapToBeatDiv6:
1063 bbt_beat_subdivision = 6;
1064 bbt_accent_modulo = 2; // XXX YIKES
1066 case SnapToBeatDiv7:
1067 bbt_beat_subdivision = 7;
1068 bbt_accent_modulo = 2; // XXX YIKES
1070 case SnapToBeatDiv8:
1071 bbt_beat_subdivision = 8;
1072 bbt_accent_modulo = 2;
1074 case SnapToBeatDiv10:
1075 bbt_beat_subdivision = 10;
1076 bbt_accent_modulo = 2; // XXX YIKES
1078 case SnapToBeatDiv12:
1079 bbt_beat_subdivision = 12;
1080 bbt_accent_modulo = 3;
1082 case SnapToBeatDiv14:
1083 bbt_beat_subdivision = 14;
1084 bbt_accent_modulo = 3; // XXX YIKES!
1086 case SnapToBeatDiv16:
1087 bbt_beat_subdivision = 16;
1088 bbt_accent_modulo = 4;
1090 case SnapToBeatDiv20:
1091 bbt_beat_subdivision = 20;
1092 bbt_accent_modulo = 5;
1094 case SnapToBeatDiv24:
1095 bbt_beat_subdivision = 24;
1096 bbt_accent_modulo = 6;
1098 case SnapToBeatDiv28:
1099 bbt_beat_subdivision = 28;
1100 bbt_accent_modulo = 7;
1102 case SnapToBeatDiv32:
1103 bbt_beat_subdivision = 32;
1104 bbt_accent_modulo = 8;
1106 case SnapToBeatDiv64:
1107 bbt_beat_subdivision = 64;
1108 bbt_accent_modulo = 8;
1110 case SnapToBeatDiv128:
1111 bbt_beat_subdivision = 128;
1112 bbt_accent_modulo = 8;
1115 bbt_beat_subdivision = 4;
1119 if (distance (begin, end) == 0) {
1125 if ((*i).beat >= (*begin).beat) {
1126 bbt_bars = (*i).bar - (*begin).bar;
1128 bbt_bars = (*i).bar - (*begin).bar - 1;
1130 beats = distance (begin, end) - bbt_bars;
1132 /* Only show the bar helper if there aren't many bars on the screen */
1133 if ((bbt_bars < 2) || (beats < 5)) {
1134 bbt_bar_helper_on = true;
1137 if (bbt_bars > 8192) {
1138 bbt_ruler_scale = bbt_over;
1139 } else if (bbt_bars > 1024) {
1140 bbt_ruler_scale = bbt_show_64;
1141 } else if (bbt_bars > 256) {
1142 bbt_ruler_scale = bbt_show_16;
1143 } else if (bbt_bars > 64) {
1144 bbt_ruler_scale = bbt_show_4;
1145 } else if (bbt_bars > 10) {
1146 bbt_ruler_scale = bbt_show_1;
1147 } else if (bbt_bars > 2) {
1148 bbt_ruler_scale = bbt_show_beats;
1149 } else if (bbt_bars > 0) {
1150 bbt_ruler_scale = bbt_show_ticks;
1152 bbt_ruler_scale = bbt_show_ticks_detail;
1155 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)) {
1156 bbt_ruler_scale = bbt_show_ticks_super_detail;
1161 edit_last_mark_label (std::vector<ArdourCanvas::Ruler::Mark>& marks, const std::string& newlabel)
1163 ArdourCanvas::Ruler::Mark copy = marks.back();
1164 copy.label = newlabel;
1166 marks.push_back (copy);
1170 Editor::metric_get_bbt (std::vector<ArdourCanvas::Ruler::Mark>& marks, gdouble lower, gdouble upper, gint /*maxchars*/)
1172 if (_session == 0) {
1176 TempoMap::BBTPointList::const_iterator i;
1181 Timecode::BBT_Time next_beat;
1182 framepos_t next_beat_pos;
1187 framepos_t frame_skip;
1188 double frame_skip_error;
1189 double bbt_position_of_helper;
1190 double accumulated_error;
1191 bool i_am_accented = false;
1192 bool helper_active = false;
1193 ArdourCanvas::Ruler::Mark mark;
1195 ARDOUR::TempoMap::BBTPointList::const_iterator begin;
1196 ARDOUR::TempoMap::BBTPointList::const_iterator end;
1198 compute_current_bbt_points (lower, upper, begin, end);
1200 if (distance (begin, end) == 0) {
1204 switch (bbt_ruler_scale) {
1206 case bbt_show_beats:
1207 beats = distance (begin, end);
1208 bbt_nmarks = beats + 2;
1211 mark.position = lower;
1212 mark.style = ArdourCanvas::Ruler::Mark::Micro;
1213 marks.push_back (mark);
1215 for (n = 1, i = begin; n < bbt_nmarks && i != end; ++i) {
1217 if ((*i).frame < lower && (bbt_bar_helper_on)) {
1218 snprintf (buf, sizeof(buf), "<%" PRIu32 "|%" PRIu32, (*i).bar, (*i).beat);
1219 edit_last_mark_label (marks, buf);
1220 helper_active = true;
1223 if ((*i).is_bar()) {
1224 mark.style = ArdourCanvas::Ruler::Mark::Major;
1225 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1226 } else if (((*i).beat % 2 == 1)) {
1227 mark.style = ArdourCanvas::Ruler::Mark::Minor;
1230 mark.style = ArdourCanvas::Ruler::Mark::Micro;
1234 mark.position = (*i).frame;
1235 marks.push_back (mark);
1241 case bbt_show_ticks:
1243 beats = distance (begin, end);
1244 bbt_nmarks = (beats + 2) * bbt_beat_subdivision;
1246 bbt_position_of_helper = lower + (30 * Editor::get_current_zoom ());
1248 // could do marks.assign() here to preallocate
1251 mark.position = lower;
1252 mark.style = ArdourCanvas::Ruler::Mark::Micro;
1253 marks.push_back (mark);
1255 for (n = 1, i = begin; n < bbt_nmarks && i != end; ++i) {
1257 if ((*i).frame < lower && (bbt_bar_helper_on)) {
1258 snprintf (buf, sizeof(buf), "<%" PRIu32 "|%" PRIu32, (*i).bar, (*i).beat);
1259 edit_last_mark_label (marks, buf);
1260 helper_active = true;
1263 if ((*i).is_bar()) {
1264 mark.style = ArdourCanvas::Ruler::Mark::Major;
1265 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1267 mark.style = ArdourCanvas::Ruler::Mark::Minor;
1268 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).beat);
1270 if (((*i).frame < bbt_position_of_helper) && helper_active) {
1274 mark.position = (*i).frame;
1275 marks.push_back (mark);
1279 /* Add the tick marks */
1281 /* Find the next beat */
1282 next_beat.beats = (*i).beat;
1283 next_beat.bars = (*i).bar;
1284 next_beat.ticks = 0;
1286 if ((*i).meter->divisions_per_bar() > (next_beat.beats + 1)) {
1287 next_beat.beats += 1;
1289 next_beat.bars += 1;
1290 next_beat.beats = 1;
1293 next_beat_pos = _session->tempo_map().frame_time(next_beat);
1295 frame_skip = (framepos_t) floor (frame_skip_error = (_session->frame_rate() * 60) / (bbt_beat_subdivision * (*i).tempo->beats_per_minute()));
1296 frame_skip_error -= frame_skip;
1297 skip = (uint32_t) (Timecode::BBT_Time::ticks_per_beat / bbt_beat_subdivision);
1299 pos = (*i).frame + frame_skip;
1300 accumulated_error = frame_skip_error;
1304 for (t = 0; (tick < Timecode::BBT_Time::ticks_per_beat) && (n < bbt_nmarks) && (pos < next_beat_pos) ; pos += frame_skip, tick += skip, ++t) {
1306 if (t % bbt_accent_modulo == (bbt_accent_modulo - 1)) {
1307 i_am_accented = true;
1312 /* Error compensation for float to framepos_t*/
1313 accumulated_error += frame_skip_error;
1314 if (accumulated_error > 1) {
1316 accumulated_error -= 1.0f;
1319 mark.position = pos;
1321 if ((bbt_beat_subdivision > 4) && i_am_accented) {
1322 mark.style = ArdourCanvas::Ruler::Mark::Minor;
1324 mark.style = ArdourCanvas::Ruler::Mark::Micro;
1326 i_am_accented = false;
1327 marks.push_back (mark);
1334 case bbt_show_ticks_detail:
1336 beats = distance (begin, end);
1337 bbt_nmarks = (beats + 2) * bbt_beat_subdivision;
1339 bbt_position_of_helper = lower + (30 * Editor::get_current_zoom ());
1342 mark.position = lower;
1343 mark.style = ArdourCanvas::Ruler::Mark::Micro;
1344 marks.push_back (mark);
1346 for (n = 1, i = begin; n < bbt_nmarks && i != end; ++i) {
1348 if ((*i).frame < lower && (bbt_bar_helper_on)) {
1349 snprintf (buf, sizeof(buf), "<%" PRIu32 "|%" PRIu32, (*i).bar, (*i).beat);
1350 edit_last_mark_label (marks, buf);
1351 helper_active = true;
1354 if ((*i).is_bar()) {
1355 mark.style = ArdourCanvas::Ruler::Mark::Major;
1356 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1358 mark.style = ArdourCanvas::Ruler::Mark::Minor;
1359 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).beat);
1361 if (((*i).frame < bbt_position_of_helper) && helper_active) {
1365 mark.position = (*i).frame;
1366 marks.push_back (mark);
1370 /* Add the tick marks */
1372 /* Find the next beat */
1374 next_beat.beats = (*i).beat;
1375 next_beat.bars = (*i).bar;
1377 if ((*i).meter->divisions_per_bar() > (next_beat.beats + 1)) {
1378 next_beat.beats += 1;
1380 next_beat.bars += 1;
1381 next_beat.beats = 1;
1384 next_beat_pos = _session->tempo_map().frame_time(next_beat);
1386 frame_skip = (framepos_t) floor (frame_skip_error = (_session->frame_rate() * 60) / (bbt_beat_subdivision * (*i).tempo->beats_per_minute()));
1387 frame_skip_error -= frame_skip;
1388 skip = (uint32_t) (Timecode::BBT_Time::ticks_per_beat / bbt_beat_subdivision);
1390 pos = (*i).frame + frame_skip;
1391 accumulated_error = frame_skip_error;
1395 for (t = 0; (tick < Timecode::BBT_Time::ticks_per_beat) && (n < bbt_nmarks) && (pos < next_beat_pos) ; pos += frame_skip, tick += skip, ++t) {
1397 if (t % bbt_accent_modulo == (bbt_accent_modulo - 1)) {
1398 i_am_accented = true;
1401 if (i_am_accented && (pos > bbt_position_of_helper)){
1402 snprintf (buf, sizeof(buf), "%" PRIu32, tick);
1409 /* Error compensation for float to framepos_t*/
1410 accumulated_error += frame_skip_error;
1411 if (accumulated_error > 1) {
1413 accumulated_error -= 1.0f;
1416 mark.position = pos;
1418 if ((bbt_beat_subdivision > 4) && i_am_accented) {
1419 mark.style = ArdourCanvas::Ruler::Mark::Minor;
1421 mark.style = ArdourCanvas::Ruler::Mark::Micro;
1423 i_am_accented = false;
1430 case bbt_show_ticks_super_detail:
1432 beats = distance (begin, end);
1433 bbt_nmarks = (beats + 2) * bbt_beat_subdivision;
1435 bbt_position_of_helper = lower + (30 * Editor::get_current_zoom ());
1438 mark.position = lower;
1439 mark.style = ArdourCanvas::Ruler::Mark::Micro;
1440 marks.push_back (mark);
1442 for (n = 1, i = begin; n < bbt_nmarks && i != end; ++i) {
1444 if ((*i).frame < lower && (bbt_bar_helper_on)) {
1445 snprintf (buf, sizeof(buf), "<%" PRIu32 "|%" PRIu32, (*i).bar, (*i).beat);
1446 edit_last_mark_label (marks, buf);
1447 helper_active = true;
1450 if ((*i).is_bar()) {
1451 mark.style = ArdourCanvas::Ruler::Mark::Major;
1452 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1454 mark.style = ArdourCanvas::Ruler::Mark::Minor;
1455 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).beat);
1457 if (((*i).frame < bbt_position_of_helper) && helper_active) {
1461 mark.position = (*i).frame;
1462 marks.push_back (mark);
1466 /* Add the tick marks */
1468 /* Find the next beat */
1470 next_beat.beats = (*i).beat;
1471 next_beat.bars = (*i).bar;
1473 if ((*i).meter->divisions_per_bar() > (next_beat.beats + 1)) {
1474 next_beat.beats += 1;
1476 next_beat.bars += 1;
1477 next_beat.beats = 1;
1480 next_beat_pos = _session->tempo_map().frame_time(next_beat);
1482 frame_skip = (framepos_t) floor (frame_skip_error = (_session->frame_rate() * 60) / (bbt_beat_subdivision * (*i).tempo->beats_per_minute()));
1483 frame_skip_error -= frame_skip;
1484 skip = (uint32_t) (Timecode::BBT_Time::ticks_per_beat / bbt_beat_subdivision);
1486 pos = (*i).frame + frame_skip;
1487 accumulated_error = frame_skip_error;
1491 for (t = 0; (tick < Timecode::BBT_Time::ticks_per_beat) && (n < bbt_nmarks) && (pos < next_beat_pos) ; pos += frame_skip, tick += skip, ++t) {
1493 if (t % bbt_accent_modulo == (bbt_accent_modulo - 1)) {
1494 i_am_accented = true;
1497 if (pos > bbt_position_of_helper) {
1498 snprintf (buf, sizeof(buf), "%" PRIu32, tick);
1505 /* Error compensation for float to framepos_t*/
1506 accumulated_error += frame_skip_error;
1507 if (accumulated_error > 1) {
1509 accumulated_error -= 1.0f;
1512 mark.position = pos;
1514 if ((bbt_beat_subdivision > 4) && i_am_accented) {
1515 mark.style = ArdourCanvas::Ruler::Mark::Minor;
1517 mark.style = ArdourCanvas::Ruler::Mark::Micro;
1519 i_am_accented = false;
1520 marks.push_back (mark);
1529 snprintf (buf, sizeof(buf), "cannot handle %" PRIu32 " bars", bbt_bars );
1530 mark.style = ArdourCanvas::Ruler::Mark::Major;
1532 mark.position = lower;
1533 marks.push_back (mark);
1538 bbt_nmarks = (gint) (bbt_bars / 64) + 1;
1539 for (n = 0, i = begin; i != end && n < bbt_nmarks; i++) {
1540 if ((*i).is_bar()) {
1541 if ((*i).bar % 64 == 1) {
1542 if ((*i).bar % 256 == 1) {
1543 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1544 mark.style = ArdourCanvas::Ruler::Mark::Major;
1547 if ((*i).bar % 256 == 129) {
1548 mark.style = ArdourCanvas::Ruler::Mark::Minor;
1550 mark.style = ArdourCanvas::Ruler::Mark::Micro;
1554 mark.position = (*i).frame;
1555 marks.push_back (mark);
1563 bbt_nmarks = (bbt_bars / 16) + 1;
1564 for (n = 0, i = begin; i != end && n < bbt_nmarks; i++) {
1565 if ((*i).is_bar()) {
1566 if ((*i).bar % 16 == 1) {
1567 if ((*i).bar % 64 == 1) {
1568 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1569 mark.style = ArdourCanvas::Ruler::Mark::Major;
1572 if ((*i).bar % 64 == 33) {
1573 mark.style = ArdourCanvas::Ruler::Mark::Minor;
1575 mark.style = ArdourCanvas::Ruler::Mark::Micro;
1579 mark.position = (*i).frame;
1580 marks.push_back (mark);
1588 bbt_nmarks = (bbt_bars / 4) + 1;
1589 for (n = 0, i = begin; i != end && n < bbt_nmarks; ++i) {
1590 if ((*i).is_bar()) {
1591 if ((*i).bar % 4 == 1) {
1592 if ((*i).bar % 16 == 1) {
1593 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1594 mark.style = ArdourCanvas::Ruler::Mark::Major;
1597 if ((*i).bar % 16 == 9) {
1598 mark.style = ArdourCanvas::Ruler::Mark::Minor;
1600 mark.style = ArdourCanvas::Ruler::Mark::Micro;
1604 mark.position = (*i).frame;
1605 marks.push_back (mark);
1614 bbt_nmarks = bbt_bars + 2;
1615 for (n = 0, i = begin; i != end && n < bbt_nmarks; ++i) {
1616 if ((*i).is_bar()) {
1617 if ((*i).bar % 4 == 1) {
1618 snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
1619 mark.style = ArdourCanvas::Ruler::Mark::Major;
1622 if ((*i).bar % 4 == 3) {
1623 mark.style = ArdourCanvas::Ruler::Mark::Minor;
1625 mark.style = ArdourCanvas::Ruler::Mark::Micro;
1629 mark.position = (*i).frame;
1630 marks.push_back (mark);
1640 Editor::set_samples_ruler_scale (framepos_t lower, framepos_t upper)
1642 _samples_ruler_interval = (upper - lower) / 5;
1646 Editor::metric_get_samples (std::vector<ArdourCanvas::Ruler::Mark>& marks, gdouble lower, gdouble /*upper*/, gint /*maxchars*/)
1649 framepos_t const ilower = (framepos_t) floor (lower);
1653 ArdourCanvas::Ruler::Mark mark;
1655 if (_session == 0) {
1660 for (n = 0, pos = ilower; n < nmarks; pos += _samples_ruler_interval, ++n) {
1661 snprintf (buf, sizeof(buf), "%" PRIi64, pos);
1663 mark.position = pos;
1664 mark.style = ArdourCanvas::Ruler::Mark::Major;
1665 marks.push_back (mark);
1670 sample_to_clock_parts ( framepos_t sample,
1671 framepos_t sample_rate,
1685 hrs = left / (sample_rate * 60 * 60 * 1000);
1686 left -= hrs * sample_rate * 60 * 60 * 1000;
1687 mins = left / (sample_rate * 60 * 1000);
1688 left -= mins * sample_rate * 60 * 1000;
1689 secs = left / (sample_rate * 1000);
1690 left -= secs * sample_rate * 1000;
1691 millisecs = left / sample_rate;
1693 *millisecs_p = millisecs;
1702 Editor::set_minsec_ruler_scale (framepos_t lower, framepos_t upper)
1707 if (_session == 0) {
1711 fr = _session->frame_rate() * 1000;
1713 /* to prevent 'flashing' */
1714 if (lower > (spacer = (framepos_t)(128 * Editor::get_current_zoom ()))) {
1720 framecnt_t const range = (upper - lower) * 1000;
1722 if (range < (fr / 50)) {
1723 minsec_mark_interval = fr / 1000; /* show 1/1000 seconds */
1724 minsec_ruler_scale = minsec_show_frames;
1725 minsec_mark_modulo = 10;
1726 } else if (range <= (fr / 10)) { /* 0-0.1 second */
1727 minsec_mark_interval = fr / 1000; /* show 1/1000 seconds */
1728 minsec_ruler_scale = minsec_show_frames;
1729 minsec_mark_modulo = 10;
1730 } else if (range <= (fr / 2)) { /* 0-0.5 second */
1731 minsec_mark_interval = fr / 100; /* show 1/100 seconds */
1732 minsec_ruler_scale = minsec_show_frames;
1733 minsec_mark_modulo = 100;
1734 } else if (range <= fr) { /* 0-1 second */
1735 minsec_mark_interval = fr / 10; /* show 1/10 seconds */
1736 minsec_ruler_scale = minsec_show_frames;
1737 minsec_mark_modulo = 200;
1738 } else if (range <= 2 * fr) { /* 1-2 seconds */
1739 minsec_mark_interval = fr / 10; /* show 1/10 seconds */
1740 minsec_ruler_scale = minsec_show_frames;
1741 minsec_mark_modulo = 500;
1742 } else if (range <= 8 * fr) { /* 2-5 seconds */
1743 minsec_mark_interval = fr / 5; /* show 2 seconds */
1744 minsec_ruler_scale = minsec_show_frames;
1745 minsec_mark_modulo = 1000;
1746 } else if (range <= 16 * fr) { /* 8-16 seconds */
1747 minsec_mark_interval = fr; /* show 1 seconds */
1748 minsec_ruler_scale = minsec_show_seconds;
1749 minsec_mark_modulo = 2;
1750 } else if (range <= 30 * fr) { /* 10-30 seconds */
1751 minsec_mark_interval = fr; /* show 1 seconds */
1752 minsec_ruler_scale = minsec_show_seconds;
1753 minsec_mark_modulo = 5;
1754 } else if (range <= 60 * fr) { /* 30-60 seconds */
1755 minsec_mark_interval = fr; /* show 1 seconds */
1756 minsec_ruler_scale = minsec_show_seconds;
1757 minsec_mark_modulo = 5;
1758 } else if (range <= 2 * 60 * fr) { /* 1-2 minutes */
1759 minsec_mark_interval = 5 * fr; /* show 5 seconds */
1760 minsec_ruler_scale = minsec_show_seconds;
1761 minsec_mark_modulo = 3;
1762 } else if (range <= 4 * 60 * fr) { /* 4 minutes */
1763 minsec_mark_interval = 5 * fr; /* show 10 seconds */
1764 minsec_ruler_scale = minsec_show_seconds;
1765 minsec_mark_modulo = 30;
1766 } else if (range <= 10 * 60 * fr) { /* 10 minutes */
1767 minsec_mark_interval = 30 * fr; /* show 30 seconds */
1768 minsec_ruler_scale = minsec_show_seconds;
1769 minsec_mark_modulo = 120;
1770 } else if (range <= 30 * 60 * fr) { /* 10-30 minutes */
1771 minsec_mark_interval = 60 * fr; /* show 1 minute */
1772 minsec_ruler_scale = minsec_show_minutes;
1773 minsec_mark_modulo = 5;
1774 } else if (range <= 60 * 60 * fr) { /* 30 minutes - 1hr */
1775 minsec_mark_interval = 2 * 60 * fr; /* show 2 minutes */
1776 minsec_ruler_scale = minsec_show_minutes;
1777 minsec_mark_modulo = 10;
1778 } else if (range <= 4 * 60 * 60 * fr) { /* 1 - 4 hrs*/
1779 minsec_mark_interval = 5 * 60 * fr; /* show 10 minutes */
1780 minsec_ruler_scale = minsec_show_minutes;
1781 minsec_mark_modulo = 30;
1782 } else if (range <= 8 * 60 * 60 * fr) { /* 4 - 8 hrs*/
1783 minsec_mark_interval = 20 * 60 * fr; /* show 20 minutes */
1784 minsec_ruler_scale = minsec_show_minutes;
1785 minsec_mark_modulo = 60;
1786 } else if (range <= 16 * 60 * 60 * fr) { /* 16-24 hrs*/
1787 minsec_mark_interval = 60 * 60 * fr; /* show 60 minutes */
1788 minsec_ruler_scale = minsec_show_hours;
1789 minsec_mark_modulo = 2;
1792 /* not possible if framepos_t is a 32 bit quantity */
1794 minsec_mark_interval = 4 * 60 * 60 * fr; /* show 4 hrs */
1796 minsec_nmarks = 2 + (range / minsec_mark_interval);
1800 Editor::metric_get_minsec (std::vector<ArdourCanvas::Ruler::Mark>& marks, gdouble lower, gdouble /*upper*/, gint /*maxchars*/)
1804 long hrs, mins, secs, millisecs;
1807 ArdourCanvas::Ruler::Mark mark;
1809 if (_session == 0) {
1813 /* to prevent 'flashing' */
1814 if (lower > (spacer = (framepos_t) (128 * Editor::get_current_zoom ()))) {
1815 lower = lower - spacer;
1820 pos = (((1000 * (framepos_t) floor(lower)) + (minsec_mark_interval/2))/minsec_mark_interval) * minsec_mark_interval;
1821 switch (minsec_ruler_scale) {
1822 case minsec_show_seconds:
1823 for (n = 0; n < minsec_nmarks; pos += minsec_mark_interval, ++n) {
1824 sample_to_clock_parts (pos, _session->frame_rate(), &hrs, &mins, &secs, &millisecs);
1825 if (secs % minsec_mark_modulo == 0) {
1827 mark.style = ArdourCanvas::Ruler::Mark::Major;
1829 mark.style = ArdourCanvas::Ruler::Mark::Minor;
1831 snprintf (buf, sizeof(buf), "%02ld:%02ld:%02ld.%03ld", hrs, mins, secs, millisecs);
1834 mark.style = ArdourCanvas::Ruler::Mark::Micro;
1837 mark.position = pos/1000.0;
1838 marks.push_back (mark);
1841 case minsec_show_minutes:
1842 for (n = 0; n < minsec_nmarks; pos += minsec_mark_interval, ++n) {
1843 sample_to_clock_parts (pos, _session->frame_rate(), &hrs, &mins, &secs, &millisecs);
1844 if (mins % minsec_mark_modulo == 0) {
1846 mark.style = ArdourCanvas::Ruler::Mark::Major;
1848 mark.style = ArdourCanvas::Ruler::Mark::Minor;
1850 snprintf (buf, sizeof(buf), "%02ld:%02ld:%02ld.%03ld", hrs, mins, secs, millisecs);
1853 mark.style = ArdourCanvas::Ruler::Mark::Micro;
1856 mark.position = pos/1000.0;
1857 marks.push_back (mark);
1860 case minsec_show_hours:
1861 for (n = 0; n < minsec_nmarks; pos += minsec_mark_interval, ++n) {
1862 sample_to_clock_parts (pos, _session->frame_rate(), &hrs, &mins, &secs, &millisecs);
1863 if (hrs % minsec_mark_modulo == 0) {
1864 mark.style = ArdourCanvas::Ruler::Mark::Major;
1865 snprintf (buf, sizeof(buf), "%02ld:%02ld:%02ld.%03ld", hrs, mins, secs, millisecs);
1868 mark.style = ArdourCanvas::Ruler::Mark::Micro;
1871 mark.position = pos/1000.0;
1872 marks.push_back (mark);
1875 case minsec_show_frames:
1876 for (n = 0; n < minsec_nmarks; pos += minsec_mark_interval, ++n) {
1877 sample_to_clock_parts (pos, _session->frame_rate(), &hrs, &mins, &secs, &millisecs);
1878 if (millisecs % minsec_mark_modulo == 0) {
1879 if (millisecs == 0) {
1880 mark.style = ArdourCanvas::Ruler::Mark::Major;
1882 mark.style = ArdourCanvas::Ruler::Mark::Minor;
1884 snprintf (buf, sizeof(buf), "%02ld:%02ld:%02ld.%03ld", hrs, mins, secs, millisecs);
1887 mark.style = ArdourCanvas::Ruler::Mark::Micro;
1890 mark.position = pos/1000.0;
1891 marks.push_back (mark);