Loading...
Searching...
No Matches
juce_UMPU32InputHandler.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.
==============================================================================
*/
#ifndef DOXYGEN
namespace juce::universal_midi_packets
{
struct U32InputHandler
{
virtual ~U32InputHandler() noexcept = default;
virtual void reset() = 0;
virtual void pushMidiData (const uint32_t* begin, const uint32_t* end, double time) = 0;
};
struct U32ToBytestreamHandler : public U32InputHandler
{
U32ToBytestreamHandler (MidiInput& i, MidiInputCallback& c)
: input (i), callback (c), dispatcher (2048) {}
class Factory
{
public:
explicit Factory (MidiInputCallback* c)
: callback (c) {}
std::unique_ptr<U32ToBytestreamHandler> operator() (MidiInput& i) const
{
if (callback != nullptr)
return std::make_unique<U32ToBytestreamHandler> (i, *callback);
jassertfalse;
return {};
}
private:
MidiInputCallback* callback = nullptr;
};
void reset() override { dispatcher.reset(); }
void pushMidiData (const uint32_t* begin, const uint32_t* end, double time) override
{
dispatcher.dispatch (begin, end, time, [this] (const BytestreamMidiView& m)
{
callback.handleIncomingMidiMessage (&input, m.getMessage());
});
}
MidiInput& input;
MidiInputCallback& callback;
ToBytestreamDispatcher dispatcher;
};
struct U32ToUMPHandler : public U32InputHandler
{
U32ToUMPHandler (PacketProtocol protocol, Receiver& c)
: recipient (c), converter (protocol) {}
class Factory
{
public:
Factory (PacketProtocol p, Receiver& c)
: protocol (p), callback (c) {}
std::unique_ptr<U32ToUMPHandler> operator() (MidiInput&) const
{
return std::make_unique<U32ToUMPHandler> (protocol, callback);
}
private:
PacketProtocol protocol;
Receiver& callback;
};
void reset() override
{
dispatcher.reset();
converter.reset();
}
void pushMidiData (const uint32_t* begin, const uint32_t* end, double time) override
{
dispatcher.dispatch (begin, end, time, [this] (const View& view, double thisTime)
{
converter.convert (view, [&] (const View& converted)
{
recipient.packetReceived (converted, thisTime);
});
});
}
Receiver& recipient;
Dispatcher dispatcher;
GenericUMPConverter converter;
};
} // namespace juce::universal_midi_packets
#endif
juce::MidiInputCallback
Definition juce_MidiDevices.h:277
juce::MidiInputCallback::handleIncomingMidiMessage
virtual void handleIncomingMidiMessage(MidiInput *source, const MidiMessage &message)=0
juce::MidiInput
Definition juce_MidiDevices.h:164
juce::universal_midi_packets::Dispatcher::dispatch
void dispatch(const uint32_t *begin, const uint32_t *end, double timeStamp, PacketCallbackFunction &&callback)
Definition juce_UMPDispatcher.h:47
juce::universal_midi_packets::ToBytestreamDispatcher::dispatch
void dispatch(const uint32_t *begin, const uint32_t *end, double timestamp, BytestreamMessageCallback &&callback)
Definition juce_UMPDispatcher.h:181
juce::universal_midi_packets::View
Definition juce_UMPView.h:44
juce::universal_midi_packets::BytestreamMidiView
Definition juce_UMPConversion.h:33
juce::universal_midi_packets::Receiver
Definition juce_UMPReceiver.h:34
juce::universal_midi_packets::Receiver::packetReceived
virtual void packetReceived(const View &packet, double time)=0
juce::universal_midi_packets::U32InputHandler
Definition juce_UMPU32InputHandler.h:35