comparison src/synth_graph.hpp @ 0:add35537fdbb tip

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