Add script node
This commit is contained in:
@@ -7,6 +7,7 @@ use crate::asset_folder::AssetFolderTree;
|
||||
use crate::clip::{AudioClip, ClipInstance, ImageAsset, VideoClip, VectorClip};
|
||||
use crate::effect::EffectDefinition;
|
||||
use crate::layer::AnyLayer;
|
||||
use crate::script::ScriptDefinition;
|
||||
use crate::layout::LayoutNode;
|
||||
use crate::shape::ShapeColor;
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -146,6 +147,14 @@ pub struct Document {
|
||||
#[serde(default)]
|
||||
pub effect_folders: AssetFolderTree,
|
||||
|
||||
/// BeamDSP script definitions (audio DSP scripts for node graph)
|
||||
#[serde(default)]
|
||||
pub script_definitions: HashMap<Uuid, ScriptDefinition>,
|
||||
|
||||
/// Folder organization for script definitions
|
||||
#[serde(default)]
|
||||
pub script_folders: AssetFolderTree,
|
||||
|
||||
/// Current UI layout state (serialized for save/load)
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub ui_layout: Option<LayoutNode>,
|
||||
@@ -181,6 +190,8 @@ impl Default for Document {
|
||||
audio_folders: AssetFolderTree::new(),
|
||||
image_folders: AssetFolderTree::new(),
|
||||
effect_folders: AssetFolderTree::new(),
|
||||
script_definitions: HashMap::new(),
|
||||
script_folders: AssetFolderTree::new(),
|
||||
ui_layout: None,
|
||||
ui_layout_base: None,
|
||||
current_time: 0.0,
|
||||
@@ -494,6 +505,26 @@ impl Document {
|
||||
self.effect_definitions.values()
|
||||
}
|
||||
|
||||
// === SCRIPT DEFINITION METHODS ===
|
||||
|
||||
pub fn add_script_definition(&mut self, definition: ScriptDefinition) -> Uuid {
|
||||
let id = definition.id;
|
||||
self.script_definitions.insert(id, definition);
|
||||
id
|
||||
}
|
||||
|
||||
pub fn get_script_definition(&self, id: &Uuid) -> Option<&ScriptDefinition> {
|
||||
self.script_definitions.get(id)
|
||||
}
|
||||
|
||||
pub fn get_script_definition_mut(&mut self, id: &Uuid) -> Option<&mut ScriptDefinition> {
|
||||
self.script_definitions.get_mut(id)
|
||||
}
|
||||
|
||||
pub fn script_definitions(&self) -> impl Iterator<Item = &ScriptDefinition> {
|
||||
self.script_definitions.values()
|
||||
}
|
||||
|
||||
// === CLIP OVERLAP DETECTION METHODS ===
|
||||
|
||||
/// Get the duration of any clip type by ID
|
||||
|
||||
@@ -20,6 +20,7 @@ pub mod instance_group;
|
||||
pub mod effect;
|
||||
pub mod effect_layer;
|
||||
pub mod effect_registry;
|
||||
pub mod script;
|
||||
pub mod document;
|
||||
pub mod renderer;
|
||||
pub mod video;
|
||||
|
||||
@@ -33,8 +33,9 @@ pub enum PaneType {
|
||||
PresetBrowser,
|
||||
/// Asset library for browsing clips
|
||||
AssetLibrary,
|
||||
/// WGSL shader code editor for custom effects
|
||||
ShaderEditor,
|
||||
/// Code editor for shaders and DSP scripts
|
||||
#[serde(alias = "shaderEditor")]
|
||||
ScriptEditor,
|
||||
}
|
||||
|
||||
impl PaneType {
|
||||
@@ -51,7 +52,7 @@ impl PaneType {
|
||||
PaneType::NodeEditor => "Node Editor",
|
||||
PaneType::PresetBrowser => "Instrument Browser",
|
||||
PaneType::AssetLibrary => "Asset Library",
|
||||
PaneType::ShaderEditor => "Shader Editor",
|
||||
PaneType::ScriptEditor => "Script Editor",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +71,7 @@ impl PaneType {
|
||||
PaneType::NodeEditor => "node-editor.svg",
|
||||
PaneType::PresetBrowser => "stage.svg", // TODO: needs own icon
|
||||
PaneType::AssetLibrary => "stage.svg", // TODO: needs own icon
|
||||
PaneType::ShaderEditor => "node-editor.svg", // TODO: needs own icon
|
||||
PaneType::ScriptEditor => "node-editor.svg", // TODO: needs own icon
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +89,7 @@ impl PaneType {
|
||||
"nodeeditor" => Some(PaneType::NodeEditor),
|
||||
"presetbrowser" => Some(PaneType::PresetBrowser),
|
||||
"assetlibrary" => Some(PaneType::AssetLibrary),
|
||||
"shadereditor" => Some(PaneType::ShaderEditor),
|
||||
"shadereditor" | "scripteditor" => Some(PaneType::ScriptEditor),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@@ -106,7 +107,7 @@ impl PaneType {
|
||||
PaneType::VirtualPiano,
|
||||
PaneType::PresetBrowser,
|
||||
PaneType::AssetLibrary,
|
||||
PaneType::ShaderEditor,
|
||||
PaneType::ScriptEditor,
|
||||
]
|
||||
}
|
||||
|
||||
@@ -123,7 +124,7 @@ impl PaneType {
|
||||
PaneType::NodeEditor => "nodeEditor",
|
||||
PaneType::PresetBrowser => "presetBrowser",
|
||||
PaneType::AssetLibrary => "assetLibrary",
|
||||
PaneType::ShaderEditor => "shaderEditor",
|
||||
PaneType::ScriptEditor => "scriptEditor",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/// BeamDSP script definitions for the asset library
|
||||
///
|
||||
/// Scripts are audio DSP programs written in the BeamDSP language.
|
||||
/// They live in the asset library and can be referenced by Script nodes.
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
/// A BeamDSP script definition stored in the document
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct ScriptDefinition {
|
||||
pub id: Uuid,
|
||||
pub name: String,
|
||||
pub source: String,
|
||||
/// Folder this script belongs to (None = root)
|
||||
#[serde(default)]
|
||||
pub folder_id: Option<Uuid>,
|
||||
}
|
||||
|
||||
impl ScriptDefinition {
|
||||
pub fn new(name: String, source: String) -> Self {
|
||||
Self {
|
||||
id: Uuid::new_v4(),
|
||||
name,
|
||||
source,
|
||||
folder_id: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_id(id: Uuid, name: String, source: String) -> Self {
|
||||
Self {
|
||||
id,
|
||||
name,
|
||||
source,
|
||||
folder_id: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user