mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 04:06:45 +01:00
refactor: compact
This commit is contained in:
parent
abee6cc2c8
commit
60627ac3e5
43 changed files with 923 additions and 780 deletions
0
.misc/crates/engine/Cargo.toml
Normal file
0
.misc/crates/engine/Cargo.toml
Normal file
179
.misc/crates/engine/src/lib.rs
Normal file
179
.misc/crates/engine/src/lib.rs
Normal file
|
|
@ -0,0 +1,179 @@
|
|||
use std::error::Error;
|
||||
use std::thread;
|
||||
use std::collections::BTreeMap;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use crate::Cli;
|
||||
use jack::{
|
||||
Control,
|
||||
AsyncClient,
|
||||
Client,
|
||||
ClientStatus,
|
||||
ClientOptions,
|
||||
ClosureProcessHandler,
|
||||
NotificationHandler,
|
||||
ProcessScope,
|
||||
ProcessHandler,
|
||||
Frames,
|
||||
Port,
|
||||
PortId,
|
||||
AudioIn,
|
||||
AudioOut,
|
||||
MidiIn,
|
||||
MidiOut,
|
||||
Transport
|
||||
};
|
||||
|
||||
pub struct Jack {
|
||||
client: Option<AsyncClient<
|
||||
Box<dyn NotificationHandler>,
|
||||
ClosureProcessHandler<Box<dyn FnMut(&Client, &ProcessScope)->Control + Send>>
|
||||
>>,
|
||||
pub transport: Option<Transport>,
|
||||
audio_ins: BTreeMap<String, Port<AudioIn>>,
|
||||
audio_outs: BTreeMap<String, Port<AudioOut>>,
|
||||
midi_ins: BTreeMap<String, Port<MidiIn>>,
|
||||
midi_outs: BTreeMap<String, Port<MidiOut>>,
|
||||
}
|
||||
|
||||
impl Jack {
|
||||
pub fn init_from_cli (options: &Cli)
|
||||
-> Result<Arc<Mutex<Self>>, Box<dyn Error>>
|
||||
{
|
||||
let jack = Self::init(&options.jack_client_name)?;
|
||||
{
|
||||
let jack = jack.clone();
|
||||
let mut jack = jack.lock().unwrap();
|
||||
for port in options.jack_audio_ins.iter() {
|
||||
jack.add_audio_in(port)?;
|
||||
}
|
||||
for port in options.jack_audio_outs.iter() {
|
||||
jack.add_audio_out(port)?;
|
||||
}
|
||||
for port in options.jack_midi_ins.iter() {
|
||||
jack.add_midi_in(port)?;
|
||||
}
|
||||
for port in options.jack_midi_outs.iter() {
|
||||
jack.add_midi_out(port)?;
|
||||
}
|
||||
}
|
||||
Ok(jack.clone())
|
||||
}
|
||||
fn init (name: &str)
|
||||
-> Result<Arc<Mutex<Self>>, Box<dyn Error>>
|
||||
{
|
||||
let jack = Arc::new(Mutex::new(Self {
|
||||
client: None,
|
||||
transport: None,
|
||||
audio_ins: BTreeMap::new(),
|
||||
audio_outs: BTreeMap::new(),
|
||||
midi_ins: BTreeMap::new(),
|
||||
midi_outs: BTreeMap::new(),
|
||||
}));
|
||||
let (client, status) = Client::new(name, ClientOptions::NO_START_SERVER)?;
|
||||
println!("Client status: {status:?}");
|
||||
let jack1 = jack.clone();
|
||||
let mut jack1 = jack1.lock().unwrap();
|
||||
let jack2 = jack.clone();
|
||||
jack1.transport = Some(client.transport());
|
||||
jack1.client = Some(client.activate_async(
|
||||
Box::new(Notifications),
|
||||
ClosureProcessHandler::new(Box::new(
|
||||
move |_client: &Client, _ps: &ProcessScope| -> Control {
|
||||
let jack = jack2.lock().expect("Failed to lock jack mutex");
|
||||
jack.read_inputs();
|
||||
jack.write_outputs();
|
||||
Control::Continue
|
||||
}
|
||||
) as Box<dyn FnMut(&Client, &ProcessScope)->Control + Send>)
|
||||
)?);
|
||||
Ok(jack)
|
||||
}
|
||||
fn start (&self) {
|
||||
}
|
||||
fn process (&self, _: &Client, ps: &ProcessScope) -> Control {
|
||||
Control::Continue
|
||||
}
|
||||
fn add_audio_in (&mut self, name: &str) -> Result<&mut Self, Box<dyn Error>> {
|
||||
let port = self.client
|
||||
.as_ref()
|
||||
.expect("Not initialized.")
|
||||
.as_client()
|
||||
.register_port(name, AudioIn::default())?;
|
||||
self.audio_ins.insert(name.into(), port);
|
||||
Ok(self)
|
||||
}
|
||||
fn add_audio_out (&mut self, name: &str) -> Result<&mut Self, Box<dyn Error>> {
|
||||
let port = self.client
|
||||
.as_ref()
|
||||
.expect("Not initialized.")
|
||||
.as_client()
|
||||
.register_port(name, AudioOut::default())?;
|
||||
self.audio_outs.insert(name.into(), port);
|
||||
Ok(self)
|
||||
}
|
||||
fn add_midi_in (&mut self, name: &str) -> Result<&mut Self, Box<dyn Error>> {
|
||||
let port = self.client
|
||||
.as_ref()
|
||||
.expect("Not initialized.")
|
||||
.as_client()
|
||||
.register_port(name, MidiIn::default())?;
|
||||
self.midi_ins.insert(name.into(), port);
|
||||
Ok(self)
|
||||
}
|
||||
fn add_midi_out (&mut self, name: &str) -> Result<&mut Self, Box<dyn Error>> {
|
||||
let port = self.client
|
||||
.as_ref()
|
||||
.expect("Not initialized.")
|
||||
.as_client()
|
||||
.register_port(name, MidiOut::default())?;
|
||||
self.midi_outs.insert(name.into(), port);
|
||||
Ok(self)
|
||||
}
|
||||
fn read_inputs (&self) {
|
||||
// read input buffers
|
||||
//println!("read");
|
||||
}
|
||||
fn write_outputs (&self) {
|
||||
// clear output buffers
|
||||
// write output buffers
|
||||
//println!("write");
|
||||
}
|
||||
}
|
||||
|
||||
struct Notifications;
|
||||
|
||||
impl NotificationHandler for Notifications {
|
||||
fn thread_init (&self, _: &Client) {
|
||||
}
|
||||
|
||||
fn shutdown (&mut self, status: ClientStatus, reason: &str) {
|
||||
}
|
||||
|
||||
fn freewheel (&mut self, _: &Client, is_enabled: bool) {
|
||||
}
|
||||
|
||||
fn sample_rate (&mut self, _: &Client, _: Frames) -> Control {
|
||||
Control::Quit
|
||||
}
|
||||
|
||||
fn client_registration (&mut self, _: &Client, name: &str, is_reg: bool) {
|
||||
}
|
||||
|
||||
fn port_registration (&mut self, _: &Client, port_id: PortId, is_reg: bool) {
|
||||
}
|
||||
|
||||
fn port_rename (&mut self, _: &Client, id: PortId, old: &str, new: &str) -> Control {
|
||||
Control::Continue
|
||||
}
|
||||
|
||||
fn ports_connected (&mut self, _: &Client, id_a: PortId, id_b: PortId, are: bool) {
|
||||
}
|
||||
|
||||
fn graph_reorder (&mut self, _: &Client) -> Control {
|
||||
Control::Continue
|
||||
}
|
||||
|
||||
fn xrun (&mut self, _: &Client) -> Control {
|
||||
Control::Continue
|
||||
}
|
||||
}
|
||||
7
.misc/crates/midikbd/Cargo.toml
Normal file
7
.misc/crates/midikbd/Cargo.toml
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
[package]
|
||||
name = "midikbd"
|
||||
|
||||
[dependencies]
|
||||
jack = "0.10"
|
||||
clap = { version = "4.5.4", features = [ "derive" ] }
|
||||
crossterm = "0.25"
|
||||
38
.misc/crates/midikbd/src/main.rs
Normal file
38
.misc/crates/midikbd/src/main.rs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
extern crate clap;
|
||||
extern crate crossterm;
|
||||
extern crate engine;
|
||||
|
||||
type StdResult<T> = Result<T, Box<dyn std::error::Error>>
|
||||
|
||||
pub fn main () -> StdResult<()> {
|
||||
let cli = Cli::parse();
|
||||
let engine = run_jack_engine(move |_: &Client, _: &ProcessScope| {
|
||||
Control::Continue
|
||||
});
|
||||
let app = App::new()
|
||||
}
|
||||
|
||||
pub struct App {
|
||||
sleep: std::time::Duration
|
||||
}
|
||||
|
||||
impl App {
|
||||
fn init () -> Self {
|
||||
Self {
|
||||
sleep: std::time::Duration::from_millis(16)
|
||||
}
|
||||
}
|
||||
fn run (&self) -> StdResult<()> {
|
||||
loop {
|
||||
self.update()?;
|
||||
self.render()?;
|
||||
std::thread::sleep(self.sleep);
|
||||
}
|
||||
}
|
||||
fn update (&self) -> StdResult<()> {
|
||||
}
|
||||
fn render (&self) -> StdResult<()> {
|
||||
use crossterm::*;
|
||||
let (cols, rows) = terminal::size()?;
|
||||
}
|
||||
}
|
||||
0
.misc/crates/mixer/Cargo.toml
Normal file
0
.misc/crates/mixer/Cargo.toml
Normal file
0
.misc/crates/mixer/src/main.rs
Normal file
0
.misc/crates/mixer/src/main.rs
Normal file
0
.misc/crates/sampler/Cargo.toml
Normal file
0
.misc/crates/sampler/Cargo.toml
Normal file
0
.misc/crates/sampler/src/main.rs
Normal file
0
.misc/crates/sampler/src/main.rs
Normal file
0
.misc/crates/sequencer/Cargo.toml
Normal file
0
.misc/crates/sequencer/Cargo.toml
Normal file
0
.misc/crates/sequencer/src/main.rs
Normal file
0
.misc/crates/sequencer/src/main.rs
Normal file
0
.misc/crates/timebase/Cargo.toml
Normal file
0
.misc/crates/timebase/Cargo.toml
Normal file
46
.misc/crates/timebase/src/lib.rs
Normal file
46
.misc/crates/timebase/src/lib.rs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
pub struct Timebase {
|
||||
/// Sample rate
|
||||
rate: u64,
|
||||
/// Current frame
|
||||
frame: u64,
|
||||
/// Beats per bar
|
||||
signature: (u64, u64),
|
||||
/// Beats per minute
|
||||
bpm: f64,
|
||||
}
|
||||
|
||||
impl Timebase {
|
||||
pub fn new (rate: u64, signature: (u64, u64), bpm: f64) -> Self {
|
||||
Self {
|
||||
rate,
|
||||
frame: 0,
|
||||
signature,
|
||||
bpm,
|
||||
}
|
||||
}
|
||||
pub fn seconds (&self) -> f64 {
|
||||
self.frame as f64 / self.rate as f64
|
||||
}
|
||||
pub fn minutes (&self) -> f64 {
|
||||
self.seconds / 60.0
|
||||
}
|
||||
pub fn beats (&self) -> f64 {
|
||||
self.minutes / self.bpm
|
||||
}
|
||||
pub fn bar (&self) -> u64 {
|
||||
((self.beats() * self.signature.0 as f64) / self.signature.1 as f64) as u64
|
||||
}
|
||||
pub fn beat (&self) -> u64 {
|
||||
((self.beats() * self.signature.0 as f64) % self.signature.1 as f64) as u64
|
||||
}
|
||||
pub fn time_string (&self) -> String {
|
||||
let minutes = self.minutes() as u64;
|
||||
let seconds = self.seconds() as u64;
|
||||
let milliseconds = self.seconds() - seconds;
|
||||
format!("{minutes}:{seconds}.{milliseconds:03}")
|
||||
}
|
||||
pub fn beat_string (&self) -> String {
|
||||
let beats = self.beats() as u64;
|
||||
format!("{beats} {}/{}", minutes, self.beat(), self.signature.1)
|
||||
}
|
||||
}
|
||||
8
.misc/crates/transport/Cargo.toml
Normal file
8
.misc/crates/transport/Cargo.toml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
[package]
|
||||
name = "bloop_transport"
|
||||
|
||||
[dependencies]
|
||||
jack = "0.10"
|
||||
clap = { version = "4.5.4", features = [ "derive" ] }
|
||||
crossterm = "0.25"
|
||||
|
||||
39
.misc/crates/transport/src/main.rs
Normal file
39
.misc/crates/transport/src/main.rs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
extern crate clap;
|
||||
extern crate crossterm;
|
||||
extern crate engine;
|
||||
|
||||
type StdResult<T> = Result<T, Box<dyn std::error::Error>>
|
||||
|
||||
pub fn main () -> StdResult<()> {
|
||||
let cli = Cli::parse();
|
||||
let engine = run_jack_engine(move |_: &Client, _: &ProcessScope| {
|
||||
Control::Continue
|
||||
});
|
||||
let app = App::new()
|
||||
}
|
||||
|
||||
pub struct App {
|
||||
sleep: std::time::Duration,
|
||||
state: TransportState,
|
||||
}
|
||||
|
||||
impl App {
|
||||
fn init () -> Self {
|
||||
Self {
|
||||
sleep: std::time::Duration::from_millis(16)
|
||||
}
|
||||
}
|
||||
fn run (&self) -> StdResult<()> {
|
||||
loop {
|
||||
self.update()?;
|
||||
self.render()?;
|
||||
std::thread::sleep(self.sleep);
|
||||
}
|
||||
}
|
||||
fn update (&self) -> StdResult<()> {
|
||||
}
|
||||
fn render (&self) -> StdResult<()> {
|
||||
use crossterm::*;
|
||||
let (cols, rows) = terminal::size()?;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue