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 ef908ed commit 72d1323
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 88 deletions.
4 changes: 2 additions & 2 deletions coupler-reflector/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
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,
Expand Down Expand Up @@ -63,7 +63,7 @@ impl PluginWindow {
}
}

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

Expand Down
8 changes: 4 additions & 4 deletions examples/gain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ 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::PluginWindow;

Expand All @@ -26,7 +26,7 @@ pub struct Gain {

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

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,7 +84,7 @@ 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,
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
36 changes: 18 additions & 18 deletions src/format/vst3/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ use vst3::{Class, ComRef, ComWrapper, Steinberg::Vst::*, Steinberg::*};
use super::buffers::ScratchBuffers;
use super::host::Vst3Host;
use super::util::{copy_wstring, utf16_from_ptr};
use super::view::{PlugView, Vst3EditorHost};
use super::view::{PlugView, Vst3ViewHost};
use crate::bus::{BusDir, Format, Layout};
use crate::editor::Editor;
use crate::engine::{Config, Engine};
use crate::events::{Data, Event, Events};
use crate::host::Host;
use crate::params::ParamId;
use crate::plugin::{Plugin, PluginInfo};
use crate::sync::params::ParamValues;
use crate::util::{slice_from_raw_parts_checked, DisplayParam};
use crate::view::View;

fn format_to_speaker_arrangement(format: &Format) -> SpeakerArrangement {
match format {
Expand All @@ -39,9 +39,9 @@ fn speaker_arrangement_to_format(speaker_arrangement: SpeakerArrangement) -> Opt
pub struct MainThreadState<P: Plugin> {
pub config: Config,
pub plugin: P,
pub editor_params: Vec<f64>,
pub editor_host: Rc<Vst3EditorHost>,
pub editor: Option<P::Editor>,
pub view_params: Vec<f64>,
pub view_host: Rc<Vst3ViewHost>,
pub view: Option<P::View>,
}

struct ProcessState<P: Plugin> {
Expand Down Expand Up @@ -95,7 +95,7 @@ impl<P: Plugin> Component<P> {
max_buffer_size: 0,
};

let editor_params = info.params.iter().map(|p| p.default).collect();
let view_params = info.params.iter().map(|p| p.default).collect();

let scratch_buffers = ScratchBuffers::new(input_bus_map.len(), output_bus_map.len());

Expand All @@ -113,9 +113,9 @@ impl<P: Plugin> Component<P> {
main_thread_state: Arc::new(UnsafeCell::new(MainThreadState {
config: config.clone(),
plugin: P::new(Host::from_inner(host)),
editor_params,
editor_host: Rc::new(Vst3EditorHost::new()),
editor: None,
view_params,
view_host: Rc::new(Vst3ViewHost::new()),
view: None,
})),
process_state: UnsafeCell::new(ProcessState {
config,
Expand Down Expand Up @@ -314,10 +314,10 @@ impl<P: Plugin> IComponentTrait for Component<P> {
for (index, param) in self.info.params.iter().enumerate() {
let value = main_thread_state.plugin.get_param(param.id);
self.engine_params.set(index, value);
main_thread_state.editor_params[index] = value;
main_thread_state.view_params[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 Expand Up @@ -675,7 +675,7 @@ impl<P: Plugin> IEditControllerTrait for Component<P> {
let main_thread_state = &*self.main_thread_state.get();

if let Some(&index) = self.param_map.get(&id) {
return main_thread_state.editor_params[index];
return main_thread_state.view_params[index];
}

0.0
Expand All @@ -685,10 +685,10 @@ impl<P: Plugin> IEditControllerTrait for Component<P> {
let main_thread_state = &mut *self.main_thread_state.get();

if let Some(&index) = self.param_map.get(&id) {
main_thread_state.editor_params[index] = value;
main_thread_state.view_params[index] = 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);
}

return kResultOk;
Expand All @@ -700,7 +700,7 @@ impl<P: Plugin> IEditControllerTrait for Component<P> {
unsafe fn setComponentHandler(&self, handler: *mut IComponentHandler) -> tresult {
let main_thread_state = &mut *self.main_thread_state.get();

let mut current_handler = main_thread_state.editor_host.handler.borrow_mut();
let mut current_handler = main_thread_state.view_host.handler.borrow_mut();
if let Some(handler) = ComRef::from_raw(handler) {
*current_handler = Some(handler.to_com_ptr());
} else {
Expand All @@ -711,7 +711,7 @@ impl<P: Plugin> IEditControllerTrait for Component<P> {
}

unsafe fn createView(&self, name: FIDString) -> *mut IPlugView {
if !self.info.has_editor {
if !self.info.has_view {
return ptr::null_mut();
}

Expand Down
Loading

0 comments on commit 72d1323

Please sign in to comment.