Driver

Struct Driver 

Source
pub struct Driver { /* private fields */ }
Expand description

A handle to a single ASIO driver.

Creating an instance of this type loads and initialises the driver.

Dropping all Driver instances will automatically dispose of any resources and de-initialise the driver.

Implementations§

Source§

impl Driver

Source

pub fn name(&self) -> &str

The name used to uniquely identify this driver.

Source

pub fn channels(&self) -> Result<Channels, AsioError>

Returns the number of input and output channels available on the driver.

Examples found in repository?
examples/test.rs (line 10)
3fn main() {
4    let asio = sys::Asio::new();
5    for driver in asio.driver_names() {
6        println!("Driver: {}", driver);
7        let driver = asio.load_driver(&driver).expect("failed to load drivers");
8        println!(
9            "  Channels: {:?}",
10            driver.channels().expect("failed to get channels")
11        );
12        println!(
13            "  Sample rate: {:?}",
14            driver.sample_rate().expect("failed to get sample rate")
15        );
16    }
17}
More examples
Hide additional examples
examples/enumerate.rs (line 41)
35fn main() {
36    let asio = sys::Asio::new();
37    for name in asio.driver_names() {
38        println!("Driver: {:?}", name);
39        let driver = asio.load_driver(&name).expect("failed to load driver");
40        let channels = driver
41            .channels()
42            .expect("failed to retrieve channel counts");
43        let sample_rate = driver
44            .sample_rate()
45            .expect("failed to retrieve sample rate");
46        let in_fmt = Format {
47            channels: channels.ins as _,
48            sample_rate: sample_rate as _,
49            data_type: SampleFormat::F32,
50        };
51        let out_fmt = Format {
52            channels: channels.outs as _,
53            sample_rate: sample_rate as _,
54            data_type: SampleFormat::F32,
55        };
56        println!("  Input {:?}", in_fmt);
57        println!("  Output {:?}", out_fmt);
58    }
59}
Source

pub fn buffersize_range(&self) -> Result<(c_long, c_long), AsioError>

Get the min and max supported buffersize of the driver.

Source

pub fn sample_rate(&self) -> Result<c_double, AsioError>

Get current sample rate of the driver.

Examples found in repository?
examples/test.rs (line 14)
3fn main() {
4    let asio = sys::Asio::new();
5    for driver in asio.driver_names() {
6        println!("Driver: {}", driver);
7        let driver = asio.load_driver(&driver).expect("failed to load drivers");
8        println!(
9            "  Channels: {:?}",
10            driver.channels().expect("failed to get channels")
11        );
12        println!(
13            "  Sample rate: {:?}",
14            driver.sample_rate().expect("failed to get sample rate")
15        );
16    }
17}
More examples
Hide additional examples
examples/enumerate.rs (line 44)
35fn main() {
36    let asio = sys::Asio::new();
37    for name in asio.driver_names() {
38        println!("Driver: {:?}", name);
39        let driver = asio.load_driver(&name).expect("failed to load driver");
40        let channels = driver
41            .channels()
42            .expect("failed to retrieve channel counts");
43        let sample_rate = driver
44            .sample_rate()
45            .expect("failed to retrieve sample rate");
46        let in_fmt = Format {
47            channels: channels.ins as _,
48            sample_rate: sample_rate as _,
49            data_type: SampleFormat::F32,
50        };
51        let out_fmt = Format {
52            channels: channels.outs as _,
53            sample_rate: sample_rate as _,
54            data_type: SampleFormat::F32,
55        };
56        println!("  Input {:?}", in_fmt);
57        println!("  Output {:?}", out_fmt);
58    }
59}
Source

pub fn can_sample_rate(&self, sample_rate: c_double) -> Result<bool, AsioError>

Can the driver accept the given sample rate.

Source

pub fn set_sample_rate(&self, sample_rate: c_double) -> Result<(), AsioError>

Set the sample rate for the driver.

Source

pub fn input_data_type(&self) -> Result<AsioSampleType, AsioError>

Get the current data type of the driver’s input stream.

This queries a single channel’s type assuming all channels have the same sample type.

Source

pub fn output_data_type(&self) -> Result<AsioSampleType, AsioError>

Get the current data type of the driver’s output stream.

This queries a single channel’s type assuming all channels have the same sample type.

Source

pub fn prepare_input_stream( &self, output: Option<AsioStream>, num_channels: usize, buffer_size: Option<i32>, ) -> Result<AsioStreams, AsioError>

Prepare the input stream.

Because only the latest call to ASIOCreateBuffers is relevant this call will destroy all past active buffers and recreate them.

For this reason we take the output stream if it exists.

num_channels is the desired number of input channels.

buffer_size sets the desired buffer_size. If None is passed in, then the default buffersize for the device is used.

This returns a full AsioStreams with both input and output if output was active.

Source

pub fn prepare_output_stream( &self, input: Option<AsioStream>, num_channels: usize, buffer_size: Option<i32>, ) -> Result<AsioStreams, AsioError>

Prepare the output stream.

Because only the latest call to ASIOCreateBuffers is relevant this call will destroy all past active buffers and recreate them.

For this reason we take the input stream if it exists.

num_channels is the desired number of output channels.

buffer_size sets the desired buffer_size. If None is passed in, then the default buffersize for the device is used.

This returns a full AsioStreams with both input and output if input was active.

Source

pub fn dispose_buffers(&self) -> Result<(), AsioError>

Releases buffers allocations.

This will stop the stream if the driver is Running.

No-op if no buffers are allocated.

Source

pub fn start(&self) -> Result<(), AsioError>

Starts ASIO streams playing.

The driver must be in the Prepared state

If called successfully, the driver will be in the Running state.

No-op if already Running.

Source

pub fn stop(&self) -> Result<(), AsioError>

Stops ASIO streams playing.

No-op if the state is not Running.

If the state was Running and the stream is stopped successfully, the driver will be in the Prepared state.

Source

pub fn add_callback<F>(&self, callback: F) -> CallbackId
where F: 'static + FnMut(&CallbackInfo) + Send,

Adds a callback to the list of active callbacks.

The given function receives the index of the buffer currently ready for processing.

Returns an ID uniquely associated with the given callback so that it may be removed later.

Source

pub fn remove_callback(&self, rem_id: CallbackId)

Remove the callback with the given ID.

Source

pub fn destroy(self) -> Result<bool, AsioError>

Consumes and destroys the Driver, stopping the streams if they are running and releasing any associated resources.

Returns Ok(true) if the driver was successfully destroyed.

Returns Ok(false) if the driver was not destroyed because another handle to the driver still exists.

Returns Err if some switching driver states failed or if ASIO returned an error on exit.

Source

pub fn add_message_callback<F>(&self, callback: F) -> MessageCallbackId
where F: Fn(AsioMessageSelectors) + Send + Sync + 'static,

Adds a callback to the list of message listeners.

Returns an ID uniquely associated with the given callback so that it may be removed later.

Source

pub fn remove_message_callback(&self, rem_id: MessageCallbackId)

Remove the callback with the given ID.

Trait Implementations§

Source§

impl Clone for Driver

Source§

fn clone(&self) -> Driver

Returns a duplicate of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Driver

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Driver

§

impl RefUnwindSafe for Driver

§

impl Send for Driver

§

impl Sync for Driver

§

impl Unpin for Driver

§

impl UnwindSafe for Driver

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.