mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
flatten workspace into 1 crate
This commit is contained in:
parent
7c4e1e2166
commit
d926422c67
147 changed files with 66 additions and 126 deletions
5
suil/src/bound.rs
Normal file
5
suil/src/bound.rs
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#![allow(non_upper_case_globals)]
|
||||
#![allow(non_camel_case_types)]
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
|
||||
37
suil/src/gtk.rs
Normal file
37
suil/src/gtk.rs
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
struct SuilX11Wrapper {
|
||||
socket: GtkSocket,
|
||||
plug: GtkPlug,
|
||||
wrapper: SuilWrapper,
|
||||
instance: SuilInstance,
|
||||
idle_iface: LV2UI_Idle_Interface,
|
||||
idle_id: usize,
|
||||
idle_ms: usize,
|
||||
idle_size_req_id: usize,
|
||||
initial_width: usize,
|
||||
initial_height: usize,
|
||||
req_width: usize,
|
||||
req_height: usize,
|
||||
}
|
||||
|
||||
struct SuilX11WrapperClass {
|
||||
parent_class: GtkSocketClass,
|
||||
}
|
||||
|
||||
impl SuilX11Wrapper {
|
||||
fn x_window_is_valid (&self) {
|
||||
let window: GdkWindow = gtk_widget_get_window(self.plug);
|
||||
let root: X11Window = Some(0);
|
||||
let parent: X11Window = Some(0);
|
||||
let children: [X11Window] = None;
|
||||
let child_count: usize = 0;
|
||||
x_query_tree(window.xdisplay, window.xid, root, parent, children, &mut childcount);
|
||||
for i in 0..child_count {
|
||||
if children[i] == self.instance.ui_widget {
|
||||
x_free(children);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
x_free(children);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
113
suil/src/lib.rs
Normal file
113
suil/src/lib.rs
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
use std::ffi::{CString, c_void};
|
||||
|
||||
pub mod bound;
|
||||
#[cfg(test)] mod test;
|
||||
|
||||
pub struct Host(*mut self::bound::SuilHost);
|
||||
|
||||
impl Drop for Host {
|
||||
fn drop (&mut self) {
|
||||
unsafe {
|
||||
bound::suil_host_free(self.0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Host {
|
||||
pub fn new () -> Self {
|
||||
Self(unsafe {
|
||||
let mut argv = [];
|
||||
bound::suil_init(
|
||||
&mut 0,
|
||||
&mut argv as *mut *mut *mut i8,
|
||||
0
|
||||
);
|
||||
bound::suil_host_new(
|
||||
Some(write),
|
||||
Some(index),
|
||||
None,
|
||||
None,
|
||||
)
|
||||
})
|
||||
}
|
||||
fn set_touch_func (&self) {
|
||||
unimplemented!();
|
||||
}
|
||||
fn instance <T> (
|
||||
&self,
|
||||
controller: &mut T,
|
||||
container_type_uri: &str,
|
||||
plugin_uri: &str,
|
||||
ui_uri: &str,
|
||||
ui_type_uri: &str,
|
||||
ui_bundle_path: &str,
|
||||
ui_binary_path: &str,
|
||||
features: &[*const bound::LV2_Feature],
|
||||
) -> Result<Instance, Box<dyn std::error::Error>> {
|
||||
let container_type_uri = CString::new(container_type_uri)?;
|
||||
let plugin_uri = CString::new(plugin_uri)?;
|
||||
let ui_uri = CString::new(ui_uri)?;
|
||||
let ui_type_uri = CString::new(ui_type_uri)?;
|
||||
let ui_bundle_path = CString::new(ui_bundle_path)?;
|
||||
let ui_binary_path = CString::new(ui_binary_path)?;
|
||||
Ok(Instance(unsafe {
|
||||
bound::suil_instance_new(
|
||||
self.0,
|
||||
controller as *mut _ as *mut std::ffi::c_void,
|
||||
container_type_uri.into_raw(),
|
||||
plugin_uri.into_raw(),
|
||||
ui_uri.into_raw(),
|
||||
ui_type_uri.into_raw(),
|
||||
ui_bundle_path.into_raw(),
|
||||
ui_binary_path.into_raw(),
|
||||
std::ptr::null_mut(),
|
||||
)
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
unsafe extern "C" fn write (
|
||||
_controller: *mut c_void, _: u32, _: u32, _: u32, _: *const c_void
|
||||
) {
|
||||
panic!("write")
|
||||
}
|
||||
|
||||
unsafe extern "C" fn index (
|
||||
_controller: *mut c_void, _: *const i8
|
||||
) -> u32 {
|
||||
0
|
||||
}
|
||||
|
||||
//unsafe extern "C" fn subscribe (
|
||||
//_: *mut c_void, _: u32, _: u32, _: *const *const bound::LV2_Feature
|
||||
//) -> u32 {
|
||||
//panic!("subscribe");
|
||||
//0
|
||||
//}
|
||||
|
||||
//unsafe extern "C" fn unsubscribe (
|
||||
//_: *mut c_void, _: u32, _: u32, _: *const *const bound::LV2_Feature
|
||||
//) -> u32 {
|
||||
//panic!("unsubscribe");
|
||||
//0
|
||||
//}
|
||||
|
||||
pub struct Instance(*mut self::bound::SuilInstance);
|
||||
|
||||
impl Drop for Instance {
|
||||
fn drop (&mut self) -> () {
|
||||
unsafe {
|
||||
bound::suil_instance_free(self.0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Send for Instance {}
|
||||
|
||||
unsafe impl Sync for Instance {}
|
||||
|
||||
impl Instance {
|
||||
fn get_widget (&self) -> *mut c_void {
|
||||
unsafe { bound::suil_instance_get_widget(self.0) }
|
||||
}
|
||||
}
|
||||
173
suil/src/test.rs
Normal file
173
suil/src/test.rs
Normal file
|
|
@ -0,0 +1,173 @@
|
|||
use crate::*;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[test]
|
||||
fn test_lv2_ui () {
|
||||
let mut features = [];
|
||||
std::mem::forget(features);
|
||||
//gtk::init().unwrap();
|
||||
use gtk::prelude::{ApplicationExt, ApplicationExtManual};
|
||||
let app = gtk::Application::builder().application_id("lol.tek").build();
|
||||
app.connect_activate(move |app| {
|
||||
let host = Host::new();
|
||||
let mut plugin = plugin::LV2Plugin::new("file:///home/user/.lv2/Odin2.lv2").unwrap();
|
||||
//let mut plugin = plugin::LV2Plugin::new("file:///home/user/.lv2/ChowKick.lv2").unwrap();
|
||||
for ui in plugin.plugin.raw().uis().unwrap().iter() {
|
||||
println!("{:?}", ui.uri());
|
||||
println!("{:?}", ui.classes());
|
||||
}
|
||||
let handle = plugin.instance.raw_mut().instance_mut().handle();
|
||||
let instance_access = crate::bound::LV2_Feature {
|
||||
URI: std::ffi::CString::new("http://lv2plug.in/ns/ext/instance-access").unwrap().into_raw(),
|
||||
data: handle as *mut _ as *mut std::ffi::c_void
|
||||
};
|
||||
let ui_instance = Arc::new(host.instance(
|
||||
&mut plugin,
|
||||
"http://lv2plug.in/ns/extensions/ui#Gtk3UI",
|
||||
"https://thewavewarden.com/odin2",
|
||||
"https://thewavewarden.com/odin2#ParentUI",
|
||||
"http://lv2plug.in/ns/extensions/ui#X11UI",
|
||||
"/home/user/.lv2/Odin2.lv2/Odin2.so",
|
||||
"/home/user/.lv2/Odin2.lv2/Odin2.so",
|
||||
&features,
|
||||
).unwrap());
|
||||
//let instance = Arc::new(host.instance(
|
||||
//&mut plugin,
|
||||
//"http://lv2plug.in/ns/extensions/ui#Gtk3UI",
|
||||
//"http://tytel.org/helm",
|
||||
//"http://tytel.org/helm#ParentUI",
|
||||
//"http://lv2plug.in/ns/extensions/ui#X11UI",
|
||||
//"/home/user/.lv2/Helm.lv2/helm.so",
|
||||
//"/home/user/.lv2/Helm.lv2/helm.so",
|
||||
//&features,
|
||||
//).unwrap());
|
||||
//let instance = Arc::new(host.instance(
|
||||
//&mut plugin,
|
||||
//"http://lv2plug.in/ns/extensions/ui#Gtk3UI",
|
||||
//"http://github.com/Chowdhury-DSP/ChowKick",
|
||||
//"http://github.com/Chowdhury-DSP/ChowKick:UI",
|
||||
//"http://lv2plug.in/ns/extensions/ui#X11UI",
|
||||
//"/home/user/.lv2/ChowKick.lv2/libChowKick.so",
|
||||
//"/home/user/.lv2/ChowKick.lv2/libChowKick.so",
|
||||
//&features,
|
||||
//).unwrap());
|
||||
//println!("{:?}", instance.get_widget());
|
||||
});
|
||||
app.run();
|
||||
//self::ui::UI::run(&instance).join();
|
||||
}
|
||||
|
||||
mod ui {
|
||||
use std::sync::Arc;
|
||||
use std::thread::{spawn, JoinHandle};
|
||||
use ::winit::{
|
||||
application::ApplicationHandler,
|
||||
event::WindowEvent,
|
||||
event_loop::{ActiveEventLoop, ControlFlow, EventLoop},
|
||||
window::{Window, WindowId},
|
||||
platform::x11::EventLoopBuilderExtX11
|
||||
};
|
||||
use crate::{Host, Instance};
|
||||
pub struct UI {
|
||||
host: Arc<Instance>,
|
||||
window: Option<Window>
|
||||
}
|
||||
impl UI {
|
||||
pub fn new (host: &Arc<Instance>) -> Self {
|
||||
Self {
|
||||
host: host.clone(),
|
||||
window: None
|
||||
}
|
||||
}
|
||||
pub fn run (host: &Arc<Instance>) -> JoinHandle<()> {
|
||||
let mut ui = Self::new(host);
|
||||
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()
|
||||
})
|
||||
}
|
||||
}
|
||||
impl ApplicationHandler for UI {
|
||||
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();
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mod plugin {
|
||||
use std::thread::JoinHandle;
|
||||
use std::sync::Arc;
|
||||
use ::livi::{
|
||||
World,
|
||||
Instance,
|
||||
Plugin as LiviPlugin,
|
||||
Features,
|
||||
FeaturesBuilder,
|
||||
Port,
|
||||
event::LV2AtomSequence,
|
||||
};
|
||||
/// A LV2 plugin.
|
||||
pub struct LV2Plugin {
|
||||
pub world: World,
|
||||
pub instance: Instance,
|
||||
pub plugin: LiviPlugin,
|
||||
pub features: Arc<Features>,
|
||||
pub port_list: Vec<Port>,
|
||||
pub input_buffer: Vec<LV2AtomSequence>,
|
||||
pub ui_thread: Option<JoinHandle<()>>,
|
||||
}
|
||||
|
||||
impl LV2Plugin {
|
||||
pub fn new (uri: &str) -> Result<Self, Box<dyn std::error::Error>> {
|
||||
// Get 1st plugin at URI
|
||||
let world = World::with_load_bundle(&uri);
|
||||
let features = FeaturesBuilder { min_block_length: 1, max_block_length: 65536 };
|
||||
let features = world.build_features(features);
|
||||
let mut plugin = None;
|
||||
#[allow(clippy::never_loop)]
|
||||
for p in world.iter_plugins() {
|
||||
plugin = Some(p);
|
||||
break
|
||||
}
|
||||
if plugin.is_none() {
|
||||
return Err(format!("plugin not found: {uri}").into())
|
||||
}
|
||||
let plugin = plugin.unwrap();
|
||||
let err = &format!("init {uri}");
|
||||
|
||||
// Instantiate
|
||||
Ok(Self {
|
||||
world,
|
||||
instance: unsafe {
|
||||
plugin
|
||||
.instantiate(features.clone(), 48000.0)
|
||||
.expect(&err)
|
||||
},
|
||||
port_list: {
|
||||
let mut port_list = vec![];
|
||||
for port in plugin.ports() {
|
||||
port_list.push(port);
|
||||
}
|
||||
port_list
|
||||
},
|
||||
plugin,
|
||||
features,
|
||||
input_buffer: Vec::with_capacity(1024),
|
||||
ui_thread: None
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue