1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-09 23:34:20 +00:00

MIDI: Add span getters for MidiMessage and MidiMessageMetadata

This commit is contained in:
reuk 2025-03-06 16:26:44 +00:00
parent 85191fa50a
commit fb4f04e4d1
No known key found for this signature in database
3 changed files with 16 additions and 4 deletions

View file

@ -60,6 +60,13 @@ struct MidiMessageMetadata
*/
MidiMessage getMessage() const { return MidiMessage (data, numBytes, samplePosition); }
Span<const std::byte> asSpan() const&
{
return { reinterpret_cast<const std::byte*> (data), (size_t) numBytes };
}
Span<const std::byte> asSpan() const&& = delete;
/** Pointer to the first byte of a MIDI message. */
const uint8* data = nullptr;

View file

@ -987,6 +987,13 @@ public:
static uint16 pitchbendToPitchwheelPos (float pitchbendInSemitones,
float pitchbendRangeInSemitones) noexcept;
Span<const std::byte> asSpan() const&
{
return { reinterpret_cast<const std::byte*> (getRawData()), (size_t) getRawDataSize() };
}
Span<const std::byte> asSpan() const&& = delete;
private:
//==============================================================================
/** @cond */

View file

@ -51,13 +51,11 @@ struct BytestreamMidiView
to a temporary.
*/
explicit BytestreamMidiView (const MidiMessage* msg)
: bytes (unalignedPointerCast<const std::byte*> (msg->getRawData()),
static_cast<size_t> (msg->getRawDataSize())),
: bytes (msg->asSpan()),
timestamp (msg->getTimeStamp()) {}
explicit BytestreamMidiView (const MidiMessageMetadata msg)
: bytes (unalignedPointerCast<const std::byte*> (msg.data),
static_cast<size_t> (msg.numBytes)),
: bytes (msg.asSpan()),
timestamp (msg.samplePosition) {}
MidiMessage getMessage() const