1 #include <cstdio> // for snprintf, grrr
3 #include <gtkmm/stock.h>
4 #include <gtkmm2ext/utils.h>
6 #include "tempo_dialog.h"
12 using namespace Gtkmm2ext;
13 using namespace ARDOUR;
15 TempoDialog::TempoDialog (TempoMap& map, jack_nframes_t frame, string action)
16 : ArdourDialog ("tempo dialog"),
17 bpm_frame (_("Beats per minute")),
19 cancel_button (_("Cancel")),
20 when_bar_label (_("Bar")),
21 when_beat_label (_("Beat")),
23 when_frame (_("Location"))
26 Tempo tempo (map.tempo_at (frame));
27 map.bbt_time (frame, when);
29 init (when, tempo.beats_per_minute(), true);
32 TempoDialog::TempoDialog (TempoSection& section, string action)
33 : ArdourDialog ("tempo dialog"),
34 bpm_frame (_("Beats per minute")),
36 cancel_button (_("Cancel")),
37 when_bar_label (_("Bar")),
38 when_beat_label (_("Beat")),
40 when_frame (_("Location"))
42 init (section.start(), section.beats_per_minute(), section.movable());
46 TempoDialog::init (const BBT_Time& when, double bpm, bool movable)
48 snprintf (buf, sizeof (buf), "%.2f", bpm);
49 bpm_entry.set_text (buf);
50 bpm_entry.select_region (0, -1);
52 hspacer1.set_border_width (5);
53 hspacer1.pack_start (bpm_entry, false, false);
54 vspacer1.set_border_width (5);
55 vspacer1.pack_start (hspacer1, false, false);
57 bpm_frame.add (vspacer1);
60 snprintf (buf, sizeof (buf), "%" PRIu32, when.bars);
61 when_bar_entry.set_text (buf);
62 snprintf (buf, sizeof (buf), "%" PRIu32, when.beats);
63 when_beat_entry.set_text (buf);
65 when_bar_entry.set_name ("MetricEntry");
66 when_beat_entry.set_name ("MetricEntry");
68 when_bar_label.set_name ("MetricLabel");
69 when_beat_label.set_name ("MetricLabel");
71 Gtkmm2ext::set_size_request_to_display_given_text (when_bar_entry, "999g", 5, 7);
72 Gtkmm2ext::set_size_request_to_display_given_text (when_beat_entry, "999g", 5, 7);
74 when_table.set_homogeneous (true);
75 when_table.set_row_spacings (2);
76 when_table.set_col_spacings (2);
77 when_table.set_border_width (5);
79 when_table.attach (when_bar_label, 0, 1, 0, 1, Gtk::AttachOptions(0), Gtk::FILL|Gtk::EXPAND);
80 when_table.attach (when_bar_entry, 0, 1, 1, 2, Gtk::AttachOptions(0), Gtk::FILL|Gtk::EXPAND);
82 when_table.attach (when_beat_label, 1, 2, 0, 1, Gtk::AttachOptions(0), Gtk::AttachOptions(0));
83 when_table.attach (when_beat_entry, 1, 2, 1, 2, Gtk::AttachOptions(0), Gtk::AttachOptions(0));
85 when_frame.set_name ("MetricDialogFrame");
86 when_frame.add (when_table);
88 get_vbox()->pack_start (when_frame, false, false);
91 bpm_frame.set_name ("MetricDialogFrame");
92 bpm_entry.set_name ("MetricEntry");
94 get_vbox()->pack_start (bpm_frame, false, false);
96 add_button (Stock::OK, RESPONSE_ACCEPT);
97 add_button (Stock::CANCEL, RESPONSE_CANCEL);
99 get_vbox()->show_all();
102 set_name ("MetricDialog");
106 TempoDialog::get_bpm ()
110 if (sscanf (bpm_entry.get_text().c_str(), "%lf", &bpm) != 1) {
118 TempoDialog::get_bbt_time (BBT_Time& requested)
120 if (sscanf (when_bar_entry.get_text().c_str(), "%" PRIu32, &requested.bars) != 1) {
124 if (sscanf (when_beat_entry.get_text().c_str(), "%" PRIu32, &requested.beats) != 1) {
132 MeterDialog::MeterDialog (TempoMap& map, jack_nframes_t frame, string action)
133 : ArdourDialog ("meter dialog"),
134 note_frame (_("Meter denominator")),
135 bpb_frame (_("Beats per bar")),
137 cancel_button (_("Cancel")),
138 when_bar_label (_("Bar")),
139 when_beat_label (_("Beat")),
140 when_frame (_("Location"))
143 frame = map.round_to_bar(frame,0);
144 Meter meter (map.meter_at(frame));
146 map.bbt_time (frame, when);
147 init (when, meter.beats_per_bar(), meter.note_divisor(), true);
150 MeterDialog::MeterDialog (MeterSection& section, string action)
151 : ArdourDialog ("meter dialog"),
152 note_frame (_("Meter denominator")),
153 bpb_frame (_("Beats per bar")),
155 cancel_button (_("Cancel")),
156 when_bar_label (_("Bar")),
157 when_beat_label (_("Beat")),
158 when_frame (_("Location"))
160 init (section.start(), section.beats_per_bar(), section.note_divisor(), section.movable());
164 MeterDialog::init (const BBT_Time& when, double bpb, double note_type, bool movable)
166 snprintf (buf, sizeof (buf), "%.2f", bpb);
167 bpb_entry.set_text (buf);
168 bpb_entry.select_region (0, -1);
169 Gtkmm2ext::set_size_request_to_display_given_text (bpb_entry, "999999g", 5, 5);
171 strings.push_back (_("whole (1)"));
172 strings.push_back (_("second (2)"));
173 strings.push_back (_("third (3)"));
174 strings.push_back (_("quarter (4)"));
175 strings.push_back (_("eighth (8)"));
176 strings.push_back (_("sixteenth (16)"));
177 strings.push_back (_("thirty-second (32)"));
179 set_popdown_strings (note_types, strings);
182 note_types.set_active_text (_("whole (1)"));
183 else if (note_type==2.0f)
184 note_types.set_active_text (_("second (2)"));
185 else if (note_type==3.0f)
186 note_types.set_active_text (_("third (3)"));
187 else if (note_type==4.0f)
188 note_types.set_active_text (_("quarter (4)"));
189 else if (note_type==8.0f)
190 note_types.set_active_text (_("eighth (8)"));
191 else if (note_type==16.0f)
192 note_types.set_active_text (_("sixteenth (16)"));
193 else if (note_type==32.0f)
194 note_types.set_active_text (_("thirty-second (32)"));
196 note_types.set_active_text (_("quarter (4)"));
198 /* strings.back() just happens to be the longest one to display */
200 // Gtkmm2ext::set_size_request_to_display_given_text (*(note_types.get_entry()), strings.back(), 7, 7);
202 hspacer1.set_border_width (5);
203 hspacer1.pack_start (note_types, false, false);
204 vspacer1.set_border_width (5);
205 vspacer1.pack_start (hspacer1, false, false);
207 hspacer2.set_border_width (5);
208 hspacer2.pack_start (bpb_entry, false, false);
209 vspacer2.set_border_width (5);
210 vspacer2.pack_start (hspacer2, false, false);
212 note_frame.add (vspacer1);
213 bpb_frame.add (vspacer2);
216 snprintf (buf, sizeof (buf), "%" PRIu32, when.bars);
217 when_bar_entry.set_text (buf);
218 snprintf (buf, sizeof (buf), "%" PRIu32, when.beats);
219 when_beat_entry.set_text (buf);
221 when_bar_entry.set_name ("MetricEntry");
222 when_beat_entry.set_name ("MetricEntry");
224 when_bar_label.set_name ("MetricLabel");
225 when_beat_label.set_name ("MetricLabel");
227 Gtkmm2ext::set_size_request_to_display_given_text (when_bar_entry, "999g", 5, 7);
228 Gtkmm2ext::set_size_request_to_display_given_text (when_beat_entry, "999g", 5, 7);
230 when_table.set_homogeneous (true);
231 when_table.set_row_spacings (2);
232 when_table.set_col_spacings (2);
233 when_table.set_border_width (5);
235 when_table.attach (when_bar_label, 0, 1, 0, 1, Gtk::AttachOptions(0), Gtk::FILL|Gtk::EXPAND);
236 when_table.attach (when_bar_entry, 0, 1, 1, 2, Gtk::AttachOptions(0), Gtk::FILL|Gtk::EXPAND);
238 when_table.attach (when_beat_label, 1, 2, 0, 1, Gtk::AttachOptions(0), Gtk::AttachOptions(0));
239 when_table.attach (when_beat_entry, 1, 2, 1, 2, Gtk::AttachOptions(0), Gtk::AttachOptions(0));
241 when_frame.set_name ("MetricDialogFrame");
242 when_frame.add (when_table);
244 get_vbox()->pack_start (when_frame, false, false);
247 get_vbox()->pack_start (bpb_frame, false, false);
248 get_vbox()->pack_start (note_frame, false, false);
250 bpb_frame.set_name ("MetricDialogFrame");
251 note_frame.set_name ("MetricDialogFrame");
252 bpb_entry.set_name ("MetricEntry");
254 add_button (Stock::OK, RESPONSE_ACCEPT);
255 add_button (Stock::CANCEL, RESPONSE_CANCEL);
257 get_vbox()->show_all ();
260 set_name ("MetricDialog");
264 MeterDialog::get_bpb ()
268 if (sscanf (bpb_entry.get_text().c_str(), "%lf", &bpb) != 1) {
276 MeterDialog::get_note_type ()
278 double note_type = 0;
279 vector<string>::iterator i;
280 string text = note_types.get_active_text();
282 for (i = strings.begin(); i != strings.end(); ++i) {
284 if (sscanf (text.c_str(), "%*[^0-9]%lf", ¬e_type) != 1) {
285 error << string_compose(_("garbaged note type entry (%1)"), text) << endmsg;
293 if (i == strings.end()) {
294 if (sscanf (text.c_str(), "%lf", ¬e_type) != 1) {
295 error << string_compose(_("incomprehensible note type entry (%1)"), text) << endmsg;
304 MeterDialog::get_bbt_time (BBT_Time& requested)
308 if (sscanf (when_bar_entry.get_text().c_str(), "%" PRIu32, &requested.bars) != 1) {
312 if (sscanf (when_beat_entry.get_text().c_str(), "%" PRIu32, &requested.beats) != 1) {