mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 04:06:45 +01:00
modularize core
This commit is contained in:
parent
a4061535b5
commit
2837ffff4a
43 changed files with 629 additions and 770 deletions
|
|
@ -1,21 +0,0 @@
|
|||
Device.inputs is Port[]
|
||||
Device.outputs is Port[]
|
||||
|
||||
Transport is Device
|
||||
Transport.session is Device
|
||||
|
||||
Mixer is Device
|
||||
Mixer.tracks is Device[]
|
||||
|
||||
Chain is Device
|
||||
Chain.devices is Device[]
|
||||
|
||||
Sequencer is Device
|
||||
|
||||
Sampler is Device
|
||||
|
||||
Plugin is Device
|
||||
|
||||
Mixer -> [Track1, Track2... TrackN]
|
||||
|
||||
Track -> [Device1, Device2... N]
|
||||
|
|
@ -1,9 +1,8 @@
|
|||
mod plugin;
|
||||
pub use self::plugin::*;
|
||||
mod sampler;
|
||||
pub use self::sampler::*;
|
||||
mod plugin; pub use self::plugin::*;
|
||||
mod sampler; pub use self::sampler::*;
|
||||
|
||||
use crate::prelude::*;
|
||||
use crate::core::*;
|
||||
use crate::layout::*;
|
||||
|
||||
pub struct Chain {
|
||||
pub name: String,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::prelude::*;
|
||||
use crate::core::*;
|
||||
|
||||
mod lv2;
|
||||
mod vst2;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::prelude::*;
|
||||
use crate::core::*;
|
||||
use super::*;
|
||||
|
||||
pub fn plug (uri: &str) -> Usually<PluginKind> {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::prelude::*;
|
||||
use crate::core::*;
|
||||
use super::*;
|
||||
|
||||
impl ::vst::host::Host for Plugin {}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::prelude::*;
|
||||
use crate::core::*;
|
||||
|
||||
pub struct Voice {
|
||||
sample: Arc<Sample>,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::prelude::*;
|
||||
use crate::core::*;
|
||||
use super::*;
|
||||
pub struct LauncherGridView<'a> {
|
||||
state: &'a Launcher,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::prelude::*;
|
||||
use crate::core::*;
|
||||
use super::*;
|
||||
pub fn handle (state: &mut Launcher, event: &AppEvent) -> Usually<bool> {
|
||||
Ok(handle_keymap(state, event, KEYMAP)? || match state.view {
|
||||
|
|
@ -54,13 +54,13 @@ fn activate (state: &mut Launcher) -> Usually<bool> {
|
|||
Some((track_id, track)),
|
||||
) = (state.scene(), state.track()) {
|
||||
// Launch clip
|
||||
if let Some(Some(phrase_id)) = scene.clips.get(track_id) {
|
||||
if let Some(phrase_id) = scene.clips.get(track_id) {
|
||||
track.sequencer.state().sequence = *phrase_id;
|
||||
}
|
||||
} else if let Some((scene_id, scene)) = state.scene() {
|
||||
// Launch scene
|
||||
for (track_id, track) in state.tracks.iter().enumerate() {
|
||||
if let Some(Some(phrase_id)) = scene.clips.get(track_id) {
|
||||
if let Some(phrase_id) = scene.clips.get(track_id) {
|
||||
track.sequencer.state().sequence = *phrase_id;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
use crate::prelude::*;
|
||||
use crate::core::*;
|
||||
use crate::layout::*;
|
||||
use crate::device::*;
|
||||
mod grid;
|
||||
pub use self::grid::*;
|
||||
mod handle;
|
||||
pub use self::grid::*; mod handle;
|
||||
pub use self::handle::*;
|
||||
pub struct Launcher {
|
||||
name: String,
|
||||
timebase: Arc<Timebase>,
|
||||
transport: Transport,
|
||||
transport: ::jack::Transport,
|
||||
playing: TransportState,
|
||||
monitoring: bool,
|
||||
recording: bool,
|
||||
|
|
@ -185,10 +186,10 @@ pub fn render (state: &Launcher, buf: &mut Buffer, mut area: Rect) -> Usually<Re
|
|||
//area.width = 80; // DOS mode
|
||||
//area.height = 25;
|
||||
let Rect { x, y, width, height } = area;
|
||||
crate::device::sequencer::draw_play_stop(buf, x + 1, y, &state.playing);
|
||||
crate::device::sequencer::draw_rec(buf, x + 12, y, state.recording);
|
||||
crate::device::sequencer::draw_mon(buf, x + 19, y, state.monitoring);
|
||||
crate::device::sequencer::draw_dub(buf, x + 26, y, state.overdub);
|
||||
crate::device::transport::draw_play_stop(buf, x + 1, y, &state.playing);
|
||||
crate::device::transport::draw_rec(buf, x + 12, y, state.recording);
|
||||
crate::device::transport::draw_mon(buf, x + 19, y, state.monitoring);
|
||||
crate::device::transport::draw_dub(buf, x + 26, y, state.overdub);
|
||||
draw_bpm(buf, x + 33, y, state.timebase.tempo());
|
||||
draw_timer(buf, x + width - 1, y, &state.timebase, state.position);
|
||||
let mut y = y + 1;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::prelude::*;
|
||||
use crate::core::*;
|
||||
|
||||
pub struct Looper {
|
||||
name: String
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
use crate::prelude::*;
|
||||
use crate::core::*;
|
||||
use crate::layout::*;
|
||||
|
||||
pub struct Mixer {
|
||||
name: String,
|
||||
|
|
|
|||
7
src/device/mod.rs
Normal file
7
src/device/mod.rs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
mod chain; pub use self::chain::{Chain, Plugin, Sampler, Sample, Voice};
|
||||
mod launcher; pub use self::launcher::{Launcher, Scene};
|
||||
mod looper; pub use self::looper::Looper;
|
||||
mod mixer; pub use self::mixer::Mixer;
|
||||
mod sequencer; pub use self::sequencer::{Sequencer, Phrase};
|
||||
mod track; pub use self::track::Track;
|
||||
mod transport; pub use self::transport::Transport;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::prelude::*;
|
||||
use crate::core::*;
|
||||
use super::*;
|
||||
pub fn handle (s: &mut Sequencer, event: &AppEvent) -> Usually<bool> {
|
||||
handle_keymap(s, event, KEYMAP)
|
||||
|
|
@ -39,7 +39,7 @@ pub const KEYMAP: &'static [KeyBinding<Sequencer>] = keymap!(Sequencer {
|
|||
});
|
||||
const fn focus_seq (i: usize) -> impl Fn(&mut Sequencer)->Usually<bool> {
|
||||
move |s: &mut Sequencer| {
|
||||
s.sequence = i;
|
||||
s.sequence = Some(i);
|
||||
Ok(true)
|
||||
}
|
||||
}
|
||||
|
|
@ -47,13 +47,16 @@ fn nop (_: &mut Sequencer) -> Usually<bool> {
|
|||
Ok(false)
|
||||
}
|
||||
fn note_add (s: &mut Sequencer) -> Usually<bool> {
|
||||
if s.sequence.is_none() {
|
||||
return Ok(false)
|
||||
}
|
||||
let step = (s.time_axis.0 + s.time_cursor) as u32;
|
||||
let start = (step as usize * s.timebase.ppq() / s.resolution) as u32;
|
||||
let end = ((step + 1) as usize * s.timebase.ppq() / s.resolution) as u32;
|
||||
let key = u7::from_int_lossy((s.note_cursor + s.note_axis.0) as u8);
|
||||
let note_on = MidiMessage::NoteOn { key, vel: 100.into() };
|
||||
let note_off = MidiMessage::NoteOff { key, vel: 100.into() };
|
||||
let sequence = &mut s.phrases[s.sequence].notes;
|
||||
let sequence = &mut s.phrases[s.sequence.unwrap()].notes;
|
||||
if sequence.contains_key(&start) {
|
||||
sequence.get_mut(&start).unwrap().push(note_on.clone());
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::prelude::*;
|
||||
use crate::core::*;
|
||||
use super::*;
|
||||
|
||||
pub fn draw (
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use super::*;
|
||||
use crate::core::*;
|
||||
|
||||
pub const KEY_WHITE: Style = Style {
|
||||
fg: Some(Color::Gray),
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
use crate::prelude::*;
|
||||
use crate::core::*;
|
||||
use crate::layout::*;
|
||||
|
||||
mod keys; use self::keys::*;
|
||||
mod handle; pub use self::handle::*;
|
||||
|
|
@ -22,7 +23,7 @@ pub struct Sequencer {
|
|||
/// FIXME: play start / end / loop in ppm
|
||||
pub steps: usize,
|
||||
/// Phrase selector
|
||||
pub sequence: usize,
|
||||
pub sequence: Option<usize>,
|
||||
/// Map: tick -> MIDI events at tick
|
||||
pub phrases: Vec<Phrase>,
|
||||
/// Red keys on piano roll.
|
||||
|
|
@ -51,12 +52,7 @@ pub struct Sequencer {
|
|||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum SequencerView {
|
||||
Tiny,
|
||||
Compact,
|
||||
Horizontal,
|
||||
Vertical,
|
||||
}
|
||||
pub enum SequencerView { Tiny, Compact, Horizontal, Vertical, }
|
||||
|
||||
impl Sequencer {
|
||||
pub fn new (
|
||||
|
|
@ -74,8 +70,10 @@ impl Sequencer {
|
|||
timebase: timebase.clone(),
|
||||
steps: 16,
|
||||
resolution: 4,
|
||||
sequence: 0,
|
||||
phrases: phrases.unwrap_or(vec![]),
|
||||
sequence: Some(0),
|
||||
phrases: phrases.unwrap_or(vec![
|
||||
Phrase::new("Phrase0", 4*timebase.ppq() as u32, None)
|
||||
]),
|
||||
notes_on: vec![false;128],
|
||||
|
||||
playing: TransportState::Starting,
|
||||
|
|
@ -93,12 +91,12 @@ impl Sequencer {
|
|||
}
|
||||
|
||||
pub fn phrase <'a> (&'a self) -> Option<&'a Phrase> {
|
||||
self.phrases.get(self.sequence)
|
||||
self.sequence.map(|s|self.phrases.get(s))?
|
||||
}
|
||||
}
|
||||
|
||||
impl PortList for Sequencer {
|
||||
fn midi_ins (&self) -> Usually<Vec<String>> {
|
||||
fn midi_ins (&self) -> Usually<Vec<String>> {
|
||||
Ok(vec![self.midi_in.name()?])
|
||||
}
|
||||
fn midi_outs (&self) -> Usually<Vec<String>> {
|
||||
|
|
@ -117,22 +115,22 @@ fn render (s: &Sequencer, buf: &mut Buffer, area: Rect) -> Usually<Rect> {
|
|||
let steps = usecs / ustep;
|
||||
let header = draw_header(s, buf, area, steps)?;
|
||||
let piano = match s.mode {
|
||||
SequencerView::Tiny =>
|
||||
Rect { x, y, width, height: 0 },
|
||||
SequencerView::Compact =>
|
||||
Rect { x, y, width, height: 0 },
|
||||
SequencerView::Vertical => self::vertical::draw(s, buf, Rect {
|
||||
x,
|
||||
y: y + header.height,
|
||||
width: 3 + note1 - note0,
|
||||
height: 3 + time1 - time0,
|
||||
}, steps)?,
|
||||
SequencerView::Horizontal => self::horizontal::draw(s, buf, Rect {
|
||||
x,
|
||||
y: y + header.height,
|
||||
width: area.width.max(3 + time1 - time0),
|
||||
height: 3 + note1 - note0,
|
||||
}, steps)?,
|
||||
SequencerView::Tiny => Rect { x, y, width, height: 0 },
|
||||
SequencerView::Compact => Rect { x, y, width, height: 0 },
|
||||
SequencerView::Vertical =>
|
||||
self::vertical::draw(s, buf, Rect {
|
||||
x,
|
||||
y: y + header.height,
|
||||
width: 3 + note1 - note0,
|
||||
height: 3 + time1 - time0,
|
||||
}, steps)?,
|
||||
SequencerView::Horizontal =>
|
||||
self::horizontal::draw(s, buf, Rect {
|
||||
x,
|
||||
y: y + header.height,
|
||||
width: area.width.max(3 + time1 - time0),
|
||||
height: 3 + note1 - note0,
|
||||
}, steps)?,
|
||||
};
|
||||
Ok(draw_box(buf, Rect {
|
||||
x,
|
||||
|
|
@ -150,12 +148,12 @@ pub fn draw_header (s: &Sequencer, buf: &mut Buffer, area: Rect, beat: usize) ->
|
|||
let steps = s.steps % s.resolution;
|
||||
draw_timer(buf, x + width - 2, y + 1, &format!("{rep}.{step:02} / {reps}.{steps}"));
|
||||
let style = Style::default().gray();
|
||||
draw_play_stop(buf, x + 2, y + 1, &s.playing);
|
||||
crate::device::transport::draw_play_stop(buf, x + 2, y + 1, &s.playing);
|
||||
let separator = format!("├{}┤", "-".repeat((area.width - 2).into()));
|
||||
separator.blit(buf, x, y + 2, Some(style.dim()));
|
||||
draw_rec(buf, x + 13, y + 1, s.recording);
|
||||
draw_dub(buf, x + 20, y + 1, s.overdub);
|
||||
draw_mon(buf, x + 27, y + 1, s.monitoring);
|
||||
crate::device::transport::draw_rec(buf, x + 13, y + 1, s.recording);
|
||||
crate::device::transport::draw_dub(buf, x + 20, y + 1, s.overdub);
|
||||
crate::device::transport::draw_mon(buf, x + 27, y + 1, s.monitoring);
|
||||
let _ = draw_clips(s, buf, area)?;
|
||||
Ok(Rect { x, y, width: area.width, height: 3 })
|
||||
}
|
||||
|
|
@ -165,45 +163,12 @@ pub fn draw_timer (
|
|||
let style = Some(Style::default().gray().bold().not_dim());
|
||||
timer.blit(buf, x - timer.len() as u16, y, style);
|
||||
}
|
||||
pub fn draw_play_stop (buf: &mut Buffer, x: u16, y: u16, state: &TransportState) {
|
||||
let style = Style::default().gray();
|
||||
match state {
|
||||
TransportState::Rolling => "▶ PLAYING",
|
||||
TransportState::Starting => "READY ...",
|
||||
TransportState::Stopped => "⏹ STOPPED",
|
||||
}.blit(buf, x, y, Some(match state {
|
||||
TransportState::Stopped => style.dim().bold(),
|
||||
TransportState::Starting => style.not_dim().bold(),
|
||||
TransportState::Rolling => style.not_dim().white().bold()
|
||||
}));
|
||||
}
|
||||
pub fn draw_rec (buf: &mut Buffer, x: u16, y: u16, on: bool) {
|
||||
"⏺ REC".blit(buf, x, y, Some(if on {
|
||||
Style::default().bold().red()
|
||||
} else {
|
||||
Style::default().bold().dim()
|
||||
}))
|
||||
}
|
||||
pub fn draw_dub (buf: &mut Buffer, x: u16, y: u16, on: bool) {
|
||||
"⏺ DUB".blit(buf, x, y, Some(if on {
|
||||
Style::default().bold().yellow()
|
||||
} else {
|
||||
Style::default().bold().dim()
|
||||
}))
|
||||
}
|
||||
pub fn draw_mon (buf: &mut Buffer, x: u16, y: u16, on: bool) {
|
||||
"⏺ MON".blit(buf, x, y, Some(if on {
|
||||
Style::default().bold().green()
|
||||
} else {
|
||||
Style::default().bold().dim()
|
||||
}))
|
||||
}
|
||||
fn draw_clips (s: &Sequencer, buf: &mut Buffer, area: Rect) -> Usually<Rect> {
|
||||
let Rect { x, y, .. } = area;
|
||||
let style = Style::default().gray();
|
||||
for (i, sequence) in s.phrases.iter().enumerate() {
|
||||
let label = format!("▶ {}", &sequence.name);
|
||||
label.blit(buf, x + 2, y + 3 + (i as u16)*2, Some(if i == s.sequence {
|
||||
label.blit(buf, x + 2, y + 3 + (i as u16)*2, Some(if Some(i) == s.sequence {
|
||||
match s.playing {
|
||||
TransportState::Rolling => style.white().bold(),
|
||||
_ => style.not_dim().bold()
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
use crate::prelude::*;
|
||||
use super::*;
|
||||
use crate::core::*;
|
||||
|
||||
pub type PhraseData = BTreeMap<u32, Vec<MidiMessage>>;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,12 @@
|
|||
use crate::prelude::*;
|
||||
use crate::core::*;
|
||||
use super::*;
|
||||
|
||||
pub fn process (state: &mut Sequencer, _: &Client, scope: &ProcessScope) -> Control {
|
||||
// Get currently playing sequence
|
||||
let sequence = state.phrases.get_mut(state.sequence);
|
||||
if state.sequence.is_none() {
|
||||
return Control::Continue
|
||||
}
|
||||
let sequence = state.phrases.get_mut(state.sequence.unwrap());
|
||||
if sequence.is_none() {
|
||||
return Control::Continue
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::prelude::*;
|
||||
use crate::core::*;
|
||||
use super::*;
|
||||
|
||||
pub fn draw (
|
||||
|
|
@ -18,6 +18,9 @@ pub fn draw (
|
|||
}
|
||||
|
||||
pub fn steps (s: &Sequencer, buf: &mut Buffer, area: Rect, beat: usize) {
|
||||
if s.sequence.is_none() {
|
||||
return
|
||||
}
|
||||
let ppq = s.timebase.ppq() as u32;
|
||||
let bg = Style::default();
|
||||
let bw = bg.dim();
|
||||
|
|
@ -41,8 +44,8 @@ pub fn steps (s: &Sequencer, buf: &mut Buffer, area: Rect, beat: usize) {
|
|||
(step + 2) as u32 * ppq / s.resolution as u32,
|
||||
);
|
||||
let (character, style) = match (
|
||||
contains_note_on(&s.phrases[s.sequence], key, a, b),
|
||||
contains_note_on(&s.phrases[s.sequence], key, b, c),
|
||||
contains_note_on(&s.phrases[s.sequence.unwrap()], key, a, b),
|
||||
contains_note_on(&s.phrases[s.sequence.unwrap()], key, b, c),
|
||||
) {
|
||||
(true, true) => ("█", wh),
|
||||
(true, false) => ("▀", wh),
|
||||
|
|
@ -106,8 +109,8 @@ pub fn keys (s: &Sequencer, buf: &mut Buffer, area: Rect, beat: usize) {
|
|||
(step + 2) as u32 * ppq / s.resolution as u32,
|
||||
);
|
||||
let key = ::midly::num::u7::from(key as u8);
|
||||
is_on = is_on || contains_note_on(&s.phrases[s.sequence], key, a, b);
|
||||
is_on = is_on || contains_note_on(&s.phrases[s.sequence], key, b, c);
|
||||
is_on = is_on || contains_note_on(&s.phrases[s.sequence.unwrap()], key, a, b);
|
||||
is_on = is_on || contains_note_on(&s.phrases[s.sequence.unwrap()], key, b, c);
|
||||
if is_on {
|
||||
color = Style::default().red();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
use crate::prelude::*;
|
||||
use crate::core::*;
|
||||
use crate::device::*;
|
||||
use crate::layout::*;
|
||||
pub struct Track {
|
||||
pub name: String,
|
||||
pub sequencer: DynamicDevice<Sequencer>,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,39 @@
|
|||
use crate::prelude::*;
|
||||
use crate::core::*;
|
||||
use crate::layout::*;
|
||||
|
||||
pub fn draw_play_stop (buf: &mut Buffer, x: u16, y: u16, state: &TransportState) {
|
||||
let style = Style::default().gray();
|
||||
match state {
|
||||
TransportState::Rolling => "▶ PLAYING",
|
||||
TransportState::Starting => "READY ...",
|
||||
TransportState::Stopped => "⏹ STOPPED",
|
||||
}.blit(buf, x, y, Some(match state {
|
||||
TransportState::Stopped => style.dim().bold(),
|
||||
TransportState::Starting => style.not_dim().bold(),
|
||||
TransportState::Rolling => style.not_dim().white().bold()
|
||||
}));
|
||||
}
|
||||
pub fn draw_rec (buf: &mut Buffer, x: u16, y: u16, on: bool) {
|
||||
"⏺ REC".blit(buf, x, y, Some(if on {
|
||||
Style::default().bold().red()
|
||||
} else {
|
||||
Style::default().bold().dim()
|
||||
}))
|
||||
}
|
||||
pub fn draw_dub (buf: &mut Buffer, x: u16, y: u16, on: bool) {
|
||||
"⏺ DUB".blit(buf, x, y, Some(if on {
|
||||
Style::default().bold().yellow()
|
||||
} else {
|
||||
Style::default().bold().dim()
|
||||
}))
|
||||
}
|
||||
pub fn draw_mon (buf: &mut Buffer, x: u16, y: u16, on: bool) {
|
||||
"⏺ MON".blit(buf, x, y, Some(if on {
|
||||
Style::default().bold().green()
|
||||
} else {
|
||||
Style::default().bold().dim()
|
||||
}))
|
||||
}
|
||||
|
||||
pub struct Transport {
|
||||
name: String,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue