pay some attention to the special guest of the night: KDE window stacking
[ardour.git] / gtk2_ardour / selection.cc
index c1a53bd00db00460362bd01b0cc8f38b5c1d8271..98b5d62c1043f2a4faa289ba8a6e40438e6eb99b 100644 (file)
@@ -26,6 +26,8 @@
 #include "ardour/playlist.h"
 #include "ardour/rc_configuration.h"
 
+#include "control_protocol/control_protocol.h"
+
 #include "audio_region_view.h"
 #include "debug.h"
 #include "gui_thread.h"
@@ -39,7 +41,7 @@
 #include "public_editor.h"
 #include "control_point.h"
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 using namespace std;
 using namespace ARDOUR;
@@ -116,36 +118,37 @@ Selection::clear ()
 }
 
 void
-Selection::clear_objects ()
+Selection::clear_objects (bool with_signal)
 {
-       clear_regions ();
-       clear_points ();
-       clear_lines();
-       clear_playlists ();
-       clear_midi_notes ();
-       clear_midi_regions ();
+       clear_regions (with_signal);
+       clear_points (with_signal);
+       clear_lines(with_signal);
+       clear_playlists (with_signal);
+       clear_midi_notes (with_signal);
+       clear_midi_regions (with_signal);
 }
 
 void
-Selection::clear_tracks ()
+Selection::clear_tracks (bool with_signal)
 {
        if (!tracks.empty()) {
                for (TrackViewList::iterator x = tracks.begin(); x != tracks.end(); ++x) {
                        (*x)->set_selected (false);
                }
                tracks.clear ();
-               if (!_no_tracks_changed) {
+               if (!_no_tracks_changed && with_signal) {
                        TracksChanged();
                }
        }
 }
 
 void
-Selection::clear_time ()
+Selection::clear_time (bool with_signal)
 {
        time.clear();
-
-       TimeChanged ();
+       if (with_signal) {
+               TimeChanged ();
+       }
 }
 
 void
@@ -159,23 +162,27 @@ Selection::dump_region_layers()
 
 
 void
-Selection::clear_regions ()
+Selection::clear_regions (bool with_signal)
 {
        if (!regions.empty()) {
                regions.clear_all ();
-               RegionsChanged();
+               if (with_signal) {
+                       RegionsChanged();
+               }
        }
 }
 
 void
-Selection::clear_midi_notes ()
+Selection::clear_midi_notes (bool with_signal)
 {
        if (!midi_notes.empty()) {
                for (MidiNoteSelection::iterator x = midi_notes.begin(); x != midi_notes.end(); ++x) {
                        delete *x;
                }
                midi_notes.clear ();
-               MidiNotesChanged ();
+               if (with_signal) {
+                       MidiNotesChanged ();
+               }
        }
 
        // clear note selections for MRV's that have note selections
@@ -193,16 +200,18 @@ Selection::clear_midi_notes ()
 }
 
 void
-Selection::clear_midi_regions ()
+Selection::clear_midi_regions (bool with_signal)
 {
        if (!midi_regions.empty()) {
                midi_regions.clear ();
-               MidiRegionsChanged ();
+               if (with_signal) {
+                       MidiRegionsChanged ();
+               }
        }
 }
 
 void
-Selection::clear_playlists ()
+Selection::clear_playlists (bool with_signal)
 {
        /* Selections own their playlists */
 
@@ -214,25 +223,31 @@ Selection::clear_playlists ()
 
        if (!playlists.empty()) {
                playlists.clear ();
-               PlaylistsChanged();
+               if (with_signal) {
+                       PlaylistsChanged();
+               }
        }
 }
 
 void
-Selection::clear_lines ()
+Selection::clear_lines (bool with_signal)
 {
        if (!lines.empty()) {
                lines.clear ();
-               LinesChanged();
+               if (with_signal) {
+                       LinesChanged();
+               }
        }
 }
 
 void
-Selection::clear_markers ()
+Selection::clear_markers (bool with_signal)
 {
        if (!markers.empty()) {
                markers.clear ();
-               MarkersChanged();
+               if (with_signal) {
+                       MarkersChanged();
+               }
        }
 }
 
@@ -607,10 +622,14 @@ Selection::add (boost::shared_ptr<Evoral::ControlList> cl)
                warning << "Programming error: Selected list is not an ARDOUR::AutomationList" << endmsg;
                return;
        }
