mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-09 23:34:20 +00:00
MIDI: Switch BytestreamMidiView for BytesOnGroup in a few places
This commit is contained in:
parent
2dd69dd0ad
commit
fa1f8ed54e
10 changed files with 50 additions and 49 deletions
|
|
@ -85,7 +85,7 @@ struct Conversion
|
||||||
`callback` is a function which accepts a single View argument.
|
`callback` is a function which accepts a single View argument.
|
||||||
*/
|
*/
|
||||||
template <typename PacketCallbackFunction>
|
template <typename PacketCallbackFunction>
|
||||||
static void toMidi1 (const BytestreamMidiView& m, PacketCallbackFunction&& callback)
|
static void toMidi1 (const BytesOnGroup& m, PacketCallbackFunction&& callback)
|
||||||
{
|
{
|
||||||
const auto size = m.bytes.size();
|
const auto size = m.bytes.size();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ namespace juce::universal_midi_packets
|
||||||
struct ToUMP1Converter
|
struct ToUMP1Converter
|
||||||
{
|
{
|
||||||
template <typename Fn>
|
template <typename Fn>
|
||||||
void convert (const BytestreamMidiView& m, Fn&& fn)
|
void convert (const BytesOnGroup& m, Fn&& fn)
|
||||||
{
|
{
|
||||||
Conversion::toMidi1 (m, std::forward<Fn> (fn));
|
Conversion::toMidi1 (m, std::forward<Fn> (fn));
|
||||||
}
|
}
|
||||||
|
|
@ -65,7 +65,7 @@ namespace juce::universal_midi_packets
|
||||||
struct ToUMP2Converter
|
struct ToUMP2Converter
|
||||||
{
|
{
|
||||||
template <typename Fn>
|
template <typename Fn>
|
||||||
void convert (const BytestreamMidiView& m, Fn&& fn)
|
void convert (const BytesOnGroup& m, Fn&& fn)
|
||||||
{
|
{
|
||||||
Conversion::toMidi1 (m, [&] (const View& v)
|
Conversion::toMidi1 (m, [&] (const View& v)
|
||||||
{
|
{
|
||||||
|
|
@ -116,7 +116,7 @@ namespace juce::universal_midi_packets
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Converter, typename Fn>
|
template <typename Converter, typename Fn>
|
||||||
static void convertImpl (Converter& converter, const BytestreamMidiView& m, Fn&& fn)
|
static void convertImpl (Converter& converter, const BytesOnGroup& m, Fn&& fn)
|
||||||
{
|
{
|
||||||
converter.convert (m, std::forward<Fn> (fn));
|
converter.convert (m, std::forward<Fn> (fn));
|
||||||
}
|
}
|
||||||
|
|
@ -137,7 +137,7 @@ namespace juce::universal_midi_packets
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Fn>
|
template <typename Fn>
|
||||||
void convert (const BytestreamMidiView& m, Fn&& fn)
|
void convert (const BytesOnGroup& m, Fn&& fn)
|
||||||
{
|
{
|
||||||
visit (*this, m, std::forward<Fn> (fn));
|
visit (*this, m, std::forward<Fn> (fn));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -123,7 +123,7 @@ public:
|
||||||
|
|
||||||
void handleIncomingMidiMessage (void*, const MidiMessage& msg) const
|
void handleIncomingMidiMessage (void*, const MidiMessage& msg) const
|
||||||
{
|
{
|
||||||
Conversion::toMidi1 (BytestreamMidiView (&msg), [&] (const View& view)
|
Conversion::toMidi1 ({ 0, msg.asSpan() }, [&] (const View& view)
|
||||||
{
|
{
|
||||||
dispatch.converter.convert (view, *callbackPtr);
|
dispatch.converter.convert (view, *callbackPtr);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -260,7 +260,7 @@ public:
|
||||||
switch (kind)
|
switch (kind)
|
||||||
{
|
{
|
||||||
case SysexExtractorCallbackKind::notSysex:
|
case SysexExtractorCallbackKind::notSysex:
|
||||||
callback (BytestreamMidiView (bytes, time));
|
callback (BytesOnGroup { 0, bytes }, time);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case SysexExtractorCallbackKind::ongoingSysex:
|
case SysexExtractorCallbackKind::ongoingSysex:
|
||||||
|
|
@ -282,7 +282,7 @@ public:
|
||||||
// If this is not true, then the sysex message was truncated somehow and we
|
// If this is not true, then the sysex message was truncated somehow and we
|
||||||
// probably shouldn't allow it to propagate
|
// probably shouldn't allow it to propagate
|
||||||
if (pendingSysExData.back() == std::byte { 0xf7 })
|
if (pendingSysExData.back() == std::byte { 0xf7 })
|
||||||
callback (BytestreamMidiView (Span<const std::byte> (pendingSysExData), pendingSysExTime));
|
callback (BytesOnGroup { 0, Span<const std::byte> (pendingSysExData) }, pendingSysExTime);
|
||||||
|
|
||||||
pendingSysExData.clear();
|
pendingSysExData.clear();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,14 @@ constexpr uint64_t operator""_u64 (unsigned long long int i) { return static_cas
|
||||||
|
|
||||||
class UniversalMidiPacketTests final : public UnitTest
|
class UniversalMidiPacketTests final : public UnitTest
|
||||||
{
|
{
|
||||||
|
static auto makeMidiMessageAppender (MidiBuffer& b)
|
||||||
|
{
|
||||||
|
return [&b] (const BytesOnGroup& x, double time)
|
||||||
|
{
|
||||||
|
b.addEvent (makeMidiMessage (x, time), (int) time);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
UniversalMidiPacketTests()
|
UniversalMidiPacketTests()
|
||||||
: UnitTest ("Universal MIDI Packet", UnitTestCategories::midi)
|
: UnitTest ("Universal MIDI Packet", UnitTestCategories::midi)
|
||||||
|
|
@ -67,9 +75,9 @@ public:
|
||||||
? Utils::MessageKind::commonRealtime
|
? Utils::MessageKind::commonRealtime
|
||||||
: Utils::MessageKind::channelVoice1));
|
: Utils::MessageKind::channelVoice1));
|
||||||
|
|
||||||
translator.dispatch (View { packets.data() }, 0, [&] (const BytestreamMidiView& roundTripped)
|
translator.dispatch (View { packets.data() }, 0, [&] (const BytesOnGroup& roundTripped, double time)
|
||||||
{
|
{
|
||||||
expect (equal (m, roundTripped.getMessage()));
|
expect (equal (m, makeMidiMessage (roundTripped, time)));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -141,13 +149,10 @@ public:
|
||||||
const auto checkRoundTrip = [&] (const MidiBuffer& expected)
|
const auto checkRoundTrip = [&] (const MidiBuffer& expected)
|
||||||
{
|
{
|
||||||
for (const auto meta : expected)
|
for (const auto meta : expected)
|
||||||
Conversion::toMidi1 (ump::BytestreamMidiView (meta), [&] (const auto p) { packets.add (p); });
|
Conversion::toMidi1 ({ 0, meta.asSpan() }, [&] (const auto p) { packets.add (p); });
|
||||||
|
|
||||||
MidiBuffer output;
|
MidiBuffer output;
|
||||||
converter.dispatch (packets, 0, [&] (const BytestreamMidiView& roundTripped)
|
converter.dispatch (packets, 0, makeMidiMessageAppender (output));
|
||||||
{
|
|
||||||
output.addEvent (roundTripped.getMessage(), int (roundTripped.timestamp));
|
|
||||||
});
|
|
||||||
packets.clear();
|
packets.clear();
|
||||||
|
|
||||||
expect (equal (expected, output));
|
expect (equal (expected, output));
|
||||||
|
|
@ -184,10 +189,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
MidiBuffer output;
|
MidiBuffer output;
|
||||||
converter.dispatch (modifiedPackets, 0, [&] (const BytestreamMidiView& roundTripped)
|
converter.dispatch (modifiedPackets, 0, makeMidiMessageAppender (output));
|
||||||
{
|
|
||||||
output.addEvent (roundTripped.getMessage(), int (roundTripped.timestamp));
|
|
||||||
});
|
|
||||||
|
|
||||||
// All Utility messages should have been ignored
|
// All Utility messages should have been ignored
|
||||||
expect (output.getNumEvents() == 1);
|
expect (output.getNumEvents() == 1);
|
||||||
|
|
@ -219,10 +221,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
MidiBuffer output;
|
MidiBuffer output;
|
||||||
converter.dispatch (modifiedPackets, 0, [&] (const BytestreamMidiView& roundTripped)
|
converter.dispatch (modifiedPackets, 0, makeMidiMessageAppender (output));
|
||||||
{
|
|
||||||
output.addEvent (roundTripped.getMessage(), int (roundTripped.timestamp));
|
|
||||||
});
|
|
||||||
|
|
||||||
const auto numOutputs = output.getNumEvents();
|
const auto numOutputs = output.getNumEvents();
|
||||||
const auto numInputs = realtimeMessages.getNumEvents();
|
const auto numInputs = realtimeMessages.getNumEvents();
|
||||||
|
|
@ -283,10 +282,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
MidiBuffer output;
|
MidiBuffer output;
|
||||||
converter.dispatch (modifiedPackets, 0, [&] (const BytestreamMidiView& roundTripped)
|
converter.dispatch (modifiedPackets, 0, makeMidiMessageAppender (output));
|
||||||
{
|
|
||||||
output.addEvent (roundTripped.getMessage(), int (roundTripped.timestamp));
|
|
||||||
});
|
|
||||||
|
|
||||||
const auto numOutputs = output.getNumEvents();
|
const auto numOutputs = output.getNumEvents();
|
||||||
const auto numInputs = realtimeMessages.getNumEvents();
|
const auto numInputs = realtimeMessages.getNumEvents();
|
||||||
|
|
@ -329,7 +325,7 @@ public:
|
||||||
Packets p;
|
Packets p;
|
||||||
|
|
||||||
for (const auto meta : noteOn)
|
for (const auto meta : noteOn)
|
||||||
Conversion::toMidi1 (ump::BytestreamMidiView (meta), [&] (const auto packet) { p.add (packet); });
|
Conversion::toMidi1 ({ 0, meta.asSpan() }, [&] (const auto packet) { p.add (packet); });
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
}();
|
}();
|
||||||
|
|
@ -363,10 +359,7 @@ public:
|
||||||
|
|
||||||
const auto pushToOutput = [&] (const Packets& p)
|
const auto pushToOutput = [&] (const Packets& p)
|
||||||
{
|
{
|
||||||
converter.dispatch (p, 0, [&] (const BytestreamMidiView& roundTripped)
|
converter.dispatch (p, 0, makeMidiMessageAppender (output));
|
||||||
{
|
|
||||||
output.addEvent (roundTripped.getMessage(), int (roundTripped.timestamp));
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pushToOutput (modifiedPackets);
|
pushToOutput (modifiedPackets);
|
||||||
|
|
@ -866,7 +859,7 @@ private:
|
||||||
static Packets toMidi1 (const MidiMessage& msg)
|
static Packets toMidi1 (const MidiMessage& msg)
|
||||||
{
|
{
|
||||||
Packets packets;
|
Packets packets;
|
||||||
Conversion::toMidi1 (ump::BytestreamMidiView (&msg), [&] (const auto p) { packets.add (p); });
|
Conversion::toMidi1 ({ 0, msg.asSpan() }, [&] (const auto p) { packets.add (p); });
|
||||||
return packets;
|
return packets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -996,6 +989,11 @@ private:
|
||||||
{
|
{
|
||||||
return a.data == b.data;
|
return a.data == b.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static MidiMessage makeMidiMessage (const BytesOnGroup& b, double time)
|
||||||
|
{
|
||||||
|
return { b.bytes.data(), (int) b.bytes.size(), time };
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static UniversalMidiPacketTests universalMidiPacketTests;
|
static UniversalMidiPacketTests universalMidiPacketTests;
|
||||||
|
|
|
||||||
|
|
@ -91,9 +91,9 @@ struct U32ToBytestreamHandler : public U32InputHandler
|
||||||
|
|
||||||
void pushMidiData (Span<const uint32_t> words, double time) override
|
void pushMidiData (Span<const uint32_t> words, double time) override
|
||||||
{
|
{
|
||||||
dispatcher.dispatch (words, time, [this] (const BytestreamMidiView& m)
|
dispatcher.dispatch (words, time, [&] (const BytesOnGroup& roundTripped, double t)
|
||||||
{
|
{
|
||||||
callback.handleIncomingMidiMessage (&input, m.getMessage());
|
callback.handleIncomingMidiMessage (&input, MidiMessage { roundTripped.bytes.data(), (int) roundTripped.bytes.size(), t });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ namespace CoreMidiHelpers
|
||||||
{
|
{
|
||||||
virtual ~SenderBase() noexcept = default;
|
virtual ~SenderBase() noexcept = default;
|
||||||
|
|
||||||
virtual void send (MIDIPortRef port, MIDIEndpointRef endpoint, const ump::BytestreamMidiView& m) = 0;
|
virtual void send (MIDIPortRef port, MIDIEndpointRef endpoint, const ump::BytesOnGroup& m) = 0;
|
||||||
virtual void send (MIDIPortRef port, MIDIEndpointRef endpoint, ump::Iterator b, ump::Iterator e) = 0;
|
virtual void send (MIDIPortRef port, MIDIEndpointRef endpoint, ump::Iterator b, ump::Iterator e) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -85,7 +85,7 @@ namespace CoreMidiHelpers
|
||||||
template <>
|
template <>
|
||||||
struct API_AVAILABLE (macos (11.0), ios (14.0)) Sender<ImplementationStrategy::onlyNew> final : public SenderBase
|
struct API_AVAILABLE (macos (11.0), ios (14.0)) Sender<ImplementationStrategy::onlyNew> final : public SenderBase
|
||||||
{
|
{
|
||||||
void send (MIDIPortRef port, MIDIEndpointRef endpoint, const ump::BytestreamMidiView& m) override
|
void send (MIDIPortRef port, MIDIEndpointRef endpoint, const ump::BytesOnGroup& m) override
|
||||||
{
|
{
|
||||||
newSendImpl (port, endpoint, m);
|
newSendImpl (port, endpoint, m);
|
||||||
}
|
}
|
||||||
|
|
@ -171,7 +171,7 @@ namespace CoreMidiHelpers
|
||||||
template <>
|
template <>
|
||||||
struct Sender<ImplementationStrategy::onlyOld> final : public SenderBase
|
struct Sender<ImplementationStrategy::onlyOld> final : public SenderBase
|
||||||
{
|
{
|
||||||
void send (MIDIPortRef port, MIDIEndpointRef endpoint, const ump::BytestreamMidiView& m) override
|
void send (MIDIPortRef port, MIDIEndpointRef endpoint, const ump::BytesOnGroup& m) override
|
||||||
{
|
{
|
||||||
oldSendImpl (port, endpoint, m);
|
oldSendImpl (port, endpoint, m);
|
||||||
}
|
}
|
||||||
|
|
@ -180,7 +180,7 @@ namespace CoreMidiHelpers
|
||||||
{
|
{
|
||||||
std::for_each (b, e, [&] (const ump::View& v)
|
std::for_each (b, e, [&] (const ump::View& v)
|
||||||
{
|
{
|
||||||
bytestreamConverter.convert (v, 0.0, [&] (const ump::BytestreamMidiView& m)
|
bytestreamConverter.convert (v, 0.0, [&] (const ump::BytesOnGroup& m, double)
|
||||||
{
|
{
|
||||||
send (port, endpoint, m);
|
send (port, endpoint, m);
|
||||||
});
|
});
|
||||||
|
|
@ -190,7 +190,7 @@ namespace CoreMidiHelpers
|
||||||
private:
|
private:
|
||||||
ump::ToBytestreamConverter bytestreamConverter { 2048 };
|
ump::ToBytestreamConverter bytestreamConverter { 2048 };
|
||||||
|
|
||||||
void oldSendImpl (MIDIPortRef port, MIDIEndpointRef endpoint, const ump::BytestreamMidiView& message)
|
void oldSendImpl (MIDIPortRef port, MIDIEndpointRef endpoint, const ump::BytesOnGroup& message)
|
||||||
{
|
{
|
||||||
#if JUCE_IOS
|
#if JUCE_IOS
|
||||||
const MIDITimeStamp timeStamp = mach_absolute_time();
|
const MIDITimeStamp timeStamp = mach_absolute_time();
|
||||||
|
|
@ -203,7 +203,10 @@ namespace CoreMidiHelpers
|
||||||
auto* packetToSend = &stackPacket;
|
auto* packetToSend = &stackPacket;
|
||||||
auto dataSize = message.bytes.size();
|
auto dataSize = message.bytes.size();
|
||||||
|
|
||||||
if (message.isSysEx())
|
const auto bytes = message.bytes;
|
||||||
|
const auto isSysEx = ! bytes.empty() && bytes.front() == std::byte { 0xf0 };
|
||||||
|
|
||||||
|
if (isSysEx)
|
||||||
{
|
{
|
||||||
const int maxPacketSize = 256;
|
const int maxPacketSize = 256;
|
||||||
int pos = 0, bytesLeft = (int) dataSize;
|
int pos = 0, bytesLeft = (int) dataSize;
|
||||||
|
|
@ -262,7 +265,7 @@ namespace CoreMidiHelpers
|
||||||
: sender (makeImpl())
|
: sender (makeImpl())
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void send (MIDIPortRef port, MIDIEndpointRef endpoint, const ump::BytestreamMidiView& m)
|
void send (MIDIPortRef port, MIDIEndpointRef endpoint, const ump::BytesOnGroup& m)
|
||||||
{
|
{
|
||||||
sender->send (port, endpoint, m);
|
sender->send (port, endpoint, m);
|
||||||
}
|
}
|
||||||
|
|
@ -358,7 +361,7 @@ namespace CoreMidiHelpers
|
||||||
endpoint.release();
|
endpoint.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
void send (const ump::BytestreamMidiView& m)
|
void send (const ump::BytesOnGroup& m)
|
||||||
{
|
{
|
||||||
sender.send (*port, *endpoint, m);
|
sender.send (*port, *endpoint, m);
|
||||||
}
|
}
|
||||||
|
|
@ -1266,7 +1269,7 @@ MidiOutput::~MidiOutput()
|
||||||
|
|
||||||
void MidiOutput::sendMessageNow (const MidiMessage& message)
|
void MidiOutput::sendMessageNow (const MidiMessage& message)
|
||||||
{
|
{
|
||||||
internal->send (ump::BytestreamMidiView (&message));
|
internal->send ({ 0, message.asSpan() });
|
||||||
}
|
}
|
||||||
|
|
||||||
MidiDeviceListConnection MidiDeviceListConnection::make (std::function<void()> cb)
|
MidiDeviceListConnection MidiDeviceListConnection::make (std::function<void()> cb)
|
||||||
|
|
|
||||||
|
|
@ -1596,9 +1596,9 @@ public:
|
||||||
toBytestreamDispatcher.dispatch ({ reinterpret_cast<const uint32_t*> (packet->words),
|
toBytestreamDispatcher.dispatch ({ reinterpret_cast<const uint32_t*> (packet->words),
|
||||||
(size_t) packet->wordCount },
|
(size_t) packet->wordCount },
|
||||||
static_cast<double> (packet->timeStamp + inOffsetSampleFrame),
|
static_cast<double> (packet->timeStamp + inOffsetSampleFrame),
|
||||||
[this] (const ump::BytestreamMidiView& message)
|
[this] (const ump::BytesOnGroup& x, double t)
|
||||||
{
|
{
|
||||||
incomingEvents.addEvent (message.getMessage(), (int) message.timestamp);
|
incomingEvents.addEvent ({ x.bytes.data(), (int) x.bytes.size(), t }, (int) t);
|
||||||
});
|
});
|
||||||
|
|
||||||
packet = MIDIEventPacketNext (packet);
|
packet = MIDIEventPacketNext (packet);
|
||||||
|
|
|
||||||
|
|
@ -1489,9 +1489,9 @@ private:
|
||||||
converter.dispatch ({ reinterpret_cast<const uint32_t*> (packet->words),
|
converter.dispatch ({ reinterpret_cast<const uint32_t*> (packet->words),
|
||||||
(size_t) packet->wordCount },
|
(size_t) packet->wordCount },
|
||||||
static_cast<int> (packet->timeStamp - (MIDITimeStamp) startTime),
|
static_cast<int> (packet->timeStamp - (MIDITimeStamp) startTime),
|
||||||
[this] (const ump::BytestreamMidiView& message)
|
[this] (const ump::BytesOnGroup& x, double t)
|
||||||
{
|
{
|
||||||
midiMessages.addEvent (message.getMessage(), (int) message.timestamp);
|
midiMessages.addEvent ({ x.bytes.data(), (int) x.bytes.size(), t }, (int) t);
|
||||||
});
|
});
|
||||||
|
|
||||||
packet = MIDIEventPacketNext (packet);
|
packet = MIDIEventPacketNext (packet);
|
||||||
|
|
|
||||||
|
|
@ -715,7 +715,7 @@ struct AudioUnitHelpers
|
||||||
|
|
||||||
for (const auto metadata : buffer)
|
for (const auto metadata : buffer)
|
||||||
{
|
{
|
||||||
toUmp1Converter.convert (ump::BytestreamMidiView (metadata), [&] (const ump::View& view)
|
toUmp1Converter.convert ({ 0, metadata.asSpan() }, [&] (const ump::View& view)
|
||||||
{
|
{
|
||||||
add (view, metadata.samplePosition);
|
add (view, metadata.samplePosition);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue