mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
track init callback
This commit is contained in:
parent
163ecaaed6
commit
c7047327d5
2 changed files with 72 additions and 55 deletions
|
|
@ -51,7 +51,7 @@ const KEYMAP: &'static [KeyBinding<App>] = keymap!(App {
|
||||||
Ok(true)
|
Ok(true)
|
||||||
}],
|
}],
|
||||||
[Char('t'), CONTROL, "add_track", "add a new track", |app: &mut App| {
|
[Char('t'), CONTROL, "add_track", "add a new track", |app: &mut App| {
|
||||||
app.add_track(None)?;
|
app.add_track(None, None)?;
|
||||||
Ok(true)
|
Ok(true)
|
||||||
}],
|
}],
|
||||||
[Char('`'), NONE, "switch_mode", "switch the display mode", |app: &mut App| {
|
[Char('`'), NONE, "switch_mode", "switch the display mode", |app: &mut App| {
|
||||||
|
|
|
||||||
55
src/main.rs
55
src/main.rs
|
|
@ -40,48 +40,50 @@ pub fn main () -> Usually<()> {
|
||||||
state.scene_cursor = 1;
|
state.scene_cursor = 1;
|
||||||
state.note_start = 12;
|
state.note_start = 12;
|
||||||
state.time_zoom = 12;
|
state.time_zoom = 12;
|
||||||
state.midi_in = Some(client.register_port("midi-in", MidiIn)?);
|
|
||||||
state.transport = Some(client.transport());
|
state.transport = Some(client.transport());
|
||||||
state.playing = Some(TransportState::Stopped);
|
state.playing = Some(TransportState::Stopped);
|
||||||
|
state.midi_in = Some(client.register_port("midi-in", MidiIn)?);
|
||||||
state.jack = Some(jack);
|
state.jack = Some(jack);
|
||||||
|
|
||||||
let drums = state.add_track(Some("Drums"))?;
|
state.add_track(Some("Drums"), Some(Box::new(move|client, track|{
|
||||||
drums.add_device(Sampler::new("Sampler", Some(BTreeMap::from([
|
track.add_device(Sampler::new("Sampler", Some(BTreeMap::from([
|
||||||
sample!(36, "Kick", "/home/user/Lab/Music/pak/kik.wav"),
|
sample!(36, "Kick", "/home/user/Lab/Music/pak/kik.wav"),
|
||||||
sample!(40, "Snare", "/home/user/Lab/Music/pak/sna.wav"),
|
sample!(40, "Snare", "/home/user/Lab/Music/pak/sna.wav"),
|
||||||
sample!(44, "Hihat", "/home/user/Lab/Music/pak/chh.wav"),
|
sample!(44, "Hihat", "/home/user/Lab/Music/pak/chh.wav"),
|
||||||
])))?);
|
])))?);
|
||||||
drums.add_device(Plugin::lv2(
|
track.add_device(Plugin::lv2(
|
||||||
"Panagement",
|
"Panagement",
|
||||||
"file:///home/user/.lv2/Auburn Sounds Panagement 2.lv2"
|
"file:///home/user/.lv2/Auburn Sounds Panagement 2.lv2"
|
||||||
)?);
|
)?);
|
||||||
|
client.connect_ports(&track.midi_out, &track.devices[0].midi_ins()?[0])?;
|
||||||
drums.add_phrase("4 kicks", ppq * 4, Some(phrase! {
|
track.sequence = Some(1); // FIXME
|
||||||
|
track.add_phrase("4 kicks", ppq * 4, Some(phrase! {
|
||||||
00 * ppq/4 => MidiMessage::NoteOn { key: 36.into(), vel: 100.into() },
|
00 * ppq/4 => MidiMessage::NoteOn { key: 36.into(), vel: 100.into() },
|
||||||
04 * ppq/4 => MidiMessage::NoteOn { key: 36.into(), vel: 100.into() },
|
04 * ppq/4 => MidiMessage::NoteOn { key: 36.into(), vel: 100.into() },
|
||||||
08 * ppq/4 => MidiMessage::NoteOn { key: 36.into(), vel: 100.into() },
|
08 * ppq/4 => MidiMessage::NoteOn { key: 36.into(), vel: 100.into() },
|
||||||
12 * ppq/4 => MidiMessage::NoteOn { key: 36.into(), vel: 100.into() },
|
12 * ppq/4 => MidiMessage::NoteOn { key: 36.into(), vel: 100.into() },
|
||||||
}));
|
}));
|
||||||
drums.add_phrase("D-Beat", ppq * 4, Some(phrase! {
|
track.add_phrase("D-Beat", ppq * 4, Some(phrase! {
|
||||||
00 * ppq/4 => MidiMessage::NoteOn { key: 36.into(), vel: 100.into() },
|
00 * ppq/4 => MidiMessage::NoteOn { key: 36.into(), vel: 100.into() },
|
||||||
04 * ppq/4 => MidiMessage::NoteOn { key: 40.into(), vel: 100.into() },
|
04 * ppq/4 => MidiMessage::NoteOn { key: 40.into(), vel: 100.into() },
|
||||||
08 * ppq/4 => MidiMessage::NoteOn { key: 36.into(), vel: 100.into() },
|
08 * ppq/4 => MidiMessage::NoteOn { key: 36.into(), vel: 100.into() },
|
||||||
10 * ppq/4 => MidiMessage::NoteOn { key: 36.into(), vel: 100.into() },
|
10 * ppq/4 => MidiMessage::NoteOn { key: 36.into(), vel: 100.into() },
|
||||||
12 * ppq/4 => MidiMessage::NoteOn { key: 40.into(), vel: 100.into() },
|
12 * ppq/4 => MidiMessage::NoteOn { key: 40.into(), vel: 100.into() },
|
||||||
}));
|
}));
|
||||||
drums.add_phrase("Garage", ppq * 4, Some(phrase! {
|
track.add_phrase("Garage", ppq * 4, Some(phrase! {
|
||||||
00 * ppq/4 => MidiMessage::NoteOn { key: 36.into(), vel: 100.into() },
|
00 * ppq/4 => MidiMessage::NoteOn { key: 36.into(), vel: 100.into() },
|
||||||
04 * ppq/4 => MidiMessage::NoteOn { key: 40.into(), vel: 100.into() },
|
04 * ppq/4 => MidiMessage::NoteOn { key: 40.into(), vel: 100.into() },
|
||||||
11 * ppq/4 => MidiMessage::NoteOn { key: 36.into(), vel: 100.into() },
|
11 * ppq/4 => MidiMessage::NoteOn { key: 36.into(), vel: 100.into() },
|
||||||
12 * ppq/4 => MidiMessage::NoteOn { key: 40.into(), vel: 100.into() },
|
12 * ppq/4 => MidiMessage::NoteOn { key: 40.into(), vel: 100.into() },
|
||||||
}));
|
}));
|
||||||
|
Ok(())
|
||||||
|
})))?;
|
||||||
|
|
||||||
// FIXME:
|
state.add_track(Some("Bass"), Some(Box::new(move|client, track|{
|
||||||
drums.sequence = Some(1);
|
track.add_device(Plugin::lv2("Odin2", "file:///home/user/.lv2/Odin2.lv2")?);
|
||||||
|
//client.connect_ports(&track.midi_out, &track.devices[0].midi_ins()?[0])?;
|
||||||
let bass = state.add_track(Some("Bass"))?;
|
track.sequence = Some(0); // FIXME
|
||||||
bass.add_device(Plugin::lv2("Odin2", "file:///home/user/.lv2/Odin2.lv2")?);
|
track.add_phrase("Offbeat", ppq * 4, Some(phrase! {
|
||||||
bass.add_phrase("Offbeat", ppq * 4, Some(phrase! {
|
|
||||||
00 * ppq/4 => MidiMessage::NoteOff { key: 40.into(), vel: 100.into() },
|
00 * ppq/4 => MidiMessage::NoteOff { key: 40.into(), vel: 100.into() },
|
||||||
02 * ppq/4 => MidiMessage::NoteOn { key: 40.into(), vel: 100.into() },
|
02 * ppq/4 => MidiMessage::NoteOn { key: 40.into(), vel: 100.into() },
|
||||||
04 * ppq/4 => MidiMessage::NoteOff { key: 40.into(), vel: 100.into() },
|
04 * ppq/4 => MidiMessage::NoteOff { key: 40.into(), vel: 100.into() },
|
||||||
|
|
@ -91,9 +93,8 @@ pub fn main () -> Usually<()> {
|
||||||
12 * ppq/4 => MidiMessage::NoteOff { key: 40.into(), vel: 100.into() },
|
12 * ppq/4 => MidiMessage::NoteOff { key: 40.into(), vel: 100.into() },
|
||||||
14 * ppq/4 => MidiMessage::NoteOn { key: 40.into(), vel: 100.into() },
|
14 * ppq/4 => MidiMessage::NoteOn { key: 40.into(), vel: 100.into() },
|
||||||
}));
|
}));
|
||||||
|
Ok(())
|
||||||
// FIXME:
|
})))?;
|
||||||
bass.sequence = Some(0);
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}))
|
}))
|
||||||
|
|
@ -174,6 +175,14 @@ process!(App |self, _client, scope| {
|
||||||
Control::Continue
|
Control::Continue
|
||||||
});
|
});
|
||||||
impl App {
|
impl App {
|
||||||
|
pub fn client (&self) -> &Client {
|
||||||
|
self.jack.as_ref().unwrap().as_client()
|
||||||
|
}
|
||||||
|
pub fn connect_ports <A: ::_jack::PortSpec, B: ::_jack::PortSpec> (
|
||||||
|
&self, a: &Port<A>, b: &Port<B>
|
||||||
|
) -> Usually<()> {
|
||||||
|
Ok(self.client().connect_ports(a, b)?)
|
||||||
|
}
|
||||||
pub fn toggle_play (&mut self) -> Usually<()> {
|
pub fn toggle_play (&mut self) -> Usually<()> {
|
||||||
self.playing = match self.playing.expect("after jack init") {
|
self.playing = match self.playing.expect("after jack init") {
|
||||||
TransportState::Stopped => {
|
TransportState::Stopped => {
|
||||||
|
|
@ -194,9 +203,17 @@ impl App {
|
||||||
self.scene_cursor = self.scenes.len();
|
self.scene_cursor = self.scenes.len();
|
||||||
Ok(&mut self.scenes[self.scene_cursor - 1])
|
Ok(&mut self.scenes[self.scene_cursor - 1])
|
||||||
}
|
}
|
||||||
pub fn add_track (&mut self, name: Option<&str>) -> Usually<&mut Track> {
|
pub fn add_track (
|
||||||
|
&mut self,
|
||||||
|
name: Option<&str>,
|
||||||
|
init: Option<Box<dyn FnOnce(&Client, &mut Track)->Usually<()>>>,
|
||||||
|
) -> Usually<&mut Track> {
|
||||||
let name = name.ok_or_else(||format!("Track {}", self.tracks.len() + 1))?;
|
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)?);
|
let mut track = Track::new(&name, self.client(), None, None)?;
|
||||||
|
if let Some(init) = init {
|
||||||
|
init(self.client(), &mut track)?;
|
||||||
|
}
|
||||||
|
self.tracks.push(track);
|
||||||
self.track_cursor = self.tracks.len();
|
self.track_cursor = self.tracks.len();
|
||||||
Ok(&mut self.tracks[self.track_cursor - 1])
|
Ok(&mut self.tracks[self.track_cursor - 1])
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue