3 * Copyright (C) 2012-2019 Filipe Coelho <falktx@falktx.com>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of
8 * the License, or any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * For a full copy of the GNU General Public License see the doc/GPL.txt file.
18 #include "CarlaNative.h"
19 #include "CarlaMIDI.h"
23 // -----------------------------------------------------------------------
26 const NativeHostDescriptor
* host
;
29 // -----------------------------------------------------------------------
31 static NativePluginHandle
midisplit_instantiate(const NativeHostDescriptor
* host
)
33 MidiSplitHandle
* const handle
= (MidiSplitHandle
*)malloc(sizeof(MidiSplitHandle
));
42 #define handlePtr ((MidiSplitHandle*)handle)
44 static void midisplit_cleanup(NativePluginHandle handle
)
49 // FIXME for v3.0, use const for the input buffer
50 static void midisplit_process(NativePluginHandle handle
,
51 float** inBuffer
, float** outBuffer
, uint32_t frames
,
52 const NativeMidiEvent
* midiEvents
, uint32_t midiEventCount
)
54 const NativeHostDescriptor
* const host
= handlePtr
->host
;
55 NativeMidiEvent tmpEvent
;
57 for (uint32_t i
=0; i
< midiEventCount
; ++i
)
59 const NativeMidiEvent
* const midiEvent
= &midiEvents
[i
];
61 const uint8_t status
= (uint8_t)MIDI_GET_STATUS_FROM_DATA(midiEvent
->data
);
62 const uint8_t channel
= (uint8_t)MIDI_GET_CHANNEL_FROM_DATA(midiEvent
->data
);
64 if (channel
>= MAX_MIDI_CHANNELS
)
67 tmpEvent
.port
= channel
;
68 tmpEvent
.time
= midiEvent
->time
;
69 tmpEvent
.data
[0] = status
;
70 tmpEvent
.data
[1] = midiEvent
->data
[1];
71 tmpEvent
.data
[2] = midiEvent
->data
[2];
72 tmpEvent
.data
[3] = midiEvent
->data
[3];
73 tmpEvent
.size
= midiEvent
->size
;
75 host
->write_midi_event(host
->handle
, &tmpEvent
);
88 // -----------------------------------------------------------------------
90 static const NativePluginDescriptor midisplitDesc
= {
91 .category
= NATIVE_PLUGIN_CATEGORY_UTILITY
,
92 .hints
= NATIVE_PLUGIN_IS_RTSAFE
,
93 .supports
= NATIVE_PLUGIN_SUPPORTS_EVERYTHING
,
99 .midiOuts
= MAX_MIDI_CHANNELS
,
102 .name
= "MIDI Split",
103 .label
= "midisplit",
105 .copyright
= "GNU GPL v2+",
107 .instantiate
= midisplit_instantiate
,
108 .cleanup
= midisplit_cleanup
,
110 .get_parameter_count
= NULL
,
111 .get_parameter_info
= NULL
,
112 .get_parameter_value
= NULL
,
114 .get_midi_program_count
= NULL
,
115 .get_midi_program_info
= NULL
,
117 .set_parameter_value
= NULL
,
118 .set_midi_program
= NULL
,
119 .set_custom_data
= NULL
,
124 .ui_set_parameter_value
= NULL
,
125 .ui_set_midi_program
= NULL
,
126 .ui_set_custom_data
= NULL
,
130 .process
= midisplit_process
,
138 // -----------------------------------------------------------------------
140 void carla_register_native_plugin_midisplit(void);
142 void carla_register_native_plugin_midisplit(void)
144 carla_register_native_plugin(&midisplitDesc
);
147 // -----------------------------------------------------------------------