feat: load pipeline graph from graph.json

studio-manager now accepts an optional path argument:
  dmf-studio-manager graph.json

load_graph() parses nodes and edges from JSON, generating fresh UUIDs
for each MXL flow on every launch. Falls back to hardcoded build_graph()
when no argument is given.

graph.json at repo root defines the current testpattern→ndiout pipeline.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
JohannesItten
2026-07-03 10:36:20 +03:00
parent f2515b7ce2
commit 2b0dfb10c6
2 changed files with 60 additions and 1 deletions
+42 -1
View File
@@ -5,6 +5,8 @@
#include <cstdio>
#include <cstdlib>
#include <filesystem>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <fcntl.h>
@@ -37,6 +39,45 @@ static std::string gen_uuid() {
// --- Pipeline graph ----------------------------------------------------------
static dmf::FlowGraph load_graph(const std::string& path) {
std::ifstream f(path);
if (!f) {
fprintf(stderr, "[studio-manager] cannot open graph file: %s\n", path.c_str());
exit(1);
}
std::ostringstream ss;
ss << f.rdbuf();
auto j = nlohmann::json::parse(ss.str(), nullptr, /*allow_exceptions=*/false);
if (j.is_discarded()) {
fprintf(stderr, "[studio-manager] invalid JSON in %s\n", path.c_str());
exit(1);
}
dmf::FlowGraph g;
for (const auto& n : j.at("nodes")) {
g.nodes.push_back({
n.at("id").get<std::string>(),
n.at("type").get<std::string>(),
n.value("params", nlohmann::json::object())
});
}
for (const auto& e : j.at("edges")) {
g.edges.push_back({
gen_uuid(),
e.at("from").get<std::string>(),
e.at("from_port").get<std::string>(),
e.value("to", std::string{}),
e.value("to_port", std::string{}),
e.at("format")
});
}
fprintf(stderr, "[studio-manager] loaded graph from %s (%zu nodes, %zu edges)\n",
path.c_str(), g.nodes.size(), g.edges.size());
return g;
}
static dmf::FlowGraph build_graph() {
dmf::FlowGraph g;
const std::string tp_video_flow = gen_uuid();
@@ -164,7 +205,7 @@ int main(int argc, char* argv[]) {
}
// --- Build and launch the pipeline graph ---
const dmf::FlowGraph graph = build_graph();
const dmf::FlowGraph graph = (argc > 1) ? load_graph(argv[1]) : build_graph();
for (const auto& e : graph.edges)
fprintf(stderr, "[studio-manager] flow %s → %s id=%s\n",