Loading...
Searching...
No Matches
juce_UMPBytestreamInputHandler.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 BytestreamInputHandler
{
virtual ~BytestreamInputHandler() noexcept = default;
virtual void reset() = 0;
virtual void pushMidiData (const void* data, int bytes, double time) = 0;
};
struct BytestreamToBytestreamHandler : public BytestreamInputHandler
{
BytestreamToBytestreamHandler (MidiInput& i, MidiInputCallback& c)
: input (i), callback (c), concatenator (2048) {}
class Factory
{
public:
explicit Factory (MidiInputCallback* c)
: callback (c) {}
std::unique_ptr<BytestreamToBytestreamHandler> operator() (MidiInput& i) const
{
if (callback != nullptr)
return std::make_unique<BytestreamToBytestreamHandler> (i, *callback);
jassertfalse;
return {};
}
private:
MidiInputCallback* callback = nullptr;
};
void reset() override { concatenator.reset(); }
void pushMidiData (const void* data, int bytes, double time) override
{
concatenator.pushMidiData (data, bytes, time, &input, callback);
}
MidiInput& input;
MidiInputCallback& callback;
MidiDataConcatenator concatenator;
};
struct BytestreamToUMPHandler : public BytestreamInputHandler
{
BytestreamToUMPHandler (PacketProtocol protocol, Receiver& c)
: recipient (c), dispatcher (protocol, 2048) {}
class Factory
{
public:
Factory (PacketProtocol p, Receiver& c)
: protocol (p), callback (c) {}
std::unique_ptr<BytestreamToUMPHandler> operator() (MidiInput&) const
{
return std::make_unique<BytestreamToUMPHandler> (protocol, callback);
}
private:
PacketProtocol protocol;
Receiver& callback;
};
void reset() override { dispatcher.reset(); }
void pushMidiData (const void* data, int bytes, double time) override
{
const auto* ptr = static_cast<const uint8_t*> (data);
dispatcher.dispatch (ptr, ptr + bytes, time, [&] (const View& v)
{
recipient.packetReceived (v, time);
});
}
Receiver& recipient;
BytestreamToUMPDispatcher dispatcher;
};
} // juce::universal_midi_packets
#endif
juce::MidiDataConcatenator
Definition juce_MidiDataConcatenator.h:34
juce::MidiInputCallback
Definition juce_MidiDevices.h:277
juce::MidiInput
Definition juce_MidiDevices.h:164
juce::universal_midi_packets::BytestreamToUMPDispatcher::dispatch
void dispatch(const uint8_t *begin, const uint8_t *end, double timestamp, PacketCallbackFunction &&callback)
Definition juce_UMPDispatcher.h:104
juce::universal_midi_packets::View
Definition juce_UMPView.h:44
juce::universal_midi_packets::BytestreamInputHandler
Definition juce_UMPBytestreamInputHandler.h:34
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