1 // synth based on supercollider-style synthdef
2 // Copyright (C) 2009, 2010 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.
29 #include "sc_synth_definition.hpp"
31 #include "../server/synth.hpp"
32 #include "../server/memory_pool.hpp"
38 public abstract_synth
,
41 typedef std::vector
<struct Unit
*, rt_pool_allocator
<void*> > unit_vector
;
42 typedef sc_synthdef::graph_t graph_t
;
44 friend class sc_synth_definition
;
47 sc_synth(int node_id
, sc_synth_definition_ptr
const & prototype
);
51 /** run ugen constructors and initialize first sample
53 * to be executed after preparing the synth and setting the controls
57 inline void perform(void)
59 if (likely(trace
== 0))
61 size_t count
= calc_unit_count
;
62 Unit
** units
= calc_units
;
64 size_t preroll
= count
& 7;
66 for (size_t i
= 0; i
!= preroll
; ++i
)
68 Unit
* unit
= units
[i
];
69 (unit
->mCalcFunc
)(unit
, unit
->mBufLength
);
72 size_t unroll
= count
>> 3;
78 for (size_t i
= 0; i
!= unroll
; ++i
)
80 Unit
* unit
= units
[0];
81 (unit
->mCalcFunc
)(unit
, unit
->mBufLength
);
83 (unit
->mCalcFunc
)(unit
, unit
->mBufLength
);
85 (unit
->mCalcFunc
)(unit
, unit
->mBufLength
);
87 (unit
->mCalcFunc
)(unit
, unit
->mBufLength
);
89 (unit
->mCalcFunc
)(unit
, unit
->mBufLength
);
91 (unit
->mCalcFunc
)(unit
, unit
->mBufLength
);
93 (unit
->mCalcFunc
)(unit
, unit
->mBufLength
);
95 (unit
->mCalcFunc
)(unit
, unit
->mBufLength
);
105 void set(slot_index_t slot_index
, sample val
);
106 float get(slot_index_t slot_index
) const;
107 void set_control_array(slot_index_t slot_index
, size_t count
, sample
* val
);
109 sample
get(slot_index_t slot_index
)
111 return mControls
[slot_index
];
115 /** control mapping */
117 void map_control_bus_control(unsigned int slot_index
, int control_bus_index
);
118 void map_control_buses_control(unsigned int slot_index
, int control_bus_index
, int count
);
119 void map_control_bus_audio(unsigned int slot_index
, int audio_bus_index
);
120 void map_control_buses_audio(unsigned int slot_index
, int audio_bus_index
, int count
);
123 template <bool ControlBusIsAudio
>
124 void map_control_bus(unsigned int slot_index
, int bus_index
)
126 if (ControlBusIsAudio
)
127 map_control_bus_audio(slot_index
, bus_index
);
129 map_control_bus_control(slot_index
, bus_index
);
132 template <bool ControlBusIsAudio
>
133 void map_control_buses(unsigned int slot_index
, int bus_index
, int count
)
135 if (ControlBusIsAudio
)
136 map_control_buses_audio(slot_index
, bus_index
, count
);
138 map_control_buses_control(slot_index
, bus_index
, count
);
141 template <bool ControlBusIsAudio
>
142 void map_control_bus(const char * slot_name
, int bus_index
)
144 int slot_index
= resolve_slot(slot_name
);
145 map_control_bus
<ControlBusIsAudio
>(slot_index
, bus_index
);
148 template <bool ControlBusIsAudio
>
149 void map_control_buses(const char * slot_name
, int bus_index
, int count
)
151 int slot_index
= resolve_slot(slot_name
);
152 map_control_buses
<ControlBusIsAudio
>(slot_index
, bus_index
, count
);
155 template <bool ControlBusIsAudio
>
156 void map_control_bus(unsigned int slot_index
, size_t arrayed_slot_index
, int bus_index
)
158 map_control_bus
<ControlBusIsAudio
>(slot_index
+ arrayed_slot_index
, bus_index
);
161 template <bool ControlBusIsAudio
>
162 void map_control_bus(const char * slot_name
, size_t arrayed_slot_index
, int bus_index
)
164 size_t slot_index
= resolve_slot(slot_name
) + arrayed_slot_index
;
165 map_control_bus
<ControlBusIsAudio
>(slot_index
, bus_index
);
169 void enable_tracing(void)
174 void apply_unit_cmd(const char * unit_cmd
, unsigned int unit_index
, struct sc_msg_iter
*args
);
177 void run_traced(void);
179 sample
get_constant(size_t index
)
181 return static_cast<sc_synth_definition
*>(class_ptr
.get())->constants
[index
];
184 friend class sc_ugen_def
;
188 sample
* unit_buffers
;
189 int32_t calc_unit_count
, unit_count
;
196 } /* namespace nova */
198 #endif /* SC_SYNTH_HPP */