Last active
December 21, 2022 00:43
-
-
Save ersin-ertan/c6de506015a3ef191247def8134b8259 to your computer and use it in GitHub Desktop.
Sonic pi sample fader both in and out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define :_togglePan do |pan| | |
if pan == -1 then pan = 1 else pan = -1 end | |
return pan | |
end | |
define :_calcFadedAmp do |isFadeIn, amp, ampFade| | |
if isFadeIn == true then amp += ampFade else amp -= ampFade end | |
return amp | |
end | |
define :_fadeRepeater do |sample, times, sleep, amp, pan, isFadeIn, ampFade, togglePan| | |
times.times do | |
sample sample, amp: amp, pan: pan | |
if togglePan == true then pan = _togglePan pan end | |
amp = _calcFadedAmp isFadeIn, amp, ampFade | |
sleep sleep | |
end | |
end | |
define :sampleFade do |sample, times: 1, sleep: nil, amp: 1.0, pan: 0| | |
puts "sample:", sample, ", times:", times, ", sleep:", sleep, ", amp:", amp, ", pan:", pan | |
isFadeIn = false | |
if times == nil or times == 0 then times = 1 end | |
if times < 0 then isFadeIn = true and times *= -1 end | |
if sleep == nil or sleep < 0 then sleep = sample_duration(sample) end | |
if amp == nil then amp = 1.0 else amp += 0.0 end | |
if pan == nil or pan == 0 then togglePan = false else togglePan = true end | |
ampFade = (amp / times) | |
if isFadeIn == true then amp = ampFade end | |
_fadeRepeater sample, times, sleep, amp, pan, isFadeIn, ampFade, togglePan | |
end | |
repeat_crow = 6 | |
define :func do |a, b: 0, c: 0| | |
print "func", a, b, c | |
end | |
func 1 | |
func 1, b: 2 | |
func 1, c: 2 | |
in_thread do | |
sampleFade :misc_crow, times:repeat_crow * -1 | |
end | |
in_thread do | |
#sampleFade :misc_crow, repeat_crow | |
end | |
in_thread do | |
#repeat_crow.times do | |
# sample :misc_crow, amp: 1.0/repeat_crow | |
# sleep sample_duration(:misc_crow) | |
#end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://in-thread.sonic-pi.net/t/function-overloading-functions-with-the-same-name-but-different-params/7361