Synth

Struct Synth 

Source
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

Source

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.

Source

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.

Source

pub fn set_chorus_on(&self, on: bool)

Turn on/off the built-in chorus unit

Source

pub fn get_chorus_nr(&self) -> u32

Query the current chorus nr

Source

pub fn get_chorus_level(&self) -> f64

Query the current chorus level

Source

pub fn get_chorus_speed(&self) -> f64

Query the current chorus speed (Hz)

Source

pub fn get_chorus_depth(&self) -> f64

Query the current chorus depth (mS)

Source

pub fn get_chorus_mode(&self) -> ChorusMode

Query the current chorus mode

Source

pub fn get_chorus(&self) -> ChorusParams

Query the current chorus params

Source§

impl Synth

Source

pub fn count_midi_channels(&self) -> u32

Returns the number of MIDI channels that the synthesizer uses internally

Source

pub fn count_audio_channels(&self) -> u32

Returns the number of audio channels that the synthesizer uses internally

Source

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.

Source

pub fn count_effects_channels(&self) -> u32

Returns the number of effects channels that the synthesizer uses internally

Source§

impl Synth

SoundFont management

Source

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.

Source

pub fn sfreload(&self, id: FontId) -> Result<FontId>

Reload a SoundFont. The reloaded SoundFont retains its ID and index on the stack.

Source

pub fn sfunload(&self, id: FontId, reset_presets: bool) -> Status

Removes a SoundFont from the stack and deallocates it.

Source

pub fn sfcount(&self) -> u32

Count the number of loaded SoundFonts.

Source

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.

  • num The number of the SoundFont (0 <= num < sfcount)
Source

pub fn sfont_iter(&self) -> FontIter<'_>

Get an iterator over loaded SoundFonts.

Source

pub fn get_sfont_by_id(&self, id: FontId) -> Option<FontRef<'_>>

Get a SoundFont. The SoundFont is specified by its ID.

Source

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.

Source

pub fn get_channel_preset(&self, chan: Chan) -> Option<PresetRef<'_>>

Get the preset of a channel

Source

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)

Source

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

Source

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

pub fn get_gen(&self, chan: Chan, param: GenParam) -> f32

Retreive the value of a generator. This function returns the value set by a previous call ‘set_gen()’ or by an NRPN message.

Returns the value of the generator.

Source§

impl Synth

Source

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.

Source§

impl Synth

This impl block contains no items.

Low level access

Source§

impl Synth

MIDI channel messages

Source

pub fn note_on(&self, chan: Chan, key: Key, vel: Vel) -> Status

Send a noteon message.

Source

pub fn note_off(&self, chan: Chan, key: Key) -> Status

Send a noteoff message.

Source

pub fn cc(&self, chan: Chan, ctrl: Ctrl, val: Val) -> Status

Send a control change message.

Source

pub fn get_cc(&self, chan: Chan, ctrl: Ctrl) -> Result<Val>

Get a control value.

Source

pub fn pitch_bend(&self, chan: Chan, val: Val) -> Status

Send a pitch bend message.

Source

pub fn get_pitch_bend(&self, chan: Chan) -> Result<Val>

Get the pitch bend value.

Source

pub fn pitch_wheel_sens(&self, chan: Chan, val: Val) -> Status

Set the pitch wheel sensitivity.

Source

pub fn get_pitch_wheel_sens(&self, chan: Chan) -> Result<Val>

Get the pitch wheel sensitivity.

Source

pub fn program_change(&self, chan: Chan, prog: Prog) -> Status

Send a program change message.

Source

pub fn channel_pressure(&self, chan: Chan, val: Val) -> Status

Set channel pressure

Source

pub fn key_pressure(&self, chan: Chan, key: Key, val: Val) -> Status

Set key pressure (aftertouch)

Source

pub fn bank_select(&self, chan: Chan, bank: Bank) -> Status

Select a bank.

Source

pub fn sfont_select(&self, chan: Chan, sfont_id: FontId) -> Status

Select a sfont.

Source

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.

Source

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.

Source

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.

Source

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

Source

