Loading...
Searching...
No Matches
juce_MidiBuffer.h
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2022 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
The code included in this file is provided under the terms of the ISC license
http://www.isc.org/downloads/software-support-policy/isc-license. Permission
To use, copy, modify, and/or distribute this software for any purpose with or
without fee is hereby granted provided that the above copyright notice and
this permission notice appear in all copies.
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
//==============================================================================
struct MidiMessageMetadata
{
MidiMessageMetadata() noexcept = default;
MidiMessageMetadata (const uint8* dataIn, int numBytesIn, int positionIn) noexcept
: data (dataIn), numBytes (numBytesIn), samplePosition (positionIn)
{
}
MidiMessage getMessage() const { return MidiMessage (data, numBytes, samplePosition); }
const uint8* data = nullptr;
int numBytes = 0;
int samplePosition = 0;
};
//==============================================================================
class JUCE_API MidiBufferIterator
{
using Ptr = const uint8*;
public:
MidiBufferIterator() = default;
explicit MidiBufferIterator (const uint8* dataIn) noexcept
: data (dataIn)
{
}
using difference_type = std::iterator_traits<Ptr>::difference_type;
using value_type = MidiMessageMetadata;
using reference = MidiMessageMetadata;
using pointer = void;
using iterator_category = std::input_iterator_tag;
MidiBufferIterator& operator++() noexcept;
MidiBufferIterator operator++ (int) noexcept;
bool operator== (const MidiBufferIterator& other) const noexcept { return data == other.data; }
bool operator!= (const MidiBufferIterator& other) const noexcept { return ! operator== (other); }
reference operator*() const noexcept;
private:
Ptr data = nullptr;
};
//==============================================================================
class JUCE_API MidiBuffer
{
public:
//==============================================================================
MidiBuffer() noexcept = default;
explicit MidiBuffer (const MidiMessage& message) noexcept;
//==============================================================================
void clear() noexcept;
void clear (int start, int numSamples);
bool isEmpty() const noexcept;
int getNumEvents() const noexcept;
bool addEvent (const MidiMessage& midiMessage, int sampleNumber);
bool addEvent (const void* rawMidiData,
int maxBytesOfMidiData,
int sampleNumber);
void addEvents (const MidiBuffer& otherBuffer,
int startSample,
int numSamples,
int sampleDeltaToAdd);
int getFirstEventTime() const noexcept;
int getLastEventTime() const noexcept;
//==============================================================================
void swapWith (MidiBuffer&) noexcept;
void ensureSize (size_t minimumNumBytes);
MidiBufferIterator begin() const noexcept { return cbegin(); }
MidiBufferIterator end() const noexcept { return cend(); }
MidiBufferIterator cbegin() const noexcept { return MidiBufferIterator (data.begin()); }
MidiBufferIterator cend() const noexcept { return MidiBufferIterator (data.end()); }
MidiBufferIterator findNextSamplePosition (int samplePosition) const noexcept;
//==============================================================================
#ifndef DOXYGEN
class [[deprecated]] JUCE_API Iterator
{
public:
//==============================================================================
Iterator (const MidiBuffer& b) noexcept;
//==============================================================================
void setNextSamplePosition (int samplePosition) noexcept;
bool getNextEvent (MidiMessage& result,
int& samplePosition) noexcept;
bool getNextEvent (const uint8* &midiData,
int& numBytesOfMidiData,
int& samplePosition) noexcept;
private:
//==============================================================================
const MidiBuffer& buffer;
MidiBufferIterator iterator;
};
#endif
Array<uint8> data;
private:
JUCE_LEAK_DETECTOR (MidiBuffer)
};
} // 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::Iterator
Iterator(const MidiBuffer &b) noexcept
Definition juce_MidiBuffer.cpp:215
juce::MidiBuffer::Iterator::setNextSamplePosition
void setNextSamplePosition(int samplePosition) noexcept
Definition juce_MidiBuffer.cpp:220
juce::MidiBuffer::Iterator::getNextEvent
bool getNextEvent(MidiMessage &result, int &samplePosition) noexcept
Definition juce_MidiBuffer.cpp:237
juce::MidiBuffer::getFirstEventTime
int getFirstEventTime() const noexcept
Definition juce_MidiBuffer.cpp:180
juce::MidiBuffer::getLastEventTime
int getLastEventTime() const noexcept
Definition juce_MidiBuffer.cpp:185
juce::MidiBuffer::ensureSize
void ensureSize(size_t minimumNumBytes)
Definition juce_MidiBuffer.cpp:111
juce::MidiBuffer::getNumEvents
int getNumEvents() const noexcept
Definition juce_MidiBuffer.cpp:169
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::isEmpty
bool isEmpty() const noexcept
Definition juce_MidiBuffer.cpp:112
juce::MidiBuffer::swapWith
void swapWith(MidiBuffer &) noexcept
Definition juce_MidiBuffer.cpp:109
juce::MidiBuffer::addEvent
bool addEvent(const MidiMessage &midiMessage, int sampleNumber)
Definition juce_MidiBuffer.cpp:122
juce::MidiBuffer::MidiBuffer
MidiBuffer() noexcept=default
juce::MidiBuffer::clear
void clear() noexcept
Definition juce_MidiBuffer.cpp:110
juce::MidiBuffer::addEvents
void addEvents(const MidiBuffer &otherBuffer, int startSample, int numSamples, int sampleDeltaToAdd)
Definition juce_MidiBuffer.cpp:155
juce::MidiBuffer::data
Array< uint8 > data
Definition juce_MidiBuffer.h:339
juce::MidiBuffer::begin
MidiBufferIterator begin() const noexcept
Definition juce_MidiBuffer.h:259
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