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
12 changes: 12 additions & 0 deletions common/src/events/io/implementation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,18 @@ unsafe extern "C" fn void_push(
true
}

impl InputEventBuffer for () {
#[inline]
fn len(&self) -> u32 {
0
}

#[inline]
fn get(&self, _index: u32) -> Option<&UnknownEvent> {
None
}
}

impl<T: Event> InputEventBuffer for T {
#[inline]
fn len(&self) -> u32 {
Expand Down
10 changes: 5 additions & 5 deletions extensions/src/ambisonic/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ impl PluginAmbisonic {
/// Check if the plugin supports the given ambisonic configuration.
pub fn is_config_supported(
&self,
handle: &mut PluginMainThreadHandle,
handle: &PluginMainThreadHandle,
config: AmbisonicConfig,
) -> bool {
if let Some(is_config_supported) = handle.use_extension(&self.0).is_config_supported {
Expand All @@ -27,7 +27,7 @@ impl PluginAmbisonic {
/// Get the ambisonic configuration for the given port, if applicable.
pub fn get_config(
&self,
handle: &mut PluginMainThreadHandle,
handle: &PluginMainThreadHandle,
is_input: bool,
port_index: u32,
) -> Option<AmbisonicConfig> {
Expand All @@ -53,7 +53,7 @@ pub trait HostAmbisonicImpl {
/// Notify the host that the ambisonic configuration for one or more ports has changed.
///
/// The info can only change when the plugin is de-activated.
fn changed(&mut self);
fn changed(&self);
}

// SAFETY: The given struct is the CLAP extension struct for the matching side of this extension.
Expand All @@ -73,8 +73,8 @@ where
for<'a> H: HostHandlers<MainThread<'a>: HostAmbisonicImpl>,
{
unsafe {
HostWrapper::<H>::handle(host, |host| {
host.main_thread().as_mut().changed();
HostWrapper::<H>::handle_main_thread(host, |host| {
host.changed();
Ok(())
});
}
Expand Down
2 changes: 1 addition & 1 deletion extensions/src/ambisonic/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ impl HostAmbisonic {
/// Notify the host that the ambisonic configuration for one or more ports has changed.
///
/// The info can only change when the plugin is de-activated.
pub fn changed(&self, handle: &mut HostMainThreadHandle) {
pub fn changed(&self, handle: &HostMainThreadHandle) {
if let Some(changed) = handle.use_extension(&self.0).changed {
// SAFETY: This type ensures the function pointer is valid.
unsafe { (changed)(handle.as_raw()) }
Expand Down
19 changes: 7 additions & 12 deletions extensions/src/audio_ports/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl AudioPortInfoBuffer {

impl PluginAudioPorts {
/// Returns number of audio ports, for either input or output
pub fn count(&self, plugin: &mut PluginMainThreadHandle, is_input: bool) -> u32 {
pub fn count(&self, plugin: &PluginMainThreadHandle, is_input: bool) -> u32 {
match plugin.use_extension(&self.0).count {
None => 0,
// SAFETY: This type ensures the function pointer is valid.
Expand All @@ -49,7 +49,7 @@ impl PluginAudioPorts {
/// Gets information about an audio port by its index, for either input or output.
pub fn get<'b>(
&self,
plugin: &mut PluginMainThreadHandle,
plugin: &PluginMainThreadHandle,
index: u32,
is_input: bool,
buffer: &'b mut AudioPortInfoBuffer,
Expand All @@ -76,7 +76,7 @@ pub trait HostAudioPortsImpl {
/// Rescan the full list of audio ports according to the flags.
/// It is illegal to ask the host to rescan with a flag that is not supported (see [`is_rescan_flag_supported`](Self::is_rescan_flag_supported)).
/// Certain flags require the plugin to be de-activated.
fn rescan(&mut self, flags: AudioPortRescanFlags);
fn rescan(&self, flags: AudioPortRescanFlags);
}

// SAFETY: The given struct is the CLAP extension struct for the matching side of this extension.
Expand All @@ -96,11 +96,8 @@ unsafe extern "C" fn is_rescan_flag_supported<H>(host: *const clap_host, flag: u
where
H: for<'a> HostHandlers<MainThread<'a>: HostAudioPortsImpl>,
{
HostWrapper::<H>::handle(host, |host| {
Ok(host
.main_thread()
.as_ref()
.is_rescan_flag_supported(AudioPortRescanFlags::from_bits_truncate(flag)))
HostWrapper::<H>::handle_main_thread(host, |host| {
Ok(host.is_rescan_flag_supported(AudioPortRescanFlags::from_bits_truncate(flag)))
})
.unwrap_or(false)
}
Expand All @@ -110,10 +107,8 @@ unsafe extern "C" fn rescan<H>(host: *const clap_host, flags: u32)
where
H: for<'a> HostHandlers<MainThread<'a>: HostAudioPortsImpl>,
{
HostWrapper::<H>::handle(host, |host| {
host.main_thread()
.as_mut()
.rescan(AudioPortRescanFlags::from_bits_truncate(flags));
HostWrapper::<H>::handle_main_thread(host, |host| {
host.rescan(AudioPortRescanFlags::from_bits_truncate(flags));

Ok(())
});
Expand Down
2 changes: 1 addition & 1 deletion extensions/src/audio_ports/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ impl HostAudioPorts {
/// It is illegal to ask the host to rescan with a flag that is not supported (see [`is_rescan_flag_supported`](Self::is_rescan_flag_supported)).
/// Certain flags require the plugin to be de-activated.
#[inline]
pub fn rescan(&self, host: &mut HostMainThreadHandle, flags: AudioPortRescanFlags) {
pub fn rescan(&self, host: &HostMainThreadHandle, flags: AudioPortRescanFlags) {
if let Some(rescan) = host.use_extension(&self.0).rescan {
// SAFETY: This type ensures the function pointer is valid.
unsafe { rescan(host.as_raw(), flags.bits()) }
Expand Down
2 changes: 1 addition & 1 deletion extensions/src/audio_ports_activation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ mod host {
impl PluginAudioPortsActivation {
/// Returns true if the plugin supports calling [`set_active_audio_active`](Self::set_active_audio_active).
#[inline]
pub fn can_activate_while_processing(&self, plugin: &mut PluginMainThreadHandle) -> bool {
pub fn can_activate_while_processing(&self, plugin: &PluginMainThreadHandle) -> bool {
match plugin.use_extension(&self.0).can_activate_while_processing {
None => false,
Some(can_activate_while_processing) => {
Expand Down
16 changes: 8 additions & 8 deletions extensions/src/audio_ports_config/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl AudioPortsConfigBuffer {

impl PluginAudioPortsConfig {
/// Returns the number of available [`AudioPortsConfiguration`]s.
pub fn count(&self, plugin: &mut PluginMainThreadHandle) -> u32 {
pub fn count(&self, plugin: &PluginMainThreadHandle) -> u32 {
match plugin.use_extension(&self.0).count {
None => 0,
// SAFETY: This type ensures the function pointer is valid.
Expand All @@ -43,7 +43,7 @@ impl PluginAudioPortsConfig {
/// unnecessary allocations.
pub fn get<'b>(
&self,
plugin: &mut PluginMainThreadHandle,
plugin: &PluginMainThreadHandle,
index: u32,
buffer: &'b mut AudioPortsConfigBuffer,
) -> Option<AudioPortsConfiguration<'b>> {
Expand Down Expand Up @@ -71,7 +71,7 @@ impl PluginAudioPortsConfig {
#[inline]
pub fn select(
&self,
plugin: &mut PluginMainThreadHandle,
plugin: &PluginMainThreadHandle,
configuration_id: ClapId,
) -> Result<(), AudioPortConfigSelectError> {
// SAFETY: This type ensures the function pointer is valid.
Expand All @@ -94,7 +94,7 @@ impl PluginAudioPortsConfig {
impl PluginAudioPortsConfigInfo {
/// Gets the id of the currently selected config, or [`None`] if the current port
/// layout isn't part of the config list.
pub fn current_config(&self, plugin: &mut PluginMainThreadHandle) -> Option<ClapId> {
pub fn current_config(&self, plugin: &PluginMainThreadHandle) -> Option<ClapId> {
// SAFETY: This type ensures the function pointer is valid.
let id = unsafe { plugin.use_extension(&self.0).current_config?(plugin.as_raw()) };
if id == CLAP_INVALID_ID {
Expand All @@ -108,7 +108,7 @@ impl PluginAudioPortsConfigInfo {
/// This is analogous to [`PluginAudioPorts::get`](crate::audio_ports::PluginAudioPorts::get).
pub fn get<'b>(
&self,
plugin: &mut PluginMainThreadHandle,
plugin: &PluginMainThreadHandle,
config_id: ClapId,
index: u32,
is_input: bool,
Expand Down Expand Up @@ -140,7 +140,7 @@ impl PluginAudioPortsConfigInfo {
pub trait HostAudioPortsConfigImpl {
/// Informs the host that the available Audio Ports Configuration list has changed and needs to
/// be rescanned.
fn rescan(&mut self);
fn rescan(&self);
}

// SAFETY: The given struct is the CLAP extension struct for the matching side of this extension.
Expand All @@ -160,8 +160,8 @@ unsafe extern "C" fn rescan<H>(host: *const clap_host)
where
H: for<'a> HostHandlers<MainThread<'a>: HostAudioPortsConfigImpl>,
{
HostWrapper::<H>::handle(host, |host| {
host.main_thread().as_mut().rescan();
HostWrapper::<H>::handle_main_thread(host, |host| {
host.rescan();

Ok(())
});
Expand Down
2 changes: 1 addition & 1 deletion extensions/src/audio_ports_config/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ impl HostAudioPortsConfig {
/// Informs the host that the available Audio Ports Configuration list has changed and needs to
/// be rescanned.
#[inline]
pub fn rescan(&self, host: &mut HostMainThreadHandle) {
pub fn rescan(&self, host: &HostMainThreadHandle) {
if let Some(rescan) = host.use_extension(&self.0).rescan {
// SAFETY: This type ensures the function pointer is valid.
unsafe { rescan(host.as_raw()) }
Expand Down
4 changes: 2 additions & 2 deletions extensions/src/clap_wrapper/vst3/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl PluginAsVST3 {
#[inline]
pub fn get_num_midi_channels(
&self,
plugin: &mut PluginMainThreadHandle<'_>,
plugin: &PluginMainThreadHandle<'_>,
note_port: u32,
) -> u32 {
let Some(ext) = plugin.use_extension(&self.0).get_num_midi_channels else {
Expand All @@ -42,7 +42,7 @@ impl PluginAsVST3 {
#[inline]
pub fn supported_note_expressions(
&self,
plugin: &mut PluginMainThreadHandle<'_>,
plugin: &PluginMainThreadHandle<'_>,
) -> SupportedNoteExpressions {
let Some(ext) = plugin.use_extension(&self.0).supported_note_expressions else {
return SupportedNoteExpressions::empty();
Expand Down
30 changes: 14 additions & 16 deletions extensions/src/context_menu/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ impl PluginContextMenu {
#[inline]
pub fn populate(
&self,
plugin: &mut PluginMainThreadHandle,
plugin: &PluginMainThreadHandle,
target: ContextMenuTarget,
builder: &mut ContextMenuBuilder,
) -> Result<(), ContextMenuError> {
Expand Down Expand Up @@ -36,7 +36,7 @@ impl PluginContextMenu {
#[inline]
pub fn perform(
&self,
plugin: &mut PluginMainThreadHandle,
plugin: &PluginMainThreadHandle,
target: ContextMenuTarget,
action_id: ClapId,
) -> Result<(), ContextMenuError> {
Expand All @@ -63,7 +63,7 @@ pub trait HostContextMenuImpl {
/// Asks the host to populate the given `builder`, with the contents of a context menu
/// that targets the given `target`.
fn populate(
&mut self,
&self,
target: ContextMenuTarget,
builder: &mut ContextMenuBuilder,
) -> Result<(), HostError>;
Expand All @@ -72,14 +72,14 @@ pub trait HostContextMenuImpl {
///
/// The given `action_id` belongs to the menu created by [`populate`](Self::populate) with the
/// given `target`.
fn perform(&mut self, target: ContextMenuTarget, action_id: ClapId) -> Result<(), HostError>;
fn perform(&self, target: ContextMenuTarget, action_id: ClapId) -> Result<(), HostError>;

/// Returns `true` if the host can pop up its context menu on behalf of the plugin, `false` otherwise.
fn can_popup(&mut self) -> bool;
fn can_popup(&self) -> bool;

/// Asks the host to pop up its context menu at a given location.
fn popup(
&mut self,
&self,
target: ContextMenuTarget,
screen_index: i32,
x: i32,
Expand Down Expand Up @@ -110,15 +110,15 @@ unsafe extern "C" fn populate<H>(
where
H: for<'a> HostHandlers<MainThread<'a>: HostContextMenuImpl>,
{
HostWrapper::<H>::handle(host, |host| {
HostWrapper::<H>::handle_main_thread(host, |host| {
// SAFETY: The CLAP spec requires this pointer to be either NULL or valid for reads.
let target = unsafe { ContextMenuTarget::from_raw_ptr(target) };

// SAFETY: the CLAP spec requires the builder pointer and all its fields to be valid
// for the duration of this function call, which is the (inferred) lifetime we give it here.
let mut builder = unsafe { ContextMenuBuilder::from_raw(builder) };

host.main_thread().as_mut().populate(target, &mut builder)?;
host.populate(target, &mut builder)?;

Ok(())
})
Expand All @@ -134,14 +134,14 @@ unsafe extern "C" fn perform<H>(
where
H: for<'a> HostHandlers<MainThread<'a>: HostContextMenuImpl>,
{
HostWrapper::<H>::handle(host, |host| {
HostWrapper::<H>::handle_main_thread(host, |host| {
// SAFETY: The CLAP spec requires this pointer to be either NULL or valid for reads.
let target = unsafe { ContextMenuTarget::from_raw_ptr(target) };

let action_id = ClapId::from_raw(action_id)
.ok_or(HostWrapperError::InvalidParameter("Invalid Action ID"))?;

host.main_thread().as_mut().perform(target, action_id)?;
host.perform(target, action_id)?;
Ok(())
})
.is_some()
Expand All @@ -152,8 +152,7 @@ unsafe extern "C" fn can_popup<H>(host: *const clap_host) -> bool
where
H: for<'a> HostHandlers<MainThread<'a>: HostContextMenuImpl>,
{
HostWrapper::<H>::handle(host, |host| Ok(host.main_thread().as_mut().can_popup()))
.unwrap_or(false)
HostWrapper::<H>::handle_main_thread(host, |host| Ok(host.can_popup())).unwrap_or(false)
}

#[allow(clippy::missing_safety_doc)]
Expand All @@ -167,12 +166,11 @@ unsafe extern "C" fn popup<H>(
where
H: for<'a> HostHandlers<MainThread<'a>: HostContextMenuImpl>,
{
HostWrapper::<H>::handle(host, |host| {
HostWrapper::<H>::handle_main_thread(host, |host| {
// SAFETY: The CLAP spec requires this pointer to be either NULL or valid for reads.
let target = unsafe { ContextMenuTarget::from_raw_ptr(target) };
host.main_thread()
.as_mut()
.popup(target, screen_index, x, y)?;
host.popup(target, screen_index, x, y)?;

Ok(())
})
.is_some()
Expand Down
8 changes: 4 additions & 4 deletions extensions/src/context_menu/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ impl HostContextMenu {
#[inline]
pub fn populate(
&self,
host: &mut HostMainThreadHandle,
host: &HostMainThreadHandle,
target: ContextMenuTarget,
builder: &mut ContextMenuBuilder,
) -> Result<(), ContextMenuError> {
Expand Down Expand Up @@ -36,7 +36,7 @@ impl HostContextMenu {
#[inline]
pub fn perform(
&self,
host: &mut HostMainThreadHandle,
host: &HostMainThreadHandle,
target: ContextMenuTarget,
action_id: ClapId,
) -> Result<(), ContextMenuError> {
Expand All @@ -59,7 +59,7 @@ impl HostContextMenu {

/// Returns `true` if the host can pop up its context menu on behalf of the plugin, `false` otherwise.
#[inline]
pub fn can_popup(&self, host: &mut HostMainThreadHandle) -> bool {
pub fn can_popup(&self, host: &HostMainThreadHandle) -> bool {
let Some(can_popup) = host.use_extension(&self.0).can_popup else {
return false;
};
Expand All @@ -73,7 +73,7 @@ impl HostContextMenu {
#[inline]
pub fn popup(
&self,
host: &mut HostMainThreadHandle,
host: &HostMainThreadHandle,
target: ContextMenuTarget,
screen_index: i32,
x: i32,
Expand Down
4 changes: 2 additions & 2 deletions extensions/src/event_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ mod host {
where
H: for<'a> HostHandlers<MainThread<'a>: HostEventRegistryImpl>,
{
let result = HostWrapper::<H>::handle(host, |host| {
let result = HostWrapper::<H>::handle_main_thread(host, |host| {
let space_name = CStr::from_ptr(space_name);

let result = host.main_thread().as_ref().query(space_name);
let result = host.query(space_name);
*space_id = EventSpaceId::optional_id(&result);

Ok(result.is_some())
Expand Down
Loading
Loading