OpenShot Audio Library | OpenShotAudio 0.4.0
 
Loading...
Searching...
No Matches
juce_UMPU32InputHandler.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
35{
36 virtual ~U32InputHandler() noexcept = default;
37
38 virtual void reset() = 0;
39 virtual void pushMidiData (const uint32_t* begin, const uint32_t* end, double time) = 0;
40};
41
48struct U32ToBytestreamHandler : public U32InputHandler
49{
50 U32ToBytestreamHandler (MidiInput& i, MidiInputCallback& c)
51 : input (i), callback (c), dispatcher (2048) {}
52
60 class Factory
61 {
62 public:
63 explicit Factory (MidiInputCallback* c)
64 : callback (c) {}
65
66 std::unique_ptr<U32ToBytestreamHandler> operator() (MidiInput& i) const
67 {
68 if (callback != nullptr)
69 return std::make_unique<U32ToBytestreamHandler> (i, *callback);
70
71 jassertfalse;
72 return {};
73 }
74
75 private:
76 MidiInputCallback* callback = nullptr;
77 };
78
79 void reset() override { dispatcher.reset(); }
80
81 void pushMidiData (const uint32_t* begin, const uint32_t* end, double time) override
82 {
83 dispatcher.dispatch (begin, end, time, [this] (const BytestreamMidiView& m)
84 {
85 callback.handleIncomingMidiMessage (&input, m.getMessage());
86 });
87 }
88
89 MidiInput& input;
90 MidiInputCallback& callback;
91 ToBytestreamDispatcher dispatcher;
92};
93
100struct U32ToUMPHandler : public U32InputHandler
101{
102 U32ToUMPHandler (PacketProtocol protocol, Receiver& c)
103 : recipient (c), converter (protocol) {}
104
112 class Factory
113 {
114 public:
115 Factory (PacketProtocol p, Receiver& c)
116 : protocol (p), callback (c) {}
117
118 std::unique_ptr<U32ToUMPHandler> operator() (MidiInput&) const
119 {
120 return std::make_unique<U32ToUMPHandler> (protocol, callback);
121 }
122
123 private:
124 PacketProtocol protocol;
125 Receiver& callback;
126 };
127
128 void reset() override
129 {
130 dispatcher.reset();
131 converter.reset();
132 }
133
134 void pushMidiData (const uint32_t* begin, const uint32_t* end, double time) override
135 {
136 dispatcher.dispatch (begin, end, time, [this] (const View& view, double thisTime)
137 {
138 converter.convert (view, [&] (const View& converted)
139 {
140 recipient.packetReceived (converted, thisTime);
141 });
142 });
143 }
144
145 Receiver& recipient;
146 Dispatcher dispatcher;
147 GenericUMPConverter converter;
148};
149
150} // namespace juce::universal_midi_packets
151
152
153#endif
virtual void handleIncomingMidiMessage(MidiInput *source, const MidiMessage &message)=0
void dispatch(const uint32_t *begin, const uint32_t *end, double timeStamp, PacketCallbackFunction &&callback)
void dispatch(const uint32_t *begin, const uint32_t *end, double timestamp, BytestreamMessageCallback &&callback)
virtual void packetReceived(const View &packet, double time)=0