impl Drop for Rawmidi { fn drop(&mutself) { unsafe { alsa::snd_rawmidi_close(self.0) }; }
}
impl Rawmidi {
/// Wrapper around open that takes a &str instead of a &CStr pubfn new(name: &str, dir: Direction, nonblock: bool) -> Result<Self> { Self::open(&CString::new(name).unwrap(), dir, nonblock)
}
pubfn open(name: &CStr, dir: Direction, nonblock: bool) -> Result<Rawmidi> { letmut h = ptr::null_mut(); let flags = if nonblock { 2 } else { 0 }; // FIXME: alsa::SND_RAWMIDI_NONBLOCK does not exist in alsa-sys
acheck!(snd_rawmidi_open( if dir == Direction::Capture { &mut h } else { ptr::null_mut() }, if dir == Direction::Playback { &mut h } else { ptr::null_mut() },
name.as_ptr(), flags))
.map(|_| Rawmidi(h))
}
impl poll::Descriptors for Rawmidi { fn count(&self) -> usize { unsafe { alsa::snd_rawmidi_poll_descriptors_count(self.0) as usize }
} fn fill(&self, p: &mut [pollfd]) -> Result<usize> { let z = unsafe { alsa::snd_rawmidi_poll_descriptors(self.0, p.as_mut_ptr(), p.len() as c_uint) };
from_code("snd_rawmidi_poll_descriptors", z).map(|_| z as usize)
} fn revents(&self, p: &[pollfd]) -> Result<poll::Flags> { letmut r = 0; let z = unsafe { alsa::snd_rawmidi_poll_descriptors_revents(self.0, p.as_ptr() as *mut pollfd, p.len() as c_uint, &mut r) };
from_code("snd_rawmidi_poll_descriptors_revents", z).map(|_| poll::Flags::from_bits_truncate(r as c_short))
}
}
/// Implements `std::io::Read` and `std::io::Write` for `Rawmidi` pubstruct IO<'a>(&'a Rawmidi);
impl<'a> io::Read for IO<'a> { fn read(&mutself, buf: &mut [u8]) -> io::Result<usize> { let r = unsafe { alsa::snd_rawmidi_read((self.0).0, buf.as_mut_ptr() as *mut c_void, buf.len() as size_t) }; if r < 0 { Err(io::Error::from_raw_os_error(r as i32)) } else { Ok(r as usize) }
}
}
impl<'a> io::Write for IO<'a> { fn write(&mutself, buf: &[u8]) -> io::Result<usize> { let r = unsafe { alsa::snd_rawmidi_write((self.0).0, buf.as_ptr() as *const c_void, buf.len() as size_t) }; if r < 0 { Err(io::Error::from_raw_os_error(r as i32)) } else { Ok(r as usize) }
} fn flush(&mutself) -> io::Result<()> { Ok(()) }
}
#[test] fn print_rawmidis() { for a insuper::card::Iter::new().map(|a| a.unwrap()) { for b in Iter::new(&Ctl::from_card(&a, false).unwrap()).map(|b| b.unwrap()) {
println!("Rawmidi {:?} (hw:{},{},{}) {} - {}", b.get_stream(), a.get_index(), b.get_device(), b.get_subdevice(),
a.get_name().unwrap(), b.get_subdevice_name().unwrap())
}
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.12 Sekunden
(vorverarbeitet am 2026-06-18)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.