Skip to main content

vst_audio_protocol/
editor.rs

1//! Framework-independent native editor operations. Unsupported native features
2//! return RequestError; no operation falls back to loading code in the parent.
3/// A native window of the application that an editor may live inside.
4#[derive(Clone, Copy, Debug, Eq, PartialEq)]
5pub enum ParentWindow {
6    /// An HWND of another process.
7    Win32 { hwnd: u64 },
8    /// An X11 window ID on the worker's display.
9    X11 { window: u64 },
10}
11
12#[derive(Clone, Debug, PartialEq)]
13pub enum EditorAction {
14    Show,
15    Hide,
16    Focus,
17    Resize { width: u32, height: u32 },
18    Scale(f32),
19    Inspect,
20    Capture,
21}
22/// How an editor is fitted to the display's scale when it opens.
23#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
24#[repr(u8)]
25#[non_exhaustive]
26pub enum EditorScaling {
27    /// The plugin scales itself when it can; otherwise the system stretches
28    /// it where the platform can (Windows), else it stays 1:1.
29    #[default]
30    Auto = 0,
31    /// Only the plugin scales; a plugin that cannot stays 1:1.
32    Plugin = 1,
33    /// The system stretches a 1:1 drawing (sharpness is lost). Windows
34    /// floating editors only; elsewhere the open fails with a request error.
35    Stretch = 2,
36    /// No scaling: the plugin is told nothing and draws 1:1 physical pixels.
37    Off = 3,
38}
39/// The backend actually hosting the editor, independent of the requested policy.
40#[derive(Clone, Copy, Debug, Eq, PartialEq)]
41#[repr(u8)]
42#[non_exhaustive]
43pub enum EditorPlatform {
44    Win32 = 0,
45    Cocoa = 1,
46    X11 = 2,
47    Wayland = 3,
48}
49#[derive(Clone, Debug, PartialEq)]
50pub struct EditorStatus {
51    pub platform: EditorPlatform,
52    pub scaling: EditorScaling,
53    pub visible: bool,
54    pub embedded: bool,
55    pub width: u32,
56    pub height: u32,
57    pub scale: f32,
58    pub resize_supported: bool,
59    pub scale_supported: bool,
60}
61#[derive(Clone, Debug, Eq, PartialEq)]
62pub struct EditorImage {
63    pub width: u32,
64    pub height: u32,
65    pub rgba: Vec<u8>,
66}
67impl EditorImage {
68    pub fn valid(&self) -> bool {
69        self.width > 0
70            && self.height > 0
71            && self.width <= 2048
72            && self.height <= 2048
73            && self.rgba.len() == self.width as usize * self.height as usize * 4
74    }
75}
76#[derive(Debug)]
77pub enum EditorReply {
78    Status(EditorStatus),
79    Image(EditorImage),
80}