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 coupler-derive/src/enum_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ pub fn expand_enum(input: &DeriveInput) -> Result<TokenStream, Error> {
Some(#count)
}

fn encode(&self) -> ::coupler::params::ParamValue {
fn encode(&self) -> ::std::primitive::f64 {
match self {
#(#encode_cases)*
}
}

fn decode(__value: ::coupler::params::ParamValue) -> Self {
fn decode(__value: ::std::primitive::f64) -> Self {
match (__value * #count as ::std::primitive::f64) as ::std::primitive::u32 {
#(#decode_cases)*
_ => #ident::#last_variant,
Expand Down
18 changes: 9 additions & 9 deletions coupler-derive/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,34 +236,34 @@ pub fn expand_params(input: &DeriveInput) -> Result<TokenStream, Error> {
#(.param(#param_info))*;
}

fn set_param(&mut self, __id: ::coupler::params::ParamId, __value: ::coupler::params::ParamValue) {
match __id {
fn set_param(&mut self, __index: ::std::primitive::usize, __value: ::std::primitive::f64) {
match __index {
#(#set_cases)*
_ => {}
}
}

fn get_param(&self, __id: ::coupler::params::ParamId) -> ::coupler::params::ParamValue {
match __id {
fn get_param(&self, __index: ::std::primitive::usize) -> ::std::primitive::f64 {
match __index {
#(#get_cases)*
_ => 0.0,
}
}

fn parse_param(&self, __id: ::coupler::params::ParamId, __text: &::std::primitive::str) -> ::std::option::Option<::coupler::params::ParamValue> {
match __id {
fn parse_param(&self, __index: ::std::primitive::usize, __text: &::std::primitive::str) -> ::std::option::Option<::std::primitive::f64> {
match __index {
#(#parse_cases)*
_ => ::std::option::Option::None
}
}

fn display_param(
&self,
__id: ::coupler::params::ParamId,
__value: ::coupler::params::ParamValue,
__index: ::std::primitive::usize,
__value: ::std::primitive::f64,
__write: impl fmt::Write,
) -> ::std::result::Result<(), ::std::fmt::Error> {
match __id {
match __index {
#(#display_cases)*
_ => Ok(())
}
Expand Down
32 changes: 16 additions & 16 deletions examples/gain-gui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use coupler::events::{Data, Events};
use coupler::format::clap::{BuildClapInfo, ClapInfo, ClapPlugin};
use coupler::format::vst3::{BuildVst3Info, Uuid, Vst3Info, Vst3Plugin};
use coupler::host::Host;
use coupler::params::{BuildParams, ParamId, ParamValue, Params};
use coupler::params::{BuildParams, Params};
use coupler::plugin::{BuildInfo, Plugin, PluginInfo};
use coupler::process::{Config, Processor};

Expand Down Expand Up @@ -79,25 +79,25 @@ impl Plugin for GainGui {
self.params.params(build)
}

fn set_param(&mut self, id: ParamId, value: ParamValue) {
self.params.set_param(id, value);
fn set_param(&mut self, index: usize, value: f64) {
self.params.set_param(index, value);
}

fn get_param(&self, id: ParamId) -> ParamValue {
self.params.get_param(id)
fn get_param(&self, index: usize) -> f64 {
self.params.get_param(index)
}

fn parse_param(&self, id: ParamId, text: &str) -> Option<ParamValue> {
self.params.parse_param(id, text)
fn parse_param(&self, index: usize, text: &str) -> Option<f64> {
self.params.parse_param(index, text)
}

fn display_param(
&self,
id: ParamId,
value: ParamValue,
index: usize,
value: f64,
write: impl fmt::Write,
) -> Result<(), fmt::Error> {
self.params.display_param(id, value, write)
self.params.display_param(index, value, write)
}

fn save(&self, output: impl io::Write) -> io::Result<()> {
Expand Down Expand Up @@ -157,16 +157,16 @@ pub struct GainGuiProcessor {
impl Processor for GainGuiProcessor {
fn reset(&mut self) {}

fn set_param(&mut self, id: ParamId, value: ParamValue) {
self.params.set_param(id, value);
fn set_param(&mut self, index: usize, value: f64) {
self.params.set_param(index, value);
}

fn process(&mut self, buffers: Buffers, events: Events) {
let mut buffers: (BufferMut,) = buffers.try_into().unwrap();
for (mut buffer, events) in buffers.0.split_at_events(events) {
for event in events {
if let Data::ParamChange { id, value } = event.data {
self.set_param(id, value);
if let Data::ParamChange { index, value } = event.data {
self.set_param(index, value);
}
}

Expand Down Expand Up @@ -368,7 +368,7 @@ impl Editor for GainGuiEditor {
}
}

fn param_changed(&mut self, id: ParamId, value: ParamValue) {
self.params.borrow_mut().set_param(id, value);
fn param_changed(&mut self, index: usize, value: f64) {
self.params.borrow_mut().set_param(index, value);
}
}
28 changes: 14 additions & 14 deletions examples/gain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use coupler::events::{Data, Events};
use coupler::format::clap::{BuildClapInfo, ClapInfo, ClapPlugin};
use coupler::format::vst3::{BuildVst3Info, Uuid, Vst3Info, Vst3Plugin};
use coupler::host::Host;
use coupler::params::{BuildParams, ParamId, ParamValue, Params};
use coupler::params::{BuildParams, Params};
use coupler::plugin::{BuildInfo, Plugin, PluginInfo};
use coupler::process::{Config, Processor};

Expand Down Expand Up @@ -70,25 +70,25 @@ impl Plugin for Gain {
self.params.params(build)
}

fn set_param(&mut self, id: ParamId, value: ParamValue) {
self.params.set_param(id, value);
fn set_param(&mut self, index: usize, value: f64) {
self.params.set_param(index, value);
}

fn get_param(&self, id: ParamId) -> ParamValue {
self.params.get_param(id)
fn get_param(&self, index: usize) -> f64 {
self.params.get_param(index)
}

fn parse_param(&self, id: ParamId, text: &str) -> Option<ParamValue> {
self.params.parse_param(id, text)
fn parse_param(&self, index: usize, text: &str) -> Option<f64> {
self.params.parse_param(index, text)
}

fn display_param(
&self,
id: ParamId,
value: ParamValue,
index: usize,
value: f64,
write: impl fmt::Write,
) -> Result<(), fmt::Error> {
self.params.display_param(id, value, write)
self.params.display_param(index, value, write)
}

fn save(&self, output: impl io::Write) -> io::Result<()> {
Expand Down Expand Up @@ -148,16 +148,16 @@ pub struct GainProcessor {
impl Processor for GainProcessor {
fn reset(&mut self) {}

fn set_param(&mut self, id: ParamId, value: ParamValue) {
self.params.set_param(id, value);
fn set_param(&mut self, index: usize, value: f64) {
self.params.set_param(index, value);
}

fn process(&mut self, buffers: Buffers, events: Events) {
let mut buffers: (BufferMut,) = buffers.try_into().unwrap();
for (mut buffer, events) in buffers.0.split_at_events(events) {
for event in events {
if let Data::ParamChange { id, value } = event.data {
self.set_param(id, value);
if let Data::ParamChange { index, value } = event.data {
self.set_param(index, value);
}
}

Expand Down
24 changes: 11 additions & 13 deletions src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ use std::ffi::{c_ulong, c_void};
use std::marker::PhantomData;
use std::rc::Rc;

use crate::params::{ParamId, ParamValue};

pub trait EditorHostInner {
fn begin_gesture(&self, id: ParamId);
fn end_gesture(&self, id: ParamId);
fn set_param(&self, id: ParamId, value: ParamValue);
fn begin_gesture(&self, index: usize);
fn end_gesture(&self, index: usize);
fn set_param(&self, index: usize, value: f64);
}

#[derive(Clone)]
Expand All @@ -25,16 +23,16 @@ impl EditorHost {
}
}

pub fn begin_gesture(&self, id: ParamId) {
self.inner.begin_gesture(id);
pub fn begin_gesture(&self, index: usize) {
self.inner.begin_gesture(index);
}

pub fn end_gesture(&self, id: ParamId) {
self.inner.end_gesture(id);
pub fn end_gesture(&self, index: usize) {
self.inner.end_gesture(index);
}

pub fn set_param(&self, id: ParamId, value: ParamValue) {
self.inner.set_param(id, value);
pub fn set_param(&self, index: usize, value: f64) {
self.inner.set_param(index, value);
}
}

Expand Down Expand Up @@ -66,7 +64,7 @@ pub struct Size {

pub trait Editor: Sized + 'static {
fn size(&self) -> Size;
fn param_changed(&mut self, id: ParamId, value: ParamValue);
fn param_changed(&mut self, index: usize, value: f64);
}

pub struct NoEditor;
Expand All @@ -79,5 +77,5 @@ impl Editor for NoEditor {
}
}

fn param_changed(&mut self, _id: ParamId, _value: ParamValue) {}
fn param_changed(&mut self, _index: usize, _value: f64) {}
}
4 changes: 1 addition & 3 deletions src/events.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::ops::{Index, RangeBounds};
use std::slice;

use crate::params::{ParamId, ParamValue};

#[derive(Copy, Clone, Debug)]
pub struct Event {
pub time: i64,
Expand All @@ -12,7 +10,7 @@ pub struct Event {
#[derive(Copy, Clone, Debug)]
#[non_exhaustive]
pub enum Data {
ParamChange { id: ParamId, value: ParamValue },
ParamChange { index: usize, value: f64 },
}

#[derive(Copy, Clone)]
Expand Down
16 changes: 6 additions & 10 deletions src/format/clap/gui.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::collections::HashMap;
use std::ffi::{CStr, c_char};
use std::rc::Rc;
use std::sync::Arc;
Expand All @@ -8,37 +7,35 @@ use clap_sys::plugin::*;

use super::instance::{Extensions, HostPtr, Instance};
use crate::editor::{Editor, EditorHost, EditorHostInner, ParentWindow, RawParent};
use crate::params::{ParamId, ParamValue};
use crate::plugin::Plugin;
use crate::sync::param_gestures::ParamGestures;
use crate::sync::thread_cell::ThreadCell;

struct ClapEditorHost {
host: HostPtr,
extensions: Extensions,
param_map: Arc<HashMap<ParamId, usize>>,
param_gestures: Arc<ParamGestures>,
}

impl EditorHostInner for ClapEditorHost {
fn begin_gesture(&self, id: ParamId) {
self.param_gestures.begin_gesture(self.param_map[&id]);
fn begin_gesture(&self, index: usize) {
self.param_gestures.begin_gesture(index);

if let Some(host_params) = self.extensions.host_params {
unsafe { host_params.as_ref().request_flush.unwrap()(self.host.0) };
}
}

fn end_gesture(&self, id: ParamId) {
self.param_gestures.end_gesture(self.param_map[&id]);
fn end_gesture(&self, index: usize) {
self.param_gestures.end_gesture(index);

if let Some(host_params) = self.extensions.host_params {
unsafe { host_params.as_ref().request_flush.unwrap()(self.host.0) };
}
}

fn set_param(&self, id: ParamId, value: ParamValue) {
self.param_gestures.set_value(self.param_map[&id], value);
fn set_param(&self, index: usize, value: f64) {
self.param_gestures.set_value(index, value);

if let Some(host_params) = self.extensions.host_params {
unsafe { host_params.as_ref().request_flush.unwrap()(self.host.0) };
Expand Down Expand Up @@ -199,7 +196,6 @@ impl<P: Plugin> Instance<P> {
let host = EditorHost::from_inner(Rc::new(ClapEditorHost {
host: instance.host,
extensions: main_thread_state.extensions,
param_map: Arc::clone(&instance.param_map),
param_gestures: Arc::clone(&instance.param_gestures),
}));
let parent = unsafe { ParentWindow::from_raw(raw_parent) };
Expand Down
Loading
Loading