pub fn set_gain(&self, gain: f32)

Set the master gain

Source

pub fn get_gain(&self) -> f32

Get the master gain

Source

pub fn set_polyphony(&self, polyphony: u32) -> Status

Set the polyphony limit (FluidSynth >= 1.0.6)

Source

pub fn get_polyphony(&self) -> u32

Get the polyphony limit (FluidSynth >= 1.0.6)

Source

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.

Source

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

Source

pub fn set_reverb_params( &self, roomsize: f64, damp: f64, width: f64, level: f64, )

Set the parameters for the built-in reverb unit

Source

pub fn set_reverb(&self, params: &ReverbParams)

Set the parameters for the built-in reverb unit

Source

pub fn set_reverb_on(&self, on: bool)

Turn on/off the built-in reverb unit

Source

pub fn get_reverb_roomsize(&self) -> f64

Query the current reverb room size

Source

pub fn get_reverb_damp(&self) -> f64

Query the current reverb dumping

Source

pub fn get_reverb_level(&self) -> f64

Query the current reverb level

Source

pub fn get_reverb_width(&self) -> f64

Query the current reverb width

Source

pub fn get_reverb(&self) -> ReverbParams

Query the current reverb params

Source§

impl Synth

Tuning

Source

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.

Source

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.

Source

pub fn activate_octave_tuning<S: AsRef<str>>( &self, bank: Bank, prog: Prog, name: S, pitch: &[f64; 12], apply: bool, ) -> Status

Source

pub fn tune_notes<K, P>( &self, tuning_bank: Bank, tuning_prog: Prog, keys: K, pitch: P, apply: bool, ) -> Status
where K: AsRef<[u32]>, P: AsRef<[f64]>,

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.

Source

pub fn select_tuning( &self, chan: Chan, tuning_bank: Bank, tuning_prog: Prog, ) -> Status

Select a tuning for a channel.

Source

pub fn activate_tuning( &self, chan: Chan, bank: Bank, prog: Prog, apply: bool, ) -> Status

Source

pub fn reset_tuning(&self, chan: Chan) -> Status

Set the tuning to the default well-tempered tuning on a channel.

Source

pub fn tuning_iter(&self) -> TuningIter<'_>

Get the iterator throught the list of available tunings.

Source

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

pub fn tuning_dump_name(&self, bank: Bank, prog: Prog) -> Result<String>

Dump the data of a tuning.

This function returns the only name of a tuning.

Source

pub fn tuning_dump_pitch(&self, bank: Bank, prog: Prog) -> Result<[f64; 128]>

Dump the data of a tuning.

This function returns the only pitch values of a tuning.

Source§

impl Synth

Synthesizer plugin

Source

pub fn write<S: IsSamples>(&self, samples: S) -> Status

Write sound samples to the sample data buffer

Source

pub unsafe fn write_i16( &self, len: usize, lbuf: *mut i16, loff: u32, lincr: u32, rbuf: *mut i16, roff: u32, rincr: u32, ) -> Status

Write samples as 16-bit signed integers

§Safety

The len must corresponds to the lenghtes of buffers.

Source

pub unsafe fn write_f32( &self, len: usize, lbuf: *mut f32, loff: u32, lincr: u32, rbuf: *mut f32, roff: u32, rincr: u32, ) -> Status

Write samples as 32-bit floating-point numbers

§Safety

The len must corresponds to the lenghtes of buffers.

Source§

impl Synth

Source

pub fn new(settings: Settings) -> Result<Self>

Creates a new synthesizer object.

As soon as the synthesizer is created, it will start playing.

Source

pub fn set_sample_rate(&self, sample_rate: f32)

Set synth sample rate

Source

pub fn get_settings(&self) -> SettingsRef<'_>

Get a reference to the settings of the synthesizer.

Trait Implementations§

Source§

impl Drop for Synth

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for Synth

Auto Trait Implementations§

§

impl Freeze for Synth

§

impl RefUnwindSafe for Synth

§

impl !Sync for Synth

§

impl Unpin for Synth

§

impl UnwindSafe for Synth

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.