OpenShot Audio Library | OpenShotAudio 0.4.0
 
Loading...
Searching...
No Matches
juce_UMPConverters.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{
34 {
35 template <typename Fn>
36 void convert (const BytestreamMidiView& m, Fn&& fn)
37 {
38 Conversion::toMidi1 (m, std::forward<Fn> (fn));
39 }
40
41 template <typename Fn>
42 void convert (const View& v, Fn&& fn)
43 {
44 Conversion::midi2ToMidi1DefaultTranslation (v, std::forward<Fn> (fn));
45 }
46 };
47
55 {
56 template <typename Fn>
57 void convert (const BytestreamMidiView& m, Fn&& fn)
58 {
59 Conversion::toMidi1 (m, [&] (const View& v)
60 {
61 translator.dispatch (v, fn);
62 });
63 }
64
65 template <typename Fn>
66 void convert (const View& v, Fn&& fn)
67 {
68 translator.dispatch (v, std::forward<Fn> (fn));
69 }
70
71 void reset()
72 {
73 translator.reset();
74 }
75
77 };
78
87 class GenericUMPConverter
88 {
89 template <typename This, typename... Args>
90 static void visit (This& t, Args&&... args)
91 {
92 if (t.mode == PacketProtocol::MIDI_1_0)
93 convertImpl (std::get<0> (t.converters), std::forward<Args> (args)...);
94 else
95 convertImpl (std::get<1> (t.converters), std::forward<Args> (args)...);
96 }
97
98 public:
99 explicit GenericUMPConverter (PacketProtocol m)
100 : mode (m) {}
101
102 void reset()
103 {
104 std::get<1> (converters).reset();
105 }
106
107 template <typename Converter, typename Fn>
108 static void convertImpl (Converter& converter, const BytestreamMidiView& m, Fn&& fn)
109 {
110 converter.convert (m, std::forward<Fn> (fn));
111 }
112
113 template <typename Converter, typename Fn>
114 static void convertImpl (Converter& converter, const View& m, Fn&& fn)
115 {
116 converter.convert (m, std::forward<Fn> (fn));
117 }
118
119 template <typename Converter, typename Fn>
120 static void convertImpl (Converter& converter, Iterator b, Iterator e, Fn&& fn)
121 {
122 std::for_each (b, e, [&] (const auto& v)
123 {
124 convertImpl (converter, v, fn);
125 });
126 }
127
128 template <typename Fn>
129 void convert (const BytestreamMidiView& m, Fn&& fn)
130 {
131 visit (*this, m, std::forward<Fn> (fn));
132 }
133
134 template <typename Fn>
135 void convert (const View& v, Fn&& fn)
136 {
137 visit (*this, v, std::forward<Fn> (fn));
138 }
139
140 template <typename Fn>
141 void convert (Iterator begin, Iterator end, Fn&& fn)
142 {
143 visit (*this, begin, end, std::forward<Fn> (fn));
144 }
145
146 PacketProtocol getProtocol() const noexcept { return mode; }
147
148 private:
149 std::tuple<ToUMP1Converter, ToUMP2Converter> converters;
150 const PacketProtocol mode{};
151 };
152
159 struct ToBytestreamConverter
160 {
161 explicit ToBytestreamConverter (int storageSize)
162 : translator (storageSize) {}
163
164 template <typename Fn>
165 void convert (const MidiMessage& m, Fn&& fn)
166 {
167 fn (m);
168 }
169
170 template <typename Fn>
171 void convert (const View& v, double time, Fn&& fn)
172 {
174 {
175 translator.dispatch (midi1, time, fn);
176 });
177 }
178
179 void reset() { translator.reset(); }
180
182 };
183} // namespace juce::universal_midi_packets
184
185#endif
static void midi2ToMidi1DefaultTranslation(const View &v, Callback &&callback)
static void toMidi1(const BytestreamMidiView &m, PacketCallbackFunction &&callback)