Skip to content

Commit

Permalink
wip: add comment areas to node editor
Browse files Browse the repository at this point in the history
Closes #228
  • Loading branch information
maxjoehnk committed Nov 19, 2024
1 parent 131a869 commit 5847426
Show file tree
Hide file tree
Showing 18 changed files with 1,787 additions and 1,115 deletions.
11 changes: 11 additions & 0 deletions crates/api/protos/nodes.proto
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ message Nodes {
repeated NodeConnection channels = 2;
// Flat list of all nodes
repeated Node all_nodes = 3;
repeated NodeCommentArea comments = 4;
}

message AvailableNodes {
Expand Down Expand Up @@ -357,3 +358,13 @@ message Port {
ChannelProtocol protocol = 2;
bool multiple = 3;
}

message NodeCommentArea {
double width = 1;
double height = 2;
NodeDesigner designer = 3;
optional string label = 4;
bool show_background = 5;
bool show_border = 6;
optional string parent = 7;
}
2 changes: 2 additions & 0 deletions crates/api/src/handlers/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ impl<R: RuntimeApi> NodesHandler<R> {

let nodes = self.runtime.execute_query(ListNodesQuery).unwrap();
let links = self.runtime.execute_query(ListLinksQuery).unwrap();
let comments = self.runtime.execute_query(ListCommentsQuery).unwrap();
res.comments = comments.into_iter().map(Into::into).collect();

for node in nodes.iter() {
let node: Node = node.clone().into();
Expand Down
14 changes: 14 additions & 0 deletions crates/api/src/mappings/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,3 +555,17 @@ impl From<mizer_node::NodeCategory> for NodeCategory {
}
}
}

impl From<mizer_node::NodeCommentArea> for NodeCommentArea {
fn from(comment_area: mizer_node::NodeCommentArea) -> Self {
Self {
parent: comment_area.parent.map(|path| path.to_string()),
designer: comment_area.designer.into(),
width: comment_area.width,
height: comment_area.height,
label: comment_area.label,
show_background: comment_area.show_background,
show_border: comment_area.show_border,
}
}
}
4 changes: 3 additions & 1 deletion crates/projects/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use serde::{Deserialize, Serialize};
use mizer_fixtures::fixture::FixtureConfiguration;
use mizer_fixtures::programmer::Group;
use mizer_layouts::ControlConfig;
use mizer_node::{NodeDesigner, NodePath, PortId};
use mizer_node::{NodeCommentArea, NodeDesigner, NodePath, PortId};
use mizer_plan::Plan;
use mizer_protocol_mqtt::MqttAddress;
use mizer_protocol_osc::OscAddress;
Expand Down Expand Up @@ -54,6 +54,8 @@ pub struct Project {
#[serde(default)]
pub channels: Vec<Channel>,
#[serde(default)]
pub comments: Vec<NodeCommentArea>,
#[serde(default)]
pub media: Media,
#[serde(default)]
pub layouts: IndexMap<String, Vec<ControlConfig>>,
Expand Down
1 change: 1 addition & 0 deletions crates/runtime/commander/executor/src/queries/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ query_impl! {
GetNodeQuery,
ListLinksQuery,
ListAvailableNodesQuery,
ListCommentsQuery,
}

impl QueryImpl {
Expand Down
11 changes: 11 additions & 0 deletions crates/runtime/pipeline/node/src/comment_area.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use crate::{NodeDesigner, NodePath};

pub struct NodeCommentArea {
pub parent: Option<NodePath>,
pub designer: NodeDesigner,
pub width: f64,
pub height: f64,
pub label: Option<String>,
pub show_background: bool,
pub show_border: bool,
}
2 changes: 2 additions & 0 deletions crates/runtime/pipeline/node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ pub use mizer_debug_ui::DebugUiDrawHandle;
pub use mizer_injector::Injector;
pub use mizer_ports::{port_types, Color, PortId, PortType};

pub use self::comment_area::*;
pub use self::context::*;
pub use self::introspection::*;
pub use self::path::*;
pub use self::ports::*;
pub use self::preview::*;
pub use self::settings::*;

mod comment_area;
mod context;
mod path;
mod ports;
Expand Down
1 change: 1 addition & 0 deletions crates/runtime/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use pinboard::NonEmptyPinboard;

use mizer_clock::ClockSnapshot;
use mizer_layouts::Layout;
use mizer_node::NodeCommentArea;
use mizer_plan::Plan;
use mizer_status_bus::StatusBus;

Expand Down
15 changes: 11 additions & 4 deletions crates/runtime/src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ use anyhow::Context;
use indexmap::IndexMap;
use mizer_clock::{BoxedClock, ClockFrame};
use mizer_debug_ui_impl::{Injector, NodeStateAccess};
use mizer_node::{
NodeDesigner, NodeLink, NodeMetadata, NodePath, NodeSetting, NodeType, PipelineNode,
PortDirection, PortMetadata, ProcessingNode,
};
use mizer_node::{NodeCommentArea, NodeDesigner, NodeLink, NodeMetadata, NodePath, NodeSetting, NodeType, PipelineNode, PortDirection, PortMetadata, ProcessingNode};
use mizer_nodes::{ContainerNode, Node, NodeDowncast, NodeExt};
use mizer_pipeline::{NodePortReader, NodePreviewRef, PipelineWorker, ProcessingNodeExt};
use mizer_ports::PortId;
Expand All @@ -24,6 +21,7 @@ use std::sync::Arc;
pub struct Pipeline {
nodes: IndexMap<NodePath, NodeState>,
links: Vec<NodeLink>,
comments: Vec<NodeCommentArea>,
worker: PipelineWorker,
}

Expand All @@ -40,6 +38,7 @@ impl Pipeline {
Self {
nodes: IndexMap::new(),
links: Vec::new(),
comments: Vec::new(),
worker: PipelineWorker::new(Arc::new(NonEmptyPinboard::new(Default::default()))),
}
}
Expand Down Expand Up @@ -188,6 +187,10 @@ impl Pipeline {
pub(crate) fn list_links(&self) -> impl Iterator<Item = &NodeLink> {
self.links.iter()
}

pub(crate) fn list_comments(&self) -> impl Iterator<Item = &NodeCommentArea> {
self.comments.iter()
}

pub(crate) fn delete_link(&mut self, link: &NodeLink) {
self.remove_links_if(|l| l == link);
Expand Down Expand Up @@ -712,6 +715,8 @@ impl Pipeline {
local: true,
})?;
}
self.comments = project.comments.clone();

Ok(())
}

Expand All @@ -737,11 +742,13 @@ impl Pipeline {
}
})
.collect();
project.comments = self.comments.clone();
}

