Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/plugin_clack/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2021"
crate-type = ["cdylib"]

[dependencies]
clack-plugin = "0.1.1"
clack-extensions = { version = "0.1.1", features = ["gui", "state", "clack-plugin", "raw-window-handle_06"] }
clack-plugin = "0.2.0"
clack-extensions = { version = "0.2.0", features = ["gui", "state", "clack-plugin", "raw-window-handle_06"] }
baseview = { path = "../..", features = ["tracing"] }
softbuffer = "0.4.8"
2 changes: 1 addition & 1 deletion examples/plugin_clack/src/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub struct ExamplePluginAudioProcessor;

impl<'a> PluginAudioProcessor<'a, (), ExamplePluginMainThread<'a>> for ExamplePluginAudioProcessor {
fn activate(
_host: HostAudioProcessorHandle<'a>, _main_thread: &mut ExamplePluginMainThread,
_host: HostAudioProcessorHandle<'a>, _main_thread: &ExamplePluginMainThread,
_shared: &'a (), _audio_config: PluginAudioConfiguration,
) -> Result<Self, PluginError> {
Ok(Self)
Expand Down
66 changes: 33 additions & 33 deletions examples/plugin_clack/src/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ pub struct ExamplePluginGui {
}

impl PluginGuiImpl for ExamplePluginMainThread<'_> {
fn is_api_supported(&mut self, configuration: GuiConfiguration) -> bool {
fn is_api_supported(&self, configuration: GuiConfiguration) -> bool {
!configuration.is_floating
&& Some(configuration.api_type) == GuiApiType::default_for_current_platform()
}

fn get_preferred_api(&mut self) -> Option<GuiConfiguration<'_>> {
fn get_preferred_api(&self) -> Option<GuiConfiguration<'_>> {
Some(GuiConfiguration {
api_type: GuiApiType::default_for_current_platform()?,
is_floating: false,
})
}

fn create(&mut self, _configuration: GuiConfiguration) -> Result<(), PluginError> {
fn create(&self, _configuration: GuiConfiguration) -> Result<(), PluginError> {
let options = WindowSettings::new()
.wait_for_parent()
.with_size(PhysicalSize::new(400, 200))
Expand All @@ -46,43 +46,43 @@ impl PluginGuiImpl for ExamplePluginMainThread<'_> {

let window = Window::create_with_host(options, OpenWindowExample::new, host)?;

self.gui = Some(ExamplePluginGui { handle: window });
self.gui.replace(Some(ExamplePluginGui { handle: window }));
Ok(())
}

fn destroy(&mut self) {
fn destroy(&self) {
let Some(gui) = self.gui.take() else { return };

gui.handle.close()
}

fn set_scale(&mut self, scale: f64) -> Result<(), PluginError> {
let Some(gui) = &self.gui else {
fn set_scale(&self, scale: f64) -> Result<(), PluginError> {
let Some(gui) = self.borrow_window() else {
return Err(PluginError::Message("set_scale called without a GUI active"));
};
gui.handle.suggest_fallback_scale_factor(scale)?;
gui.suggest_fallback_scale_factor(scale)?;

Ok(())
}

fn get_size(&mut self) -> Option<GuiSize> {
let Some(gui) = &self.gui else {
fn get_size(&self) -> Option<GuiSize> {
let Some(gui) = self.borrow_window() else {
eprintln!("get_size called without a GUI active");
return None;
};

let size = gui.handle.size().to_native_size();
let size = gui.size().to_native_size();

Some(GuiSize { width: size.width, height: size.height })
}

fn can_resize(&mut self) -> bool {
let Some(gui) = &self.gui else { return false };
fn can_resize(&self) -> bool {
let Some(gui) = self.borrow_window() else { return false };

gui.handle.is_resizable()
gui.is_resizable()
}

fn get_resize_hints(&mut self) -> Option<GuiResizeHints> {
fn get_resize_hints(&self) -> Option<GuiResizeHints> {
let can_resize = self.can_resize();

Some(GuiResizeHints {
Expand All @@ -93,60 +93,60 @@ impl PluginGuiImpl for ExamplePluginMainThread<'_> {
})
}

fn adjust_size(&mut self, size: GuiSize) -> Option<GuiSize> {
let Some(gui) = &self.gui else { return None };
fn adjust_size(&self, size: GuiSize) -> Option<GuiSize> {
let gui = self.borrow_window()?;

let size = gui.handle.adjust_size(NativeSize::new(size.width, size.height));
let size = gui.adjust_size(NativeSize::new(size.width, size.height));

Some(GuiSize { width: size.width, height: size.height })
}

fn set_size(&mut self, size: GuiSize) -> Result<(), PluginError> {
let Some(gui) = &self.gui else {
fn set_size(&self, size: GuiSize) -> Result<(), PluginError> {
let Some(gui) = self.borrow_window() else {
return Err(PluginError::Message("set_size called without a GUI active"));
};

gui.handle.resize(NativeSize { width: size.width, height: size.height })?;
gui.resize(NativeSize { width: size.width, height: size.height })?;

Ok(())
}

fn set_parent(&mut self, window: ClapWindow) -> Result<(), PluginError> {
let Some(gui) = &self.gui else {
fn set_parent(&self, window: ClapWindow) -> Result<(), PluginError> {
let Some(gui) = self.borrow_window() else {
return Err(PluginError::Message("set_parent called without a GUI active"));
};

// SAFETY: The CLAP spec ensures the parent window handle is valid for at least this call
let parent = unsafe { window.borrow_handle_unchecked()? };

gui.handle.set_parent(&parent)?;
gui.handle.show()?;
gui.set_parent(&parent)?;
gui.show()?;

Ok(())
}

fn set_transient(&mut self, _window: ClapWindow) -> Result<(), PluginError> {
fn set_transient(&self, _window: ClapWindow) -> Result<(), PluginError> {
unimplemented!() // Not supported yet
}

fn suggest_title(&mut self, _title: &str) {
fn suggest_title(&self, _title: &str) {
// Not supported yet
}

fn show(&mut self) -> Result<(), PluginError> {
let Some(gui) = &self.gui else {
fn show(&self) -> Result<(), PluginError> {
let Some(gui) = self.borrow_window() else {
return Err(PluginError::Message("show called without a GUI active"));
};
gui.handle.show()?;
gui.show()?;

Ok(())
}

fn hide(&mut self) -> Result<(), PluginError> {
let Some(gui) = &self.gui else {
fn hide(&self) -> Result<(), PluginError> {
let Some(gui) = self.borrow_window() else {
return Err(PluginError::Message("hide called without a GUI active"));
};
gui.handle.show()?;
gui.show()?;

Ok(())
}
Expand Down
20 changes: 14 additions & 6 deletions examples/plugin_clack/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use clack_extensions::gui::{HostGui, PluginGui};
use clack_extensions::state::{PluginState, PluginStateImpl};
use clack_plugin::prelude::*;
use clack_plugin::stream::{InputStream, OutputStream};
use std::cell::{Ref, RefCell};

mod audio;
mod gui;
Expand Down Expand Up @@ -39,7 +40,7 @@ impl DefaultPluginFactory for ExamplePlugin {
fn new_main_thread<'a>(
host: HostMainThreadHandle<'a>, _shared: &'a Self::Shared<'a>,
) -> Result<Self::MainThread<'a>, PluginError> {
Ok(Self::MainThread { gui: None, host_gui: host.get_extension(), host })
Ok(Self::MainThread { gui: None.into(), host_gui: host.get_extension(), host })
}
}

Expand All @@ -50,23 +51,30 @@ pub struct ExamplePluginMainThread<'a> {
// The host GUI extension handle
host_gui: Option<HostGui>,
/// The plugin's GUI state and context
gui: Option<ExamplePluginGui>,
gui: RefCell<Option<ExamplePluginGui>>,
}

impl<'a> ExamplePluginMainThread<'a> {
fn borrow_window(&self) -> Option<Ref<'_, baseview::Window>> {
let gui = self.gui.borrow();
gui.is_some().then(|| Ref::map(gui, |g| &g.as_ref().unwrap().handle))
}
}

impl<'a> PluginMainThread<'a, ()> for ExamplePluginMainThread<'a> {
fn on_main_thread(&mut self) {
if let Some(gui) = self.gui.as_mut() {
fn on_main_thread(&self) {
if let Some(gui) = self.gui.borrow().as_ref() {
gui.handle.host_main_thread_callback();
}
}
}

impl PluginStateImpl for ExamplePluginMainThread<'_> {
fn save(&mut self, _output: &mut OutputStream) -> Result<(), PluginError> {
fn save(&self, _output: &mut OutputStream) -> Result<(), PluginError> {
Ok(())
}

fn load(&mut self, _input: &mut InputStream) -> Result<(), PluginError> {
fn load(&self, _input: &mut InputStream) -> Result<(), PluginError> {
Ok(())
}
}
Expand Down
4 changes: 2 additions & 2 deletions examples/plugin_clack_femtovg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ edition = "2021"
crate-type = ["cdylib"]

[dependencies]
clack-plugin = "0.1.1"
clack-extensions = { version = "0.1.1", features = ["gui", "state", "clack-plugin", "raw-window-handle_06"] }
clack-plugin = "0.2.0"
clack-extensions = { version = "0.2.0", features = ["gui", "state", "clack-plugin", "raw-window-handle_06"] }
baseview = { path = "../..", features = ["opengl", "tracing"] }
femtovg = "0.26"
raw-window-handle = { version = "0.6.2", features = ["std"] }
2 changes: 1 addition & 1 deletion examples/plugin_clack_femtovg/src/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub struct ExamplePluginAudioProcessor;

impl<'a> PluginAudioProcessor<'a, (), ExamplePluginMainThread<'a>> for ExamplePluginAudioProcessor {
fn activate(
_host: HostAudioProcessorHandle<'a>, _main_thread: &mut ExamplePluginMainThread,
_host: HostAudioProcessorHandle<'a>, _main_thread: &ExamplePluginMainThread,
_shared: &'a (), _audio_config: PluginAudioConfiguration,
) -> Result<Self, PluginError> {
Ok(Self)
Expand Down
Loading