2 Copyright (C) 2012 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include "pbd/unwind.h"
21 #include "ardour/tempo.h"
24 #include "main_clock.h"
25 #include "ui_config.h"
26 #include "public_editor.h"
31 using namespace ARDOUR;
33 MainClock::MainClock (
34 const std::string& clock_name,
35 const std::string& widget_name,
38 : AudioClock (clock_name, false, widget_name, true, true, false, true)
40 , _suspend_delta_mode_signal (false)
45 MainClock::set_session (ARDOUR::Session *s)
47 AudioClock::set_session (s);
48 _left_btn.set_related_action (ActionManager::get_action (X_("Editor"), X_("edit-current-tempo")));
49 _right_btn.set_related_action (ActionManager::get_action (X_("Editor"), X_("edit-current-meter")));
53 MainClock::build_ops_menu ()
55 using namespace Menu_Helpers;
57 AudioClock::build_ops_menu ();
59 MenuList& ops_items = ops_menu->items();
60 ops_items.push_back (SeparatorElem ());
61 RadioMenuItem::Group group;
62 PBD::Unwinder<bool> uw (_suspend_delta_mode_signal, true);
65 mode = UIConfiguration::instance().get_primary_clock_delta_mode ();
67 mode = UIConfiguration::instance().get_secondary_clock_delta_mode ();
70 ops_items.push_back (RadioMenuElem (group, _("Display absolute time"), sigc::bind (sigc::mem_fun (*this, &MainClock::set_display_delta_mode), NoDelta)));
71 if (mode == NoDelta) {
72 RadioMenuItem* i = dynamic_cast<RadioMenuItem *> (&ops_items.back ());
75 ops_items.push_back (RadioMenuElem (group, _("Display delta to edit cursor"), sigc::bind (sigc::mem_fun (*this, &MainClock::set_display_delta_mode), DeltaEditPoint)));
76 if (mode == DeltaEditPoint) {
77 RadioMenuItem* i = dynamic_cast<RadioMenuItem *> (&ops_items.back ());
80 ops_items.push_back (RadioMenuElem (group, _("Display delta to origin marker"), sigc::bind (sigc::mem_fun (*this, &MainClock::set_display_delta_mode), DeltaOriginMarker)));
81 if (mode == DeltaOriginMarker) {
82 RadioMenuItem* i = dynamic_cast<RadioMenuItem *> (&ops_items.back ());
86 ops_items.push_back (SeparatorElem());
88 ops_items.push_back (MenuElem (_("Edit Tempo"), sigc::mem_fun(*this, &MainClock::edit_current_tempo)));
89 ops_items.push_back (MenuElem (_("Edit Meter"), sigc::mem_fun(*this, &MainClock::edit_current_meter)));
90 ops_items.push_back (MenuElem (_("Insert Tempo Change"), sigc::mem_fun(*this, &MainClock::insert_new_tempo)));
91 ops_items.push_back (MenuElem (_("Insert Meter Change"), sigc::mem_fun(*this, &MainClock::insert_new_meter)));
95 MainClock::absolute_time () const
97 if (get_is_duration ()) {
98 return current_time () + offset ();
100 return current_time ();
105 MainClock::set (samplepos_t when, bool force, ARDOUR::samplecnt_t /*offset*/)
109 mode = UIConfiguration::instance().get_primary_clock_delta_mode ();
111 mode = UIConfiguration::instance().get_secondary_clock_delta_mode ();
113 if (!PublicEditor::instance().session()) {
119 AudioClock::set (when, force, 0);
122 AudioClock::set (when, force, PublicEditor::instance().get_preferred_edit_position (Editing::EDIT_IGNORE_PHEAD));
124 case DeltaOriginMarker:
126 Location* loc = PublicEditor::instance().session()->locations()->clock_origin_location ();
127 AudioClock::set (when, force, loc ? loc->start() : 0);
134 MainClock::set_display_delta_mode (ClockDeltaMode m)
136 if (_suspend_delta_mode_signal) {
140 UIConfiguration::instance().set_primary_clock_delta_mode (m);
142 UIConfiguration::instance().set_secondary_clock_delta_mode (m);
147 MainClock::edit_current_tempo ()
149 if (!PublicEditor::instance().session()) return;
150 ARDOUR::TempoSection* ts = const_cast<ARDOUR::TempoSection*>(&PublicEditor::instance().session()->tempo_map().tempo_section_at_sample (absolute_time()));
151 PublicEditor::instance().edit_tempo_section (ts);
155 MainClock::edit_current_meter ()
157 if (!PublicEditor::instance().session()) return;
158 ARDOUR::MeterSection* ms = const_cast<ARDOUR::MeterSection*>(&PublicEditor::instance().session()->tempo_map().meter_section_at_sample (absolute_time()));
159 PublicEditor::instance().edit_meter_section (ms);
163 MainClock::insert_new_tempo ()
165 PublicEditor::instance().mouse_add_new_tempo_event (absolute_time ());
169 MainClock::insert_new_meter ()
171 PublicEditor::instance().mouse_add_new_meter_event (absolute_time ());