mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
76 lines
2.1 KiB
Rust
76 lines
2.1 KiB
Rust
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: (),
|
|
//controller: (),
|
|
//widget: (),
|
|
//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)
|
|
}
|