form caption("Poli-rythm") size(1000, 380), colour("black"),pluginID("add1"), guirefresh(1)
groupbox bounds(579, 104, 383, 102), colour(212, 211, 211, 255), fontcolour(212, 211, 211, 255),
groupbox bounds(579, 0, 383, 102), colour(212, 211, 211, 255), fontcolour(212, 211, 211, 255),
; Tempo in BPM
rslider bounds(644, 244, 80, 80), channel("Tempo"), range(10, 400, 120, 1, 1), text("BPM"), trackercolour(0, 255, 96, 255), textcolour(255, 255, 255, 255), outlinecolour(0, 0, 0, 50),
; Start/stop
checkbox bounds(776, 260, 150, 49), channel("StartStop"), items("Start/Stop"), colour("yellow"), fontcolour("white")
; Filename
filebutton bounds(588, 136, 118, 39), text("Choose a sound","OPEN MONO FILE"), fontcolour(255,255,100) channel("filename2"), shape("ellipse"), channel("beg","len")
label bounds(8, 164, 534, 16), text("Choose an audio file to play"), align("left"), identchannel("stringbox2"), fontcolour(0, 255, 96, 255),
; Pattern 1
gentable bounds(10, 10, 560, 40), tablenumber(11), active(1), tablebackgroundcolour(0,0,0,0), tablecolour("purple"), zoom(-1), amprange(0, 1, -1, 1), identchannel("tables1")
image bounds(-100, 9, 35, 35), colour(0,0,0,0), outlinethickness(2), outlinecolour("white"), identchannel("scrubber")
rslider bounds(724, 12, 128, 78), channel("Beats"), range(1, 15, 4, 1, 1), text("Num Beats Pattern 1"), colour(2, 2, 2, 255), trackercolour(0, 255, 96, 255), fontcolour(0, 0, 0, 255), textcolour(0, 0, 0, 255), outlinecolour(0, 0, 0, 50),
numberbox bounds(872, 32, 79, 29), channel("Beats"), range(1, 15, 4, 1, 1), colour(0, 0, 0, 255), fontcolour(231, 233, 120, 255), textcolour(0, 0, 0, 255),
filebutton bounds(588, 32, 116, 38), text("Choose a sound","OPEN MONO FILE"), fontcolour(255,255,100) channel("filename1"), shape("ellipse"), channel("beg","len")
label bounds(8, 60, 539, 16), text("Choose an audio file to play"), align("left"), identchannel("stringbox1"), fontcolour(0, 255, 96, 255),
; Pattern 2
gentable bounds(10, 112, 560, 40), tablenumber(12), active(1), tablebackgroundcolour(0,0,0,0), tablecolour("lime"), zoom(-1), amprange(0, 1, -1, 1), identchannel("tables2")
image bounds(-100, 39, 35, 35), colour(0,0,0,0), outlinethickness(2), outlinecolour("white"), identchannel("scrubber2")
rslider bounds(724, 112, 129, 83), channel("Beats2"), range(1, 15, 2, 1, 1), text("Num Beats Pattern 2"), colour(0, 0, 0, 255), trackercolour(0, 255, 96, 255), fontcolour(0, 0, 0, 255), textcolour(0, 0, 0, 255), outlinecolour(0, 0, 0, 50),
numberbox bounds(872, 132, 75, 30), channel("Beats2"), range(1, 15, 2, 1, 1), colour(0, 0, 0, 255), fontcolour(236, 218, 117, 255), textcolour(0, 0, 0, 255),
-n -d -m0d
sr = 44100
ksmps = 32
nchnls = 2
0dbfs=1
gSfilename1 init ""
gSfilename2 init ""
;===================================================== PATTERN 1 ======================================================
instr 1
gkTempo chnget "Tempo"
gkBeats chnget "Beats"
kTempo = gkTempo/60
k1 metro kTempo
kStep init 0
iLen = 16
kStart chnget "StartStop"
if k1 == 1 && kStart==1 then;
;call instrument to trigger notes at i-time
event "i", 11, 0, 1, kStep ;pattern 1
;updates scrubber position
Sposition sprintfk "pos(%d, 9)", kStep*(560/iLen)+10
kStep = (kStep>(gkBeats-2) ? 0 : kStep+1) ; inserendo kBeats posso modificare la lunghezza degli step da leggere
chnset Sposition, "scrubber"
endif
if changed:k(kStart)==1 then
;hide scrubber when not playing
chnset "pos(-100, 9)", "scrubber"
endif
endin
;===================================================== PATTERN 2 ======================================================
instr 2
kBeats2 chnget "Beats2"
k1 = gkTempo/gkBeats ; divide the tempo in BPM by the pattern1 beats number
k2 = gkTempo/kBeats2 ; divide the tempo in BPM by the pattern2 beats number
k3 = k1/k2 ; divide the results to obtain the ratio between the two patterns
kTempo = (gkTempo/60)*k3 ; multiply by the ratio to have different beats in the same bar
k1 metro kTempo
kStep init 0
iLen = 16
kStart chnget "StartStop"
if k1 == 1 && kStart==1 then;
;call instrument to trigger notes at i-time
event "i", 12, 0, 1, kStep ;pattern 2
;updates scrubber position
Sposition2 sprintfk "pos(%d, 111)", kStep*(560/iLen)+10
kStep = (kStep>(kBeats2-2) ? 0 : kStep+1) ; inserendo kBeats posso modificare la lunghezza degli step da leggere
chnset Sposition2, "scrubber2"
endif
;toggle play/puase
if changed:k(kStart)==1 then
;hide scrubber when not playing
chnset "pos(-100, 111)", "scrubber2"
endif
;endif
endin
;---------------------------------------
; trigger notes
;---------------------------------------
instr 11
gSfilename chnget "filename1"
iAmp tab_i p4, 11
if iAmp == 1 then
aout soundin gSfilename
outs aout, aout
endif
endin
instr 12
gSfilename chnget "filename2"
iAmp tab_i p4, 12
if iAmp == 1 then
aout soundin gSfilename
outs aout, aout
endif
endin
;============================================================== WRITE FILE PATH ====================================================================
opcode FileNameFromPath,S,S ; Extract a file name (as a string) from a full path (also as a string)
Ssrc xin ; Read in the file path string
icnt strlen Ssrc ; Get the length of the file path string
LOOP: ; Loop back to here when checking for a backslash
iasc strchar Ssrc, icnt ; Read ascii value of current letter for checking
if iasc==92 igoto ESCAPE ; If it is a backslash, escape from loop
loop_gt icnt,1,0,LOOP ; Loop back and decrement counter which is also used as an index into the string
ESCAPE: ; Escape point once the backslash has been found
Sname strsub Ssrc, icnt+1, -1 ; Create a new string of just the file name
xout Sname ; Send it back to the caller instrument
endop
instr 100
gSfilename1 chnget "filename1"
gSfilename2 chnget "filename2"
if changed:k(gSfilename1)==1 then ; call instrument to update waveform viewer
event "i",101,0,0
endif
if changed:k(gSfilename2)==1 then ; call instrument to update waveform viewer
event "i",102,0,0
endif
endin
instr 101
Smessage sprintfk "file(%s)", gSfilename1 ; print sound file image to fileplayer
chnset Smessage, "filer1"
/* write file name to GUI */
Sname FileNameFromPath gSfilename1 ; Call UDO to extract file name from the full path
Smessage sprintfk "text(%s)",Sname ; create string to update text() identifier for label widget
chnset Smessage, "stringbox1" ; send string to widget
endin
instr 102
Smessage sprintfk "file(%s)", gSfilename2 ; print sound file image to fileplayer
chnset Smessage, "filer2"
/* write file name to GUI */
Sname FileNameFromPath gSfilename2 ; Call UDO to extract file name from the full path
Smessage sprintfk "text(%s)",Sname ; create string to update text() identifier for label widget
chnset Smessage, "stringbox2" ; send string to widget
endin
;8 tables of 16 samples
f11 0 16 -2 0
f12 0 16 -2 0
f13 0 16 -2 0
f14 0 16 -2 0
;main instrument
i1 0 1000
i2 0 1000
i100 0 [60*60*24*7]