pub struct Synth { /* private fields */ }Expand description
The synth object
You create a new synthesizer with Synth::new().
Use the settings structure to specify the synthesizer characteristics.
You have to load a SoundFont in order to hear any sound.
For that you use the Synth::sfload() function.
You can use the audio driver functions described below to open the audio device and create a background audio thread.
The API for sending MIDI events is probably what you expect:
Synth::noteon(), Synth::noteoff(), …
Implementations§
Source§impl Synth
Chorus
impl Synth
Chorus
Sourcepub fn set_chorus_params(
&self,
nr: u32,
level: f64,
speed: f64,
depth: f64,
mode: ChorusMode,
)
pub fn set_chorus_params( &self, nr: u32, level: f64, speed: f64, depth: f64, mode: ChorusMode, )
Set up the chorus. It should be turned on with Synth::chorus_on().
If faulty parameters are given, all new settings are discarded.
Keep in mind, that the needed CPU time is proportional to nr.
Sourcepub fn set_chorus(&self, params: &ChorusParams)
pub fn set_chorus(&self, params: &ChorusParams)
Set up the chorus. It should be turned on with Synth::chorus_on().
If faulty parameters are given, all new settings are discarded.
Keep in mind, that the needed CPU time is proportional to nr.
Sourcepub fn set_chorus_on(&self, on: bool)
pub fn set_chorus_on(&self, on: bool)
Turn on/off the built-in chorus unit
Sourcepub fn get_chorus_nr(&self) -> u32
pub fn get_chorus_nr(&self) -> u32
Query the current chorus nr
Sourcepub fn get_chorus_level(&self) -> f64
pub fn get_chorus_level(&self) -> f64
Query the current chorus level
Sourcepub fn get_chorus_speed(&self) -> f64
pub fn get_chorus_speed(&self) -> f64
Query the current chorus speed (Hz)
Sourcepub fn get_chorus_depth(&self) -> f64
pub fn get_chorus_depth(&self) -> f64
Query the current chorus depth (mS)
Sourcepub fn get_chorus_mode(&self) -> ChorusMode
pub fn get_chorus_mode(&self) -> ChorusMode
Query the current chorus mode
Sourcepub fn get_chorus(&self) -> ChorusParams
pub fn get_chorus(&self) -> ChorusParams
Query the current chorus params
Source§impl Synth
impl Synth
Sourcepub fn count_midi_channels(&self) -> u32
pub fn count_midi_channels(&self) -> u32
Returns the number of MIDI channels that the synthesizer uses internally
Sourcepub fn count_audio_channels(&self) -> u32
pub fn count_audio_channels(&self) -> u32
Returns the number of audio channels that the synthesizer uses internally
Sourcepub fn count_audio_groups(&self) -> u32
pub fn count_audio_groups(&self) -> u32
Returns the number of audio groups that the synthesizer uses internally. This is usually identical to audio_channels.
Sourcepub fn count_effects_channels(&self) -> u32
pub fn count_effects_channels(&self) -> u32
Returns the number of effects channels that the synthesizer uses internally
Source§impl Synth
SoundFont management
impl Synth
SoundFont management
Sourcepub fn sfload<P: AsRef<Path>>(
&self,
filename: P,
reset_presets: bool,
) -> Result<FontId>
pub fn sfload<P: AsRef<Path>>( &self, filename: P, reset_presets: bool, ) -> Result<FontId>
Loads a SoundFont file and creates a new SoundFont. The newly loaded SoundFont will be put on top of the SoundFont stack. Presets are searched starting from the SoundFont on the top of the stack, working the way down the stack until a preset is found.
Sourcepub fn sfreload(&self, id: FontId) -> Result<FontId>
pub fn sfreload(&self, id: FontId) -> Result<FontId>
Reload a SoundFont. The reloaded SoundFont retains its ID and index on the stack.
Sourcepub fn sfunload(&self, id: FontId, reset_presets: bool) -> Status
pub fn sfunload(&self, id: FontId, reset_presets: bool) -> Status
Removes a SoundFont from the stack and deallocates it.
Sourcepub fn get_sfont(&self, num: u32) -> Option<FontRef<'_>>
pub fn get_sfont(&self, num: u32) -> Option<FontRef<'_>>
Get a SoundFont. The SoundFont is specified by its index on the stack. The top of the stack has index zero.
numThe number of the SoundFont (0 <= num < sfcount)
Sourcepub fn sfont_iter(&self) -> FontIter<'_>
pub fn sfont_iter(&self) -> FontIter<'_>
Get an iterator over loaded SoundFonts.
Sourcepub fn get_sfont_by_id(&self, id: FontId) -> Option<FontRef<'_>>
pub fn get_sfont_by_id(&self, id: FontId) -> Option<FontRef<'_>>
Get a SoundFont. The SoundFont is specified by its ID.
Sourcepub fn remove_sfont(&self, sfont: FontRef<'_>)
pub fn remove_sfont(&self, sfont: FontRef<'_>)
Remove a SoundFont that was previously added using fluid_synth_add_sfont(). The synthesizer does not delete the SoundFont; this is responsability of the caller.
Sourcepub fn get_channel_preset(&self, chan: Chan) -> Option<PresetRef<'_>>
pub fn get_channel_preset(&self, chan: Chan) -> Option<PresetRef<'_>>
Get the preset of a channel
Sourcepub fn set_bank_offset(&self, sfont_id: FontId, offset: u32) -> Status
pub fn set_bank_offset(&self, sfont_id: FontId, offset: u32) -> Status
Offset the bank numbers in a SoundFont. Returns -1 if an error occured (out of memory or negative offset)
Sourcepub fn get_bank_offset(&self, sfont_id: FontId) -> Result<u32>
pub fn get_bank_offset(&self, sfont_id: FontId) -> Result<u32>
Get the offset of the bank numbers in a SoundFont.
Source§impl Synth
Generator interface
impl Synth
Generator interface
Sourcepub fn set_gen(&self, chan: Chan, param: GenParam, value: f32) -> Status
pub fn set_gen(&self, chan: Chan, param: GenParam, value: f32) -> Status
Change the value of a generator. This function allows to control all synthesis parameters in real-time. The changes are additive, i.e. they add up to the existing parameter value. This function is similar to sending an NRPN message to the synthesizer. The function accepts a float as the value of the parameter. The parameter numbers and ranges are described in the SoundFont 2.01 specification, paragraph 8.1.3, page 48.
Source§impl Synth
impl Synth
Sourcepub fn add_sfloader(&self, loader: Loader)
pub fn add_sfloader(&self, loader: Loader)
Add a SoundFont loader to the synthesizer. Note that SoundFont loader don’t necessarily load SoundFonts. They can load any type of wavetable data but export a SoundFont interface.
impl Synth
Low level access
Source§impl Synth
MIDI channel messages
impl Synth
MIDI channel messages
Sourcepub fn pitch_bend(&self, chan: Chan, val: Val) -> Status
pub fn pitch_bend(&self, chan: Chan, val: Val) -> Status
Send a pitch bend message.
Sourcepub fn get_pitch_bend(&self, chan: Chan) -> Result<Val>
pub fn get_pitch_bend(&self, chan: Chan) -> Result<Val>
Get the pitch bend value.
Sourcepub fn pitch_wheel_sens(&self, chan: Chan, val: Val) -> Status
pub fn pitch_wheel_sens(&self, chan: Chan, val: Val) -> Status
Set the pitch wheel sensitivity.
Sourcepub fn get_pitch_wheel_sens(&self, chan: Chan) -> Result<Val>
pub fn get_pitch_wheel_sens(&self, chan: Chan) -> Result<Val>
Get the pitch wheel sensitivity.
Sourcepub fn program_change(&self, chan: Chan, prog: Prog) -> Status
pub fn program_change(&self, chan: Chan, prog: Prog) -> Status
Send a program change message.
Sourcepub fn channel_pressure(&self, chan: Chan, val: Val) -> Status
pub fn channel_pressure(&self, chan: Chan, val: Val) -> Status
Set channel pressure
Sourcepub fn key_pressure(&self, chan: Chan, key: Key, val: Val) -> Status
pub fn key_pressure(&self, chan: Chan, key: Key, val: Val) -> Status
Set key pressure (aftertouch)
Sourcepub fn bank_select(&self, chan: Chan, bank: Bank) -> Status
pub fn bank_select(&self, chan: Chan, bank: Bank) -> Status
Select a bank.
Sourcepub fn sfont_select(&self, chan: Chan, sfont_id: FontId) -> Status
pub fn sfont_select(&self, chan: Chan, sfont_id: FontId) -> Status
Select a sfont.
Sourcepub fn program_select(
&self,
chan: Chan,
sfont_id: FontId,
bank_num: Bank,
preset_num: PresetId,
) -> Status
pub fn program_select( &self, chan: Chan, sfont_id: FontId, bank_num: Bank, preset_num: PresetId, ) -> Status
Select a preset for a channel. The preset is specified by the SoundFont ID, the bank number, and the preset number. This allows any preset to be selected and circumvents preset masking due to previously loaded SoundFonts on the SoundFont stack.
Sourcepub fn get_program(&self, chan: Chan) -> Result<(FontId, Bank, PresetId)>
pub fn get_program(&self, chan: Chan) -> Result<(FontId, Bank, PresetId)>
Returns the program, bank, and SoundFont number of the preset on a given channel.
Sourcepub fn program_reset(&self) -> Status
pub fn program_reset(&self) -> Status
Send a bank select and a program change to every channel to reinitialize the preset of the channel.
This function is useful mainly after a SoundFont has been loaded, unloaded or reloaded.
Sourcepub fn system_reset(&self) -> Status
pub fn system_reset(&self) -> Status
Send a reset.
A reset turns all the notes off and resets the controller values.
Source§impl Synth
Synthesis parameters
impl Synth
Synthesis parameters
Sourcepub fn set_polyphony(&self, polyphony: u32) -> Status
pub fn set_polyphony(&self, polyphony: u32) -> Status
Set the polyphony limit (FluidSynth >= 1.0.6)
Sourcepub fn get_polyphony(&self) -> u32
pub fn get_polyphony(&self) -> u32
Get the polyphony limit (FluidSynth >= 1.0.6)
Sourcepub fn get_internal_buffer_size(&self) -> usize
pub fn get_internal_buffer_size(&self) -> usize
Get the internal buffer size. The internal buffer size if not the same thing as the buffer size specified in the settings. Internally, the synth always uses a specific buffer size independent of the buffer size used by the audio driver. The internal buffer size is normally 64 samples. The reason why it uses an internal buffer size is to allow audio drivers to call the synthesizer with a variable buffer length. The internal buffer size is useful for client who want to optimize their buffer sizes.
Sourcepub fn set_interp_method(
&self,
chan: Option<u32>,
interp_method: InterpMethod,
) -> Status
pub fn set_interp_method( &self, chan: Option<u32>, interp_method: InterpMethod, ) -> Status
Set the interpolation method for one channel (Some(chan)) or all channels (None)
Source§impl Synth
Reverb
impl Synth
Reverb
Sourcepub fn set_reverb_params(
&self,
roomsize: f64,
damp: f64,
width: f64,
level: f64,
)
pub fn set_reverb_params( &self, roomsize: f64, damp: f64, width: f64, level: f64, )
Set the parameters for the built-in reverb unit
Sourcepub fn set_reverb(&self, params: &ReverbParams)
pub fn set_reverb(&self, params: &ReverbParams)
Set the parameters for the built-in reverb unit
Sourcepub fn set_reverb_on(&self, on: bool)
pub fn set_reverb_on(&self, on: bool)
Turn on/off the built-in reverb unit
Sourcepub fn get_reverb_roomsize(&self) -> f64
pub fn get_reverb_roomsize(&self) -> f64
Query the current reverb room size
Sourcepub fn get_reverb_damp(&self) -> f64
pub fn get_reverb_damp(&self) -> f64
Query the current reverb dumping
Sourcepub fn get_reverb_level(&self) -> f64
pub fn get_reverb_level(&self) -> f64
Query the current reverb level
Sourcepub fn get_reverb_width(&self) -> f64
pub fn get_reverb_width(&self) -> f64
Query the current reverb width
Sourcepub fn get_reverb(&self) -> ReverbParams
pub fn get_reverb(&self) -> ReverbParams
Query the current reverb params
Source§impl Synth
Tuning
impl Synth
Tuning
Sourcepub fn create_key_tuning<S: AsRef<str>>(
&self,
tuning_bank: Bank,
tuning_prog: Prog,
name: S,
pitch: &[f64; 128],
) -> Status
pub fn create_key_tuning<S: AsRef<str>>( &self, tuning_bank: Bank, tuning_prog: Prog, name: S, pitch: &[f64; 128], ) -> Status
Create a new key-based tuning with given name, number, and pitches. The array ‘pitches’ should have length 128 and contains the pitch in cents of every key in cents. However, if ‘pitches’ is NULL, a new tuning is created with the well-tempered scale.
Sourcepub fn create_octave_tuning<S: AsRef<str>>(
&self,
tuning_bank: Bank,
tuning_prog: Prog,
name: S,
pitch: &[f64; 12],
) -> Status
pub fn create_octave_tuning<S: AsRef<str>>( &self, tuning_bank: Bank, tuning_prog: Prog, name: S, pitch: &[f64; 12], ) -> Status
Create a new octave-based tuning with given name, number, and pitches. The array ‘pitches’ should have length 12 and contains derivation in cents from the well-tempered scale. For example, if pitches[0] equals -33, then the C-keys will be tuned 33 cents below the well-tempered C.
pub fn activate_octave_tuning<S: AsRef<str>>( &self, bank: Bank, prog: Prog, name: S, pitch: &[f64; 12], apply: bool, ) -> Status
Sourcepub fn tune_notes<K, P>(
&self,
tuning_bank: Bank,
tuning_prog: Prog,
keys: K,
pitch: P,
apply: bool,
) -> Status
pub fn tune_notes<K, P>( &self, tuning_bank: Bank, tuning_prog: Prog, keys: K, pitch: P, apply: bool, ) -> Status
Request a note tuning changes. Both they ‘keys’ and ‘pitches’ arrays should be of length ‘num_pitches’. If ‘apply’ is non-zero, the changes should be applied in real-time, i.e. sounding notes will have their pitch updated. ‘APPLY’ IS CURRENTLY IGNORED. The changes will be available for newly triggered notes only.
Sourcepub fn select_tuning(
&self,
chan: Chan,
tuning_bank: Bank,
tuning_prog: Prog,
) -> Status
pub fn select_tuning( &self, chan: Chan, tuning_bank: Bank, tuning_prog: Prog, ) -> Status
Select a tuning for a channel.
pub fn activate_tuning( &self, chan: Chan, bank: Bank, prog: Prog, apply: bool, ) -> Status
Sourcepub fn reset_tuning(&self, chan: Chan) -> Status
pub fn reset_tuning(&self, chan: Chan) -> Status
Set the tuning to the default well-tempered tuning on a channel.
Sourcepub fn tuning_iter(&self) -> TuningIter<'_> ⓘ
pub fn tuning_iter(&self) -> TuningIter<'_> ⓘ
Get the iterator throught the list of available tunings.
Sourcepub fn tuning_dump(
&self,
bank: Bank,
prog: Prog,
) -> Result<(String, [f64; 128])>
pub fn tuning_dump( &self, bank: Bank, prog: Prog, ) -> Result<(String, [f64; 128])>
Dump the data of a tuning.
This function returns both the name and pitch values of a tuning.
Source§impl Synth
Synthesizer plugin
impl Synth
Synthesizer plugin
Sourcepub fn write<S: IsSamples>(&self, samples: S) -> Status
pub fn write<S: IsSamples>(&self, samples: S) -> Status
Write sound samples to the sample data buffer
Source§impl Synth
impl Synth
Sourcepub fn new(settings: Settings) -> Result<Self>
pub fn new(settings: Settings) -> Result<Self>
Creates a new synthesizer object.
As soon as the synthesizer is created, it will start playing.
Sourcepub fn set_sample_rate(&self, sample_rate: f32)
pub fn set_sample_rate(&self, sample_rate: f32)
Set synth sample rate
Sourcepub fn get_settings(&self) -> SettingsRef<'_>
pub fn get_settings(&self) -> SettingsRef<'_>
Get a reference to the settings of the synthesizer.