mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-08 04:36:45 +01:00
wip: long awaited fixes to main sequencer
This commit is contained in:
parent
2837ffff4a
commit
78e5469b32
17 changed files with 391 additions and 563 deletions
|
|
@ -1,6 +1,6 @@
|
|||
use crate::core::*;
|
||||
|
||||
mod lv2;
|
||||
mod lv2; pub use lv2::*;
|
||||
mod vst2;
|
||||
mod vst3;
|
||||
|
||||
|
|
@ -8,7 +8,6 @@ pub struct Plugin {
|
|||
name: String,
|
||||
path: Option<String>,
|
||||
plugin: Option<PluginKind>,
|
||||
offset: usize,
|
||||
selected: usize,
|
||||
mapping: bool,
|
||||
midi_ins: Vec<Port<MidiIn>>,
|
||||
|
|
@ -18,12 +17,7 @@ pub struct Plugin {
|
|||
}
|
||||
|
||||
enum PluginKind {
|
||||
LV2 {
|
||||
world: ::livi::World,
|
||||
features: Arc<::livi::Features>,
|
||||
port_list: Vec<::livi::Port>,
|
||||
instance: ::livi::Instance,
|
||||
},
|
||||
LV2(LV2Plugin),
|
||||
VST2 {
|
||||
instance: ::vst::host::PluginInstance
|
||||
},
|
||||
|
|
@ -34,57 +28,66 @@ const HELM: &'static str = "file:///nix/store/ij3sz7nqg5l7v2dygdvzy3w6cj62bd6r-h
|
|||
|
||||
impl Plugin {
|
||||
/// Load a LV2 plugin.
|
||||
pub fn lv2 (name: &str, path: &str, ports: &[usize;4]) -> Usually<DynamicDevice<Self>> {
|
||||
let plugin = Self::new(name, ports)?;
|
||||
let mut state = plugin.state();
|
||||
state.plugin = Some(self::lv2::plug(path)?);
|
||||
pub fn lv2 (name: &str, path: &str) -> Usually<DynamicDevice<Self>> {
|
||||
let host = Self::new(name)?;
|
||||
let plugin = LV2Plugin::new(path)?;
|
||||
let mut state = host.state();
|
||||
let client = host.client.as_ref().unwrap().as_client();
|
||||
let (midi_ins, midi_outs, audio_ins, audio_outs) = (
|
||||
plugin.plugin.port_counts().atom_sequence_inputs,
|
||||
plugin.plugin.port_counts().atom_sequence_outputs,
|
||||
plugin.plugin.port_counts().audio_inputs,
|
||||
plugin.plugin.port_counts().audio_outputs,
|
||||
);
|
||||
state.midi_ins = {
|
||||
let mut ports = vec![];
|
||||
for i in 0..midi_ins {
|
||||
ports.push(client.register_port(&format!("midi-in-{i}"), MidiIn::default())?)
|
||||
}
|
||||
ports
|
||||
};
|
||||
state.midi_outs = {
|
||||
let mut ports = vec![];
|
||||
for i in 0..midi_outs {
|
||||
ports.push(client.register_port(&format!("midi-out-{i}"), MidiOut::default())?)
|
||||
}
|
||||
ports
|
||||
};
|
||||
state.audio_ins = {
|
||||
let mut ports = vec![];
|
||||
for i in 0..audio_ins {
|
||||
ports.push(client.register_port(&format!("audio-in-{i}"), AudioIn::default())?)
|
||||
}
|
||||
ports
|
||||
};
|
||||
state.audio_outs = {
|
||||
let mut ports = vec![];
|
||||
for i in 0..audio_outs {
|
||||
ports.push(client.register_port(&format!("audio-out-{i}"), AudioOut::default())?)
|
||||
}
|
||||
ports
|
||||
};
|
||||
state.plugin = Some(PluginKind::LV2(plugin));
|
||||
state.path = Some(String::from(path));
|
||||
std::mem::drop(state);
|
||||
Ok(plugin)
|
||||
Ok(host)
|
||||
}
|
||||
pub fn new (name: &str, ports: &[usize;4]) -> Usually<DynamicDevice<Self>> {
|
||||
let (client, _status) = Client::new(name, ClientOptions::NO_START_SERVER)?;
|
||||
let [midi_ins, midi_outs, audio_ins, audio_outs] = ports;
|
||||
pub fn new (name: &str) -> Usually<DynamicDevice<Self>> {
|
||||
DynamicDevice::new(render, handle, Self::process, Self {
|
||||
name: name.into(),
|
||||
path: None,
|
||||
plugin: None,
|
||||
offset: 0,
|
||||
selected: 0,
|
||||
mapping: false,
|
||||
midi_ins: {
|
||||
let mut ports = vec![];
|
||||
for i in 0..*midi_ins {
|
||||
ports.push(client.register_port(&format!("midi-in-{i}"), MidiIn::default())?)
|
||||
}
|
||||
ports
|
||||
},
|
||||
midi_outs: {
|
||||
let mut ports = vec![];
|
||||
for i in 0..*midi_outs {
|
||||
ports.push(client.register_port(&format!("midi-out-{i}"), MidiOut::default())?)
|
||||
}
|
||||
ports
|
||||
},
|
||||
audio_ins: {
|
||||
let mut ports = vec![];
|
||||
for i in 0..*audio_ins {
|
||||
ports.push(client.register_port(&format!("audio-in-{i}"), AudioIn::default())?)
|
||||
}
|
||||
ports
|
||||
},
|
||||
audio_outs: {
|
||||
let mut ports = vec![];
|
||||
for i in 0..*audio_outs {
|
||||
ports.push(client.register_port(&format!("audio-out-{i}"), AudioOut::default())?)
|
||||
}
|
||||
ports
|
||||
},
|
||||
}).activate(client)
|
||||
name: name.into(),
|
||||
path: None,
|
||||
plugin: None,
|
||||
selected: 0,
|
||||
mapping: false,
|
||||
midi_ins: vec![],
|
||||
midi_outs: vec![],
|
||||
audio_ins: vec![],
|
||||
audio_outs: vec![],
|
||||
}).activate(Client::new(name, ClientOptions::NO_START_SERVER)?.0)
|
||||
}
|
||||
pub fn process (&mut self, _: &Client, scope: &ProcessScope) -> Control {
|
||||
match self.plugin.as_mut() {
|
||||
Some(PluginKind::LV2 { features, ref mut instance, .. }) => {
|
||||
Some(PluginKind::LV2(LV2Plugin { features, ref mut instance, .. })) => {
|
||||
let urid = features.midi_urid();
|
||||
let mut inputs = vec![];
|
||||
for port in self.midi_ins.iter() {
|
||||
|
|
@ -171,7 +174,7 @@ pub fn render (state: &Plugin, buf: &mut Buffer, area: Rect)
|
|||
let Rect { x, y, height, .. } = area;
|
||||
let mut width = 40u16;
|
||||
match &state.plugin {
|
||||
Some(PluginKind::LV2 { port_list, instance, .. }) => {
|
||||
Some(PluginKind::LV2(LV2Plugin { port_list, instance, .. })) => {
|
||||
let start = state.selected.saturating_sub((height as usize / 2).saturating_sub(1));
|
||||
let end = start + height as usize - 2;
|
||||
//draw_box(buf, Rect { x, y, width, height });
|
||||
|
|
@ -218,7 +221,7 @@ pub fn handle (s: &mut Plugin, event: &AppEvent) -> Usually<bool> {
|
|||
s.selected = s.selected - 1
|
||||
} else {
|
||||
s.selected = match &s.plugin {
|
||||
Some(PluginKind::LV2 { port_list, .. }) => port_list.len() - 1,
|
||||
Some(PluginKind::LV2(LV2Plugin { port_list, .. })) => port_list.len() - 1,
|
||||
_ => 0
|
||||
}
|
||||
}
|
||||
|
|
@ -229,7 +232,7 @@ pub fn handle (s: &mut Plugin, event: &AppEvent) -> Usually<bool> {
|
|||
|s: &mut Plugin|{
|
||||
s.selected = s.selected + 1;
|
||||
match &s.plugin {
|
||||
Some(PluginKind::LV2 { port_list, .. }) => {
|
||||
Some(PluginKind::LV2(LV2Plugin { port_list, .. })) => {
|
||||
if s.selected >= port_list.len() {
|
||||
s.selected = 0;
|
||||
}
|
||||
|
|
@ -242,7 +245,7 @@ pub fn handle (s: &mut Plugin, event: &AppEvent) -> Usually<bool> {
|
|||
[Char(','), NONE, "decrement", "decrement value",
|
||||
|s: &mut Plugin|{
|
||||
match s.plugin.as_mut() {
|
||||
Some(PluginKind::LV2 { port_list, ref mut instance, .. }) => {
|
||||
Some(PluginKind::LV2(LV2Plugin { port_list, ref mut instance, .. })) => {
|
||||
let index = port_list[s.selected].index;
|
||||
if let Some(value) = instance.control_input(index) {
|
||||
instance.set_control_input(index, value - 0.01);
|
||||
|
|
@ -256,7 +259,7 @@ pub fn handle (s: &mut Plugin, event: &AppEvent) -> Usually<bool> {
|
|||
[Char('.'), NONE, "increment", "increment value",
|
||||
|s: &mut Plugin|{
|
||||
match s.plugin.as_mut() {
|
||||
Some(PluginKind::LV2 { port_list, ref mut instance, .. }) => {
|
||||
Some(PluginKind::LV2(LV2Plugin { port_list, ref mut instance, .. })) => {
|
||||
let index = port_list[s.selected].index;
|
||||
if let Some(value) = instance.control_input(index) {
|
||||
instance.set_control_input(index, value + 0.01);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue