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"
24 // -----------------------------------------------------------------------
27 const NativeHostDescriptor
* host
;
30 // -----------------------------------------------------------------------
32 static NativePluginHandle
midijoin_instantiate(const NativeHostDescriptor
* host
)
34 MidiSplitHandle
* const handle
= (MidiSplitHandle
*)malloc(sizeof(MidiSplitHandle
));
43 #define handlePtr ((MidiSplitHandle*)handle)
45 static void midijoin_cleanup(NativePluginHandle handle
)
50 // FIXME for v3.0, use const for the input buffer
51 static void midijoin_process(NativePluginHandle handle
,
52 float** inBuffer
, float** outBuffer
, uint32_t frames
,
53 const NativeMidiEvent
* midiEvents
, uint32_t midiEventCount
)
55 const NativeHostDescriptor
* const host
= handlePtr
->host
;
56 NativeMidiEvent tmpEvent
;
58 for (uint32_t i
=0; i
< midiEventCount
; ++i
)
60 const NativeMidiEvent
* const midiEvent
= &midiEvents
[i
];
62 if (midiEvent
->port
>= MAX_MIDI_CHANNELS
)
64 printf("Assertion error: midiEvent->port:%u >= MAX_MIDI_CHANNELS\n", midiEvent
->port
);
68 const uint8_t statusByte
= midiEvent
->data
[0];
70 if (MIDI_IS_CHANNEL_MESSAGE(statusByte
))
71 tmpEvent
.data
[0] = (uint8_t)((statusByte
& MIDI_STATUS_BIT
) | (midiEvent
->port
& MIDI_CHANNEL_BIT
));
73 tmpEvent
.data
[0] = statusByte
;
76 tmpEvent
.time
= midiEvent
->time
;
77 tmpEvent
.data
[1] = midiEvent
->data
[1];
78 tmpEvent
.data
[2] = midiEvent
->data
[2];
79 tmpEvent
.data
[3] = midiEvent
->data
[3];
80 tmpEvent
.size
= midiEvent
->size
;
82 host
->write_midi_event(host
->handle
, &tmpEvent
);
95 // -----------------------------------------------------------------------
97 static const NativePluginDescriptor midijoinDesc
= {
98 .category
= NATIVE_PLUGIN_CATEGORY_UTILITY
,
99 .hints
= NATIVE_PLUGIN_IS_RTSAFE
,
100 .supports
= NATIVE_PLUGIN_SUPPORTS_EVERYTHING
,
105 .midiIns
= MAX_MIDI_CHANNELS
,
112 .copyright
= "GNU GPL v2+",
114 .instantiate
= midijoin_instantiate
,
115 .cleanup
= midijoin_cleanup
,
117 .get_parameter_count
= NULL
,
118 .get_parameter_info
= NULL
,
119 .get_parameter_value
= NULL
,
121 .get_midi_program_count
= NULL
,
122 .get_midi_program_info
= NULL
,
124 .set_parameter_value
= NULL
,
125 .set_midi_program
= NULL
,
126 .set_custom_data
= NULL
,
131 .ui_set_parameter_value
= NULL
,
132 .ui_set_midi_program
= NULL
,
133 .ui_set_custom_data
= NULL
,
137 .process
= midijoin_process
,
145 // -----------------------------------------------------------------------
147 void carla_register_native_plugin_midijoin(void);
149 void carla_register_native_plugin_midijoin(void)
151 carla_register_native_plugin(&midijoinDesc
);
154 // -----------------------------------------------------------------------