fix a bunch of undo-able tempo map operations to use RCU

This commit is contained in:
Paul Davis 2020-12-31 12:05:20 -07:00
parent eab0bdfde0
commit eaedcd79d4
3 changed files with 43 additions and 20 deletions

View File

@ -3393,6 +3393,10 @@ 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 */
TempoMap::fetch_writable ();
}
void
@ -3487,6 +3491,8 @@ MeterMarkerDrag::finished (GdkEvent* event, bool movement_occurred)
if (was_double_click()) {
_editor->edit_meter_marker (*_marker);
}
/* reset thread local tempo map to the original state */
TempoMap::fetch ();
return;
}
@ -3495,11 +3501,14 @@ MeterMarkerDrag::finished (GdkEvent* event, bool movement_occurred)
_editor->set_snap_mode (_old_snap_mode);
TempoMap::SharedPtr map (TempoMap::use());
TempoMap::update (map);
XMLNode &after = map->get_state();
XMLNode &after = TempoMap::use()->get_state();
_editor->session()->add_command (new MementoCommand<Temporal::TempoMap> (new Temporal::TempoMap::MementoBinder(), before_state, &after));
_editor->commit_reversible_command ();
TempoMap::update (map);
// delete the dummy marker we used for visual representation while moving.
// a new visual marker will show up automatically.
delete _marker;
@ -3508,6 +3517,9 @@ MeterMarkerDrag::finished (GdkEvent* event, bool movement_occurred)
void
MeterMarkerDrag::aborted (bool moved)
{
/* reset thread local tempo map to the original state */
TempoMap::fetch ();
_marker->set_position (_marker->meter().time());
if (moved) {
@ -3515,11 +3527,11 @@ MeterMarkerDrag::aborted (bool moved)
_editor->set_grid_to (_old_grid_type);
_editor->set_snap_mode (_old_snap_mode);
TempoMap::use()->set_state (*before_state, Stateful::current_state_version);
// delete the dummy marker we used for visual representation while moving.
// a new visual marker will show up automatically.
delete _marker;
}
}
TempoMarkerDrag::TempoMarkerDrag (Editor* e, ArdourCanvas::Item* i, bool c)
@ -3562,7 +3574,6 @@ TempoMarkerDrag::setup_pointer_offset ()
void
TempoMarkerDrag::motion (GdkEvent* event, bool first_move)
{
if (!_marker->tempo().active()) {
return;
}
@ -3676,6 +3687,7 @@ TempoMarkerDrag::finished (GdkEvent* event, bool movement_occurred)
if (!_marker->tempo().active()) {
return;
}
if (!movement_occurred) {
if (was_double_click()) {
_editor->edit_tempo_marker (*_marker);
@ -3692,14 +3704,9 @@ TempoMarkerDrag::finished (GdkEvent* event, bool movement_occurred)
/* push the current state of our writable map copy */
TempoMap::SharedPtr map (TempoMap::use());
TempoMap::update (map);
/* fetch it back into thre thread-local and locally-scoped ptrs */
map = TempoMap::fetch();
XMLNode &after = map->get_state();
XMLNode &after = TempoMap::use()->get_state();
_editor->session()->add_command (new MementoCommand<Temporal::TempoMap> (new Temporal::TempoMap::MementoBinder(), _before_state, &after));
_editor->commit_reversible_command ();
@ -3712,15 +3719,15 @@ TempoMarkerDrag::finished (GdkEvent* event, bool movement_occurred)
void
TempoMarkerDrag::aborted (bool moved)
{
// _point->end_float ();
_marker->set_position (timepos_t (_marker->tempo().beats()));
/* reset the per-thread tempo map ptr back to the current
* official version
*/
TempoMap::fetch ();
// _point->end_float ();
_marker->set_position (timepos_t (_marker->tempo().beats()));
if (moved) {
// delete the dummy (hidden) marker we used for events while moving.
delete _marker;

View File

@ -7080,7 +7080,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::SharedPtr tmap (TempoMap::write_copy());
const Meter& m (tmap->meter_at (start));
/* length = 1 bar */
@ -7165,6 +7165,8 @@ Editor::define_one_bar (timepos_t const & start, timepos_t const & end)
_session->add_command (new MementoCommand<Temporal::TempoMap> (new Temporal::TempoMap::MementoBinder(), &before, &after));
commit_reversible_command ();
TempoMap::update (tmap);
}
void
@ -8097,12 +8099,14 @@ Editor::insert_time (
begin_reversible_command (_("insert time"));
in_command = true;
}
TempoMap::SharedPtr tmap (TempoMap::use());
TempoMap::SharedPtr tmap (TempoMap::write_copy());
XMLNode& before (tmap->get_state());
tmap->insert_time (pos, samples);
XMLNode& after (tmap->get_state());
_session->add_command (new MementoCommand<Temporal::TempoMap> (new Temporal::TempoMap::MementoBinder(), &before, &after));
TempoMap::update (tmap);
}
if (in_command) {
@ -8273,7 +8277,7 @@ Editor::remove_time (timepos_t const & pos, timecnt_t const & duration, InsertTi
}
if (tempo_too) {
TempoMap::SharedPtr tmap (TempoMap::use());
TempoMap::SharedPtr tmap (TempoMap::write_copy());
XMLNode& before (tmap->get_state());
if (tmap->remove_time (pos, duration)) {
@ -8283,6 +8287,8 @@ Editor::remove_time (timepos_t const & pos, timecnt_t const & duration, InsertTi
}
XMLNode& after (tmap->get_state());
_session->add_command (new MementoCommand<Temporal::TempoMap> (new Temporal::TempoMap::MementoBinder(), &before, &after));
TempoMap::update (tmap);
}
}

View File

@ -443,7 +443,7 @@ Editor::mouse_add_new_meter_event (timepos_t pos)
return;
}
TempoMap::SharedPtr map (TempoMap::use());
TempoMap::SharedPtr map (TempoMap::write_copy());
MeterDialog meter_dialog (map, pos, _("add"));
switch (meter_dialog.run ()) {
@ -476,6 +476,8 @@ Editor::mouse_add_new_meter_event (timepos_t pos)
_session->add_command (new MementoCommand<Temporal::TempoMap> (new Temporal::TempoMap::MementoBinder(), &before, &map->get_state()));
commit_reversible_command ();
TempoMap::update (map);
//map.dump (cerr);
}
@ -521,7 +523,7 @@ Editor::edit_meter_section (Temporal::MeterPoint& section)
Temporal::BBT_Time when;
meter_dialog.get_bbt_time (when);
TempoMap::SharedPtr tmap (TempoMap::use());
TempoMap::SharedPtr tmap (TempoMap::write_copy());
begin_reversible_command (_("replace meter mark"));
XMLNode &before = tmap->get_state();
@ -531,6 +533,8 @@ Editor::edit_meter_section (Temporal::MeterPoint& section)
XMLNode &after = tmap->get_state();
_session->add_command (new MementoCommand<Temporal::TempoMap> (new Temporal::TempoMap::MementoBinder(), &before, &after));
commit_reversible_command ();
TempoMap::update (tmap);
}
void
@ -551,7 +555,7 @@ Editor::edit_tempo_section (TempoPoint& section)
bpm = max (0.01, bpm);
const Tempo tempo (bpm, nt, end_bpm);
TempoMap::SharedPtr tmap (TempoMap::use());
TempoMap::SharedPtr tmap (TempoMap::write_copy());
Temporal::BBT_Time when;
tempo_dialog.get_bbt_time (when);
@ -564,6 +568,8 @@ Editor::edit_tempo_section (TempoPoint& section)
XMLNode &after = tmap->get_state();
_session->add_command (new MementoCommand<Temporal::TempoMap> (new Temporal::TempoMap::MementoBinder(), &before, &after));
commit_reversible_command ();
TempoMap::update (tmap);
}
void
@ -582,13 +588,15 @@ gint
Editor::real_remove_tempo_marker (TempoPoint *section)
{
begin_reversible_command (_("remove tempo mark"));
TempoMap::SharedPtr tmap (TempoMap::use());
TempoMap::SharedPtr tmap (TempoMap::write_copy());
XMLNode &before = tmap->get_state();
tmap->remove_tempo (*section);
XMLNode &after = tmap->get_state();
_session->add_command (new MementoCommand<Temporal::TempoMap> (new Temporal::TempoMap::MementoBinder(), &before, &after));
commit_reversible_command ();
TempoMap::update (tmap);
return FALSE;
}
@ -617,12 +625,14 @@ gint
Editor::real_remove_meter_marker (Temporal::MeterPoint *section)
{
begin_reversible_command (_("remove tempo mark"));
TempoMap::SharedPtr tmap (TempoMap::use());
TempoMap::SharedPtr tmap (TempoMap::write_copy());
XMLNode &before = tmap->get_state();
tmap->remove_meter (*section);
XMLNode &after = tmap->get_state();
_session->add_command (new MementoCommand<Temporal::TempoMap> (new Temporal::TempoMap::MementoBinder(), &before, &after));
commit_reversible_command ();
TempoMap::update (tmap);
return FALSE;
}