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