1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +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); } 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. */ /** Pointer to the first byte of a MIDI message. */
const uint8* data = nullptr; const uint8* data = nullptr;

View file

@ -987,6 +987,13 @@ public:
static uint16 pitchbendToPitchwheelPos (float pitchbendInSemitones, static uint16 pitchbendToPitchwheelPos (float pitchbendInSemitones,
float pitchbendRangeInSemitones) noexcept; 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: private:
//============================================================================== //==============================================================================
/** @cond */ /** @cond */

View file

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