25namespace juce::universal_midi_packets
35 template <
typename Fn>
41 template <
typename Fn>
42 void convert (
const View& v, Fn&& fn)
56 template <
typename Fn>
65 template <
typename Fn>
66 void convert (
const View& v, Fn&& fn)
68 translator.
dispatch (v, std::forward<Fn> (fn));
89 template <
typename This,
typename... Args>
90 static void visit (This& t, Args&&... args)
92 if (t.mode == PacketProtocol::MIDI_1_0)
93 convertImpl (std::get<0> (t.converters), std::forward<Args> (args)...);
95 convertImpl (std::get<1> (t.converters), std::forward<Args> (args)...);
104 std::get<1> (converters).reset();
107 template <
typename Converter,
typename Fn>
110 converter.convert (m, std::forward<Fn> (fn));
113 template <
typename Converter,
typename Fn>
114 static void convertImpl (Converter& converter,
const View& m, Fn&& fn)
116 converter.convert (m, std::forward<Fn> (fn));
119 template <
typename Converter,
typename Fn>
120 static void convertImpl (Converter& converter,
Iterator b,
Iterator e, Fn&& fn)
122 std::for_each (b, e, [&] (
const auto& v)
124 convertImpl (converter, v, fn);
128 template <
typename Fn>
131 visit (*
this, m, std::forward<Fn> (fn));
134 template <
typename Fn>
135 void convert (
const View& v, Fn&& fn)
137 visit (*
this, v, std::forward<Fn> (fn));
140 template <
typename Fn>
143 visit (*
this, begin, end, std::forward<Fn> (fn));
146 PacketProtocol getProtocol()
const noexcept {
return mode; }
149 std::tuple<ToUMP1Converter, ToUMP2Converter> converters;
150 const PacketProtocol mode{};
162 : translator (storageSize) {}
164 template <
typename Fn>
170 template <
typename Fn>
171 void convert (
const View& v,
double time, Fn&& fn)
175 translator.
dispatch (midi1, time, fn);
179 void reset() { translator.
reset(); }
void dispatch(const View &packet, double time, MessageCallback &&callback)
void dispatch(const View &v, PacketCallback &&callback)
static void midi2ToMidi1DefaultTranslation(const View &v, Callback &&callback)
static void toMidi1(const BytestreamMidiView &m, PacketCallbackFunction &&callback)