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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
use std::ffi::c_void;
use std::mem;
use std::os::raw::c_char;

pub const fn cconst(a: u8, b: u8, c: u8, d: u8) -> i32 {
    ((a as i32) << 24) | ((b as i32) << 16) | ((c as i32) << 8) | ((d as i32) << 0)
}

pub mod host_opcodes {
    pub const AUTOMATE: i32 = 0;
    pub const VERSION: i32 = 1;
    pub const CURRENT_ID: i32 = 2;
    pub const IDLE: i32 = 3;
    pub const PIN_CONNECTED: i32 = 4;
    pub const WANT_MIDI: i32 = 6;
    pub const GET_TIME: i32 = 7;
    pub const PROCESS_EVENTS: i32 = 8;
    pub const SET_TIME: i32 = 9;
    pub const TEMPO_AT: i32 = 10;
    pub const GET_NUM_AUTOMATABLE_PARAMETERS: i32 = 11;
    pub const GET_PARAMETER_QUANTIZATION: i32 = 12;
    pub const IO_CHANGED: i32 = 13;
    pub const NEED_IDLE: i32 = 14;
    pub const SIZE_WINDOW: i32 = 15;
    pub const GET_SAMPLE_RATE: i32 = 16;
    pub const GET_BLOCK_SIZE: i32 = 17;
    pub const GET_INPUT_LATENCY: i32 = 18;
    pub const GET_OUTPUT_LATENCY: i32 = 19;
    pub const GET_PREVIOUS_PLUG: i32 = 20;
    pub const GET_NEXT_PLUG: i32 = 21;
    pub const WILL_REPLACE_OR_ACCUMULATE: i32 = 22;
    pub const GET_CURRENT_PROCESS_LEVEL: i32 = 23;
    pub const GET_AUTOMATION_STATE: i32 = 24;
    pub const OFFLINE_START: i32 = 25;
    pub const OFFLINE_READ: i32 = 26;
    pub const OFFLINE_WRITE: i32 = 27;
    pub const OFFLINE_GET_CURRENT_PASS: i32 = 28;
    pub const OFFLINE_GET_CURRENT_META_PASS: i32 = 29;
    pub const SET_OUTPUT_SAMPLE_RATE: i32 = 30;
    pub const GET_SPEAKER_ARRANGEMENT: i32 = 31;
    pub const GET_VENDOR_STRING: i32 = 32;
    pub const GET_PRODUCT_STRING: i32 = 33;
    pub const GET_VENDOR_VERSION: i32 = 34;
    pub const VENDOR_SPECIFIC: i32 = 35;
    pub const SET_ICON: i32 = 36;
    pub const CAN_DO: i32 = 37;
    pub const GET_LANGUAGE: i32 = 38;
    pub const OPEN_WINDOW: i32 = 39;
    pub const CLOSE_WINDOW: i32 = 40;
    pub const GET_DIRECTORY: i32 = 41;
    pub const UPDATE_DISPLAY: i32 = 42;
    pub const BEGIN_EDIT: i32 = 43;
    pub const END_EDIT: i32 = 44;
    pub const OPEN_FILE_SELECTOR: i32 = 45;
    pub const CLOSE_FILE_SELECTOR: i32 = 46;
    pub const EDIT_FILE: i32 = 47;
    pub const GET_CHUNK_FILE: i32 = 48;
    pub const GET_INPUT_SPEAKER_ARRANGEMENT: i32 = 49;
}

pub mod effect_flags {
    pub const HAS_EDITOR: i32 = 1;
    pub const CAN_REPLACING: i32 = 1 << 4;
    pub const PROGRAM_CHUNKS: i32 = 1 << 5;
    pub const IS_SYNTH: i32 = 1 << 8;
}

