Fix wine build
[carla.git] / source / native-plugins / midi-split.c
blob6488b7bb822fea7bdb56d37764dab9ad43649a19
1 /*
2 * Carla Native Plugins
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"
21 #include <stdlib.h>
23 // -----------------------------------------------------------------------
25 typedef struct {
26 const NativeHostDescriptor* host;
27 } MidiSplitHandle;
29 // -----------------------------------------------------------------------
31 static NativePluginHandle midisplit_instantiate(const NativeHostDescriptor* host)
33 MidiSplitHandle* const handle = (MidiSplitHandle*)malloc(sizeof(MidiSplitHandle));
35 if (handle == NULL)
36 return NULL;
38 handle->host = host;
39 return handle;
42 #define handlePtr ((MidiSplitHandle*)handle)
44 static void midisplit_cleanup(NativePluginHandle handle)
46 free(handlePtr);
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)
65 continue;
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);
78 return;
80 // unused
81 (void)inBuffer;
82 (void)outBuffer;
83 (void)frames;
86 #undef handlePtr
88 // -----------------------------------------------------------------------
90 static const NativePluginDescriptor midisplitDesc = {
91 .category = NATIVE_PLUGIN_CATEGORY_UTILITY,
92 .hints = NATIVE_PLUGIN_IS_RTSAFE,
93 .supports = NATIVE_PLUGIN_SUPPORTS_EVERYTHING,
94 .audioIns = 0,
95 .audioOuts = 0,
96 .cvIns = 0,
97 .cvOuts = 0,
98 .midiIns = 1,
99 .midiOuts = MAX_MIDI_CHANNELS,
100 .paramIns = 0,
101 .paramOuts = 0,
102 .name = "MIDI Split",
103 .label = "midisplit",
104 .maker = "falkTX",
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,
121 .ui_show = NULL,
122 .ui_idle = NULL,
124 .ui_set_parameter_value = NULL,
125 .ui_set_midi_program = NULL,
126 .ui_set_custom_data = NULL,
128 .activate = NULL,
129 .deactivate = NULL,
130 .process = midisplit_process,
132 .get_state = NULL,
133 .set_state = NULL,
135 .dispatcher = NULL
138 // -----------------------------------------------------------------------
140 void carla_register_native_plugin_midisplit(void);
142 void carla_register_native_plugin_midisplit(void)
144 carla_register_native_plugin(&midisplitDesc);
147 // -----------------------------------------------------------------------