hoist connect_ fns

This commit is contained in:
facile pop culture reference 2026-07-28 04:14:04 +03:00
parent 8b24b052ca
commit 815bfe9379
4 changed files with 56 additions and 57 deletions

View file

@ -814,7 +814,6 @@ pub struct Connect {
}
impl Connect {
pub fn new <T: AsRef<str>> (
exact: Option<impl Iterator<Item = T>>,
re: Option<impl Iterator<Item = T>>,
@ -827,62 +826,6 @@ impl Connect {
connections
}
pub fn midi_ins <T: AsRef<str>> (
jack: &Jack<'static>,
name: &T,
midi_from: &[T],
midi_from_re: Option<&[T]>,
) -> Usually<Vec<MidiInput>> {
Ok(Connect::new(
Some(midi_from.into_iter()),
Some([].into_iter()),
midi_from_re.map(|x|x.into_iter())).iter().enumerate()
.map(|(index, connect)|jack.midi_in(&format!("{}/{index}", name.as_ref()), &[connect.clone()]))
.collect::<Result<_, _>>()?)
}
pub fn midi_outs <T: AsRef<str>> (
jack: &Jack<'static>,
name: &T,
midi_to: &[T],
midi_to_re: Option<&[T]>,
) -> Usually<Vec<MidiOutput>> {
Ok(Connect::new(
Some(midi_to.into_iter()),
Some([].into_iter()),
midi_to_re.map(|x|x.into_iter())).iter().enumerate()
.map(|(index, connect)|jack.midi_out(&format!("{index}/{}", name.as_ref()), &[connect.clone()]))
.collect::<Result<_, _>>()?)
}
pub fn audio_ins <T: AsRef<str>> (
jack: &Jack<'static>,
name: &T,
audio_from: &[T],
audio_from_re: Option<&[T]>,
) -> Usually<Vec<AudioInput>> {
Ok(Connect::new(
Some(audio_from.into_iter()),
Some([].into_iter()),
audio_from_re.map(|x|x.into_iter())).iter().enumerate()
.map(|(index, connect)|jack.audio_in(&format!("{}/{index}", name.as_ref()), &[connect.clone()]))
.collect::<Result<_, _>>()?)
}
pub fn audio_outs <T: AsRef<str>> (
jack: &Jack<'static>,
name: &T,
audio_to: &[T],
audio_to_re: Option<&[T]>,
) -> Usually<Vec<AudioOutput>> {
Ok(Connect::new(
Some(audio_to.into_iter()),
Some([].into_iter()),
audio_to_re.map(|x|x.into_iter())).iter().enumerate()
.map(|(index, connect)|jack.audio_out(&format!("{index}/{}", name.as_ref()), &[connect.clone()]))
.collect::<Result<_, _>>()?)
}
/// Connect to this exact port
pub fn exact (name: impl AsRef<str>) -> Self {
let info = format!("=:{}", name.as_ref()).into();
@ -923,3 +866,59 @@ impl Connect {
}).into()
}
}
pub fn connect_midi_ins <T: AsRef<str>> (
jack: &Jack<'static>,
name: &T,
midi_from: &[T],
midi_from_re: Option<&[T]>,
) -> Usually<Vec<MidiInput>> {
Ok(Connect::new(
Some(midi_from.into_iter()),
Some([].into_iter()),
midi_from_re.map(|x|x.into_iter())).iter().enumerate()
.map(|(index, connect)|jack.midi_in(&format!("{}/{index}", name.as_ref()), &[connect.clone()]))
.collect::<Result<_, _>>()?)
}
pub fn connect_midi_outs <T: AsRef<str>> (
jack: &Jack<'static>,
name: &T,
midi_to: &[T],
midi_to_re: Option<&[T]>,
) -> Usually<Vec<MidiOutput>> {
Ok(Connect::new(
Some(midi_to.into_iter()),
Some([].into_iter()),
midi_to_re.map(|x|x.into_iter())).iter().enumerate()
.map(|(index, connect)|jack.midi_out(&format!("{index}/{}", name.as_ref()), &[connect.clone()]))
.collect::<Result<_, _>>()?)
}
pub fn connect_audio_ins <T: AsRef<str>> (
jack: &Jack<'static>,
name: &T,
audio_from: &[T],
audio_from_re: Option<&[T]>,
) -> Usually<Vec<AudioInput>> {
Ok(Connect::new(
Some(audio_from.into_iter()),
Some([].into_iter()),
audio_from_re.map(|x|x.into_iter())).iter().enumerate()
.map(|(index, connect)|jack.audio_in(&format!("{}/{index}", name.as_ref()), &[connect.clone()]))
.collect::<Result<_, _>>()?)
}
pub fn connect_audio_outs <T: AsRef<str>> (
jack: &Jack<'static>,
name: &T,
audio_to: &[T],
audio_to_re: Option<&[T]>,
) -> Usually<Vec<AudioOutput>> {
Ok(Connect::new(
Some(audio_to.into_iter()),
Some([].into_iter()),
audio_to_re.map(|x|x.into_iter())).iter().enumerate()
.map(|(index, connect)|jack.audio_out(&format!("{index}/{}", name.as_ref()), &[connect.clone()]))
.collect::<Result<_, _>>()?)
}

View file

View file

View file