mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-10 21:56:42 +01:00
This commit is contained in:
parent
573534a9a6
commit
447638ee71
30 changed files with 824 additions and 548 deletions
|
|
@ -1,14 +1,14 @@
|
|||
use crate::*;
|
||||
|
||||
#[derive(Debug)] pub struct JackMidiOut {
|
||||
#[derive(Debug)] pub struct MidiOutput {
|
||||
/// Handle to JACK client, for receiving reconnect events.
|
||||
jack: Jack,
|
||||
jack: Jack<'static>,
|
||||
/// Port name
|
||||
name: Arc<str>,
|
||||
/// Port handle.
|
||||
port: Port<MidiOut>,
|
||||
/// List of ports to connect to.
|
||||
conn: Vec<PortConnect>,
|
||||
conn: Vec<Connect>,
|
||||
/// List of currently held notes.
|
||||
held: Arc<RwLock<[bool;128]>>,
|
||||
/// Buffer
|
||||
|
|
@ -17,10 +17,10 @@ use crate::*;
|
|||
output_buffer: Vec<Vec<Vec<u8>>>,
|
||||
}
|
||||
|
||||
has!(Jack: |self: JackMidiOut|self.jack);
|
||||
has!(Jack<'static>: |self: MidiOutput|self.jack);
|
||||
|
||||
impl JackMidiOut {
|
||||
pub fn new (jack: &Jack, name: impl AsRef<str>, connect: &[PortConnect])
|
||||
impl MidiOutput {
|
||||
pub fn new (jack: &Jack, name: impl AsRef<str>, connect: &[Connect])
|
||||
-> Usually<Self>
|
||||
{
|
||||
let jack = jack.clone();
|
||||
|
|
@ -94,20 +94,20 @@ impl JackMidiOut {
|
|||
}
|
||||
}
|
||||
|
||||
impl AsRef<Port<MidiOut>> for JackMidiOut {
|
||||
impl AsRef<Port<MidiOut>> for MidiOutput {
|
||||
fn as_ref (&self) -> &Port<MidiOut> {
|
||||
&self.port
|
||||
}
|
||||
}
|
||||
|
||||
impl JackPort for JackMidiOut {
|
||||
impl JackPort<'static> for MidiOutput {
|
||||
type Port = MidiOut;
|
||||
type Pair = MidiIn;
|
||||
fn port (&self) -> &Port<MidiOut> { &self.port }
|
||||
}
|
||||
|
||||
impl JackPortConnect<&str> for JackMidiOut {
|
||||
fn connect_to (&self, to: &str) -> Usually<PortConnectStatus> {
|
||||
impl ConnectTo<'static, &str> for MidiOutput {
|
||||
fn connect_to (&self, to: &str) -> Usually<ConnectStatus> {
|
||||
self.with_client(|c|if let Some(ref port) = c.port_by_name(to.as_ref()) {
|
||||
self.connect_to(port)
|
||||
} else {
|
||||
|
|
@ -116,8 +116,8 @@ impl JackPortConnect<&str> for JackMidiOut {
|
|||
}
|
||||
}
|
||||
|
||||
impl JackPortConnect<&Port<Unowned>> for JackMidiOut {
|
||||
fn connect_to (&self, port: &Port<Unowned>) -> Usually<PortConnectStatus> {
|
||||
impl ConnectTo<'static, &Port<Unowned>> for MidiOutput {
|
||||
fn connect_to (&self, port: &Port<Unowned>) -> Usually<ConnectStatus> {
|
||||
self.with_client(|c|Ok(if let Ok(_) = c.connect_ports(&self.port, port) {
|
||||
Connected
|
||||
} else if let Ok(_) = c.connect_ports(port, &self.port) {
|
||||
|
|
@ -128,8 +128,8 @@ impl JackPortConnect<&Port<Unowned>> for JackMidiOut {
|
|||
}
|
||||
}
|
||||
|
||||
impl JackPortConnect<&Port<MidiIn>> for JackMidiOut {
|
||||
fn connect_to (&self, port: &Port<MidiIn>) -> Usually<PortConnectStatus> {
|
||||
impl ConnectTo<'static, &Port<MidiIn>> for MidiOutput {
|
||||
fn connect_to (&self, port: &Port<MidiIn>) -> Usually<ConnectStatus> {
|
||||
self.with_client(|c|Ok(if let Ok(_) = c.connect_ports(&self.port, port) {
|
||||
Connected
|
||||
} else if let Ok(_) = c.connect_ports(port, &self.port) {
|
||||
|
|
@ -140,22 +140,22 @@ impl JackPortConnect<&Port<MidiIn>> for JackMidiOut {
|
|||
}
|
||||
}
|
||||
|
||||
impl JackPortAutoconnect for JackMidiOut {
|
||||
fn conn (&self) -> &[PortConnect] {
|
||||
impl ConnectAuto<'static> for MidiOutput {
|
||||
fn connections (&self) -> &[Connect] {
|
||||
&self.conn
|
||||
}
|
||||
}
|
||||
|
||||
#[tengri_proc::command(JackMidiOut)]
|
||||
#[tengri_proc::command(MidiOutput)]
|
||||
impl MidiOutputCommand {
|
||||
fn _todo_ (_port: &mut JackMidiOut) -> Perhaps<Self> { Ok(None) }
|
||||
fn _todo_ (_port: &mut MidiOutput) -> Perhaps<Self> { Ok(None) }
|
||||
}
|
||||
|
||||
impl<T: Has<Vec<JackMidiOut>>> HasMidiOuts for T {
|
||||
fn midi_outs (&self) -> &Vec<JackMidiOut> {
|
||||
impl<T: Has<Vec<MidiOutput>>> HasMidiOuts for T {
|
||||
fn midi_outs (&self) -> &Vec<MidiOutput> {
|
||||
self.get()
|
||||
}
|
||||
fn midi_outs_mut (&mut self) -> &mut Vec<JackMidiOut> {
|
||||
fn midi_outs_mut (&mut self) -> &mut Vec<MidiOutput> {
|
||||
self.get_mut()
|
||||
}
|
||||
}
|
||||
|
|
@ -163,10 +163,10 @@ impl<T: Has<Vec<JackMidiOut>>> HasMidiOuts for T {
|
|||
|
||||
/// Trait for thing that may output MIDI.
|
||||
pub trait HasMidiOuts {
|
||||
fn midi_outs (&self) -> &Vec<JackMidiOut>;
|
||||
fn midi_outs_mut (&mut self) -> &mut Vec<JackMidiOut>;
|
||||
fn midi_outs (&self) -> &Vec<MidiOutput>;
|
||||
fn midi_outs_mut (&mut self) -> &mut Vec<MidiOutput>;
|
||||
fn midi_outs_with_sizes <'a> (&'a self) ->
|
||||
impl Iterator<Item=(usize, &Arc<str>, &[PortConnect], usize, usize)> + Send + Sync + 'a
|
||||
impl Iterator<Item=(usize, &Arc<str>, &[Connect], usize, usize)> + Send + Sync + 'a
|
||||
{
|
||||
let mut y = 0;
|
||||
self.midi_outs().iter().enumerate().map(move|(i, output)|{
|
||||
|
|
@ -184,10 +184,10 @@ pub trait HasMidiOuts {
|
|||
}
|
||||
|
||||
/// Trail for thing that may gain new MIDI ports.
|
||||
impl<T: HasMidiOuts + HasJack> AddMidiOut for T {
|
||||
impl<'j, T: HasMidiOuts + HasJack<'j>> AddMidiOut for T {
|
||||
fn midi_out_add (&mut self) -> Usually<()> {
|
||||
let index = self.midi_outs().len();
|
||||
let port = JackMidiOut::new(self.jack(), &format!("{index}/M"), &[])?;
|
||||
let port = MidiOutput::new(self.jack(), &format!("{index}/M"), &[])?;
|
||||
self.midi_outs_mut().push(port);
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue