move control surface prefs onto their own tab in the user prefs; for Generic MIDI...
[ardour.git] / libs / evoral / evoral / Sequence.hpp
index bc3831df6bc592b63db0a4656bc1aa676e243638..e2e92385aaf1f18446d435fe548aec22c30ef19a 100644 (file)
@@ -25,7 +25,7 @@
 #include <list>
 #include <utility>
 #include <boost/shared_ptr.hpp>
-#include <glibmm/thread.h>
+#include <glibmm/threads.h>
 #include "evoral/types.hpp"
 #include "evoral/Note.hpp"
 #include "evoral/Parameter.hpp"
@@ -67,16 +67,15 @@ public:
 
 protected:
        struct WriteLockImpl {
-               WriteLockImpl(Glib::RWLock& s, Glib::Mutex& c)
-                       : sequence_lock(new Glib::RWLock::WriterLock(s))
-                       , control_lock(new Glib::Mutex::Lock(c))
-               { }
+               WriteLockImpl(Glib::Threads::RWLock& s, Glib::Threads::Mutex& c)
+                       : sequence_lock(new Glib::Threads::RWLock::WriterLock(s))
+                       , control_lock(new Glib::Threads::Mutex::Lock(c)) { }
                ~WriteLockImpl() {
                        delete sequence_lock;
                        delete control_lock;
                }
-               Glib::RWLock::WriterLock* sequence_lock;
-               Glib::Mutex::Lock*        control_lock;
+               Glib::Threads::RWLock::WriterLock* sequence_lock;
+               Glib::Threads::Mutex::Lock*        control_lock;
        };
 
 public:
@@ -84,11 +83,11 @@ 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<Glib::Threads::RWLock::ReaderLock> ReadLock;
        typedef boost::shared_ptr<WriteLockImpl>            WriteLock;
 
-       virtual ReadLock  read_lock() const { return ReadLock(new Glib::RWLock::ReaderLock(_lock)); }
-       virtual WriteLock write_lock()      { return WriteLock(new WriteLockImpl(_lock, _control_lock)); }
+       virtual ReadLock  read_lock() const { return ReadLock(new Glib::Threads::RWLock::ReaderLock(_lock)); }
+        virtual WriteLock write_lock()      { return WriteLock(new WriteLockImpl(_lock, _control_lock)); }
 
        void clear();
 
@@ -98,13 +97,13 @@ public:
        void start_write();
        bool writing() const { return _writing; }
 
-        enum StuckNoteOption {
+       enum StuckNoteOption {
                Relax,
                DeleteStuckNotes,
                ResolveStuckNotes
        };
 
-        void end_write (StuckNoteOption, Time when = 0);
+       void end_write (StuckNoteOption, Time when = 0);
 
        void append(const Event<Time>& ev, Evoral::event_id_t evid);
 
@@ -126,7 +125,7 @@ public:
        struct EarlierNoteComparator {
                inline bool operator()(const boost::shared_ptr< const Note<Time> > a,
                                       const boost::shared_ptr< const Note<Time> > b) const {
-                       return a->time() < b->time();
+                       return musical_time_less_than (a->time(), b->time());
                }
        };
 
@@ -134,6 +133,7 @@ public:
                typedef const Note<Time>* value_type;
                inline bool operator()(const boost::shared_ptr< const Note<Time> > a,
                                       const boost::shared_ptr< const Note<Time> > b) const {
+                       return musical_time_greater_than (a->time(), b->time());
                        return a->time() > b->time();
                }
        };
@@ -142,7 +142,7 @@ public:
                typedef const Note<Time>* value_type;
                inline bool operator()(const boost::shared_ptr< const Note<Time> > a,
                                       const boost::shared_ptr< const Note<Time> > b) const {
-                       return a->end_time() > b->end_time();
+                       return musical_time_greater_than (a->end_time(), b->end_time());
                }
        };
 
@@ -150,7 +150,7 @@ public:
        inline       Notes& notes()       { return _notes; }
        inline const Notes& notes() const { return _notes; }
 
