annotate src/sc_converter.hpp @ 0:add35537fdbb tip

Initial import
author irh <ian.r.hobson@gmail.com>
date Thu, 25 Aug 2011 11:05:55 +0100
parents
children
rev   line source
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 // Converter class for SuperCollider, handles converting to synthdefs and dot
ian@0 20 // graphs
ian@0 21
ian@0 22 #pragma once
ian@0 23
ian@0 24 #include "converter.hpp"
ian@0 25 #include "sc_grammar.hpp"
ian@0 26 #include "synth_graph.hpp"
ian@0 27
ian@0 28 #include <map>
ian@0 29 #include <set>
ian@0 30 #include <sstream>
ian@0 31 #include <vector>
ian@0 32
ian@0 33 namespace sc {
ian@0 34
ian@0 35 class Converter : public ConverterInterface {
ian@0 36 const std::vector<sc::Command>& commands_;
ian@0 37 std::map<sg::Vertex, int> variable_map_;
ian@0 38 std::set<int> available_variables_;
ian@0 39 int variables_created_;
ian@0 40 std::stringstream command_script_;
ian@0 41
ian@0 42 public:
ian@0 43 Converter(const sc::Grammar& grammar) : commands_(grammar.Commands()) {}
ian@0 44
ian@0 45 // converts a graph to graphviz DOT format
ian@0 46 std::string ToDOT(const sg::Graph& graph);
ian@0 47
ian@0 48 // generates a supercollider script intended for realtime use
ian@0 49 void Export(const sg::Graph& graph,
ian@0 50 const std::string& export_folder,
ian@0 51 const std::string& export_name);
ian@0 52
ian@0 53 // converts a graph to a supercollider synthdef
ian@0 54 std::string ToSynthDef(const sg::Graph& graph,
ian@0 55 const std::string& synth_name,
ian@0 56 bool prepare_for_render = true,
ian@0 57 const std::string& synthdef_path = "");
ian@0 58
ian@0 59 // generates a supercollider score for the graph
ian@0 60 std::string ToScore(const sg::Graph& graph,
ian@0 61 const std::string& synth_name,
ian@0 62 const std::string& score_variable,
ian@0 63 bool prepare_for_render = true,
ian@0 64 const std::string& synthdef_path = "",
ian@0 65 double render_length = 0);
ian@0 66
ian@0 67 private:
ian@0 68 void SynthDefVertex(sg::Vertex vertex, const sg::Graph& graph);
ian@0 69 void SynthDefCommand(sg::Vertex vertex,
ian@0 70 const sg::Node& node,
ian@0 71 const sg::Graph& graph);
ian@0 72 void SynthDefSpecial(sg::Vertex vertex,
ian@0 73 const sg::Node& node,
ian@0 74 const sg::Graph& graph);
ian@0 75
ian@0 76 int AssignVariable(sg::Vertex vertex);
ian@0 77 int GetVariable(sg::Vertex vertex);
ian@0 78 };
ian@0 79
ian@0 80 } // sc namespace