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
26 #include <boost/cstdint.hpp>
27 #include <boost/filesystem/path.hpp>
29 #include "utilities/malloc_aligned.hpp"
30 #include "utilities/named_hash_entry.hpp"
40 typedef c_string string
;
41 typedef std::vector
<float, aligned_allocator
<float> > fvector
;
42 typedef std::vector
<c_string
, aligned_allocator
<string
> > svector
;
44 typedef boost::int16_t int16
;
45 typedef boost::int32_t int32
;
47 typedef std::vector
<char, aligned_allocator
<char> > char_vector
;
50 typedef std::map
<string
, int, std::less
<string
>, aligned_allocator
<string
> > parameter_map_t
;
54 input_spec(int16_t source
, int16_t index
):
55 source(source
), index(index
)
58 bool operator<(input_spec
const & rhs
) const
60 if (source
< rhs
.source
)
62 if (source
> rhs
.source
)
64 return index
< rhs
.index
;
67 int16_t source
; /* index of ugen or -1 for constant */
68 int16_t index
; /* number of output or constant index */
70 typedef std::vector
<input_spec
, aligned_allocator
<input_spec
> > input_spec_vector
;
74 explicit unit_spec_t(const char *& buffer
);
76 unit_spec_t(string
const & name
, int16_t rate
, int16_t special_index
,
77 input_spec_vector
const & in_specs
,
78 char_vector
const & out_specs
):
79 name(name
), rate(rate
), special_index(special_index
),
80 input_specs(in_specs
), output_specs(out_specs
)
83 #ifdef BOOST_HAS_RVALUE_REFS
84 unit_spec_t(unit_spec_t
&& rhs
):
85 name(std::move(rhs
.name
)), rate(rhs
.rate
), special_index(rhs
.special_index
),
86 input_specs(std::move(rhs
.input_specs
)), output_specs(std::move(rhs
.output_specs
)),
87 buffer_mapping(std::move(rhs
.buffer_mapping
)), prototype(rhs
.prototype
)
90 unit_spec_t(unit_spec_t
const & rhs
) = default;
91 unit_spec_t
& operator=(unit_spec_t
const & rhs
) = default;
94 int16_t rate
; /* 0: scalar rate, 1: buffer rate, 2: full rate, 3: demand rate */
95 int16_t special_index
;
97 input_spec_vector input_specs
;
98 char_vector output_specs
; /* calculation rates */
99 std::vector
<int16_t, aligned_allocator
<int16_t> > buffer_mapping
;
101 std::size_t memory_requirement(void)
103 return input_specs
.size() * (sizeof(Wire
*) + sizeof(float*)) +
104 output_specs
.size() * (sizeof(Wire
*) + sizeof(float*)) +
105 output_specs
.size() * sizeof(Wire
);
108 struct sc_ugen_def
* prototype
;
111 friend class sc_synth_prototype
;
112 friend class sc_synth
;
113 friend class sc_ugen_factory
;
114 friend class sc_ugen_def
;
116 typedef std::vector
<unit_spec_t
, aligned_allocator
<unit_spec_t
> > graph_t
;
117 typedef std::vector
<int32_t, aligned_allocator
<int32_t> > calc_units_t
;
119 explicit sc_synthdef(const char *& buffer
);
121 #ifdef BOOST_HAS_RVALUE_REFS
122 sc_synthdef(sc_synthdef
&& rhs
):
123 name_(std::move(rhs
.name_
)), constants(std::move(rhs
.constants
)), parameters(std::move(rhs
.parameters
)),
124 parameter_map(std::move(rhs
.parameter_map
)), graph(std::move(rhs
.graph
)), buffer_count(rhs
.buffer_count
),
125 calc_unit_indices(std::move(rhs
.calc_unit_indices
)), memory_requirement_(rhs
.memory_requirement_
)
128 sc_synthdef(sc_synthdef
const & rhs
) = default;
129 sc_synthdef
& operator=(sc_synthdef
const & rhs
) = default;
132 std::string
dump(void) const;
134 string
const & name(void) const
139 std::size_t parameter_count(void) const
141 return parameters
.size();
144 std::size_t unit_count(void) const
149 std::size_t calc_unit_count(void) const
151 return calc_unit_indices
.size();
154 std::size_t memory_requirement(void) const
156 assert(memory_requirement_
);
157 return memory_requirement_
;
161 void read_synthdef(const char *&);
163 /** assign buffers, collect memory requirement & cache ugen prototype */
169 parameter_map_t parameter_map
;
172 boost::uint16_t buffer_count
;
173 calc_units_t calc_unit_indices
; /**< indices of the units, that need to be calculated */
174 std::size_t memory_requirement_
;
177 std::vector
<sc_synthdef
> read_synthdefs(const char * buf_ptr
);
178 std::vector
<sc_synthdef
> read_synthdef_file(boost::filesystem::path
const & filename
);
180 } /* namespace nova */
182 #endif /* SC_SYNTHDEF_HPP */