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
//! MKAU plugin format for modular audio processing chains.
//!
//! This module provides the `Processor` trait for implementing audio plugins
//! and a loader function for dynamically loading `.mkap` plugin files.
//!
//! ## Example Plugin Implementation
//!
//! ```ignore
//! use mkaudiolibrary::buffer::Buffer;
//! use mkaudiolibrary::processor::Processor;
//!
//! struct GainPlugin
//! {
//! parameters : [(String, f64); 1],
//! internal_buffer : Buffer<f64>
//! }
//!
//! impl GainPlugin
//! {
//! fn new() -> Self
//! {
//! Self
//! {
//! parameters : [(String::from("Gain"), 0.5)],
//! internal_buffer : Buffer::new(1024)
//! }
//! }
//! }
//!
//! impl Processor for GainPlugin
//! {
//! fn init(&mut self) {}
//! fn name(&self) -> String { String::from("Gain") }
//! fn get_parameter(&self, index : usize) -> f64 { self.parameters[index].1 }
//! fn set_parameter(&mut self, index : usize, value : f64) { self.parameters[index].1 = value; }
//! fn get_parameter_name(&self, index : usize) -> String { self.parameters[index].0.clone() }
//! fn open_window(&self) {}
//! fn close_window(&self) {}
//!
//! fn prepare_to_play(&mut self, buffer_size : usize, _sample_rate : usize)
//! {
//! self.internal_buffer.resize(buffer_size);
//! }
//!
//! fn run(&self, input : &[&[f64]], _sidechain_in : &[&[f64]],
//! output : &mut [&mut [f64]], _sidechain_out : &mut [&mut [f64]])
//! {
//! let gain = self.parameters[0].1;
//! for channel in 0..input.len()
//! {
//! for sample in 0..input[channel].len()
//! {
//! output[channel][sample] = input[channel][sample] * gain;
//! }
//! }
//! }
//! }
//!
//! mkaudiolibrary::declare_plugin!(GainPlugin, GainPlugin::new);
//! ```
//!
//! ## Loading Plugins
//!
//! ```ignore
//! use mkaudiolibrary::processor::load;
//!
//! // Load a plugin from /path/to/plugins/myplugin.mkap
//! let plugin = load("/path/to/plugins", "myplugin").expect("Failed to load plugin");
//! println!("Loaded: {}", plugin.name());
//! ```
extern crate libloading;
use ;
/// Declare a plugin for dynamic loading.
///
/// This macro generates the `_create` extern function required for
/// loading the plugin as a `.mkap` dynamic library.
///
/// # Arguments
/// * `$plugin_type` - The type implementing `Processor`
/// * `$constructor` - Path to the constructor function (e.g., `MyPlugin::new`)
/// Audio processor trait for MKAU plugins.
///
/// Implement this trait to create an audio plugin that can be loaded
/// dynamically or used directly in a processing chain.
/// Load a plugin from a `.mkap` dynamic library file.
///
/// # Arguments
/// * `path` - Directory containing the plugin file
/// * `name` - Plugin name (without `.mkap` extension)
///
/// # Returns
/// A boxed `Processor` trait object on success, or a loading error.
///
/// # Safety
/// This function loads and executes code from an external library.
/// Only load plugins from trusted sources.