OpenShot Audio Library | OpenShotAudio: juce_UMPBytestreamInputHandler.h Source File

OpenShot Audio Library | OpenShotAudio 0.4.0

Loading...
Searching...
No Matches
juce_UMPBytestreamInputHandler.h
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 The code included in this file is provided under the terms of the ISC license
11 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12 To use, copy, modify, and/or distribute this software for any purpose with or
13 without fee is hereby granted provided that the above copyright notice and
14 this permission notice appear in all copies.
15
16 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18 DISCLAIMED.
19
20 ==============================================================================
21*/
22
23#ifndef DOXYGEN
24
25namespace juce::universal_midi_packets
26{
27
33 struct BytestreamInputHandler
34{
35 virtual ~BytestreamInputHandler() noexcept = default;
36
37 virtual void reset() = 0;
38 virtual void pushMidiData (const void* data, int bytes, double time) = 0;
39};
40
47 struct BytestreamToBytestreamHandler : public BytestreamInputHandler
48{
49 BytestreamToBytestreamHandler (MidiInput& i, MidiInputCallback& c)
50 : input (i), callback (c), concatenator (2048) {}
51
59 class Factory
60 {
61 public:
62 explicit Factory (MidiInputCallback* c)
63 : callback (c) {}
64
65 std::unique_ptr<BytestreamToBytestreamHandler> operator() (MidiInput& i) const
66 {
67 if (callback != nullptr)
68 return std::make_unique<BytestreamToBytestreamHandler> (i, *callback);
69
70 jassertfalse;
71 return {};
72 }
73
74 private:
75 MidiInputCallback* callback = nullptr;
76 };
77
78 void reset() override { concatenator.reset(); }
79
80 void pushMidiData (const void* data, int bytes, double time) override
81 {
82 concatenator.pushMidiData (data, bytes, time, &input, callback);
83 }
84
85 MidiInput& input;
86 MidiInputCallback& callback;
87 MidiDataConcatenator concatenator;
88};
89
96 struct BytestreamToUMPHandler : public BytestreamInputHandler
97{
98 BytestreamToUMPHandler (PacketProtocol protocol, Receiver& c)
99 : recipient (c), dispatcher (protocol, 2048) {}
100
108 class Factory
109 {
110 public:
111 Factory (PacketProtocol p, Receiver& c)
112 : protocol (p), callback (c) {}
113
114 std::unique_ptr<BytestreamToUMPHandler> operator() (MidiInput&) const
115 {
116 return std::make_unique<BytestreamToUMPHandler> (protocol, callback);
117 }
118
119 private:
120 PacketProtocol protocol;
121 Receiver& callback;
122 };
123
124 void reset() override { dispatcher.reset(); }
125
126 void pushMidiData (const void* data, int bytes, double time) override
127 {
128 const auto* ptr = static_cast<const uint8_t*> (data);
129 dispatcher.dispatch (ptr, ptr + bytes, time, [&] (const View& v)
130 {
131 recipient.packetReceived (v, time);
132 });
133 }
134
135 Receiver& recipient;
136 BytestreamToUMPDispatcher dispatcher;
137};
138
139} // juce::universal_midi_packets
140
141#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::BytestreamToBytestreamHandler::Factory
Definition juce_UMPBytestreamInputHandler.h:60
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::BytestreamToUMPHandler::Factory
Definition juce_UMPBytestreamInputHandler.h:109
juce::universal_midi_packets::View
Definition juce_UMPView.h:44
juce::universal_midi_packets::BytestreamInputHandler
Definition juce_UMPBytestreamInputHandler.h:34
juce::universal_midi_packets::BytestreamToBytestreamHandler
Definition juce_UMPBytestreamInputHandler.h:48
juce::universal_midi_packets::BytestreamToUMPHandler
Definition juce_UMPBytestreamInputHandler.h:97
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