def play( self, add_action=None, bus=0, level=1, loop=False, rate=1, target_node=None, ): from supriya.tools import synthdeftools from supriya.tools import ugentools with synthdeftools.SynthDefBuilder( level=1, rate=1, ) as builder: player = ugentools.PlayBuf.ar( buffer_id=self.buffer_id, channel_count=self.channel_count, loop=loop, rate=ugentools.BufRateScale.kr(self.buffer_id) * builder['rate'], ) if not loop: ugentools.FreeSelfWhenDone.kr(player) source = player * builder['level'] ugentools.Out.ar(bus=bus, source=source) synthdef = builder.build() return synthdef.play( add_action=add_action, level=level, rate=rate, target_node=target_node, )
def _build_synthdef(): builder = synthdeftools.SynthDefBuilder( bus=0, cutoff=0.5, ) with builder: source = ugentools.In.ar(bus=builder['bus']) cutoff = builder['cutoff'] cutoff = ugentools.Lag.kr(source=cutoff) lpf_cutoff = cutoff.clip(0., 0.75) lpf_frequency = lpf_cutoff.scale(0, 0.75, 20, 22000, True) hpf_cutoff = cutoff.clip(0.25, 1.0) hpf_frequency = hpf_cutoff.scale(0.25, 1.0, 20, 22000, True) source = ugentools.LPF.ar( source=source, frequency=lpf_frequency, ) source = ugentools.HPF.ar( source=source, frequency=hpf_frequency, ) ugentools.ReplaceOut.ar( bus=builder['bus'], source=source, ) synthdef = builder.build() return synthdef
def test_SynthDefDecompiler_08(): r'''Multiple parameters with different lags.''' builder = synthdeftools.SynthDefBuilder( amp=0.5, freqs=synthdeftools.Parameter( lag=0.5, value=[300, 400], ), ) with builder: sines = ugentools.SinOsc.ar(frequency=builder['freqs'], ) sines = ugentools.Mix.new(sines) sines = sines * builder['amp'] ugentools.Out.ar( bus=0, source=sines, ) old_synthdef = builder.build('arrayarg') compiled_synthdef = old_synthdef.compile() new_synthdef = decompiler.decompile_synthdef(compiled_synthdef) assert str(old_synthdef) == str(new_synthdef) assert old_synthdef.indexed_parameters == new_synthdef.indexed_parameters assert compiled_synthdef == new_synthdef.compile() assert old_synthdef.anonymous_name == new_synthdef.anonymous_name assert old_synthdef.name == new_synthdef.name
def from_ugens(ugens): """ Makes a synthdef from `ugens`. :: >>> from supriya.tools import synthdeftools >>> from supriya.tools import ugentools >>> ugen = ugentools.Out.ar(source=ugentools.SinOsc.ar() * 0.5) >>> synthdef = synthdeftools.SynthDef.from_ugens(ugen) :: >>> print(synthdef) SynthDef e0041b72f3e50206267d5f426f7c592f { const_0:440.0 -> 0_SinOsc[0:frequency] const_1:0.0 -> 0_SinOsc[1:phase] 0_SinOsc[0] -> 1_BinaryOpUGen:MULTIPLICATION[0:left] const_2:0.5 -> 1_BinaryOpUGen:MULTIPLICATION[1:right] const_1:0.0 -> 2_Out[0:bus] 1_BinaryOpUGen:MULTIPLICATION[0] -> 2_Out[1:source] } Returns synthdef. """ from supriya.tools import synthdeftools builder = synthdeftools.SynthDefBuilder() if isinstance(ugens, collections.Sequence): for ugen in ugens: builder.add_ugens(ugen) elif isinstance(ugens, synthdeftools.UGenMethodMixin): builder.add_ugens(ugens) synthdef = builder.build() return synthdef
def test_SynthDefDecompiler_06(): r'''Multiple parameters with different rates.''' builder = synthdeftools.SynthDefBuilder( a_phase=0.0, freq=440, i_decay_time=1.0, t_trig_a=0, t_trig_b=0, ) with builder: decay = ugentools.Decay2.kr( source=(builder['t_trig_a'], builder['t_trig_b']), attack_time=0.5, decay_time=builder['i_decay_time'], ) sin_osc = ugentools.SinOsc.ar( frequency=builder['freq'], phase=builder['a_phase'], ) enveloped_sin_osc = sin_osc * decay ugentools.Out.ar( bus=0, source=enveloped_sin_osc, ) old_synthdef = builder.build('trigTest') compiled_synthdef = old_synthdef.compile() new_synthdef = decompiler.decompile_synthdef(compiled_synthdef) assert str(old_synthdef) == str(new_synthdef) assert old_synthdef.indexed_parameters == new_synthdef.indexed_parameters assert compiled_synthdef == new_synthdef.compile() assert old_synthdef.anonymous_name == new_synthdef.anonymous_name assert old_synthdef.name == new_synthdef.name
def build_duration_synthdef(self, bus=0): builder = synthdeftools.SynthDefBuilder(duration=0) with builder: ugentools.Out.ar( bus=bus, source=ugentools.Line.ar(duration=builder['duration'], ), ) return builder.build()
def build_basic_synthdef(self, bus=0): builder = synthdeftools.SynthDefBuilder() with builder: ugentools.Out.ar( bus=bus, source=ugentools.SinOsc.ar(), ) return builder.build()
def test_SynthDefCompiler_basic_02(): with synthdeftools.SynthDefBuilder() as builder: sine = ugentools.SinOsc.ar() sine = -sine ugentools.Out.ar(bus=99, source=sine) py_synthdef = builder.build('test') py_compiled_synthdef = py_synthdef.compile() sc_synthdef = synthdeftools.SuperColliderSynthDef( 'test', 'Out.ar(99, SinOsc.ar(freq: 440).neg)', ) sc_compiled_synthdef = sc_synthdef.compile() test_compiled_synthdef = bytes( b'SCgf' b'\x00\x00\x00\x02' b'\x00\x01' b'\x04test' b'\x00\x00\x00\x03' b'C\xdc\x00\x00' b'\x00\x00\x00\x00' b'B\xc6\x00\x00' b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' b'\x00\x00\x00\x03' b'\x06SinOsc' b'\x02' b'\x00\x00\x00\x02' b'\x00\x00\x00\x01' b'\x00\x00' b'\xff\xff\xff\xff' b'\x00\x00\x00\x00' b'\xff\xff\xff\xff' b'\x00\x00\x00\x01' b'\x02' b'\x0bUnaryOpUGen' b'\x02' b'\x00\x00\x00\x01' b'\x00\x00\x00\x01' b'\x00\x00' b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' b'\x02' b'\x03Out' b'\x02' b'\x00\x00\x00\x02' b'\x00\x00\x00\x00' b'\x00\x00' b'\xff\xff\xff\xff' b'\x00\x00\x00\x02' b'\x00\x00\x00\x01' b'\x00\x00\x00\x00' b'\x00\x00', ) assert sc_compiled_synthdef == test_compiled_synthdef assert py_compiled_synthdef == test_compiled_synthdef
def _build_kick_synthdef(): builder = synthdeftools.SynthDefBuilder(out=0, ) with builder: ### ENVELOPE ### gate = ugentools.Impulse.ar(frequency=2) envelope = synthdeftools.Envelope.percussive( attack_time=0.01, release_time=1.0, ) envelope = ugentools.EnvGen.ar(done_action=0, envelope=envelope, gate=gate) envelope = synthdeftools.Op.squared(envelope) ### NOISE COMPONENT ### noise = ugentools.PinkNoise.ar() noise = ugentools.BPF.ar( source=noise, frequency=ugentools.LinLin.ar( source=synthdeftools.Op.cubed(envelope), output_minimum=30, output_maximum=120, ), reciprocal_of_q=2, ) noise *= envelope ### PITCHED COMPONENT ### pitch = ugentools.SinOsc.ar(frequency=ugentools.LinLin.ar( source=envelope, output_minimum=10, output_maximum=80, ), ) pitch = pitch * 2.0 pitch = synthdeftools.Op.distort(pitch) pitch = ugentools.RLPF.ar( source=pitch, frequency=ugentools.LinLin.ar( source=envelope, output_minimum=30, output_maximum=120, ), reciprocal_of_q=0.5, ) pitch *= envelope mix = pitch + noise ugentools.Out.ar(builder['out'], (mix, mix)) synthdef = builder.build() return synthdef
def test_SynthDefCompiler_basic_04(): r'''FreeSelf. ''' sc_synthdef = synthdeftools.SuperColliderSynthDef( 'test', r''' Out.ar(0, FreeSelf.kr(SinOsc.ar())) ''') sc_compiled_synthdef = bytes(sc_synthdef.compile()) with synthdeftools.SynthDefBuilder() as builder: sin_osc = ugentools.SinOsc.ar() ugentools.FreeSelf.kr(sin_osc) ugentools.Out.ar(bus=0, source=sin_osc) py_synthdef = builder.build('test') py_compiled_synthdef = py_synthdef.compile() test_compiled_synthdef = bytes( b'SCgf' b'\x00\x00\x00\x02' b'\x00\x01' b'\x04test' b'\x00\x00\x00\x02' b'C\xdc\x00\x00' b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' b'\x00\x00\x00\x03' b'\x06SinOsc' b'\x02' b'\x00\x00\x00\x02' b'\x00\x00\x00\x01' b'\x00\x00' b'\xff\xff\xff\xff' b'\x00\x00\x00\x00' b'\xff\xff\xff\xff' b'\x00\x00\x00\x01' b'\x02' b'\x08FreeSelf' b'\x01' b'\x00\x00\x00\x01' b'\x00\x00\x00\x01' b'\x00\x00' b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' b'\x01' b'\x03Out' b'\x02' b'\x00\x00\x00\x02' b'\x00\x00\x00\x00' b'\x00\x00' b'\xff\xff\xff\xff' b'\x00\x00\x00\x01' b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' b'\x00\x00', ) assert sc_compiled_synthdef == test_compiled_synthdef assert py_compiled_synthdef == test_compiled_synthdef
def _build_test_synthdef(): builder = synthdeftools.SynthDefBuilder() builder.add_parameter('frequency', 440) builder.add_parameter('amplitude', 1.0, 'audio') with builder: sin_osc = ugentools.SinOsc.ar(frequency=builder['frequency']) enveloped_sin = sin_osc * builder['amplitude'] ugentools.Out.ar(bus=0, source=enveloped_sin) synthdef = builder.build(name='test') return synthdef
def test_SynthDefCompiler_optimization_01(): sc_synthdef = synthdeftools.SuperColliderSynthDef( 'optimized', r''' var sine_a, sine_b, sine_c, sine_d; sine_a = SinOsc.ar(420); sine_b = SinOsc.ar(440); sine_c = SinOsc.ar(460); sine_d = SinOsc.ar(sine_c); Out.ar(0, sine_a); ''') sc_compiled_synthdef = bytes(sc_synthdef.compile()) with synthdeftools.SynthDefBuilder() as builder: sine_a = ugentools.SinOsc.ar(frequency=420) sine_b = ugentools.SinOsc.ar(frequency=440) sine_c = ugentools.SinOsc.ar(frequency=460) sine_d = ugentools.SinOsc.ar(frequency=sine_c) ugentools.Out.ar(bus=0, source=sine_a) py_synthdef = builder.build('optimized') py_compiled_synthdef = py_synthdef.compile() test_compiled_synthdef = bytes(b'SCgf' b'\x00\x00\x00\x02' b'\x00\x01' b'\toptimized' b'\x00\x00\x00\x02' b'C\xd2\x00\x00' b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' b'\x00\x00\x00\x02' b'\x06SinOsc' b'\x02' b'\x00\x00\x00\x02' b'\x00\x00\x00\x01' b'\x00\x00' b'\xff\xff\xff\xff' b'\x00\x00\x00\x00' b'\xff\xff\xff\xff' b'\x00\x00\x00\x01' b'\x02' b'\x03Out' b'\x02' b'\x00\x00\x00\x02' b'\x00\x00\x00\x00' b'\x00\x00' b'\xff\xff\xff\xff' b'\x00\x00\x00\x01' b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' b'\x00\x00') assert sc_compiled_synthdef == test_compiled_synthdef assert py_compiled_synthdef == test_compiled_synthdef
def _build_dc_synthdef(self, channel_count=1): with synthdeftools.SynthDefBuilder( out_bus=0, source=0, ) as builder: source = ugentools.K2A.ar(source=builder['source']) ugentools.Out.ar( bus=builder['out_bus'], source=[source] * channel_count, ) return builder.build()
def test_SynthDefDecompiler_03(): r'''Named SynthDef with one parameter.''' with synthdeftools.SynthDefBuilder(freq=440) as builder: sine = ugentools.SinOsc.ar(frequency=builder['freq']) ugentools.Out.ar(bus=0, source=sine) old_synthdef = builder.build('test') compiled_synthdef = old_synthdef.compile() new_synthdef = decompiler.decompile_synthdef(compiled_synthdef) assert str(old_synthdef) == str(new_synthdef) assert old_synthdef.indexed_parameters == new_synthdef.indexed_parameters assert compiled_synthdef == new_synthdef.compile() assert old_synthdef.anonymous_name == new_synthdef.anonymous_name assert old_synthdef.name == new_synthdef.name
def test_SynthDefDecompiler_01(): r'''Anonymous SynthDef without parameters.''' with synthdeftools.SynthDefBuilder() as builder: sine = ugentools.SinOsc.ar() sine = -sine ugentools.Out.ar(bus=99, source=sine) old_synthdef = builder.build() compiled_synthdef = old_synthdef.compile() new_synthdef = decompiler.decompile_synthdef(compiled_synthdef) assert str(old_synthdef) == str(new_synthdef) assert old_synthdef.indexed_parameters == new_synthdef.indexed_parameters assert compiled_synthdef == new_synthdef.compile() assert old_synthdef.anonymous_name == new_synthdef.anonymous_name assert old_synthdef.name == new_synthdef.name
def build_gate_synthdef(self, bus=0): builder = synthdeftools.SynthDefBuilder(gate=1) with builder: envelope = synthdeftools.Envelope.asr() envgen = ugentools.EnvGen.ar( envelope=envelope, gate=builder['gate'], ) source = ugentools.Saw.ar() * envgen ugentools.Out.ar( bus=bus, source=source, ) return builder.build()
def _build_diskin_synthdef(self, channel_count=1): with synthdeftools.SynthDefBuilder( out_bus=0, buffer_id=0, ) as builder: source = ugentools.DiskIn.ar( buffer_id=builder['buffer_id'], channel_count=channel_count, ) ugentools.Out.ar( bus=builder['out_bus'], source=source, ) return builder.build()
def test_SynthDefCompiler_basic_03(): sc_synthdef = synthdeftools.SuperColliderSynthDef( 'test', r''' Out.ar(0, In.ar(8, 2)) ''') sc_compiled_synthdef = sc_synthdef.compile() with synthdeftools.SynthDefBuilder() as builder: inputs = ugentools.In.ar(bus=8, channel_count=2) ugentools.Out.ar(bus=0, source=inputs) py_synthdef = builder.build('test') py_compiled_synthdef = py_synthdef.compile() test_compiled_synthdef = bytes( b'SCgf' b'\x00\x00\x00\x02' b'\x00\x01' b'\x04test' b'\x00\x00\x00\x02' b'A\x00\x00\x00' b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' b'\x00\x00\x00\x02' b'\x02In' b'\x02' b'\x00\x00\x00\x01' b'\x00\x00\x00\x02' b'\x00\x00' b'\xff\xff\xff\xff' b'\x00\x00\x00\x00' b'\x02' b'\x02' b'\x03Out' b'\x02' b'\x00\x00\x00\x03' b'\x00\x00\x00\x00' b'\x00\x00' b'\xff\xff\xff\xff' b'\x00\x00\x00\x01' b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' b'\x00\x00\x00\x01' b'\x00\x00', ) assert sc_compiled_synthdef == test_compiled_synthdef assert py_compiled_synthdef == test_compiled_synthdef
def _build_multiplier_synthdef(self, channel_count=1): with synthdeftools.SynthDefBuilder( in_bus=0, out_bus=0, multiplier=1, ) as builder: source = ugentools.In.ar( bus=builder['in_bus'], channel_count=channel_count, ) ugentools.ReplaceOut.ar( bus=builder['out_bus'], source=source * builder['multiplier'], ) return builder.build()
def _setup_synthdef(self): from supriya.tools import synthdeftools from supriya.tools import ugentools with synthdeftools.SynthDefBuilder() as builder: source = ugentools.In.ar( bus=0, channel_count=self.current_channel_count, ) buffer_id = int(self.record_buffer) ugentools.DiskOut.ar( buffer_id=buffer_id, source=source, ) synthdef = builder.build() synthdef.allocate(server=self.server) self._record_synthdef = synthdef
def test_SynthDefDecompiler_04(): r'''Multiple parameters.''' builder = synthdeftools.SynthDefBuilder( freq=1200, out=23, ) sine = ugentools.SinOsc.ar(frequency=builder['freq']) out = ugentools.Out.ar(bus=builder['out'], source=sine) builder.add_ugens(out) old_synthdef = builder.build('test') compiled_synthdef = old_synthdef.compile() new_synthdef = decompiler.decompile_synthdef(compiled_synthdef) assert str(old_synthdef) == str(new_synthdef) assert old_synthdef.indexed_parameters == new_synthdef.indexed_parameters assert compiled_synthdef == new_synthdef.compile() assert old_synthdef.anonymous_name == new_synthdef.anonymous_name assert old_synthdef.name == new_synthdef.name
def test_SynthDefCompiler_basic_05(): with synthdeftools.SynthDefBuilder() as builder: source = ugentools.In.ar(bus=8, channel_count=2) ugentools.DetectSilence.ar(source=source) ugentools.Out.ar(bus=0, source=source) py_synthdef = builder.build('DetectSilenceTest') py_compiled_synthdef = py_synthdef.compile() sc_synthdef = synthdeftools.SuperColliderSynthDef( 'DetectSilenceTest', r''' var source, detect_silence, out; source = In.ar(8, 2); detect_silence = DetectSilence.ar(source); out = Out.ar(0, source); ''') sc_compiled_synthdef = bytes(sc_synthdef.compile()) assert sc_compiled_synthdef == py_compiled_synthdef
def make_meter_synthdef( channel_count=1, command_name='/reply', initial_bus=0, ): from supriya.tools import synthdeftools from supriya.tools import ugentools with synthdeftools.SynthDefBuilder() as builder: source = ugentools.In.ar( bus=initial_bus, channel_count=channel_count, ) ugentools.SendPeakRMS.kr( command_name=command_name, peak_lag=1, reply_rate=20, source=source, ) synthdef = builder.build() return synthdef
def _build_link_audio_synthdef(channel_count): """ SynthDef("system_link_audio_" ++ i, { arg out=0, in=16, vol=1, level=1, lag=0.05, doneAction=2; var env = EnvGate(doneAction:doneAction, curve:'sin') * Lag.kr(vol * level, lag); Out.ar(out, InFeedback.ar(in, i) * env); }, [\kr, \kr, \kr, \kr, \kr, \ir]).add; """ name = 'system_link_audio_{}'.format(channel_count) builder = synthdeftools.SynthDefBuilder( name=name, out=0, in_=16, gate=1, fade_time=0.02, done_action=2, ) with builder: start_value = builder['fade_time'] <= 0 envelope = synthdeftools.Envelope( amplitudes=[start_value, 1.0, 0.0], durations=[1.0, 1.0], curves=synthdeftools.EnvelopeShape.SINE, release_node=1.0, ) envelope = ugentools.EnvGen.kr( done_action=builder['done_action'], envelope=envelope, gate=builder['gate'], time_scale=builder['fade_time'], ) input_ = ugentools.InFeedback.ar( bus=builder['in_'], channel_count=channel_count, ) ugentools.Out.ar( bus=builder['out'], source=input_ * envelope, ) globals()[name] = builder.build() __all__.append(name)
def test_SynthDefDecompiler_05(): '''Multiple parameters.''' builder = synthdeftools.SynthDefBuilder( damping=0.5, delay_time=1.0, room_size=0.75, ) with builder: microphone = ugentools.In.ar(bus=0) delay = ugentools.DelayC.ar( source=microphone, maximum_delay_time=5.0, delay_time=builder['delay_time'], ) ugentools.Out.ar(bus=0, source=delay) old_synthdef = builder.build('test') compiled_synthdef = old_synthdef.compile() new_synthdef = decompiler.decompile_synthdef(compiled_synthdef) assert str(old_synthdef) == str(new_synthdef) assert old_synthdef.indexed_parameters == new_synthdef.indexed_parameters assert compiled_synthdef == new_synthdef.compile() assert old_synthdef.anonymous_name == new_synthdef.anonymous_name assert old_synthdef.name == new_synthdef.name
def test_SynthDefCompiler_basic_01(): with synthdeftools.SynthDefBuilder() as builder: sine_one = ugentools.SinOsc.ar(frequency=420) sine_two = ugentools.SinOsc.ar(frequency=440) sines = sine_one * sine_two ugentools.Out.ar(bus=0, source=sines) py_synthdef = builder.build('foo') py_compiled_synthdef = py_synthdef.compile() sc_synthdef = synthdeftools.SuperColliderSynthDef( 'foo', 'Out.ar(0, SinOsc.ar(freq: 420) * SinOsc.ar(freq: 440))', ) sc_compiled_synthdef = sc_synthdef.compile() test_compiled_synthdef = bytes( b'SCgf' b'\x00\x00\x00\x02' b'\x00\x01' b'\x03foo' b'\x00\x00\x00\x03' b'C\xd2\x00\x00' b'\x00\x00\x00\x00' b'C\xdc\x00\x00' b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' b'\x00\x00\x00\x04' b'\x06SinOsc' b'\x02' b'\x00\x00\x00\x02' b'\x00\x00\x00\x01' b'\x00\x00' b'\xff\xff\xff\xff' b'\x00\x00\x00\x00' b'\xff\xff\xff\xff' b'\x00\x00\x00\x01' b'\x02' b'\x06SinOsc' b'\x02' b'\x00\x00\x00\x02' b'\x00\x00\x00\x01' b'\x00\x00' b'\xff\xff\xff\xff' b'\x00\x00\x00\x02' b'\xff\xff\xff\xff' b'\x00\x00\x00\x01' b'\x02' b'\x0cBinaryOpUGen' b'\x02' b'\x00\x00\x00\x02' b'\x00\x00\x00\x01' b'\x00\x02' b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' b'\x00\x00\x00\x01' b'\x00\x00\x00\x00' b'\x02' b'\x03Out' b'\x02' b'\x00\x00\x00\x02' b'\x00\x00\x00\x00' b'\x00\x00' b'\xff\xff\xff\xff' b'\x00\x00\x00\x01' b'\x00\x00\x00\x02' b'\x00\x00\x00\x00' b'\x00\x00', ) assert sc_compiled_synthdef == test_compiled_synthdef assert py_compiled_synthdef == test_compiled_synthdef
def _build_clap_synthdef(): builder = synthdeftools.SynthDefBuilder( out=0, amplitude=0.5, ) with builder: envelope_one = synthdeftools.Envelope( amplitudes=(0, 1, 0, 1, 0, 1, 0, 1, 0), durations=(0.001, 0.013, 0, 0.01, 0, 0.01, 0, 0.03), curves=(0, -3, 0, -3, 0, -3, 0, -4), ) envelope_generator_one = ugentools.EnvGen.ar(envelope=envelope_one, ) envelope_two = synthdeftools.Envelope( amplitudes=(0, 1, 0), durations=(0.02, 0.3), curves=(0, -4), ) envelope_generator_two = ugentools.EnvGen.ar( envelope=envelope_two, done_action=2, ) noise_one = ugentools.WhiteNoise.ar() * envelope_generator_one noise_one = ugentools.HPF.ar( source=noise_one, frequency=600, ) noise_one = ugentools.BPF.ar( source=noise_one, frequency=2000, reciprocal_of_q=3, ) noise_two = ugentools.WhiteNoise.ar() * envelope_generator_two noise_two = ugentools.HPF.ar( source=noise_two, frequency=1000, ) noise_two = ugentools.BPF.ar( source=noise_two, frequency=1200, reciprocal_of_q=0.7, ) noise_two = noise_two * 0.7 result = noise_one + noise_two result = result * 2 result = synthdeftools.Op.softclip(result) result = result * builder['amplitude'] ugentools.Out.ar( bus=builder['out'], source=(result, result), ) synthdef = builder.build() return synthdef
def test_SynthDefCompiler_parameters_02(): sc_synthdef = synthdeftools.SuperColliderSynthDef( 'test', r''' arg freq=1200, out=23; Out.ar(out, SinOsc.ar(freq: freq)); ''') sc_compiled_synthdef = sc_synthdef.compile() builder = synthdeftools.SynthDefBuilder( freq=1200, out=23, ) sine = ugentools.SinOsc.ar(frequency=builder['freq']) out = ugentools.Out.ar(bus=builder['out'], source=sine) builder.add_ugens(out) py_synthdef = builder.build('test') py_compiled_synthdef = py_synthdef.compile() assert py_synthdef.indexed_parameters == ( ( 0, synthdeftools.Parameter( name='freq', parameter_rate=synthdeftools.ParameterRate.CONTROL, value=1200.0, ), ), ( 1, synthdeftools.Parameter( name='out', parameter_rate=synthdeftools.ParameterRate.CONTROL, value=23.0, ), ), ) test_compiled_synthdef = bytes( b'SCgf' b'\x00\x00\x00\x02' b'\x00\x01' b'\x04test' b'\x00\x00\x00\x01' b'\x00\x00\x00\x00' b'\x00\x00\x00\x02' b'D\x96\x00\x00' b'A\xb8\x00\x00' b'\x00\x00\x00\x02' b'\x04freq' b'\x00\x00\x00\x00' b'\x03out' b'\x00\x00\x00\x01' b'\x00\x00\x00\x03' b'\x07Control' b'\x01' b'\x00\x00\x00\x00' b'\x00\x00\x00\x02' b'\x00\x00' b'\x01' b'\x01' b'\x06SinOsc' b'\x02' b'\x00\x00\x00\x02' b'\x00\x00\x00\x01' b'\x00\x00' b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' b'\xff\xff\xff\xff' b'\x00\x00\x00\x00' b'\x02' b'\x03Out' b'\x02' b'\x00\x00\x00\x02' b'\x00\x00\x00\x00' b'\x00\x00' b'\x00\x00\x00\x00' b'\x00\x00\x00\x01' b'\x00\x00\x00\x01' b'\x00\x00\x00\x00' b'\x00\x00', ) assert sc_compiled_synthdef == test_compiled_synthdef assert py_compiled_synthdef == test_compiled_synthdef
def _build_default_synthdef(): """ SynthDef(\default, { arg out=0, freq=440, amp=0.1, pan=0, gate=1; var z; z = LPF.ar( Mix.new( VarSaw.ar( freq + [0, Rand(-0.4, 0.0), Rand(0.0, 0.4)], 0, 0.3, 0.3 ) ), XLine.kr(Rand(4000,5000), Rand(2500,3200), 1) ); z = z * Linen.kr(gate, 0.01, 0.7, 0.3, 2); OffsetOut.ar(out, Pan2.ar(z, pan, amp)); }, [\ir]).add; """ builder = synthdeftools.SynthDefBuilder( amplitude=0.1, frequency=440, gate=1, out=synthdeftools.Parameter( name='out', parameter_rate=synthdeftools.ParameterRate.SCALAR, value=0, ), pan=0.5, ) with builder: low_pass = ugentools.LPF.ar(source=ugentools.Mix.new( ugentools.VarSaw.ar( frequency=builder['frequency'] + ( 0, ugentools.Rand.ir(minimum=-0.4, maximum=0.), ugentools.Rand.ir(minimum=0., maximum=0.4), ), width=0.3, ), ) * 0.3, frequency=ugentools.XLine.kr( start=ugentools.Rand.ir(minimum=4000, maximum=5000), stop=ugentools.Rand.ir(minimum=2500, maximum=3200), )) linen = ugentools.Linen.kr( attack_time=0.01, done_action=synthdeftools.DoneAction.FREE_SYNTH, gate=builder['gate'], release_time=0.3, sustain_level=0.7, ) pan = ugentools.Pan2.ar( source=low_pass * linen * builder['amplitude'], position=builder['pan'], ) ugentools.OffsetOut.ar(bus=builder['out'], source=pan) synthdef = builder.build() return synthdef
def test_SynthDefCompiler_parameters_06(): r'''Literal array arguments.''' builder = synthdeftools.SynthDefBuilder( amp=0.1, freqs=synthdeftools.Parameter( lag=0.5, value=[300, 400], ), ) with builder: sines = ugentools.SinOsc.ar(frequency=builder['freqs'], ) sines = ugentools.Mix.new(sines) sines = sines * builder['amp'] ugentools.Out.ar( bus=0, source=sines, ) py_synthdef = builder.build('arrayarg') py_compiled_synthdef = py_synthdef.compile() assert py_synthdef.indexed_parameters == ( ( 0, synthdeftools.Parameter( name='amp', parameter_rate=synthdeftools.ParameterRate.CONTROL, value=0.1, ), ), ( 1, synthdeftools.Parameter( lag=0.5, name='freqs', parameter_rate=synthdeftools.ParameterRate.CONTROL, value=(300.0, 400.0)), ), ) sc_synthdef = synthdeftools.SuperColliderSynthDef( 'arrayarg', r''' | amp = 0.1, freqs = #[300, 400] | var sines; sines = SinOsc.ar(freqs).sum; Out.ar(0, sines * amp); ''', [0, 0.5], ) sc_compiled_synthdef = bytes(sc_synthdef.compile()) test_compiled_synthdef = bytes(b'SCgf' b'\x00\x00\x00\x02' b'\x00\x01' b'\x08arrayarg' b'\x00\x00\x00\x02' b'\x00\x00\x00\x00' b'?\x00\x00\x00' b'\x00\x00\x00\x03' b'=\xcc\xcc\xcd' b'C\x96\x00\x00' b'C\xc8\x00\x00' b'\x00\x00\x00\x02' b'\x03amp' b'\x00\x00\x00\x00' b'\x05freqs' b'\x00\x00\x00\x01' b'\x00\x00\x00\x06' b'\nLagControl' b'\x01' b'\x00\x00\x00\x03' b'\x00\x00\x00\x03' b'\x00\x00' b'\xff\xff\xff\xff' b'\x00\x00\x00\x00' b'\xff\xff\xff\xff' b'\x00\x00\x00\x01' b'\xff\xff\xff\xff' b'\x00\x00\x00\x01' b'\x01' b'\x01' b'\x01' b'\x06SinOsc' b'\x02' b'\x00\x00\x00\x02' b'\x00\x00\x00\x01' b'\x00\x00' b'\x00\x00\x00\x00' b'\x00\x00\x00\x01' b'\xff\xff\xff\xff' b'\x00\x00\x00\x00' b'\x02' b'\x06SinOsc' b'\x02' b'\x00\x00\x00\x02' b'\x00\x00\x00\x01' b'\x00\x00' b'\x00\x00\x00\x00' b'\x00\x00\x00\x02' b'\xff\xff\xff\xff' b'\x00\x00\x00\x00' b'\x02' b'\x0cBinaryOpUGen' b'\x02' b'\x00\x00\x00\x02' b'\x00\x00\x00\x01' b'\x00\x00' b'\x00\x00\x00\x01' b'\x00\x00\x00\x00' b'\x00\x00\x00\x02' b'\x00\x00\x00\x00' b'\x02' b'\x0cBinaryOpUGen' b'\x02' b'\x00\x00\x00\x02' b'\x00\x00\x00\x01' b'\x00\x02' b'\x00\x00\x00\x03' b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' b'\x02' b'\x03Out' b'\x02' b'\x00\x00\x00\x02' b'\x00\x00\x00\x00' b'\x00\x00' b'\xff\xff\xff\xff' b'\x00\x00\x00\x00' b'\x00\x00\x00\x04' b'\x00\x00\x00\x00' b'\x00\x00') assert sc_compiled_synthdef == test_compiled_synthdef assert py_compiled_synthdef == test_compiled_synthdef