1 // supercollider-style synthdef
2 // Copyright (C) 2008-2012 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
27 #include <boost/filesystem/path.hpp>
29 #include "utilities/malloc_aligned.hpp"
30 #include "utilities/named_hash_entry.hpp"
39 typedef c_string string
;
40 typedef std::vector
<float, aligned_allocator
<float> > fvector
;
41 typedef std::vector
<c_string
, aligned_allocator
<string
> > svector
;
43 typedef std::vector
<char, aligned_allocator
<char> > char_vector
;
46 typedef std::map
<string
, int32_t, std::less
<string
>, aligned_allocator
<string
> > parameter_map_t
;
50 input_spec(int32_t source
, int32_t index
):
51 source(source
), index(index
)
54 bool operator<(input_spec
const & rhs
) const
56 if (source
< rhs
.source
)
58 if (source
> rhs
.source
)
60 return index
< rhs
.index
;
63 int32_t source
; /* index of ugen or -1 for constant */
64 int32_t index
; /* number of output or constant index */
66 typedef std::vector
<input_spec
, aligned_allocator
<input_spec
> > input_spec_vector
;
70 explicit unit_spec_t(const char *& buffer
, int version
);
72 unit_spec_t(string
const & name
, int16_t rate
, int16_t special_index
,
73 input_spec_vector
const & in_specs
,
74 char_vector
const & out_specs
):
75 name(name
), rate(rate
), special_index(special_index
),
76 input_specs(in_specs
), output_specs(out_specs
)
79 unit_spec_t(unit_spec_t
&& rhs
):
80 name(std::move(rhs
.name
)), rate(rhs
.rate
), special_index(rhs
.special_index
),
81 input_specs(std::move(rhs
.input_specs
)), output_specs(std::move(rhs
.output_specs
)),
82 buffer_mapping(std::move(rhs
.buffer_mapping
)), prototype(rhs
.prototype
)
85 unit_spec_t(unit_spec_t
const & rhs
) = default;
86 unit_spec_t
& operator=(unit_spec_t
const & rhs
) = default;
89 int16_t rate
; /* 0: scalar rate, 1: buffer rate, 2: full rate, 3: demand rate */
90 int16_t special_index
;
92 input_spec_vector input_specs
;
93 char_vector output_specs
; /* calculation rates */
94 std::vector
<int32_t, aligned_allocator
<int32_t> > buffer_mapping
;
96 std::size_t memory_requirement(void)
98 return input_specs
.size() * (sizeof(Wire
*) + sizeof(float*)) +
99 output_specs
.size() * (sizeof(Wire
*) + sizeof(float*)) +
100 output_specs
.size() * sizeof(Wire
);
103 struct sc_ugen_def
* prototype
;
106 friend class sc_synth_prototype
;
107 friend class sc_synth
;
108 friend class sc_ugen_factory
;
109 friend class sc_ugen_def
;
111 typedef std::vector
<unit_spec_t
, aligned_allocator
<unit_spec_t
> > graph_t
;
112 typedef std::vector
<int32_t, aligned_allocator
<int32_t> > calc_units_t
;
114 sc_synthdef(const char *& buffer
, int version
);
116 sc_synthdef(sc_synthdef
&& rhs
):
117 name_(std::move(rhs
.name_
)), constants(std::move(rhs
.constants
)), parameters(std::move(rhs
.parameters
)),
118 parameter_map(std::move(rhs
.parameter_map
)), graph(std::move(rhs
.graph
)), buffer_count(rhs
.buffer_count
),
119 calc_unit_indices(std::move(rhs
.calc_unit_indices
)), memory_requirement_(rhs
.memory_requirement_
)
122 sc_synthdef(sc_synthdef
const & rhs
) = default;
123 sc_synthdef
& operator=(sc_synthdef
const & rhs
) = default;
125 std::string
dump(void) const;
127 string
const & name(void) const
132 std::size_t parameter_count(void) const
134 return parameters
.size();
137 std::size_t unit_count(void) const
142 std::size_t calc_unit_count(void) const
144 return calc_unit_indices
.size();
147 std::size_t memory_requirement(void) const
149 assert(memory_requirement_
);
150 return memory_requirement_
;
154 void read_synthdef(const char *&, int version
);
156 /** assign buffers, collect memory requirement & cache ugen prototype */
162 parameter_map_t parameter_map
;
165 std::uint16_t buffer_count
;
166 calc_units_t calc_unit_indices
; /**< indices of the units, that need to be calculated */
167 std::size_t memory_requirement_
;
170 std::vector
<sc_synthdef
> read_synthdefs(const char * buf_ptr
);
171 std::vector
<sc_synthdef
> read_synthdef_file(boost::filesystem::path
const & filename
);
173 } /* namespace nova */
175 #endif /* SC_SYNTHDEF_HPP */