pub struct Preset {
pub name: String,
pub description: String,
pub author: Option<String>,
pub tags: Vec<String>,
pub nodes: Vec<NodeConfig>,
pub connections: Vec<Connection>,
pub metadata: HashMap<String, String>,
}Expand description
A complete preset containing graph structure and parameter values.
§Example
use aether_core::preset::Preset;
let mut preset = Preset::new("My Synth", "A simple synthesizer");
// Add nodes
preset.add_node(0, "Oscillator");
preset.add_node(1, "Filter");
preset.add_node(2, "Gain");
// Add connections
preset.add_connection(0, 1, 0); // Osc -> Filter
preset.add_connection(1, 2, 0); // Filter -> Gain
// Set parameters
preset.set_param(0, 0, 440.0); // Oscillator frequency
preset.set_param(1, 0, 1000.0); // Filter cutoff
preset.set_param(2, 0, 0.75); // Gain level
// Serialize to JSON
let json = preset.to_json().unwrap();
println!("{}", json);
// Deserialize from JSON
let loaded = Preset::from_json(&json).unwrap();
assert_eq!(loaded.name, "My Synth");Fields§
§name: StringPreset name
description: StringPreset description
Author name (optional)
Tags for categorization
nodes: Vec<NodeConfig>Nodes in the graph
connections: Vec<Connection>Connections between nodes
metadata: HashMap<String, String>Metadata (BPM, key, etc.)
Implementations§
Source§impl Preset
impl Preset
Sourcepub fn add_connection(&mut self, src_id: usize, dst_id: usize, slot: usize)
pub fn add_connection(&mut self, src_id: usize, dst_id: usize, slot: usize)
Adds a connection between two nodes.
§Arguments
src_id- Source node IDdst_id- Destination node IDslot- Input slot on destination node
§Example
use aether_core::preset::Preset;
let mut preset = Preset::new("Test", "Test preset");
preset.add_node(0, "Oscillator");
preset.add_node(1, "Filter");
preset.add_connection(0, 1, 0); // Osc -> Filter input 0
assert_eq!(preset.connections.len(), 1);Sourcepub fn set_param(&mut self, node_id: usize, param_index: usize, value: f32)
pub fn set_param(&mut self, node_id: usize, param_index: usize, value: f32)
Sets a parameter value for a node.
§Arguments
node_id- Node IDparam_index- Parameter indexvalue- Parameter value
§Example
use aether_core::preset::Preset;
let mut preset = Preset::new("Test", "Test preset");
preset.add_node(0, "Oscillator");
preset.set_param(0, 0, 440.0); // Set frequency to 440 Hz
preset.set_param(0, 1, 0.5); // Set amplitude to 0.5Sourcepub fn set_position(&mut self, node_id: usize, x: f32, y: f32)
pub fn set_position(&mut self, node_id: usize, x: f32, y: f32)
Sourcepub fn to_json(&self) -> Result<String, Error>
pub fn to_json(&self) -> Result<String, Error>
Serializes the preset to JSON.
§Returns
JSON string representation of the preset.
§Errors
Returns an error if serialization fails.
§Example
use aether_core::preset::Preset;
let mut preset = Preset::new("Test", "Test preset");
preset.add_node(0, "Oscillator");
let json = preset.to_json().unwrap();
assert!(json.contains("\"name\":\"Test\""));Sourcepub fn from_json(json: &str) -> Result<Self, Error>
pub fn from_json(json: &str) -> Result<Self, Error>
Deserializes a preset from JSON.
§Arguments
json- JSON string
§Returns
Deserialized preset.
§Errors
Returns an error if deserialization fails.
§Example
use aether_core::preset::Preset;
let json = r#"{
"name": "Test",
"description": "Test preset",
"nodes": [],
"connections": []
}"#;
let preset = Preset::from_json(json).unwrap();
assert_eq!(preset.name, "Test");Sourcepub fn validate(&self) -> Result<(), String>
pub fn validate(&self) -> Result<(), String>
Validates the preset structure.
Checks for:
- Duplicate node IDs
- Invalid connections (referencing non-existent nodes)
- Empty preset name
§Returns
Ok(()) if valid, Err(String) with error message if invalid.
§Example
use aether_core::preset::Preset;
let mut preset = Preset::new("Test", "Test preset");
preset.add_node(0, "Oscillator");
preset.add_node(1, "Filter");
preset.add_connection(0, 1, 0);
assert!(preset.validate().is_ok());
// Invalid connection
preset.add_connection(0, 99, 0); // Node 99 doesn't exist
assert!(preset.validate().is_err());Trait Implementations§
Source§impl<'de> Deserialize<'de> for Preset
impl<'de> Deserialize<'de> for Preset
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Preset
impl RefUnwindSafe for Preset
impl Send for Preset
impl Sync for Preset
impl Unpin for Preset
impl UnsafeUnpin for Preset
impl UnwindSafe for Preset
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more