Skip to main content

xsynth_core/soundfont/
config.rs

1/// Type of the audio sample interpolation algorithm.
2#[derive(Clone, Copy, Debug, Eq, PartialEq)]
3#[cfg_attr(
4    feature = "serde",
5    derive(serde::Deserialize, serde::Serialize),
6    serde(rename_all = "snake_case")
7)]
8pub enum Interpolator {
9    /// Nearest neighbor interpolation
10    ///
11    /// See more info about this method [here](https://en.wikipedia.org/wiki/Nearest-neighbor_interpolation)
12    Nearest,
13
14    /// Linear interpolation
15    ///
16    /// See more info about this method [here](https://en.wikipedia.org/wiki/Linear_interpolation)
17    Linear,
18}
19
20/// Type of curve to be used in certain envelope stages.
21#[derive(Clone, Copy, Debug, Eq, PartialEq)]
22#[cfg_attr(
23    feature = "serde",
24    derive(serde::Deserialize, serde::Serialize),
25    serde(rename_all = "snake_case")
26)]
27pub enum EnvelopeCurveType {
28    /// Apply a linear curve to the envelope stage.
29    /// This option is supported by the attack, decay and release stages.
30    Linear,
31
32    /// Apply an exponential curve to the envelope stage.
33    /// The decay and release stages will use a concave curve, while the
34    /// attack stage will use a convex curve.
35    Exponential,
36}
37
38/// Options for the curves of a specific envelope.
39#[derive(Clone, Copy, Debug, PartialEq)]
40#[cfg_attr(
41    feature = "serde",
42    derive(serde::Deserialize, serde::Serialize),
43    serde(default)
44)]
45pub struct EnvelopeOptions {
46    /// Controls the type of curve of the attack envelope stage. See the
47    /// documentation of the `EnvelopeCurveType` enum for available options.
48    ///
49    /// Default: `Exponential`
50    pub attack_curve: EnvelopeCurveType,
51
52    /// Controls the type of curve of the decay envelope stage. See the
53    /// documentation of the `EnvelopeCurveType` enum for available options.
54    ///
55    /// Default: `Linear`
56    pub decay_curve: EnvelopeCurveType,
57
58    /// Controls the type of curve of the release envelope stage. See the
59    /// documentation of the `EnvelopeCurveType` enum for available options.
60    ///
61    /// Default: `Linear`
62    pub release_curve: EnvelopeCurveType,
63}
64
65impl Default for EnvelopeOptions {
66    fn default() -> Self {
67        Self {
68            attack_curve: EnvelopeCurveType::Exponential,
69            decay_curve: EnvelopeCurveType::Linear,
70            release_curve: EnvelopeCurveType::Linear,
71        }
72    }
73}
74
75/// Options for initializing/loading a new sample soundfont.
76#[derive(Clone, Copy, Debug, PartialEq)]
77#[cfg_attr(
78    feature = "serde",
79    derive(serde::Deserialize, serde::Serialize),
80    serde(default)
81)]
82pub struct SoundfontInitOptions {
83    /// The bank number (0-128) to extract and use from the soundfont.
84    /// `None` means to use all available banks (bank 0 for SFZ).
85    ///
86    /// Default: `None`
87    pub bank: Option<u8>,
88
89    /// The preset number (0-127) to extract and use from the soundfont.
90    /// `None` means to use all available presets (preset 0 for SFZ).
91    ///
92    /// Default: `None`
93    pub preset: Option<u8>,
94
95    /// Configures the volume envelope curves in dB units. See the
96    /// documentation for `EnvelopeOptions` for more information.
97    pub vol_envelope_options: EnvelopeOptions,
98
99    /// If set to true, the voices generated using this soundfont will
100    /// be able to use signal processing effects. Currently this option
101    /// only affects the cutoff filter.
102    ///
103    /// Default: `true`
104    pub use_effects: bool,
105
106    /// The type of interpolator to use for the new soundfont. See the
107    /// documentation of the `Interpolator` enum for available options.
108    ///
109    /// Default: `Nearest`
110    pub interpolator: Interpolator,
111}
112
113impl Default for SoundfontInitOptions {
114    fn default() -> Self {
115        Self {
116            bank: None,
117            preset: None,
118            vol_envelope_options: Default::default(),
119            use_effects: true,
120            interpolator: Interpolator::Nearest,
121        }
122    }
123}