update some calls to use new get_preferred_edit_position; needs testing
[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_ui.h"
21 #include "main_clock.h"
22 #include "public_editor.h"
23
24 #include "i18n.h"
25
26 #include "ardour/tempo.h"
27
28 using namespace Gtk;
29
30 MainClock::MainClock (
31         const std::string& clock_name,
32         const std::string& widget_name,
33         bool primary
34         )
35         : AudioClock (clock_name, false, widget_name, true, true, false, true)
36           , _primary (primary)
37 {
38
39 }
40
41 void
42 MainClock::build_ops_menu ()
43 {
44         using namespace Menu_Helpers;
45
46         AudioClock::build_ops_menu ();
47
48         MenuList& ops_items = ops_menu->items();
49         ops_items.push_back (SeparatorElem ());
50         ops_items.push_back (CheckMenuElem (_("Display delta to edit cursor"), sigc::mem_fun (*this, &MainClock::display_delta_to_edit_cursor)));
51         Gtk::CheckMenuItem* c = dynamic_cast<Gtk::CheckMenuItem *> (&ops_items.back());
52         if (_primary) {
53                 if (ARDOUR_UI::config()->get_primary_clock_delta_edit_cursor ()) {
54                         ARDOUR_UI::config()->set_primary_clock_delta_edit_cursor (false);
55                         c->set_active (true);
56                 }
57         } else {
58                 if (ARDOUR_UI::config()->get_secondary_clock_delta_edit_cursor ()) {
59                         ARDOUR_UI::config()->set_secondary_clock_delta_edit_cursor (false);
60                         c->set_active (true);
61                 }
62         }
63
64         ops_items.push_back (SeparatorElem());
65         ops_items.push_back (MenuElem (_("Edit Tempo"), sigc::mem_fun(*this, &MainClock::edit_current_tempo)));
66         ops_items.push_back (MenuElem (_("Edit Meter"), sigc::mem_fun(*this, &MainClock::edit_current_meter)));
67         ops_items.push_back (MenuElem (_("Insert Tempo Change"), sigc::mem_fun(*this, &MainClock::insert_new_tempo)));
68         ops_items.push_back (MenuElem (_("Insert Meter Change"), sigc::mem_fun(*this, &MainClock::insert_new_meter)));
69 }
70
71 framepos_t
72 MainClock::absolute_time () const
73 {
74         if (get_is_duration ()) {
75                 // delta to edit cursor
76                 return current_time () + PublicEditor::instance().get_preferred_edit_position (Editing::EDIT_IGNORE_PHEAD);
77         } else {
78                 return current_time ();
79         }
80 }
81
82 void
83 MainClock::display_delta_to_edit_cursor ()
84 {
85         if (_primary) {
86                 ARDOUR_UI::config()->set_primary_clock_delta_edit_cursor (!ARDOUR_UI::config()->get_primary_clock_delta_edit_cursor ());
87         } else {
88                 ARDOUR_UI::config()->set_secondary_clock_delta_edit_cursor (!ARDOUR_UI::config()->get_secondary_clock_delta_edit_cursor ());
89         }
90 }
91
92 void
93 MainClock::edit_current_tempo ()
94 {
95         ARDOUR::TempoSection ts = PublicEditor::instance().session()->tempo_map().tempo_section_at (absolute_time());
96         PublicEditor::instance().edit_tempo_section (&ts);
97 }
98
99 void
100 MainClock::edit_current_meter ()
101 {
102         ARDOUR::MeterSection ms = PublicEditor::instance().session()->tempo_map().meter_section_at (absolute_time());
103         PublicEditor::instance().edit_meter_section (&ms);
104 }
105
106 void
107 MainClock::insert_new_tempo ()
108 {
109         PublicEditor::instance().mouse_add_new_tempo_event (absolute_time ());
110 }
111
112 void
113 MainClock::insert_new_meter ()
114 {
115         PublicEditor::instance().mouse_add_new_meter_event (absolute_time ());
116 }
117
118 bool
119 MainClock::on_button_press_event (GdkEventButton *ev)
120 {
121         if (ev->button == 1) {
122                 if (mode() == BBT) {
123                         if (is_lower_layout_click(ev->y)) {
124                                 if (is_right_layout_click(ev->x)) {
125                                         // meter on the right
126                                         edit_current_meter();
127                                 } else {
128                                         // tempo on the left
129                                         edit_current_tempo();
130                                 }
131                                 return true;
132                         }
133                 }
134         }
135
136         return AudioClock::on_button_press_event (ev);
137 }
138