Skip to content

Commit

Permalink
Fix AutomationTrackItem rubberband click thinking it was unhandled.
Browse files Browse the repository at this point in the history
Fix several other cases where a single mouse click could cause several
(not nested) selection ops.
Fix missing selection memento for midi notes and midi commands.
Rename some variables.
Fix random style issues.
  • Loading branch information
nmains committed Jan 10, 2015
1 parent 9e873ac commit 44203ce
Show file tree
Hide file tree
Showing 14 changed files with 375 additions and 66 deletions.
2 changes: 1 addition & 1 deletion gtk2_ardour/automation_line.cc
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ void
AutomationLine::update_visibility ()
{
if (_visible & Line) {
/* Only show the line there are some points, otherwise we may show an out-of-date line
/* Only show the line when there are some points, otherwise we may show an out-of-date line
when automation points have been removed (the line will still follow the shape of the
old points).
*/
Expand Down
56 changes: 42 additions & 14 deletions gtk2_ardour/editor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@

#include "control_protocol/control_protocol.h"

#include "actions.h"
#include "actions.h"
#include "analysis_window.h"
#include "audio_clock.h"
Expand Down Expand Up @@ -251,6 +250,7 @@ pane_size_watcher (Paned* pane)
Editor::Editor ()
: _join_object_range_state (JOIN_OBJECT_RANGE_NONE)

, _mouse_changed_selection (false)
/* time display buttons */
, minsec_label (_("Mins:Secs"))
, bbt_label (_("Bars:Beats"))
Expand Down Expand Up @@ -3336,7 +3336,7 @@ void
Editor::begin_reversible_selection_op (string name)
{
if (_session) {
//cerr << name << endl;
cerr << name << endl;
/* begin/commit pairs can be nested */
selection_op_cmd_depth++;
}
Expand All @@ -3349,20 +3349,22 @@ Editor::commit_reversible_selection_op ()
if (selection_op_cmd_depth == 1) {

if (selection_op_history_it > 0 && selection_op_history_it < selection_op_history.size()) {
/* the user has undone some selection ops and then made a new one */
list<XMLNode *>::iterator it = selection_op_history.begin();
advance (it, selection_op_history_it);
selection_op_history.erase (selection_op_history.begin(), it);
}

selection_op_history.push_front (&_selection_memento->get_state ());
selection_op_history_it = 0;

selection_undo_action->set_sensitive (true);
selection_redo_action->set_sensitive (false);
}

if (selection_op_cmd_depth > 0) {
selection_op_cmd_depth--;
}

selection_undo_action->set_sensitive (true);
selection_redo_action->set_sensitive (false);
}
}

Expand All @@ -3378,7 +3380,6 @@ Editor::undo_selection_op ()
selection_redo_action->set_sensitive (true);
}
++n;

}
/* is there an earlier entry? */
if ((selection_op_history_it + 1) >= selection_op_history.size()) {
Expand All @@ -3401,7 +3402,6 @@ Editor::redo_selection_op ()
selection_undo_action->set_sensitive (true);
}
++n;

}

if (selection_op_history_it == 0) {
Expand Down Expand Up @@ -4899,34 +4899,49 @@ Editor::get_regions_from_selection_and_entered ()
}

