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: // Converter class for SuperCollider, handles converting to synthdefs and dot ian@0: // graphs ian@0: ian@0: #pragma once ian@0: ian@0: #include "converter.hpp" ian@0: #include "sc_grammar.hpp" ian@0: #include "synth_graph.hpp" ian@0: ian@0: #include ian@0: #include ian@0: #include ian@0: #include ian@0: ian@0: namespace sc { ian@0: ian@0: class Converter : public ConverterInterface { ian@0: const std::vector& commands_; ian@0: std::map variable_map_; ian@0: std::set available_variables_; ian@0: int variables_created_; ian@0: std::stringstream command_script_; ian@0: ian@0: public: ian@0: Converter(const sc::Grammar& grammar) : commands_(grammar.Commands()) {} ian@0: ian@0: // converts a graph to graphviz DOT format ian@0: std::string ToDOT(const sg::Graph& graph); ian@0: ian@0: // generates a supercollider script intended for realtime use ian@0: void Export(const sg::Graph& graph, ian@0: const std::string& export_folder, ian@0: const std::string& export_name); ian@0: ian@0: // converts a graph to a supercollider synthdef ian@0: std::string ToSynthDef(const sg::Graph& graph, ian@0: const std::string& synth_name, ian@0: bool prepare_for_render = true, ian@0: const std::string& synthdef_path = ""); ian@0: ian@0: // generates a supercollider score for the graph ian@0: std::string ToScore(const sg::Graph& graph, ian@0: const std::string& synth_name, ian@0: const std::string& score_variable, ian@0: bool prepare_for_render = true, ian@0: const std::string& synthdef_path = "", ian@0: double render_length = 0); ian@0: ian@0: private: ian@0: void SynthDefVertex(sg::Vertex vertex, const sg::Graph& graph); ian@0: void SynthDefCommand(sg::Vertex vertex, ian@0: const sg::Node& node, ian@0: const sg::Graph& graph); ian@0: void SynthDefSpecial(sg::Vertex vertex, ian@0: const sg::Node& node, ian@0: const sg::Graph& graph); ian@0: ian@0: int AssignVariable(sg::Vertex vertex); ian@0: int GetVariable(sg::Vertex vertex); ian@0: }; ian@0: ian@0: } // sc namespace