OpenShot Audio Library | OpenShotAudio: juce_MidiBuffer.h Source File

OpenShot Audio Library | OpenShotAudio 0.4.0

Loading...
Searching...
No Matches
juce_MidiBuffer.h
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 The code included in this file is provided under the terms of the ISC license
11 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12 To use, copy, modify, and/or distribute this software for any purpose with or
13 without fee is hereby granted provided that the above copyright notice and
14 this permission notice appear in all copies.
15
16 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18 DISCLAIMED.
19
20 ==============================================================================
21*/
22
23namespace juce
24{
25
26//==============================================================================
36 struct MidiMessageMetadata
37{
38 MidiMessageMetadata() noexcept = default;
39
40 MidiMessageMetadata (const uint8* dataIn, int numBytesIn, int positionIn) noexcept
41 : data (dataIn), numBytes (numBytesIn), samplePosition (positionIn)
42 {
43 }
44
49 MidiMessage getMessage() const { return MidiMessage (data, numBytes, samplePosition); }
50
52 const uint8* data = nullptr;
53
55 int numBytes = 0;
56
58 int samplePosition = 0;
59};
60
61//==============================================================================
78 class JUCE_API MidiBufferIterator
79{
80 using Ptr = const uint8*;
81
82public:
83 MidiBufferIterator() = default;
84
90 explicit MidiBufferIterator (const uint8* dataIn) noexcept
91 : data (dataIn)
92 {
93 }
94
95 using difference_type = std::iterator_traits<Ptr>::difference_type;
96 using value_type = MidiMessageMetadata;
97 using reference = MidiMessageMetadata;
98 using pointer = void;
99 using iterator_category = std::input_iterator_tag;
100
102 MidiBufferIterator& operator++() noexcept;
103
107 MidiBufferIterator operator++ (int) noexcept;
108
112 bool operator== (const MidiBufferIterator& other) const noexcept { return data == other.data; }
113
117 bool operator!= (const MidiBufferIterator& other) const noexcept { return ! operator== (other); }
118
122 reference operator*() const noexcept;
123
124private:
125 Ptr data = nullptr;
126};
127
128//==============================================================================
144class JUCE_API MidiBuffer
145{
146public:
147 //==============================================================================
149 MidiBuffer() noexcept = default;
150
152 explicit MidiBuffer (const MidiMessage& message) noexcept;
153
154 //==============================================================================
156 void clear() noexcept;
157
163 void clear (int start, int numSamples);
164
168 bool isEmpty() const noexcept;
169
176 int getNumEvents() const noexcept;
177
191 bool addEvent (const MidiMessage& midiMessage, int sampleNumber);
192
211 bool addEvent (const void* rawMidiData,
212 int maxBytesOfMidiData,
213 int sampleNumber);
214
229 void addEvents (const MidiBuffer& otherBuffer,
230 int startSample,
231 int numSamples,
232 int sampleDeltaToAdd);
233
237 int getFirstEventTime() const noexcept;
238
242 int getLastEventTime() const noexcept;
243
244 //==============================================================================
250 void swapWith (MidiBuffer&) noexcept;
251
256 void ensureSize (size_t minimumNumBytes);
257
259 MidiBufferIterator begin() const noexcept { return cbegin(); }
260
262 MidiBufferIterator end() const noexcept { return cend(); }
263
265 MidiBufferIterator cbegin() const noexcept { return MidiBufferIterator (data.begin()); }
266
268 MidiBufferIterator cend() const noexcept { return MidiBufferIterator (data.end()); }
269
273 MidiBufferIterator findNextSamplePosition (int samplePosition) const noexcept;
274
275 //==============================================================================
276 #ifndef DOXYGEN
286 class [[deprecated]] JUCE_API Iterator
287 {
288 public:
289 //==============================================================================
291 Iterator (const MidiBuffer& b) noexcept;
292
293 //==============================================================================
297 void setNextSamplePosition (int samplePosition) noexcept;
298
308 bool getNextEvent (MidiMessage& result,
309 int& samplePosition) noexcept;
310
324 bool getNextEvent (const uint8* &midiData,
325 int& numBytesOfMidiData,
326 int& samplePosition) noexcept;
327
328 private:
329 //==============================================================================
330 const MidiBuffer& buffer;
331 MidiBufferIterator iterator;
332 };
333 #endif
334
339 Array<uint8> data;
340
341private:
342 JUCE_LEAK_DETECTOR (MidiBuffer)
343};
344
345} // namespace juce
juce::Array
Definition juce_Array.h:56
juce::MidiBufferIterator
Definition juce_MidiBuffer.h:79
juce::MidiBufferIterator::MidiBufferIterator
MidiBufferIterator(const uint8 *dataIn) noexcept
Definition juce_MidiBuffer.h:90
juce::MidiBuffer::Iterator
Definition juce_MidiBuffer.h:287
juce::MidiBuffer
Definition juce_MidiBuffer.h:145
juce::MidiBuffer::cbegin
MidiBufferIterator cbegin() const noexcept
Definition juce_MidiBuffer.h:265
juce::MidiBuffer::cend
MidiBufferIterator cend() const noexcept
Definition juce_MidiBuffer.h:268
juce::MidiBuffer::MidiBuffer
MidiBuffer() noexcept=default
juce::MidiBuffer::data
Array< uint8 > data
Definition juce_MidiBuffer.h:339
juce::MidiBuffer::end
MidiBufferIterator end() const noexcept
Definition juce_MidiBuffer.h:262
juce::MidiMessage
Definition juce_MidiMessage.h:35
juce::MidiMessageMetadata
Definition juce_MidiBuffer.h:37
juce::MidiMessageMetadata::data
const uint8 * data
Definition juce_MidiBuffer.h:52
juce::MidiMessageMetadata::samplePosition
int samplePosition
Definition juce_MidiBuffer.h:58
juce::MidiMessageMetadata::numBytes
int numBytes
Definition juce_MidiBuffer.h:55
juce::MidiMessageMetadata::getMessage
MidiMessage getMessage() const
Definition juce_MidiBuffer.h:49