feat: ship the Furumi OpenDeck plugin for Windows, macOS and Linux

This commit is contained in:
ab committed 2026-11-28 18:09:48 +02:00
1 parent 57e60a7fe3
commit 79df5edd8c
72 files changed
+9785 -71

No files matched your search

+13
View File
@@ -0,0 +1,13 @@
[package]
name = "furumi-control-protocol"
version = "0.1.0"
edition = "2024"
rust-version = "1.97"
license = "WTFPL"
[dependencies]
directories = "6"
serde = { version = "1", features = ["derive"] }
[dev-dependencies]
serde_json = "1"
+195
View File
@@ -0,0 +1,195 @@
//! Versioned, device-local control API. This is not a device-sync wire protocol.
use std::path::PathBuf;
use serde::{Deserialize, Serialize};
pub const API_VERSION: u16 = 1;
pub const MAX_MESSAGE_BYTES: usize = 2 * 1024 * 1024;
/// Third-octave levels, from 20 Hz to 20 kHz, quantized to 0..=255.
pub const SPECTRUM_BANDS: usize = 31;
pub fn discovery_path() -> Option<PathBuf> {
directories::ProjectDirs::from("", "", "furumi")
.map(|dirs| dirs.data_local_dir().join("control-endpoint.json"))
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Discovery {
pub api_version: u16,
pub port: u16,
pub token: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct Snapshot {
pub api_version: u16,
#[serde(default, skip_serializing_if = "is_false")]
pub spectrum_supported: bool,
pub revision: u64,
pub updated_at_ms: u64,
pub role: Role,
pub self_device_id: String,
pub active_device_id: Option<String>,
pub active_device_name: Option<String>,
pub playing: bool,
pub paused: bool,
pub position_secs: f64,
pub duration_secs: f64,
pub volume: u8,
pub shuffle: bool,
pub repeat: Repeat,
pub radio: Radio,
/// Optional for backward compatibility with local API servers predating
/// remote command acknowledgement. This is not a device-sync wire field.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub remote_command: Option<RemoteCommand>,
pub track: Option<Track>,
pub devices: Vec<Device>,
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum Role {
Active,
Control,
Jam,
}
#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum Repeat {
#[default]
Off,
All,
One,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
pub struct Radio {
pub id: u64,
pub state: RadioState,
pub error: Option<String>,
}
#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum RadioState {
#[default]
Idle,
Searching,
Starting,
Playing,
Failed,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
pub struct RemoteCommand {
pub id: u64,
pub state: RemoteCommandState,
pub error: Option<String>,
}
#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum RemoteCommandState {
#[default]
Idle,
Pending,
Confirmed,
Failed,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct Track {
/// Stable playback identity, including podcast episodes (never a row ID).
pub key: String,
pub title: String,
pub artist: String,
pub album: String,
pub year: Option<i32>,
/// Opaque reference; clients cannot ask the server to read arbitrary paths.
pub artwork_id: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct Device {
pub id: String,
pub name: String,
pub is_self: bool,
pub active: bool,
pub online: bool,
pub can_transfer: bool,
pub unavailable_reason: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum ClientMessage {
Authenticate {
token: String,
api_version: u16,
},
Command {
id: String,
command: Command,
},
/// Local to this authenticated connection. Only request after the server
/// advertises spectrum_supported.
SubscribeSpectrum {
enabled: bool,
},
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum Command {
PlayPause,
Next,
Previous,
Seek {
seconds: i64,
},
VolumeUp,
VolumeDown,
ToggleShuffle,
CycleRepeat,
StartRadio,
Transfer {
device_id: String,
},
Artwork {
artwork_id: String,
#[serde(default, skip_serializing_if = "is_false")]
federation: bool,
},
}
fn is_false(value: &bool) -> bool {
!*value
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum ServerMessage {
Snapshot {
snapshot: Box<Snapshot>,
},
/// A new epoch invalidates visual history. No bands means clear the display.
/// Only explicit subscribers receive this message.
Spectrum {
epoch: u64,
sequence: u64,
bands: Option<[u8; SPECTRUM_BANDS]>,
},
/// `accepted` means dispatched locally, not acknowledged by a remote engine.
Result {
id: String,
accepted: bool,
error: Option<String>,
},
Artwork {
id: String,
artwork_id: String,
png_base64: Option<String>,
},
}