void
Editor::get_regionviews_by_id (PBD::ID const & id, RegionSelection & regions) const
Editor::get_regionviews_by_id (PBD::ID const id, RegionSelection & regions) const
{
for (TrackViewList::const_iterator i = track_views.begin(); i != track_views.end(); ++i) {
RouteTimeAxisView* tatv;
RouteTimeAxisView* rtav;

if ((tatv = dynamic_cast<RouteTimeAxisView*> (*i)) != 0) {
if ((rtav = dynamic_cast<RouteTimeAxisView*> (*i)) != 0) {
boost::shared_ptr<Playlist> pl;
std::vector<boost::shared_ptr<Region> > results;
boost::shared_ptr<Track> tr;

if ((tr = tatv->track()) == 0) {
if ((tr = rtav->track()) == 0) {
/* bus */
continue;
}

if ((pl = (tr->playlist())) != 0) {
boost::shared_ptr<Region> r = pl->region_by_id (id);
if (r) {
RegionView* marv = tatv->view()->find_view (r);
if (marv) {
regions.push_back (marv);
RegionView* rv = rtav->view()->find_view (r);
if (rv) {
regions.push_back (rv);
}
}
}
}
}
}

void
Editor::get_per_region_note_selection (list<pair<PBD::ID, set<boost::shared_ptr<Evoral::Note<Evoral::Beats> > > > > &selection) const
{

for (TrackViewList::const_iterator i = track_views.begin(); i != track_views.end(); ++i) {
MidiTimeAxisView* mtav;

if ((mtav = dynamic_cast<MidiTimeAxisView*> (*i)) != 0) {

mtav->get_per_region_note_selection (selection);
}
}

}

void
Editor::get_regions_corresponding_to (boost::shared_ptr<Region> region, vector<RegionView*>& regions, bool src_comparison)
{
Expand Down Expand Up @@ -5102,6 +5117,19 @@ Editor::region_view_added (RegionView * rv)
break;
}
}

MidiRegionView* mrv = dynamic_cast<MidiRegionView*> (rv);
if (mrv) {
list<pair<PBD::ID const, list<boost::shared_ptr<Evoral::Note<Evoral::Beats> > > > >::iterator rnote;
for (rnote = selection->pending_midi_note_selection.begin(); rnote != selection->pending_midi_note_selection.end(); ++rnote) {
if (rv->region()->id () == (*rnote).first) {
mrv->select_notes ((*rnote).second);
selection->pending_midi_note_selection.erase(rnote);
break;
}
}
}

_summary->set_background_dirty ();
}

Expand Down
4 changes: 3 additions & 1 deletion gtk2_ardour/editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,8 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD

void get_regions_corresponding_to (boost::shared_ptr<ARDOUR::Region> region, std::vector<RegionView*>& regions, bool src_comparison);

void get_regionviews_by_id (PBD::ID const & id, RegionSelection & regions) const;
void get_regionviews_by_id (PBD::ID const id, RegionSelection & regions) const;
void get_per_region_note_selection (std::list<std::pair<PBD::ID, std::set<boost::shared_ptr<Evoral::Note<Evoral::Beats> > > > >&) const;

void center_screen (framepos_t);

Expand Down Expand Up @@ -706,6 +707,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD

void button_selection (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_type);
bool button_release_can_deselect;
bool _mouse_changed_selection;

void catch_vanishing_regionview (RegionView *);

Expand Down
4 changes: 4 additions & 0 deletions gtk2_ardour/editor_canvas_events.cc
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ Editor::canvas_scroll_event (GdkEventScroll *event, bool from_canvas)
bool
Editor::track_canvas_button_press_event (GdkEventButton */*event*/)
{
begin_reversible_selection_op (_("Clear Selection Click (track canvas)"));
selection->clear ();
commit_reversible_selection_op();
_track_canvas->grab_focus();
return false;
}
Expand Down Expand Up @@ -1105,8 +1107,10 @@ Editor::canvas_drop_zone_event (GdkEvent* event)
switch (event->type) {
case GDK_BUTTON_RELEASE:
if (event->button.button == 1) {
begin_reversible_selection_op (_("Nowhere Click"));
selection->clear_objects ();
selection->clear_tracks ();
commit_reversible_selection_op ();
}
break;

Expand Down
26 changes: 21 additions & 5 deletions gtk2_ardour/editor_drag.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4718,6 +4718,9 @@ NoteDrag::start_grab (GdkEvent* event, Gdk::Cursor *)
} else {
_region->unique_select (_primary);
}

_editor->begin_reversible_selection_op(_("Select Note Press"));
_editor->commit_reversible_selection_op();
}
}
}
Expand Down Expand Up @@ -4799,27 +4802,37 @@ NoteDrag::finished (GdkEvent* ev, bool moved)
{
if (!moved) {
/* no motion - select note */

if (_editor->current_mouse_mode() == Editing::MouseObject ||
_editor->current_mouse_mode() == Editing::MouseDraw) {


bool changed = false;

if (_was_selected) {
bool add = Keyboard::modifier_state_equals (ev->button.state, Keyboard::PrimaryModifier);
if (add) {
_region->note_deselected (_primary);
changed = true;
}
} else {
bool extend = Keyboard::modifier_state_equals (ev->button.state, Keyboard::TertiaryModifier);
bool add = Keyboard::modifier_state_equals (ev->button.state, Keyboard::PrimaryModifier);

if (!extend && !add && _region->selection_size() > 1) {
_region->unique_select (_primary);
changed = true;
} else if (extend) {
_region->note_selected (_primary, true, true);
changed = true;
} else {
/* it was added during button press */
}
}

if (changed) {
_editor->begin_reversible_selection_op(_("Select Note Release"));
_editor->commit_reversible_selection_op();
}
}
} else {
_region->note_dropped (_primary, total_dx(), total_dy());
Expand Down Expand Up @@ -5204,12 +5217,15 @@ EditorRubberbandSelectDrag::select_things (int button_state, framepos_t x1, fram
void
EditorRubberbandSelectDrag::deselect_things ()
{
if (!getenv("ARDOUR_SAE")) {
_editor->selection->clear_tracks();
}
_editor->begin_reversible_selection_op (_("Clear Selection (rubberband)"));

_editor->selection->clear_tracks();
_editor->selection->clear_regions();
_editor->selection->clear_points ();
_editor->selection->clear_lines ();
_editor->selection->clear_midi_notes ();

_editor->commit_reversible_selection_op();
}

NoteCreateDrag::NoteCreateDrag (Editor* e, ArdourCanvas::Item* i, MidiRegionView* rv)
Expand Down
25 changes: 17 additions & 8 deletions gtk2_ardour/editor_mouse.cc
Original file line number Diff line number Diff line change
Expand Up @@ -448,11 +448,15 @@ Editor::button_selection (ArdourCanvas::Item* /*item*/, GdkEvent* event, ItemTyp
Selection::Operation op = ArdourKeyboard::selection_type (event->button.state);
bool press = (event->type == GDK_BUTTON_PRESS);

if (press) {
_mouse_changed_selection = false;
}

switch (item_type) {
case RegionItem:
if (press) {
if (eff_mouse_mode != MouseRange) {
set_selected_regionview_from_click (press, op);
_mouse_changed_selection = set_selected_regionview_from_click (press, op);
} else {
/* don't change the selection unless the
clicked track is not currently selected. if
Expand All @@ -465,7 +469,7 @@ Editor::button_selection (ArdourCanvas::Item* /*item*/, GdkEvent* event, ItemTyp
}
} else {
if (eff_mouse_mode != MouseRange) {
set_selected_regionview_from_click (press, op);
_mouse_changed_selection = set_selected_regionview_from_click (press, op);
}
}
break;
Expand All @@ -483,7 +487,7 @@ Editor::button_selection (ArdourCanvas::Item* /*item*/, GdkEvent* event, ItemTyp
case StartCrossFadeItem:
case EndCrossFadeItem:
if (get_smart_mode() || eff_mouse_mode != MouseRange) {
set_selected_regionview_from_click (press, op);
_mouse_changed_selection = set_selected_regionview_from_click (press, op);
} else if (event->type == GDK_BUTTON_PRESS) {
set_selected_track_as_side_effect (op);
}
Expand All @@ -492,7 +496,7 @@ Editor::button_selection (ArdourCanvas::Item* /*item*/, GdkEvent* event, ItemTyp
case ControlPointItem:
set_selected_track_as_side_effect (op);
if (eff_mouse_mode != MouseRange) {
set_selected_control_point_from_click (press, op);
_mouse_changed_selection = set_selected_control_point_from_click (press, op);
}
break;

Expand All @@ -501,6 +505,7 @@ Editor::button_selection (ArdourCanvas::Item* /*item*/, GdkEvent* event, ItemTyp
if (event->button.button == 3) {
selection->clear_tracks ();
set_selected_track_as_side_effect (op);
_mouse_changed_selection = true;
}
break;

Expand All @@ -511,6 +516,12 @@ Editor::button_selection (ArdourCanvas::Item* /*item*/, GdkEvent* event, ItemTyp
default:
break;
}

if ((!press) && _mouse_changed_selection) {
begin_reversible_selection_op (_("Button Selection"));
commit_reversible_selection_op ();
_mouse_changed_selection = false;
}
}

bool
Expand Down Expand Up @@ -744,6 +755,7 @@ Editor::button_press_handler_1 (ArdourCanvas::Item* item, GdkEvent* event, ItemT
case AutomationTrackItem:
/* rubberband drag to select automation points */
_drags->set (new EditorRubberbandSelectDrag (this, item), event);
return true;
break;

default:
Expand Down Expand Up @@ -1465,10 +1477,7 @@ Editor::button_release_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemT
}

/* do any (de)selection operations that should occur on button release */

begin_reversible_selection_op (_("Button Select"));
button_selection (item, event, item_type);
commit_reversible_selection_op ();
button_selection (item, event, item_type);

return true;
break;
Expand Down
14 changes: 9 additions & 5 deletions gtk2_ardour/editor_selection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,9 @@ Editor::set_selected_track_as_side_effect (Selection::Operation op)
}
} else if (group && group->is_active()) {
for (TrackViewList::iterator i = track_views.begin(); i != track_views.end (); ++i) {
if ((*i)->route_group() == group)
if ((*i)->route_group() == group) {
selection->remove(*i);
}
}
} else {
selection->remove (clicked_axisview);
Expand All @@ -215,8 +216,9 @@ Editor::set_selected_track_as_side_effect (Selection::Operation op)
}
} else if (group && group->is_active()) {
for (TrackViewList::iterator i = track_views.begin(); i != track_views.end (); ++i) {
if ( (*i)->route_group() == group)
if ((*i)->route_group() == group) {
selection->add(*i);
}
}
} else {
selection->add (clicked_axisview);
Expand All @@ -234,8 +236,9 @@ Editor::set_selected_track_as_side_effect (Selection::Operation op)
}
} else if (group && group->is_active()) {
for (TrackViewList::iterator i = track_views.begin(); i != track_views.end (); ++i) {
if ((*i)->route_group() == group)
if ((*i)->route_group() == group) {
selection->add(*i);
}
}
} else {
selection->add (clicked_axisview);
Expand All @@ -253,8 +256,9 @@ Editor::set_selected_track_as_side_effect (Selection::Operation op)
}
} else if (group && group->is_active()) {
for (TrackViewList::iterator i = track_views.begin(); i != track_views.end (); ++i) {
if ((*i)->route_group() == group)
if ((*i)->route_group() == group) {
selection->add(*i);
}
}
} else {
selection->set (clicked_axisview);
Expand Down Expand Up @@ -1953,7 +1957,7 @@ Editor::get_edit_op_range (framepos_t& start, framepos_t& end) const
void
Editor::deselect_all ()
{
begin_reversible_selection_op(_("Clear Selection"));
begin_reversible_selection_op(_("Deselect All"));
selection->clear ();
commit_reversible_selection_op ();
}
Expand Down
Loading

0 comments on commit 44203ce

Please sign in to comment.