temporal: TempoMap::use() returns a const ptr to enforce semantics (GUI version)
This commit leaves two issues outstanding: 1. unclear/ugly semantics for drag operations that reset the GUI thread's tempo map to the writable copy 2. undo/redo for the tempo map These will be addressed in future commits
This commit is contained in:
parent
7c3268d12f
commit
883a44e6a4
|
@ -1740,7 +1740,6 @@ private:
|
|||
|
||||
void begin_tempo_map_edit ();
|
||||
void abort_tempo_map_edit ();
|
||||
void commit_tempo_map_edit ();
|
||||
void mid_tempo_change ();
|
||||
|
||||
private:
|
||||
|
|
|
@ -296,7 +296,7 @@ Editor::import_smf_tempo_map (Evoral::SMF const & smf, timepos_t const & pos)
|
|||
values for tempo and meter, then overwrite them.
|
||||
*/
|
||||
|
||||
TempoMap::SharedPtr new_map (new TempoMap (Tempo (120, 4), Meter (4, 4)));
|
||||
TempoMap::WritableSharedPtr new_map (new TempoMap (Tempo (120, 4), Meter (4, 4)));
|
||||
Meter last_meter (4.0, 4.0);
|
||||
bool have_initial_meter = false;
|
||||
|
||||
|
|
|
@ -3416,9 +3416,11 @@ MeterMarkerDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
|
|||
Drag::start_grab (event, cursor);
|
||||
show_verbose_cursor_time (adjusted_current_time (event));
|
||||
|
||||
/* setup thread-local tempo map ptr as a writable copy */
|
||||
/* setup thread-local tempo map ptr as a writable copy, and keep a
|
||||
* local reference
|
||||
*/
|
||||
|
||||
TempoMap::fetch_writable ();
|
||||
map = TempoMap::fetch_writable ();
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -3430,8 +3432,6 @@ MeterMarkerDrag::setup_pointer_offset ()
|
|||
void
|
||||
MeterMarkerDrag::motion (GdkEvent* event, bool first_move)
|
||||
{
|
||||
TempoMap::SharedPtr map (TempoMap::use());
|
||||
|
||||
if (first_move) {
|
||||
// create a dummy marker to catch events, then hide it.
|
||||
|
||||
|
@ -3524,9 +3524,7 @@ MeterMarkerDrag::finished (GdkEvent* event, bool movement_occurred)
|
|||
_editor->set_grid_to (_old_grid_type);
|
||||
_editor->set_snap_mode (_old_snap_mode);
|
||||
|
||||
TempoMap::SharedPtr map (TempoMap::use());
|
||||
|
||||
XMLNode &after = TempoMap::use()->get_state();
|
||||
XMLNode &after = map->get_state();
|
||||
_editor->session()->add_command (new MementoCommand<Temporal::TempoMap> (new Temporal::TempoMap::MementoBinder(), before_state, &after));
|
||||
_editor->commit_reversible_command ();
|
||||
|
||||
|
@ -3567,7 +3565,7 @@ TempoMarkerDrag::TempoMarkerDrag (Editor* e, ArdourCanvas::Item* i, bool c)
|
|||
|
||||
_marker = reinterpret_cast<TempoMarker*> (_item->get_data ("marker"));
|
||||
_real_section = &_marker->tempo();
|
||||
_movable = !TempoMap::use()->is_initial (_marker->tempo());
|
||||
_movable = !map->is_initial (_marker->tempo());
|
||||
_grab_bpm = Tempo (_real_section->note_types_per_minute(), _real_section->note_type(), _real_section->end_note_types_per_minute());
|
||||
_grab_qn = _real_section->beats();
|
||||
assert (_marker);
|
||||
|
@ -3601,8 +3599,6 @@ TempoMarkerDrag::motion (GdkEvent* event, bool first_move)
|
|||
return;
|
||||
}
|
||||
|
||||
TempoMap::SharedPtr map (TempoMap::use());
|
||||
|
||||
if (first_move) {
|
||||
/* get current state */
|
||||
_before_state = &map->get_state();
|
||||
|
@ -3656,8 +3652,8 @@ TempoMarkerDrag::finished (GdkEvent* event, bool movement_occurred)
|
|||
|
||||
/* push the current state of our writable map copy */
|
||||
|
||||
_editor->commit_tempo_map_edit ();
|
||||
XMLNode &after = TempoMap::use()->get_state();
|
||||
TempoMap::update (map);
|
||||
XMLNode &after = map->get_state();
|
||||
|
||||
_editor->session()->add_command (new MementoCommand<Temporal::TempoMap> (new Temporal::TempoMap::MementoBinder(), _before_state, &after));
|
||||
_editor->commit_reversible_command ();
|
||||
|
@ -3694,11 +3690,10 @@ BBTRulerDrag::BBTRulerDrag (Editor* e, ArdourCanvas::Item* i)
|
|||
void
|
||||
BBTRulerDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
|
||||
{
|
||||
TempoMap::fetch_writable ();
|
||||
map = TempoMap::fetch_writable ();
|
||||
|
||||
Drag::start_grab (event, cursor);
|
||||
|
||||
TempoMap::SharedPtr map (TempoMap::use());
|
||||
_tempo = const_cast<TempoPoint*> (&map->metric_at (raw_grab_time().beats()).tempo());
|
||||
|
||||
if (adjusted_current_time (event, false) <= _tempo->time()) {
|
||||
|
@ -3723,7 +3718,6 @@ BBTRulerDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
|
|||
void
|
||||
BBTRulerDrag::setup_pointer_offset ()
|
||||
{
|
||||
TempoMap::SharedPtr map (TempoMap::use());
|
||||
/* get current state */
|
||||
_before_state = &map->get_state();
|
||||
|
||||
|
@ -3750,7 +3744,6 @@ BBTRulerDrag::motion (GdkEvent* event, bool first_move)
|
|||
_editor->begin_reversible_command (_("stretch tempo"));
|
||||
}
|
||||
|
||||
TempoMap::SharedPtr map (TempoMap::use());
|
||||
timepos_t pf;
|
||||
|
||||
if (_editor->grid_musical()) {
|
||||
|
@ -3785,8 +3778,6 @@ BBTRulerDrag::finished (GdkEvent* event, bool movement_occurred)
|
|||
return;
|
||||
}
|
||||
|
||||
TempoMap::SharedPtr map (TempoMap::use());
|
||||
|
||||
if (!movement_occurred) {
|
||||
|
||||
_editor->begin_reversible_command (_("add BBT marker"));
|
||||
|
@ -3832,7 +3823,7 @@ BBTRulerDrag::finished (GdkEvent* event, bool movement_occurred)
|
|||
|
||||
TempoMap::update (map);
|
||||
|
||||
XMLNode &after = TempoMap::use()->get_state();
|
||||
XMLNode &after = map->get_state();
|
||||
|
||||
_editor->session()->add_command(new MementoCommand<TempoMap>(new Temporal::TempoMap::MementoBinder(), _before_state, &after));
|
||||
_editor->commit_reversible_command ();
|
||||
|
@ -3996,12 +3987,10 @@ TempoEndDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
|
|||
{
|
||||
Drag::start_grab (event, cursor);
|
||||
|
||||
TempoMap::fetch_writable();
|
||||
|
||||
TempoMap::SharedPtr tmap (TempoMap::use());
|
||||
map = TempoMap::fetch_writable();
|
||||
|
||||
/* get current state */
|
||||
_before_state = &tmap->get_state();
|
||||
_before_state = &map->get_state();
|
||||
if (_tempo->locked_to_meter()) {
|
||||
_drag_valid = false;
|
||||
return;
|
||||
|
@ -4010,10 +3999,10 @@ TempoEndDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
|
|||
ostringstream sstr;
|
||||
|
||||
TempoPoint const * prev = 0;
|
||||
if ((prev = tmap->previous_tempo (*_tempo)) != 0) {
|
||||
if ((prev = map->previous_tempo (*_tempo)) != 0) {
|
||||
_editor->tempo_curve_selected (prev, true);
|
||||
const samplecnt_t sr = AudioEngine::instance()->sample_rate();
|
||||
sstr << "end: " << fixed << setprecision(3) << tmap->tempo_at (samples_to_superclock (_tempo->sample (sr) - 1, sr)).end_note_types_per_minute() << "\n";
|
||||
sstr << "end: " << fixed << setprecision(3) << map->tempo_at (samples_to_superclock (_tempo->sample (sr) - 1, sr)).end_note_types_per_minute() << "\n";
|
||||
}
|
||||
|
||||
if (_tempo->clamped()) {
|
||||
|
@ -4066,19 +4055,15 @@ TempoEndDrag::finished (GdkEvent* event, bool movement_occurred)
|
|||
return;
|
||||
}
|
||||
|
||||
TempoMap::SharedPtr tmap (TempoMap::use());
|
||||
TempoMap::update (map);
|
||||
|
||||
TempoMap::update (tmap);
|
||||
|
||||
tmap = TempoMap::use ();
|
||||
|
||||
XMLNode &after = tmap->get_state();
|
||||
XMLNode &after = map->get_state();
|
||||
_editor->session()->add_command(new MementoCommand<TempoMap>(new Temporal::TempoMap::MementoBinder(), _before_state, &after));
|
||||
_editor->commit_reversible_command ();
|
||||
|
||||
TempoPoint const * prev = 0;
|
||||
|
||||
if ((prev = tmap->previous_tempo (*_tempo)) != 0) {
|
||||
if ((prev = map->previous_tempo (*_tempo)) != 0) {
|
||||
_editor->tempo_curve_selected (prev, false);
|
||||
}
|
||||
|
||||
|
|
|
@ -847,6 +847,7 @@ public:
|
|||
|
||||
private:
|
||||
MeterMarker* _marker;
|
||||
Temporal::TempoMap::WritableSharedPtr map;
|
||||
|
||||
bool _copy;
|
||||
bool _movable;
|
||||
|
@ -879,6 +880,7 @@ public:
|
|||
private:
|
||||
TempoMarker* _marker;
|
||||
Temporal::TempoPoint const * _real_section;
|
||||
Temporal::TempoMap::WritableSharedPtr map;
|
||||
|
||||
bool _copy;
|
||||
bool _movable;
|
||||
|
@ -911,6 +913,8 @@ public:
|
|||
private:
|
||||
Temporal::Beats _grab_qn;
|
||||
Temporal::TempoPoint* _tempo;
|
||||
Temporal::TempoMap::WritableSharedPtr map;
|
||||
|
||||
XMLNode* _before_state;
|
||||
bool _drag_valid;
|
||||
};
|
||||
|
@ -972,6 +976,8 @@ public:
|
|||
private:
|
||||
Temporal::Beats _grab_qn;
|
||||
Temporal::TempoPoint const * _tempo;
|
||||
Temporal::TempoMap::WritableSharedPtr map;
|
||||
|
||||
XMLNode* _before_state;
|
||||
bool _drag_valid;
|
||||
};
|
||||
|
|
|
@ -1610,7 +1610,7 @@ Editor::toggle_tempo_type ()
|
|||
if (tm) {
|
||||
|
||||
begin_reversible_command (_("set tempo to constant"));
|
||||
TempoMap::SharedPtr tmap (TempoMap::write_copy());
|
||||
TempoMap::WritableSharedPtr tmap (TempoMap::write_copy());
|
||||
|
||||
reassociate_metric_markers (tmap);
|
||||
Temporal::TempoPoint const & tempo = tm->tempo();
|
||||
|
@ -1637,7 +1637,7 @@ Editor::toggle_tempo_clamped ()
|
|||
if (tm) {
|
||||
begin_reversible_command (_("Clamp Tempo"));
|
||||
|
||||
TempoMap::SharedPtr tmap (TempoMap::write_copy());
|
||||
TempoMap::WritableSharedPtr tmap (TempoMap::write_copy());
|
||||
XMLNode &before = tmap->get_state();
|
||||
|
||||
reassociate_metric_markers (tmap);
|
||||
|
@ -1664,7 +1664,7 @@ Editor::ramp_to_next_tempo ()
|
|||
if (tm) {
|
||||
|
||||
begin_reversible_command (_("ramp to next tempo"));
|
||||
TempoMap::SharedPtr tmap (TempoMap::write_copy());
|
||||
TempoMap::WritableSharedPtr tmap (TempoMap::write_copy());
|
||||
XMLNode &before = tmap->get_state();
|
||||
|
||||
reassociate_metric_markers (tmap);
|
||||
|
|
|
@ -7288,7 +7288,7 @@ Editor::define_one_bar (timepos_t const & start, timepos_t const & end)
|
|||
{
|
||||
timecnt_t length = start.distance (end);
|
||||
|
||||
TempoMap::SharedPtr tmap (TempoMap::use());
|
||||
TempoMap::WritableSharedPtr tmap (TempoMap::write_copy());
|
||||
const Meter& m (tmap->meter_at (start));
|
||||
|
||||
/* length = 1 bar */
|
||||
|
@ -8311,7 +8311,7 @@ Editor::insert_time (
|
|||
begin_reversible_command (_("insert time"));
|
||||
in_command = true;
|
||||
}
|
||||
TempoMap::SharedPtr tmap (TempoMap::write_copy());
|
||||
TempoMap::WritableSharedPtr tmap (TempoMap::write_copy());
|
||||
|
||||
XMLNode& before (tmap->get_state());
|
||||
tmap->insert_time (pos, samples);
|
||||
|
@ -8489,7 +8489,7 @@ Editor::remove_time (timepos_t const & pos, timecnt_t const & duration, InsertTi
|
|||
}
|
||||
|
||||
if (tempo_too) {
|
||||
TempoMap::SharedPtr tmap (TempoMap::write_copy());
|
||||
TempoMap::WritableSharedPtr tmap (TempoMap::write_copy());
|
||||
XMLNode& before (tmap->get_state());
|
||||
|
||||
if (tmap->remove_time (pos, duration)) {
|
||||
|
|
|
@ -112,19 +112,19 @@ Editor::reassociate_metric_marker (TempoMap::SharedPtr const & tmap, TempoMap::M
|
|||
MeterMarker* mm;
|
||||
BBTMarker* bm;
|
||||
|
||||
Temporal::TempoPoint* tp;
|
||||
Temporal::MeterPoint* mp;
|
||||
Temporal::MusicTimePoint* mtp;
|
||||
Temporal::TempoPoint const * tp;
|
||||
Temporal::MeterPoint const * mp;
|
||||
Temporal::MusicTimePoint const * mtp;
|
||||
|
||||
if ((tm = dynamic_cast<TempoMarker*> (&marker)) != 0) {
|
||||
|
||||
for (TempoMap::Metrics::iterator m = metrics.begin(); m != metrics.end(); ++m) {
|
||||
if ((mtp = dynamic_cast<Temporal::MusicTimePoint*>(*m)) != 0) {
|
||||
if ((mtp = dynamic_cast<Temporal::MusicTimePoint const *>(*m)) != 0) {
|
||||
/* do nothing .. but we had to catch
|
||||
this first because MusicTimePoint
|
||||
IS-A TempoPoint
|
||||
*/
|
||||
} else if ((tp = dynamic_cast<Temporal::TempoPoint*>(*m)) != 0) {
|
||||
} else if ((tp = dynamic_cast<Temporal::TempoPoint const *>(*m)) != 0) {
|
||||
if (tm->tempo() == *tp) {
|
||||
tm->reset_tempo (*tp);
|
||||
tm->curve().reset_point (*tp);
|
||||
|
@ -134,13 +134,13 @@ Editor::reassociate_metric_marker (TempoMap::SharedPtr const & tmap, TempoMap::M
|
|||
}
|
||||
} else if ((mm = dynamic_cast<MeterMarker*> (&marker)) != 0) {
|
||||
for (TempoMap::Metrics::iterator m = metrics.begin(); m != metrics.end(); ++m) {
|
||||
if ((mtp = dynamic_cast<Temporal::MusicTimePoint*>(*m)) != 0) {
|
||||
if ((mtp = dynamic_cast<Temporal::MusicTimePoint const *>(*m)) != 0) {
|
||||
/* do nothing .. but we had to catch
|
||||
this first because MusicTimePoint
|
||||
IS-A TempoPoint
|
||||
*/
|
||||
|
||||
} else if ((mp = dynamic_cast<Temporal::MeterPoint*>(*m)) != 0) {
|
||||
} else if ((mp = dynamic_cast<Temporal::MeterPoint const *>(*m)) != 0) {
|
||||
if (mm->meter() == *mp) {
|
||||
mm->reset_meter (*mp);
|
||||
break;
|
||||
|
@ -151,7 +151,7 @@ Editor::reassociate_metric_marker (TempoMap::SharedPtr const & tmap, TempoMap::M
|
|||
} else if ((bm = dynamic_cast<BBTMarker*> (&marker)) != 0) {
|
||||
|
||||
for (TempoMap::Metrics::iterator m = metrics.begin(); m != metrics.end(); ++m) {
|
||||
if ((mtp = dynamic_cast<Temporal::MusicTimePoint*>(*m)) != 0) {
|
||||
if ((mtp = dynamic_cast<Temporal::MusicTimePoint const *>(*m)) != 0) {
|
||||
if (bm->point() == *mtp) {
|
||||
bm->reset_point (*mtp);
|
||||
break;
|
||||
|
@ -594,7 +594,7 @@ Editor::mouse_add_new_tempo_event (timepos_t pos)
|
|||
|
||||
begin_reversible_command (_("add tempo mark"));
|
||||
|
||||
TempoMap::SharedPtr map (TempoMap::write_copy());
|
||||
TempoMap::WritableSharedPtr map (TempoMap::write_copy());
|
||||
|
||||
XMLNode &before = map->get_state();
|
||||
|
||||
|
@ -627,7 +627,7 @@ Editor::mouse_add_new_meter_event (timepos_t pos)
|
|||
return;
|
||||
}
|
||||
|
||||
TempoMap::SharedPtr map (TempoMap::write_copy());
|
||||
TempoMap::WritableSharedPtr map (TempoMap::write_copy());
|
||||
|
||||
double bpb = meter_dialog.get_bpb ();
|
||||
bpb = max (1.0, bpb); // XXX is this a reasonable limit?
|
||||
|
@ -699,7 +699,7 @@ Editor::edit_meter_section (Temporal::MeterPoint& section)
|
|||
Temporal::BBT_Time when;
|
||||
meter_dialog.get_bbt_time (when);
|
||||
|
||||
TempoMap::SharedPtr tmap (TempoMap::write_copy());
|
||||
TempoMap::WritableSharedPtr tmap (TempoMap::write_copy());
|
||||
|
||||
reassociate_metric_markers (tmap);
|
||||
|
||||
|
@ -734,7 +734,7 @@ Editor::edit_tempo_section (TempoPoint& section)
|
|||
|
||||
const Tempo tempo (bpm, end_bpm, nt);
|
||||
|
||||
TempoMap::SharedPtr tmap (TempoMap::write_copy());
|
||||
TempoMap::WritableSharedPtr tmap (TempoMap::write_copy());
|
||||
reassociate_metric_markers (tmap);
|
||||
|
||||
Temporal::BBT_Time when;
|
||||
|
@ -768,7 +768,7 @@ gint
|
|||
Editor::real_remove_tempo_marker (TempoPoint const * section)
|
||||
{
|
||||
begin_reversible_command (_("remove tempo mark"));
|
||||
TempoMap::SharedPtr tmap (TempoMap::write_copy());
|
||||
TempoMap::WritableSharedPtr tmap (TempoMap::write_copy());
|
||||
XMLNode &before = tmap->get_state();
|
||||
tmap->remove_tempo (*section);
|
||||
XMLNode &after = tmap->get_state();
|
||||
|
@ -805,7 +805,7 @@ gint
|
|||
Editor::real_remove_meter_marker (Temporal::MeterPoint const * section)
|
||||
{
|
||||
begin_reversible_command (_("remove tempo mark"));
|
||||
TempoMap::SharedPtr tmap (TempoMap::write_copy());
|
||||
TempoMap::WritableSharedPtr tmap (TempoMap::write_copy());
|
||||
XMLNode &before = tmap->get_state();
|
||||
tmap->remove_meter (*section);
|
||||
XMLNode &after = tmap->get_state();
|
||||
|
@ -835,13 +835,6 @@ Editor::abort_tempo_map_edit ()
|
|||
reassociate_metric_markers (tmap);
|
||||
}
|
||||
|
||||
void
|
||||
Editor::commit_tempo_map_edit ()
|
||||
{
|
||||
TempoMap::SharedPtr tmap (TempoMap::use());
|
||||
TempoMap::update (tmap);
|
||||
}
|
||||
|
||||
void
|
||||
Editor::mid_tempo_change ()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user