mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-08 12:46:42 +01:00
wip: optional dependency from mixer to sampler and plugin
This commit is contained in:
parent
a819e042c7
commit
6dd4caeb42
18 changed files with 330 additions and 316 deletions
|
|
@ -1,5 +1,4 @@
|
|||
use super::*;
|
||||
|
||||
use ::livi::{
|
||||
World,
|
||||
Instance,
|
||||
|
|
@ -9,33 +8,7 @@ use ::livi::{
|
|||
Port,
|
||||
event::LV2AtomSequence,
|
||||
};
|
||||
|
||||
use ::winit::{
|
||||
application::ApplicationHandler,
|
||||
event::WindowEvent,
|
||||
event_loop::{ActiveEventLoop, ControlFlow, EventLoop},
|
||||
window::{Window, WindowId},
|
||||
platform::x11::EventLoopBuilderExtX11
|
||||
};
|
||||
|
||||
use ::suil_rs::{self};
|
||||
|
||||
use std::thread::{spawn, JoinHandle};
|
||||
|
||||
impl Plugin {
|
||||
pub fn lv2 (name: &str, path: &str) -> Usually<JackDevice> {
|
||||
let plugin = LV2Plugin::new(path)?;
|
||||
jack_from_lv2(name, &plugin.plugin)?
|
||||
.run(|ports|Box::new(Self {
|
||||
name: name.into(),
|
||||
path: Some(String::from(path)),
|
||||
plugin: Some(PluginKind::LV2(plugin)),
|
||||
selected: 0,
|
||||
mapping: false,
|
||||
ports
|
||||
}))
|
||||
}
|
||||
}
|
||||
use std::thread::JoinHandle;
|
||||
|
||||
/// A LV2 plugin.
|
||||
pub struct LV2Plugin {
|
||||
|
|
@ -49,6 +22,22 @@ pub struct LV2Plugin {
|
|||
}
|
||||
|
||||
impl LV2Plugin {
|
||||
pub fn from_edn <'e> (args: &[Edn<'e>]) -> Usually<JackDevice> {
|
||||
let mut name = String::new();
|
||||
let mut path = String::new();
|
||||
edn!(edn in args {
|
||||
Edn::Map(map) => {
|
||||
if let Some(Edn::Str(n)) = map.get(&Edn::Key(":name")) {
|
||||
name = String::from(*n);
|
||||
}
|
||||
if let Some(Edn::Str(p)) = map.get(&Edn::Key(":path")) {
|
||||
path = String::from(*p);
|
||||
}
|
||||
},
|
||||
_ => panic!("unexpected in lv2 '{name}'"),
|
||||
});
|
||||
Plugin::new_lv2(&name, &path)
|
||||
}
|
||||
pub fn new (uri: &str) -> Usually<Self> {
|
||||
// Get 1st plugin at URI
|
||||
let world = World::with_load_bundle(&uri);
|
||||
|
|
@ -84,62 +73,3 @@ impl LV2Plugin {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run_lv2_ui (mut ui: LV2PluginUI) -> Usually<JoinHandle<()>> {
|
||||
Ok(spawn(move||{
|
||||
let event_loop = EventLoop::builder().with_x11().with_any_thread(true).build().unwrap();
|
||||
event_loop.set_control_flow(ControlFlow::Wait);
|
||||
event_loop.run_app(&mut ui).unwrap()
|
||||
}))
|
||||
}
|
||||
|
||||
/// A LV2 plugin's X11 UI.
|
||||
pub struct LV2PluginUI {
|
||||
pub window: Option<Window>
|
||||
}
|
||||
|
||||
impl LV2PluginUI {
|
||||
pub fn new () -> Usually<Self> {
|
||||
Ok(Self { window: None })
|
||||
}
|
||||
}
|
||||
|
||||
impl ApplicationHandler for LV2PluginUI {
|
||||
fn resumed (&mut self, event_loop: &ActiveEventLoop) {
|
||||
self.window = Some(event_loop.create_window(Window::default_attributes()).unwrap());
|
||||
}
|
||||
fn window_event (&mut self, event_loop: &ActiveEventLoop, id: WindowId, event: WindowEvent) {
|
||||
match event {
|
||||
WindowEvent::CloseRequested => {
|
||||
self.window.as_ref().unwrap().set_visible(false);
|
||||
event_loop.exit();
|
||||
},
|
||||
WindowEvent::RedrawRequested => {
|
||||
self.window.as_ref().unwrap().request_redraw();
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn lv2_ui_instantiate (kind: &str) {
|
||||
//let host = Suil
|
||||
}
|
||||
|
||||
pub fn jack_from_lv2 (name: &str, plugin: &::livi::Plugin) -> Usually<Jack> {
|
||||
let counts = plugin.port_counts();
|
||||
let mut jack = Jack::new(name)?;
|
||||
for i in 0..counts.atom_sequence_inputs {
|
||||
jack = jack.midi_in(&format!("midi-in-{i}"))
|
||||
}
|
||||
for i in 0..counts.atom_sequence_outputs {
|
||||
jack = jack.midi_out(&format!("midi-out-{i}"));
|
||||
}
|
||||
for i in 0..counts.audio_inputs {
|
||||
jack = jack.audio_in(&format!("audio-in-{i}"));
|
||||
}
|
||||
for i in 0..counts.audio_outputs {
|
||||
jack = jack.audio_out(&format!("audio-out-{i}"));
|
||||
}
|
||||
Ok(jack)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +0,0 @@
|
|||
use crate::*;
|
||||
impl LV2Plugin {
|
||||
fn load_edn <'e> (args: &[Edn<'e>]) -> Usually<JackDevice> {
|
||||
let mut name = String::new();
|
||||
let mut path = String::new();
|
||||
edn!(edn in args {
|
||||
Edn::Map(map) => {
|
||||
if let Some(Edn::Str(n)) = map.get(&Edn::Key(":name")) {
|
||||
name = String::from(*n);
|
||||
}
|
||||
if let Some(Edn::Str(p)) = map.get(&Edn::Key(":path")) {
|
||||
path = String::from(*p);
|
||||
}
|
||||
},
|
||||
_ => panic!("unexpected in lv2 '{name}'"),
|
||||
});
|
||||
Plugin::lv2(&name, &path)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,4 +1,12 @@
|
|||
|
||||
use crate::*;
|
||||
use std::thread::{spawn, JoinHandle};
|
||||
use ::winit::{
|
||||
application::ApplicationHandler,
|
||||
event::WindowEvent,
|
||||
event_loop::{ActiveEventLoop, ControlFlow, EventLoop},
|
||||
window::{Window, WindowId},
|
||||
platform::x11::EventLoopBuilderExtX11
|
||||
};
|
||||
|
||||
//pub struct LV2PluginUI {
|
||||
//write: (),
|
||||
|
|
@ -7,3 +15,62 @@
|
|||
//features: (),
|
||||
//transfer: (),
|
||||
//}
|
||||
|
||||
pub fn run_lv2_ui (mut ui: LV2PluginUI) -> Usually<JoinHandle<()>> {
|
||||
Ok(spawn(move||{
|
||||
let event_loop = EventLoop::builder().with_x11().with_any_thread(true).build().unwrap();
|
||||
event_loop.set_control_flow(ControlFlow::Wait);
|
||||
event_loop.run_app(&mut ui).unwrap()
|
||||
}))
|
||||
}
|
||||
|
||||
/// A LV2 plugin's X11 UI.
|
||||
pub struct LV2PluginUI {
|
||||
pub window: Option<Window>
|
||||
}
|
||||
|
||||
impl LV2PluginUI {
|
||||
pub fn new () -> Usually<Self> {
|
||||
Ok(Self { window: None })
|
||||
}
|
||||
}
|
||||
|
||||
impl ApplicationHandler for LV2PluginUI {
|
||||
fn resumed (&mut self, event_loop: &ActiveEventLoop) {
|
||||
self.window = Some(event_loop.create_window(Window::default_attributes()).unwrap());
|
||||
}
|
||||
fn window_event (&mut self, event_loop: &ActiveEventLoop, id: WindowId, event: WindowEvent) {
|
||||
match event {
|
||||
WindowEvent::CloseRequested => {
|
||||
self.window.as_ref().unwrap().set_visible(false);
|
||||
event_loop.exit();
|
||||
},
|
||||
WindowEvent::RedrawRequested => {
|
||||
self.window.as_ref().unwrap().request_redraw();
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn lv2_ui_instantiate (kind: &str) {
|
||||
//let host = Suil
|
||||
}
|
||||
|
||||
pub fn jack_from_lv2 (name: &str, plugin: &::livi::Plugin) -> Usually<Jack> {
|
||||
let counts = plugin.port_counts();
|
||||
let mut jack = Jack::new(name)?;
|
||||
for i in 0..counts.atom_sequence_inputs {
|
||||
jack = jack.midi_in(&format!("midi-in-{i}"))
|
||||
}
|
||||
for i in 0..counts.atom_sequence_outputs {
|
||||
jack = jack.midi_out(&format!("midi-out-{i}"));
|
||||
}
|
||||
for i in 0..counts.audio_inputs {
|
||||
jack = jack.audio_in(&format!("audio-in-{i}"));
|
||||
}
|
||||
for i in 0..counts.audio_outputs {
|
||||
jack = jack.audio_out(&format!("audio-out-{i}"));
|
||||
}
|
||||
Ok(jack)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,18 @@ pub enum PluginKind {
|
|||
}
|
||||
|
||||
impl Plugin {
|
||||
pub fn new_lv2 (name: &str, path: &str) -> Usually<JackDevice> {
|
||||
let plugin = LV2Plugin::new(path)?;
|
||||
jack_from_lv2(name, &plugin.plugin)?
|
||||
.run(|ports|Box::new(Self {
|
||||
name: name.into(),
|
||||
path: Some(String::from(path)),
|
||||
plugin: Some(PluginKind::LV2(plugin)),
|
||||
selected: 0,
|
||||
mapping: false,
|
||||
ports
|
||||
}))
|
||||
}
|
||||
/// Create a plugin host device.
|
||||
pub fn new (name: &str) -> Usually<Self> {
|
||||
Ok(Self {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue