move all port connections to constructors (port: impl AsRef<str>)

This commit is contained in:
🪞👃🪞 2024-12-29 20:15:12 +01:00
parent e8b97bed37
commit 6607491f16
9 changed files with 215 additions and 129 deletions

View file

@ -127,7 +127,13 @@ pub struct MidiPlayer {
pub note_buf: Vec<u8>,
}
impl MidiPlayer {
pub fn new (jack: &Arc<RwLock<JackConnection>>, name: &str) -> Usually<Self> {
pub fn new (
jack: &Arc<RwLock<JackConnection>>,
name: impl AsRef<str>,
midi_from: &[impl AsRef<str>],
midi_to: &[impl AsRef<str>],
) -> Usually<Self> {
let name = name.as_ref();
Ok(Self {
clock: ClockModel::from(jack),
play_phrase: None,
@ -138,11 +144,11 @@ impl MidiPlayer {
notes_in: RwLock::new([false;128]).into(),
midi_ins: vec![
jack.midi_in(&format!("M/{name}"))?,
jack.midi_in(&format!("M/{name}"), midi_from)?,
],
midi_outs: vec![
jack.midi_out(&format!("{name}/M"))?,
jack.midi_out(&format!("{name}/M"), midi_to)?,
],
notes_out: RwLock::new([false;128]).into(),
reset: true,