forward port automation handling changes from 2.x, upto and including about rev 6981...
[ardour.git] / libs / evoral / evoral / Sequence.hpp
index 8acd04fd27a53c4ffc0b63b3eb18ef1bdd8149b4..6c6c58357f6e5bfc63d224f919453788584a4a68 100644 (file)
@@ -22,6 +22,7 @@
 #include <vector>
 #include <queue>
 #include <set>
+#include <list>
 #include <utility>
 #include <boost/shared_ptr.hpp>
 #include <glibmm/thread.h>
@@ -78,6 +79,10 @@ protected:
        };
 
 public:
+
+        typedef typename boost::shared_ptr<Evoral::Note<Time> >  NotePtr;
+        typedef typename boost::shared_ptr<const Evoral::Note<Time> >  constNotePtr;
+
        typedef boost::shared_ptr<Glib::RWLock::ReaderLock> ReadLock;
        typedef boost::shared_ptr<WriteLockImpl>            WriteLock;
 
@@ -93,7 +98,7 @@ public:
        bool writing() const { return _writing; }
        void end_write(bool delete_stuck=false);
 
-       void append(const Event<Time>& ev);
+        void append(const Event<Time>& ev, Evoral::event_id_t evid);
 
        inline size_t n_notes() const { return _notes.size(); }
        inline bool   empty()   const { return _notes.size() == 0 && ControlSet::controls_empty(); }
@@ -133,7 +138,7 @@ public:
                }
        };
 
-       typedef std::multiset<boost::shared_ptr< Note<Time> >, EarlierNoteComparator> Notes;
+       typedef std::multiset<NotePtr, EarlierNoteComparator> Notes;
        inline       Notes& notes()       { return _notes; }
        inline const Notes& notes() const { return _notes; }
 
@@ -153,8 +158,19 @@ public:
         void get_notes (Notes&, NoteOperator, uint8_t val, int chan_mask = 0) const;
 
         void remove_overlapping_notes ();
+        void trim_overlapping_notes ();
         void remove_duplicate_notes ();
 
+        enum OverlapPitchResolution { 
+                LastOnFirstOff,
+                FirstOnFirstOff
+        };
+
+        bool overlapping_pitches_accepted() const { return _overlapping_pitches_accepted; }
+        void overlapping_pitches_accepted(bool yn)  { _overlapping_pitches_accepted = yn; }
+        OverlapPitchResolution overlap_pitch_resolution() const { return _overlap_pitch_resolution; }
+        void set_overlap_pitch_resolution(OverlapPitchResolution opr);
+
        void set_notes (const Sequence<Time>::Notes& n);
 
        typedef std::vector< boost::shared_ptr< Event<Time> > > SysExes;
@@ -162,17 +178,14 @@ public:
        inline const SysExes& sysexes() const { return _sysexes; }
 
 private:
-       typedef std::priority_queue< boost::shared_ptr< Note<Time> >,
-                                    std::deque< boost::shared_ptr< Note<Time> > >,
-                                    LaterNoteEndComparator >
-               ActiveNotes;
+       typedef std::priority_queue<NotePtr, std::deque<NotePtr>, LaterNoteEndComparator> ActiveNotes;
 public:
 
        /** Read iterator */
        class const_iterator {
        public:
                const_iterator();
-               const_iterator(const Sequence<Time>& seq, Time t);
+               const_iterator(const Sequence<Time>& seq, Time t, bool, std::set<Evoral::Parameter> const &);
                ~const_iterator();
 
                inline bool valid() const { return !_is_end && _event; }
@@ -207,9 +220,12 @@ public:
                typename SysExes::const_iterator _sysex_iter;
                ControlIterators                 _control_iters;
                ControlIterators::iterator       _control_iter;
+               bool                             _force_discrete;
        };
 