pub fn clear(&mut self) {
self.nodes.clear();
self.links.clear();
self.comments.clear();
self.worker = PipelineWorker::new(Arc::new(NonEmptyPinboard::new(Default::default())));
}
}
Expand Down
24 changes: 24 additions & 0 deletions crates/runtime/src/queries/list_comments.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use crate::commands::StaticNodeDescriptor;
use crate::Pipeline;
use mizer_commander::{Query, Ref};
use serde::{Deserialize, Serialize};
use mizer_node::NodeCommentArea;

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct ListCommentsQuery;

impl<'a> Query<'a> for ListCommentsQuery {
type Dependencies = Ref<Pipeline>;
type Result = Vec<NodeCommentArea>;

#[profiling::function]
fn query(&self, pipeline: &Pipeline) -> anyhow::Result<Self::Result> {
let comments = pipeline.list_comments().cloned().collect();

Ok(comments)
}

fn requires_main_loop(&self) -> bool {
true
}
}
2 changes: 2 additions & 0 deletions crates/runtime/src/queries/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ pub use get_node::*;
pub use list_available_nodes::*;
pub use list_links::*;
pub use list_nodes::*;
pub use list_comments::*;

mod get_node;
mod list_available_nodes;
mod list_links;
mod list_nodes;
mod list_comments;
Loading

0 comments on commit 5847426

Please sign in to comment.