3 * Copyright (C) 2012-2019 Filipe Coelho <falktx@falktx.com>
4 * Copyright (C) 2018 Milk Brewster <code@milkmiruku.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of
9 * the License, or any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * For a full copy of the GNU General Public License see the doc/GPL.txt file.
19 #include "CarlaNative.h"
20 #include "CarlaMIDI.h"
26 // -----------------------------------------------------------------------
29 const NativeHostDescriptor
* host
;
30 bool channels
[MAX_MIDI_CHANNELS
];
33 // -----------------------------------------------------------------------
35 static NativePluginHandle
midichanab_instantiate(const NativeHostDescriptor
* host
)
37 MidiGainHandle
* const handle
= (MidiGainHandle
*)malloc(sizeof(MidiGainHandle
));
44 memset(handle
->channels
, 0, MAX_MIDI_CHANNELS
);
49 #define handlePtr ((MidiGainHandle*)handle)
51 static void midichanab_cleanup(NativePluginHandle handle
)
56 static uint32_t midichanab_get_parameter_count(NativePluginHandle handle
)
58 return MAX_MIDI_CHANNELS
;
64 static const NativeParameter
* midichanab_get_parameter_info(NativePluginHandle handle
, uint32_t index
)
66 if (index
>= MAX_MIDI_CHANNELS
)
69 static NativeParameter param
;
70 static const NativeParameterScalePoint scalePoints
[2] = { { "Output A", 0 }, { "Output B", 1 } };
71 static char paramName
[24];
73 param
.hints
= NATIVE_PARAMETER_IS_ENABLED
|NATIVE_PARAMETER_IS_AUTOMATABLE
|NATIVE_PARAMETER_IS_BOOLEAN
|NATIVE_PARAMETER_USES_SCALEPOINTS
;
74 param
.name
= paramName
;
79 param
.ranges
.step
= 1;
80 param
.ranges
.stepSmall
= 1;
81 param
.ranges
.stepLarge
= 1;
82 param
.scalePointCount
= 2;
83 param
.scalePoints
= scalePoints
;
85 snprintf(paramName
, 24, "%u", index
+1);
93 static float midichanab_get_parameter_value(NativePluginHandle handle
, uint32_t index
)
95 if (index
>= MAX_MIDI_CHANNELS
)
98 return handlePtr
->channels
[index
] ? 1 : 0;
101 static void midichanab_set_parameter_value(NativePluginHandle handle
, uint32_t index
, float value
)
103 if (index
>= MAX_MIDI_CHANNELS
)
106 handlePtr
->channels
[index
] = (value
>= 0.5f
);
109 // FIXME for v3.0, use const for the input buffer
110 static void midichanab_process(NativePluginHandle handle
,
111 float** inBuffer
, float** outBuffer
, uint32_t frames
,
112 const NativeMidiEvent
* midiEvents
, uint32_t midiEventCount
)
114 const NativeHostDescriptor
* const host
= handlePtr
->host
;
115 const bool* const channels
= handlePtr
->channels
;
116 NativeMidiEvent tmpEvent
;
118 for (uint32_t i
=0; i
< midiEventCount
; ++i
)
120 const NativeMidiEvent
* const midiEvent
= &midiEvents
[i
];
122 const uint8_t status
= (uint8_t)MIDI_GET_STATUS_FROM_DATA(midiEvent
->data
);
124 if (MIDI_IS_CHANNEL_MESSAGE(status
))
126 const uint8_t channel
= (uint8_t)MIDI_GET_CHANNEL_FROM_DATA(midiEvent
->data
);
128 if (channel
>= MAX_MIDI_CHANNELS
)
131 if (channels
[channel
])
133 memcpy(&tmpEvent
, midiEvent
, sizeof(NativeMidiEvent
));
135 host
->write_midi_event(host
->handle
, &tmpEvent
);
139 host
->write_midi_event(host
->handle
, midiEvent
);
144 // pass through all non-message events
145 host
->write_midi_event(host
->handle
, midiEvent
);
157 // -----------------------------------------------------------------------
159 static const NativePluginDescriptor midichanabDesc
= {
160 .category
= NATIVE_PLUGIN_CATEGORY_UTILITY
,
161 .hints
= NATIVE_PLUGIN_IS_RTSAFE
,
162 .supports
= NATIVE_PLUGIN_SUPPORTS_EVERYTHING
,
171 .name
= "MIDI Channel A/B",
172 .label
= "midichanab",
173 .maker
= "Milk Brewster",
174 .copyright
= "GNU GPL v2+",
176 .instantiate
= midichanab_instantiate
,
177 .cleanup
= midichanab_cleanup
,
179 .get_parameter_count
= midichanab_get_parameter_count
,
180 .get_parameter_info
= midichanab_get_parameter_info
,
181 .get_parameter_value
= midichanab_get_parameter_value
,
183 .get_midi_program_count
= NULL
,
184 .get_midi_program_info
= NULL
,
186 .set_parameter_value
= midichanab_set_parameter_value
,
187 .set_midi_program
= NULL
,
188 .set_custom_data
= NULL
,
193 .ui_set_parameter_value
= NULL
,
194 .ui_set_midi_program
= NULL
,
195 .ui_set_custom_data
= NULL
,
199 .process
= midichanab_process
,
207 // -----------------------------------------------------------------------
209 void carla_register_native_plugin_midichanab(void);
211 void carla_register_native_plugin_midichanab(void)
213 carla_register_native_plugin(&midichanabDesc
);
216 // -----------------------------------------------------------------------