Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename Processor to Engine and Editor to View #2

Merged
merged 4 commits into from
Nov 29, 2024
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
22 changes: 11 additions & 11 deletions coupler-reflector/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use coupler::editor::{Editor, ParentWindow, RawParent, Size};
use coupler::params::{ParamId, ParamValue};
use coupler::view::{ParentWindow, RawParent, Size, View};
use reflector::platform::{
App, AppMode, AppOptions, Bitmap, Event, RawWindow, Response, Result, Window, WindowContext,
WindowOptions,
};

struct EditorState {
struct State {
framebuffer: Vec<u32>,
}

impl EditorState {
fn new() -> EditorState {
EditorState {
impl State {
fn new() -> State {
State {
framebuffer: Vec::new(),
}
}
Expand All @@ -34,14 +34,14 @@ impl EditorState {
}
}

pub struct EditorWindow {
pub struct PluginWindow {
#[allow(unused)]
app: App,
window: Window,
}

impl EditorWindow {
pub fn open(parent: &ParentWindow, size: Size) -> Result<EditorWindow> {
impl PluginWindow {
pub fn open(parent: &ParentWindow, size: Size) -> Result<PluginWindow> {
let app = AppOptions::new().mode(AppMode::Guest).build()?;

let mut options = WindowOptions::new();
Expand All @@ -54,16 +54,16 @@ impl EditorWindow {
};
unsafe { options.raw_parent(raw_parent) };

let mut state = EditorState::new();
let mut state = State::new();
let window = options.open(app.handle(), move |cx, event| state.handle_event(cx, event))?;

window.show();

Ok(EditorWindow { app, window })
Ok(PluginWindow { app, window })
}
}

impl Editor for EditorWindow {
impl View for PluginWindow {
fn size(&self) -> Size {
let size = self.window.size();

Expand Down
26 changes: 12 additions & 14 deletions examples/gain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ use serde::{Deserialize, Serialize};

use coupler::format::clap::*;
use coupler::format::vst3::*;
use coupler::{
buffers::*, bus::*, editor::*, events::*, host::*, params::*, plugin::*, process::*,
};
use coupler::{buffers::*, bus::*, engine::*, events::*, host::*, params::*, plugin::*, view::*};

use coupler_reflector::EditorWindow;
use coupler_reflector::PluginWindow;

#[derive(Params, Serialize, Deserialize, Clone)]
struct GainParams {
Expand All @@ -27,8 +25,8 @@ pub struct Gain {
}

impl Plugin for Gain {
type Processor = GainProcessor;
type Editor = EditorWindow;
type Engine = GainEngine;
type View = PluginWindow;

fn info() -> PluginInfo {
PluginInfo {
Expand All @@ -50,7 +48,7 @@ impl Plugin for Gain {
},
],
params: GainParams::params(),
has_editor: true,
has_view: true,
}
}

Expand Down Expand Up @@ -80,19 +78,19 @@ impl Plugin for Gain {
Ok(())
}

fn processor(&mut self, _config: Config) -> Self::Processor {
GainProcessor {
fn engine(&mut self, _config: Config) -> Self::Engine {
GainEngine {
params: self.params.clone(),
}
}

fn editor(&mut self, _host: EditorHost, parent: &ParentWindow) -> Self::Editor {
fn view(&mut self, _host: ViewHost, parent: &ParentWindow) -> Self::View {
let size = Size {
width: 512.0,
height: 512.0,
};

EditorWindow::open(parent, size).unwrap()
PluginWindow::open(parent, size).unwrap()
}
}

Expand All @@ -112,19 +110,19 @@ impl ClapPlugin for Gain {
}
}

pub struct GainProcessor {
pub struct GainEngine {
params: GainParams,
}

impl GainProcessor {
impl GainEngine {
fn handle_event(&mut self, event: &Event) {
if let Data::ParamChange { id, value } = event.data {
self.params.set_param(id, value);
}
}
}

impl Processor for GainProcessor {
impl Engine for GainEngine {
fn reset(&mut self) {}

fn flush(&mut self, events: Events) {
Expand Down
2 changes: 1 addition & 1 deletion src/process.rs → src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub struct Config {
pub max_buffer_size: usize,
}

pub trait Processor: Send + Sized + 'static {
pub trait Engine: Send + Sized + 'static {
fn reset(&mut self);
fn flush(&mut self, events: Events);
fn process(&mut self, buffers: Buffers, events: Events);
Expand Down
18 changes: 9 additions & 9 deletions src/format/clap/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ use clap_sys::ext::{gui::*, params::*};
use clap_sys::{host::*, plugin::*};

use super::instance::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::view::{ParentWindow, RawParent, View, ViewHost, ViewHostInner};

struct ClapEditorHost {
struct ClapViewHost {
host: *const clap_host,
host_params: Option<*const clap_host_params>,
param_map: Arc<HashMap<ParamId, usize>>,
param_gestures: Arc<ParamGestures>,
}

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

Expand Down Expand Up @@ -113,7 +113,7 @@ impl<P: Plugin> Instance<P> {
let instance = &*(plugin as *const Self);
let main_thread_state = &mut *instance.main_thread_state.get();

main_thread_state.editor = None;
main_thread_state.view = None;
}

unsafe extern "C" fn gui_set_scale(_plugin: *const clap_plugin, _scale: f64) -> bool {
Expand All @@ -128,8 +128,8 @@ impl<P: Plugin> Instance<P> {
let instance = &*(plugin as *const Self);
let main_thread_state = &mut *instance.main_thread_state.get();

if let Some(editor) = &main_thread_state.editor {
let size = editor.size();
if let Some(view) = &main_thread_state.view {
let size = view.size();

*width = size.width.round() as u32;
*height = size.height.round() as u32;
Expand Down Expand Up @@ -189,15 +189,15 @@ impl<P: Plugin> Instance<P> {
let instance = &*(plugin as *const Self);
let main_thread_state = &mut *instance.main_thread_state.get();

let host = EditorHost::from_inner(Rc::new(ClapEditorHost {
let host = ViewHost::from_inner(Rc::new(ClapViewHost {
host: instance.host,
host_params: main_thread_state.host_params,
param_map: Arc::clone(&instance.param_map),
param_gestures: Arc::clone(&instance.param_gestures),
}));
let parent = ParentWindow::from_raw(raw_parent);
let editor = main_thread_state.plugin.editor(host, &parent);
main_thread_state.editor = Some(editor);
let view = main_thread_state.plugin.view(host, &parent);
main_thread_state.view = Some(view);

true
}
Expand Down
Loading