use std::borrow::Cow;
use std::path::PathBuf;
use serde::{Deserialize, Serialize};
use serde_with::serde_as;
use crate::errors::InputError;
use crate::parameter::ParameterInfo;
use crate::plugin::{PluginInfo, PluginRef};
use crate::render::Tail;
use crate::state::{PluginState, PresetInfo, StatePurpose};
use crate::{CapabilityReport, DiagnosticBatch, Failure, HostIdentity};
pub const PROTOCOL_VERSION: u32 = 45;
pub const MAX_MESSAGE_BYTES: usize = 256 << 20;
pub const MAX_MENU_DEPTH: usize = 16;
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct Hello {
pub protocol: u32,
pub token: u64,
}
#[serde_as]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub enum Request<'a> {
Changes,
AudioBuses {
slot: usize,
},
EventPorts {
slot: usize,
},
AudioConfigurations {
slot: usize,
},
Bypass {
slot: usize,
},
SetBypass {
slot: usize,
enabled: bool,
},
PrepareAudio {
#[serde_as(as = "wire::RoutedChainConfigDef")]
config: crate::RoutedChainConfig,
memory: shared::Descriptor,
handle: u64,
},
ParameterEvents {
slot: usize,
},
FactoryPresets {
slot: usize,
},
SelectFactoryPreset {
slot: usize,
#[serde_as(as = "wire::FactoryPresetIdDef")]
preset: crate::FactoryPresetId,
},
LoadDiscoveredPreset {
slot: usize,
#[serde_as(as = "wire::PresetLocationDef")]
location: crate::PresetLocation,
load_key: Option<String>,
},
PresetProviders {
bundle: PathBuf,
#[serde_as(as = "wire::HostIdentityDef")]
host: HostIdentity,
},
DiscoverPresets {
bundle: PathBuf,
#[serde_as(as = "wire::HostIdentityDef")]
host: HostIdentity,
#[serde_as(as = "wire::PresetDiscoveryTargetDef")]
target: crate::PresetDiscoveryTarget,
},
Diagnostics,
Scan {
bundle: PathBuf,
#[serde_as(as = "wire::HostIdentityDef")]
host: HostIdentity,
interactive: bool,
},
ListAudioUnits,
ValidateAutomation {
targets: Vec<(usize, u64)>,
},
Load {
#[serde_as(as = "wire::HostIdentityDef")]
host: HostIdentity,
#[serde_as(as = "Vec<wire::PluginRefDef>")]
plugins: Vec<PluginRef>,
activity: u64,
},
LoadState {
slot: usize,
#[serde(
serialize_with = "state::serialize",
deserialize_with = "state::deserialize_cow"
)]
state: Cow<'a, PluginState>,
},
Process {
#[serde_as(as = "wire::BlockContextDef")]
context: crate::BlockContext,
submission: shared::Submission,
},
Parameters {
slot: usize,
},
Capabilities {
slot: usize,
},
SetParameter {
slot: usize,
id: u64,
value: f64,
},
ParameterDetails {
slot: usize,
id: u64,
},
ParameterChoices {
slot: usize,
id: u64,
start: u64,
count: u32,
},
ParameterText {
slot: usize,
id: u64,
value: f64,
},
ParameterFromText {
slot: usize,
id: u64,
text: String,
},
ParameterToPlain {
slot: usize,
id: u64,
value: f64,
},
ParameterToNormalized {
slot: usize,
id: u64,
plain: f64,
},
SetParameterText {
slot: usize,
id: u64,
text: String,
},
SaveState {
slot: usize,
#[serde_as(as = "wire::StatePurposeDef")]
purpose: StatePurpose,
},
RestoreState {
slot: usize,
#[serde(
serialize_with = "state::serialize",
deserialize_with = "state::deserialize_cow"
)]
state: Cow<'a, PluginState>,
#[serde_as(as = "wire::StatePurposeDef")]
purpose: StatePurpose,
},
InspectPreset {
slot: usize,
bytes: Cow<'a, [u8]>,
},
ExportPreset {
slot: usize,
},
ImportPreset {
slot: usize,
bytes: Cow<'a, [u8]>,
},
ReprepareSlot {
slot: usize,
},
Reset,
Timing,
OpenEditor {
slot: usize,
},
CloseEditor {
slot: usize,
},
EditorOpen {
slot: usize,
},
SetRemoteRegion {
#[serde_as(as = "wire::RegionDef")]
region: crate::remote::Region,
},
OpenRemoteEditor {
slot: usize,
},
ShowRemoteEditor {
slot: usize,
},
RemoteSession {
commands: u64,
notices: u64,
menu_timeout_ms: u64,
},
RealtimeInstall {
ring: shared::realtime::RingDescriptor,
tokens: Vec<u64>,
},
RealtimeStart,
RealtimeStop,
RealtimeResync,
Shutdown,
}
impl Request<'_> {
pub fn slot(&self) -> Option<usize> {
match self {
Self::AudioBuses { slot }
| Self::EventPorts { slot }
| Self::AudioConfigurations { slot }
| Self::Bypass { slot }
| Self::SetBypass { slot, .. }
| Self::ParameterEvents { slot }
| Self::FactoryPresets { slot }
| Self::SelectFactoryPreset { slot, .. }
| Self::LoadDiscoveredPreset { slot, .. }
| Self::Parameters { slot }
| Self::Capabilities { slot }
| Self::SetParameter { slot, .. }
| Self::ParameterDetails { slot, .. }
| Self::ParameterChoices { slot, .. }
| Self::ParameterText { slot, .. }
| Self::ParameterFromText { slot, .. }
| Self::ParameterToPlain { slot, .. }
| Self::ParameterToNormalized { slot, .. }
| Self::SetParameterText { slot, .. }
| Self::InspectPreset { slot, .. }
| Self::ExportPreset { slot }
| Self::ImportPreset { slot, .. }
| Self::ReprepareSlot { slot }
| Self::SaveState { slot, .. }
| Self::RestoreState { slot, .. }
| Self::LoadState { slot, .. }
| Self::OpenEditor { slot }
| Self::CloseEditor { slot }
| Self::EditorOpen { slot }
| Self::OpenRemoteEditor { slot }
| Self::ShowRemoteEditor { slot } => Some(*slot),
_ => None,
}
}
}
#[serde_as]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct CommandMessage(#[serde_as(as = "wire::CommandDef")] pub crate::remote::Command);
#[serde_as]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct NoticeMessage(#[serde_as(as = "wire::NoticeDef")] pub crate::remote::Notice);
#[serde_as]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub enum Response {
Changes(#[serde_as(as = "wire::ChangeBatchDef")] crate::ChangeBatch),
AudioBuses(#[serde_as(as = "Vec<wire::AudioBusInfoDef>")] Vec<crate::AudioBusInfo>),
EventPorts(#[serde_as(as = "Vec<wire::EventPortInfoDef>")] Vec<crate::EventPortInfo>),
AudioConfigurations(
#[serde_as(as = "Vec<wire::AudioConfigurationDef>")] Vec<crate::AudioConfiguration>,
),
Bypass(#[serde_as(as = "wire::BypassStateDef")] crate::BypassState),
AudioPrepared {
generation: u64,
#[serde_as(as = "Vec<Vec<wire::AudioBusInfoDef>>")]
buses: Vec<Vec<crate::AudioBusInfo>>,
latency: u32,
#[serde_as(as = "wire::TailDef")]
tail: Tail,
},
ParameterEvents(#[serde_as(as = "wire::ParameterEventBatchDef")] crate::ParameterEventBatch),
FactoryPresets(#[serde_as(as = "Vec<wire::FactoryPresetDef>")] Vec<crate::FactoryPreset>),
PresetProviders(
#[serde_as(as = "Vec<wire::PresetProviderInfoDef>")] Vec<crate::PresetProviderInfo>,
),
DiscoveredPresets(#[serde_as(as = "wire::PresetDiscoveryDef")] crate::PresetDiscovery),
Diagnostics(#[serde_as(as = "wire::DiagnosticBatchDef")] DiagnosticBatch),
ModuleLoaded,
Class(#[serde_as(as = "wire::PluginInfoDef")] PluginInfo),
Loaded(#[serde_as(as = "Vec<wire::PluginInfoDef>")] Vec<PluginInfo>),
Done,
Progress,
Processed {
submission: shared::Submission,
events: usize,
latency: u32,
#[serde_as(as = "wire::TailDef")]
tail: Tail,
},
Parameters(
#[serde_as(as = "Vec<(wire::ParameterInfoDef, _)>")] Vec<(ParameterInfo, Option<f64>)>,
),
Capabilities(#[serde_as(as = "wire::CapabilityReportDef")] CapabilityReport),
ParameterDetails(#[serde_as(as = "wire::ParameterDetailsDef")] crate::ParameterDetails),
ParameterChoices(#[serde_as(as = "wire::ParameterChoicePageDef")] crate::ParameterChoicePage),
ParameterText(String),
ParameterValue(f64),
State(#[serde(with = "state")] PluginState),
PresetInfo(#[serde_as(as = "wire::PresetInfoDef")] PresetInfo),
Preset(Vec<u8>),
StateRestored {
#[serde_as(as = "Option<(_, wire::TailDef)>")]
timing: Option<(u32, Tail)>,
},
Timing {
latency: u32,
#[serde_as(as = "wire::TailDef")]
tail: Tail,
latency_changed: bool,
},
EditorOpen(bool),
RemoteEditorOpened(#[serde_as(as = "wire::OpenedDef")] crate::remote::Opened),
Rejected {
slot: Option<usize>,
#[serde_as(as = "wire::InputErrorDef")]
error: InputError,
},
Failed {
slot: Option<usize>,
#[serde_as(as = "wire::FailureDef")]
failure: Failure,
},
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub enum AudioSamples {
F32(Vec<Vec<f32>>),
F64(Vec<Vec<f64>>),
}
mod framing;
mod state;
mod wire;
pub use framing::{FrameDecoder, MessageReader, MessageWriter, encode_message, write_message};
pub mod shared;
#[cfg(any(test, fuzzing))]
pub mod fuzz;