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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
//! # Rsynth
//! A crate for developing audio plugins and applications in Rust, with a focus on software synthesis.
//! Rsynth is well suited as a bootstrap for common audio plugin generators.
//! It handles voices, voice-stealing, polyphony, etc. so the programmer's main focus can be DSP.
//!
//! ## Deprecation notice
//! This crate has been deprecated. See its README.md for more details.
//!
//! ## Back-ends
//! `rsynth` currently supports the following back-ends:
//!
//! * [`combined`] combine different back-ends for audio input, audio output, midi input and
//! midi output, mostly for offline rendering and testing (behind various features)
//! * [`jack`] (behind the `backend-jack` feature)
//! * [`vst`] (behind the `backend-vst` feature)
//!
//! See the documentation of each back-end for more information.
//!
//! ## Rendering audio
//! Audio can be rendered by using a number of traits:
//!
//! * the [`AudioRenderer`] trait
//! * the [`ContextualAudioRenderer`] trait
//!
//! The difference between these traits is that the [`ContextualAudioRenderer`] trait adds one extra
//! parameter that defines a "context" that can be passed to the implementor of the trait, so that
//! the implementor of the trait does not need to own all data that is needed for rendering the
//! audio; it can also borrow some data with additional the `context` parameter.
//!
//! Both traits are generic over the data type that represents the sample.
//! For which specific data-type an application or plugin needs to implement the trait, depends on
//! the back-end. Because the trait is generic, the application or plugin can have a generic implementation
//! as well that can be used by different back-ends.
//!
//! ## Meta-data
//! There are a number of traits that an application or plugin needs to implement in order to define meta-data.
//! Every plugin should implement these, but it can be tedious, so you can implement these
//! traits in a more straightforward way by implementing the [`Meta`] trait.
//! However, you can also implement these trait "by hand":
//!
//! * [`CommonPluginMeta`]
//! * Name of the plugin etc
//! * [`AudioHandlerMeta`]
//! * Number of audio ports
//! * [`MidiHandlerMeta`]
//! * Number of midi ports
//! * [`CommonAudioPortMeta`]
//! * Names of the audio in and out ports
//! * [`CommonPluginMeta`]
//! * Name of the plugin or application
//!
//! Additionally, back-ends can require extra trait related to meta-data.
//!
//! ## Handling events
//! Plugins or application can handle events by implementing a number of traits:
//!
//! * [`EventHandler`]
//! * [`ContextualEventHandler`]
//!
//! Both traits are generic over the event type.
//! These traits are very similar, the [`ContextualEventHandler`] trait adds one extra parameter
//! that defines a "context" that can be passed to the implementor of the trait, so that the
//! implementor of the trait does not need to own all data that is needed for handling the event;
//! it can also borrow some data with additional the `context` parameter.
//!
//! ### Events
//! `rsynth` defines a number of event types:
//!
//! * [`RawMidiEvent`]: a raw MIDI event
//! * [`SysExEvent`]: a system exclusive event
//! * [`Timed<T>`]: a generic timed event
//! * [`Indexed<T>`]: a generic event that associates a timestamp with the event
//!
//! ## Utilities
//! Utilities are are types that you can include to perform several common tasks for the
//! plugin or application:
//!
//! * [polyphony]: managing of different voices
//!
//! [`jack`]: ./backend/jack_backend/index.html
//! [`vst`]: ./backend/vst_backend/index.html
//! [`combined`]: ./backend/combined/index.html
//! [`EventHandler`]: ./event/trait.EventHandler.html
//! [`RawMidiEvent`]: ./event/struct.RawMidiEvent.html
//! [`SysExEvent`]: ./event/struct.SysExEvent.html
//! [`Timed<T>`]: ./event/struct.Timed.html
//! [`Indexed<T>`]: ./event/struct.Indexed.html
//! [`CommonPluginMeta`]: ./trait.CommonPluginMeta.html
//! [`AudioHandlerMeta`]: ./trait.AudioHandlerMeta.html
//! [`MidiHandlerMeta`]: ./trait.MidiHandlerMeta.html
//! [`CommonAudioPortMeta`]: ./trait.CommonAudioPortMeta.html
//! [`Meta`]: ./meta/trait.Meta.html
//! [`AudioRenderer`]: ./trait.AudioRenderer.html
//! [`ContextualAudioRenderer`]: trait.ContextualAudioRenderer.html
//! [`ContextualEventHandler`]: ./event/trait.ContextualEventHandler.html
//! [`EventHandler`]: ./event/trait.EventHandler.html
//! [polyphony]: ./utilities/polyphony/index.html
extern crate log;
extern crate num_traits;
extern crate vecstorage;
extern crate hound;
extern crate jack;
extern crate sample;
extern crate vst;
extern crate doc_comment;
use crateAudioBufferInOut;
use crate;
doctest!;
/// Define the maximum number of audio inputs and the maximum number of audio outputs.
///
/// Backends that require the plugin to implement this trait ensure that when calling the
/// [`render_buffer`] method of the [`AudioRenderer`] trait
/// * the number of inputs channels (`buffer.number_of_input_channels()`) is smaller than or equal to
/// `Self::max_number_of_audio_inputs()` and
/// * the number of outputs (`buffer.number_of_output_channels()`) is smaller than or equal to
/// `Self::max_number_of_audio_outputs()`.
///
/// # Remark
/// This trait can be more conveniently implemented by implementing the [`Meta`] trait.
///
/// [`Meta`]: ./meta/trait.Meta.html
/// [`render_buffer`]: ./trait.AudioRenderer.html#tymethod.render_buffer
/// [`AudioRenderer`]: ./trait.AudioRenderer.html
/// Define how sample-rate changes are handled.
/// Define the maximum number of midi inputs and the maximum number of midi outputs.
/// This trait can be more conveniently implemented by implementing the [`Meta`] trait.
///
/// [`Meta`]: ./meta/trait.Meta.html
// TODO: Is this trait actually used?
/// Defines how audio is rendered.
///
/// The type parameter `S` refers to the data type of a sample.
/// It is typically `f32` or `f64`.
/// Defines how audio is rendered, similar to the [`AudioRenderer`] trait.
/// The extra parameter `context` can be used by the backend to provide extra information.
///
/// The type parameter `S` refers to the data type of a sample.
/// It is typically `f32` or `f64`.
///
/// [`AudioRenderer`]: ./trait.AudioRenderer.html
/// Provides common meta-data of the plugin or application to the host.
/// This trait is common for all backends that need this info.
/// This trait can be more conveniently implemented by implementing the [`Meta`] trait.
///
/// [`Meta`]: ./meta/trait.Meta.html
/// Provides some meta-data of the audio-ports used by the plugin or application to the host.
/// This trait can be more conveniently implemented by implementing the [`Meta`] trait.
///
/// [`Meta`]: ./meta/trait.Meta.html
/// Provides some meta-data of the midi-ports used by the plugin or application to the host.
/// This trait can be more conveniently implemented by implementing the [`Meta`] trait.
///
/// [`Meta`]: ./meta/trait.Meta.html