OpenShot Audio Library | OpenShotAudio: juce_UMPDispatcher.h Source File

OpenShot Audio Library | OpenShotAudio 0.6.0

Loading...
Searching...
No Matches
juce_UMPDispatcher.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
34 class Dispatcher
35{
36public:
38 void reset() { currentPacketLen = 0; }
39
46 template <typename PacketCallbackFunction>
47 void dispatch (const uint32_t* begin,
48 const uint32_t* end,
49 double timeStamp,
50 PacketCallbackFunction&& callback)
51 {
52 std::for_each (begin, end, [&] (uint32_t word)
53 {
54 nextPacket[currentPacketLen++] = word;
55
56 if (currentPacketLen == Utils::getNumWordsForMessageType (nextPacket.front()))
57 {
58 callback (View (nextPacket.data()), timeStamp);
59 currentPacketLen = 0;
60 }
61 });
62 }
63
64private:
65 std::array<uint32_t, 4> nextPacket;
66 size_t currentPacketLen = 0;
67};
68
69//==============================================================================
77 class BytestreamToUMPDispatcher
78{
79public:
85 explicit BytestreamToUMPDispatcher (PacketProtocol pp, int storageSize)
86 : concatenator (storageSize),
87 converter (pp)
88 {}
89
90 void reset()
91 {
92 concatenator.reset();
93 converter.reset();
94 }
95
103 template <typename PacketCallbackFunction>
104 void dispatch (const uint8_t* begin,
105 const uint8_t* end,
106 double timestamp,
107 PacketCallbackFunction&& callback)
108 {
109 using CallbackPtr = decltype (std::addressof (callback));
110
111 #if JUCE_MINGW
112 #define JUCE_MINGW_HIDDEN_VISIBILITY __attribute__ ((visibility ("hidden")))
113 #else
114 #define JUCE_MINGW_HIDDEN_VISIBILITY
115 #endif
116
117 struct JUCE_MINGW_HIDDEN_VISIBILITY Callback
118 {
119 Callback (BytestreamToUMPDispatcher& d, CallbackPtr c)
120 : dispatch (d), callbackPtr (c) {}
121
122 void handleIncomingMidiMessage (void*, const MidiMessage& msg) const
123 {
124 Conversion::toMidi1 (BytestreamMidiView (&msg), [&] (const View& view)
125 {
126 dispatch.converter.convert (view, *callbackPtr);
127 });
128 }
129
130 void handlePartialSysexMessage (void*, const uint8_t*, int, double) const {}
131
132 BytestreamToUMPDispatcher& dispatch;
133 CallbackPtr callbackPtr = nullptr;
134 };
135
136 #undef JUCE_MINGW_HIDDEN_VISIBILITY
137
138 Callback inputCallback { *this, &callback };
139 concatenator.pushMidiData (begin, int (end - begin), timestamp, (void*) nullptr, inputCallback);
140 }
141
142private:
143 MidiDataConcatenator concatenator;
144 GenericUMPConverter converter;
145};
146
147//==============================================================================
155 class ToBytestreamDispatcher
156{
157public:
162 explicit ToBytestreamDispatcher (int storageSize)
163 : converter (storageSize) {}
164
166 void reset()
167 {
168 dispatcher.reset();
169 converter.reset();
170 }
171
180 template <typename BytestreamMessageCallback>
181 void dispatch (const uint32_t* begin,
182 const uint32_t* end,
183 double timestamp,
184 BytestreamMessageCallback&& callback)
185 {
186 dispatcher.dispatch (begin, end, timestamp, [&] (const View& view, double time)
187 {
188 converter.convert (view, time, callback);
189 });
190 }
191
192private:
193 Dispatcher dispatcher;
194 ToBytestreamConverter converter;
195};
196
197} // namespace juce::universal_midi_packets
198
199#endif
juce::MidiDataConcatenator
Definition juce_MidiDataConcatenator.h:34
juce::MidiMessage
Definition juce_MidiMessage.h:35
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::BytestreamToUMPDispatcher::BytestreamToUMPDispatcher
BytestreamToUMPDispatcher(PacketProtocol pp, int storageSize)
Definition juce_UMPDispatcher.h:85
juce::universal_midi_packets::Dispatcher
Definition juce_UMPDispatcher.h:35
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::Dispatcher::reset
void reset()
Definition juce_UMPDispatcher.h:38
juce::universal_midi_packets::GenericUMPConverter
Definition juce_UMPConverters.h:88
juce::universal_midi_packets::ToBytestreamDispatcher::ToBytestreamDispatcher
ToBytestreamDispatcher(int storageSize)
Definition juce_UMPDispatcher.h:162
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::ToBytestreamDispatcher::reset
void reset()
Definition juce_UMPDispatcher.h:166
juce::universal_midi_packets::View
Definition juce_UMPView.h:44
juce::universal_midi_packets::BytestreamMidiView
Definition juce_UMPConversion.h:33
juce::universal_midi_packets::Conversion::toMidi1
static void toMidi1(const BytestreamMidiView &m, PacketCallbackFunction &&callback)
Definition juce_UMPConversion.h:79
juce::universal_midi_packets::ToBytestreamConverter
Definition juce_UMPConverters.h:160
juce::universal_midi_packets::Utils::getNumWordsForMessageType
static uint32_t getNumWordsForMessageType(uint32_t)
Definition juce_UMPUtils.cpp:26