forked from sudip-mondal-2002/Amplitron
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaudio_graph.h
More file actions
82 lines (63 loc) · 1.94 KB
/
Copy pathaudio_graph.h
File metadata and controls
82 lines (63 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#pragma once
#include <memory>
#include <string>
#include <vector>
namespace Amplitron {
// Forward declaration of your existing base pedal agent interface
class Effect;
enum class NodeRoutingType {
StandardEffect,
Splitter,
Mixer,
MergeSum = Mixer
};
struct DSPNode {
int id;
std::string name;
NodeRoutingType routing_type;
std::shared_ptr<Effect> pedal;
std::vector<int> input_pin_ids;
std::vector<int> output_pin_ids;
bool is_graph_input = false;
bool is_graph_output = false;
bool is_reachable = true;
float x = 0.0f;
float y = 0.0f;
};
struct GraphLink {
int id;
int source_pin_id; // Mapping from Output Pin
int dest_pin_id; // Mapping to Input Pin
};
class AudioGraph {
public:
AudioGraph() = default;
~AudioGraph() = default;
// Graph Construction Interface
int add_node(const std::string &name, NodeRoutingType type,
std::shared_ptr<Effect> pedal = nullptr, int num_inputs = 0);
bool remove_node(int node_id);
int add_link(int source_pin_id, int dest_pin_id);
bool remove_link(int link_id);
void set_node_as_input(int node_id, bool is_input);
void set_node_as_output(int node_id, bool is_output);
void set_node_position(int node_id, float x, float y);
// Topological Order & Loop Validation Core
bool rebuild_topology();
// For Undo/Redo System (forces cache reload)
void restore_node(const DSPNode& node);
void restore_link(const GraphLink& link);
// Accessors
const std::vector<int> &get_sorted_nodes() const { return sorted_node_ids_; }
const std::vector<DSPNode> &get_nodes() const { return nodes_; }
const std::vector<GraphLink> &get_links() const { return links_; }
int get_node_from_pin(int pin_id) const;
const DSPNode *find_node(int node_id) const;
private:
size_t get_node_index(int node_id) const;
int next_id_ = 1;
std::vector<DSPNode> nodes_;
std::vector<GraphLink> links_;
std::vector<int> sorted_node_ids_;
};
} // namespace Amplitron