pub mod effect_opcodes {
    pub const OPEN: i32 = 0;
    pub const CLOSE: i32 = 1;
    pub const SET_PROGRAM: i32 = 2;
    pub const GET_PROGRAM: i32 = 3;
    pub const GET_PROGRAM_NAME: i32 = 5;
    pub const GET_PARAM_LABEL: i32 = 6;
    pub const GET_PARAM_DISPLAY: i32 = 7;
    pub const GET_PARAM_NAME: i32 = 8;
    pub const SET_SAMPLE_RATE: i32 = 10;
    pub const SET_BLOCK_SIZE: i32 = 11;
    pub const MAINS_CHANGED: i32 = 12;
    pub const EDIT_GET_RECT: i32 = 13;
    pub const EDIT_OPEN: i32 = 14;
    pub const EDIT_CLOSE: i32 = 15;
    pub const EDIT_IDLE: i32 = 19;
    pub const EDIT_TOP: i32 = 20;
    pub const GET_CHUNK: i32 = 23;
    pub const SET_CHUNK: i32 = 24;
    pub const PROCESS_EVENTS: i32 = 25;
    pub const CAN_BE_AUTOMATED: i32 = 26;
    pub const STRING_TO_PARAMETER: i32 = 27;
    pub const GET_PLUG_CATEGORY: i32 = 35;
    pub const SET_BYPASS: i32 = 44;
    pub const GET_EFFECT_NAME: i32 = 45;
    pub const GET_VENDOR_STRING: i32 = 47;
    pub const GET_PRODUCT_STRING: i32 = 48;
    pub const GET_VENDOR_VERSION: i32 = 49;
    pub const VENDOR_SPECIFIC: i32 = 50;
    pub const CAN_DO: i32 = 51;
    pub const IDLE: i32 = 53;
    pub const GET_PARAMETER_PROPERTIES: i32 = 56;
    pub const GET_VST_VERSION: i32 = 58;
    pub const SHELL_GET_NEXT_PLUGIN: i32 = 70;
    pub const START_PROCESS: i32 = 71;
    pub const STOP_PROCESS: i32 = 72;
    pub const BEGIN_SET_PROGRAM: i32 = 67;
    pub const END_SET_PROGRAM: i32 = 68;
}

pub const MAGIC: i32 = cconst(b'V', b's', b't', b'P');
pub const LANG_ENGLISH: i32 = 1;
pub const MIDI_TYPE: i32 = 1;
pub const SYSEX_TYPE: i32 = 6;

pub mod transport {
    pub const CHANGED: i32 = 1;
    pub const PLAYING: i32 = 1 << 1;
    pub const CYCLE_ACTIVE: i32 = 1 << 2;
    pub const RECORDING: i32 = 1 << 3;
}

pub mod automation {
    pub const WRITING: i32 = 1 << 6;
    pub const READING: i32 = 1 << 7;
}

pub mod time_info_flags {
    pub const NANOS_VALID: i32 = 1 << 8;
    pub const PPQ_POS_VALID: i32 = 1 << 9;
    pub const TEMPO_VALID: i32 = 1 << 10;
    pub const BARS_VALID: i32 = 1 << 11;
    pub const CYCLE_POS_VALID: i32 = 1 << 12;
    pub const TIME_SIG_VALID: i32 = 1 << 13;
    pub const SMPTE_VALID: i32 = 1 << 14;
    pub const CLOCK_VALID: i32 = 1 << 15;
}

#[repr(C)]
#[derive(Copy, Clone)]
pub struct MidiEvent {
    pub event_type: i32,
    pub byte_size: i32,
    pub delta_frames: i32,
    pub flags: i32,
    pub note_length: i32,
    pub note_offset: i32,
    pub midi_data: [u8; 4],
    pub detune: i8,
    pub note_off_velocity: u8,
    pub reserved_1: u8,
    pub reserved_2: u8,
}

#[repr(C)]
#[derive(Copy, Clone)]
pub struct SysExEvent {
    pub event_type: i32,
    pub byte_size: i32,
    pub delta_frames: i32,
    pub flags: i32,
    pub dump_bytes: i32,
    pub reserved_1: *const c_void,
    pub sysex_dump: *const i8,
    pub reserved_2: *const c_void,
}

#[repr(C)]
#[derive(Copy, Clone)]
pub struct Event {
    pub dump: [u8; mem::size_of::<MidiEvent>()],
}

#[repr(C)]
#[derive(Copy, Clone)]
pub struct Events {
    pub num_events: i32,
    pub reserved: *const c_void,
    pub events: [*const Event; 2],
}

pub mod string_constants {
    pub const MAX_NAME_LEN: usize = 64;
    pub const MAX_LABEL_LEN: usize = 64;
    pub const MAX_SHORT_LABEL_LEN: usize = 8;
    pub const MAX_CATEG_LABEL_LEN: usize = 24;
    pub const MAX_FILE_NAME_LEN: usize = 100;
}

