mirror of
https://github.com/haileys/mixlab.git
synced 2026-02-13 16:25:35 +01:00
197 lines
4.7 KiB
Rust
197 lines
4.7 KiB
Rust
use serde_derive::{Serialize, Deserialize};
|
|
|
|
#[derive(Serialize, Deserialize, Debug)]
|
|
pub enum ServerMessage {
|
|
WorkspaceState(WorkspaceState),
|
|
ModelOp(LogPosition, ModelOp),
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
pub struct WorkspaceState {
|
|
pub modules: Vec<(ModuleId, ModuleParams)>,
|
|
pub geometry: Vec<(ModuleId, WindowGeometry)>,
|
|
pub indications: Vec<(ModuleId, Indication)>,
|
|
pub connections: Vec<(InputId, OutputId)>,
|
|
pub inputs: Vec<(ModuleId, Vec<LineType>)>,
|
|
pub outputs: Vec<(ModuleId, Vec<LineType>)>,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug)]
|
|
pub enum ClientMessage {
|
|
CreateModule(ModuleParams, WindowGeometry),
|
|
UpdateModuleParams(ModuleId, ModuleParams),
|
|
UpdateWindowGeometry(ModuleId, WindowGeometry),
|
|
DeleteModule(ModuleId),
|
|
CreateConnection(InputId, OutputId),
|
|
DeleteConnection(InputId),
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialOrd, Ord, PartialEq, Eq)]
|
|
pub struct LogPosition(pub usize);
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
pub enum ModelOp {
|
|
CreateModule {
|
|
id: ModuleId,
|
|
params: ModuleParams,
|
|
geometry: WindowGeometry,
|
|
indication: Indication,
|
|
inputs: Vec<LineType>,
|
|
outputs: Vec<LineType>,
|
|
},
|
|
UpdateModuleParams(ModuleId, ModuleParams),
|
|
UpdateWindowGeometry(ModuleId, WindowGeometry),
|
|
UpdateModuleIndication(ModuleId, Indication),
|
|
DeleteModule(ModuleId),
|
|
CreateConnection(InputId, OutputId),
|
|
DeleteConnection(InputId),
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialOrd, Ord, PartialEq, Eq, Hash)]
|
|
pub struct ModuleId(pub usize);
|
|
|
|
#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialOrd, Ord, PartialEq, Eq, Hash)]
|
|
pub enum TerminalId {
|
|
Input(InputId),
|
|
Output(OutputId),
|
|
}
|
|
|
|
impl TerminalId {
|
|
pub fn module_id(&self) -> ModuleId {
|
|
match self {
|
|
TerminalId::Input(input) => input.module_id(),
|
|
TerminalId::Output(output) => output.module_id(),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialOrd, Ord, PartialEq, Eq, Hash)]
|
|
pub struct InputId(pub ModuleId, pub usize);
|
|
|
|
impl InputId {
|
|
pub fn module_id(&self) -> ModuleId {
|
|
self.0
|
|
}
|
|
|
|
pub fn index(&self) -> usize {
|
|
self.1
|
|
}
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialOrd, Ord, PartialEq, Eq, Hash)]
|
|
pub struct OutputId(pub ModuleId, pub usize);
|
|
|
|
impl OutputId {
|
|
pub fn module_id(&self) -> ModuleId {
|
|
self.0
|
|
}
|
|
|
|
pub fn index(&self) -> usize {
|
|
self.1
|
|
}
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)]
|
|
pub enum LineType {
|
|
Mono,
|
|
Stereo,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
pub enum ModuleParams {
|
|
Amplifier(AmplifierParams),
|
|
FmSine(FmSineParams),
|
|
Mixer2ch(()),
|
|
OutputDevice(OutputDeviceParams),
|
|
SineGenerator(SineGeneratorParams),
|
|
StereoPanner(()),
|
|
StereoSplitter(()),
|
|
Trigger(GateState),
|
|
Envelope(EnvelopeParams),
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
|
pub enum Indication {
|
|
Amplifier(()),
|
|
FmSine(()),
|
|
Mixer2ch(()),
|
|
OutputDevice(OutputDeviceIndication),
|
|
SineGenerator(()),
|
|
StereoPanner(()),
|
|
StereoSplitter(()),
|
|
Trigger(()),
|
|
Envelope(()),
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
|
pub struct SineGeneratorParams {
|
|
pub freq: f32,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
|
pub struct OutputDeviceParams {
|
|
pub device: Option<String>,
|
|
pub left: Option<usize>,
|
|
pub right: Option<usize>,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
|
pub struct OutputDeviceIndication {
|
|
pub default_device: Option<String>,
|
|
pub devices: Option<Vec<(String, usize)>>,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
|
pub struct FmSineParams {
|
|
pub freq_lo: f32,
|
|
pub freq_hi: f32,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
|
pub struct AmplifierParams {
|
|
pub amplitude: f32,
|
|
pub mod_depth: f32,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
|
pub enum GateState {
|
|
Open,
|
|
Closed
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
|
pub struct EnvelopeParams {
|
|
pub attack_ms: f32,
|
|
pub decay_ms: f32,
|
|
pub sustain_amplitude: f32,
|
|
pub release_ms: f32,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
|
|
pub struct Coords {
|
|
pub x: i32,
|
|
pub y: i32,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
pub struct WindowGeometry {
|
|
pub position: Coords,
|
|
pub z_index: usize,
|
|
}
|
|
|
|
impl Coords {
|
|
pub fn add(&self, other: Coords) -> Coords {
|
|
Coords {
|
|
x: self.x + other.x,
|
|
y: self.y + other.y,
|
|
}
|
|
}
|
|
|
|
pub fn sub(&self, other: Coords) -> Coords {
|
|
Coords {
|
|
x: self.x - other.x,
|
|
y: self.y - other.y,
|
|
}
|
|
}
|
|
}
|