-
-
Notifications
You must be signed in to change notification settings - Fork 129
/
lib.rs
235 lines (221 loc) · 7.76 KB
/
lib.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
use nih_plug::prelude::*;
use std::sync::Arc;
/// A plugin that inverts all MIDI note numbers, channels, CCs, velocitires, pressures, and
/// everything else you don't want to be inverted.
struct MidiInverter {
params: Arc<MidiInverterParams>,
}
#[derive(Default, Params)]
struct MidiInverterParams {}
impl Default for MidiInverter {
fn default() -> Self {
Self {
params: Arc::new(MidiInverterParams::default()),
}
}
}
impl Plugin for MidiInverter {
const NAME: &'static str = "MIDI Inverter";
const VENDOR: &'static str = "Moist Plugins GmbH";
const URL: &'static str = "https://youtu.be/dQw4w9WgXcQ";
const EMAIL: &'static str = "info@example.com";
const VERSION: &'static str = env!("CARGO_PKG_VERSION");
// This plugin doesn't have any audio IO
const AUDIO_IO_LAYOUTS: &'static [AudioIOLayout] = &[];
const MIDI_INPUT: MidiConfig = MidiConfig::MidiCCs;
const MIDI_OUTPUT: MidiConfig = MidiConfig::MidiCCs;
const SAMPLE_ACCURATE_AUTOMATION: bool = true;
type SysExMessage = ();
type BackgroundTask = ();
fn params(&self) -> Arc<dyn Params> {
self.params.clone()
}
fn process(
&mut self,
_buffer: &mut Buffer,
_aux: &mut AuxiliaryBuffers,
context: &mut impl ProcessContext<Self>,
) -> ProcessStatus {
// We'll invert the channel, note index, velocity, pressure, CC value, pitch bend, and
// anything else that is invertable for all events we receive
while let Some(event) = context.next_event() {
match event {
NoteEvent::NoteOn {
timing,
voice_id,
channel,
note,
velocity,
} => context.send_event(NoteEvent::NoteOn {
timing,
voice_id,
channel: 15 - channel,
note: 127 - note,
velocity: 1.0 - velocity,
}),
NoteEvent::NoteOff {
timing,
voice_id,
channel,
note,
velocity,
} => context.send_event(NoteEvent::NoteOff {
timing,
voice_id,
channel: 15 - channel,
note: 127 - note,
velocity: 1.0 - velocity,
}),
NoteEvent::Choke {
timing,
voice_id,
channel,
note,
} => context.send_event(NoteEvent::Choke {
timing,
voice_id,
channel: 15 - channel,
note: 127 - note,
}),
NoteEvent::PolyPressure {
timing,
voice_id,
channel,
note,
pressure,
} => context.send_event(NoteEvent::PolyPressure {
timing,
voice_id,
channel: 15 - channel,
note: 127 - note,
pressure: 1.0 - pressure,
}),
NoteEvent::PolyVolume {
timing,
voice_id,
channel,
note,
gain,
} => context.send_event(NoteEvent::PolyVolume {
timing,
voice_id,
channel: 15 - channel,
note: 127 - note,
gain: 1.0 - gain,
}),
NoteEvent::PolyPan {
timing,
voice_id,
channel,
note,
pan,
} => context.send_event(NoteEvent::PolyPan {
timing,
voice_id,
channel: 15 - channel,
note: 127 - note,
pan: 1.0 - pan,
}),
NoteEvent::PolyTuning {
timing,
voice_id,
channel,
note,
tuning,
} => context.send_event(NoteEvent::PolyTuning {
timing,
voice_id,
channel: 15 - channel,
note: 127 - note,
tuning: 1.0 - tuning,
}),
NoteEvent::PolyVibrato {
timing,
voice_id,
channel,
note,
vibrato,
} => context.send_event(NoteEvent::PolyVibrato {
timing,
voice_id,
channel: 15 - channel,
note: 127 - note,
vibrato: 1.0 - vibrato,
}),
NoteEvent::PolyExpression {
timing,
voice_id,
channel,
note,
expression,
} => context.send_event(NoteEvent::PolyExpression {
timing,
voice_id,
channel: 15 - channel,
note: 127 - note,
expression: 1.0 - expression,
}),
NoteEvent::PolyBrightness {
timing,
voice_id,
channel,
note,
brightness,
} => context.send_event(NoteEvent::PolyBrightness {
timing,
voice_id,
channel: 15 - channel,
note: 127 - note,
brightness: 1.0 - brightness,
}),
NoteEvent::MidiChannelPressure {
timing,
channel,
pressure,
} => context.send_event(NoteEvent::MidiChannelPressure {
timing,
channel: 15 - channel,
pressure: 1.0 - pressure,
}),
NoteEvent::MidiPitchBend {
timing,
channel,
value,
} => context.send_event(NoteEvent::MidiPitchBend {
timing,
channel: 15 - channel,
value: 1.0 - value,
}),
NoteEvent::MidiCC {
timing,
channel,
cc,
value,
} => context.send_event(NoteEvent::MidiCC {
timing,
channel: 15 - channel,
// The one thing we won't invert, because uuhhhh
cc,
value: 1.0 - value,
}),
_ => (),
}
}
ProcessStatus::Normal
}
}
impl ClapPlugin for MidiInverter {
const CLAP_ID: &'static str = "com.moist-plugins-gmbh.midi-inverter";
const CLAP_DESCRIPTION: Option<&'static str> =
Some("Inverts all note and MIDI signals in ways you don't want to");
const CLAP_MANUAL_URL: Option<&'static str> = Some(Self::URL);
const CLAP_SUPPORT_URL: Option<&'static str> = None;
const CLAP_FEATURES: &'static [ClapFeature] = &[ClapFeature::NoteEffect, ClapFeature::Utility];
}
impl Vst3Plugin for MidiInverter {
const VST3_CLASS_ID: [u8; 16] = *b"M1d1Inv3r70rzAaA";
const VST3_SUBCATEGORIES: &'static [Vst3SubCategory] =
&[Vst3SubCategory::Instrument, Vst3SubCategory::Tools];
}
nih_export_clap!(MidiInverter);
nih_export_vst3!(MidiInverter);