From 44790ebff017173ff6a593c1278bbe6cbab3fa4b Mon Sep 17 00:00:00 2001 From: nick_m Date: Wed, 17 Jun 2015 09:26:40 +1000 Subject: [PATCH] More _reversible_command() auditing in the gui. - try to keep begin/commit pairs in the same file where possible. --- gtk2_ardour/automation_line.cc | 3 --- gtk2_ardour/editor_drag.cc | 43 ++++++++++++++++++++++++---------- gtk2_ardour/midi_time_axis.cc | 5 ++-- gtk2_ardour/region_editor.cc | 33 +++++++++++++++++--------- 4 files changed, 55 insertions(+), 29 deletions(-) diff --git a/gtk2_ardour/automation_line.cc b/gtk2_ardour/automation_line.cc index 069a823155..a354afeeb6 100644 --- a/gtk2_ardour/automation_line.cc +++ b/gtk2_ardour/automation_line.cc @@ -466,7 +466,6 @@ AutomationLine::string_to_fraction (string const & s) const void AutomationLine::start_drag_single (ControlPoint* cp, double x, float fraction) { - trackview.editor().begin_reversible_command (_("automation event move")); trackview.editor().session()->add_command ( new MementoCommand (memento_command_binder(), &get_state(), 0)); @@ -492,7 +491,6 @@ AutomationLine::start_drag_single (ControlPoint* cp, double x, float fraction) void AutomationLine::start_drag_line (uint32_t i1, uint32_t i2, float fraction) { - trackview.editor().begin_reversible_command (_("automation range move")); trackview.editor().session()->add_command ( new MementoCommand (memento_command_binder (), &get_state(), 0)); @@ -512,7 +510,6 @@ AutomationLine::start_drag_line (uint32_t i1, uint32_t i2, float fraction) void AutomationLine::start_drag_multiple (list cp, float fraction, XMLNode* state) { - trackview.editor().begin_reversible_command (_("automation range move")); trackview.editor().session()->add_command ( new MementoCommand (memento_command_binder(), state, 0)); diff --git a/gtk2_ardour/editor_drag.cc b/gtk2_ardour/editor_drag.cc index d3ed92a97c..ab08f7f10b 100644 --- a/gtk2_ardour/editor_drag.cc +++ b/gtk2_ardour/editor_drag.cc @@ -3479,7 +3479,7 @@ FadeInDrag::finished (GdkEvent* event, bool movement_occurred) fade_length = pos - region->position(); } - _editor->begin_reversible_command (_("change fade in length")); + bool in_command = false; for (list::iterator i = _views.begin(); i != _views.end(); ++i) { @@ -3495,11 +3495,17 @@ FadeInDrag::finished (GdkEvent* event, bool movement_occurred) tmp->audio_region()->set_fade_in_length (fade_length); tmp->audio_region()->set_fade_in_active (true); + if (!in_command) { + _editor->begin_reversible_command (_("change fade in length")); + in_command = true; + } XMLNode &after = alist->get_state(); _editor->session()->add_command(new MementoCommand(*alist.get(), &before, &after)); } - _editor->commit_reversible_command (); + if (in_command) { + _editor->commit_reversible_command (); + } } void @@ -3598,7 +3604,7 @@ FadeOutDrag::finished (GdkEvent* event, bool movement_occurred) fade_length = region->last_frame() - pos; } - _editor->begin_reversible_command (_("change fade out length")); + bool in_command = false; for (list::iterator i = _views.begin(); i != _views.end(); ++i) { @@ -3614,11 +3620,17 @@ FadeOutDrag::finished (GdkEvent* event, bool movement_occurred) tmp->audio_region()->set_fade_out_length (fade_length); tmp->audio_region()->set_fade_out_active (true); + if (!in_command) { + _editor->begin_reversible_command (_("change fade out length")); + in_command = false; + } XMLNode &after = alist->get_state(); _editor->session()->add_command(new MementoCommand(*alist.get(), &before, &after)); } - _editor->commit_reversible_command (); + if (in_command) { + _editor->commit_reversible_command (); + } } void @@ -3952,8 +3964,8 @@ MarkerDrag::finished (GdkEvent* event, bool movement_occurred) _editor->_dragging_edit_point = false; - _editor->begin_reversible_command ( _("move marker") ); XMLNode &before = _editor->session()->locations()->get_state(); + bool in_command = false; MarkerSelection::iterator i; CopiedLocationInfo::iterator x; @@ -3968,9 +3980,12 @@ MarkerDrag::finished (GdkEvent* event, bool movement_occurred) if (location) { if (location->locked()) { - return; + continue; + } + if (!in_command) { + _editor->begin_reversible_command ( _("move marker") ); + in_command = true; } - if (location->is_mark()) { location->set_start (((*x).location)->start()); } else { @@ -3979,9 +3994,11 @@ MarkerDrag::finished (GdkEvent* event, bool movement_occurred) } } - XMLNode &after = _editor->session()->locations()->get_state(); - _editor->session()->add_command(new MementoCommand(*(_editor->session()->locations()), &before, &after)); - _editor->commit_reversible_command (); + if (in_command) { + XMLNode &after = _editor->session()->locations()->get_state(); + _editor->session()->add_command(new MementoCommand(*(_editor->session()->locations()), &before, &after)); + _editor->commit_reversible_command (); + } } void @@ -4044,7 +4061,7 @@ ControlPointDrag::start_grab (GdkEvent* event, Gdk::Cursor* /*cursor*/) setup_snap_delta (pos); float const fraction = 1 - (_point->get_y() / _point->line().height()); - + _editor->begin_reversible_command (_("automation event move")); _point->line().start_drag_single (_point, _fixed_grab_x, fraction); show_verbose_cursor_text (_point->line().get_verbose_cursor_string (fraction)); @@ -4190,7 +4207,7 @@ LineDrag::start_grab (GdkEvent* event, Gdk::Cursor* /*cursor*/) _fixed_grab_y = cy; double fraction = 1.0 - (cy / _line->height()); - + _editor->begin_reversible_command (_("automation range move")); _line->start_drag_line (before, after, fraction); show_verbose_cursor_text (_line->get_verbose_cursor_string (fraction)); @@ -5583,7 +5600,7 @@ AutomationRangeDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor) if (_nothing_to_drag) { return; } - + _editor->begin_reversible_command (_("automation range move")); for (list::iterator i = _lines.begin(); i != _lines.end(); ++i) { i->line->start_drag_multiple (i->points, y_fraction (i->line, current_pointer_y()), i->state); } diff --git a/gtk2_ardour/midi_time_axis.cc b/gtk2_ardour/midi_time_axis.cc index be475216c1..e412b82c32 100644 --- a/gtk2_ardour/midi_time_axis.cc +++ b/gtk2_ardour/midi_time_axis.cc @@ -1509,8 +1509,9 @@ boost::shared_ptr MidiTimeAxisView::add_region (framepos_t pos, framecnt_t length, bool commit) { Editor* real_editor = dynamic_cast (&_editor); - - real_editor->begin_reversible_command (Operations::create_region); + if (commit) { + real_editor->begin_reversible_command (Operations::create_region); + } playlist()->clear_changes (); real_editor->snap_to (pos, RoundNearest); diff --git a/gtk2_ardour/region_editor.cc b/gtk2_ardour/region_editor.cc index 16888fb688..e41e012ce6 100644 --- a/gtk2_ardour/region_editor.cc +++ b/gtk2_ardour/region_editor.cc @@ -270,33 +270,41 @@ RegionEditor::connect_editor_events () void RegionEditor::position_clock_changed () { - PublicEditor::instance().begin_reversible_command (_("change region start position")); - + bool in_command = false; boost::shared_ptr pl = _region->playlist(); if (pl) { + PublicEditor::instance().begin_reversible_command (_("change region start position")); + in_command = true; + _region->clear_changes (); _region->set_position (position_clock.current_time()); _session->add_command(new StatefulDiffCommand (_region)); } - PublicEditor::instance().commit_reversible_command (); + if (in_command) { + PublicEditor::instance().commit_reversible_command (); + } } void RegionEditor::end_clock_changed () { - PublicEditor::instance().begin_reversible_command (_("change region end position")); - + bool in_command = false; boost::shared_ptr pl = _region->playlist(); if (pl) { + PublicEditor::instance().begin_reversible_command (_("change region end position")); + in_command = true; + _region->clear_changes (); _region->trim_end (end_clock.current_time()); _session->add_command(new StatefulDiffCommand (_region)); } - PublicEditor::instance().commit_reversible_command (); + if (in_command) { + PublicEditor::instance().commit_reversible_command (); + } end_clock.set (_region->position() + _region->length() - 1, true); } @@ -305,18 +313,21 @@ void RegionEditor::length_clock_changed () { framecnt_t frames = length_clock.current_time(); - - PublicEditor::instance().begin_reversible_command (_("change region length")); - + bool in_command = false; boost::shared_ptr pl = _region->playlist(); if (pl) { - _region->clear_changes (); + PublicEditor::instance().begin_reversible_command (_("change region length")); + in_command = true; + + _region->clear_changes (); _region->trim_end (_region->position() + frames - 1); _session->add_command(new StatefulDiffCommand (_region)); } - PublicEditor::instance().commit_reversible_command (); + if (in_command) { + PublicEditor::instance().commit_reversible_command (); + } length_clock.set (_region->length()); }