-       const_iterator        begin(Time t=0) const { return const_iterator(*this, t); }
+       const_iterator begin (Time t = 0, bool force_discrete = false, std::set<Evoral::Parameter> const & f = std::set<Evoral::Parameter> ()) const {
+               return const_iterator (*this, t, force_discrete, f);
+       }
        const const_iterator& end()           const { return _end_iter; }
 
        typename Notes::const_iterator note_lower_bound (Time t) const;
@@ -220,41 +236,56 @@ public:
        bool edited() const      { return _edited; }
        void set_edited(bool yn) { _edited = yn; }
 
-        bool overlaps (const boost::shared_ptr< Note<Time> > ev) const;
-        bool contains (const boost::shared_ptr< Note<Time> > ev) const;
+        bool overlaps (const NotePtr& ev, 
+                       const NotePtr& ignore_this_note) const;
+        bool contains (const NotePtr& ev) const;
 
-       bool add_note_unlocked(const boost::shared_ptr< Note<Time> > note);
-       void remove_note_unlocked(const boost::shared_ptr< const Note<Time> > note);
+        bool add_note_unlocked (const NotePtr note, void* arg = 0);
+       void remove_note_unlocked(const constNotePtr note);
 
        uint8_t lowest_note()  const { return _lowest_note; }
        uint8_t highest_note() const { return _highest_note; }
 
+
 protected:
-       bool                 _edited;
-       mutable Glib::RWLock _lock;
+       bool                   _edited;
+        bool                   _overlapping_pitches_accepted;
+        OverlapPitchResolution _overlap_pitch_resolution;
+       mutable Glib::RWLock   _lock;
+       bool                   _writing;
+
+        virtual int resolve_overlaps_unlocked (const NotePtr, void* arg = 0) {
+                return 0;
+        }
+
+       typedef std::multiset<NotePtr, NoteNumberComparator>  Pitches;
+       inline       Pitches& pitches(uint8_t chan)       { return _pitches[chan&0xf]; }
+        inline const Pitches& pitches(uint8_t chan) const { return _pitches[chan&0xf]; }
 
 private:
        friend class const_iterator;
 
-        bool overlaps_unlocked (const boost::shared_ptr< Note<Time> > ev) const;
-        bool contains_unlocked (const boost::shared_ptr< Note<Time> > ev) const;
+        bool overlaps_unlocked (const NotePtr& ev, const NotePtr& ignore_this_note) const;
+        bool contains_unlocked (const NotePtr& ev) const;
 
-        void append_note_on_unlocked (boost::shared_ptr< Note<Time> >);
-        void append_note_off_unlocked(boost::shared_ptr< Note<Time> >);
-       void append_control_unlocked(const Parameter& param, Time time, double value);
-       void append_sysex_unlocked(const MIDIEvent<Time>& ev);
+        void append_note_on_unlocked (NotePtr, Evoral::event_id_t);
+        void append_note_off_unlocked(NotePtr);
+        void append_control_unlocked(const Parameter& param, Time time, double value, Evoral::event_id_t);
+        void append_sysex_unlocked(const MIDIEvent<Time>& ev, Evoral::event_id_t);
+
+        void get_notes_by_pitch (Notes&, NoteOperator, uint8_t val, int chan_mask = 0) const;
+        void get_notes_by_velocity (Notes&, NoteOperator, uint8_t val, int chan_mask = 0) const;
+
+       void control_list_marked_dirty ();
 
        const TypeMap& _type_map;
 
-       Notes   _notes;
+        Notes   _notes;       // notes indexed by time
+        Pitches _pitches[16]; // notes indexed by channel+pitch
        SysExes _sysexes;
 
-       typedef std::multiset<boost::shared_ptr< Note<Time> >, EarlierNoteComparator> WriteNotes;
+       typedef std::multiset<NotePtr, EarlierNoteComparator> WriteNotes;
        WriteNotes _write_notes[16];
-       bool       _writing;
-
-       typedef std::vector< boost::shared_ptr<const ControlList> > ControlLists;
-       ControlLists _dirty_controls;
 
        const   const_iterator _end_iter;
        bool                   _percussive;