1 /* This file is part of Evoral.
2 * Copyright (C) 2008 Dave Robillard <http://drobilla.net>
3 * Copyright (C) 2000-2008 Paul Davis
5 * Evoral is free software; you can redistribute it and/or modify it under the
6 * terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 2 of the License, or (at your option) any later
10 * Evoral is distributed in the hope that it will be useful, but WITHOUT ANY
11 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 #ifndef EVORAL_SEQUENCE_HPP
20 #define EVORAL_SEQUENCE_HPP
27 #include <boost/shared_ptr.hpp>
28 #include <glibmm/thread.h>
29 #include <evoral/types.hpp>
30 #include <evoral/Note.hpp>
31 #include <evoral/Parameter.hpp>
32 #include <evoral/ControlSet.hpp>
42 /** This class keeps track of the current x and y for a control
44 class ControlIterator {
46 boost::shared_ptr<const ControlList> list;
50 ControlIterator(boost::shared_ptr<const ControlList> a_list,
60 /** This is a higher level view of events, with separate representations for
61 * notes (instead of just unassociated note on/off events) and controller data.
62 * Controller data is represented as a list of time-stamped float values. */
63 class Sequence : virtual public ControlSet {
65 Sequence(size_t size=0);
67 bool read_locked() { return _read_iter.locked(); }
72 void read_lock() const;
73 void read_unlock() const;
77 bool percussive() const { return _percussive; }
78 void set_percussive(bool p) { _percussive = p; }
81 bool writing() const { return _writing; }
82 void end_write(bool delete_stuck=false);
84 size_t read(EventSink& dst,
87 timestamp_t stamp_offset) const;
89 /** Resizes vector if necessary (NOT realtime safe) */
90 void append(const Event& ev);
92 inline const boost::shared_ptr<const Note> note_at(unsigned i) const { return _notes[i]; }
93 inline const boost::shared_ptr<Note> note_at(unsigned i) { return _notes[i]; }
95 inline size_t n_notes() const { return _notes.size(); }
96 inline bool empty() const { return _notes.size() == 0 && ControlSet::empty(); }
98 inline static bool note_time_comparator(const boost::shared_ptr<const Note>& a,
99 const boost::shared_ptr<const Note>& b) {
100 return a->time() < b->time();
103 struct LaterNoteEndComparator {
104 typedef const Note* value_type;
105 inline bool operator()(const boost::shared_ptr<const Note> a,
106 const boost::shared_ptr<const Note> b) const {
107 return a->end_time() > b->end_time();
111 typedef std::vector< boost::shared_ptr<Note> > Notes;
112 inline Notes& notes() { return _notes; }
113 inline const Notes& notes() const { return _notes; }
116 class const_iterator {
118 const_iterator(const Sequence& seq, double t);
121 inline bool valid() const { return !_is_end && _event; }
122 inline bool locked() const { return _locked; }
124 const Event& operator*() const { return *_event; }
125 const boost::shared_ptr<Event> operator->() const { return _event; }
126 const boost::shared_ptr<Event> get_event_pointer() { return _event; }
128 const const_iterator& operator++(); // prefix only
129 bool operator==(const const_iterator& other) const;
130 bool operator!=(const const_iterator& other) const { return ! operator==(other); }
132 const_iterator& operator=(const const_iterator& other);
135 friend class Sequence;
137 const Sequence* _seq;
138 boost::shared_ptr<Event> _event;
140 typedef std::priority_queue< boost::shared_ptr<Note>,
141 std::deque< boost::shared_ptr<Note> >,
142 LaterNoteEndComparator >
145 mutable ActiveNotes _active_notes;
149 Notes::const_iterator _note_iter;
150 std::vector<ControlIterator> _control_iters;
151 std::vector<ControlIterator>::iterator _control_iter;
154 const_iterator begin(double t=0) const { return const_iterator(*this, t); }
155 const const_iterator& end() const { return _end_iter; }
157 void read_seek(double t) { _read_iter = begin(t); }
158 double read_time() const { return _read_iter.valid() ? _read_iter->time() : 0.0; }
160 bool control_to_midi_event(boost::shared_ptr<Event>& ev,
161 const ControlIterator& iter) const;
163 bool edited() const { return _edited; }
164 void set_edited(bool yn) { _edited = yn; }
167 bool is_sorted() const;
170 void add_note_unlocked(const boost::shared_ptr<Note> note);
171 void remove_note_unlocked(const boost::shared_ptr<const Note> note);
174 mutable const_iterator _read_iter;
178 friend class const_iterator;
180 void append_note_on_unlocked(uint8_t chan, double time, uint8_t note, uint8_t velocity);
181 void append_note_off_unlocked(uint8_t chan, double time, uint8_t note);
182 void append_control_unlocked(const Parameter& param, double time, double value);
184 mutable Glib::RWLock _lock;
188 typedef std::vector<size_t> WriteNotes;
189 WriteNotes _write_notes[16];
192 typedef std::vector< boost::shared_ptr<const ControlList> > ControlLists;
193 ControlLists _dirty_controls;
195 const const_iterator _end_iter;
196 mutable nframes_t _next_read;
199 /** FIXME: Make fully dynamic, map to URIs */
201 midi_cc_type=0x20, // FIXME FIXME FIXME eeww
207 typedef std::priority_queue<
208 boost::shared_ptr<Note>, std::deque< boost::shared_ptr<Note> >,
209 LaterNoteEndComparator>
214 } // namespace Evoral
216 #endif // EVORAL_SEQUENCE_HPP