OpenShot Audio Library | OpenShotAudio  0.6.0
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 
23 namespace juce
24 {
25 
26 //==============================================================================
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 
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 
82 public:
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 
124 private:
125  Ptr data = nullptr;
126 };
127 
128 //==============================================================================
144 class JUCE_API MidiBuffer
145 {
146 public:
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 
340 
341 private:
342  JUCE_LEAK_DETECTOR (MidiBuffer)
343 };
344 
345 } // namespace juce
MidiBufferIterator(const uint8 *dataIn) noexcept
MidiBufferIterator cbegin() const noexcept
MidiBufferIterator cend() const noexcept
MidiBuffer() noexcept=default
Array< uint8 > data
MidiBufferIterator end() const noexcept
MidiMessage getMessage() const