JackClient -> JackConnection

This commit is contained in:
🪞👃🪞 2024-12-29 15:32:39 +01:00
parent c3f9aa7549
commit 411d4bc91d
23 changed files with 55 additions and 51 deletions

View file

@ -10,7 +10,7 @@ mod arranger_h;
/// Root view for standalone `tek_arranger`
pub struct ArrangerTui {
jack: Arc<RwLock<JackClient>>,
jack: Arc<RwLock<JackConnection>>,
pub clock: ClockModel,
pub phrases: PoolModel,
pub tracks: Vec<ArrangerTrack>,

View file

@ -33,7 +33,7 @@ pub trait FromEdn<C>: Sized {
}
}
from_edn!("sampler" => |jack: &Arc<RwLock<JackClient>>, args| -> crate::Sampler {
from_edn!("sampler" => |jack: &Arc<RwLock<JackConnection>>, args| -> crate::Sampler {
let mut name = String::new();
let mut dir = String::new();
let mut samples = BTreeMap::new();
@ -64,7 +64,7 @@ from_edn!("sampler" => |jack: &Arc<RwLock<JackClient>>, args| -> crate::Sampler
type MidiSample = (Option<u7>, Arc<RwLock<crate::Sample>>);
from_edn!("sample" => |(_jack, dir): (&Arc<RwLock<JackClient>>, &str), args| -> MidiSample {
from_edn!("sample" => |(_jack, dir): (&Arc<RwLock<JackConnection>>, &str), args| -> MidiSample {
let mut name = String::new();
let mut file = String::new();
let mut midi = None;
@ -97,7 +97,7 @@ from_edn!("sample" => |(_jack, dir): (&Arc<RwLock<JackClient>>, &str), args| ->
}))))
});
from_edn!("plugin/lv2" => |jack: &Arc<RwLock<JackClient>>, args| -> Plugin {
from_edn!("plugin/lv2" => |jack: &Arc<RwLock<JackConnection>>, args| -> Plugin {
let mut name = String::new();
let mut path = String::new();
edn!(edn in args {
@ -119,7 +119,7 @@ const SYM_GAIN: &str = ":gain";
const SYM_SAMPLER: &str = "sampler";
const SYM_LV2: &str = "lv2";
from_edn!("mixer/track" => |jack: &Arc<RwLock<JackClient>>, args| -> MixerTrack {
from_edn!("mixer/track" => |jack: &Arc<RwLock<JackConnection>>, args| -> MixerTrack {
let mut _gain = 0.0f64;
let mut track = MixerTrack {
name: String::new(),

View file

@ -7,7 +7,7 @@ use PhraseCommand::*;
use PhrasePoolCommand::*;
pub struct GrooveboxTui {
_jack: Arc<RwLock<JackClient>>,
_jack: Arc<RwLock<JackConnection>>,
pub player: MidiPlayer,
pub pool: PoolModel,

View file

@ -15,7 +15,7 @@ pub use self::activate::JackActivate;
pub mod client;
pub(crate) use self::client::*;
pub use self::client::JackClient;
pub use self::client::JackConnection;
pub mod jack_event;
pub(crate) use self::jack_event::*;
@ -24,12 +24,12 @@ pub mod ports;
pub(crate) use self::ports::*;
pub use self::ports::RegisterPort;
/// Implement [TryFrom<&Arc<RwLock<JackClient>>>]: create app state from wrapped JACK handle.
/// 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<JackClient>>> for $Struct $(<$($L),*$($T),*>)? {
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<JackClient>>) -> Usually<Self> {
fn try_from ($jack: &Arc<RwLock<JackConnection>>) -> Usually<Self> {
Ok($cb)
}
}

View file

@ -3,15 +3,15 @@ use crate::*;
pub trait JackActivate: Sized {
fn activate_with <T: Audio + 'static> (
self,
init: impl FnOnce(&Arc<RwLock<JackClient>>)->Usually<T>
init: impl FnOnce(&Arc<RwLock<JackConnection>>)->Usually<T>
)
-> Usually<Arc<RwLock<T>>>;
}
impl JackActivate for JackClient {
impl JackActivate for JackConnection {
fn activate_with <T: Audio + 'static> (
self,
init: impl FnOnce(&Arc<RwLock<JackClient>>)->Usually<T>
init: impl FnOnce(&Arc<RwLock<JackConnection>>)->Usually<T>
)
-> Usually<Arc<RwLock<T>>>
{

View file

@ -4,7 +4,7 @@ pub type DynamicAudioHandler = ClosureProcessHandler<(), BoxedAudioHandler>;
pub type BoxedAudioHandler = Box<dyn FnMut(&Client, &ProcessScope) -> Control + Send>;
/// Wraps [Client] or [DynamicAsyncClient] in place.
#[derive(Debug)]
pub enum JackClient {
pub enum JackConnection {
/// Before activation.
Inactive(Client),
/// During activation.
@ -12,18 +12,19 @@ pub enum JackClient {
/// After activation. Must not be dropped for JACK thread to persist.
Active(DynamicAsyncClient),
}
from!(|jack: JackClient|Client = match jack {
JackClient::Inactive(client) => client,
JackClient::Activating => panic!("jack client still activating"),
JackClient::Active(_) => panic!("jack client already activated"),
from!(|jack: JackConnection|Client = match jack {
JackConnection::Inactive(client) => client,
JackConnection::Activating => panic!("jack client still activating"),
JackConnection::Active(_) => panic!("jack client already activated"),
});
impl JackClient {
impl JackConnection {
pub fn new (name: &str) -> Usually<Self> {
let (client, _) = Client::new(name, ClientOptions::NO_START_SERVER)?;
Ok(Self::Inactive(client))
}
}
impl AudioEngine for JackClient {
impl AudioEngine for JackConnection {
/// Return the internal [Client] handle that lets you call the JACK API.
fn client(&self) -> &Client {
match self {
Self::Inactive(ref client) => client,
@ -31,6 +32,10 @@ impl AudioEngine for JackClient {
Self::Active(ref client) => client.as_client(),
}
}
/// Bind a process callback to a `JackConnection::Inactive`,
/// turning it into 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,

View file

@ -11,7 +11,7 @@ pub trait RegisterPort {
fn connect_audio_to (&self, my_output: &Port<AudioOut>, ports: &[String]) -> Usually<()>;
}
impl RegisterPort for Arc<RwLock<JackClient>> {
impl RegisterPort for Arc<RwLock<JackConnection>> {
fn midi_in (&self, name: &str) -> Usually<Port<MidiIn>> {
Ok(self.read().unwrap().client().register_port(name, MidiIn::default())?)
}

View file

@ -127,7 +127,7 @@ pub struct MidiPlayer {
pub note_buf: Vec<u8>,
}
impl MidiPlayer {
pub fn new (jack: &Arc<RwLock<JackClient>>, name: &str) -> Usually<Self> {
pub fn new (jack: &Arc<RwLock<JackConnection>>, name: &str) -> Usually<Self> {
Ok(Self {
clock: ClockModel::from(jack),
play_phrase: None,
@ -324,7 +324,7 @@ impl HasPlayPhrase for MidiPlayer {
///// Methods used primarily by the process callback
//impl MIDIPlayer {
//pub fn new (
//jack: &Arc<RwLock<JackClient>>,
//jack: &Arc<RwLock<JackConnection>>,
//clock: &Arc<Clock>,
//name: &str
//) -> Usually<Self> {

View file

@ -3,7 +3,7 @@ use crate::*;
#[derive(Debug)]
pub struct Mixer {
/// JACK client handle (needs to not be dropped for standalone mode to work).
pub jack: Arc<RwLock<JackClient>>,
pub jack: Arc<RwLock<JackConnection>>,
pub name: String,
pub tracks: Vec<MixerTrack>,
pub selected_track: usize,
@ -25,7 +25,7 @@ pub struct MixerTrack {
audio!(|self: Mixer, _client, _scope|Control::Continue);
impl Mixer {
pub fn new (jack: &Arc<RwLock<JackClient>>, name: &str) -> Usually<Self> {
pub fn new (jack: &Arc<RwLock<JackConnection>>, name: &str) -> Usually<Self> {
Ok(Self {
jack: jack.clone(),
name: name.into(),

View file

@ -7,7 +7,7 @@ pub use self::lv2::LV2Plugin;
#[derive(Debug)]
pub struct Plugin {
/// JACK client handle (needs to not be dropped for standalone mode to work).
pub jack: Arc<RwLock<JackClient>>,
pub jack: Arc<RwLock<JackConnection>>,
pub name: String,
pub path: Option<String>,
pub plugin: Option<PluginKind>,
@ -40,7 +40,7 @@ impl Debug for PluginKind {
}
impl Plugin {
pub fn new_lv2 (
jack: &Arc<RwLock<JackClient>>,
jack: &Arc<RwLock<JackConnection>>,
name: &str,
path: &str,
) -> Usually<Self> {
@ -131,7 +131,7 @@ audio!(|self: PluginAudio, client, scope|{
impl Plugin {
/// Create a plugin host device.
pub fn new (
jack: &Arc<RwLock<JackClient>>,
jack: &Arc<RwLock<JackConnection>>,
name: &str,
) -> Usually<Self> {
Ok(Self {

View file

@ -35,7 +35,7 @@ pub use self::sample_viewer::SampleViewer;
/// The sampler plugin plays sounds.
#[derive(Debug)]
pub struct Sampler {
pub jack: Arc<RwLock<JackClient>>,
pub jack: Arc<RwLock<JackConnection>>,
pub name: String,
pub mapped: [Option<Arc<RwLock<Sample>>>;128],
pub recording: Option<(usize, Arc<RwLock<Sample>>)>,
@ -49,7 +49,7 @@ pub struct Sampler {
pub output_gain: f32
}
impl Sampler {
pub fn new (jack: &Arc<RwLock<JackClient>>, name: &str) -> Usually<Self> {
pub fn new (jack: &Arc<RwLock<JackConnection>>, name: &str) -> Usually<Self> {
Ok(Self {
midi_in: jack.midi_in(&format!("M/{name}"))?,
audio_ins: vec![

View file

@ -6,7 +6,7 @@ use PhraseCommand::*;
use PhrasePoolCommand::*;
/// Root view for standalone `tek_sequencer`.
pub struct SequencerTui {
_jack: Arc<RwLock<JackClient>>,
_jack: Arc<RwLock<JackConnection>>,
pub transport: bool,
pub selectors: bool,
pub clock: ClockModel,

View file

@ -82,7 +82,7 @@ pub struct ClockModel {
pub chunk: Arc<AtomicUsize>,
}
from!(|jack: &Arc<RwLock<JackClient>>| ClockModel = {
from!(|jack: &Arc<RwLock<JackConnection>>| ClockModel = {
let jack = jack.read().unwrap();
let chunk = jack.client().buffer_size();
let transport = jack.client().transport();

View file

@ -5,7 +5,7 @@ use FocusCommand::{Next, Prev};
use KeyCode::{Enter, Left, Right, Char};
/// Transport clock app.
pub struct TransportTui {
pub jack: Arc<RwLock<JackClient>>,
pub jack: Arc<RwLock<JackConnection>>,
pub clock: ClockModel,
pub size: Measure<Tui>,
pub cursor: (usize, usize),