-       if (find (lines.begin(), lines.end(), al) == lines.end()) {
-               lines.push_back (al);
-               LinesChanged();
-       }
+
+       /* The original may change so we must store a copy (not a pointer) here.
+        * e.g AutomationLine rewrites the list with gain mapping.
+        * the downside is that we can't perfom duplicate checks.
+        * This code was changed in response to #6842
+        */
+       lines.push_back (boost::shared_ptr<ARDOUR::AutomationList> (new ARDOUR::AutomationList(*al)));
+       LinesChanged();
 }
 
 void
@@ -620,6 +639,7 @@ Selection::remove (TimeAxisView* track)
        if ((i = find (tracks.begin(), tracks.end(), track)) != tracks.end()) {
                track->set_selected (false);
                tracks.erase (i);
+
                if (!_no_tracks_changed) {
                        TracksChanged();
                }
@@ -776,8 +796,8 @@ Selection::remove (boost::shared_ptr<ARDOUR::AutomationList> ac)
 void
 Selection::set (TimeAxisView* track)
 {
-       clear_objects();  //enforce object/range exclusivity
-       clear_tracks ();
+       clear_objects ();  //enforce object/range exclusivity
+       clear_tracks (false);
        add (track);
 }
 
@@ -785,7 +805,7 @@ void
 Selection::set (const TrackViewList& track_list)
 {
        clear_objects();  //enforce object/range exclusivity
-       clear_tracks ();
+       clear_tracks (false);
        add (track_list);
 }
 
@@ -934,7 +954,7 @@ Selection::selected (ArdourMarker* m)
 bool
 Selection::selected (TimeAxisView* tv)
 {
-       return tv->get_selected ();
+       return tv->selected ();
 }
 
 bool
@@ -980,7 +1000,7 @@ Selection::toggle (ControlPoint* cp)
        clear_time();  //enforce region/object exclusivity
        clear_tracks();  //enforce object/track exclusivity
 
-       cp->set_selected (!cp->get_selected ());
+       cp->set_selected (!cp->selected ());
        PointSelection::iterator i = find (points.begin(), points.end(), cp);
        if (i == points.end()) {
                points.push_back (cp);
@@ -1090,11 +1110,13 @@ Selection::add (list<Selectable*> const & selectables)
 }
 
 void
-Selection::clear_points ()
+Selection::clear_points (bool with_signal)
 {
        if (!points.empty()) {
                points.clear ();
-               PointsChanged ();
+               if (with_signal) {
+                       PointsChanged ();
+               }
        }
 }
 
@@ -1128,7 +1150,7 @@ Selection::set (ControlPoint* cp)
        clear_time ();  //enforce region/object exclusivity
        clear_tracks();  //enforce object/track exclusivity
 
-       if (cp->get_selected () && points.size () == 1) {
+       if (cp->selected () && points.size () == 1) {
                return;
        }
 
@@ -1248,36 +1270,19 @@ Selection::get_state () const
        }
 
        /* midi region views have thir own internal selection. */
-       XMLNode* n = NULL;
        list<pair<PBD::ID, std::set<boost::shared_ptr<Evoral::Note<Evoral::Beats> > > > > rid_notes;
        editor->get_per_region_note_selection (rid_notes);
-       if (!rid_notes.empty()) {
-               n = node->add_child (X_("MIDINote"));
-       }
+
        list<pair<PBD::ID, std::set<boost::shared_ptr<Evoral::Note<Evoral::Beats> > > > >::iterator rn_it;
        for (rn_it = rid_notes.begin(); rn_it != rid_notes.end(); ++rn_it) {
-               assert(n); // hint for clang static analysis
-               n->add_property (X_("region_id"), atoi((*rn_it).first.to_s().c_str()));
+               XMLNode* n = node->add_child (X_("MIDINotes"));
+               n->add_property (X_("region-id"), atoi((*rn_it).first.to_s().c_str()));
 
                for (std::set<boost::shared_ptr<Evoral::Note<Evoral::Beats> > >::iterator i = (*rn_it).second.begin(); i != (*rn_it).second.end(); ++i) {
                        XMLNode* nc = n->add_child(X_("note"));
-                       snprintf(buf, sizeof(buf), "%d", (*i)->channel());
-                       nc->add_property(X_("channel"), string(buf));
-
-                       snprintf(buf, sizeof(buf), "%f", (*i)->time().to_double());
-                       nc->add_property(X_("time"), string(buf));
 
-                       snprintf(buf, sizeof(buf), "%d", (*i)->note());
-                       nc->add_property(X_("note"), string(buf));
-
-                       snprintf(buf, sizeof(buf), "%f", (*i)->length().to_double());
-                       nc->add_property(X_("length"), string(buf));
-
-                       snprintf(buf, sizeof(buf), "%d", (*i)->velocity());
-                       nc->add_property(X_("velocity"), string(buf));
-
-                       snprintf(buf, sizeof(buf), "%d", (*i)->off_velocity());
-                       nc->add_property(X_("off-velocity"), string(buf));
+                       snprintf(buf, sizeof(buf), "%d", (*i)->id());
+                       nc->add_property (X_("note-id"), string(buf));
                }
        }
 
@@ -1346,7 +1351,7 @@ Selection::set_state (XMLNode const & node, int)
        for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
                if ((*i)->name() == X_("RouteView")) {
 
-                       XMLProperty* prop_id = (*i)->property (X_("id"));
+                       XMLProperty const * prop_id = (*i)->property (X_("id"));
                        assert (prop_id);
                        PBD::ID id (prop_id->value ());
                        RouteTimeAxisView* rtv = editor->get_route_view_by_route_id (id);
@@ -1355,7 +1360,7 @@ Selection::set_state (XMLNode const & node, int)
                        }
 
                } else if ((*i)->name() == X_("Region")) {
-                       XMLProperty* prop_id = (*i)->property (X_("id"));
+                       XMLProperty const * prop_id = (*i)->property (X_("id"));
                        assert (prop_id);
                        PBD::ID id (prop_id->value ());
 
@@ -1372,8 +1377,8 @@ Selection::set_state (XMLNode const & node, int)
                                regions.pending.push_back (id);
                        }
 
-               } else if ((*i)->name() == X_("MIDINote")) {
-                       XMLProperty* prop_region_id = (*i)->property (X_("region-id"));
+               } else if ((*i)->name() == X_("MIDINotes")) {
+                       XMLProperty const * prop_region_id = (*i)->property (X_("region-id"));
 
                        assert (prop_region_id);
 
@@ -1382,35 +1387,15 @@ Selection::set_state (XMLNode const & node, int)
 
                        editor->get_regionviews_by_id (id, rs); // there could be more than one
 
-                       std::list<boost::shared_ptr<Evoral::Note<Evoral::Beats> > > notes;
+                       std::list<Evoral::event_id_t> notes;
                        XMLNodeList children = (*i)->children ();
 
                        for (XMLNodeList::const_iterator ci = children.begin(); ci != children.end(); ++ci) {
-                               XMLProperty* prop_channel = (*ci)->property (X_("channel"));
-                               XMLProperty* prop_time = (*ci)->property (X_("time"));
-                               XMLProperty* prop_note = (*ci)->property (X_("note"));
-                               XMLProperty* prop_length = (*ci)->property (X_("length"));
-                               XMLProperty* prop_velocity = (*ci)->property (X_("velocity"));
-                               XMLProperty* prop_off_velocity = (*ci)->property (X_("off-velocity"));
-
-                               assert (prop_channel);
-                               assert (prop_time);
-                               assert (prop_note);
-                               assert (prop_length);
-                               assert (prop_velocity);
-                               assert (prop_off_velocity);
-
-                               uint8_t channel = atoi(prop_channel->value());
-                               Evoral::Beats time (atof(prop_time->value()));
-                               Evoral::Beats length (atof(prop_length->value()));
-                               uint8_t note = atoi(prop_note->value());
-                               uint8_t velocity = atoi(prop_velocity->value());
-                               uint8_t off_velocity = atoi(prop_off_velocity->value());
-                               boost::shared_ptr<Evoral::Note<Evoral::Beats> > the_note
-                                       (new Evoral::Note<Evoral::Beats>  (channel, time, length, note, velocity));
-                               the_note->set_off_velocity (off_velocity);
-
-                               notes.push_back (the_note);
+                               XMLProperty const * prop_id = (*ci)->property (X_("note-id"));
+                               if (prop_id) {
+                                       Evoral::event_id_t id = atoi(prop_id->value());
+                                       notes.push_back (id);
+                               }
                        }
 
                        for (RegionSelection::iterator rsi = rs.begin(); rsi != rs.end(); ++rsi) {
@@ -1426,16 +1411,16 @@ Selection::set_state (XMLNode const & node, int)
                        }
 
                } else if  ((*i)->name() == X_("ControlPoint")) {
-                       XMLProperty* prop_type = (*i)->property (X_("type"));
+                       XMLProperty const * prop_type = (*i)->property (X_("type"));
 
                        assert(prop_type);
 
                        if (prop_type->value () == "track") {
 
-                               XMLProperty* prop_route_id = (*i)->property (X_("route-id"));
-                               XMLProperty* prop_alist_id = (*i)->property (X_("automation-list-id"));
-                               XMLProperty* prop_parameter = (*i)->property (X_("parameter"));
-                               XMLProperty* prop_view_index = (*i)->property (X_("view-index"));
+                               XMLProperty const * prop_route_id = (*i)->property (X_("route-id"));
+                               XMLProperty const * prop_alist_id = (*i)->property (X_("automation-list-id"));
+                               XMLProperty const * prop_parameter = (*i)->property (X_("parameter"));
+                               XMLProperty const * prop_view_index = (*i)->property (X_("view-index"));
 
                                assert (prop_route_id);
                                assert (prop_alist_id);
@@ -1465,8 +1450,8 @@ Selection::set_state (XMLNode const & node, int)
                                        add (cps);
                                }
                        } else if (prop_type->value () == "region") {
-                               XMLProperty* prop_region_id = (*i)->property (X_("region-id"));
-                               XMLProperty* prop_view_index = (*i)->property (X_("view-index"));
+                               XMLProperty const * prop_region_id = (*i)->property (X_("region-id"));
+                               XMLProperty const * prop_view_index = (*i)->property (X_("view-index"));
 
                                if (!prop_region_id || !prop_view_index) {
                                        continue;
@@ -1496,8 +1481,8 @@ Selection::set_state (XMLNode const & node, int)
                        }
 
                } else if  ((*i)->name() == X_("AudioRange")) {
-                       XMLProperty* prop_start = (*i)->property (X_("start"));
-                       XMLProperty* prop_end = (*i)->property (X_("end"));
+                       XMLProperty const * prop_start = (*i)->property (X_("start"));
+                       XMLProperty const * prop_end = (*i)->property (X_("end"));
 
                        assert (prop_start);
                        assert (prop_end);
@@ -1509,8 +1494,8 @@ Selection::set_state (XMLNode const & node, int)
 
                } else if ((*i)->name() == X_("AutomationView")) {
 
-                       XMLProperty* prop_id = (*i)->property (X_("id"));
-                       XMLProperty* prop_parameter = (*i)->property (X_("parameter"));
+                       XMLProperty const * prop_id = (*i)->property (X_("id"));
+                       XMLProperty const * prop_parameter = (*i)->property (X_("parameter"));
 
                        assert (prop_id);
                        assert (prop_parameter);
@@ -1533,8 +1518,8 @@ Selection::set_state (XMLNode const & node, int)
 
                } else if ((*i)->name() == X_("Marker")) {
 
-                       XMLProperty* prop_id = (*i)->property (X_("id"));
-                       XMLProperty* prop_start = (*i)->property (X_("start"));
+                       XMLProperty const * prop_id = (*i)->property (X_("id"));
+                       XMLProperty const * prop_start = (*i)->property (X_("start"));
                        assert (prop_id);
                        assert (prop_start);