pub mod plug_category {
    pub const UNKNOWN: i32 = 0;
    pub const EFFECT: i32 = 1;
    pub const SYNTH: i32 = 2;
    pub const ANALYSIS: i32 = 3;
    pub const MASTERING: i32 = 4;
    pub const SPACIALIZER: i32 = 5;
    pub const ROOM_FX: i32 = 6;
    pub const SURROUND_FX: i32 = 7;
    pub const RESTORATION: i32 = 8;
    pub const OFFLINE_PROCESS: i32 = 9;
    pub const SHELL: i32 = 10;
    pub const GENERATOR: i32 = 11;
    pub const MAX_COUNT: i32 = 12;
}

#[repr(C)]
#[derive(Copy, Clone)]
pub struct ParameterProperties {
    pub step_float: f32,
    pub small_step_float: f32,
    pub large_step_float: f32,
    pub label: [c_char; string_constants::MAX_LABEL_LEN],
    pub flags: i32,
    pub min_integer: i32,
    pub max_integer: i32,
    pub step_integer: i32,
    pub large_step_integer: i32,
    pub short_label: [c_char; string_constants::MAX_SHORT_LABEL_LEN],
    pub display_index: i16,
    pub category: i16,
    pub num_parameters_in_category: i16,
    pub reserved: i16,
    pub category_label: [c_char; string_constants::MAX_CATEG_LABEL_LEN],
    pub future: [u8; 16],
}

pub mod parameter_flags {
    pub const IS_SWITCH: i32 = 1 << 0;
    pub const USES_INTEGER_MIN_MAX: i32 = 1 << 1;
    pub const USES_FLOAT_STEP: i32 = 1 << 2;
    pub const USES_INT_STEP: i32 = 1 << 3;
    pub const SUPPORTS_DISPLAY_INDEX: i32 = 1 << 4;
    pub const SUPPORTS_DISPLAY_CATEGORY: i32 = 1 << 5;
    pub const CAN_RAMP: i32 = 1 << 6;
}

#[repr(C)]
#[derive(Copy, Clone)]
pub struct AEffect {
    pub magic: i32,
    pub dispatcher: extern "C" fn(*mut AEffect, i32, i32, isize, *mut c_void, f32) -> isize,
    pub process: extern "C" fn(*mut AEffect, *const *const f32, *mut *mut f32, i32),
    pub set_parameter: extern "C" fn(*mut AEffect, i32, f32),
    pub get_parameter: extern "C" fn(*mut AEffect, i32) -> f32,
    pub num_programs: i32,
    pub num_params: i32,
    pub num_inputs: i32,
    pub num_outputs: i32,
    pub flags: i32,
    pub ptr_1: *mut c_void,
    pub ptr_2: *mut c_void,
    pub initial_delay: i32,
    pub empty_2: [u8; 4 + 4],
    pub unknown_float: f32,
    pub object: *mut c_void,
    pub user: *mut c_void,
    pub unique_id: i32,
    pub version: i32,
    pub process_replacing: extern "C" fn(*mut AEffect, *const *const f32, *mut *mut f32, i32),
    pub process_double_replacing: extern "C" fn(*mut AEffect, *const *const f64, *mut *mut f64, i32),
}

#[repr(C)]
#[derive(Copy, Clone)]
pub struct TimeInfo {
    pub sample_pos: f64,
    pub sample_rate: f64,
    pub nano_seconds: f64,
    pub ppq_pos: f64,
    pub tempo: f64,
    pub bar_start_pos: f64,
    pub cycle_start_pos: f64,
    pub cycle_end_pos: f64,
    pub time_sig_numerator: i32,
    pub time_sig_denominator: i32,
    pub smpte_offset: i32,
    pub smpte_frame_rate: i32,
    pub samples_to_next_clock: i32,
    pub flags: i32,
}

#[repr(C)]
#[derive(Copy, Clone)]
pub struct Rect {
    pub top: i16,
    pub left: i16,
    pub bottom: i16,
    pub right: i16,
}

pub type HostCallbackProc = extern "C" fn(*mut AEffect, i32, i32, isize, *mut c_void, f32) -> isize;