ian@0: // Copyright 2011, Ian Hobson. ian@0: // ian@0: // This file is part of gpsynth. ian@0: // ian@0: // gpsynth is free software: you can redistribute it and/or modify ian@0: // it under the terms of the GNU General Public License as published by ian@0: // the Free Software Foundation, either version 3 of the License, or ian@0: // (at your option) any later version. ian@0: // ian@0: // gpsynth is distributed in the hope that it will be useful, ian@0: // but WITHOUT ANY WARRANTY; without even the implied warranty of ian@0: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ian@0: // GNU General Public License for more details. ian@0: // ian@0: // You should have received a copy of the GNU General Public License ian@0: // along with gpsynth in the file COPYING. ian@0: // If not, see http://www.gnu.org/licenses/. ian@0: ian@0: // The main synth graph classes ian@0: ian@0: #pragma once ian@0: ian@0: #include "boost/graph/adjacency_list.hpp" ian@0: ian@0: #include ian@0: #include ian@0: ian@0: namespace synth_graph { ian@0: ian@0: enum NodeType { ian@0: kUnknown = -1, ian@0: kCommand, ian@0: kSpecial, ian@0: kConstant, ian@0: kParameter ian@0: }; ian@0: ian@0: enum CommandRate { ian@0: kAudioRate, ian@0: kControlRate ian@0: }; ian@0: ian@0: // Node, attached to each vertex ian@0: struct Node { ian@0: int id_; ian@0: NodeType type_; ian@0: CommandRate rate_; ian@0: double constant_value_; ian@0: ian@0: Node() ian@0: : id_(-1), ian@0: type_(kUnknown), ian@0: rate_(kAudioRate), ian@0: constant_value_(0) ian@0: {} ian@0: ian@0: Node(int id, ian@0: NodeType type, ian@0: CommandRate rate = kControlRate) ian@0: : id_(id), ian@0: type_(type), ian@0: rate_(rate), ian@0: constant_value_(0) ian@0: {} ian@0: ian@0: Node(double constant_value) ian@0: : id_(-1), ian@0: type_(kConstant), ian@0: rate_(kControlRate), ian@0: constant_value_(constant_value) ian@0: {} ian@0: }; ian@0: ian@0: // Connection, attached to each edge ian@0: struct Connection { ian@0: // input that the edge is connected to ian@0: int input_; ian@0: double weight_; ian@0: double offset_; ian@0: ian@0: Connection(int input = -1, double weight = 1, double offset = 0) ian@0: : input_(input), ian@0: weight_(weight), ian@0: offset_(offset) ian@0: {} ian@0: ian@0: // constructor for connection input is irrelevant ian@0: Connection(double weight, double offset = 0) ian@0: : input_(0), ian@0: weight_(weight), ian@0: offset_(offset) ian@0: {} ian@0: ian@0: bool IsActive() const { ian@0: return (weight_ != 1) || (offset_ != 0); ian@0: } ian@0: }; ian@0: ian@0: enum { ian@0: kFitnessUnrated = -1 ian@0: }; ian@0: ian@0: // Properties stored with the graph ian@0: struct GraphProperties { ian@0: // parameter values ian@0: std::vector parameters_; ian@0: // graph id ian@0: int id_; ian@0: // measured fitness ian@0: double fitness_; ian@0: // rendered output path ian@0: std::string render_path_; ian@0: // converted graphviz path ian@0: std::string dot_path_; ian@0: ian@0: GraphProperties() ian@0: : parameters_(0), ian@0: fitness_(kFitnessUnrated), ian@0: id_(0) ian@0: {} ian@0: }; ian@0: ian@0: // defined as bidirectional to allow access to in_edges of a vertex ian@0: // we need to use vecS for storage for to_graphviz ian@0: typedef boost::adjacency_list Graph; ian@0: ian@0: typedef boost::graph_traits::vertex_descriptor Vertex; ian@0: typedef boost::graph_traits::vertex_iterator VertexIterator; ian@0: typedef boost::graph_traits::edge_descriptor Edge; ian@0: typedef boost::graph_traits::edge_iterator EdgeIterator; ian@0: typedef boost::graph_traits::in_edge_iterator InEdgeIterator; ian@0: ian@0: } // synth_graph namespace ian@0: namespace sg = synth_graph;