Skip to content

Commit

Permalink
rename Editor to View
Browse files Browse the repository at this point in the history
  • Loading branch information
micahrj committed Nov 29, 2024
1 parent 5d5a206 commit 162c1b1
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 99 deletions.
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 ViewState {
framebuffer: Vec<u32>,
}

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

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

impl EditorWindow {
pub fn open(parent: &ParentWindow, size: Size) -> Result<EditorWindow> {
impl ViewWindow {
pub fn open(parent: &ParentWindow, size: Size) -> Result<ViewWindow> {
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 = ViewState::new();
let window = options.open(app.handle(), move |cx, event| state.handle_event(cx, event))?;

window.show();

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

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

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

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

use coupler_reflector::EditorWindow;
use coupler_reflector::ViewWindow;

#[derive(Params, Serialize, Deserialize, Clone)]
struct GainParams {
Expand All @@ -26,7 +26,7 @@ pub struct Gain {

impl Plugin for Gain {
type Engine = GainEngine;
type Editor = EditorWindow;
type View = ViewWindow;

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

Expand Down Expand Up @@ -84,13 +84,13 @@ impl Plugin for Gain {
}
}

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()
ViewWindow::open(parent, size).unwrap()
}
}

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
24 changes: 12 additions & 12 deletions src/format/clap/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use clap_sys::{events::*, host::*, id::*, plugin::*, process::*, stream::*};
use super::host::ClapHost;
use crate::buffers::{BufferData, BufferType, Buffers};
use crate::bus::{BusDir, Format};
use crate::editor::Editor;
use crate::engine::{Config, Engine};
use crate::events::{Data, Event, Events};
use crate::host::Host;
Expand All @@ -21,6 +20,7 @@ use crate::plugin::{Plugin, PluginInfo};
use crate::sync::param_gestures::{GestureStates, GestureUpdate, ParamGestures};
use crate::sync::params::ParamValues;
use crate::util::{copy_cstring, slice_from_raw_parts_checked, DisplayParam};
use crate::view::View;

fn port_type_from_format(format: &Format) -> &'static CStr {
match format {
Expand Down Expand Up @@ -49,7 +49,7 @@ pub struct MainThreadState<P: Plugin> {
pub host_params: Option<*const clap_host_params>,
pub layout_index: usize,
pub plugin: P,
pub editor: Option<P::Editor>,
pub view: Option<P::View>,
}

pub struct ProcessState<P: Plugin> {
Expand Down Expand Up @@ -131,7 +131,7 @@ impl<P: Plugin> Instance<P> {
host_params: None,
layout_index: 0,
plugin: P::new(Host::from_inner(Arc::new(ClapHost {}))),
editor: None,
view: None,
}),
process_state: UnsafeCell::new(ProcessState {
gesture_states: GestureStates::with_count(info.params.len()),
Expand All @@ -148,8 +148,8 @@ impl<P: Plugin> Instance<P> {
let id = self.info.params[index].id;
main_thread_state.plugin.set_param(id, value);

if let Some(editor) = &mut main_thread_state.editor {
editor.param_changed(id, value);
if let Some(view) = &mut main_thread_state.view {
view.param_changed(id, value);
}
}
}
Expand Down Expand Up @@ -519,7 +519,7 @@ impl<P: Plugin> Instance<P> {

if id == CLAP_EXT_GUI {
let instance = &*(plugin as *const Self);
if instance.info.has_editor {
if instance.info.has_view {
return &Self::GUI as *const _ as *const c_void;
}
}
Expand Down Expand Up @@ -830,8 +830,8 @@ impl<P: Plugin> Instance<P> {
let value = map_param_in(&instance.info.params[index], event.value);
main_thread_state.plugin.set_param(event.param_id, value);

if let Some(editor) = &mut main_thread_state.editor {
editor.param_changed(event.param_id, value);
if let Some(view) = &mut main_thread_state.view {
view.param_changed(event.param_id, value);
}
}
}
Expand All @@ -843,8 +843,8 @@ impl<P: Plugin> Instance<P> {
if let Some(value) = update.set_value {
main_thread_state.plugin.set_param(param.id, value);

if let Some(editor) = &mut main_thread_state.editor {
editor.param_changed(param.id, value);
if let Some(view) = &mut main_thread_state.view {
view.param_changed(param.id, value);
}
}

Expand Down Expand Up @@ -935,8 +935,8 @@ impl<P: Plugin> Instance<P> {
let value = main_thread_state.plugin.get_param(param.id);
instance.engine_params.set(index, value);

if let Some(editor) = &mut main_thread_state.editor {
editor.param_changed(param.id, value);
if let Some(view) = &mut main_thread_state.view {
view.param_changed(param.id, value);
}
}

Expand Down
14 changes: 7 additions & 7 deletions src/format/clap/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::ffi::{c_char, CStr};
use std::io::{self, Read, Write};

use crate::buffers::Buffers;
use crate::editor::{Editor, EditorHost, ParentWindow, Size};
use crate::events::Events;
use crate::view::{ParentWindow, Size, View, ViewHost};

use clap_sys::plugin_factory::{clap_plugin_factory, CLAP_PLUGIN_FACTORY_ID};
use clap_sys::version::CLAP_VERSION;
Expand All @@ -26,7 +26,7 @@ struct TestPlugin;

impl Plugin for TestPlugin {
type Engine = TestEngine;
type Editor = TestEditor;
type View = TestView;

fn info() -> PluginInfo {
PluginInfo {
Expand All @@ -38,7 +38,7 @@ impl Plugin for TestPlugin {
buses: Vec::new(),
layouts: vec![],
params: Vec::new(),
has_editor: false,
has_view: false,
}
}
fn new(_host: Host) -> Self {
Expand All @@ -57,8 +57,8 @@ impl Plugin for TestPlugin {
fn engine(&mut self, _config: Config) -> Self::Engine {
TestEngine
}
fn editor(&mut self, _host: EditorHost, _parent: &ParentWindow) -> Self::Editor {
TestEditor
fn view(&mut self, _host: ViewHost, _parent: &ParentWindow) -> Self::View {
TestView
}

#[allow(unused_variables)]
Expand All @@ -81,9 +81,9 @@ impl Engine for TestEngine {
fn process(&mut self, _buffers: Buffers, _events: Events) {}
}

struct TestEditor;
struct TestView;

impl Editor for TestEditor {
impl View for TestView {
fn size(&self) -> Size {
Size {
width: 0.0,
Expand Down
Loading

0 comments on commit 162c1b1

Please sign in to comment.