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_prototype.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_prototype
;
47 sc_synth(int node_id
, sc_synth_prototype_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 void set_control_array(slot_index_t slot_index
, size_t count
, sample
* val
);
108 sample
get(slot_index_t slot_index
)
110 return mControls
[slot_index
];
114 /** control mapping */
116 void map_control_bus_control(unsigned int slot_index
, int control_bus_index
);
117 void map_control_buses_control(unsigned int slot_index
, int control_bus_index
, int count
);
118 void map_control_bus_audio(unsigned int slot_index
, int audio_bus_index
);
119 void map_control_buses_audio(unsigned int slot_index
, int audio_bus_index
, int count
);
122 template <bool ControlBusIsAudio
>
123 void map_control_bus(unsigned int slot_index
, int bus_index
)
125 if (ControlBusIsAudio
)
126 map_control_bus_audio(slot_index
, bus_index
);
128 map_control_bus_control(slot_index
, bus_index
);
131 template <bool ControlBusIsAudio
>
132 void map_control_buses(unsigned int slot_index
, int bus_index
, int count
)
134 if (ControlBusIsAudio
)
135 map_control_buses_audio(slot_index
, bus_index
, count
);
137 map_control_buses_control(slot_index
, bus_index
, count
);
140 template <bool ControlBusIsAudio
>
141 void map_control_bus(const char * slot_name
, int bus_index
)
143 int slot_index
= resolve_slot(slot_name
);
144 map_control_bus
<ControlBusIsAudio
>(slot_index
, bus_index
);
147 template <bool ControlBusIsAudio
>
148 void map_control_buses(const char * slot_name
, int bus_index
, int count
)
150 int slot_index
= resolve_slot(slot_name
);
151 map_control_buses
<ControlBusIsAudio
>(slot_index
, bus_index
, count
);
154 template <bool ControlBusIsAudio
>
155 void map_control_bus(unsigned int slot_index
, size_t arrayed_slot_index
, int bus_index
)
157 map_control_bus
<ControlBusIsAudio
>(slot_index
+ arrayed_slot_index
, bus_index
);
160 template <bool ControlBusIsAudio
>
161 void map_control_bus(const char * slot_name
, size_t arrayed_slot_index
, int bus_index
)
163 size_t slot_index
= resolve_slot(slot_name
) + arrayed_slot_index
;
164 map_control_bus
<ControlBusIsAudio
>(slot_index
, bus_index
);
168 void enable_tracing(void)
173 void apply_unit_cmd(const char * unit_cmd
, unsigned int unit_index
, struct sc_msg_iter
*args
);
176 void run_traced(void);
178 sample
get_constant(size_t index
)
180 return static_cast<sc_synth_prototype
*>(class_ptr
.get())->constants
[index
];
183 friend class sc_ugen_def
;
187 sample
* unit_buffers
;
188 int32_t calc_unit_count
, unit_count
;
195 } /* namespace nova */
197 #endif /* SC_SYNTH_HPP */