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