do not change Session::_transport_frame is a locate is pending
[ardour.git] / gtk2_ardour / main_clock.cc
1 /*
2     Copyright (C) 2012 Paul Davis
3
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.
8
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.
13
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.
17
18 */
19
20 #include "ardour/tempo.h"
21
22 #include "actions.h"
23 #include "main_clock.h"
24 #include "ui_config.h"
25 #include "public_editor.h"
26
27 #include "pbd/i18n.h"
28
29 using namespace Gtk;
30
31 MainClock::MainClock (
32         const std::string& clock_name,
33         const std::string& widget_name,
34         bool primary
35         )
36         : AudioClock (clock_name, false, widget_name, true, true, false, true)
37           , _primary (primary)
38 {
39 }
40
41 void
42 MainClock::set_session (ARDOUR::Session *s)
43 {
44         AudioClock::set_session (s);
45         _left_btn.set_related_action (ActionManager::get_action (X_("Editor"), X_("edit-current-tempo")));
46         _right_btn.set_related_action (ActionManager::get_action (X_("Editor"), X_("edit-current-meter")));
47 }
48
49 void
50 MainClock::build_ops_menu ()
51 {
52         using namespace Menu_Helpers;
53
54         AudioClock::build_ops_menu ();
55
56         MenuList& ops_items = ops_menu->items();
57         ops_items.push_back (SeparatorElem ());
58         ops_items.push_back (CheckMenuElem (_("Display delta to edit cursor"), sigc::mem_fun (*this, &MainClock::display_delta_to_edit_cursor)));
59         Gtk::CheckMenuItem* c = dynamic_cast<Gtk::CheckMenuItem *> (&ops_items.back());
60         if (_primary) {
61                 if (UIConfiguration::instance().get_primary_clock_delta_edit_cursor ()) {
62                         UIConfiguration::instance().set_primary_clock_delta_edit_cursor (false);
63                         c->set_active (true);
64                 }
65         } else {
66                 if (UIConfiguration::instance().get_secondary_clock_delta_edit_cursor ()) {
67                         UIConfiguration::instance().set_secondary_clock_delta_edit_cursor (false);
68                         c->set_active (true);
69                 }
70         }
71
72         ops_items.push_back (SeparatorElem());
73         ops_items.push_back (MenuElem (_("Edit Tempo"), sigc::mem_fun(*this, &MainClock::edit_current_tempo)));
74         ops_items.push_back (MenuElem (_("Edit Meter"), sigc::mem_fun(*this, &MainClock::edit_current_meter)));
75         ops_items.push_back (MenuElem (_("Insert Tempo Change"), sigc::mem_fun(*this, &MainClock::insert_new_tempo)));
76         ops_items.push_back (MenuElem (_("Insert Meter Change"), sigc::mem_fun(*this, &MainClock::insert_new_meter)));
77 }
78
79 framepos_t
80 MainClock::absolute_time () const
81 {
82         if (get_is_duration ()) {
83                 // delta to edit cursor
84                 return current_time () + PublicEditor::instance().get_preferred_edit_position (Editing::EDIT_IGNORE_PHEAD);
85         } else {
86                 return current_time ();
87         }
88 }
89
90 void
91 MainClock::display_delta_to_edit_cursor ()
92 {
93         if (_primary) {
94                 UIConfiguration::instance().set_primary_clock_delta_edit_cursor (!UIConfiguration::instance().get_primary_clock_delta_edit_cursor ());
95         } else {
96                 UIConfiguration::instance().set_secondary_clock_delta_edit_cursor (!UIConfiguration::instance().get_secondary_clock_delta_edit_cursor ());
97         }
98 }
99
100 void
101 MainClock::edit_current_tempo ()
102 {
103         if (!PublicEditor::instance().session()) return;
104         ARDOUR::TempoSection* ts = const_cast<ARDOUR::TempoSection*>(&PublicEditor::instance().session()->tempo_map().tempo_section_at_frame (absolute_time()));
105         PublicEditor::instance().edit_tempo_section (ts);
106 }
107
108 void
109 MainClock::edit_current_meter ()
110 {
111         if (!PublicEditor::instance().session()) return;
112         ARDOUR::MeterSection* ms = const_cast<ARDOUR::MeterSection*>(&PublicEditor::instance().session()->tempo_map().meter_section_at_frame (absolute_time()));
113         PublicEditor::instance().edit_meter_section (ms);
114 }
115
116 void
117 MainClock::insert_new_tempo ()
118 {
119         PublicEditor::instance().mouse_add_new_tempo_event (absolute_time ());
120 }
121
122 void
123 MainClock::insert_new_meter ()
124 {
125         PublicEditor::instance().mouse_add_new_meter_event (absolute_time ());
126 }