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
//! Mechanisms for defining the meta-data of a plugin or application.
//!
//! `rsynth` uses a hierarchy of different traits that allow your audio application
//! or plug-in to define various aspects of the meta-data.
//!
//! Implementing each of these traits one by one can be rather tedious.
//! For this reason, these traits have blanket impls, so that you only need
//! to implement the [`Meta`] trait and in its implementation, return the
//! meta-data.
//!
//! Example
//! -------
//! ```
//! use rsynth::meta::{Meta, MetaData, InOut};
//! struct MyPlugin {
//! meta: MetaData<&'static str, &'static str, &'static str>
//! /* ... */
//! }
//!
//! impl MyPlugin {
//! pub fn new() -> Self {
//! Self {
//! meta: MetaData {
//! general_meta: unimplemented!(),
//! audio_port_meta: InOut {
//! inputs: vec![unimplemented!()],
//! outputs: vec![unimplemented!()],
//! },
//! midi_port_meta: InOut {
//! inputs: vec![unimplemented!()],
//! outputs: vec![unimplemented!()],
//! },
//! }
//! }
//! }
//! }
//!
//! impl Meta for MyPlugin {
//! type MetaData = MetaData<&'static str, &'static str, &'static str>;
//! fn meta(&self) -> &Self::MetaData {
//! &self.meta
//! }
//! }
//! ```
//!
//! # How it works under the hood
//!
//! Back-ends may require the plugin to implement a number of traits concerning meta-data.
//! Suppose for instance a backend requires plugins to implement the `CommonPluginMeta` trait.
//! The `CommonPluginMeta` trait defines the "name" of the plugin.
//! There is a blanket impl that implements the `CommonPluginMeta` for any type that
//! implements `Meta` where the associated type `Meta::MetaData` implements the `General` trait
//! (which allows getting general meta-data) where the associated type `General::GeneralData`
//! implements the `Name` trait.
//! Now the `MetaData<G, _, _>` struct implements `General` with associated type
//! `General::GeneralData` equal to `G`.
//! Also, `Name` is implemented for `String` and for `&'static str`.
//! So if a plugin implements `Meta` with the associated type `Meta::MetaData` equal to the struct
//! `MetaData<&'static str, _, _>`, then it automatically implements `CommonPluginMeta`.
/// Define the meta-data for an application or plug-in.
///
/// See the [module level documentation] for more details.
///
/// [module level documentation]: ./index.html
/// [`MetaData`]: ./struct.MetaData.html
/// [`Meta`]: ./trait.Meta.html
/// Define meta-data of an application or plugin as a whole.
/// Implement this trait to indicate that a type can be used to represent
/// meta-data that contains a name.
/// Define meta-data for input ports and output ports.
///
/// The type parameter `T` is a dummy type parameter so that meta-data for different types of
/// ports can be defined.
/// Typical values for `T` are [`MidiPort`] and [`AudioPort`].
///
/// Example
/// -------
/// ```
/// use rsynth::meta::{Port, MidiPort, AudioPort};
/// struct MyMetaData {
/// audio_input_port_names: Vec<String>,
/// audio_output_port_names: Vec<String>,
/// midi_input_port_names: Vec<String>,
/// midi_output_port_names: Vec<String>,
/// }
///
/// impl Port<AudioPort> for MyMetaData {
/// type PortData = String;
/// fn in_ports(&self) -> &[Self::PortData] {
/// self.audio_input_port_names.as_slice()
/// }
/// fn out_ports(&self) -> &[Self::PortData] {
/// self.audio_output_port_names.as_slice()
/// }
/// }
///
/// impl Port<MidiPort> for MyMetaData {
/// type PortData = String;
/// fn in_ports(&self) -> &[Self::PortData] {
/// self.audio_input_port_names.as_slice()
/// }
/// fn out_ports(&self) -> &[Self::PortData] {
/// self.audio_output_port_names.as_slice()
/// }
/// }
/// ```
///
/// Note
/// ----
/// For most use cases, you can use the pre-defined [`MetaData`] struct, which already implements
/// `Port<MidiPort>` and `Port<AudioPort>`.
///
/// [`MidiPort`]: ./struct.MidiPort.html
/// [`AudioPort`]: ./struct.AudioPort.html
/// [`MetaData`]: ./struct.MetaData.html
/// A "marker" struct to be used as a type parameter for the [`Port`] trait, indicating
/// that this implementation of [`Port`] defines meta-data for an audio port.
///
/// [`Port`]: ./trait.Port.html
;
/// A "marker" struct to be used as a type parameter for the [`Port`] trait, indicating
/// that this implementation of [`Port`] defines meta-data for a midi port.
///
/// [`Port`]: ./trait.Port.html
;
/// Represents general-purpose meta-data of an audio application or plugin.
///
/// See the [module level documentation] for an example.
///
/// The struct `MetaData<G, AP, MP>` has three type parameters:
/// * `G`: the data type of the "general" meta-data.
/// * `AP`: the data type of the meta-data for the audio ports
/// * `MP`: the data type of the meta-data for the midi ports
/// [module level documentation]: ./index.html
/// Represents meta-data about a input and output ports.
///
/// See the documentation of the [`MetaData`] struct for more information.
///
/// [`MetaData`]: ./struct.MetaData.html