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 // -----------------------------------------------------------------------
28 } MidiChannelizeParams
;
31 const NativeHostDescriptor
* host
;
33 } MidiChannelizeHandle
;
35 // -----------------------------------------------------------------------
37 static NativePluginHandle
midichannelize_instantiate(const NativeHostDescriptor
* host
)
39 MidiChannelizeHandle
* const handle
= (MidiChannelizeHandle
*)malloc(sizeof(MidiChannelizeHandle
));
49 #define handlePtr ((MidiChannelizeHandle*)handle)
51 static void midichannelize_cleanup(NativePluginHandle handle
)
56 static uint32_t midichannelize_get_parameter_count(NativePluginHandle handle
)
64 static const NativeParameter
* midichannelize_get_parameter_info(NativePluginHandle handle
, uint32_t index
)
66 if (index
> PARAM_COUNT
)
69 static NativeParameter param
;
71 param
.hints
= NATIVE_PARAMETER_IS_ENABLED
|NATIVE_PARAMETER_IS_AUTOMATABLE
|NATIVE_PARAMETER_IS_INTEGER
;
73 param
.scalePointCount
= 0;
74 param
.scalePoints
= NULL
;
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
;
95 static float midichannelize_get_parameter_value(NativePluginHandle handle
, uint32_t index
)
100 return (float)handlePtr
->channel
;
106 static void midichannelize_set_parameter_value(NativePluginHandle handle
, uint32_t index
, float value
)
111 handlePtr
->channel
= (int)value
;
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
);
156 // -----------------------------------------------------------------------
158 static const NativePluginDescriptor midichannelizeDesc
= {
159 .category
= NATIVE_PLUGIN_CATEGORY_UTILITY
,
160 .hints
= NATIVE_PLUGIN_IS_RTSAFE
,
161 .supports
= NATIVE_PLUGIN_SUPPORTS_EVERYTHING
,
170 .name
= "MIDI Channelize",
171 .label
= "midichannelize",
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
,
192 .ui_set_parameter_value
= NULL
,
193 .ui_set_midi_program
= NULL
,
194 .ui_set_custom_data
= NULL
,
198 .process
= midichannelize_process
,
206 // -----------------------------------------------------------------------
208 void carla_register_native_plugin_midichannelize(void);
210 void carla_register_native_plugin_midichannelize(void)
212 carla_register_native_plugin(&midichannelizeDesc
);
215 // -----------------------------------------------------------------------