1 #include <cstdio> // for snprintf, grrr
3 #include <gtkmm2ext/utils.h>
5 #include "tempo_dialog.h"
11 using namespace ARDOUR;
13 TempoDialog::TempoDialog (TempoMap& map, jack_nframes_t frame, string action)
14 : ArdourDialog ("tempo dialog"),
15 bpm_frame (_("Beats per minute")),
17 cancel_button (_("Cancel")),
18 when_bar_label (_("Bar")),
19 when_beat_label (_("Beat")),
21 when_frame (_("Location"))
24 Tempo tempo (map.tempo_at (frame));
25 map.bbt_time (frame, when);
27 init (when, tempo.beats_per_minute(), true);
30 TempoDialog::TempoDialog (TempoSection& section, string action)
31 : ArdourDialog ("tempo dialog"),
32 bpm_frame (_("Beats per minute")),
34 cancel_button (_("Cancel")),
35 when_bar_label (_("Bar")),
36 when_beat_label (_("Beat")),
38 when_frame (_("Location"))
40 init (section.start(), section.beats_per_minute(), section.movable());
44 TempoDialog::init (const BBT_Time& when, double bpm, bool movable)
46 snprintf (buf, sizeof (buf), "%.2f", bpm);
47 bpm_entry.set_text (buf);
48 bpm_entry.select_region (0, -1);
50 hspacer1.set_border_width (5);
51 hspacer1.pack_start (bpm_entry, false, false);
52 vspacer1.set_border_width (5);
53 vspacer1.pack_start (hspacer1, false, false);
55 bpm_frame.add (vspacer1);
57 button_box.set_border_width (10);
58 button_box.set_spacing (5);
59 button_box.set_homogeneous (true);
60 button_box.pack_start (ok_button);
61 button_box.pack_start (cancel_button);
63 vpacker.set_border_width (10);
64 vpacker.set_spacing (5);
67 snprintf (buf, sizeof (buf), "%" PRIu32, when.bars);
68 when_bar_entry.set_text (buf);
69 snprintf (buf, sizeof (buf), "%" PRIu32, when.beats);
70 when_beat_entry.set_text (buf);
72 when_bar_entry.set_name ("MetricEntry");
73 when_beat_entry.set_name ("MetricEntry");
75 when_bar_label.set_name ("MetricLabel");
76 when_beat_label.set_name ("MetricLabel");
78 Gtkmm2ext::set_size_request_to_display_given_text (when_bar_entry, "999g", 5, 7);
79 Gtkmm2ext::set_size_request_to_display_given_text (when_beat_entry, "999g", 5, 7);
81 when_table.set_homogeneous (true);
82 when_table.set_row_spacings (2);
83 when_table.set_col_spacings (2);
84 when_table.set_border_width (5);
86 when_table.attach (when_bar_label, 0, 1, 0, 1, Gtk::AttachOptions(0), Gtk::FILL|Gtk::EXPAND);
87 when_table.attach (when_bar_entry, 0, 1, 1, 2, Gtk::AttachOptions(0), Gtk::FILL|Gtk::EXPAND);
89 when_table.attach (when_beat_label, 1, 2, 0, 1, Gtk::AttachOptions(0), Gtk::AttachOptions(0));
90 when_table.attach (when_beat_entry, 1, 2, 1, 2, Gtk::AttachOptions(0), Gtk::AttachOptions(0));
92 when_frame.set_name ("MetricDialogFrame");
93 when_frame.add (when_table);
95 vpacker.pack_start (when_frame, false, false);
98 vpacker.pack_start (bpm_frame, false, false);
99 vpacker.pack_start (button_box, false, false);
101 bpm_frame.set_name ("MetricDialogFrame");
102 bpm_entry.set_name ("MetricEntry");
103 ok_button.set_name ("MetricButton");
104 cancel_button.set_name ("MetricButton");
107 set_name ("MetricDialog");
109 set_keyboard_input(true);
113 TempoDialog::get_bpm ()
117 if (sscanf (bpm_entry.get_text().c_str(), "%lf", &bpm) != 1) {
125 TempoDialog::get_bbt_time (BBT_Time& requested)
127 if (sscanf (when_bar_entry.get_text().c_str(), "%" PRIu32, &requested.bars) != 1) {
131 if (sscanf (when_beat_entry.get_text().c_str(), "%" PRIu32, &requested.beats) != 1) {
139 MeterDialog::MeterDialog (TempoMap& map, jack_nframes_t frame, string action)
140 : ArdourDialog ("meter dialog"),
141 note_frame (_("Meter denominator")),
142 bpb_frame (_("Beats per bar")),
144 cancel_button (_("Cancel")),
145 when_bar_label (_("Bar")),
146 when_beat_label (_("Beat")),
147 when_frame (_("Location"))
150 frame = map.round_to_bar(frame,0);
151 Meter meter (map.meter_at(frame));
153 map.bbt_time (frame, when);
154 init (when, meter.beats_per_bar(), meter.note_divisor(), true);
157 MeterDialog::MeterDialog (MeterSection& section, string action)
158 : ArdourDialog ("meter dialog"),
159 note_frame (_("Meter denominator")),
160 bpb_frame (_("Beats per bar")),
162 cancel_button (_("Cancel")),
163 when_bar_label (_("Bar")),
164 when_beat_label (_("Beat")),
165 when_frame (_("Location"))
167 init (section.start(), section.beats_per_bar(), section.note_divisor(), section.movable());
171 MeterDialog::init (const BBT_Time& when, double bpb, double note_type, bool movable)
173 snprintf (buf, sizeof (buf), "%.2f", bpb);
174 bpb_entry.set_text (buf);
175 bpb_entry.select_region (0, -1);
176 Gtkmm2ext::set_size_request_to_display_given_text (bpb_entry, "999999g", 5, 5);
179 strings.push_back (_("whole (1)"));
180 strings.push_back (_("second (2)"));
181 strings.push_back (_("third (3)"));
182 strings.push_back (_("quarter (4)"));
183 strings.push_back (_("eighth (8)"));
184 strings.push_back (_("sixteenth (16)"));
185 strings.push_back (_("thirty-second (32)"));
187 set_popdown_strings (note_types, strings);
190 note_types.set_active_text (_("whole (1)"));
191 else if (note_type==2.0f)
192 note_types.set_active_text (_("second (2)"));
193 else if (note_type==3.0f)
194 note_types.set_active_text (_("third (3)"));
195 else if (note_type==4.0f)
196 note_types.set_active_text (_("quarter (4)"));
197 else if (note_type==8.0f)
198 note_types.set_active_text (_("eighth (8)"));
199 else if (note_type==16.0f)
200 note_types.set_active_text (_("sixteenth (16)"));
201 else if (note_type==32.0f)
202 note_types.set_active_text (_("thirty-second (32)"));
204 note_types.set_active_text (_("quarter (4)"));
206 /* strings.back() just happens to be the longest one to display */
208 // Gtkmm2ext::set_size_request_to_display_given_text (*(note_types.get_entry()), strings.back(), 7, 7);
210 hspacer1.set_border_width (5);
211 hspacer1.pack_start (note_types, false, false);
212 vspacer1.set_border_width (5);
213 vspacer1.pack_start (hspacer1, false, false);
215 hspacer2.set_border_width (5);
216 hspacer2.pack_start (bpb_entry, false, false);
217 vspacer2.set_border_width (5);
218 vspacer2.pack_start (hspacer2, false, false);
220 note_frame.add (vspacer1);
221 bpb_frame.add (vspacer2);
223 button_box.set_border_width (10);
224 button_box.set_spacing (5);
225 button_box.set_homogeneous (true);
226 button_box.pack_start (ok_button);
227 button_box.pack_start (cancel_button);
229 vpacker.set_border_width (10);
230 vpacker.set_spacing (5);
233 snprintf (buf, sizeof (buf), "%" PRIu32, when.bars);
234 when_bar_entry.set_text (buf);
235 snprintf (buf, sizeof (buf), "%" PRIu32, when.beats);
236 when_beat_entry.set_text (buf);
238 when_bar_entry.set_name ("MetricEntry");
239 when_beat_entry.set_name ("MetricEntry");
241 when_bar_label.set_name ("MetricLabel");
242 when_beat_label.set_name ("MetricLabel");
244 Gtkmm2ext::set_size_request_to_display_given_text (when_bar_entry, "999g", 5, 7);
245 Gtkmm2ext::set_size_request_to_display_given_text (when_beat_entry, "999g", 5, 7);
247 when_table.set_homogeneous (true);
248 when_table.set_row_spacings (2);
249 when_table.set_col_spacings (2);
250 when_table.set_border_width (5);
252 when_table.attach (when_bar_label, 0, 1, 0, 1, Gtk::AttachOptions(0), Gtk::FILL|Gtk::EXPAND);
253 when_table.attach (when_bar_entry, 0, 1, 1, 2, Gtk::AttachOptions(0), Gtk::FILL|Gtk::EXPAND);
255 when_table.attach (when_beat_label, 1, 2, 0, 1, Gtk::AttachOptions(0), Gtk::AttachOptions(0));
256 when_table.attach (when_beat_entry, 1, 2, 1, 2, Gtk::AttachOptions(0), Gtk::AttachOptions(0));
258 when_frame.set_name ("MetricDialogFrame");
259 when_frame.add (when_table);
261 vpacker.pack_start (when_frame, false, false);
264 vpacker.pack_start (bpb_frame, false, false);
265 vpacker.pack_start (note_frame, false, false);
266 vpacker.pack_start (button_box, false, false);
268 bpb_frame.set_name ("MetricDialogFrame");
269 note_frame.set_name ("MetricDialogFrame");
270 bpb_entry.set_name ("MetricEntry");
271 ok_button.set_name ("MetricButton");
272 cancel_button.set_name ("MetricButton");
275 set_name ("MetricDialog");
277 set_keyboard_input(true);
281 MeterDialog::get_bpb ()
285 if (sscanf (bpb_entry.get_text().c_str(), "%lf", &bpb) != 1) {
293 MeterDialog::get_note_type ()
295 double note_type = 0;
296 vector<const gchar *>::iterator i;
297 string text = note_types.get_active_text();
299 for (i = strings.begin(); i != strings.end(); ++i) {
301 if (sscanf (text.c_str(), "%*[^0-9]%lf", ¬e_type) != 1) {
302 error << compose(_("garbaged note type entry (%1)"), text) << endmsg;
310 if (i == strings.end()) {
311 if (sscanf (text.c_str(), "%lf", ¬e_type) != 1) {
312 error << compose(_("incomprehensible note type entry (%1)"), text) << endmsg;
321 MeterDialog::get_bbt_time (BBT_Time& requested)
325 if (sscanf (when_bar_entry.get_text().c_str(), "%" PRIu32, &requested.bars) != 1) {
329 if (sscanf (when_beat_entry.get_text().c_str(), "%" PRIu32, &requested.beats) != 1) {