-       enum NoteOperator { 
+       enum NoteOperator {
                PitchEqual,
                PitchLessThan,
                PitchLessThanOrEqual,
@@ -169,7 +169,7 @@ public:
        void trim_overlapping_notes ();
        void remove_duplicate_notes ();
 
-       enum OverlapPitchResolution { 
+       enum OverlapPitchResolution {
                LastOnFirstOff,
                FirstOnFirstOff
        };
@@ -181,16 +181,25 @@ public:
 
        void set_notes (const Sequence<Time>::Notes& n);
 
-       typedef std::vector< boost::shared_ptr< Event<Time> > > SysExes;
+       typedef boost::shared_ptr< Event<Time> > SysExPtr;
+       typedef boost::shared_ptr<const Event<Time> > constSysExPtr;
+
+       struct EarlierSysExComparator {
+               inline bool operator() (constSysExPtr a, constSysExPtr b) const {
+                       return musical_time_less_than (a->time(), b->time());
+               }
+       };
+
+       typedef std::multiset<SysExPtr, EarlierSysExComparator> SysExes;
        inline       SysExes& sysexes()       { return _sysexes; }
        inline const SysExes& sysexes() const { return _sysexes; }
 
        typedef boost::shared_ptr<PatchChange<Time> > PatchChangePtr;
        typedef boost::shared_ptr<const PatchChange<Time> > constPatchChangePtr;
-       
+
        struct EarlierPatchChangeComparator {
                inline bool operator() (constPatchChangePtr a, constPatchChangePtr b) const {
-                       return a->time() < b->time();
+                       return musical_time_less_than (a->time(), b->time());
                }
        };
 
@@ -198,7 +207,7 @@ public:
        inline       PatchChanges& patch_changes ()       { return _patch_changes; }
        inline const PatchChanges& patch_changes () const { return _patch_changes; }
 
-        void dump (std::ostream&) const;
+       void dump (std::ostream&) const;
 
 private:
        typedef std::priority_queue<NotePtr, std::deque<NotePtr>, LaterNoteEndComparator> ActiveNotes;
@@ -257,11 +266,12 @@ public:
                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;
        typename PatchChanges::const_iterator patch_change_lower_bound (Time t) const;
+       typename SysExes::const_iterator sysex_lower_bound (Time t) const;
 
        bool control_to_midi_event(boost::shared_ptr< Event<Time> >& ev,
                                   const ControlIterator&            iter) const;
@@ -269,7 +279,7 @@ public:
        bool edited() const      { return _edited; }
        void set_edited(bool yn) { _edited = yn; }
 
-       bool overlaps (const NotePtr& ev, 
+       bool overlaps (const NotePtr& ev,
                       const NotePtr& ignore_this_note) const;
        bool contains (const NotePtr& ev) const;
 
@@ -279,6 +289,9 @@ public:
        void add_patch_change_unlocked (const PatchChangePtr);
        void remove_patch_change_unlocked (const constPatchChangePtr);
 
+       void add_sysex_unlocked (const SysExPtr);
+       void remove_sysex_unlocked (const SysExPtr);
+
        uint8_t lowest_note()  const { return _lowest_note; }
        uint8_t highest_note() const { return _highest_note; }
 
@@ -287,7 +300,7 @@ protected:
        bool                   _edited;
        bool                   _overlapping_pitches_accepted;
        OverlapPitchResolution _overlap_pitch_resolution;
-       mutable Glib::RWLock   _lock;
+       mutable Glib::Threads::RWLock   _lock;
        bool                   _writing;
 
        virtual int resolve_overlaps_unlocked (const NotePtr, void* /* arg */ = 0) {
@@ -298,6 +311,8 @@ protected:
        inline       Pitches& pitches(uint8_t chan)       { return _pitches[chan&0xf]; }
        inline const Pitches& pitches(uint8_t chan) const { return _pitches[chan&0xf]; }
 
+       virtual void control_list_marked_dirty ();
+
 private:
        friend class const_iterator;
 
@@ -313,8 +328,6 @@ private:
        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;
 
-       virtual void control_list_marked_dirty ();
-
        const TypeMap& _type_map;
 
        Notes        _notes;       // notes indexed by time
@@ -341,7 +354,7 @@ private:
 
 } // namespace Evoral
 
-// template<typename Time> std::ostream& operator<<(std::ostream& o, const Evoral::Sequence<Time>& s) { s.dump (o); return o; }
+template<typename Time> std::ostream& operator<<(std::ostream& o, const Evoral::Sequence<Time>& s) { s.dump (o); return o; }
 
 #endif // EVORAL_SEQUENCE_HPP