1 // supercollider-style synthdef
2 // Copyright (C) 2008, 2009 Tim Blechmann
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; see the file COPYING. If not, write to
16 // the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 // Boston, MA 02111-1307, USA.
19 #ifndef SC_SYNTHDEF_HPP
20 #define SC_SYNTHDEF_HPP
26 #include <boost/cstdint.hpp>
27 #include <boost/filesystem/path.hpp>
29 #include "utilities/malloc_aligned.hpp"
30 #include "utilities/named_hash_entry.hpp"
41 typedef c_string string
;
42 typedef std::vector
<float, aligned_allocator
<float> > fvector
;
43 typedef std::vector
<c_string
, aligned_allocator
<string
> > svector
;
45 typedef boost::int16_t int16
;
46 typedef boost::int32_t int32
;
48 typedef std::vector
<char, aligned_allocator
<char> > char_vector
;
51 typedef std::map
<string
, int, std::less
<string
>, aligned_allocator
<string
> > parameter_map_t
;
55 input_spec(int16_t source
, int16_t index
):
56 source(source
), index(index
)
59 bool operator<(input_spec
const & rhs
) const
61 if (source
< rhs
.source
)
63 if (source
> rhs
.source
)
65 return index
< rhs
.index
;
68 int16_t source
; /* index of ugen or -1 for constant */
69 int16_t index
; /* number of output or constant index */
71 typedef std::vector
<input_spec
, aligned_allocator
<input_spec
> > input_spec_vector
;
75 explicit unit_spec_t(const char *& buffer
);
77 unit_spec_t(string
const & name
, int16_t rate
, int16_t special_index
,
78 input_spec_vector
const & in_specs
,
79 char_vector
const & out_specs
):
80 name(name
), rate(rate
), special_index(special_index
),
81 input_specs(in_specs
), output_specs(out_specs
)
84 #ifdef BOOST_HAS_RVALUE_REFS
85 unit_spec_t(unit_spec_t
&& rhs
):
86 name(std::move(rhs
.name
)), rate(rhs
.rate
), special_index(rhs
.special_index
),
87 input_specs(std::move(rhs
.input_specs
)), output_specs(std::move(rhs
.output_specs
))
90 unit_spec_t(unit_spec_t
const & rhs
):
91 name(rhs
.name
), rate(rhs
.rate
), special_index(rhs
.special_index
),
92 input_specs(rhs
.input_specs
), output_specs(rhs
.output_specs
)
96 int16_t rate
; /* 0: scalar rate, 1: buffer rate, 2: full rate, 3: demand rate */
97 int16_t special_index
;
99 input_spec_vector input_specs
;
100 char_vector output_specs
; /* calculation rates */
101 std::vector
<int16_t, aligned_allocator
<int16_t> > buffer_mapping
;
103 std::size_t memory_requirement(void)
105 return input_specs
.size() * (sizeof(Wire
*) + sizeof(float*)) +
106 output_specs
.size() * (sizeof(Wire
*) + sizeof(float*)) +
107 output_specs
.size() * sizeof(Wire
);
110 struct sc_ugen_def
* prototype
;
113 friend class sc_synth_prototype
;
114 friend class sc_synth
;
115 friend class sc_ugen_factory
;
116 friend class sc_ugen_def
;
118 typedef std::vector
<unit_spec_t
, aligned_allocator
<unit_spec_t
> > graph_t
;
119 typedef std::vector
<int32_t, aligned_allocator
<int32_t> > calc_units_t
;
121 explicit sc_synthdef(const char *& buffer
);
123 #ifdef BOOST_HAS_RVALUE_REFS
124 sc_synthdef(sc_synthdef
&& rhs
):
125 name_(std::move(rhs
.name_
)), constants(std::move(rhs
.constants
)), parameters(std::move(rhs
.parameters
)),
126 parameter_map(std::move(rhs
.parameter_map
)), graph(std::move(rhs
.graph
)), buffer_count(rhs
.buffer_count
),
127 calc_unit_indices(std::move(rhs
.calc_unit_indices
)), memory_requirement_(rhs
.memory_requirement_
)
130 sc_synthdef(sc_synthdef
const & rhs
):
131 name_(rhs
.name_
), constants(rhs
.constants
), parameters(rhs
.parameters
),
132 parameter_map(rhs
.parameter_map
), graph(rhs
.graph
), buffer_count(rhs
.buffer_count
),
133 calc_unit_indices(rhs
.calc_unit_indices
), memory_requirement_(rhs
.memory_requirement_
)
137 std::string
dump(void) const;
139 string
const & name(void) const
144 std::size_t parameter_count(void) const
146 return parameters
.size();
149 std::size_t unit_count(void) const
154 std::size_t calc_unit_count(void) const
156 return calc_unit_indices
.size();
159 std::size_t memory_requirement(void) const
161 assert(memory_requirement_
);
162 return memory_requirement_
;
166 void read_synthdef(const char *&);
168 /** assign buffers, collect memory requirement & cache ugen prototype */
174 parameter_map_t parameter_map
;
177 boost::uint16_t buffer_count
;
178 calc_units_t calc_unit_indices
; /**< indices of the units, that need to be calculated */
179 std::size_t memory_requirement_
;
182 std::vector
<sc_synthdef
> read_synthdefs(const char * buf_ptr
);
183 std::vector
<sc_synthdef
> read_synthdef_file(boost::filesystem::path
const & filename
);
185 } /* namespace nova */
187 #endif /* SC_SYNTHDEF_HPP */