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.
21
#include "gtk2ardour-config.h"
24
#include <cstdio> // for sprintf, grrr
30
#include <libgnomecanvasmm.h>
32
#include "pbd/error.h"
33
#include "pbd/memento_command.h"
35
#include <gtkmm2ext/utils.h>
36
#include <gtkmm2ext/gtk_ui.h>
38
#include "ardour/session.h"
39
#include "ardour/tempo.h"
40
#include <gtkmm2ext/doi.h>
41
#include <gtkmm2ext/utils.h>
45
#include "simpleline.h"
46
#include "tempo_dialog.h"
47
#include "rgb_macros.h"
48
#include "gui_thread.h"
49
#include "time_axis_view.h"
50
#include "ardour_ui.h"
51
#include "tempo_lines.h"
57
using namespace ARDOUR;
60
using namespace Gtkmm2ext;
61
using namespace Editing;
64
Editor::remove_metric_marks ()
66
/* don't delete these while handling events, just punt till the GUI is idle */
68
for (Marks::iterator x = metric_marks.begin(); x != metric_marks.end(); ++x) {
69
delete_when_idle (*x);
71
metric_marks.clear ();
75
Editor::draw_metric_marks (const Metrics& metrics)
78
const MeterSection *ms;
79
const TempoSection *ts;
82
remove_metric_marks ();
84
for (Metrics::const_iterator i = metrics.begin(); i != metrics.end(); ++i) {
86
if ((ms = dynamic_cast<const MeterSection*>(*i)) != 0) {
87
snprintf (buf, sizeof(buf), "%g/%g", ms->divisions_per_bar(), ms->note_divisor ());
88
metric_marks.push_back (new MeterMarker (*this, *meter_group, ARDOUR_UI::config()->canvasvar_MeterMarker.get(), buf,
89
*(const_cast<MeterSection*>(ms))));
90
} else if ((ts = dynamic_cast<const TempoSection*>(*i)) != 0) {
91
if (Config->get_allow_non_quarter_pulse()) {
92
snprintf (buf, sizeof (buf), "%.2f/%.0f", ts->beats_per_minute(), ts->note_type());
94
snprintf (buf, sizeof (buf), "%.2f", ts->beats_per_minute());
96
metric_marks.push_back (new TempoMarker (*this, *tempo_group, ARDOUR_UI::config()->canvasvar_TempoMarker.get(), buf,
97
*(const_cast<TempoSection*>(ts))));
105
Editor::tempo_map_changed (const PropertyChange& /*ignored*/)
111
ENSURE_GUI_THREAD (*this, &Editor::tempo_map_changed, ignored);
114
tempo_lines->tempo_map_changed();
117
ARDOUR::TempoMap::BBTPointList::const_iterator begin;
118
ARDOUR::TempoMap::BBTPointList::const_iterator end;
120
compute_current_bbt_points (leftmost_frame, leftmost_frame + current_page_frames(), begin, end);
121
_session->tempo_map().apply_with_metrics (*this, &Editor::draw_metric_marks); // redraw metric markers
123
update_tempo_based_rulers (begin, end);
127
Editor::redisplay_tempo (bool immediate_redraw)
133
ARDOUR::TempoMap::BBTPointList::const_iterator current_bbt_points_begin;
134
ARDOUR::TempoMap::BBTPointList::const_iterator current_bbt_points_end;
136
compute_current_bbt_points (leftmost_frame, leftmost_frame + current_page_frames(),
137
current_bbt_points_begin, current_bbt_points_end);
139
if (immediate_redraw) {
145
Glib::signal_idle().connect (sigc::mem_fun (*this, &Editor::redraw_measures));
148
update_tempo_based_rulers (current_bbt_points_begin, current_bbt_points_end); // redraw rulers and measures
152
Editor::compute_current_bbt_points (framepos_t leftmost, framepos_t rightmost,
153
ARDOUR::TempoMap::BBTPointList::const_iterator& begin,
154
ARDOUR::TempoMap::BBTPointList::const_iterator& end)
160
/* prevent negative values of leftmost from creeping into tempomap
163
_session->tempo_map().get_grid (begin, end, max (leftmost, (framepos_t) 0), rightmost);
167
Editor::hide_measures ()
174
Editor::redraw_measures ()
176
ARDOUR::TempoMap::BBTPointList::const_iterator begin;
177
ARDOUR::TempoMap::BBTPointList::const_iterator end;
179
compute_current_bbt_points (leftmost_frame, leftmost_frame + current_page_frames(), begin, end);
180
draw_measures (begin, end);
186
Editor::draw_measures (ARDOUR::TempoMap::BBTPointList::const_iterator& begin,
187
ARDOUR::TempoMap::BBTPointList::const_iterator& end)
189
if (_session == 0 || _show_measures == false || distance (begin, end) == 0) {
193
if (tempo_lines == 0) {
194
tempo_lines = new TempoLines(*track_canvas, time_line_group, physical_screen_height(get_window()));
197
tempo_lines->draw (begin, end, frames_per_unit);
201
Editor::mouse_add_new_tempo_event (framepos_t frame)
207
TempoMap& map(_session->tempo_map());
208
TempoDialog tempo_dialog (map, frame, _("add"));
210
//this causes compiz to display no border.
211
//tempo_dialog.signal_realize().connect (sigc::bind (sigc::ptr_fun (set_decoration), &tempo_dialog, Gdk::WMDecoration (Gdk::DECOR_BORDER|Gdk::DECOR_RESIZEH)));
213
ensure_float (tempo_dialog);
215
switch (tempo_dialog.run()) {
216
case RESPONSE_ACCEPT:
223
Timecode::BBT_Time requested;
225
bpm = tempo_dialog.get_bpm ();
226
double nt = tempo_dialog.get_note_type();
227
bpm = max (0.01, bpm);
229
tempo_dialog.get_bbt_time (requested);
231
begin_reversible_command (_("add tempo mark"));
232
XMLNode &before = map.get_state();
233
map.add_tempo (Tempo (bpm,nt), requested);
234
XMLNode &after = map.get_state();
235
_session->add_command(new MementoCommand<TempoMap>(map, &before, &after));
236
commit_reversible_command ();
242
Editor::mouse_add_new_meter_event (framepos_t frame)
249
TempoMap& map(_session->tempo_map());
250
MeterDialog meter_dialog (map, frame, _("add"));
252
//this causes compiz to display no border..
253
//meter_dialog.signal_realize().connect (sigc::bind (sigc::ptr_fun (set_decoration), &meter_dialog, Gdk::WMDecoration (Gdk::DECOR_BORDER|Gdk::DECOR_RESIZEH)));
255
ensure_float (meter_dialog);
257
switch (meter_dialog.run ()) {
258
case RESPONSE_ACCEPT:
264
double bpb = meter_dialog.get_bpb ();
265
bpb = max (1.0, bpb); // XXX is this a reasonable limit?
267
double note_type = meter_dialog.get_note_type ();
268
Timecode::BBT_Time requested;
270
meter_dialog.get_bbt_time (requested);
272
begin_reversible_command (_("add meter mark"));
273
XMLNode &before = map.get_state();
274
map.add_meter (Meter (bpb, note_type), requested);
275
_session->add_command(new MementoCommand<TempoMap>(map, &before, &map.get_state()));
276
commit_reversible_command ();
282
Editor::remove_tempo_marker (ArdourCanvas::Item* item)
285
TempoMarker* tempo_marker;
287
if ((marker = reinterpret_cast<Marker *> (item->get_data ("marker"))) == 0) {
288
fatal << _("programming error: tempo marker canvas item has no marker object pointer!") << endmsg;
292
if ((tempo_marker = dynamic_cast<TempoMarker*> (marker)) == 0) {
293
fatal << _("programming error: marker for tempo is not a tempo marker!") << endmsg;
297
if (tempo_marker->tempo().movable()) {
298
Glib::signal_idle().connect (sigc::bind (sigc::mem_fun(*this, &Editor::real_remove_tempo_marker), &tempo_marker->tempo()));
303
Editor::edit_meter_section (MeterSection* section)
305
MeterDialog meter_dialog (*section, _("done"));
307
ensure_float (meter_dialog);
309
switch (meter_dialog.run()) {
310
case RESPONSE_ACCEPT:
316
double bpb = meter_dialog.get_bpb ();
317
bpb = max (1.0, bpb); // XXX is this a reasonable limit?
319
double note_type = meter_dialog.get_note_type ();
321
Timecode::BBT_Time when;
322
meter_dialog.get_bbt_time(when);
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), when);
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
ensure_float (tempo_dialog);
339
switch (tempo_dialog.run ()) {
340
case RESPONSE_ACCEPT:
346
double bpm = tempo_dialog.get_bpm ();
347
double nt = tempo_dialog.get_note_type ();
348
Timecode::BBT_Time when;
349
tempo_dialog.get_bbt_time(when);
350
bpm = max (0.01, bpm);
352
begin_reversible_command (_("replace tempo mark"));
353
XMLNode &before = _session->tempo_map().get_state();
354
_session->tempo_map().replace_tempo (*section, Tempo (bpm, nt), when);
355
XMLNode &after = _session->tempo_map().get_state();
356
_session->add_command (new MementoCommand<TempoMap>(_session->tempo_map(), &before, &after));
357
commit_reversible_command ();
361
Editor::edit_tempo_marker (ArdourCanvas::Item *item)
364
TempoMarker* tempo_marker;
366
if ((marker = reinterpret_cast<Marker *> (item->get_data ("marker"))) == 0) {
367
fatal << _("programming error: tempo marker canvas item has no marker object pointer!") << endmsg;
371
if ((tempo_marker = dynamic_cast<TempoMarker*> (marker)) == 0) {
372
fatal << _("programming error: marker for tempo is not a tempo marker!") << endmsg;
376
edit_tempo_section (&tempo_marker->tempo());
380
Editor::edit_meter_marker (ArdourCanvas::Item *item)
383
MeterMarker* meter_marker;
385
if ((marker = reinterpret_cast<Marker *> (item->get_data ("marker"))) == 0) {
386
fatal << _("programming error: tempo marker canvas item has no marker object pointer!") << endmsg;
390
if ((meter_marker = dynamic_cast<MeterMarker*> (marker)) == 0) {
391
fatal << _("programming error: marker for meter is not a meter marker!") << endmsg;
395
edit_meter_section (&meter_marker->meter());
399
Editor::real_remove_tempo_marker (TempoSection *section)
401
begin_reversible_command (_("remove tempo mark"));
402
XMLNode &before = _session->tempo_map().get_state();
403
_session->tempo_map().remove_tempo (*section, true);
404
XMLNode &after = _session->tempo_map().get_state();
405
_session->add_command(new MementoCommand<TempoMap>(_session->tempo_map(), &before, &after));
406
commit_reversible_command ();
412
Editor::remove_meter_marker (ArdourCanvas::Item* item)
415
MeterMarker* meter_marker;
417
if ((marker = reinterpret_cast<Marker *> (item->get_data ("marker"))) == 0) {
418
fatal << _("programming error: meter marker canvas item has no marker object pointer!") << endmsg;
422
if ((meter_marker = dynamic_cast<MeterMarker*> (marker)) == 0) {
423
fatal << _("programming error: marker for meter is not a meter marker!") << endmsg;
427
if (meter_marker->meter().movable()) {
428
Glib::signal_idle().connect (sigc::bind (sigc::mem_fun(*this, &Editor::real_remove_meter_marker), &meter_marker->meter()));
433
Editor::real_remove_meter_marker (MeterSection *section)
435
begin_reversible_command (_("remove tempo mark"));
436
XMLNode &before = _session->tempo_map().get_state();
437
_session->tempo_map().remove_meter (*section, true);
438
XMLNode &after = _session->tempo_map().get_state();
439
_session->add_command(new MementoCommand<TempoMap>(_session->tempo_map(), &before, &after));
440
commit_reversible_command ();