1#![allow(non_camel_case_types)]
6
7use std::ffi::{c_void, CStr};
8
9use num_derive::{FromPrimitive, ToPrimitive};
10
11use crate::ffi::ffgl1;
12use crate::ffi::ffgl2::*;
13
14#[repr(u32)]
15#[derive(FromPrimitive, Debug, Clone, Copy)]
16pub enum Op {
17 GetInfo = FF_GET_INFO,
18 Initialise,
19 Deinitialise,
20 ProcessFrame,
21 GetNumParameters,
22 GetParameterName,
23 GetParameterDefault,
24 GetParameterDisplay,
25 SetParameter,
26 GetParameter,
27 GetPluginCaps,
28 Instantiate,
29 Deinstantiate,
30 GetExtendedInfo,
31 ProcessFrameCopy,
32 GetParameterType,
33 GetInputStatus,
34
35 ProcessOpenGL,
36 InstantiateGL,
37 DeinstantiateGL,
38 SetTime,
39 Connect,
40 Disconnect,
41 Resize,
42 InitialiseV2 = FF_INITIALISE_V2,
43
44 GetPluginShortName = FF_GET_PLUGIN_SHORT_NAME,
46
47 SetBeatInfo = FF_SET_BEATINFO,
48 SetHostInfo,
49 SetSampleRate,
50
51 GetThumbnail = FF_GET_THUMBNAIL,
52
53 GetParameterEvents = FF_GET_PARAMETER_EVENTS,
54
55 GetParameterRange = FF_GET_RANGE,
56 GetParameterVisibility = FF_GET_PRAMETER_VISIBILITY,
57 GetParameterGroup = FF_GET_PARAM_GROUP,
58
59 EnablePluginCap = FF_ENABLE_PLUGIN_CAP,
60}
61
62impl TryFrom<u32> for Op {
63 type Error = ();
64
65 fn try_from(value: u32) -> Result<Self, Self::Error> {
66 num::FromPrimitive::from_u32(value).ok_or(())
67 }
68}
69
70#[repr(u32)]
71#[derive(FromPrimitive, Debug)]
72pub enum PluginCapacity {
73 Video16b = ffgl1::FF_CAP_16BITVIDEO,
75 Video24 = ffgl1::FF_CAP_24BITVIDEO,
76 Video32 = ffgl1::FF_CAP_32BITVIDEO,
77 ProcessFrameCopy = ffgl1::FF_CAP_PROCESSFRAMECOPY,
78
79 ProcessOpenGl = ffgl1::FF_CAP_PROCESSOPENGL,
80
81 SetTime = FF_CAP_SET_TIME,
82
83 MinInputFrames = FF_CAP_MINIMUM_INPUT_FRAMES,
84 MaxInputFrames = FF_CAP_MAXIMUM_INPUT_FRAMES,
85
86 TopLeftTextureOrientation = FF_CAP_TOP_LEFT_TEXTURE_ORIENTATION,
87}
88
89#[repr(u32)]
90#[derive(FromPrimitive, ToPrimitive, Debug)]
91pub enum SupportVal {
92 Supported = FF_SUPPORTED,
93 Unsupported = FF_UNSUPPORTED,
94}
95
96#[repr(u32)]
97#[derive(FromPrimitive, Debug)]
98pub enum SuccessVal {
99 Success = FF_SUCCESS,
100 Fail = FF_FAIL,
101}
102
103#[repr(u32)]
104#[derive(FromPrimitive, Debug)]
105pub enum BoolVal {
106 True = FF_TRUE,
107 False = FF_FALSE,
108}
109
110#[repr(C)]
111pub union FFGLVal {
112 pub num: u32,
113 ptr: *const c_void,
114}
115
116impl std::fmt::Debug for FFGLVal {
117 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
118 f.debug_struct("FFGLVal")
119 .field("num", unsafe { &self.num })
120 .finish()
121 }
122}
123
124impl From<&'static CStr> for FFGLVal {
125 fn from(a: &'static CStr) -> Self {
126 Self {
127 ptr: a.as_ptr() as *const c_void,
128 }
129 }
130}
131
132impl<T> From<&'static T> for FFGLVal {
133 fn from(a: &'static T) -> Self {
134 Self::from_static(a)
135 }
136}
137
138impl From<f32> for FFGLVal {
139 fn from(a: f32) -> Self {
140 Self {
141 num: unsafe { std::mem::transmute(a) },
142 }
143 }
144}
145
146impl<T> From<&'static mut T> for FFGLVal {
147 fn from(a: &'static mut T) -> Self {
148 Self::from_static(a)
149 }
150}
151
152impl FFGLVal {
153 pub fn from_static<T: ?Sized>(a: &'static T) -> Self {
155 Self {
156 ptr: a as *const _ as *const c_void,
157 }
158 }
159
160 pub unsafe fn as_ref<T>(&self) -> &T {
161 &*(self.ptr as *const T)
162 }
163
164 pub unsafe fn as_mut<T>(&mut self) -> &mut T {
165 &mut *(self.ptr as *mut T)
166 }
167}
168
169impl Into<FFGLVal> for SuccessVal {
170 fn into(self) -> FFGLVal {
171 FFGLVal { num: self as u32 }
172 }
173}
174impl Into<FFGLVal> for BoolVal {
175 fn into(self) -> FFGLVal {
176 FFGLVal { num: self as u32 }
177 }
178}
179impl Into<FFGLVal> for SupportVal {
180 fn into(self) -> FFGLVal {
181 FFGLVal { num: self as u32 }
182 }
183}