mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
refactor jack ports again
This commit is contained in:
parent
c13eff95ca
commit
6c8f85ab84
16 changed files with 558 additions and 609 deletions
|
|
@ -1,24 +1,11 @@
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
/// Things that can provide a [JackClient] reference.
|
||||||
pub trait HasJack {
|
pub trait HasJack { fn jack (&self) -> &JackClient; }
|
||||||
fn jack (&self) -> &Arc<RwLock<JackConnection>>;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Implement [HasJack].
|
/// Implement [HasJack].
|
||||||
#[macro_export] macro_rules! has_jack {
|
#[macro_export] macro_rules! has_jack {
|
||||||
(|$self:ident:$Struct:ident$(<$($L:lifetime),*$($T:ident$(:$U:path)?),*>)?|$cb:expr) => {
|
(|$self:ident:$Struct:ident$(<$($L:lifetime),*$($T:ident$(:$U:path)?),*>)?|$cb:expr) => {
|
||||||
impl $(<$($L),*$($T $(: $U)?),*>)? HasJack for $Struct $(<$($L),*$($T),*>)? {
|
impl $(<$($L),*$($T $(: $U)?),*>)? HasJack for $Struct $(<$($L),*$($T),*>)? {
|
||||||
fn jack (&$self) -> &Arc<RwLock<JackConnection>> { $cb }
|
fn jack (&$self) -> &JackClient { $cb }
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Implement [TryFrom<&Arc<RwLock<JackConnection>>>]: create app state from wrapped JACK handle.
|
|
||||||
#[macro_export] macro_rules! from_jack {
|
|
||||||
(|$jack:ident|$Struct:ident$(<$($L:lifetime),*$($T:ident$(:$U:path)?),*>)? $cb:expr) => {
|
|
||||||
impl $(<$($L),*$($T $(: $U)?),*>)? TryFrom<&Arc<RwLock<JackConnection>>> for $Struct $(<$($L),*$($T),*>)? {
|
|
||||||
type Error = Box<dyn std::error::Error>;
|
|
||||||
fn try_from ($jack: &Arc<RwLock<JackConnection>>) -> Usually<Self> { Ok($cb) }
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
150
jack/src/jack_client.rs
Normal file
150
jack/src/jack_client.rs
Normal file
|
|
@ -0,0 +1,150 @@
|
||||||
|
use crate::*;
|
||||||
|
use self::JackClientState::*;
|
||||||
|
|
||||||
|
/// Wraps [JackClientState] and through it [jack::Client].
|
||||||
|
#[derive(Clone, Debug, Default)]
|
||||||
|
pub struct JackClient {
|
||||||
|
state: Arc<RwLock<JackClientState>>
|
||||||
|
}
|
||||||
|
impl JackClient {
|
||||||
|
pub fn new (name: &str) -> Usually<Self> {
|
||||||
|
let (client, _) = Client::new(name, ClientOptions::NO_START_SERVER)?;
|
||||||
|
Ok(Self { state: Arc::new(RwLock::new(Inactive(client))) })
|
||||||
|
}
|
||||||
|
/// Return the internal [Client] handle that lets you call the JACK API.
|
||||||
|
pub fn inner (&self) -> Client {
|
||||||
|
self.state.read().unwrap().inner()
|
||||||
|
}
|
||||||
|
/// Activate a connection with an application.
|
||||||
|
///
|
||||||
|
/// Consume a `JackClient::Inactive`, binding a process callback and returning a `JackClient::Active`.
|
||||||
|
///
|
||||||
|
/// * [ ] TODO: Needs work. Strange ownership situation between the callback and the host object.
|
||||||
|
fn activate <'a: 'static> (
|
||||||
|
&'a self, mut cb: impl FnMut(JackClient, &Client, &ProcessScope) -> Control + Send + 'a
|
||||||
|
) -> Usually<Self> where Self: Send + Sync + 'a {
|
||||||
|
let client = self.inner();
|
||||||
|
let state = Arc::new(RwLock::new(Activating));
|
||||||
|
let event = Box::new(move|_|{/*TODO*/}) as Box<dyn Fn(JackEvent) + Send + Sync>;
|
||||||
|
let events = Notifications(event);
|
||||||
|
let frame = Box::new(move|c: &_, s: &_|cb(self.clone(), c, s));
|
||||||
|
let frames = ClosureProcessHandler::new(frame as BoxedAudioHandler<'a>);
|
||||||
|
*state.write().unwrap() = Active(client.activate_async(events, frames)?);
|
||||||
|
Ok(Self { state })
|
||||||
|
}
|
||||||
|
/// Activate a connection with an application.
|
||||||
|
///
|
||||||
|
/// * Wrap a [JackClient::Inactive] into [Arc<RwLock<_>>].
|
||||||
|
/// * Pass it to the `init` callback
|
||||||
|
/// * This allows user code to connect to JACK
|
||||||
|
/// * While user code retains clone of the
|
||||||
|
/// [Arc<RwLock<JackClient>>] that is
|
||||||
|
/// passed to `init`, the audio engine is running.
|
||||||
|
pub fn activate_with <'a: 'static, T> (
|
||||||
|
&self, init: impl FnOnce(&JackClient)->Usually<T>
|
||||||
|
) -> Usually<Arc<RwLock<T>>> where T: Audio + 'a {
|
||||||
|
// Run init callback. Return value is target. Target must retain clone of `connection`.
|
||||||
|
let target = Arc::new(RwLock::new(init(&self)?));
|
||||||
|
// Swap the `client` from the `JackClient::Inactive`
|
||||||
|
// for a `JackClient::Activating`.
|
||||||
|
let mut client = Activating;
|
||||||
|
std::mem::swap(&mut*self.state.write().unwrap(), &mut client);
|
||||||
|
// Replace the `JackClient::Activating` with a
|
||||||
|
// `JackClient::Active` wrapping the [AsyncClient]
|
||||||
|
// returned by the activation.
|
||||||
|
*self.state.write().unwrap() = Active(client.inner().activate_async(
|
||||||
|
// This is the misc notifications handler. It's a struct that wraps a [Box]
|
||||||
|
// which performs type erasure on a callback that takes [JackEvent], which is
|
||||||
|
// one of the available misc notifications.
|
||||||
|
Notifications(Box::new(move|_|{/*TODO*/}) as BoxedJackEventHandler),
|
||||||
|
// This is the main processing handler. It's a struct that wraps a [Box]
|
||||||
|
// which performs type erasure on a callback that takes [Client] and [ProcessScope]
|
||||||
|
// and passes them down to the `target`'s `process` callback, which in turn
|
||||||
|
// implements audio and MIDI input and output on a realtime basis.
|
||||||
|
ClosureProcessHandler::new(Box::new({
|
||||||
|
let target = target.clone();
|
||||||
|
move|c: &_, s: &_|if let Ok(mut target) = target.write() {
|
||||||
|
target.process(c, s)
|
||||||
|
} else {
|
||||||
|
Control::Quit
|
||||||
|
}
|
||||||
|
}) as BoxedAudioHandler),
|
||||||
|
)?);
|
||||||
|
Ok(target)
|
||||||
|
}
|
||||||
|
pub fn port_by_name (&self, name: &str) -> Option<Port<Unowned>> {
|
||||||
|
self.inner().port_by_name(name)
|
||||||
|
}
|
||||||
|
pub fn register_port <PS: PortSpec> (&self, name: &str, spec: PS) -> Usually<Port<PS>> {
|
||||||
|
Ok(self.inner().register_port(name, spec)?)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// This is a connection which may be [Inactive], [Activating], or [Active].
|
||||||
|
/// In the [Active] and [Inactive] states, [JackClientState::client] returns a
|
||||||
|
/// [jack::Client], which you can use to talk to the JACK API.
|
||||||
|
#[derive(Debug, Default)] enum JackClientState {
|
||||||
|
/// Unused
|
||||||
|
#[default] Inert,
|
||||||
|
/// Before activation.
|
||||||
|
Inactive(Client),
|
||||||
|
/// During activation.
|
||||||
|
Activating,
|
||||||
|
/// After activation. Must not be dropped for JACK thread to persist.
|
||||||
|
Active(DynamicAsyncClient<'static>),
|
||||||
|
}
|
||||||
|
impl JackClientState {
|
||||||
|
pub fn inner (&self) -> Client {
|
||||||
|
match self {
|
||||||
|
Inert => panic!("jack client not activated"),
|
||||||
|
Inactive(ref client) => unsafe { Client::from_raw(client.raw()) },
|
||||||
|
Activating => panic!("jack client has not finished activation"),
|
||||||
|
Active(ref client) => unsafe { Client::from_raw(client.as_client().raw()) },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// This is a boxed realtime callback.
|
||||||
|
pub type BoxedAudioHandler<'j> =
|
||||||
|
Box<dyn FnMut(&Client, &ProcessScope) -> Control + Send + 'j>;
|
||||||
|
/// This is the notification handler wrapper for a boxed realtime callback.
|
||||||
|
pub type DynamicAudioHandler<'j> =
|
||||||
|
ClosureProcessHandler<(), BoxedAudioHandler<'j>>;
|
||||||
|
/// This is a boxed [JackEvent] callback.
|
||||||
|
pub type BoxedJackEventHandler<'j> =
|
||||||
|
Box<dyn Fn(JackEvent) + Send + Sync + 'j>;
|
||||||
|
/// This is the notification handler wrapper for a boxed [JackEvent] callback.
|
||||||
|
pub type DynamicNotifications<'j> =
|
||||||
|
Notifications<BoxedJackEventHandler<'j>>;
|
||||||
|
/// This is a running JACK [AsyncClient] with maximum type erasure.
|
||||||
|
/// It has one [Box] containing a function that handles [JackEvent]s,
|
||||||
|
/// and another [Box] containing a function that handles realtime IO,
|
||||||
|
/// and that's all it knows about them.
|
||||||
|
pub type DynamicAsyncClient<'j>
|
||||||
|
= AsyncClient<DynamicNotifications<'j>, DynamicAudioHandler<'j>>;
|
||||||
|
|
||||||
|
impl RegisterPort for JackClient {
|
||||||
|
fn midi_in (&self, name: impl AsRef<str>) -> Usually<Port<MidiIn>> {
|
||||||
|
Ok(self.inner().register_port(name.as_ref(), MidiIn::default())?)
|
||||||
|
}
|
||||||
|
fn midi_out (&self, name: impl AsRef<str>) -> Usually<Port<MidiOut>> {
|
||||||
|
Ok(self.inner().register_port(name.as_ref(), MidiOut::default())?)
|
||||||
|
}
|
||||||
|
fn audio_in (&self, name: impl AsRef<str>) -> Usually<Port<AudioIn>> {
|
||||||
|
Ok(self.inner().register_port(name.as_ref(), AudioIn::default())?)
|
||||||
|
}
|
||||||
|
fn audio_out (&self, name: impl AsRef<str>) -> Usually<Port<AudioOut>> {
|
||||||
|
Ok(self.inner().register_port(name.as_ref(), AudioOut::default())?)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl ConnectPort for JackClient {
|
||||||
|
fn ports (&self, re_name: Option<&str>, re_type: Option<&str>, flags: PortFlags) -> Vec<String> {
|
||||||
|
self.inner().ports(re_name, re_type, flags)
|
||||||
|
}
|
||||||
|
fn port_by_name (&self, name: impl AsRef<str>) -> Option<Port<Unowned>> {
|
||||||
|
self.inner().port_by_name(name.as_ref())
|
||||||
|
}
|
||||||
|
fn connect_ports <A: PortSpec, B: PortSpec> (&self, source: &Port<A>, target: &Port<B>)
|
||||||
|
-> Usually<()>
|
||||||
|
{
|
||||||
|
Ok(self.inner().connect_ports(source, target)?)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,136 +1,165 @@
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
pub trait JackPortConnect<T: PortSpec> {
|
||||||
/// This is a boxed realtime callback.
|
fn jack (&self) -> &JackClient;
|
||||||
pub type BoxedAudioHandler = Box<dyn FnMut(&Client, &ProcessScope) -> Control + Send>;
|
fn port (&self) -> &Port<T>;
|
||||||
|
fn conn (&self) -> &[PortConnection];
|
||||||
/// This is the notification handler wrapper for a boxed realtime callback.
|
fn connect_to_matching (&mut self) -> Usually<()> {
|
||||||
pub type DynamicAudioHandler = ClosureProcessHandler<(), BoxedAudioHandler>;
|
use PortConnectionName::*;
|
||||||
|
use PortConnectionScope::*;
|
||||||
/// This is a boxed [JackEvent] callback.
|
use PortConnectionStatus::*;
|
||||||
pub type BoxedJackEventHandler = Box<dyn Fn(JackEvent) + Send + Sync>;
|
let jack = self.jack();
|
||||||
|
for connect in self.conn().iter() {
|
||||||
/// This is the notification handler wrapper for a boxed [JackEvent] callback.
|
let mut status = vec![];
|
||||||
pub type DynamicNotifications = Notifications<BoxedJackEventHandler>;
|
match &connect.name {
|
||||||
|
Exact(name) => for port in jack.ports(None, None, PortFlags::empty()).iter() {
|
||||||
/// This is a running JACK [AsyncClient] with maximum type erasure.
|
if port.as_str() == &**name {
|
||||||
/// It has one [Box] containing a function that handles [JackEvent]s,
|
if let Some(port) = jack.port_by_name(port.as_str()) {
|
||||||
/// and another [Box] containing a function that handles realtime IO,
|
let port_status = Self::try_both_ways(jack, &port, &self.port());
|
||||||
/// and that's all it knows about them.
|
let name = port.name()?.into();
|
||||||
pub type DynamicAsyncClient = AsyncClient<DynamicNotifications, DynamicAudioHandler>;
|
status.push((port, name, port_status));
|
||||||
|
if port_status == Connected {
|
||||||
/// This is a connection which may be `Inactive`, `Activating`, or `Active`.
|
break
|
||||||
/// In the `Active` and `Inactive` states, its `client` method returns a
|
}
|
||||||
/// [Client] which you can use to talk to the JACK API.
|
}
|
||||||
#[derive(Debug, Default)]
|
}
|
||||||
pub enum JackConnection {
|
},
|
||||||
#[default]
|
RegExp(re) => for port in jack.ports(Some(&re), None, PortFlags::empty()).iter() {
|
||||||
Inert,
|
if let Some(port) = jack.port_by_name(port.as_str()) {
|
||||||
/// Before activation.
|
let port_status = Self::try_both_ways(jack, &port, &self.port());
|
||||||
Inactive(Client),
|
let name = port.name()?.into();
|
||||||
/// During activation.
|
status.push((port, name, port_status));
|
||||||
Activating,
|
if port_status == Connected && connect.scope == One {
|
||||||
/// After activation. Must not be dropped for JACK thread to persist.
|
break
|
||||||
Active(DynamicAsyncClient),
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<JackConnection> for Client {
|
|
||||||
fn from (jack: JackConnection) -> Self {
|
|
||||||
match jack {
|
|
||||||
JackConnection::Inactive(client) => client,
|
|
||||||
JackConnection::Inert => panic!("jack client not activated"),
|
|
||||||
JackConnection::Activating => panic!("jack client still activating"),
|
|
||||||
JackConnection::Active(_) => panic!("jack client already activated"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl JackConnection {
|
|
||||||
pub fn new (name: &str) -> Usually<Self> {
|
|
||||||
let (client, _) = Client::new(name, ClientOptions::NO_START_SERVER)?;
|
|
||||||
Ok(Self::Inactive(client))
|
|
||||||
}
|
|
||||||
/// Return the internal [Client] handle that lets you call the JACK API.
|
|
||||||
pub fn client (&self) -> &Client {
|
|
||||||
match self {
|
|
||||||
Self::Inert => panic!("jack client not activated"),
|
|
||||||
Self::Inactive(ref client) => client,
|
|
||||||
Self::Activating => panic!("jack client has not finished activation"),
|
|
||||||
Self::Active(ref client) => client.as_client(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// Activate a connection with an application.
|
|
||||||
///
|
|
||||||
/// Consume a `JackConnection::Inactive`,
|
|
||||||
/// binding a process callback and
|
|
||||||
/// returning a `JackConnection::Active`.
|
|
||||||
///
|
|
||||||
/// Needs work. Strange ownership situation between the callback
|
|
||||||
/// and the host object.
|
|
||||||
fn activate (
|
|
||||||
self,
|
|
||||||
mut cb: impl FnMut(&Arc<RwLock<Self>>, &Client, &ProcessScope) -> Control + Send + 'static,
|
|
||||||
) -> Usually<Arc<RwLock<Self>>>
|
|
||||||
where
|
|
||||||
Self: Send + Sync + 'static
|
|
||||||
{
|
|
||||||
let client = Client::from(self);
|
|
||||||
let state = Arc::new(RwLock::new(Self::Activating));
|
|
||||||
let event = Box::new(move|_|{/*TODO*/}) as Box<dyn Fn(JackEvent) + Send + Sync>;
|
|
||||||
let events = Notifications(event);
|
|
||||||
let frame = Box::new({let state = state.clone(); move|c: &_, s: &_|cb(&state, c, s)});
|
|
||||||
let frames = ClosureProcessHandler::new(frame as BoxedAudioHandler);
|
|
||||||
*state.write().unwrap() = Self::Active(client.activate_async(events, frames)?);
|
|
||||||
Ok(state)
|
|
||||||
}
|
|
||||||
/// Activate a connection with an application.
|
|
||||||
///
|
|
||||||
/// * Wrap a [JackConnection::Inactive] into [Arc<RwLock<_>>].
|
|
||||||
/// * Pass it to the `init` callback
|
|
||||||
/// * This allows user code to connect to JACK
|
|
||||||
/// * While user code retains clone of the
|
|
||||||
/// [Arc<RwLock<JackConnection>>] that is
|
|
||||||
/// passed to `init`, the audio engine is running.
|
|
||||||
pub fn activate_with <T: Audio + 'static> (
|
|
||||||
self,
|
|
||||||
init: impl FnOnce(&Arc<RwLock<JackConnection>>)->Usually<T>
|
|
||||||
)
|
|
||||||
-> Usually<Arc<RwLock<T>>>
|
|
||||||
{
|
|
||||||
// Wrap self for multiple ownership.
|
|
||||||
let connection = Arc::new(RwLock::new(self));
|
|
||||||
// Run init callback. Return value is target. Target must retain clone of `connection`.
|
|
||||||
let target = Arc::new(RwLock::new(init(&connection)?));
|
|
||||||
// Swap the `client` from the `JackConnection::Inactive`
|
|
||||||
// for a `JackConnection::Activating`.
|
|
||||||
let mut client = Self::Activating;
|
|
||||||
std::mem::swap(&mut*connection.write().unwrap(), &mut client);
|
|
||||||
// Replace the `JackConnection::Activating` with a
|
|
||||||
// `JackConnection::Active` wrapping the [AsyncClient]
|
|
||||||
// returned by the activation.
|
|
||||||
*connection.write().unwrap() = Self::Active(Client::from(client).activate_async(
|
|
||||||
// This is the misc notifications handler. It's a struct that wraps a [Box]
|
|
||||||
// which performs type erasure on a callback that takes [JackEvent], which is
|
|
||||||
// one of the available misc notifications.
|
|
||||||
Notifications(Box::new(move|_|{/*TODO*/}) as BoxedJackEventHandler),
|
|
||||||
// This is the main processing handler. It's a struct that wraps a [Box]
|
|
||||||
// which performs type erasure on a callback that takes [Client] and [ProcessScope]
|
|
||||||
// and passes them down to the `target`'s `process` callback, which in turn
|
|
||||||
// implements audio and MIDI input and output on a realtime basis.
|
|
||||||
ClosureProcessHandler::new(Box::new({
|
|
||||||
let target = target.clone();
|
|
||||||
move|c: &_, s: &_|if let Ok(mut target) = target.write() {
|
|
||||||
target.process(c, s)
|
|
||||||
} else {
|
|
||||||
Control::Quit
|
|
||||||
}
|
}
|
||||||
}) as BoxedAudioHandler),
|
}
|
||||||
)?);
|
*connect.status.write().unwrap() = status
|
||||||
Ok(target)
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
pub fn port_by_name (&self, name: &str) -> Option<Port<Unowned>> {
|
fn try_both_ways <A, B> (
|
||||||
self.client().port_by_name(name)
|
jack: &impl ConnectPort, port_a: &Port<A>, port_b: &Port<B>
|
||||||
}
|
) -> PortConnectionStatus where A: PortSpec, B: PortSpec {
|
||||||
pub fn register_port <PS: PortSpec> (&self, name: &str, spec: PS) -> Usually<Port<PS>> {
|
if let Ok(_) = jack.connect_ports(port_a, port_b) {
|
||||||
Ok(self.client().register_port(name, spec)?)
|
PortConnectionStatus::Connected
|
||||||
|
} else if let Ok(_) = jack.connect_ports(port_b, port_a) {
|
||||||
|
PortConnectionStatus::Connected
|
||||||
|
} else {
|
||||||
|
PortConnectionStatus::Mismatch
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct PortConnection {
|
||||||
|
pub name: PortConnectionName,
|
||||||
|
pub scope: PortConnectionScope,
|
||||||
|
pub status: Arc<RwLock<Vec<(Port<Unowned>, Arc<str>, PortConnectionStatus)>>>,
|
||||||
|
}
|
||||||
|
pub trait ConnectPort {
|
||||||
|
fn ports (&self, re_name: Option<&str>, re_type: Option<&str>, flags: PortFlags) -> Vec<String>;
|
||||||
|
fn port_by_name (&self, name: impl AsRef<str>) -> Option<Port<Unowned>>;
|
||||||
|
fn connect_ports <A: PortSpec, B: PortSpec> (&self, source: &Port<A>, target: &Port<B>)
|
||||||
|
-> Usually<()>;
|
||||||
|
fn connect_midi_from (&self, input: &Port<MidiIn>, ports: &[impl AsRef<str>]) -> Usually<()> {
|
||||||
|
for port in ports.iter() {
|
||||||
|
let port = port.as_ref();
|
||||||
|
if let Some(port) = self.port_by_name(port).as_ref() {
|
||||||
|
self.connect_ports(port, input)?;
|
||||||
|
} else {
|
||||||
|
panic!("Missing MIDI output: {port}. Use jack_lsp to list all port names.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
fn connect_midi_to (&self, output: &Port<MidiOut>, ports: &[impl AsRef<str>]) -> Usually<()> {
|
||||||
|
for port in ports.iter() {
|
||||||
|
let port = port.as_ref();
|
||||||
|
if let Some(port) = self.port_by_name(port).as_ref() {
|
||||||
|
self.connect_ports(output, port)?;
|
||||||
|
} else {
|
||||||
|
panic!("Missing MIDI input: {port}. Use jack_lsp to list all port names.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
fn connect_audio_from (&self, input: &Port<AudioIn>, ports: &[impl AsRef<str>]) -> Usually<()> {
|
||||||
|
for port in ports.iter() {
|
||||||
|
let port = port.as_ref();
|
||||||
|
if let Some(port) = self.port_by_name(port).as_ref() {
|
||||||
|
self.connect_ports(port, input)?;
|
||||||
|
} else {
|
||||||
|
panic!("Missing MIDI output: {port}. Use jack_lsp to list all port names.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
fn connect_audio_to (&self, output: &Port<AudioOut>, ports: &[impl AsRef<str>]) -> Usually<()> {
|
||||||
|
for port in ports.iter() {
|
||||||
|
let port = port.as_ref();
|
||||||
|
if let Some(port) = self.port_by_name(port).as_ref() {
|
||||||
|
self.connect_ports(output, port)?;
|
||||||
|
} else {
|
||||||
|
panic!("Missing MIDI input: {port}. Use jack_lsp to list all port names.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl<T: ConnectPort> ConnectPort for Arc<RwLock<T>> {
|
||||||
|
fn ports (&self, re_name: Option<&str>, re_type: Option<&str>, flags: PortFlags) -> Vec<String> {
|
||||||
|
self.read().unwrap().ports(re_name, re_type, flags)
|
||||||
|
}
|
||||||
|
fn port_by_name (&self, name: impl AsRef<str>) -> Option<Port<Unowned>> {
|
||||||
|
self.read().unwrap().port_by_name(name.as_ref())
|
||||||
|
}
|
||||||
|
fn connect_ports <A: PortSpec, B: PortSpec> (&self, source: &Port<A>, target: &Port<B>)
|
||||||
|
-> Usually<()>
|
||||||
|
{
|
||||||
|
Ok(self.read().unwrap().connect_ports(source, target)?)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl PortConnection {
|
||||||
|
pub fn collect (exact: &[impl AsRef<str>], re: &[impl AsRef<str>], re_all: &[impl AsRef<str>])
|
||||||
|
-> Vec<Self>
|
||||||
|
{
|
||||||
|
let mut connections = vec![];
|
||||||
|
for port in exact.iter() { connections.push(Self::exact(port)) }
|
||||||
|
for port in re.iter() { connections.push(Self::regexp(port)) }
|
||||||
|
for port in re_all.iter() { connections.push(Self::regexp_all(port)) }
|
||||||
|
connections
|
||||||
|
}
|
||||||
|
/// Connect to this exact port
|
||||||
|
pub fn exact (name: impl AsRef<str>) -> Self {
|
||||||
|
let name = PortConnectionName::Exact(name.as_ref().into());
|
||||||
|
Self { name, scope: PortConnectionScope::One, status: Arc::new(RwLock::new(vec![])) }
|
||||||
|
}
|
||||||
|
pub fn regexp (name: impl AsRef<str>) -> Self {
|
||||||
|
let name = PortConnectionName::RegExp(name.as_ref().into());
|
||||||
|
Self { name, scope: PortConnectionScope::One, status: Arc::new(RwLock::new(vec![])) }
|
||||||
|
}
|
||||||
|
pub fn regexp_all (name: impl AsRef<str>) -> Self {
|
||||||
|
let name = PortConnectionName::RegExp(name.as_ref().into());
|
||||||
|
Self { name, scope: PortConnectionScope::All, status: Arc::new(RwLock::new(vec![])) }
|
||||||
|
}
|
||||||
|
pub fn info (&self) -> Arc<str> {
|
||||||
|
format!("{} {} {}", match self.scope {
|
||||||
|
PortConnectionScope::One => " ",
|
||||||
|
PortConnectionScope::All => "*",
|
||||||
|
}, match &self.name {
|
||||||
|
PortConnectionName::Exact(name) => format!("= {name}"),
|
||||||
|
PortConnectionName::RegExp(name) => format!("~ {name}"),
|
||||||
|
}, self.status.read().unwrap().len()).into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
|
pub enum PortConnectionName {
|
||||||
|
/** Exact match */
|
||||||
|
Exact(Arc<str>),
|
||||||
|
/** Match regular expression */
|
||||||
|
RegExp(Arc<str>),
|
||||||
|
}
|
||||||
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||||
|
pub enum PortConnectionScope { One, All }
|
||||||
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||||
|
pub enum PortConnectionStatus { Missing, Disconnected, Connected, Mismatch, }
|
||||||
|
|
|
||||||
|
|
@ -1,279 +1,56 @@
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
|
||||||
#[derive(Debug)]
|
macro_rules! impl_port {
|
||||||
pub struct JackPort<T: PortSpec> {
|
($Name:ident $Spec:ident |$jack:ident, $name:ident|$port:expr) => {
|
||||||
/// Handle to JACK client, for receiving reconnect events.
|
#[derive(Debug)] pub struct $Name {
|
||||||
pub jack: Arc<RwLock<JackConnection>>,
|
/// Handle to JACK client, for receiving reconnect events.
|
||||||
/// Port name
|
pub jack: JackClient,
|
||||||
pub name: Arc<str>,
|
/// Port name
|
||||||
/// Port handle.
|
pub name: Arc<str>,
|
||||||
pub port: Port<T>,
|
/// Port handle.
|
||||||
/// List of ports to connect to.
|
pub port: Port<$Spec>,
|
||||||
pub connect: Vec<PortConnection>
|
/// List of ports to connect to.
|
||||||
}
|
pub conn: Vec<PortConnection>
|
||||||
impl<T: PortSpec> JackPort<T> {
|
}
|
||||||
pub fn connect_to_matching (&mut self) -> Usually<()> {
|
impl AsRef<Port<$Spec>> for $Name { fn as_ref (&self) -> &Port<$Spec> { &self.port } }
|
||||||
use PortConnectionName::*;
|
impl $Name {
|
||||||
use PortConnectionScope::*;
|
pub fn new ($jack: &JackClient, name: impl AsRef<str>, connect: &[PortConnection])
|
||||||
use PortConnectionStatus::*;
|
-> Usually<Self>
|
||||||
for connect in self.connect.iter_mut() {
|
{
|
||||||
let mut status = vec![];
|
let $name = name.as_ref();
|
||||||
match &connect.name {
|
let mut port = Self {
|
||||||
Exact(name) => for port in self.jack.ports(None, None, PortFlags::empty()).iter() {
|
jack: $jack.clone(),
|
||||||
if port.as_str() == &**name {
|
port: $port?,
|
||||||
if let Some(port) = self.jack.port_by_name(port.as_str()) {
|
name: $name.into(),
|
||||||
let port_status = Self::try_both_ways(&self.jack, &port, &self.port);
|
conn: connect.to_vec()
|
||||||
let name = port.name()?.into();
|
};
|
||||||
status.push((port, name, port_status));
|
port.connect_to_matching()?;
|
||||||
if port_status == Connected {
|
Ok(port)
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
RegExp(re) => for port in self.jack.ports(Some(&re), None, PortFlags::empty()).iter() {
|
|
||||||
if let Some(port) = self.jack.port_by_name(port.as_str()) {
|
|
||||||
let port_status = Self::try_both_ways(&self.jack, &port, &self.port);
|
|
||||||
let name = port.name()?.into();
|
|
||||||
status.push((port, name, port_status));
|
|
||||||
if port_status == Connected && connect.scope == One {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
connect.status = status
|
|
||||||
}
|
}
|
||||||
Ok(())
|
impl JackPortConnect<$Spec> for $Name {
|
||||||
}
|
fn jack (&self) -> &JackClient { &self.jack }
|
||||||
fn try_both_ways <A: PortSpec, B: PortSpec> (
|
fn port (&self) -> &Port<$Spec> { &self.port }
|
||||||
jack: &impl ConnectPort, port_a: &Port<A>, port_b: &Port<B>
|
fn conn (&self) -> &[PortConnection] { self.conn.as_slice() }
|
||||||
)
|
|
||||||
-> PortConnectionStatus
|
|
||||||
{
|
|
||||||
if let Ok(_) = jack.connect_ports(port_a, port_b) {
|
|
||||||
PortConnectionStatus::Connected
|
|
||||||
} else if let Ok(_) = jack.connect_ports(port_b, port_a) {
|
|
||||||
PortConnectionStatus::Connected
|
|
||||||
} else {
|
|
||||||
PortConnectionStatus::Mismatch
|
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
impl_port! { JackAudioIn AudioIn |jack, name|jack.audio_in(name) }
|
||||||
pub struct PortConnection {
|
impl_port! { JackAudioOut AudioOut |jack, name|jack.audio_out(name) }
|
||||||
pub name: PortConnectionName,
|
impl_port! { JackMidiIn MidiIn |jack, name|jack.midi_in(name) }
|
||||||
pub scope: PortConnectionScope,
|
impl_port! { JackMidiOut MidiOut |jack, name|jack.midi_out(name) }
|
||||||
pub status: Vec<(Port<Unowned>, Arc<str>, PortConnectionStatus)>,
|
|
||||||
}
|
|
||||||
impl PortConnection {
|
|
||||||
pub fn collect (exact: &[impl AsRef<str>], re: &[impl AsRef<str>], re_all: &[impl AsRef<str>])
|
|
||||||
-> Vec<Self>
|
|
||||||
{
|
|
||||||
let mut connections = vec![];
|
|
||||||
for port in exact.iter() { connections.push(Self::exact(port)) }
|
|
||||||
for port in re.iter() { connections.push(Self::regexp(port)) }
|
|
||||||
for port in re_all.iter() { connections.push(Self::regexp_all(port)) }
|
|
||||||
connections
|
|
||||||
}
|
|
||||||
/// Connect to this exact port
|
|
||||||
pub fn exact (name: impl AsRef<str>) -> Self {
|
|
||||||
let name = PortConnectionName::Exact(name.as_ref().into());
|
|
||||||
Self { name, scope: PortConnectionScope::One, status: vec![] }
|
|
||||||
}
|
|
||||||
pub fn regexp (name: impl AsRef<str>) -> Self {
|
|
||||||
let name = PortConnectionName::RegExp(name.as_ref().into());
|
|
||||||
Self { name, scope: PortConnectionScope::One, status: vec![] }
|
|
||||||
}
|
|
||||||
pub fn regexp_all (name: impl AsRef<str>) -> Self {
|
|
||||||
let name = PortConnectionName::RegExp(name.as_ref().into());
|
|
||||||
Self { name, scope: PortConnectionScope::All, status: vec![] }
|
|
||||||
}
|
|
||||||
pub fn info (&self) -> Arc<str> {
|
|
||||||
format!("{} {} {}", match self.scope {
|
|
||||||
PortConnectionScope::One => " ",
|
|
||||||
PortConnectionScope::All => "*",
|
|
||||||
}, match &self.name {
|
|
||||||
PortConnectionName::Exact(name) => format!("= {name}"),
|
|
||||||
PortConnectionName::RegExp(name) => format!("~ {name}"),
|
|
||||||
}, self.status.len()).into()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
|
||||||
pub enum PortConnectionName {
|
|
||||||
/** Exact match */
|
|
||||||
Exact(Arc<str>),
|
|
||||||
/** Match regular expression */
|
|
||||||
RegExp(Arc<str>),
|
|
||||||
}
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
|
||||||
pub enum PortConnectionScope { One, All }
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
|
||||||
pub enum PortConnectionStatus { Missing, Disconnected, Connected, Mismatch, }
|
|
||||||
|
|
||||||
impl<T: PortSpec> AsRef<Port<T>> for JackPort<T> {
|
|
||||||
fn as_ref (&self) -> &Port<T> {
|
|
||||||
&self.port
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl JackPort<MidiIn> {
|
|
||||||
pub fn new (
|
|
||||||
jack: &Arc<RwLock<JackConnection>>, name: impl AsRef<str>, connect: &[PortConnection]
|
|
||||||
) -> Usually<Self> {
|
|
||||||
let mut port = JackPort {
|
|
||||||
jack: jack.clone(),
|
|
||||||
port: jack.midi_in(name.as_ref())?,
|
|
||||||
name: name.as_ref().into(),
|
|
||||||
connect: connect.to_vec()
|
|
||||||
};
|
|
||||||
port.connect_to_matching()?;
|
|
||||||
Ok(port)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl JackPort<MidiOut> {
|
|
||||||
pub fn new (
|
|
||||||
jack: &Arc<RwLock<JackConnection>>, name: impl AsRef<str>, connect: &[PortConnection]
|
|
||||||
) -> Usually<Self> {
|
|
||||||
let mut port = Self {
|
|
||||||
jack: jack.clone(),
|
|
||||||
port: jack.midi_out(name.as_ref())?,
|
|
||||||
name: name.as_ref().into(),
|
|
||||||
connect: connect.to_vec()
|
|
||||||
};
|
|
||||||
port.connect_to_matching()?;
|
|
||||||
Ok(port)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl JackPort<AudioIn> {
|
|
||||||
pub fn new (
|
|
||||||
jack: &Arc<RwLock<JackConnection>>, name: impl AsRef<str>, connect: &[PortConnection]
|
|
||||||
) -> Usually<Self> {
|
|
||||||
let mut port = Self {
|
|
||||||
jack: jack.clone(),
|
|
||||||
port: jack.audio_in(name.as_ref())?,
|
|
||||||
name: name.as_ref().into(),
|
|
||||||
connect: connect.to_vec()
|
|
||||||
};
|
|
||||||
port.connect_to_matching()?;
|
|
||||||
Ok(port)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl JackPort<AudioOut> {
|
|
||||||
pub fn new (
|
|
||||||
jack: &Arc<RwLock<JackConnection>>, name: impl AsRef<str>, connect: &[PortConnection]
|
|
||||||
) -> Usually<Self> {
|
|
||||||
let mut port = Self {
|
|
||||||
jack: jack.clone(),
|
|
||||||
port: jack.audio_out(name.as_ref())?,
|
|
||||||
name: name.as_ref().into(),
|
|
||||||
connect: connect.to_vec()
|
|
||||||
};
|
|
||||||
port.connect_to_matching()?;
|
|
||||||
Ok(port)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait ConnectPort {
|
|
||||||
fn ports (&self, re_name: Option<&str>, re_type: Option<&str>, flags: PortFlags) -> Vec<String>;
|
|
||||||
fn port_by_name (&self, name: impl AsRef<str>) -> Option<Port<Unowned>>;
|
|
||||||
fn connect_ports <A: PortSpec, B: PortSpec> (&self, source: &Port<A>, target: &Port<B>)
|
|
||||||
-> Usually<()>;
|
|
||||||
fn connect_midi_from (&self, input: &Port<MidiIn>, ports: &[impl AsRef<str>]) -> Usually<()> {
|
|
||||||
for port in ports.iter() {
|
|
||||||
let port = port.as_ref();
|
|
||||||
if let Some(port) = self.port_by_name(port).as_ref() {
|
|
||||||
self.connect_ports(port, input)?;
|
|
||||||
} else {
|
|
||||||
panic!("Missing MIDI output: {port}. Use jack_lsp to list all port names.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
fn connect_midi_to (&self, output: &Port<MidiOut>, ports: &[impl AsRef<str>]) -> Usually<()> {
|
|
||||||
for port in ports.iter() {
|
|
||||||
let port = port.as_ref();
|
|
||||||
if let Some(port) = self.port_by_name(port).as_ref() {
|
|
||||||
self.connect_ports(output, port)?;
|
|
||||||
} else {
|
|
||||||
panic!("Missing MIDI input: {port}. Use jack_lsp to list all port names.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
fn connect_audio_from (&self, input: &Port<AudioIn>, ports: &[impl AsRef<str>]) -> Usually<()> {
|
|
||||||
for port in ports.iter() {
|
|
||||||
let port = port.as_ref();
|
|
||||||
if let Some(port) = self.port_by_name(port).as_ref() {
|
|
||||||
self.connect_ports(port, input)?;
|
|
||||||
} else {
|
|
||||||
panic!("Missing MIDI output: {port}. Use jack_lsp to list all port names.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
fn connect_audio_to (&self, output: &Port<AudioOut>, ports: &[impl AsRef<str>]) -> Usually<()> {
|
|
||||||
for port in ports.iter() {
|
|
||||||
let port = port.as_ref();
|
|
||||||
if let Some(port) = self.port_by_name(port).as_ref() {
|
|
||||||
self.connect_ports(output, port)?;
|
|
||||||
} else {
|
|
||||||
panic!("Missing MIDI input: {port}. Use jack_lsp to list all port names.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl ConnectPort for JackConnection {
|
|
||||||
fn ports (&self, re_name: Option<&str>, re_type: Option<&str>, flags: PortFlags) -> Vec<String> {
|
|
||||||
self.client().ports(re_name, re_type, flags)
|
|
||||||
}
|
|
||||||
fn port_by_name (&self, name: impl AsRef<str>) -> Option<Port<Unowned>> {
|
|
||||||
self.client().port_by_name(name.as_ref())
|
|
||||||
}
|
|
||||||
fn connect_ports <A: PortSpec, B: PortSpec> (&self, source: &Port<A>, target: &Port<B>)
|
|
||||||
-> Usually<()>
|
|
||||||
{
|
|
||||||
Ok(self.client().connect_ports(source, target)?)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl<T: ConnectPort> ConnectPort for Arc<RwLock<T>> {
|
|
||||||
fn ports (&self, re_name: Option<&str>, re_type: Option<&str>, flags: PortFlags) -> Vec<String> {
|
|
||||||
self.read().unwrap().ports(re_name, re_type, flags)
|
|
||||||
}
|
|
||||||
fn port_by_name (&self, name: impl AsRef<str>) -> Option<Port<Unowned>> {
|
|
||||||
self.read().unwrap().port_by_name(name.as_ref())
|
|
||||||
}
|
|
||||||
fn connect_ports <A: PortSpec, B: PortSpec> (&self, source: &Port<A>, target: &Port<B>)
|
|
||||||
-> Usually<()>
|
|
||||||
{
|
|
||||||
Ok(self.read().unwrap().connect_ports(source, target)?)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// This is a utility trait for things that may register or connect [Port]s.
|
/// This is a utility trait for things that may register or connect [Port]s.
|
||||||
/// It contains shorthand methods to this purpose. It's implemented for
|
/// It contains shorthand methods to this purpose. It's implemented for
|
||||||
/// `Arc<RwLock<JackConnection>>` for terse port registration in the
|
/// `Arc<RwLock<JackClient>>` for terse port registration in the
|
||||||
/// `init` callback of [JackClient::activate_with].
|
/// `init` callback of [jack::Client::activate_with].
|
||||||
pub trait RegisterPort {
|
pub trait RegisterPort {
|
||||||
fn midi_in (&self, name: impl AsRef<str>) -> Usually<Port<MidiIn>>;
|
fn midi_in (&self, name: impl AsRef<str>) -> Usually<Port<MidiIn>>;
|
||||||
fn midi_out (&self, name: impl AsRef<str>) -> Usually<Port<MidiOut>>;
|
fn midi_out (&self, name: impl AsRef<str>) -> Usually<Port<MidiOut>>;
|
||||||
fn audio_in (&self, name: impl AsRef<str>) -> Usually<Port<AudioIn>>;
|
fn audio_in (&self, name: impl AsRef<str>) -> Usually<Port<AudioIn>>;
|
||||||
fn audio_out (&self, name: impl AsRef<str>) -> Usually<Port<AudioOut>>;
|
fn audio_out (&self, name: impl AsRef<str>) -> Usually<Port<AudioOut>>;
|
||||||
}
|
}
|
||||||
impl RegisterPort for JackConnection {
|
|
||||||
fn midi_in (&self, name: impl AsRef<str>) -> Usually<Port<MidiIn>> {
|
|
||||||
Ok(self.client().register_port(name.as_ref(), MidiIn::default())?)
|
|
||||||
}
|
|
||||||
fn midi_out (&self, name: impl AsRef<str>) -> Usually<Port<MidiOut>> {
|
|
||||||
Ok(self.client().register_port(name.as_ref(), MidiOut::default())?)
|
|
||||||
}
|
|
||||||
fn audio_in (&self, name: impl AsRef<str>) -> Usually<Port<AudioIn>> {
|
|
||||||
Ok(self.client().register_port(name.as_ref(), AudioIn::default())?)
|
|
||||||
}
|
|
||||||
fn audio_out (&self, name: impl AsRef<str>) -> Usually<Port<AudioOut>> {
|
|
||||||
Ok(self.client().register_port(name.as_ref(), AudioOut::default())?)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl<T: RegisterPort> RegisterPort for Arc<RwLock<T>> {
|
impl<T: RegisterPort> RegisterPort for Arc<RwLock<T>> {
|
||||||
fn midi_in (&self, name: impl AsRef<str>) -> Usually<Port<MidiIn>> {
|
fn midi_in (&self, name: impl AsRef<str>) -> Usually<Port<MidiIn>> {
|
||||||
self.read().unwrap().midi_in(name)
|
self.read().unwrap().midi_in(name)
|
||||||
|
|
|
||||||
20
jack/src/jack_sync.rs
Normal file
20
jack/src/jack_sync.rs
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
use crate::*;
|
||||||
|
use jack::contrib::*;
|
||||||
|
|
||||||
|
pub trait SyncToTransport {
|
||||||
|
fn client (&self) -> Client;
|
||||||
|
fn sync_lead (&self, enable: bool, cb: impl Fn(TimebaseInfo)->Position) -> Usually<()> {
|
||||||
|
if enable {
|
||||||
|
self.client().register_timebase_callback(false, cb)?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
fn sync_follow (&self, enable: bool) -> Usually<()> {
|
||||||
|
// TODO: sync follow
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SyncToTransport for JackClient {
|
||||||
|
fn client (&self) -> Client { self.inner() }
|
||||||
|
}
|
||||||
|
|
@ -1,8 +1,16 @@
|
||||||
|
#![feature(type_alias_impl_trait)]
|
||||||
|
|
||||||
|
mod has_jack; pub use self::has_jack::*;
|
||||||
|
mod jack_audio; pub use self::jack_audio::*;
|
||||||
|
mod jack_connect; pub use self::jack_connect::*;
|
||||||
|
mod jack_client; pub use self::jack_client::*;
|
||||||
|
mod jack_event; pub use self::jack_event::*;
|
||||||
|
mod jack_port; pub use self::jack_port::*;
|
||||||
|
mod jack_sync; pub use self::jack_sync::*;
|
||||||
|
|
||||||
pub(crate) use std::sync::{Arc, RwLock};
|
pub(crate) use std::sync::{Arc, RwLock};
|
||||||
pub(crate) use std::collections::BTreeMap;
|
pub(crate) use std::collections::BTreeMap;
|
||||||
|
pub use ::jack; pub(crate) use ::jack::{
|
||||||
pub use ::jack;
|
|
||||||
pub(crate) use ::jack::{
|
|
||||||
contrib::ClosureProcessHandler, NotificationHandler,
|
contrib::ClosureProcessHandler, NotificationHandler,
|
||||||
Client, AsyncClient, ClientOptions, ClientStatus,
|
Client, AsyncClient, ClientOptions, ClientStatus,
|
||||||
ProcessScope, Control, Frames,
|
ProcessScope, Control, Frames,
|
||||||
|
|
@ -10,12 +18,6 @@ pub(crate) use ::jack::{
|
||||||
Unowned, MidiIn, MidiOut, AudioIn, AudioOut,
|
Unowned, MidiIn, MidiOut, AudioIn, AudioOut,
|
||||||
};
|
};
|
||||||
|
|
||||||
mod has_jack; pub use self::has_jack::*;
|
|
||||||
mod jack_audio; pub use self::jack_audio::*;
|
|
||||||
mod jack_connect; pub use self::jack_connect::*;
|
|
||||||
mod jack_event; pub use self::jack_event::*;
|
|
||||||
mod jack_port; pub use self::jack_port::*;
|
|
||||||
|
|
||||||
pub(crate) type Usually<T> = Result<T, Box<dyn std::error::Error>>;
|
pub(crate) type Usually<T> = Result<T, Box<dyn std::error::Error>>;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@ use crate::*;
|
||||||
|
|
||||||
/// Trait for thing that may receive MIDI.
|
/// Trait for thing that may receive MIDI.
|
||||||
pub trait HasMidiIns {
|
pub trait HasMidiIns {
|
||||||
fn midi_ins (&self) -> &Vec<JackPort<MidiIn>>;
|
fn midi_ins (&self) -> &Vec<JackMidiIn>;
|
||||||
fn midi_ins_mut (&mut self) -> &mut Vec<JackPort<MidiIn>>;
|
fn midi_ins_mut (&mut self) -> &mut Vec<JackMidiIn>;
|
||||||
fn has_midi_ins (&self) -> bool {
|
fn has_midi_ins (&self) -> bool {
|
||||||
!self.midi_ins().is_empty()
|
!self.midi_ins().is_empty()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@ use crate::*;
|
||||||
|
|
||||||
/// Trait for thing that may output MIDI.
|
/// Trait for thing that may output MIDI.
|
||||||
pub trait HasMidiOuts {
|
pub trait HasMidiOuts {
|
||||||
fn midi_outs (&self) -> &Vec<JackPort<MidiOut>>;
|
fn midi_outs (&self) -> &Vec<JackMidiOut>;
|
||||||
fn midi_outs_mut (&mut self) -> &mut Vec<JackPort<MidiOut>>;
|
fn midi_outs_mut (&mut self) -> &mut Vec<JackMidiOut>;
|
||||||
fn has_midi_outs (&self) -> bool {
|
fn has_midi_outs (&self) -> bool {
|
||||||
!self.midi_outs().is_empty()
|
!self.midi_outs().is_empty()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,9 +30,9 @@ pub struct MidiPlayer {
|
||||||
/// Send all notes off
|
/// Send all notes off
|
||||||
pub reset: bool, // TODO?: after Some(nframes)
|
pub reset: bool, // TODO?: after Some(nframes)
|
||||||
/// Record from MIDI ports to current sequence.
|
/// Record from MIDI ports to current sequence.
|
||||||
pub midi_ins: Vec<JackPort<MidiIn>>,
|
pub midi_ins: Vec<JackMidiIn>,
|
||||||
/// Play from current sequence to MIDI ports
|
/// Play from current sequence to MIDI ports
|
||||||
pub midi_outs: Vec<JackPort<MidiOut>>,
|
pub midi_outs: Vec<JackMidiOut>,
|
||||||
/// Notes currently held at input
|
/// Notes currently held at input
|
||||||
pub notes_in: Arc<RwLock<[bool; 128]>>,
|
pub notes_in: Arc<RwLock<[bool; 128]>>,
|
||||||
/// Notes currently held at output
|
/// Notes currently held at output
|
||||||
|
|
@ -62,7 +62,7 @@ impl Default for MidiPlayer {
|
||||||
}
|
}
|
||||||
impl MidiPlayer {
|
impl MidiPlayer {
|
||||||
pub fn new (
|
pub fn new (
|
||||||
jack: &Arc<RwLock<JackConnection>>,
|
jack: &JackClient,
|
||||||
name: impl AsRef<str>,
|
name: impl AsRef<str>,
|
||||||
clip: Option<&Arc<RwLock<MidiClip>>>,
|
clip: Option<&Arc<RwLock<MidiClip>>>,
|
||||||
midi_from: &[PortConnection],
|
midi_from: &[PortConnection],
|
||||||
|
|
@ -71,8 +71,8 @@ impl MidiPlayer {
|
||||||
let name = name.as_ref();
|
let name = name.as_ref();
|
||||||
let clock = Clock::from(jack);
|
let clock = Clock::from(jack);
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
midi_ins: vec![JackPort::<MidiIn>::new(jack, format!("M/{name}"), midi_from)?,],
|
midi_ins: vec![JackMidiIn::new(jack, format!("M/{name}"), midi_from)?,],
|
||||||
midi_outs: vec![JackPort::<MidiOut>::new(jack, format!("{name}/M"), midi_to)?, ],
|
midi_outs: vec![JackMidiOut::new(jack, format!("{name}/M"), midi_to)?, ],
|
||||||
play_clip: Some((Moment::zero(&clock.timebase), clip.cloned())),
|
play_clip: Some((Moment::zero(&clock.timebase), clip.cloned())),
|
||||||
clock,
|
clock,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
|
@ -89,18 +89,18 @@ impl std::fmt::Debug for MidiPlayer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
from!(|clock: &Clock| MidiPlayer = Self {
|
from!(|clock: &Clock| MidiPlayer = Self {
|
||||||
clock: clock.clone(),
|
clock: clock.clone(),
|
||||||
midi_ins: vec![],
|
midi_ins: vec![],
|
||||||
midi_outs: vec![],
|
midi_outs: vec![],
|
||||||
note_buf: vec![0;8],
|
note_buf: vec![0;8],
|
||||||
reset: true,
|
reset: true,
|
||||||
recording: false,
|
recording: false,
|
||||||
monitoring: false,
|
monitoring: false,
|
||||||
overdub: false,
|
overdub: false,
|
||||||
play_clip: None,
|
play_clip: None,
|
||||||
next_clip: None,
|
next_clip: None,
|
||||||
notes_in: RwLock::new([false;128]).into(),
|
notes_in: RwLock::new([false;128]).into(),
|
||||||
notes_out: RwLock::new([false;128]).into(),
|
notes_out: RwLock::new([false;128]).into(),
|
||||||
});
|
});
|
||||||
from!(|state: (&Clock, &Arc<RwLock<MidiClip>>)|MidiPlayer = {
|
from!(|state: (&Clock, &Arc<RwLock<MidiClip>>)|MidiPlayer = {
|
||||||
let (clock, clip) = state;
|
let (clock, clip) = state;
|
||||||
|
|
@ -110,12 +110,12 @@ from!(|state: (&Clock, &Arc<RwLock<MidiClip>>)|MidiPlayer = {
|
||||||
});
|
});
|
||||||
has_clock!(|self: MidiPlayer|self.clock);
|
has_clock!(|self: MidiPlayer|self.clock);
|
||||||
impl HasMidiIns for MidiPlayer {
|
impl HasMidiIns for MidiPlayer {
|
||||||
fn midi_ins (&self) -> &Vec<JackPort<MidiIn>> { &self.midi_ins }
|
fn midi_ins (&self) -> &Vec<JackMidiIn> { &self.midi_ins }
|
||||||
fn midi_ins_mut (&mut self) -> &mut Vec<JackPort<MidiIn>> { &mut self.midi_ins }
|
fn midi_ins_mut (&mut self) -> &mut Vec<JackMidiIn> { &mut self.midi_ins }
|
||||||
}
|
}
|
||||||
impl HasMidiOuts for MidiPlayer {
|
impl HasMidiOuts for MidiPlayer {
|
||||||
fn midi_outs (&self) -> &Vec<JackPort<MidiOut>> { &self.midi_outs }
|
fn midi_outs (&self) -> &Vec<JackMidiOut> { &self.midi_outs }
|
||||||
fn midi_outs_mut (&mut self) -> &mut Vec<JackPort<MidiOut>> { &mut self.midi_outs }
|
fn midi_outs_mut (&mut self) -> &mut Vec<JackMidiOut> { &mut self.midi_outs }
|
||||||
fn midi_note (&mut self) -> &mut Vec<u8> { &mut self.note_buf }
|
fn midi_note (&mut self) -> &mut Vec<u8> { &mut self.note_buf }
|
||||||
}
|
}
|
||||||
/// Hosts the JACK callback for a single MIDI player
|
/// Hosts the JACK callback for a single MIDI player
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ use crate::*;
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Plugin {
|
pub struct Plugin {
|
||||||
/// JACK client handle (needs to not be dropped for standalone mode to work).
|
/// JACK client handle (needs to not be dropped for standalone mode to work).
|
||||||
pub jack: Arc<RwLock<JackConnection>>,
|
pub jack: JackClient,
|
||||||
pub name: Arc<str>,
|
pub name: Arc<str>,
|
||||||
pub path: Option<Arc<str>>,
|
pub path: Option<Arc<str>>,
|
||||||
pub plugin: Option<PluginKind>,
|
pub plugin: Option<PluginKind>,
|
||||||
|
|
@ -37,7 +37,7 @@ impl Debug for PluginKind {
|
||||||
}
|
}
|
||||||
impl Plugin {
|
impl Plugin {
|
||||||
pub fn new_lv2 (
|
pub fn new_lv2 (
|
||||||
jack: &Arc<RwLock<JackConnection>>,
|
jack: &JackClient,
|
||||||
name: &str,
|
name: &str,
|
||||||
path: &str,
|
path: &str,
|
||||||
) -> Usually<Self> {
|
) -> Usually<Self> {
|
||||||
|
|
@ -128,7 +128,7 @@ audio!(|self: PluginAudio, client, scope|{
|
||||||
impl Plugin {
|
impl Plugin {
|
||||||
/// Create a plugin host device.
|
/// Create a plugin host device.
|
||||||
pub fn new (
|
pub fn new (
|
||||||
jack: &Arc<RwLock<JackConnection>>,
|
jack: &JackClient,
|
||||||
name: &str,
|
name: &str,
|
||||||
) -> Usually<Self> {
|
) -> Usually<Self> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
|
|
@ -257,7 +257,7 @@ fn draw_header (state: &Plugin, to: &mut TuiOut, x: u16, y: u16, w: u16) {
|
||||||
//}
|
//}
|
||||||
//});
|
//});
|
||||||
|
|
||||||
//from_atom!("plugin/lv2" => |jack: &Arc<RwLock<JackConnection>>, args| -> Plugin {
|
//from_atom!("plugin/lv2" => |jack: &JackClient, args| -> Plugin {
|
||||||
//let mut name = String::new();
|
//let mut name = String::new();
|
||||||
//let mut path = String::new();
|
//let mut path = String::new();
|
||||||
//atom!(atom in args {
|
//atom!(atom in args {
|
||||||
|
|
|
||||||
|
|
@ -30,16 +30,16 @@ pub trait HasSampler {
|
||||||
}
|
}
|
||||||
/// The sampler device plays sounds in response to MIDI notes.
|
/// The sampler device plays sounds in response to MIDI notes.
|
||||||
#[derive(Debug)] pub struct Sampler {
|
#[derive(Debug)] pub struct Sampler {
|
||||||
pub jack: Arc<RwLock<JackConnection>>,
|
pub jack: JackClient,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub mapped: [Option<Arc<RwLock<Sample>>>;128],
|
pub mapped: [Option<Arc<RwLock<Sample>>>;128],
|
||||||
pub recording: Option<(usize, Arc<RwLock<Sample>>)>,
|
pub recording: Option<(usize, Arc<RwLock<Sample>>)>,
|
||||||
pub unmapped: Vec<Arc<RwLock<Sample>>>,
|
pub unmapped: Vec<Arc<RwLock<Sample>>>,
|
||||||
pub voices: Arc<RwLock<Vec<Voice>>>,
|
pub voices: Arc<RwLock<Vec<Voice>>>,
|
||||||
pub midi_in: Option<JackPort<MidiIn>>,
|
pub midi_in: Option<JackMidiIn>,
|
||||||
pub audio_ins: Vec<JackPort<AudioIn>>,
|
pub audio_ins: Vec<JackAudioIn>,
|
||||||
pub input_meter: Vec<f32>,
|
pub input_meter: Vec<f32>,
|
||||||
pub audio_outs: Vec<JackPort<AudioOut>>,
|
pub audio_outs: Vec<JackAudioOut>,
|
||||||
pub buffer: Vec<Vec<f32>>,
|
pub buffer: Vec<Vec<f32>>,
|
||||||
pub output_gain: f32
|
pub output_gain: f32
|
||||||
}
|
}
|
||||||
|
|
@ -89,7 +89,7 @@ impl Default for Sampler {
|
||||||
}
|
}
|
||||||
impl Sampler {
|
impl Sampler {
|
||||||
pub fn new (
|
pub fn new (
|
||||||
jack: &Arc<RwLock<JackConnection>>,
|
jack: &JackClient,
|
||||||
name: impl AsRef<str>,
|
name: impl AsRef<str>,
|
||||||
midi_from: &[PortConnection],
|
midi_from: &[PortConnection],
|
||||||
audio_from: &[&[PortConnection];2],
|
audio_from: &[&[PortConnection];2],
|
||||||
|
|
@ -97,14 +97,14 @@ impl Sampler {
|
||||||
) -> Usually<Self> {
|
) -> Usually<Self> {
|
||||||
let name = name.as_ref();
|
let name = name.as_ref();
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
midi_in: Some(JackPort::<MidiIn>::new(jack, format!("M/{name}"), midi_from)?),
|
midi_in: Some(JackMidiIn::new(jack, format!("M/{name}"), midi_from)?),
|
||||||
audio_ins: vec![
|
audio_ins: vec![
|
||||||
JackPort::<AudioIn>::new(jack, &format!("L/{name}"), audio_from[0])?,
|
JackAudioIn::new(jack, &format!("L/{name}"), audio_from[0])?,
|
||||||
JackPort::<AudioIn>::new(jack, &format!("R/{name}"), audio_from[1])?,
|
JackAudioIn::new(jack, &format!("R/{name}"), audio_from[1])?,
|
||||||
],
|
],
|
||||||
audio_outs: vec![
|
audio_outs: vec![
|
||||||
JackPort::<AudioOut>::new(jack, &format!("{name}/L"), audio_to[0])?,
|
JackAudioOut::new(jack, &format!("{name}/L"), audio_to[0])?,
|
||||||
JackPort::<AudioOut>::new(jack, &format!("{name}/R"), audio_to[1])?,
|
JackAudioOut::new(jack, &format!("{name}/R"), audio_to[1])?,
|
||||||
],
|
],
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
|
|
@ -349,7 +349,7 @@ impl Sampler {
|
||||||
}
|
}
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
type MidiSample = (Option<u7>, Arc<RwLock<crate::Sample>>);
|
type MidiSample = (Option<u7>, Arc<RwLock<crate::Sample>>);
|
||||||
//from_atom!("sampler" => |jack: &Arc<RwLock<JackConnection>>, args| -> crate::Sampler {
|
//from_atom!("sampler" => |jack: &JackClient, args| -> crate::Sampler {
|
||||||
//let mut name = String::new();
|
//let mut name = String::new();
|
||||||
//let mut dir = String::new();
|
//let mut dir = String::new();
|
||||||
//let mut samples = BTreeMap::new();
|
//let mut samples = BTreeMap::new();
|
||||||
|
|
@ -377,7 +377,7 @@ type MidiSample = (Option<u7>, Arc<RwLock<crate::Sample>>);
|
||||||
//});
|
//});
|
||||||
//Self::new(jack, &name)
|
//Self::new(jack, &name)
|
||||||
//});
|
//});
|
||||||
//from_atom!("sample" => |(_jack, dir): (&Arc<RwLock<JackConnection>>, &str), args| -> MidiSample {
|
//from_atom!("sample" => |(_jack, dir): (&JackClient, &str), args| -> MidiSample {
|
||||||
//let mut name = String::new();
|
//let mut name = String::new();
|
||||||
//let mut file = String::new();
|
//let mut file = String::new();
|
||||||
//let mut midi = None;
|
//let mut midi = None;
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ impl TekCli {
|
||||||
pub fn run (&self) -> Usually<()> {
|
pub fn run (&self) -> Usually<()> {
|
||||||
let name = self.name.as_ref().map_or("tek", |x|x.as_str());
|
let name = self.name.as_ref().map_or("tek", |x|x.as_str());
|
||||||
//let color = ItemPalette::random();
|
//let color = ItemPalette::random();
|
||||||
let jack = JackConnection::new(name)?;
|
let jack = JackClient::new(name)?;
|
||||||
let engine = Tui::new()?;
|
let engine = Tui::new()?;
|
||||||
let empty = &[] as &[&str];
|
let empty = &[] as &[&str];
|
||||||
let midi_froms = PortConnection::collect(&self.midi_from, &self.midi_from_re, empty);
|
let midi_froms = PortConnection::collect(&self.midi_from, &self.midi_from_re, empty);
|
||||||
|
|
@ -94,7 +94,7 @@ impl TekCli {
|
||||||
}
|
}
|
||||||
impl Tek {
|
impl Tek {
|
||||||
pub fn new_clock (
|
pub fn new_clock (
|
||||||
jack: &Arc<RwLock<JackConnection>>,
|
jack: &JackClient,
|
||||||
bpm: Option<f64>, sync_lead: bool, sync_follow: bool,
|
bpm: Option<f64>, sync_lead: bool, sync_follow: bool,
|
||||||
midi_froms: &[PortConnection], midi_tos: &[PortConnection],
|
midi_froms: &[PortConnection], midi_tos: &[PortConnection],
|
||||||
) -> Usually<Self> {
|
) -> Usually<Self> {
|
||||||
|
|
@ -103,8 +103,8 @@ impl Tek {
|
||||||
jack: jack.clone(),
|
jack: jack.clone(),
|
||||||
color: ItemPalette::random(),
|
color: ItemPalette::random(),
|
||||||
clock: Clock::new(jack, bpm),
|
clock: Clock::new(jack, bpm),
|
||||||
midi_ins: vec![JackPort::<MidiIn>::new(jack, "GlobalI", midi_froms)?],
|
midi_ins: vec![JackMidiIn::new(jack, "GlobalI", midi_froms)?],
|
||||||
midi_outs: vec![JackPort::<MidiOut>::new(jack, "GlobalO", midi_tos)?],
|
midi_outs: vec![JackMidiOut::new(jack, "GlobalO", midi_tos)?],
|
||||||
keys: SourceIter(KEYS_APP),
|
keys: SourceIter(KEYS_APP),
|
||||||
keys_clip: SourceIter(KEYS_CLIP),
|
keys_clip: SourceIter(KEYS_CLIP),
|
||||||
keys_track: SourceIter(KEYS_TRACK),
|
keys_track: SourceIter(KEYS_TRACK),
|
||||||
|
|
@ -112,12 +112,17 @@ impl Tek {
|
||||||
keys_mix: SourceIter(KEYS_MIX),
|
keys_mix: SourceIter(KEYS_MIX),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
tek.sync_lead(sync_lead);
|
jack.sync_lead(sync_lead, |mut state|{
|
||||||
tek.sync_follow(sync_follow);
|
let clock = tek.clock();
|
||||||
|
clock.playhead.update_from_sample(state.position.frame() as f64);
|
||||||
|
state.position.bbt = Some(clock.bbt());
|
||||||
|
state.position
|
||||||
|
});
|
||||||
|
jack.sync_follow(sync_follow);
|
||||||
Ok(tek)
|
Ok(tek)
|
||||||
}
|
}
|
||||||
pub fn new_sequencer (
|
pub fn new_sequencer (
|
||||||
jack: &Arc<RwLock<JackConnection>>,
|
jack: &JackClient,
|
||||||
bpm: Option<f64>, sync_lead: bool, sync_follow: bool,
|
bpm: Option<f64>, sync_lead: bool, sync_follow: bool,
|
||||||
midi_froms: &[PortConnection], midi_tos: &[PortConnection],
|
midi_froms: &[PortConnection], midi_tos: &[PortConnection],
|
||||||
) -> Usually<Self> {
|
) -> Usually<Self> {
|
||||||
|
|
@ -134,7 +139,7 @@ impl Tek {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
pub fn new_groovebox (
|
pub fn new_groovebox (
|
||||||
jack: &Arc<RwLock<JackConnection>>,
|
jack: &JackClient,
|
||||||
bpm: Option<f64>, sync_lead: bool, sync_follow: bool,
|
bpm: Option<f64>, sync_lead: bool, sync_follow: bool,
|
||||||
midi_froms: &[PortConnection], midi_tos: &[PortConnection],
|
midi_froms: &[PortConnection], midi_tos: &[PortConnection],
|
||||||
audio_froms: &[&[PortConnection];2], audio_tos: &[&[PortConnection];2],
|
audio_froms: &[&[PortConnection];2], audio_tos: &[&[PortConnection];2],
|
||||||
|
|
@ -150,7 +155,7 @@ impl Tek {
|
||||||
Ok(app)
|
Ok(app)
|
||||||
}
|
}
|
||||||
pub fn new_arranger (
|
pub fn new_arranger (
|
||||||
jack: &Arc<RwLock<JackConnection>>,
|
jack: &JackClient,
|
||||||
bpm: Option<f64>, sync_lead: bool, sync_follow: bool,
|
bpm: Option<f64>, sync_lead: bool, sync_follow: bool,
|
||||||
midi_froms: &[PortConnection], midi_tos: &[PortConnection],
|
midi_froms: &[PortConnection], midi_tos: &[PortConnection],
|
||||||
audio_froms: &[&[PortConnection];2], audio_tos: &[&[PortConnection];2],
|
audio_froms: &[&[PortConnection];2], audio_tos: &[&[PortConnection];2],
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::*;
|
use crate::*;
|
||||||
#[derive(Default, Debug)] pub struct Tek {
|
#[derive(Default, Debug)] pub struct Tek {
|
||||||
/// Must not be dropped for the duration of the process
|
/// Must not be dropped for the duration of the process
|
||||||
pub jack: Arc<RwLock<JackConnection>>,
|
pub jack: JackClient,
|
||||||
/// Source of time
|
/// Source of time
|
||||||
pub clock: Clock,
|
pub clock: Clock,
|
||||||
/// Theme
|
/// Theme
|
||||||
|
|
@ -11,10 +11,10 @@ use crate::*;
|
||||||
pub player: Option<MidiPlayer>,
|
pub player: Option<MidiPlayer>,
|
||||||
pub sampler: Option<Sampler>,
|
pub sampler: Option<Sampler>,
|
||||||
pub midi_buf: Vec<Vec<Vec<u8>>>,
|
pub midi_buf: Vec<Vec<Vec<u8>>>,
|
||||||
pub midi_ins: Vec<JackPort<MidiIn>>,
|
pub midi_ins: Vec<JackMidiIn>,
|
||||||
pub midi_outs: Vec<JackPort<MidiOut>>,
|
pub midi_outs: Vec<JackMidiOut>,
|
||||||
pub audio_ins: Vec<JackPort<AudioIn>>,
|
pub audio_ins: Vec<JackAudioIn>,
|
||||||
pub audio_outs: Vec<JackPort<AudioOut>>,
|
pub audio_outs: Vec<JackAudioOut>,
|
||||||
pub note_buf: Vec<u8>,
|
pub note_buf: Vec<u8>,
|
||||||
pub tracks: Vec<Track>,
|
pub tracks: Vec<Track>,
|
||||||
pub scenes: Vec<Scene>,
|
pub scenes: Vec<Scene>,
|
||||||
|
|
@ -118,10 +118,10 @@ impl Tek {
|
||||||
name,
|
name,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
track.player.midi_ins.push(JackPort::<MidiIn>::new(
|
track.player.midi_ins.push(JackMidiIn::new(
|
||||||
&self.jack, &format!("{}I", &track.name), midi_from
|
&self.jack, &format!("{}I", &track.name), midi_from
|
||||||
)?);
|
)?);
|
||||||
track.player.midi_outs.push(JackPort::<MidiOut>::new(
|
track.player.midi_outs.push(JackMidiOut::new(
|
||||||
&self.jack, &format!("{}O", &track.name), midi_to
|
&self.jack, &format!("{}O", &track.name), midi_to
|
||||||
)?);
|
)?);
|
||||||
self.tracks_mut().push(track);
|
self.tracks_mut().push(track);
|
||||||
|
|
@ -134,21 +134,6 @@ impl Tek {
|
||||||
}
|
}
|
||||||
Ok((index, &mut self.tracks_mut()[index]))
|
Ok((index, &mut self.tracks_mut()[index]))
|
||||||
}
|
}
|
||||||
pub fn sync_lead (&self, enable: bool) -> Usually<()> {
|
|
||||||
if enable {
|
|
||||||
self.jack.read().unwrap().client().register_timebase_callback(false, |mut state|{
|
|
||||||
let clock = self.clock();
|
|
||||||
clock.playhead.update_from_sample(state.position.frame() as f64);
|
|
||||||
state.position.bbt = Some(clock.bbt());
|
|
||||||
state.position
|
|
||||||
})?;
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
pub fn sync_follow (&self, enable: bool) -> Usually<()> {
|
|
||||||
// TODO: sync follow
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
fn clip (&self) -> Option<Arc<RwLock<MidiClip>>> {
|
fn clip (&self) -> Option<Arc<RwLock<MidiClip>>> {
|
||||||
self.scene()?.clips.get(self.selected().track()?)?.clone()
|
self.scene()?.clips.get(self.selected().track()?)?.clone()
|
||||||
}
|
}
|
||||||
|
|
@ -254,9 +239,9 @@ pub trait HasSelection {
|
||||||
/// Device chain
|
/// Device chain
|
||||||
pub devices: Vec<Box<dyn Device>>,
|
pub devices: Vec<Box<dyn Device>>,
|
||||||
/// Inputs of 1st device
|
/// Inputs of 1st device
|
||||||
pub audio_ins: Vec<JackPort<AudioIn>>,
|
pub audio_ins: Vec<JackAudioIn>,
|
||||||
/// Outputs of last device
|
/// Outputs of last device
|
||||||
pub audio_outs: Vec<JackPort<AudioOut>>,
|
pub audio_outs: Vec<JackAudioOut>,
|
||||||
}
|
}
|
||||||
has_clock!(|self: Track|self.player.clock);
|
has_clock!(|self: Track|self.player.clock);
|
||||||
has_player!(|self: Track|self.player);
|
has_player!(|self: Track|self.player);
|
||||||
|
|
@ -266,14 +251,14 @@ impl Track {
|
||||||
fn width_dec (&mut self) { if self.width > Track::MIN_WIDTH { self.width -= 1; } }
|
fn width_dec (&mut self) { if self.width > Track::MIN_WIDTH { self.width -= 1; } }
|
||||||
}
|
}
|
||||||
impl HasTracks for Tek {
|
impl HasTracks for Tek {
|
||||||
fn midi_ins (&self) -> &Vec<JackPort<MidiIn>> { &self.midi_ins }
|
fn midi_ins (&self) -> &Vec<JackMidiIn> { &self.midi_ins }
|
||||||
fn midi_outs (&self) -> &Vec<JackPort<MidiOut>> { &self.midi_outs }
|
fn midi_outs (&self) -> &Vec<JackMidiOut> { &self.midi_outs }
|
||||||
fn tracks (&self) -> &Vec<Track> { &self.tracks }
|
fn tracks (&self) -> &Vec<Track> { &self.tracks }
|
||||||
fn tracks_mut (&mut self) -> &mut Vec<Track> { &mut self.tracks }
|
fn tracks_mut (&mut self) -> &mut Vec<Track> { &mut self.tracks }
|
||||||
}
|
}
|
||||||
pub trait HasTracks: HasSelection + HasClock + HasJack + HasEditor + Send + Sync {
|
pub trait HasTracks: HasSelection + HasClock + HasJack + HasEditor + Send + Sync {
|
||||||
fn midi_ins (&self) -> &Vec<JackPort<MidiIn>>;
|
fn midi_ins (&self) -> &Vec<JackMidiIn>;
|
||||||
fn midi_outs (&self) -> &Vec<JackPort<MidiOut>>;
|
fn midi_outs (&self) -> &Vec<JackMidiOut>;
|
||||||
fn tracks (&self) -> &Vec<Track>;
|
fn tracks (&self) -> &Vec<Track>;
|
||||||
fn tracks_mut (&mut self) -> &mut Vec<Track>;
|
fn tracks_mut (&mut self) -> &mut Vec<Track>;
|
||||||
fn track_longest (&self) -> usize {
|
fn track_longest (&self) -> usize {
|
||||||
|
|
|
||||||
211
tek/src/view.rs
211
tek/src/view.rs
|
|
@ -30,6 +30,8 @@ impl<T: PartialEq, U> ViewMemo<T, U> {
|
||||||
scns: ViewMemo<Option<(usize, usize)>, String>,
|
scns: ViewMemo<Option<(usize, usize)>, String>,
|
||||||
trks: ViewMemo<Option<(usize, usize)>, String>,
|
trks: ViewMemo<Option<(usize, usize)>, String>,
|
||||||
stop: Arc<str>,
|
stop: Arc<str>,
|
||||||
|
edit: Arc<str>,
|
||||||
|
last_color: Arc<RwLock<ItemPalette>>
|
||||||
}
|
}
|
||||||
impl Default for ViewCache {
|
impl Default for ViewCache {
|
||||||
fn default () -> Self {
|
fn default () -> Self {
|
||||||
|
|
@ -43,6 +45,8 @@ impl Default for ViewCache {
|
||||||
scns: ViewMemo::new(None, String::with_capacity(16)),
|
scns: ViewMemo::new(None, String::with_capacity(16)),
|
||||||
trks: ViewMemo::new(None, String::with_capacity(16)),
|
trks: ViewMemo::new(None, String::with_capacity(16)),
|
||||||
stop: "⏹".into(),
|
stop: "⏹".into(),
|
||||||
|
edit: "edit".into(),
|
||||||
|
last_color: Arc::new(RwLock::new(ItemPalette::G[0]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -65,17 +69,16 @@ provide_num!(u16: |self: Tek| {
|
||||||
":sample-h" => if self.is_editing() { 0 } else { 5 },
|
":sample-h" => if self.is_editing() { 0 } else { 5 },
|
||||||
":samples-w" => if self.is_editing() { 4 } else { 11 },
|
":samples-w" => if self.is_editing() { 4 } else { 11 },
|
||||||
":samples-y" => if self.is_editing() { 1 } else { 0 },
|
":samples-y" => if self.is_editing() { 1 } else { 0 },
|
||||||
":pool-w" => if self.is_editing() { 5 } else {
|
});
|
||||||
let w = self.size.w();
|
|
||||||
if w > 60 { 20 } else if w > 40 { 15 } else { 10 } } });
|
|
||||||
macro_rules! per_track {
|
macro_rules! per_track {
|
||||||
(|$self:ident,$track:ident,$index:ident|$content:expr) => {{
|
($area:expr;|$self:ident,$track:ident,$index:ident|$content:expr) => {{
|
||||||
let tracks = ||$self.tracks_sizes($self.is_editing(), $self.editor_w());
|
let tracks = ||$self.tracks_sizes($self.is_editing(), $self.editor_w());
|
||||||
Box::new(move||Align::x(Map::new(tracks, move|(_, $track, x1, x2), $index| {
|
Box::new(move||Align::x(Map::new(tracks, move|(_, $track, x1, x2), $index| {
|
||||||
let width = (x2 - x1) as u16;
|
let width = (x2 - x1) as u16;
|
||||||
let content = Fixed::y(1, $content);
|
let content = Fixed::y(1, $content);
|
||||||
let styled = Tui::fg_bg($track.color.lightest.rgb, $track.color.base.rgb, content);
|
let styled = Tui::fg_bg($track.color.lightest.rgb, $track.color.base.rgb, content);
|
||||||
map_east(x1 as u16, width, Fixed::x(width, styled)) }))).into() }} }
|
Either(x2 >= $area, (),
|
||||||
|
map_east(x1 as u16, width, Fixed::x(width, styled))) }))).into() }} }
|
||||||
macro_rules! io_header {
|
macro_rules! io_header {
|
||||||
($self:ident, $key:expr, $label:expr, $count:expr, $content:expr) => {
|
($self:ident, $key:expr, $label:expr, $count:expr, $content:expr) => {
|
||||||
(move||{
|
(move||{
|
||||||
|
|
@ -204,13 +207,13 @@ impl Tek {
|
||||||
" midi ins",
|
" midi ins",
|
||||||
self.midi_ins.len(),
|
self.midi_ins.len(),
|
||||||
self.midi_ins().get(0).map(
|
self.midi_ins().get(0).map(
|
||||||
move|input: &JackPort<MidiIn>|Bsp::s(
|
move|input: &JackMidiIn|Bsp::s(
|
||||||
Fill::x(Tui::bold(true, Tui::fg_bg(fg, bg, Align::w(input.name.clone())))),
|
Fill::x(Tui::bold(true, Tui::fg_bg(fg, bg, Align::w(input.name.clone())))),
|
||||||
input.connect.get(0).map(|connect|Fill::x(Align::w(Tui::bold(false,
|
input.conn().get(0).map(|connect|Fill::x(Align::w(Tui::bold(false,
|
||||||
Tui::fg_bg(fg, bg, connect.info()))))))));
|
Tui::fg_bg(fg, bg, connect.info()))))))));
|
||||||
let rec = false;
|
let rec = false;
|
||||||
let mon = false;
|
let mon = false;
|
||||||
let cells: ThunkBox<_> = per_track!(|self, track, _t|Bsp::s(Tui::bold(true, row!(
|
let cells: ThunkBox<_> = per_track!(self.size.w();|self, track, _t|Bsp::s(Tui::bold(true, row!(
|
||||||
Tui::fg_bg(if rec { White } else { track.color.light.rgb }, track.color.dark.rgb, "Rcrd"),
|
Tui::fg_bg(if rec { White } else { track.color.light.rgb }, track.color.dark.rgb, "Rcrd"),
|
||||||
Tui::fg_bg(if rec { White } else { track.color.dark.rgb }, track.color.dark.rgb, "▐"),
|
Tui::fg_bg(if rec { White } else { track.color.dark.rgb }, track.color.dark.rgb, "▐"),
|
||||||
Tui::fg_bg(if mon { White } else { track.color.light.rgb }, track.color.dark.rgb, "Mntr"),
|
Tui::fg_bg(if mon { White } else { track.color.light.rgb }, track.color.dark.rgb, "Mntr"),
|
||||||
|
|
@ -226,13 +229,13 @@ impl Tek {
|
||||||
let bg = Tui::g(64);
|
let bg = Tui::g(64);
|
||||||
let h = 1 + self.midi_outs.len() as u16;
|
let h = 1 + self.midi_outs.len() as u16;
|
||||||
let header: ThunkBox<_> = io_header!(self, " O ", " midi outs", self.midi_outs.len(), self.midi_outs().get(0).map(
|
let header: ThunkBox<_> = io_header!(self, " O ", " midi outs", self.midi_outs.len(), self.midi_outs().get(0).map(
|
||||||
move|output: &JackPort<MidiOut>|Bsp::s(
|
move|output: &JackMidiOut|Bsp::s(
|
||||||
Fill::x(Tui::bold(true, Tui::fg_bg(fg, bg, Align::w(output.name.clone())))),
|
Fill::x(Tui::bold(true, Tui::fg_bg(fg, bg, Align::w(output.name.clone())))),
|
||||||
output.connect.get(0).map(|connect|Fill::x(Align::w(Tui::bold(false,
|
output.conn().get(0).map(|connect|Fill::x(Align::w(Tui::bold(false,
|
||||||
Tui::fg_bg(fg, bg, connect.info()))))))));
|
Tui::fg_bg(fg, bg, connect.info()))))))));
|
||||||
let mute = false;
|
let mute = false;
|
||||||
let solo = false;
|
let solo = false;
|
||||||
let cells: ThunkBox<_> = per_track!(|self, track, _t|Bsp::s(Tui::bold(true, row!(
|
let cells: ThunkBox<_> = per_track!(self.size.w();|self, track, _t|Bsp::s(Tui::bold(true, row!(
|
||||||
Tui::fg_bg(if mute { White } else { track.color.light.rgb }, track.color.dark.rgb, "Mute"),
|
Tui::fg_bg(if mute { White } else { track.color.light.rgb }, track.color.dark.rgb, "Mute"),
|
||||||
Tui::fg_bg(if mute { White } else { track.color.dark.rgb }, track.color.dark.rgb, "▐"),
|
Tui::fg_bg(if mute { White } else { track.color.dark.rgb }, track.color.dark.rgb, "▐"),
|
||||||
Tui::fg_bg(if solo { White } else { track.color.light.rgb }, track.color.dark.rgb, "Solo"),
|
Tui::fg_bg(if solo { White } else { track.color.light.rgb }, track.color.dark.rgb, "Solo"),
|
||||||
|
|
@ -247,7 +250,7 @@ impl Tek {
|
||||||
let h = 1;
|
let h = 1;
|
||||||
let header: ThunkBox<_> =
|
let header: ThunkBox<_> =
|
||||||
(move||Tui::bg(Tui::g(32), Fill::x(Align::w(self.view_track_add()))).boxed()).into();
|
(move||Tui::bg(Tui::g(32), Fill::x(Align::w(self.view_track_add()))).boxed()).into();
|
||||||
let cells: ThunkBox<_> = per_track!(|self, track, t|{
|
let cells: ThunkBox<_> = per_track!(self.size.w();|self, track, t|{
|
||||||
let active = self.selected().track() == Some(t+1);
|
let active = self.selected().track() == Some(t+1);
|
||||||
let name = &track.name;
|
let name = &track.name;
|
||||||
let fg = track.color.lightest.rgb;
|
let fg = track.color.lightest.rgb;
|
||||||
|
|
@ -277,110 +280,101 @@ impl Tek {
|
||||||
self.fmtd.read().unwrap().scns.view.clone()))
|
self.fmtd.read().unwrap().scns.view.clone()))
|
||||||
}
|
}
|
||||||
fn view_scenes (&self) -> impl Content<TuiOut> + use<'_> {
|
fn view_scenes (&self) -> impl Content<TuiOut> + use<'_> {
|
||||||
let header: ThunkBox<_> = (move||{
|
let bstyle = Style::default().fg(Tui::g(0));
|
||||||
|
let size_w = self.size.w();
|
||||||
|
let size_h = self.size.h();
|
||||||
|
let editing = self.is_editing();
|
||||||
|
let tracks = move||self.tracks_sizes(editing, self.editor_w());
|
||||||
|
let scenes = move||self.scenes_sizes(editing, 2, 15);
|
||||||
|
let selected_track = self.selected().track();
|
||||||
|
let selected_scene = self.selected().scene();
|
||||||
|
let border = move|h, cell|Push::y(1, Fixed::y(h, Outer(false, bstyle).enclose(cell)));
|
||||||
|
let header = move||{
|
||||||
let last_color = Arc::new(RwLock::new(ItemPalette::G[0]));
|
let last_color = Arc::new(RwLock::new(ItemPalette::G[0]));
|
||||||
let iter = ||self.scenes_sizes(self.is_editing(), 2, 15);
|
let iter = ||self.scenes_sizes(self.is_editing(), 2, 15);
|
||||||
Map::new(iter, move|(_, scene, y1, y2), i| {
|
let cell = {
|
||||||
let cell = phat_sel_3(
|
let last_color = last_color.clone();
|
||||||
|
move|i, color: &ItemPalette, name: Arc<str>|phat_sel_3(
|
||||||
self.selected().scene() == Some(i),
|
self.selected().scene() == Some(i),
|
||||||
Tui::bold(true, Bsp::e("🭬", &scene.name)),
|
Tui::bold(true, Bsp::e("🭬", name.clone())),
|
||||||
Tui::bold(true, Bsp::e("🭬", &scene.name)),
|
Tui::bold(true, Bsp::e("🭬", name)),
|
||||||
if i == 0 { Some(Reset) }
|
if i == 0 { Some(Reset) }
|
||||||
else if self.selected().scene() == Some(i) { None }
|
else if self.selected().scene() == Some(i) { None }
|
||||||
else { Some(last_color.read().unwrap().base.rgb) },
|
else { Some(last_color.read().unwrap().base.rgb) },
|
||||||
if self.selected().scene() == Some(i+1) { scene.color.light } else { scene.color.base }.rgb,
|
if self.selected().scene() == Some(i+1) { color.light } else { color.base }.rgb,
|
||||||
Some(Reset)
|
Some(Reset)
|
||||||
);
|
)
|
||||||
let h = (1 + y2 - y1) as u16;
|
};
|
||||||
|
Map::new(iter, move|(_, scene, y1, y2), s| {
|
||||||
|
let cell = cell(s, &scene.color, scene.name.clone());
|
||||||
|
let height = (1 + y2 - y1) as u16;
|
||||||
*last_color.write().unwrap() = scene.color;
|
*last_color.write().unwrap() = scene.color;
|
||||||
map_south(y1 as u16, h, Push::y(1, Fixed::y(h,
|
map_south(y1 as u16, height, border(height, cell))
|
||||||
Outer(false, Style::default().fg(Tui::g(0))).enclose(cell))))
|
|
||||||
}).boxed()
|
}).boxed()
|
||||||
}).into();
|
};
|
||||||
let editing = self.is_editing();
|
let border = move|x|Outer(false, bstyle).enclose_bg(x);
|
||||||
let tracks = move||self.tracks_sizes(editing, self.editor_w());
|
let content: ThunkBox<_> = per_track!(size_w; |self, track, t|{
|
||||||
let scenes = move||self.scenes_sizes(editing, 2, 15);
|
let last_color = self.fmtd.read().unwrap().last_color.clone();
|
||||||
let selected_track = self.selected().track();
|
let same_track = selected_track == Some(t+1);
|
||||||
let selected_scene = self.selected().scene();
|
border(Map::new(scenes, move|(_, scene, y1, y2), s|{
|
||||||
let border = |x|Outer(false, Style::default().fg(Tui::g(0))).enclose(x);
|
|
||||||
let d = 6 + self.midi_ins.len() + self.midi_outs.len();
|
|
||||||
let cells: ThunkBox<_> = (move||Align::c(Map::new(tracks, {
|
|
||||||
let last_color = Arc::new(RwLock::new(ItemPalette::default()));
|
|
||||||
let area = self.size.w().saturating_sub(self.w_sidebar() as usize * 2);
|
|
||||||
move|(_, track, x1, x2), t| {
|
|
||||||
let last_color = last_color.clone();
|
let last_color = last_color.clone();
|
||||||
let same_track = selected_track == Some(t+1);
|
Thunk::new(move||{
|
||||||
let w = (x2 - x1) as u16;
|
|
||||||
map_east(x1 as u16, w, border(Map::new(scenes, move|(_, scene, y1, y2), s|{
|
|
||||||
let last_color = last_color.clone();
|
let last_color = last_color.clone();
|
||||||
Either(x2 >= area, (), Thunk::new(move||{
|
let mut fg = Tui::g(64);
|
||||||
let last_color = last_color.clone();
|
let mut bg = ItemPalette::G[32];
|
||||||
let mut fg = Tui::g(64);
|
if let Some(clip) = &scene.clips[t] {
|
||||||
let mut bg = ItemPalette::G[32];
|
let clip = clip.read().unwrap();
|
||||||
if let Some(clip) = &scene.clips[t] {
|
fg = clip.color.lightest.rgb;
|
||||||
let clip = clip.read().unwrap();
|
bg = clip.color
|
||||||
fg = clip.color.lightest.rgb;
|
};
|
||||||
bg = clip.color
|
// weird offsetting:
|
||||||
};
|
let selected = same_track && selected_scene == Some(s+1);
|
||||||
|
let neighbor = same_track && selected_scene == Some(s);
|
||||||
// weird offsetting:
|
let active = editing && selected;
|
||||||
let selected = same_track && selected_scene == Some(s+1);
|
let top = if s == 0 {
|
||||||
let neighbor = same_track && selected_scene == Some(s);
|
Some(Reset)
|
||||||
let active = editing && selected;
|
} else if neighbor {
|
||||||
|
Some(last_color.read().unwrap().light.rgb)
|
||||||
//let top = if neighbor { None } else { Some(last_color.read().unwrap().base.rgb) };
|
} else {
|
||||||
let top = if s == 0 {
|
Some(last_color.read().unwrap().base.rgb)
|
||||||
Some(Reset)
|
};
|
||||||
} else if neighbor {
|
let mid = if selected { bg.light } else { bg.base }.rgb;
|
||||||
Some(last_color.read().unwrap().light.rgb)
|
let low = Some(Reset);
|
||||||
} else {
|
let h = (1 + y2 - y1) as u16;
|
||||||
Some(last_color.read().unwrap().base.rgb)
|
*last_color.write().unwrap() = bg;
|
||||||
};
|
let tab = " Tab ";
|
||||||
let mid = if selected { bg.light } else { bg.base }.rgb;
|
let name = if active {
|
||||||
let low = Some(Reset);
|
self.editor.as_ref()
|
||||||
let h = (1 + y2 - y1) as u16;
|
.map(|e|e.clip().as_ref().map(|c|c.clone()))
|
||||||
*last_color.write().unwrap() = bg;
|
.flatten()
|
||||||
let tab = " Tab ";
|
.map(|c|c.read().unwrap().name.clone())
|
||||||
let name = if active {
|
.unwrap_or_else(||"".into())
|
||||||
self.editor.as_ref()
|
} else {
|
||||||
.map(|e|e.clip().as_ref().map(|c|c.clone()))
|
self.fmtd.read().unwrap().edit.clone()
|
||||||
.flatten()
|
};
|
||||||
.map(|c|c.read().unwrap().name.clone())
|
let label = move||{
|
||||||
.unwrap_or_else(||"".into())
|
let clip = scene.clips[t].clone();
|
||||||
} else {
|
let icon = " ⏹ ";
|
||||||
"edit".into()
|
let name = clip.map(|c|c.read().unwrap().name.clone());
|
||||||
};
|
Align::nw(Tui::fg(fg, Bsp::e(icon, Bsp::e(Tui::bold(true, name), " "))))};
|
||||||
let label = move||{
|
let editor = Thunk::new(move||Bsp::a(
|
||||||
let clip = scene.clips[t].clone();
|
Fill::xy(Align::nw(button(tab, label()))),
|
||||||
let icon = " ⏹ ";
|
&self.editor));
|
||||||
let name = clip.map(|c|c.read().unwrap().name.clone());
|
let cell = Thunk::new(move||Bsp::a(
|
||||||
Align::nw(Tui::fg(fg, Bsp::e(icon, Bsp::e(Tui::bold(true, name), " "))))
|
When::new(selected, Fill::y(Align::n(button(tab, "edit")))),
|
||||||
};
|
phat_sel_3(selected, Fill::xy(label()), Fill::xy(label()), top, mid, low)));
|
||||||
let area = self.size.h().saturating_sub(d);//self.w_sidebar() as usize * 2);
|
let cell = Either::new(active, editor, cell);
|
||||||
Either(y2 > area, (), map_south(y1 as u16, h, Push::y(1, Fixed::y(h, Either::new(active,
|
Either(y2 > size_h, (), map_south(y1 as u16, h, Push::y(1, Fixed::y(h, cell))))
|
||||||
Thunk::new(move||Bsp::a(
|
})
|
||||||
Fill::xy(Align::nw(button(tab, label()))),
|
}))
|
||||||
&self.editor)),
|
});
|
||||||
Thunk::new(move||Bsp::a(
|
let border = move|x|Outer(false, bstyle).enclose_bg(x);
|
||||||
When::new(selected, Fill::y(Align::n(button(tab, "edit")))),
|
border(self.view_row(
|
||||||
phat_sel_3(
|
size_w as u16,
|
||||||
selected,
|
size_h as u16,
|
||||||
Fill::xy(label()),
|
<_ as Into<ThunkBox<_>>>::into(header),
|
||||||
Fill::xy(label()),
|
<_ as Into<ThunkBox<_>>>::into(content),
|
||||||
top, mid, low
|
))
|
||||||
)
|
|
||||||
)),
|
|
||||||
)))))
|
|
||||||
|
|
||||||
}))
|
|
||||||
}))).boxed()
|
|
||||||
}
|
|
||||||
})).boxed()).into();
|
|
||||||
Outer(false, Style::default().fg(Tui::g(0))).enclose_bg({
|
|
||||||
let w = self.w();
|
|
||||||
let d = 6 + self.midi_ins.len() + self.midi_outs.len();
|
|
||||||
let h = self.size.h().saturating_sub(d) as u16;
|
|
||||||
self.view_row(w, h, header, cells)})
|
|
||||||
}
|
}
|
||||||
fn w (&self) -> u16 {
|
fn w (&self) -> u16 {
|
||||||
self.tracks_sizes(self.is_editing(), self.editor_w())
|
self.tracks_sizes(self.is_editing(), self.editor_w())
|
||||||
|
|
@ -390,8 +384,9 @@ impl Tek {
|
||||||
}
|
}
|
||||||
fn w_sidebar (&self) -> u16 {
|
fn w_sidebar (&self) -> u16 {
|
||||||
let w = self.size.w();
|
let w = self.size.w();
|
||||||
let w = if w > 60 { 20 } else if w > 40 { 15 } else { 10 };
|
let w = if w > 80 { 20 } else if w > 70 { 18 } else if w > 60 { 16 }
|
||||||
let w = if self.is_editing() { 8 } else { w };
|
else if w > 50 { 14 } else if w > 40 { 12 } else { 10 };
|
||||||
|
let w = if self.is_editing() { w / 2 } else { w };
|
||||||
w
|
w
|
||||||
}
|
}
|
||||||
fn button <'a> (
|
fn button <'a> (
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
(bsp/a (fill/xy (align/n (max/y 1 :toolbar)))
|
(bsp/a (fill/xy (align/n (max/y 1 :toolbar)))
|
||||||
(fill/x (align/c (bsp/a (fill/xy (align/e (fixed/x :pool-w :pool)))
|
(fill/x (align/c (bsp/a (fill/xy (align/e (fixed/x :sidebar-w :pool)))
|
||||||
(bsp/a
|
(bsp/a
|
||||||
(fill/xy (align/s (bsp/s :scene-add (bsp/s :tracks (bsp/n :inputs :outputs)))))
|
(fill/xy (align/s (bsp/s :scene-add (bsp/s :tracks (bsp/n :inputs :outputs)))))
|
||||||
(fill/xy :scenes))))))
|
(fill/xy :scenes))))))
|
||||||
|
|
|
||||||
|
|
@ -81,11 +81,10 @@ pub struct Clock {
|
||||||
/// Size of buffer in samples
|
/// Size of buffer in samples
|
||||||
pub chunk: Arc<AtomicUsize>,
|
pub chunk: Arc<AtomicUsize>,
|
||||||
}
|
}
|
||||||
impl From<&Arc<RwLock<JackConnection>>> for Clock {
|
impl From<&JackClient> for Clock {
|
||||||
fn from (jack: &Arc<RwLock<JackConnection>>) -> Self {
|
fn from (jack: &JackClient) -> Self {
|
||||||
let jack = jack.read().unwrap();
|
let chunk = jack.inner().buffer_size();
|
||||||
let chunk = jack.client().buffer_size();
|
let transport = jack.inner().transport();
|
||||||
let transport = jack.client().transport();
|
|
||||||
let timebase = Arc::new(Timebase::default());
|
let timebase = Arc::new(Timebase::default());
|
||||||
Self {
|
Self {
|
||||||
quant: Arc::new(24.into()),
|
quant: Arc::new(24.into()),
|
||||||
|
|
@ -114,7 +113,7 @@ impl std::fmt::Debug for Clock {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Clock {
|
impl Clock {
|
||||||
pub fn new (jack: &Arc<RwLock<JackConnection>>, bpm: Option<f64>) -> Self {
|
pub fn new (jack: &JackClient, bpm: Option<f64>) -> Self {
|
||||||
let clock = Self::from(jack);
|
let clock = Self::from(jack);
|
||||||
if let Some(bpm) = bpm {
|
if let Some(bpm) = bpm {
|
||||||
clock.timebase.bpm.set(bpm);
|
clock.timebase.bpm.set(bpm);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue