2 Copyright (C) 2002 Paul Davis
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.
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.
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.
20 #include <cstdio> // for sprintf, grrr
26 #include <libgnomecanvasmm.h>
28 #include "pbd/error.h"
29 #include "pbd/memento_command.h"
31 #include <gtkmm2ext/utils.h>
32 #include <gtkmm2ext/gtk_ui.h>
34 #include "ardour/session.h"
35 #include "ardour/tempo.h"
36 #include <gtkmm2ext/doi.h>
37 #include <gtkmm2ext/utils.h>
41 #include "simpleline.h"
42 #include "tempo_dialog.h"
43 #include "rgb_macros.h"
44 #include "gui_thread.h"
45 #include "time_axis_view.h"
46 #include "ardour_ui.h"
47 #include "tempo_lines.h"
53 using namespace ARDOUR;
56 using namespace Gtkmm2ext;
57 using namespace Editing;
60 Editor::remove_metric_marks ()
62 /* don't delete these while handling events, just punt till the GUI is idle */
64 for (Marks::iterator x = metric_marks.begin(); x != metric_marks.end(); ++x) {
65 delete_when_idle (*x);
67 metric_marks.clear ();
71 Editor::draw_metric_marks (const Metrics& metrics)
74 const MeterSection *ms;
75 const TempoSection *ts;
78 remove_metric_marks ();
80 for (Metrics::const_iterator i = metrics.begin(); i != metrics.end(); ++i) {
82 if ((ms = dynamic_cast<const MeterSection*>(*i)) != 0) {
83 snprintf (buf, sizeof(buf), "%g/%g", ms->beats_per_bar(), ms->note_divisor ());
84 metric_marks.push_back (new MeterMarker (*this, *meter_group, ARDOUR_UI::config()->canvasvar_MeterMarker.get(), buf,
85 *(const_cast<MeterSection*>(ms))));
86 } else if ((ts = dynamic_cast<const TempoSection*>(*i)) != 0) {
87 snprintf (buf, sizeof (buf), "%.2f", ts->beats_per_minute());
88 metric_marks.push_back (new TempoMarker (*this, *tempo_group, ARDOUR_UI::config()->canvasvar_TempoMarker.get(), buf,
89 *(const_cast<TempoSection*>(ts))));
97 Editor::tempo_map_changed (Change ignored)
103 ENSURE_GUI_THREAD(bind (mem_fun (*this, &Editor::tempo_map_changed), ignored));
106 tempo_lines->tempo_map_changed();
108 compute_current_bbt_points(leftmost_frame, leftmost_frame + current_page_frames());
109 session->tempo_map().apply_with_metrics (*this, &Editor::draw_metric_marks); // redraw metric markers
114 Editor::redisplay_tempo (bool immediate_redraw)
120 compute_current_bbt_points (leftmost_frame, leftmost_frame + current_page_frames()); // redraw rulers and measures
122 compute_current_bbt_points (leftmost_frame, leftmost_frame + current_page_frames());
123 if (immediate_redraw) {
129 Glib::signal_idle().connect (mem_fun (*this, &Editor::redraw_measures));
132 update_tempo_based_rulers (); // redraw rulers and measures
136 Editor::compute_current_bbt_points (nframes_t leftmost, nframes_t rightmost)
142 BBT_Time previous_beat, next_beat; // the beats previous to the leftmost frame and after the rightmost frame
144 session->bbt_time(leftmost, previous_beat);
145 session->bbt_time(rightmost, next_beat);
147 if (previous_beat.beats > 1) {
148 previous_beat.beats -= 1;
149 } else if (previous_beat.bars > 1) {
150 previous_beat.bars--;
151 previous_beat.beats += 1;
153 previous_beat.ticks = 0;
155 if (session->tempo_map().meter_at(rightmost).beats_per_bar () > next_beat.beats + 1) {
156 next_beat.beats += 1;
163 delete current_bbt_points;
164 current_bbt_points = 0;
166 current_bbt_points = session->tempo_map().get_points (session->tempo_map().frame_time (previous_beat), session->tempo_map().frame_time (next_beat) + 1);
170 Editor::hide_measures ()
177 Editor::redraw_measures ()
184 Editor::draw_measures ()
186 if (session == 0 || _show_measures == false ||
187 !current_bbt_points || current_bbt_points->empty()) {
191 if (tempo_lines == 0) {
192 tempo_lines = new TempoLines(*track_canvas, time_line_group, physical_screen_height);
195 tempo_lines->draw(*current_bbt_points, frames_per_unit);
199 Editor::mouse_add_new_tempo_event (nframes64_t frame)
205 TempoMap& map(session->tempo_map());
206 TempoDialog tempo_dialog (map, frame, _("add"));
208 tempo_dialog.set_position (Gtk::WIN_POS_MOUSE);
209 //this causes compiz to display no border.
210 //tempo_dialog.signal_realize().connect (bind (sigc::ptr_fun (set_decoration), &tempo_dialog, Gdk::WMDecoration (Gdk::DECOR_BORDER|Gdk::DECOR_RESIZEH)));
212 ensure_float (tempo_dialog);
214 switch (tempo_dialog.run()) {
215 case RESPONSE_ACCEPT:
224 bpm = tempo_dialog.get_bpm ();
225 double nt = tempo_dialog.get_note_type();
226 bpm = max (0.01, bpm);
228 tempo_dialog.get_bbt_time (requested);
230 begin_reversible_command (_("add tempo mark"));
231 XMLNode &before = map.get_state();
232 map.add_tempo (Tempo (bpm,nt), requested);
233 XMLNode &after = map.get_state();
234 session->add_command(new MementoCommand<TempoMap>(map, &before, &after));
235 commit_reversible_command ();
241 Editor::mouse_add_new_meter_event (nframes64_t frame)
248 TempoMap& map(session->tempo_map());
249 MeterDialog meter_dialog (map, frame, _("add"));
251 meter_dialog.set_position (Gtk::WIN_POS_MOUSE);
253 //this causes compiz to display no border..
254 //meter_dialog.signal_realize().connect (bind (sigc::ptr_fun (set_decoration), &meter_dialog, Gdk::WMDecoration (Gdk::DECOR_BORDER|Gdk::DECOR_RESIZEH)));
256 ensure_float (meter_dialog);
258 switch (meter_dialog.run ()) {
259 case RESPONSE_ACCEPT:
265 double bpb = meter_dialog.get_bpb ();
266 bpb = max (1.0, bpb); // XXX is this a reasonable limit?
268 double note_type = meter_dialog.get_note_type ();
271 meter_dialog.get_bbt_time (requested);
273 begin_reversible_command (_("add meter mark"));
274 XMLNode &before = map.get_state();
275 map.add_meter (Meter (bpb, note_type), requested);
276 session->add_command(new MementoCommand<TempoMap>(map, &before, &map.get_state()));
277 commit_reversible_command ();
283 Editor::remove_tempo_marker (ArdourCanvas::Item* item)
286 TempoMarker* tempo_marker;
288 if ((marker = reinterpret_cast<Marker *> (item->get_data ("marker"))) == 0) {
289 fatal << _("programming error: tempo marker canvas item has no marker object pointer!") << endmsg;
293 if ((tempo_marker = dynamic_cast<TempoMarker*> (marker)) == 0) {
294 fatal << _("programming error: marker for tempo is not a tempo marker!") << endmsg;
298 if (tempo_marker->tempo().movable()) {
299 Glib::signal_idle().connect (bind (mem_fun(*this, &Editor::real_remove_tempo_marker), &tempo_marker->tempo()));
304 Editor::edit_meter_section (MeterSection* section)
306 MeterDialog meter_dialog (*section, _("done"));
308 meter_dialog.set_position (Gtk::WIN_POS_MOUSE);
310 ensure_float (meter_dialog);
312 switch (meter_dialog.run()) {
313 case RESPONSE_ACCEPT:
319 double bpb = meter_dialog.get_bpb ();
320 bpb = max (1.0, bpb); // XXX is this a reasonable limit?
322 double note_type = meter_dialog.get_note_type ();
324 begin_reversible_command (_("replace tempo mark"));
325 XMLNode &before = session->tempo_map().get_state();
326 session->tempo_map().replace_meter (*section, Meter (bpb, note_type));
327 XMLNode &after = session->tempo_map().get_state();
328 session->add_command(new MementoCommand<TempoMap>(session->tempo_map(), &before, &after));
329 commit_reversible_command ();
333 Editor::edit_tempo_section (TempoSection* section)
335 TempoDialog tempo_dialog (*section, _("done"));
337 tempo_dialog.set_position (Gtk::WIN_POS_MOUSE);
339 ensure_float (tempo_dialog);
341 switch (tempo_dialog.run ()) {
342 case RESPONSE_ACCEPT:
348 double bpm = tempo_dialog.get_bpm ();
349 double nt = tempo_dialog.get_note_type ();
351 tempo_dialog.get_bbt_time(when);
352 bpm = max (0.01, bpm);
354 cerr << "Editing tempo section to be at " << when << endl;
355 session->tempo_map().dump (cerr);
356 begin_reversible_command (_("replace tempo mark"));
357 XMLNode &before = session->tempo_map().get_state();
358 session->tempo_map().replace_tempo (*section, Tempo (bpm,nt));
359 session->tempo_map().dump (cerr);
360 session->tempo_map().move_tempo (*section, when);
361 session->tempo_map().dump (cerr);
362 XMLNode &after = session->tempo_map().get_state();
363 session->add_command (new MementoCommand<TempoMap>(session->tempo_map(), &before, &after));
364 commit_reversible_command ();
368 Editor::edit_tempo_marker (ArdourCanvas::Item *item)
371 TempoMarker* tempo_marker;
373 if ((marker = reinterpret_cast<Marker *> (item->get_data ("marker"))) == 0) {
374 fatal << _("programming error: tempo marker canvas item has no marker object pointer!") << endmsg;
378 if ((tempo_marker = dynamic_cast<TempoMarker*> (marker)) == 0) {
379 fatal << _("programming error: marker for tempo is not a tempo marker!") << endmsg;
383 edit_tempo_section (&tempo_marker->tempo());
387 Editor::edit_meter_marker (ArdourCanvas::Item *item)
390 MeterMarker* meter_marker;
392 if ((marker = reinterpret_cast<Marker *> (item->get_data ("marker"))) == 0) {
393 fatal << _("programming error: tempo marker canvas item has no marker object pointer!") << endmsg;
397 if ((meter_marker = dynamic_cast<MeterMarker*> (marker)) == 0) {
398 fatal << _("programming error: marker for meter is not a meter marker!") << endmsg;
402 edit_meter_section (&meter_marker->meter());
406 Editor::real_remove_tempo_marker (TempoSection *section)
408 begin_reversible_command (_("remove tempo mark"));
409 XMLNode &before = session->tempo_map().get_state();
410 session->tempo_map().remove_tempo (*section);
411 XMLNode &after = session->tempo_map().get_state();
412 session->add_command(new MementoCommand<TempoMap>(session->tempo_map(), &before, &after));
413 commit_reversible_command ();
419 Editor::remove_meter_marker (ArdourCanvas::Item* item)
422 MeterMarker* meter_marker;
424 if ((marker = reinterpret_cast<Marker *> (item->get_data ("marker"))) == 0) {
425 fatal << _("programming error: meter marker canvas item has no marker object pointer!") << endmsg;
429 if ((meter_marker = dynamic_cast<MeterMarker*> (marker)) == 0) {
430 fatal << _("programming error: marker for meter is not a meter marker!") << endmsg;
434 if (meter_marker->meter().movable()) {
435 Glib::signal_idle().connect (bind (mem_fun(*this, &Editor::real_remove_meter_marker), &meter_marker->meter()));
440 Editor::real_remove_meter_marker (MeterSection *section)
442 begin_reversible_command (_("remove tempo mark"));
443 XMLNode &before = session->tempo_map().get_state();
444 session->tempo_map().remove_meter (*section);
445 XMLNode &after = session->tempo_map().get_state();
446 session->add_command(new MementoCommand<TempoMap>(session->tempo_map(), &before, &after));
447 commit_reversible_command ();