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
//! Declares the most basic traits concerning [`Signals`](Signal).
//!
//! ## Example
//!
//! The following example is a simplified implementation of [`NoiseGen`](crate::gen::NoiseGen).
//!
//! ```
//! # use pointillism::prelude::*;
//! /// A signal that produces random envelope data.
//! struct NoiseGen {
//! /// The current random value.
//! current: smp::Env,
//! }
//!
//! impl Signal for NoiseGen {
//! // This signal produces envelope data.
//! type Sample = smp::Env;
//!
//! // Returns the current value.
//! fn get(&self) -> smp::Env {
//! self.current
//! }
//! }
//!
//! impl SignalMut for NoiseGen {
//! // Updates the current value.
//! fn advance(&mut self) {
//! self.current = smp::Env::rand();
//! }
//!
//! // Retriggering a random signal amounts to choosing a new random value.
//! fn retrigger(&mut self) {
//! self.current = smp::Env::rand();
//! }
//! }
//! ```
use crate::;
/// A trait for a stream of data [`Samples`](Sample), generated every frame.
///
/// This data can either be audio data, meaning [`Mono`](crate::smp::Mono) or
/// [`Stereo`](crate::smp::Stereo), or envelope data [`Env`](crate::smp::Env).
///
/// Most signals will implement the stronger trait [`SignalMut`], meaning that the state of the
/// signal can be advanced. The main use case for this weaker trait is signal routing. For instance,
/// you can create two references to a [`SignalMut`] via [`rtn::Ref`](crate::rtn::Ref), and apply
/// separate effects to them.
///
/// ## Implementing the trait
///
/// In order to implement this trait on your custom type, you only need to define one method:
///
/// - [`get`](Signal::get): Gets the next sample from the signal.
///
/// See the [module docs](self) for an example implementation.
/// A trait for a stream of data [`Samples`](Sample), generated every frame.
///
/// This data can either be audio data, meaning [`Mono`](crate::smp::Mono) or
/// [`Stereo`](crate::smp::Stereo), or envelope data [`Env`](crate::smp::Env).
///
/// This trait is stronger than the [`Signal`] trait, as it also allows the signal to be advanced by
/// a frame.
///
/// ## Implementing the trait
///
/// In order to implement this trait on your custom type, you need to implement [`Sample`] together
/// with the following two methods:
///
/// - [`advance`](SignalMut::advance): Advances the state of the signal by a frame.
/// - [`retrigger`](SignalMut::retrigger): Resets the signal to its initial state.
///
/// See the [module docs](self) for an example implementation.
/// A trait for a signal with a "main" frequency that can be modified.
///
/// This is implemented both for signals that have a frequency parameter such as
/// [`gen::Loop`](crate::gen::Loop), as well as straightforward wrappers for these signals.
///
/// Not to be confused with [`Freq`].
/// A trait for a signal with a "base" signal that can be modified. This is often a generator in a
/// chain of effects. This is implemented both for basic signals that don't depend on others, as
/// well as straightforward wrappers of these.
///
/// This convenience trait doesn't really add functionality, but is instead meant to help make code
/// a bit more manageable.
/// Implements the [`Base`] trait on a base signal.
pub use impl_base;
/// Represents a signal that ends.
///
/// This trait is used in [polyphonic](crate::gen::poly) signals, so that a synth can be cleared
/// from memory when it stops.
///
/// If a signal never ends, it should not implement this trait. If you really want to use such a
/// signal within a [`Polyphony`](crate::gen::poly) struct, wrap it in the
/// [`eff::Trailing`](crate::eff::Trailing) structure.
/// Represents a signal that can be stopped. You can think of the `stop` method as an analog to a
/// MIDI note off event.
///
/// Note that stopping a signal doesn't necessarily mean it will immediately stop producing sound.
/// Use [`Panic`] for this purpose.
/// Represents a signal that can be stopped abruptly.
///
/// All sound or envelope data should stop being produced once the `panic` method is called.
///
/// Depending on how your code is structured, it might be easier to simply stop calling `next` on
/// your signal.