mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
ports macro
This commit is contained in:
parent
2067004d4a
commit
e86be4facc
10 changed files with 104 additions and 102 deletions
|
|
@ -144,33 +144,13 @@ impl Plugin {
|
|||
}
|
||||
}
|
||||
|
||||
impl PortList for Plugin {
|
||||
fn audio_ins (&self) -> Usually<Vec<String>> {
|
||||
let mut ports = vec![];
|
||||
for port in self.audio_ins.iter() {
|
||||
ports.push(port.name()?);
|
||||
}
|
||||
Ok(ports)
|
||||
ports!(Plugin {
|
||||
audio: {
|
||||
ins: |track|Ok(track.audio_ins.iter().collect()),
|
||||
outs: |track|Ok(track.audio_outs.iter().collect()),
|
||||
}
|
||||
fn audio_outs (&self) -> Usually<Vec<String>> {
|
||||
let mut ports = vec![];
|
||||
for port in self.audio_outs.iter() {
|
||||
ports.push(port.name()?);
|
||||
}
|
||||
Ok(ports)
|
||||
midi: {
|
||||
ins: |track|Ok(track.midi_ins.iter().collect()),
|
||||
outs: |track|Ok(track.midi_outs.iter().collect()),
|
||||
}
|
||||
fn midi_ins (&self) -> Usually<Vec<String>> {
|
||||
let mut ports = vec![];
|
||||
for port in self.midi_ins.iter() {
|
||||
ports.push(port.name()?);
|
||||
}
|
||||
Ok(ports)
|
||||
}
|
||||
fn midi_outs (&self) -> Usually<Vec<String>> {
|
||||
let mut ports = vec![];
|
||||
for port in self.midi_outs.iter() {
|
||||
ports.push(port.name()?);
|
||||
}
|
||||
Ok(ports)
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -135,25 +135,15 @@ impl Sampler {
|
|||
fn load_sample (&mut self, _path: &str) {}
|
||||
}
|
||||
|
||||
impl PortList for Sampler {
|
||||
fn midi_ins (&self) -> Usually<Vec<String>> {
|
||||
Ok(vec![self.midi_in.name()?])
|
||||
ports!(Sampler {
|
||||
audio: {
|
||||
ins: |sampler|Ok(sampler.audio_ins.iter().collect()),
|
||||
outs: |sampler|Ok(sampler.audio_outs.iter().collect()),
|
||||
}
|
||||
fn audio_ins (&self) -> Usually<Vec<String>> {
|
||||
let mut ports = vec![];
|
||||
for port in self.audio_ins.iter() {
|
||||
ports.push(port.name()?);
|
||||
}
|
||||
Ok(ports)
|
||||
midi: {
|
||||
ins: |sampler|Ok(vec![&sampler.midi_in]),
|
||||
}
|
||||
fn audio_outs (&self) -> Usually<Vec<String>> {
|
||||
let mut ports = vec![];
|
||||
for port in self.audio_outs.iter() {
|
||||
ports.push(port.name()?);
|
||||
}
|
||||
Ok(ports)
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
#[macro_export] macro_rules! sample {
|
||||
($note:expr, $name:expr, $src:expr) => {
|
||||
|
|
|
|||
|
|
@ -43,6 +43,15 @@ impl Track {
|
|||
device: 0,
|
||||
})
|
||||
}
|
||||
pub fn device (&self) -> Option<&Box<dyn Device>> {
|
||||
self.devices.get(self.device)
|
||||
}
|
||||
pub fn first_device (&self) -> Option<&Box<dyn Device>> {
|
||||
self.devices.get(0)
|
||||
}
|
||||
pub fn last_device (&self) -> Option<&Box<dyn Device>> {
|
||||
self.devices.get(self.devices.len().saturating_sub(1))
|
||||
}
|
||||
pub fn phrase (&self) -> Option<&Phrase> {
|
||||
if let Some(phrase) = self.sequence {
|
||||
return self.phrases.get(phrase)
|
||||
|
|
@ -52,23 +61,24 @@ impl Track {
|
|||
}
|
||||
}
|
||||
|
||||
impl PortList for Track {
|
||||
fn midi_outs (&self) -> Usually<Vec<String>> {
|
||||
Ok(vec![self.midi_out.name()?])
|
||||
ports!(Track {
|
||||
audio: {
|
||||
outs: |track|{
|
||||
if let Some(device) = track.last_device() {
|
||||
device.audio_outs()
|
||||
} else {
|
||||
Ok(vec![])
|
||||
}
|
||||
},
|
||||
}
|
||||
fn midi_ins (&self) -> Usually<Vec<String>> {
|
||||
if let Some(device) = self.devices.get(0) {
|
||||
midi: {
|
||||
ins: |track|if let Some(device) = track.first_device() {
|
||||
device.midi_ins()
|
||||
} else {
|
||||
Ok(vec![])
|
||||
}
|
||||
},
|
||||
outs: |track|Ok(vec![
|
||||
&track.midi_out
|
||||
]),
|
||||
}
|
||||
fn audio_outs (&self) -> Usually<Vec<String>> {
|
||||
if let Some(device) = self.devices.get(self.devices.len().saturating_sub(1)) {
|
||||
device.audio_outs()
|
||||
} else {
|
||||
Ok(vec![])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue