mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
fix timer of horizontal sequencer
This commit is contained in:
parent
2601592d17
commit
1259176576
6 changed files with 293 additions and 254 deletions
235
src/control.rs
235
src/control.rs
|
|
@ -5,7 +5,7 @@ pub mod sampler;
|
|||
|
||||
pub use self::focus::*;
|
||||
|
||||
use crate::{core::*, model::*, handle, App};
|
||||
use crate::{core::*, handle, App};
|
||||
|
||||
handle!(App |self, e| {
|
||||
if let Some(ref mut modal) = self.modal {
|
||||
|
|
@ -18,82 +18,117 @@ handle!(App |self, e| {
|
|||
});
|
||||
|
||||
const KEYMAP: &'static [KeyBinding<App>] = keymap!(App {
|
||||
[F(1), NONE, "toggle_help", "toggle help", toggle_help],
|
||||
[Char(' '), NONE, "toggle_play", "play or pause", |app: &mut App| {
|
||||
app.toggle_play()?;
|
||||
Ok(true)
|
||||
}],
|
||||
[Char('a'), CONTROL, "add_scene", "add a new scene", |app: &mut App| {
|
||||
app.add_scene(None)?;
|
||||
Ok(true)
|
||||
}],
|
||||
[Char('t'), CONTROL, "add_track", "add a new track", |app: &mut App| {
|
||||
app.add_track(None)?;
|
||||
Ok(true)
|
||||
}],
|
||||
[Char('`'), NONE, "switch_mode", "switch the display mode", |app: &mut App| {
|
||||
match app.section {
|
||||
0 => {app.grid_mode = !app.grid_mode; Ok(true)},
|
||||
1 => {app.chain_mode = !app.chain_mode; Ok(true)},
|
||||
2 => {app.seq_mode = !app.seq_mode; Ok(true)},
|
||||
_ => Ok(false)
|
||||
}
|
||||
}],
|
||||
[F(1), NONE, "toggle_help", "toggle help", |_: &mut App| {Ok(true)}],
|
||||
[Char('r'), NONE, "toggle_record", "toggle recording", |_: &mut App| {Ok(true)}],
|
||||
[Char('d'), NONE, "toggle_overdub", "toggle overdub", |_: &mut App| {Ok(true)}],
|
||||
[Char('m'), NONE, "toggle_monitor", "toggle input monitoring", |_: &mut App| {Ok(true)}],
|
||||
[Up, NONE, "cursor_up", "move cursor up", |app: &mut App| {
|
||||
if app.entered {
|
||||
match app.section {
|
||||
0 => match app.grid_mode {
|
||||
false => {app.scene_cursor = app.scene_cursor.saturating_sub(1); Ok(true)},
|
||||
true => {app.track_cursor = app.track_cursor.saturating_sub(1); Ok(true)},
|
||||
},
|
||||
_ => Ok(false)
|
||||
}
|
||||
} else {
|
||||
focus_prev(app)
|
||||
}
|
||||
}],
|
||||
[Down, NONE, "cursor_down", "move cursor down", |app: &mut App| {
|
||||
if app.entered {
|
||||
match app.section {
|
||||
0 => match app.grid_mode {
|
||||
false => {app.scene_cursor = app.scenes.len().min(app.scene_cursor + 1); Ok(true)},
|
||||
true => {app.track_cursor = app.tracks.len().min(app.track_cursor + 1); Ok(true)},
|
||||
},
|
||||
_ => Ok(false)
|
||||
}
|
||||
} else {
|
||||
focus_next(app)
|
||||
}
|
||||
}],
|
||||
[Left, NONE, "cursor_left", "move cursor left", |app: &mut App| {
|
||||
match app.section {
|
||||
0 => match app.grid_mode {
|
||||
false => {app.track_cursor = app.track_cursor.saturating_sub(1); Ok(true)},
|
||||
true => {app.scene_cursor = app.scene_cursor.saturating_sub(1); Ok(true)},
|
||||
},
|
||||
1 => {
|
||||
if let Some((_, track)) = app.track_mut() {
|
||||
track.device = track.device.saturating_sub(1);
|
||||
Ok(true)
|
||||
} else {
|
||||
Ok(false)
|
||||
}
|
||||
},
|
||||
2 => {
|
||||
app.time_cursor = app.time_cursor.saturating_sub(1);
|
||||
Ok(true)
|
||||
},
|
||||
_ => Ok(false)
|
||||
}
|
||||
}],
|
||||
[Right, NONE, "cursor_right", "move cursor right", |app: &mut App| {
|
||||
match app.section {
|
||||
0 => match app.grid_mode {
|
||||
false => {app.track_cursor = app.tracks.len().min(app.track_cursor + 1); Ok(true)},
|
||||
true => {app.scene_cursor = app.scenes.len().min(app.scene_cursor + 1); Ok(true)},
|
||||
},
|
||||
1 => {
|
||||
if let Some((_, track)) = app.track_mut() {
|
||||
track.device = (track.device + 1).min(track.devices.len().saturating_sub(1));
|
||||
Ok(true)
|
||||
} else {
|
||||
Ok(false)
|
||||
}
|
||||
},
|
||||
2 => {
|
||||
app.time_cursor = app.time_cursor + 1;
|
||||
Ok(true)
|
||||
},
|
||||
_ => Ok(false)
|
||||
}
|
||||
}],
|
||||
[Tab, NONE, "focus_next", "focus next area", focus_next],
|
||||
[Tab, SHIFT, "focus_prev", "focus previous area", focus_prev],
|
||||
[Up, NONE, "cursor_up", "move cursor up", cursor_up],
|
||||
[Down, NONE, "cursor_down", "move cursor down", cursor_down],
|
||||
[Left, NONE, "cursor_left", "move cursor left", cursor_left],
|
||||
[Right, NONE, "cursor_right", "move cursor right", cursor_right],
|
||||
[Char('.'), NONE, "increment", "increment value at cursor", increment],
|
||||
[Char(','), NONE, "decrement", "decrement value at cursor", decrement],
|
||||
[Char('.'), NONE, "increment", "increment value", increment],
|
||||
[Char(','), NONE, "decrement", "decrement value", decrement],
|
||||
[Delete, CONTROL, "delete", "delete track", delete],
|
||||
[Char('d'), CONTROL, "duplicate", "duplicate scene or track", duplicate],
|
||||
[Enter, NONE, "activate", "activate item at cursor", enter],
|
||||
[Esc, NONE, "escape", "unfocus", escape],
|
||||
[Char(' '), NONE, "toggle_play", "play or pause", toggle_play],
|
||||
[Char('r'), NONE, "toggle_record", "toggle recording", toggle_record],
|
||||
[Char('d'), NONE, "toggle_overdub", "toggle overdub", toggle_overdub],
|
||||
[Char('m'), NONE, "toggle_monitor", "toggle input monitoring", toggle_monitor],
|
||||
[Char('r'), CONTROL, "rename", "rename current element", rename],
|
||||
[Char('t'), CONTROL, "add_track", "add a new track", add_track],
|
||||
[Char('a'), CONTROL, "add_scene", "add a new scene", add_scene],
|
||||
[Char('`'), NONE, "switch_mode", "switch the display mode", switch_mode],
|
||||
// [Char('='), NONE, "zoom_in", "Zoom in", zoom_in],
|
||||
// [Char('-'), NONE, "zoom_out", "Zoom out", zoom_out],
|
||||
// [Char('a'), NONE, "note_add", "Add note", note_add],
|
||||
// [Char('z'), NONE, "note_del", "Delete note", note_del],
|
||||
// [CapsLock, NONE, "advance", "Toggle auto advance", nop],
|
||||
// [Char('w'), NONE, "rest", "Advance by note duration", nop],
|
||||
// [Char('s'), NONE, "stop_and_rewind", "Stop and rewind", stop_and_rewind],
|
||||
// [Char('q'), NONE, "quantize_next", "Next quantize value", quantize_next],
|
||||
// [Char('Q'), SHIFT, "quantize_prev", "Previous quantize value", quantize_prev],
|
||||
});
|
||||
//-pub const KEYMAP: &'static [KeyBinding<Sequencer>] = keymap!(Sequencer {
|
||||
//- [Up, NONE, "cursor_up", "move cursor up", cursor_up],
|
||||
//- [Down, NONE, "cursor_down", "move cursor down", cursor_down],
|
||||
//- [Left, NONE, "cursor_left", "move cursor left", cursor_left],
|
||||
//- [Right, NONE, "cursor_right", "move cursor right", cursor_right],
|
||||
//- [Char('.'), NONE, "cursor_inc", "increase note duration", cursor_duration_inc],
|
||||
//- [Char(','), NONE, "cursor_dec", "decrease note duration", cursor_duration_dec],
|
||||
//- [Char('`'), NONE, "mode_next", "Next view mode", mode_next],
|
||||
//- [Char('='), NONE, "zoom_in", "Zoom in", zoom_in],
|
||||
//- [Char('-'), NONE, "zoom_out", "Zoom out", zoom_out],
|
||||
//- [Char('a'), NONE, "note_add", "Add note", note_add],
|
||||
//- [Char('z'), NONE, "note_del", "Delete note", note_del],
|
||||
//- [CapsLock, NONE, "advance", "Toggle auto advance", nop],
|
||||
//- [Char('w'), NONE, "rest", "Advance by note duration", nop],
|
||||
//- [Char(' '), NONE, "toggle_play", "Toggle play/pause", toggle_play],
|
||||
//- [Char('r'), NONE, "toggle_record", "Toggle recording", toggle_record],
|
||||
//- [Char('d'), NONE, "toggle_overdub", "Toggle overdub", toggle_overdub],
|
||||
//- [Char('m'), NONE, "toggle_monitor", "Toggle input monitoring", toggle_monitor],
|
||||
//- [Char('s'), NONE, "stop_and_rewind", "Stop and rewind", stop_and_rewind],
|
||||
//- [Char('q'), NONE, "quantize_next", "Next quantize value", quantize_next],
|
||||
//- [Char('Q'), SHIFT, "quantize_prev", "Previous quantize value", quantize_prev],
|
||||
//-});
|
||||
|
||||
fn toggle_play (app: &mut App) -> Usually<bool> {
|
||||
app.playing = match app.playing.expect("after jack init") {
|
||||
TransportState::Stopped => {
|
||||
app.transport.as_ref().unwrap().start()?;
|
||||
Some(TransportState::Starting)
|
||||
},
|
||||
_ => {
|
||||
app.transport.as_ref().unwrap().stop()?;
|
||||
app.transport.as_ref().unwrap().locate(0)?;
|
||||
Some(TransportState::Stopped)
|
||||
},
|
||||
};
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
fn toggle_record (_: &mut App) -> Usually<bool> { Ok(true) }
|
||||
|
||||
fn toggle_overdub (_: &mut App) -> Usually<bool> { Ok(true) }
|
||||
|
||||
fn toggle_monitor (_: &mut App) -> Usually<bool> { Ok(true) }
|
||||
|
||||
fn toggle_help (_: &mut App) -> Usually<bool> { Ok(true) }
|
||||
|
||||
fn switch_mode (app: &mut App) -> Usually<bool> {
|
||||
match app.section {
|
||||
0 => {app.grid_mode = !app.grid_mode; Ok(true)},
|
||||
1 => {app.chain_mode = !app.chain_mode; Ok(true)},
|
||||
2 => {app.seq_mode = !app.seq_mode; Ok(true)},
|
||||
_ => Ok(false)
|
||||
}
|
||||
}
|
||||
|
||||
fn focus_next (app: &mut App) -> Usually<bool> {
|
||||
if app.section >= 2 {
|
||||
|
|
@ -113,54 +148,6 @@ fn focus_prev (app: &mut App) -> Usually<bool> {
|
|||
Ok(true)
|
||||
}
|
||||
|
||||
fn cursor_up (app: &mut App) -> Usually<bool> {
|
||||
if app.entered {
|
||||
match app.section {
|
||||
0 => match app.grid_mode {
|
||||
false => {app.scene_cursor = app.scene_cursor.saturating_sub(1); Ok(true)},
|
||||
true => {app.track_cursor = app.track_cursor.saturating_sub(1); Ok(true)},
|
||||
},
|
||||
_ => Ok(false)
|
||||
}
|
||||
} else {
|
||||
focus_prev(app)
|
||||
}
|
||||
}
|
||||
|
||||
fn cursor_down (app: &mut App) -> Usually<bool> {
|
||||
if app.entered {
|
||||
match app.section {
|
||||
0 => match app.grid_mode {
|
||||
false => {app.scene_cursor = app.scenes.len().min(app.scene_cursor + 1); Ok(true)},
|
||||
true => {app.track_cursor = app.tracks.len().min(app.track_cursor + 1); Ok(true)},
|
||||
},
|
||||
_ => Ok(false)
|
||||
}
|
||||
} else {
|
||||
focus_next(app)
|
||||
}
|
||||
}
|
||||
|
||||
fn cursor_left (app: &mut App) -> Usually<bool> {
|
||||
match app.section {
|
||||
0 => match app.grid_mode {
|
||||
false => {app.track_cursor = app.track_cursor.saturating_sub(1); Ok(true)},
|
||||
true => {app.scene_cursor = app.scene_cursor.saturating_sub(1); Ok(true)},
|
||||
},
|
||||
_ => Ok(false)
|
||||
}
|
||||
}
|
||||
|
||||
fn cursor_right (app: &mut App) -> Usually<bool> {
|
||||
match app.section {
|
||||
0 => match app.grid_mode {
|
||||
false => {app.track_cursor = app.tracks.len().min(app.track_cursor + 1); Ok(true)},
|
||||
true => {app.scene_cursor = app.scenes.len().min(app.scene_cursor + 1); Ok(true)},
|
||||
},
|
||||
_ => Ok(false)
|
||||
}
|
||||
}
|
||||
|
||||
fn increment (app: &mut App) -> Usually<bool> {
|
||||
match app.section {
|
||||
0 => clip_next(app),
|
||||
|
|
@ -291,20 +278,6 @@ fn escape (app: &mut App) -> Usually<bool> {
|
|||
}
|
||||
}
|
||||
|
||||
fn add_scene (app: &mut App) -> Usually<bool> {
|
||||
let name = format!("Scene {}", app.scenes.len() + 1);
|
||||
app.scenes.push(Scene::new(&name, vec![]));
|
||||
app.scene_cursor = app.scenes.len();
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
fn add_track (app: &mut App) -> Usually<bool> {
|
||||
let name = format!("Track {}", app.tracks.len() + 1);
|
||||
app.tracks.push(Track::new(&name, app.jack.as_ref().unwrap().as_client(), None, None)?);
|
||||
app.track_cursor = app.tracks.len();
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
fn delete_track (app: &mut App) -> Usually<bool> {
|
||||
if app.tracks.len() > 0 {
|
||||
let track = app.tracks.remove(app.track_cursor);
|
||||
|
|
|
|||
27
src/main.rs
27
src/main.rs
|
|
@ -73,6 +73,7 @@ pub fn main () -> Usually<()> {
|
|||
state.midi_in = Some(client.register_port("midi-in", MidiIn)?);
|
||||
state.transport = Some(client.transport());
|
||||
state.playing = Some(TransportState::Stopped);
|
||||
state.time_zoom = 24;
|
||||
state.jack = Some(jack);
|
||||
Ok(())
|
||||
}))
|
||||
|
|
@ -156,6 +157,20 @@ process!(App |self, _client, scope| {
|
|||
});
|
||||
|
||||
impl App {
|
||||
pub fn toggle_play (&mut self) -> Usually<()> {
|
||||
self.playing = match self.playing.expect("after jack init") {
|
||||
TransportState::Stopped => {
|
||||
self.transport.as_ref().unwrap().start()?;
|
||||
Some(TransportState::Starting)
|
||||
},
|
||||
_ => {
|
||||
self.transport.as_ref().unwrap().stop()?;
|
||||
self.transport.as_ref().unwrap().locate(0)?;
|
||||
Some(TransportState::Stopped)
|
||||
},
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
pub fn connect_tracks (&self) -> Usually<()> {
|
||||
//let (client, _status) = Client::new(
|
||||
//&format!("{}-init", &self.name), ClientOptions::NO_START_SERVER
|
||||
|
|
@ -184,6 +199,18 @@ impl App {
|
|||
//}
|
||||
Ok(())
|
||||
}
|
||||
pub fn add_scene (&mut self, name: Option<&str>) -> Usually<&mut Scene> {
|
||||
let name = name.ok_or_else(||format!("Scene {}", self.scenes.len() + 1))?;
|
||||
self.scenes.push(Scene::new(&name, vec![]));
|
||||
self.scene_cursor = self.scenes.len();
|
||||
Ok(&mut self.scenes[self.scene_cursor - 1])
|
||||
}
|
||||
pub fn add_track (&mut self, name: Option<&str>) -> Usually<&mut Track> {
|
||||
let name = name.ok_or_else(||format!("Track {}", self.tracks.len() + 1))?;
|
||||
self.tracks.push(Track::new(&name, self.jack.as_ref().unwrap().as_client(), None, None)?);
|
||||
self.track_cursor = self.tracks.len();
|
||||
Ok(&mut self.tracks[self.track_cursor - 1])
|
||||
}
|
||||
pub fn track (&self) -> Option<(usize, &Track)> {
|
||||
match self.track_cursor { 0 => None, _ => {
|
||||
let id = self.track_cursor as usize - 1;
|
||||
|
|
|
|||
|
|
@ -43,10 +43,32 @@ impl Track {
|
|||
device: 0,
|
||||
})
|
||||
}
|
||||
pub fn phrase (&self) -> Option<&Phrase> {
|
||||
if let Some(phrase) = self.sequence {
|
||||
return self.phrases.get(phrase)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PortList for Track {
|
||||
fn midi_ins (&self) -> Usually<Vec<String>> { Ok(vec![]) }
|
||||
fn midi_outs (&self) -> Usually<Vec<String>> { Ok(vec![self.midi_out.name()?]) }
|
||||
fn midi_outs (&self) -> Usually<Vec<String>> {
|
||||
Ok(vec![self.midi_out.name()?])
|
||||
}
|
||||
fn midi_ins (&self) -> Usually<Vec<String>> {
|
||||
if let Some(device) = self.devices.get(0) {
|
||||
device.midi_ins()
|
||||
} else {
|
||||
Ok(vec![])
|
||||
}
|
||||
}
|
||||
fn audio_outs (&self) -> Usually<Vec<String>> {
|
||||
if let Some(device) = self.devices.get(self.devices.len().saturating_sub(1)) {
|
||||
device.audio_outs()
|
||||
} else {
|
||||
Ok(vec![])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
13
src/view.rs
13
src/view.rs
|
|
@ -39,16 +39,17 @@ render!(App |self, buf, area| {
|
|||
}.draw()?.height;
|
||||
|
||||
if self.track_cursor > 0 {
|
||||
let track = self.tracks.get(self.track_cursor - 1);
|
||||
y = y + ChainView {
|
||||
focused: self.section == 1,
|
||||
chain: track,
|
||||
}.render(buf, Rect { x, y, width, height: height / 3 })?.height;
|
||||
|
||||
let track = self.tracks.get(self.track_cursor - 1).unwrap();
|
||||
|
||||
y = y + ChainView { focused: self.section == 1, track: Some(track) }
|
||||
.render(buf, Rect { x, y, width, height: height / 3 })?.height;
|
||||
|
||||
y = y + SequencerView {
|
||||
focused: self.section == 2,
|
||||
ppq: self.timebase.ppq() as usize,
|
||||
phrase: track.map(|t|&t.phrases[0]),
|
||||
now: self.timebase.frames_pulses(self.playhead as f64) as usize,
|
||||
phrase: track.phrases.get(0),
|
||||
time_cursor: self.time_cursor,
|
||||
time_start: self.time_start,
|
||||
time_zoom: self.time_zoom,
|
||||
|
|
|
|||
|
|
@ -11,70 +11,92 @@ pub enum ChainViewMode {
|
|||
|
||||
pub struct ChainView<'a> {
|
||||
pub focused: bool,
|
||||
pub chain: Option<&'a Track>,
|
||||
pub track: Option<&'a Track>,
|
||||
}
|
||||
|
||||
impl<'a> Render for ChainView<'a> {
|
||||
fn render (&self, buf: &mut Buffer, area: Rect) -> Usually<Rect> {
|
||||
let style = Some(if self.focused {
|
||||
Style::default().green()
|
||||
} else {
|
||||
Style::default().green().dim()
|
||||
} else {
|
||||
Style::default().dim()
|
||||
});
|
||||
let (area, _plugins) = if let Some(ref chain) = self.chain {
|
||||
draw_as_row(&*chain, buf, area, style)?
|
||||
let Rect { x, y, width, height } = area;
|
||||
if self.track.is_none() {
|
||||
let label = "No track selected";
|
||||
label.blit(
|
||||
buf,
|
||||
x + (width - label.len() as u16) / 2,
|
||||
y + height / 2,
|
||||
Some(Style::default().dim().bold())
|
||||
);
|
||||
}
|
||||
lozenge_left(buf, x, y, height, style);
|
||||
let (area, _plugins) = if let Some(ref chain) = self.track {
|
||||
self.draw_as_row(buf, area, style)?
|
||||
} else {
|
||||
(area, vec![])
|
||||
};
|
||||
let Rect { x, y, width, height} = area;
|
||||
lozenge_left(buf, x, y, height, style);
|
||||
lozenge_right(buf, x + width - 1, y, height, style);
|
||||
Ok(area)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn draw_as_row (
|
||||
state: &Track, buf: &mut Buffer, area: Rect, style: Option<Style>
|
||||
) -> Usually<(Rect, Vec<Rect>)> {
|
||||
let Rect { mut x, y, width, height } = area;
|
||||
let mut h = 3u16;
|
||||
let mut frames = vec![];
|
||||
for (i, device) in state.devices.iter().enumerate() {
|
||||
let x2 = 0u16;
|
||||
let _y2 = 1u16;
|
||||
//for port in device.midi_ins()?.iter() {
|
||||
//port.blit(buf, x, y + y2, Some(Style::default()));
|
||||
//x2 = x2.max(port.len() as u16);
|
||||
//y2 = y2 + 1;
|
||||
//}
|
||||
//for port in device.audio_ins()?.iter() {
|
||||
//port.blit(buf, x, y + y2, Some(Style::default()));
|
||||
//x2 = x2.max(port.len() as u16);
|
||||
//y2 = y2 + 1;
|
||||
//}
|
||||
let width = width.saturating_sub(x).saturating_sub(x2);
|
||||
let frame = device.render(buf, Rect { x: x + x2, y, width, height })?;
|
||||
lozenge_left(buf, x + x2, y, frame.height, style);
|
||||
lozenge_right(buf, x + x2 + frame.width - 1, y, frame.height, style);
|
||||
//let mut y2 = 1u16;
|
||||
//for port in device.midi_outs()?.iter() {
|
||||
//port.blit(buf, x + x2 + frame.width, y + y2, Some(Style::default()));
|
||||
//x2 = x2.max(port.len() as u16);
|
||||
//y2 = y2 + 1;
|
||||
//}
|
||||
//for port in device.audio_outs()?.iter() {
|
||||
//port.blit(buf, x + x2 + frame.width, y + y2, Some(Style::default()));
|
||||
//x2 = x2.max(port.len() as u16);
|
||||
//y2 = y2 + 1;
|
||||
//}
|
||||
frames.push(frame);
|
||||
h = h.max(frame.height);
|
||||
x = x + frame.width;
|
||||
impl<'a> ChainView<'a> {
|
||||
pub fn draw_as_row (
|
||||
&self, buf: &mut Buffer, area: Rect, style: Option<Style>
|
||||
) -> Usually<(Rect, Vec<Rect>)> {
|
||||
let Rect { mut x, y, width, height } = area;
|
||||
let mut h = 3u16;
|
||||
let mut frames = vec![];
|
||||
let track = self.track.as_ref().unwrap();
|
||||
for (i, device) in track.devices.iter().enumerate() {
|
||||
let x2 = 0u16;
|
||||
let _y2 = 1u16;
|
||||
//for port in device.midi_ins()?.iter() {
|
||||
//port.blit(buf, x, y + y2, Some(Style::default()));
|
||||
//x2 = x2.max(port.len() as u16);
|
||||
//y2 = y2 + 1;
|
||||
//}
|
||||
//for port in device.audio_ins()?.iter() {
|
||||
//port.blit(buf, x, y + y2, Some(Style::default()));
|
||||
//x2 = x2.max(port.len() as u16);
|
||||
//y2 = y2 + 1;
|
||||
//}
|
||||
let width = width.saturating_sub(x).saturating_sub(x2);
|
||||
let frame = device.render(buf, Rect { x: x + x2, y, width, height })?;
|
||||
let style = if i == track.device {
|
||||
Some(if self.focused {
|
||||
Style::default().green().bold().not_dim()
|
||||
} else {
|
||||
Style::default().green().dim()
|
||||
})
|
||||
} else {
|
||||
style
|
||||
};
|
||||
lozenge_left(buf, x + x2, y, frame.height, style);
|
||||
lozenge_right(buf, x + x2 + frame.width - 1, y, frame.height, style);
|
||||
//let mut y2 = 1u16;
|
||||
//for port in device.midi_outs()?.iter() {
|
||||
//port.blit(buf, x + x2 + frame.width, y + y2, Some(Style::default()));
|
||||
//x2 = x2.max(port.len() as u16);
|
||||
//y2 = y2 + 1;
|
||||
//}
|
||||
//for port in device.audio_outs()?.iter() {
|
||||
//port.blit(buf, x + x2 + frame.width, y + y2, Some(Style::default()));
|
||||
//x2 = x2.max(port.len() as u16);
|
||||
//y2 = y2 + 1;
|
||||
//}
|
||||
frames.push(frame);
|
||||
h = h.max(frame.height);
|
||||
x = x + frame.width;
|
||||
}
|
||||
let label = "[Add device…]";
|
||||
label.blit(buf, x + 1, area.y + 1, Some(Style::default().dim()));
|
||||
x = x + 1 + label.len() as u16 + 1;
|
||||
Ok((Rect { x: area.x, y: area.y, width: x, height: h }, frames))
|
||||
}
|
||||
let label = "[Add device…]";
|
||||
label.blit(buf, x + 1, area.y + 1, Some(Style::default().dim()));
|
||||
x = x + 1 + label.len() as u16 + 1;
|
||||
Ok((Rect { x: area.x, y: area.y, width: x, height: h }, frames))
|
||||
|
||||
}
|
||||
|
||||
pub fn draw_as_column (
|
||||
|
|
|
|||
|
|
@ -17,6 +17,9 @@ pub struct SequencerView<'a> {
|
|||
pub time_start: usize,
|
||||
/// Position of cursor within time range
|
||||
pub time_cursor: usize,
|
||||
|
||||
/// Current time
|
||||
pub now: usize
|
||||
}
|
||||
|
||||
impl<'a> Render for SequencerView<'a> {
|
||||
|
|
@ -27,82 +30,70 @@ impl<'a> Render for SequencerView<'a> {
|
|||
lozenge_left(buf, x, y, height, style);
|
||||
lozenge_right(buf, x + width - 1, y, height, style);
|
||||
}
|
||||
self::horizontal::draw(
|
||||
buf,
|
||||
area,
|
||||
self.phrase,
|
||||
self.ppq,
|
||||
self.time_cursor,
|
||||
self.time_start,
|
||||
self.time_zoom,
|
||||
self.note_cursor,
|
||||
self.note_start,
|
||||
Some(if self.focused {
|
||||
Style::default().green().not_dim()
|
||||
} else {
|
||||
Style::default().green().dim()
|
||||
})
|
||||
)?;
|
||||
self.draw_horizontal(buf, area)?;
|
||||
Ok(area)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> SequencerView<'a> {
|
||||
fn draw_horizontal (&self, buf: &mut Buffer, area: Rect) -> Usually<()> {
|
||||
let style = Some(if self.focused {
|
||||
Style::default().green().not_dim()
|
||||
} else {
|
||||
Style::default().green().dim()
|
||||
});
|
||||
let notes = &[];
|
||||
pulse_to_note_length(self.time_zoom)
|
||||
.blit(buf, area.x, area.y, Some(Style::default().dim()));
|
||||
self::horizontal::keys(buf, area, self.note_start, notes)?;
|
||||
if let Some(phrase) = self.phrase {
|
||||
self::horizontal::timer(buf, area, self.time_start, self.time_zoom, self.now % phrase.length);
|
||||
self::horizontal::lanes(buf, area, phrase, self.ppq, self.time_zoom, self.time_start, self.note_start);
|
||||
}
|
||||
let style = style.unwrap_or_else(||{Style::default().green().not_dim()});
|
||||
self::horizontal::cursor(buf, area, style, self.time_cursor, self.note_cursor);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn pulse_to_note_length (time_z: usize) -> &'static str {
|
||||
match time_z {
|
||||
1 => "1/384",
|
||||
2 => "1/192",
|
||||
3 => "1/128",
|
||||
4 => "1/96",
|
||||
6 => "1/64",
|
||||
8 => "1/48",
|
||||
12 => "1/32",
|
||||
16 => "1/24",
|
||||
24 => "1/16",
|
||||
32 => "1/12",
|
||||
48 => "1/8",
|
||||
64 => "1/6",
|
||||
96 => "1/4",
|
||||
128 => "1/3",
|
||||
192 => "1/2",
|
||||
384 => "1/1",
|
||||
_ => ""
|
||||
}
|
||||
}
|
||||
|
||||
mod horizontal {
|
||||
use crate::core::*;
|
||||
use super::*;
|
||||
|
||||
pub fn draw (
|
||||
buf: &mut Buffer,
|
||||
area: Rect,
|
||||
phrase: Option<&Phrase>,
|
||||
ppq: usize,
|
||||
time: usize,
|
||||
time0: usize,
|
||||
time_z: usize,
|
||||
note: usize,
|
||||
note0: usize,
|
||||
style: Option<Style>,
|
||||
) -> Usually<Rect> {
|
||||
let now = 0;
|
||||
let notes = &[];
|
||||
match time_z {
|
||||
1 => "1/384",
|
||||
2 => "1/192",
|
||||
3 => "1/128",
|
||||
4 => "1/96",
|
||||
6 => "1/64",
|
||||
8 => "1/48",
|
||||
12 => "1/32",
|
||||
16 => "1/24",
|
||||
24 => "1/16",
|
||||
32 => "1/12",
|
||||
48 => "1/8",
|
||||
64 => "1/6",
|
||||
96 => "1/4",
|
||||
128 => "1/3",
|
||||
192 => "1/2",
|
||||
384 => "1/1",
|
||||
_ => ""
|
||||
}.blit(buf, area.x, area.y, Some(Style::default().dim()));
|
||||
keys(buf, area, note0, notes)?;
|
||||
timer(buf, area, time0, now);
|
||||
if let Some(phrase) = phrase {
|
||||
lanes(buf, area, phrase, ppq, time_z, time0, note0);
|
||||
}
|
||||
let style = style.unwrap_or_else(||{Style::default().green().not_dim()});
|
||||
cursor(buf, area, style, time, note);
|
||||
//footer(buf, area, note0, note, time0, time, time_z);
|
||||
Ok(area)
|
||||
}
|
||||
|
||||
pub fn timer (buf: &mut Buffer, area: Rect, time0: usize, now: usize) {
|
||||
let x = area.x + 5;
|
||||
for step in time0..(time0+area.width as usize).saturating_sub(5) {
|
||||
buf.set_string(x + step as u16, area.y, &"-", if step == now {
|
||||
pub fn timer (buf: &mut Buffer, area: Rect, time0: usize, time_z: usize, now: usize) {
|
||||
let Rect { x, width, .. } = area;
|
||||
let offset = 5;
|
||||
for x in x+offset..x+width-offset {
|
||||
let step = (time0 + (x-offset) as usize) * time_z;
|
||||
let next_step = (time0 + (x-offset) as usize + 1) * time_z;
|
||||
let style = if step <= now && now < next_step {
|
||||
Style::default().yellow().bold().not_dim()
|
||||
} else {
|
||||
Style::default()
|
||||
});
|
||||
};
|
||||
"-".blit(buf, x, area.y, Some(style))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -164,16 +155,19 @@ mod horizontal {
|
|||
for index in 0..height-2 {
|
||||
let note_a = note0 + index as usize * 2;
|
||||
let note_b = note0 + index as usize * 2 + 1;
|
||||
let (character, style) = match (
|
||||
let (character, mut style) = match (
|
||||
phrase.contains_note_on(u7::from_int_lossy(note_a as u8), a, b),
|
||||
phrase.contains_note_on(u7::from_int_lossy(note_b as u8), a, b),
|
||||
) {
|
||||
(true, true) => ("█", wh),
|
||||
(false, true) => ("▀", wh),
|
||||
(true, false) => ("▄", wh),
|
||||
(false, false) => ("·", bw),
|
||||
(false, false) => (if step % ppq == 0 { "|" } else { "·" }, bw),
|
||||
};
|
||||
let y = y + height.saturating_sub(index+2) as u16;
|
||||
if step > phrase.length {
|
||||
style = Style::default().gray()
|
||||
}
|
||||
character.blit(buf, x, y, Some(style));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue