ian@0
|
1 // Copyright 2011, Ian Hobson.
|
ian@0
|
2 //
|
ian@0
|
3 // This file is part of gpsynth.
|
ian@0
|
4 //
|
ian@0
|
5 // gpsynth is free software: you can redistribute it and/or modify
|
ian@0
|
6 // it under the terms of the GNU General Public License as published by
|
ian@0
|
7 // the Free Software Foundation, either version 3 of the License, or
|
ian@0
|
8 // (at your option) any later version.
|
ian@0
|
9 //
|
ian@0
|
10 // gpsynth is distributed in the hope that it will be useful,
|
ian@0
|
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
ian@0
|
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
ian@0
|
13 // GNU General Public License for more details.
|
ian@0
|
14 //
|
ian@0
|
15 // You should have received a copy of the GNU General Public License
|
ian@0
|
16 // along with gpsynth in the file COPYING.
|
ian@0
|
17 // If not, see http://www.gnu.org/licenses/.
|
ian@0
|
18
|
ian@0
|
19 // The main synth graph classes
|
ian@0
|
20
|
ian@0
|
21 #pragma once
|
ian@0
|
22
|
ian@0
|
23 #include "boost/graph/adjacency_list.hpp"
|
ian@0
|
24
|
ian@0
|
25 #include <string>
|
ian@0
|
26 #include <vector>
|
ian@0
|
27
|
ian@0
|
28 namespace synth_graph {
|
ian@0
|
29
|
ian@0
|
30 enum NodeType {
|
ian@0
|
31 kUnknown = -1,
|
ian@0
|
32 kCommand,
|
ian@0
|
33 kSpecial,
|
ian@0
|
34 kConstant,
|
ian@0
|
35 kParameter
|
ian@0
|
36 };
|
ian@0
|
37
|
ian@0
|
38 enum CommandRate {
|
ian@0
|
39 kAudioRate,
|
ian@0
|
40 kControlRate
|
ian@0
|
41 };
|
ian@0
|
42
|
ian@0
|
43 // Node, attached to each vertex
|
ian@0
|
44 struct Node {
|
ian@0
|
45 int id_;
|
ian@0
|
46 NodeType type_;
|
ian@0
|
47 CommandRate rate_;
|
ian@0
|
48 double constant_value_;
|
ian@0
|
49
|
ian@0
|
50 Node()
|
ian@0
|
51 : id_(-1),
|
ian@0
|
52 type_(kUnknown),
|
ian@0
|
53 rate_(kAudioRate),
|
ian@0
|
54 constant_value_(0)
|
ian@0
|
55 {}
|
ian@0
|
56
|
ian@0
|
57 Node(int id,
|
ian@0
|
58 NodeType type,
|
ian@0
|
59 CommandRate rate = kControlRate)
|
ian@0
|
60 : id_(id),
|
ian@0
|
61 type_(type),
|
ian@0
|
62 rate_(rate),
|
ian@0
|
63 constant_value_(0)
|
ian@0
|
64 {}
|
ian@0
|
65
|
ian@0
|
66 Node(double constant_value)
|
ian@0
|
67 : id_(-1),
|
ian@0
|
68 type_(kConstant),
|
ian@0
|
69 rate_(kControlRate),
|
ian@0
|
70 constant_value_(constant_value)
|
ian@0
|
71 {}
|
ian@0
|
72 };
|
ian@0
|
73
|
ian@0
|
74 // Connection, attached to each edge
|
ian@0
|
75 struct Connection {
|
ian@0
|
76 // input that the edge is connected to
|
ian@0
|
77 int input_;
|
ian@0
|
78 double weight_;
|
ian@0
|
79 double offset_;
|
ian@0
|
80
|
ian@0
|
81 Connection(int input = -1, double weight = 1, double offset = 0)
|
ian@0
|
82 : input_(input),
|
ian@0
|
83 weight_(weight),
|
ian@0
|
84 offset_(offset)
|
ian@0
|
85 {}
|
ian@0
|
86
|
ian@0
|
87 // constructor for connection input is irrelevant
|
ian@0
|
88 Connection(double weight, double offset = 0)
|
ian@0
|
89 : input_(0),
|
ian@0
|
90 weight_(weight),
|
ian@0
|
91 offset_(offset)
|
ian@0
|
92 {}
|
ian@0
|
93
|
ian@0
|
94 bool IsActive() const {
|
ian@0
|
95 return (weight_ != 1) || (offset_ != 0);
|
ian@0
|
96 }
|
ian@0
|
97 };
|
ian@0
|
98
|
ian@0
|
99 enum {
|
ian@0
|
100 kFitnessUnrated = -1
|
ian@0
|
101 };
|
ian@0
|
102
|
ian@0
|
103 // Properties stored with the graph
|
ian@0
|
104 struct GraphProperties {
|
ian@0
|
105 // parameter values
|
ian@0
|
106 std::vector<double> parameters_;
|
ian@0
|
107 // graph id
|
ian@0
|
108 int id_;
|
ian@0
|
109 // measured fitness
|
ian@0
|
110 double fitness_;
|
ian@0
|
111 // rendered output path
|
ian@0
|
112 std::string render_path_;
|
ian@0
|
113 // converted graphviz path
|
ian@0
|
114 std::string dot_path_;
|
ian@0
|
115
|
ian@0
|
116 GraphProperties()
|
ian@0
|
117 : parameters_(0),
|
ian@0
|
118 fitness_(kFitnessUnrated),
|
ian@0
|
119 id_(0)
|
ian@0
|
120 {}
|
ian@0
|
121 };
|
ian@0
|
122
|
ian@0
|
123 // defined as bidirectional to allow access to in_edges of a vertex
|
ian@0
|
124 // we need to use vecS for storage for to_graphviz
|
ian@0
|
125 typedef boost::adjacency_list<boost::vecS,
|
ian@0
|
126 boost::vecS,
|
ian@0
|
127 boost::bidirectionalS,
|
ian@0
|
128 Node,
|
ian@0
|
129 Connection,
|
ian@0
|
130 GraphProperties> Graph;
|
ian@0
|
131
|
ian@0
|
132 typedef boost::graph_traits<Graph>::vertex_descriptor Vertex;
|
ian@0
|
133 typedef boost::graph_traits<Graph>::vertex_iterator VertexIterator;
|
ian@0
|
134 typedef boost::graph_traits<Graph>::edge_descriptor Edge;
|
ian@0
|
135 typedef boost::graph_traits<Graph>::edge_iterator EdgeIterator;
|
ian@0
|
136 typedef boost::graph_traits<Graph>::in_edge_iterator InEdgeIterator;
|
ian@0
|
137
|
ian@0
|
138 } // synth_graph namespace
|
ian@0
|
139 namespace sg = synth_graph;
|