Skip to main content

virtualdj_plugin_sdk/
ffi.rs

1//! VirtualDJ Rust SDK - FFI Bindings
2//! 
3//! Raw FFI bindings to the C ABI layer. These are low-level unsafe wrappers
4//! around the C ABI functions. Use the safe API in the parent module for higher-level access.
5
6#![allow(non_camel_case_types)]
7#![allow(non_snake_case)]
8
9use std::ffi::c_void;
10
11/* ============================================================================
12   Types and Constants
13   ============================================================================ */
14
15pub type HRESULT = i32;
16pub type DWORD = u32;
17pub type ULONG = u32;
18
19pub const S_OK: HRESULT = 0x00000000;
20pub const S_FALSE: HRESULT = 0x00000001;
21pub const E_NOTIMPL: HRESULT = 0x80004001u32 as i32;
22pub const E_FAIL: HRESULT = 0x80004005u32 as i32;
23
24/* Plugin parameter types */
25pub const VDJPARAM_BUTTON: i32 = 0;
26pub const VDJPARAM_SLIDER: i32 = 1;
27pub const VDJPARAM_SWITCH: i32 = 2;
28pub const VDJPARAM_STRING: i32 = 3;
29pub const VDJPARAM_CUSTOM: i32 = 4;
30pub const VDJPARAM_RADIO: i32 = 5;
31pub const VDJPARAM_COMMAND: i32 = 6;
32pub const VDJPARAM_COLORFX: i32 = 7;
33pub const VDJPARAM_BEATS: i32 = 8;
34pub const VDJPARAM_BEATS_RELATIVE: i32 = 9;
35pub const VDJPARAM_POSITION: i32 = 10;
36pub const VDJPARAM_RELEASEFX: i32 = 11;
37pub const VDJPARAM_TRANSITIONFX: i32 = 12;
38
39/* Plugin flags */
40pub const VDJFLAG_NODOCK: DWORD = 0x1;
41pub const VDJFLAG_PROCESSAFTERSTOP: DWORD = 0x2;
42pub const VDJFLAG_PROCESSFIRST: DWORD = 0x4;
43pub const VDJFLAG_PROCESSLAST: DWORD = 0x8;
44pub const VDJFLAG_EXTENSION1: DWORD = 0x10;
45pub const VDJFLAG_SETPREVIEW: DWORD = 0x20;
46pub const VDJFLAG_POSITION_NOSLIP: DWORD = 0x40;
47pub const VDJFLAG_ALWAYSPREFADER: DWORD = 0x80;
48pub const VDJFLAG_ALWAYSPOSTFADER: DWORD = 0x100;
49pub const VDJFLAG_EPHEMERAL: DWORD = 0x200;
50
51/* Video-specific flags */
52pub const VDJFLAG_VIDEO_MASTERONLY: DWORD = 0x10000;
53pub const VDJFLAG_VIDEO_VISUALISATION: DWORD = 0x20000;
54pub const VDJFLAG_VIDEO_OVERLAY: DWORD = 0x40000;
55pub const VDJFLAG_VIDEO_HASRESIZE: DWORD = 0x80000;
56pub const VDJFLAG_VIDEO_NOAUTOACTIVE: DWORD = 0x200000;
57pub const VDJFLAG_VIDEO_OUTPUTRESOLUTION: DWORD = 0x400000;
58pub const VDJFLAG_VIDEO_OUTPUTASPECTRATIO: DWORD = 0x800000;
59pub const VDJFLAG_VIDEO_FORRECORDING: DWORD = 0x1000000;
60pub const VDJFLAG_VIDEOTRANSITION_CONTINOUS: DWORD = 0x100000;
61
62/* Video engines */
63#[repr(C)]
64#[derive(Clone, Copy, Debug)]
65pub enum EVdjVideoEngine {
66    VdjVideoEngineAny = 0,
67    VdjVideoEngineDirectX9 = 1,
68    VdjVideoEngineOpenGL = 2,
69    VdjVideoEngineDirectX11 = 3,
70    VdjVideoEngineOpenGLES2 = 4,
71    VdjVideoEngineMetal = 5,
72    VdjVideoEngineAnyPtr = 6,
73}
74
75/* ============================================================================
76   Opaque Plugin Handles
77   ============================================================================ */
78
79#[repr(C)]
80pub struct VdjPlugin {
81    _priv: [u8; 0],
82}
83
84#[repr(C)]
85pub struct VdjPluginDsp {
86    _priv: [u8; 0],
87}
88
89#[repr(C)]
90pub struct VdjPluginBufferDsp {
91    _priv: [u8; 0],
92}
93
94#[repr(C)]
95pub struct VdjPluginPositionDsp {
96    _priv: [u8; 0],
97}
98
99#[repr(C)]
100pub struct VdjPluginVideoFx {
101    _priv: [u8; 0],
102}
103
104#[repr(C)]
105pub struct VdjPluginVideoTransition {
106    _priv: [u8; 0],
107}
108
109#[repr(C)]
110pub struct VdjPluginVideoTransitionMultiDeck {
111    _priv: [u8; 0],
112}
113
114#[repr(C)]
115pub struct VdjPluginOnlineSource {
116    _priv: [u8; 0],
117}
118
119/* ============================================================================
120   Callback Structures
121   ============================================================================ */
122
123#[repr(C)]
124pub struct VdjCallbacks {
125    pub send_command: extern "C" fn(*mut VdjPlugin, *const u8) -> HRESULT,
126    pub get_info: extern "C" fn(*mut VdjPlugin, *const u8, *mut f64) -> HRESULT,
127    pub get_string_info: extern "C" fn(*mut VdjPlugin, *const u8, *mut u8, i32) -> HRESULT,
128    pub declare_parameter: extern "C" fn(*mut VdjPlugin, *mut c_void, i32, i32, *const u8, *const u8, f32) -> HRESULT,
129    pub get_song_buffer: extern "C" fn(*mut VdjPlugin, i32, i32, *mut *mut i16) -> HRESULT,
130}
131
132#[repr(C)]
133pub struct VdjVideoMouseCallbacks {
134    pub on_mouse_move: extern "C" fn(*mut VdjPlugin, i32, i32, i32, i32) -> i32,
135    pub on_mouse_down: extern "C" fn(*mut VdjPlugin, i32, i32, i32, i32) -> i32,
136    pub on_mouse_up: extern "C" fn(*mut VdjPlugin, i32, i32, i32, i32) -> i32,
137    pub on_key: extern "C" fn(*mut VdjPlugin, *const u8, i32, i32, i32, i32),
138}
139
140#[repr(C)]
141pub struct VdjVideoCallbacks {
142    pub draw_deck: extern "C" fn(*mut VdjPlugin) -> HRESULT,
143    pub get_device: extern "C" fn(*mut VdjPlugin, EVdjVideoEngine, *mut *mut c_void) -> HRESULT,
144    pub get_texture: extern "C" fn(*mut VdjPlugin, EVdjVideoEngine, *mut *mut c_void, *mut *mut c_void) -> HRESULT,
145}
146
147/* ============================================================================
148   Plugin Info Structure
149   ============================================================================ */
150
151#[repr(C)]
152pub struct VdjPluginInfo {
153    pub plugin_name: *const u8,
154    pub author: *const u8,
155    pub description: *const u8,
156    pub version: *const u8,
157    pub bitmap: *mut c_void,
158    pub flags: DWORD,
159}
160
161/* ============================================================================
162   Core Plugin FFI Functions
163   ============================================================================ */
164
165extern "C" {
166    pub fn vdj_plugin_create() -> *mut VdjPlugin;
167    pub fn vdj_plugin_release(plugin: *mut VdjPlugin);
168    pub fn vdj_plugin_init(plugin: *mut VdjPlugin, callbacks: *const VdjCallbacks) -> HRESULT;
169    pub fn vdj_plugin_on_load(plugin: *mut VdjPlugin) -> HRESULT;
170    pub fn vdj_plugin_get_info(plugin: *mut VdjPlugin, info: *mut VdjPluginInfo) -> HRESULT;
171    pub fn vdj_plugin_on_parameter(plugin: *mut VdjPlugin, id: i32) -> HRESULT;
172    pub fn vdj_plugin_on_get_parameter_string(plugin: *mut VdjPlugin, id: i32, out_param: *mut u8, out_param_size: i32) -> HRESULT;
173}
174
175/* ============================================================================
176   DSP Plugin FFI Functions
177   ============================================================================ */
178
179extern "C" {
180    pub fn vdj_plugin_dsp_create() -> *mut VdjPluginDsp;
181    pub fn vdj_plugin_dsp_release(plugin: *mut VdjPluginDsp);
182    pub fn vdj_plugin_dsp_init(plugin: *mut VdjPluginDsp, callbacks: *const VdjCallbacks) -> HRESULT;
183    pub fn vdj_plugin_dsp_on_start(plugin: *mut VdjPluginDsp) -> HRESULT;
184    pub fn vdj_plugin_dsp_on_stop(plugin: *mut VdjPluginDsp) -> HRESULT;
185    pub fn vdj_plugin_dsp_on_process_samples(plugin: *mut VdjPluginDsp, buffer: *mut f32, nb: i32) -> HRESULT;
186    pub fn vdj_plugin_dsp_get_info(plugin: *mut VdjPluginDsp, info: *mut VdjPluginInfo) -> HRESULT;
187    pub fn vdj_plugin_dsp_get_sample_rate(plugin: *mut VdjPluginDsp) -> i32;
188    pub fn vdj_plugin_dsp_get_song_bpm(plugin: *mut VdjPluginDsp) -> i32;
189    pub fn vdj_plugin_dsp_get_song_pos_beats(plugin: *mut VdjPluginDsp) -> f64;
190}
191
192/* ============================================================================
193   Buffer DSP Plugin FFI Functions
194   ============================================================================ */
195
196extern "C" {
197    pub fn vdj_plugin_buffer_dsp_create() -> *mut VdjPluginBufferDsp;
198    pub fn vdj_plugin_buffer_dsp_release(plugin: *mut VdjPluginBufferDsp);
199    pub fn vdj_plugin_buffer_dsp_init(plugin: *mut VdjPluginBufferDsp, callbacks: *const VdjCallbacks) -> HRESULT;
200    pub fn vdj_plugin_buffer_dsp_on_start(plugin: *mut VdjPluginBufferDsp) -> HRESULT;
201    pub fn vdj_plugin_buffer_dsp_on_stop(plugin: *mut VdjPluginBufferDsp) -> HRESULT;
202    pub fn vdj_plugin_buffer_dsp_on_get_song_buffer(plugin: *mut VdjPluginBufferDsp, song_pos: i32, nb: i32) -> *mut i16;
203    pub fn vdj_plugin_buffer_dsp_get_song_buffer(plugin: *mut VdjPluginBufferDsp, pos: i32, nb: i32, buffer: *mut *mut i16) -> HRESULT;
204    pub fn vdj_plugin_buffer_dsp_get_sample_rate(plugin: *mut VdjPluginBufferDsp) -> i32;
205    pub fn vdj_plugin_buffer_dsp_get_song_bpm(plugin: *mut VdjPluginBufferDsp) -> i32;
206    pub fn vdj_plugin_buffer_dsp_get_song_pos(plugin: *mut VdjPluginBufferDsp) -> i32;
207    pub fn vdj_plugin_buffer_dsp_get_song_pos_beats(plugin: *mut VdjPluginBufferDsp) -> f64;
208}
209
210/* ============================================================================
211   Position DSP Plugin FFI Functions
212   ============================================================================ */
213
214extern "C" {
215    pub fn vdj_plugin_position_dsp_create() -> *mut VdjPluginPositionDsp;
216    pub fn vdj_plugin_position_dsp_release(plugin: *mut VdjPluginPositionDsp);
217    pub fn vdj_plugin_position_dsp_init(plugin: *mut VdjPluginPositionDsp, callbacks: *const VdjCallbacks) -> HRESULT;
218    pub fn vdj_plugin_position_dsp_on_start(plugin: *mut VdjPluginPositionDsp) -> HRESULT;
219    pub fn vdj_plugin_position_dsp_on_stop(plugin: *mut VdjPluginPositionDsp) -> HRESULT;
220    pub fn vdj_plugin_position_dsp_on_transform_position(plugin: *mut VdjPluginPositionDsp, song_pos: *mut f64, video_pos: *mut f64, volume: *mut f32, src_volume: *mut f32) -> HRESULT;
221    pub fn vdj_plugin_position_dsp_on_process_samples(plugin: *mut VdjPluginPositionDsp, buffer: *mut f32, nb: i32) -> HRESULT;
222    pub fn vdj_plugin_position_dsp_get_sample_rate(plugin: *mut VdjPluginPositionDsp) -> i32;
223    pub fn vdj_plugin_position_dsp_get_song_bpm(plugin: *mut VdjPluginPositionDsp) -> i32;
224    pub fn vdj_plugin_position_dsp_get_song_pos(plugin: *mut VdjPluginPositionDsp) -> i32;
225    pub fn vdj_plugin_position_dsp_get_song_pos_beats(plugin: *mut VdjPluginPositionDsp) -> f64;
226}
227
228/* ============================================================================
229   Video FX Plugin FFI Functions
230   ============================================================================ */
231
232extern "C" {
233    pub fn vdj_plugin_video_fx_create() -> *mut VdjPluginVideoFx;
234    pub fn vdj_plugin_video_fx_release(plugin: *mut VdjPluginVideoFx);
235    pub fn vdj_plugin_video_fx_init(plugin: *mut VdjPluginVideoFx, callbacks: *const VdjCallbacks, video_callbacks: *const VdjVideoCallbacks) -> HRESULT;
236    pub fn vdj_plugin_video_fx_on_start(plugin: *mut VdjPluginVideoFx) -> HRESULT;
237    pub fn vdj_plugin_video_fx_on_stop(plugin: *mut VdjPluginVideoFx) -> HRESULT;
238    pub fn vdj_plugin_video_fx_on_draw(plugin: *mut VdjPluginVideoFx) -> HRESULT;
239    pub fn vdj_plugin_video_fx_on_device_init(plugin: *mut VdjPluginVideoFx) -> HRESULT;
240    pub fn vdj_plugin_video_fx_on_device_close(plugin: *mut VdjPluginVideoFx) -> HRESULT;
241    pub fn vdj_plugin_video_fx_on_audio_samples(plugin: *mut VdjPluginVideoFx, buffer: *mut f32, nb: i32) -> HRESULT;
242    pub fn vdj_plugin_video_fx_get_width(plugin: *mut VdjPluginVideoFx) -> i32;
243    pub fn vdj_plugin_video_fx_get_height(plugin: *mut VdjPluginVideoFx) -> i32;
244    pub fn vdj_plugin_video_fx_get_sample_rate(plugin: *mut VdjPluginVideoFx) -> i32;
245    pub fn vdj_plugin_video_fx_get_song_bpm(plugin: *mut VdjPluginVideoFx) -> i32;
246    pub fn vdj_plugin_video_fx_get_song_pos_beats(plugin: *mut VdjPluginVideoFx) -> f64;
247}
248
249/* ============================================================================
250   Video Transition Plugin FFI Functions
251   ============================================================================ */
252
253extern "C" {
254    pub fn vdj_plugin_video_transition_create() -> *mut VdjPluginVideoTransition;
255    pub fn vdj_plugin_video_transition_release(plugin: *mut VdjPluginVideoTransition);
256    pub fn vdj_plugin_video_transition_init(plugin: *mut VdjPluginVideoTransition, callbacks: *const VdjCallbacks, video_callbacks: *const VdjVideoCallbacks) -> HRESULT;
257    pub fn vdj_plugin_video_transition_on_draw(plugin: *mut VdjPluginVideoTransition, crossfader: f32) -> HRESULT;
258    pub fn vdj_plugin_video_transition_on_device_init(plugin: *mut VdjPluginVideoTransition) -> HRESULT;
259    pub fn vdj_plugin_video_transition_on_device_close(plugin: *mut VdjPluginVideoTransition) -> HRESULT;
260    pub fn vdj_plugin_video_transition_get_width(plugin: *mut VdjPluginVideoTransition) -> i32;
261    pub fn vdj_plugin_video_transition_get_height(plugin: *mut VdjPluginVideoTransition) -> i32;
262    pub fn vdj_plugin_video_transition_get_sample_rate(plugin: *mut VdjPluginVideoTransition) -> i32;
263    pub fn vdj_plugin_video_transition_get_song_bpm(plugin: *mut VdjPluginVideoTransition) -> i32;
264    pub fn vdj_plugin_video_transition_get_song_pos_beats(plugin: *mut VdjPluginVideoTransition) -> f64;
265}
266
267/* ============================================================================
268   Online Source Plugin FFI Functions
269   ============================================================================ */
270
271extern "C" {
272    pub fn vdj_plugin_online_source_create() -> *mut VdjPluginOnlineSource;
273    pub fn vdj_plugin_online_source_release(plugin: *mut VdjPluginOnlineSource);
274    pub fn vdj_plugin_online_source_init(plugin: *mut VdjPluginOnlineSource, callbacks: *const VdjCallbacks) -> HRESULT;
275    pub fn vdj_plugin_online_source_is_logged(plugin: *mut VdjPluginOnlineSource) -> HRESULT;
276    pub fn vdj_plugin_online_source_on_login(plugin: *mut VdjPluginOnlineSource) -> HRESULT;
277    pub fn vdj_plugin_online_source_on_logout(plugin: *mut VdjPluginOnlineSource) -> HRESULT;
278    pub fn vdj_plugin_online_source_on_search(plugin: *mut VdjPluginOnlineSource, search: *const u8, tracks_list: *mut c_void) -> HRESULT;
279    pub fn vdj_plugin_online_source_on_search_cancel(plugin: *mut VdjPluginOnlineSource) -> HRESULT;
280}