Browse Source

Implement `default` for `SoundIo` and add `name` argument to `new`

master
Andreas Linz 4 years ago
parent
commit
315f0200ea
5 changed files with 15 additions and 7 deletions
  1. +1
    -1
      examples/sine.rs
  2. +10
    -2
      src/base.rs
  3. +1
    -1
      src/lib.rs
  4. +2
    -2
      tests/basic.rs
  5. +1
    -1
      tests/stream.rs

+ 1
- 1
examples/sine.rs View File

@ -10,7 +10,7 @@ fn main() {
let rb = SpscRb::new(4096);
let (producer, consumer) = (rb.producer(), rb.consumer());
// create an audio context
let mut sio = rsoundio::SoundIo::new();
let mut sio = rsoundio::SoundIo::default();
sio.set_name("rsoundio-example").unwrap();
// connect to the default audio backend
sio.connect().unwrap();

+ 10
- 2
src/base.rs View File

@ -17,10 +17,10 @@ pub struct SoundIo {
name: CString,
}
impl SoundIo {
pub fn new() -> Self {
pub fn new<S: Into<String>>(name: S) -> Self {
SoundIo {
context: unsafe { ffi::soundio_create() },
name: CString::new("rsoundio").unwrap(),
name: CString::new(name.into()).unwrap(),
}
}
@ -250,6 +250,14 @@ impl SoundIo {
unsafe { ffi::utils::ptr_to_string((*self.context).app_name) }
}
}
impl Default for SoundIo {
fn default() -> Self {
SoundIo {
context: unsafe { ffi::soundio_create() },
name: CString::new("rsoundio").unwrap(),
}
}
}
impl Drop for SoundIo {
fn drop(&mut self) {
unsafe {

+ 1
- 1
src/lib.rs View File

@ -6,7 +6,7 @@
//! extern crate rsoundio;
//!
//! // create new context
//! let sio = rsoundio::SoundIo::new();
//! let sio = rsoundio::SoundIo::default();
//! // connect to default audio backend
//! sio.connect().unwrap();
//! sio.flush_events();

+ 2
- 2
tests/basic.rs View File

@ -8,7 +8,7 @@ fn test_soundio() {
if Ci::new().is_some() {
return
}
let sio = rsoundio::SoundIo::new();
let sio = rsoundio::SoundIo::default();
assert!(sio.backend_count() > 0);
assert!(sio.backend(0).is_some());
sio.connect().unwrap();
@ -65,7 +65,7 @@ fn test_enums() {
#[test]
fn test_device() {
let sio = rsoundio::SoundIo::new();
let sio = rsoundio::SoundIo::default();
sio.connect().unwrap();
sio.flush_events();
let in_dev_idx = sio.default_input_device_index().unwrap();

+ 1
- 1
tests/stream.rs View File

@ -11,7 +11,7 @@ fn test_outstream() {
if Ci::new().is_some() {
::std::process::exit(0)
}
let sio = rsoundio::SoundIo::new();
let sio = rsoundio::SoundIo::default();
sio.connect_backend(rsoundio::SioBackend::Dummy).unwrap();
let current_backend = sio.current_backend().unwrap();
assert_eq!(current_backend, rsoundio::SioBackend::Dummy);

Loading…
Cancel
Save