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

MIDI: Use Spans instead of pointer pairs in more places

This commit is contained in:
reuk 2025-03-06 16:46:03 +00:00
parent fb4f04e4d1
commit 835216c581
No known key found for this signature in database
7 changed files with 45 additions and 66 deletions

View file

@ -55,12 +55,11 @@ public:
continue from that point in the packet (unless `reset` is called first).
*/
template <typename PacketCallbackFunction>
void dispatch (const uint32_t* begin,
const uint32_t* end,
void dispatch (Span<const uint32_t> words,
double timeStamp,
PacketCallbackFunction&& callback)
{
std::for_each (begin, end, [&] (uint32_t word)
for (const auto word : words)
{
nextPacket[currentPacketLen++] = word;
@ -69,7 +68,7 @@ public:
callback (View (nextPacket.data()), timeStamp);
currentPacketLen = 0;
}
});
}
}
private:
@ -106,14 +105,12 @@ public:
/** Calls `callback` with a View of each converted packet as it becomes ready.
@param begin the first byte in a range of bytes representing bytestream-encoded MIDI messages.
@param end one-past the last byte in a range of bytes representing bytestream-encoded MIDI messages.
@param bytes range of bytes representing bytestream-encoded MIDI messages.
@param timestamp a timestamp to apply to the created packets.
@param callback a callback which will be passed a View pointing to each new packet as it becomes ready.
*/
template <typename PacketCallbackFunction>
void dispatch (const uint8_t* begin,
const uint8_t* end,
void dispatch (Span<const std::byte> bytes,
double timestamp,
PacketCallbackFunction&& callback)
{
@ -139,7 +136,7 @@ public:
};
Callback inputCallback { *this, &callback };
concatenator.pushMidiData (begin, int (end - begin), timestamp, (void*) nullptr, inputCallback);
concatenator.pushMidiData (bytes, timestamp, (void*) nullptr, inputCallback);
}
private:
@ -181,12 +178,11 @@ public:
@param callback a callback which will be passed a MidiMessage each time a new message becomes ready.
*/
template <typename BytestreamMessageCallback>
void dispatch (const uint32_t* begin,
const uint32_t* end,
void dispatch (Span<const uint32_t> words,
double timestamp,
BytestreamMessageCallback&& callback)
{
dispatcher.dispatch (begin, end, timestamp, [&] (const View& view, double time)
dispatcher.dispatch (words, timestamp, [&] (const View& view, double time)
{
converter.convert (view, time, callback);
});

View file

@ -67,12 +67,10 @@ public:
? Utils::MessageKind::commonRealtime
: Utils::MessageKind::channelVoice1));
translator.dispatch (View {packets.data() },
0,
[&] (const BytestreamMidiView& roundTripped)
{
expect (equal (m, roundTripped.getMessage()));
});
translator.dispatch (View { packets.data() }, 0, [&] (const BytestreamMidiView& roundTripped)
{
expect (equal (m, roundTripped.getMessage()));
});
});
}
@ -146,13 +144,10 @@ public:
Conversion::toMidi1 (ump::BytestreamMidiView (meta), [&] (const auto p) { packets.add (p); });
MidiBuffer output;
converter.dispatch (packets.data(),
packets.data() + packets.size(),
0,
[&] (const BytestreamMidiView& roundTripped)
{
output.addEvent (roundTripped.getMessage(), int (roundTripped.timestamp));
});
converter.dispatch (packets, 0, [&] (const BytestreamMidiView& roundTripped)
{
output.addEvent (roundTripped.getMessage(), int (roundTripped.timestamp));
});
packets.clear();
expect (equal (expected, output));
@ -189,13 +184,10 @@ public:
}
MidiBuffer output;
converter.dispatch (modifiedPackets.data(),
modifiedPackets.data() + modifiedPackets.size(),
0,
[&] (const BytestreamMidiView& roundTripped)
{
output.addEvent (roundTripped.getMessage(), int (roundTripped.timestamp));
});
converter.dispatch (modifiedPackets, 0, [&] (const BytestreamMidiView& roundTripped)
{
output.addEvent (roundTripped.getMessage(), int (roundTripped.timestamp));
});
// All Utility messages should have been ignored
expect (output.getNumEvents() == 1);
@ -227,13 +219,10 @@ public:
}
MidiBuffer output;
converter.dispatch (modifiedPackets.data(),
modifiedPackets.data() + modifiedPackets.size(),
0,
[&] (const BytestreamMidiView& roundTripped)
{
output.addEvent (roundTripped.getMessage(), int (roundTripped.timestamp));
});
converter.dispatch (modifiedPackets, 0, [&] (const BytestreamMidiView& roundTripped)
{
output.addEvent (roundTripped.getMessage(), int (roundTripped.timestamp));
});
const auto numOutputs = output.getNumEvents();
const auto numInputs = realtimeMessages.getNumEvents();
@ -294,13 +283,10 @@ public:
}
MidiBuffer output;
converter.dispatch (modifiedPackets.data(),
modifiedPackets.data() + modifiedPackets.size(),
0,
[&] (const BytestreamMidiView& roundTripped)
{
output.addEvent (roundTripped.getMessage(), int (roundTripped.timestamp));
});
converter.dispatch (modifiedPackets, 0, [&] (const BytestreamMidiView& roundTripped)
{
output.addEvent (roundTripped.getMessage(), int (roundTripped.timestamp));
});
const auto numOutputs = output.getNumEvents();
const auto numInputs = realtimeMessages.getNumEvents();
@ -377,13 +363,10 @@ public:
const auto pushToOutput = [&] (const Packets& p)
{
converter.dispatch (p.data(),
p.data() + p.size(),
0,
[&] (const BytestreamMidiView& roundTripped)
{
output.addEvent (roundTripped.getMessage(), int (roundTripped.timestamp));
});
converter.dispatch (p, 0, [&] (const BytestreamMidiView& roundTripped)
{
output.addEvent (roundTripped.getMessage(), int (roundTripped.timestamp));
});
};
pushToOutput (modifiedPackets);