mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
ports macro
This commit is contained in:
parent
2067004d4a
commit
e86be4facc
10 changed files with 104 additions and 102 deletions
|
|
@ -49,10 +49,11 @@ const KEYMAP: &'static [KeyBinding<App>] = keymap!(App {
|
|||
false => {app.scene_cursor = app.scene_cursor.saturating_sub(1); Ok(true)},
|
||||
true => {app.track_cursor = app.track_cursor.saturating_sub(1); Ok(true)},
|
||||
},
|
||||
2 => { app.note_cursor = app.note_cursor.saturating_sub(1); Ok(true) }
|
||||
_ => Ok(false)
|
||||
}
|
||||
} else {
|
||||
focus_prev(app)
|
||||
focus_next(app)
|
||||
}
|
||||
}],
|
||||
[Down, NONE, "cursor_down", "move cursor down", |app: &mut App| {
|
||||
|
|
@ -62,10 +63,11 @@ const KEYMAP: &'static [KeyBinding<App>] = keymap!(App {
|
|||
false => {app.scene_cursor = app.scenes.len().min(app.scene_cursor + 1); Ok(true)},
|
||||
true => {app.track_cursor = app.tracks.len().min(app.track_cursor + 1); Ok(true)},
|
||||
},
|
||||
2 => { app.note_cursor = app.note_cursor + 1; Ok(true) }
|
||||
_ => Ok(false)
|
||||
}
|
||||
} else {
|
||||
focus_next(app)
|
||||
focus_prev(app)
|
||||
}
|
||||
}],
|
||||
[Left, NONE, "cursor_left", "move cursor left", |app: &mut App| {
|
||||
|
|
|
|||
|
|
@ -26,5 +26,6 @@ pub use crate::{
|
|||
process,
|
||||
phrase,
|
||||
keymap,
|
||||
key
|
||||
key,
|
||||
ports
|
||||
};
|
||||
|
|
|
|||
|
|
@ -5,14 +5,14 @@ pub trait Component: Render + Handle {}
|
|||
impl<T: Render + Handle> Component for T {}
|
||||
|
||||
/// A UI component that may have presence on the JACK grap.
|
||||
pub trait Device: Render + Handle + PortList + Send + Sync {
|
||||
pub trait Device: Render + Handle + Ports + Send + Sync {
|
||||
fn boxed (self) -> Box<dyn Device> where Self: Sized + 'static {
|
||||
Box::new(self)
|
||||
}
|
||||
}
|
||||
|
||||
/// All things that implement the required traits can be treated as `Device`.
|
||||
impl<T: Render + Handle + PortList + Send + Sync> Device for T {}
|
||||
impl<T: Render + Handle + Ports + Send + Sync> Device for T {}
|
||||
|
||||
/// A device dynamicammy composed of state and handlers.
|
||||
pub struct DynamicDevice<T> {
|
||||
|
|
@ -35,20 +35,7 @@ impl<T: Send> Render for DynamicDevice<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: PortList + Send + Sync + 'static> PortList for DynamicDevice<T> {
|
||||
fn audio_ins (&self) -> Usually<Vec<String>> {
|
||||
self.state().audio_ins()
|
||||
}
|
||||
fn audio_outs (&self) -> Usually<Vec<String>> {
|
||||
self.state().audio_outs()
|
||||
}
|
||||
fn midi_ins (&self) -> Usually<Vec<String>> {
|
||||
self.state().midi_ins()
|
||||
}
|
||||
fn midi_outs (&self) -> Usually<Vec<String>> {
|
||||
self.state().midi_outs()
|
||||
}
|
||||
}
|
||||
impl<T: Ports + Send + Sync + 'static> Ports for DynamicDevice<T> {}
|
||||
|
||||
impl<T: Send + Sync + 'static> DynamicDevice<T> {
|
||||
pub fn new <'a, R, H, P> (render: R, handle: H, process: P, state: T) -> Self where
|
||||
|
|
|
|||
|
|
@ -1,32 +1,58 @@
|
|||
use crate::core::*;
|
||||
|
||||
/// Trait for things that may expose JACK ports.
|
||||
pub trait PortList {
|
||||
fn audio_ins (&self) -> Usually<Vec<String>> {
|
||||
pub trait Ports {
|
||||
fn audio_ins (&self) -> Usually<Vec<&Port<AudioIn>>> {
|
||||
Ok(vec![])
|
||||
}
|
||||
fn audio_outs (&self) -> Usually<Vec<String>> {
|
||||
fn audio_outs (&self) -> Usually<Vec<&Port<AudioOut>>> {
|
||||
Ok(vec![])
|
||||
}
|
||||
fn midi_ins (&self) -> Usually<Vec<String>> {
|
||||
fn midi_ins <'a> (&'a self) -> Usually<Vec<&'a Port<MidiIn>>> {
|
||||
Ok(vec![])
|
||||
}
|
||||
fn midi_outs (&self) -> Usually<Vec<String>> {
|
||||
fn midi_outs <'a> (&'a self) -> Usually<Vec<&'a Port<MidiOut>>> {
|
||||
Ok(vec![])
|
||||
}
|
||||
fn connect (&mut self, _connect: bool, _source: &str, _target: &str)
|
||||
-> Usually<()>
|
||||
{
|
||||
Ok(())
|
||||
}
|
||||
fn connect_all (&mut self, connections: &[(bool, &str, &str)])
|
||||
-> Usually<()>
|
||||
{
|
||||
for (connect, source, target) in connections.iter() {
|
||||
self.connect(*connect, source, target)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export] macro_rules! ports {
|
||||
($T:ty $({ $(audio: {
|
||||
$(ins: |$ai_arg:ident|$ai_impl:expr,)?
|
||||
$(outs: |$ao_arg:ident|$ao_impl:expr,)?
|
||||
})? $(midi: {
|
||||
$(ins: |$mi_arg:ident|$mi_impl:expr,)?
|
||||
$(outs: |$mo_arg:ident|$mo_impl:expr,)?
|
||||
})?})?) => {
|
||||
impl Ports for $T {$(
|
||||
$(
|
||||
$(fn audio_ins <'a> (&'a self) -> Usually<Vec<&'a Port<AudioIn>>> {
|
||||
let cb = |$ai_arg:&'a Self|$ai_impl;
|
||||
cb(self)
|
||||
})?
|
||||
)?
|
||||
$(
|
||||
$(fn audio_outs <'a> (&'a self) -> Usually<Vec<&'a Port<AudioOut>>> {
|
||||
let cb = (|$ao_arg:&'a Self|$ao_impl);
|
||||
cb(self)
|
||||
})?
|
||||
)?
|
||||
)? $(
|
||||
$(
|
||||
$(fn midi_ins <'a> (&'a self) -> Usually<Vec<&'a Port<MidiIn>>> {
|
||||
let cb = (|$mi_arg:&'a Self|$mi_impl);
|
||||
cb(self)
|
||||
})?
|
||||
)?
|
||||
$(
|
||||
$(fn midi_outs <'a> (&'a self) -> Usually<Vec<&'a Port<MidiOut>>> {
|
||||
let cb = (|$mo_arg:&'a Self|$mo_impl);
|
||||
cb(self)
|
||||
})?
|
||||
)?
|
||||
)?}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
pub struct DevicePort<T: PortSpec> {
|
||||
|
|
|
|||
|
|
@ -69,7 +69,13 @@ pub fn main () -> Usually<()> {
|
|||
];
|
||||
state.track_cursor = 1;
|
||||
state.scene_cursor = 1;
|
||||
state.note_start = 12;
|
||||
let client = jack.as_client();
|
||||
for track in state.tracks.iter() {
|
||||
if let Some(port) = track.midi_ins()?.get(0) {
|
||||
client.connect_ports(&track.midi_out, port)?;
|
||||
}
|
||||
}
|
||||
state.midi_in = Some(client.register_port("midi-in", MidiIn)?);
|
||||
state.transport = Some(client.transport());
|
||||
state.playing = Some(TransportState::Stopped);
|
||||
|
|
|
|||
|
|
@ -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![])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -159,23 +159,23 @@ pub fn draw_as_column (
|
|||
w = w.max(frame.width);
|
||||
y = y - midi_ins.len() as u16;
|
||||
for port in midi_ins.iter() {
|
||||
buf.set_string(x + frame.width - 10, y, &format!(" <i> MIDI {port} "), style_midi);
|
||||
buf.set_string(x + frame.width - 10, y, &format!(" <i> MIDI {} ", port.name()?), style_midi);
|
||||
y = y + 1;
|
||||
}
|
||||
y = y - audio_ins.len() as u16;
|
||||
for port in audio_ins.iter() {
|
||||
buf.set_string(x + frame.width - 10, y, &format!(" <i> MIDI {port} "), style_audio);
|
||||
buf.set_string(x + frame.width - 10, y, &format!(" <i> MIDI {} ", port.name()?), style_audio);
|
||||
y = y + 1;
|
||||
}
|
||||
y = y + frame.height - 1;
|
||||
y = y + midi_outs.len() as u16;
|
||||
for port in midi_outs.iter() {
|
||||
buf.set_string(x + 2, y, &format!(" <o> MIDI {port} "), style_midi);
|
||||
buf.set_string(x + 2, y, &format!(" <o> MIDI {} ", port.name()?), style_midi);
|
||||
y = y + 1;
|
||||
}
|
||||
y = y + audio_outs.len() as u16;
|
||||
for port in audio_outs.iter() {
|
||||
buf.set_string(x + 2, y, &format!(" <o> Audio {port} "), style_audio);
|
||||
buf.set_string(x + 2, y, &format!(" <o> Audio {} ", port.name()?), style_audio);
|
||||
y = y + 1;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@ mod horizontal {
|
|||
//let time1 = time0 + width as usize;
|
||||
//let note1 = note0 + height as usize;
|
||||
let bg = Style::default();
|
||||
let (bw, wh) = (bg.dim(), bg.white());
|
||||
let (bw, wh) = (bg.dim(), bg.white().not_dim());
|
||||
let offset = 5;
|
||||
for x in x+offset..x+width-offset {
|
||||
let step = (x-offset) as usize * time_z;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue