73class MidiEventVector final
76 MidiEventVector () { events_.reserve (MAX_MIDI_EVENTS); }
81 using Iterator = std::vector<MidiEvent>::iterator;
82 using ConstIterator = std::vector<MidiEvent>::const_iterator;
87 const std::lock_guard<crill::spin_mutex> lock (lock_);
88 return events_.begin ();
93 const std::lock_guard<crill::spin_mutex> lock (lock_);
94 return events_.end ();
97 void erase (Iterator it, Iterator it_end)
99 const std::lock_guard<crill::spin_mutex> lock (lock_);
100 events_.erase (it, it_end);
103 ConstIterator begin ()
const
105 const std::lock_guard<crill::spin_mutex> lock (lock_);
106 return events_.begin ();
109 ConstIterator end ()
const
111 const std::lock_guard<crill::spin_mutex> lock (lock_);
112 return events_.end ();
117 const std::lock_guard<crill::spin_mutex> lock (lock_);
118 events_.push_back (ev);
121 void push_back (
const std::vector<MidiEvent> &events)
123 const std::lock_guard<crill::spin_mutex> lock (lock_);
124 events_.insert (events_.end (), events.begin (), events.end ());
129 const std::lock_guard<crill::spin_mutex> lock (lock_);
131 events_.erase (events_.begin ());
137 const std::lock_guard<crill::spin_mutex> lock (lock_);
145 const std::lock_guard<crill::spin_mutex> lock (lock_);
151 const std::lock_guard<crill::spin_mutex> lock (lock_);
152 return events_.size ();
157 const std::lock_guard<crill::spin_mutex> lock (lock_);
158 return events_.front ();
163 const std::lock_guard<crill::spin_mutex> lock (lock_);
164 return events_.back ();
169 const std::lock_guard<crill::spin_mutex> lock (lock_);
170 return events_.at (index);
173 void swap (MidiEventVector &other)
175 const std::lock_guard<crill::spin_mutex> lock (lock_);
176 events_.swap (other.events_);
179 void remove_if (std::function<
bool (
const MidiEvent &)> predicate)
181 const std::lock_guard<crill::spin_mutex> lock (lock_);
185 std::remove_if (events_.begin (), events_.end (), std::move (predicate));
186 events_.erase (it, events_.end ());
194 remove_if ([&event] (
const MidiEvent &e) {
return e == event; });
197 template <
typename Func>
void foreach_event (Func &&func)
const
199 const std::lock_guard<crill::spin_mutex> lock (lock_);
200 std::ranges::for_each (events_, std::forward<Func> (func));
203 size_t capacity ()
const
205 const std::lock_guard<crill::spin_mutex> lock (lock_);
206 return events_.capacity ();
209 void reserve (
size_t new_capacity)
211 const std::lock_guard<crill::spin_mutex> lock (lock_);
212 events_.reserve (new_capacity);
225 const MidiEventVector &src,
226 std::optional<std::array<bool, 16>> channels,
227 units::sample_u32_t local_offset,
228 units::sample_u32_t nframes);
237 const MidiEventVector &src,
238 units::sample_u32_t local_offset,
239 units::sample_u32_t nframes);
241 using NotePitchToChordDescriptorFunc =
242 std::function<
const ChordDescriptor *(
midi_byte_t)>;
251 const MidiEventVector &src,
252 NotePitchToChordDescriptorFunc note_number_to_chord_descriptor,
254 units::sample_u32_t local_offset,
255 units::sample_u32_t nframes);
267 units::sample_u32_t time);
273 const ChordDescriptor &descr,
276 units::sample_u32_t time);
282 const ChordDescriptor &descr,
284 units::sample_u32_t time);
294 units::sample_u32_t time);
303 bool has_note_on (
bool check_main,
bool check_queued);
306 bool has_any ()
const {
return !empty (); }
307 bool empty ()
const {
return size () == 0; }
327 units::sample_u32_t time);
338 units::sample_u32_t time);
345 void add_song_pos (int64_t total_sixteenths, units::sample_u32_t time);
347 void add_raw (
const uint8_t * buf,
size_t buf_sz, units::sample_u32_t time);
353 units::sample_u32_t time)
355 push_back (
MidiEvent (byte1, byte2, byte3, time));
367 units::sample_u32_t time);
369 void add_channel_pressure (
372 units::sample_u32_t time);
379 units::sample_u32_t time,
408 juce::MidiMessageSequence &sequence,
409 bool update_matched_pairs)
const;
420 bool check_for_note_on (
int note);
426 bool delete_note_on (
int note);
440 void delete_event (
const MidiEvent * ev);
443 std::vector<MidiEvent> events_;
446 mutable crill::spin_mutex lock_;