Update CI version
[carla.git] / source / native-plugins / midi-channelize.c
blobc723312b2c9101b9228ddff985dd75d499232be1
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 enum {
26 PARAM_CHANNEL = 0,
27 PARAM_COUNT
28 } MidiChannelizeParams;
30 typedef struct {
31 const NativeHostDescriptor* host;
32 int channel;
33 } MidiChannelizeHandle;
35 // -----------------------------------------------------------------------
37 static NativePluginHandle midichannelize_instantiate(const NativeHostDescriptor* host)
39 MidiChannelizeHandle* const handle = (MidiChannelizeHandle*)malloc(sizeof(MidiChannelizeHandle));
41 if (handle == NULL)
42 return NULL;
44 handle->host = host;
45 handle->channel = 1;
46 return handle;
49 #define handlePtr ((MidiChannelizeHandle*)handle)
51 static void midichannelize_cleanup(NativePluginHandle handle)
53 free(handlePtr);
56 static uint32_t midichannelize_get_parameter_count(NativePluginHandle handle)
58 return PARAM_COUNT;
60 // unused
61 (void)handle;
64 static const NativeParameter* midichannelize_get_parameter_info(NativePluginHandle handle, uint32_t index)
66 if (index > PARAM_COUNT)
67 return NULL;
69 static NativeParameter param;
71 param.hints = NATIVE_PARAMETER_IS_ENABLED|NATIVE_PARAMETER_IS_AUTOMATABLE|NATIVE_PARAMETER_IS_INTEGER;
72 param.unit = NULL;
73 param.scalePointCount = 0;
74 param.scalePoints = NULL;
76 switch (index)
78 case PARAM_CHANNEL:
79 param.name = "Channel";
80 param.ranges.def = 1.0f,
81 param.ranges.min = 1.0f,
82 param.ranges.max = 16.0f,
83 param.ranges.step = 1.0f;
84 param.ranges.stepSmall = 1.0f;
85 param.ranges.stepLarge = 1.0f;
86 break;
89 return &param;
91 // unused
92 (void)handle;
95 static float midichannelize_get_parameter_value(NativePluginHandle handle, uint32_t index)
97 switch (index)
99 case PARAM_CHANNEL:
100 return (float)handlePtr->channel;
101 default:
102 return 0.0f;
106 static void midichannelize_set_parameter_value(NativePluginHandle handle, uint32_t index, float value)
108 switch (index)
110 case PARAM_CHANNEL:
111 handlePtr->channel = (int)value;
112 break;
116 // FIXME for v3.0, use const for the input buffer
117 static void midichannelize_process(NativePluginHandle handle,
118 float** inBuffer, float** outBuffer, uint32_t frames,
119 const NativeMidiEvent* midiEvents, uint32_t midiEventCount)
121 const NativeHostDescriptor* const host = handlePtr->host;
122 const int channel = handlePtr->channel;
123 NativeMidiEvent tmpEvent;
125 for (uint32_t i=0; i < midiEventCount; ++i)
127 const NativeMidiEvent* const midiEvent = &midiEvents[i];
129 const uint8_t status = (uint8_t)MIDI_GET_STATUS_FROM_DATA(midiEvent->data);
131 if (MIDI_IS_CHANNEL_MESSAGE(status))
133 tmpEvent.port = midiEvent->port;
134 tmpEvent.time = midiEvent->time;
136 tmpEvent.data[0] = (uint8_t)(status | (channel - 1));
137 tmpEvent.data[1] = midiEvent->data[1];
138 tmpEvent.data[2] = midiEvent->data[2];
139 tmpEvent.data[3] = midiEvent->data[3];
140 tmpEvent.size = midiEvent->size;
142 host->write_midi_event(host->handle, &tmpEvent);
146 return;
148 // unused
149 (void)inBuffer;
150 (void)outBuffer;
151 (void)frames;
154 #undef handlePtr
156 // -----------------------------------------------------------------------
158 static const NativePluginDescriptor midichannelizeDesc = {
159 .category = NATIVE_PLUGIN_CATEGORY_UTILITY,
160 .hints = NATIVE_PLUGIN_IS_RTSAFE,
161 .supports = NATIVE_PLUGIN_SUPPORTS_EVERYTHING,
162 .audioIns = 0,
163 .audioOuts = 0,
164 .cvIns = 0,
165 .cvOuts = 0,
166 .midiIns = 1,
167 .midiOuts = 1,
168 .paramIns = 1,
169 .paramOuts = 0,
170 .name = "MIDI Channelize",
171 .label = "midichannelize",
172 .maker = "falkTX",
173 .copyright = "GNU GPL v2+",
175 .instantiate = midichannelize_instantiate,
176 .cleanup = midichannelize_cleanup,
178 .get_parameter_count = midichannelize_get_parameter_count,
179 .get_parameter_info = midichannelize_get_parameter_info,
180 .get_parameter_value = midichannelize_get_parameter_value,
182 .get_midi_program_count = NULL,
183 .get_midi_program_info = NULL,
185 .set_parameter_value = midichannelize_set_parameter_value,
186 .set_midi_program = NULL,
187 .set_custom_data = NULL,
189 .ui_show = NULL,
190 .ui_idle = NULL,
192 .ui_set_parameter_value = NULL,
193 .ui_set_midi_program = NULL,
194 .ui_set_custom_data = NULL,
196 .activate = NULL,
197 .deactivate = NULL,
198 .process = midichannelize_process,
200 .get_state = NULL,
201 .set_state = NULL,
203 .dispatcher = NULL
206 // -----------------------------------------------------------------------
208 void carla_register_native_plugin_midichannelize(void);
210 void carla_register_native_plugin_midichannelize(void)
212 carla_register_native_plugin(&midichannelizeDesc);
215 // -----------------------------------------------------------------------