giuliomoro Thanks for taking a look. Here's the code. The part that makes the cpu increase is this one:
; sensor 1 drum 1 + sensor 3 drum 2 ;STROBOSCOPI ON/OFF +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
kson1123 trigger ks103, 0.5, 0
ksoff1123 trigger ks103, 0.1, 1
idrum1123 = 2
; p4 p5
; drum freq
schedkwhen kson1123, imin, imax, 60, 0, 100, idrum1123, 20
schedkwhen ksoff1123, imin, imax, 61, 0, 0.1 ;stroboscopic off
schedkwhen ksoff1123, imin, imax, 63, 0.1, 0.1, idrum1123 ;stop light
;-----------------------------------------------------------------------------------------------------------------------------
Now it is commented in the code below.
Complete code:
<CsoundSynthesizer>
<CsOptions>
-dm0 -odac -iadc
</CsOptions>
<CsInstruments>
ksmps = 8
nchnls = 2
0dbfs = 1
;;;;OPTIONS
;-m0d --daemon --realtime -odac -iadc
giportrelay1 init 14
giportrelay2 init 15
gidel init 2
;------------------------------------------------------
; Digital in/out - use a switch to turn an LED
; on and off. See comments at bottom for wiring
;------------------------------------------------------
;===============================================================
instr 10;digital ports ;========================================
ks101 = 0 ;initialize control signal for sensor 1 drum 1 + sensor 1 drum 2
ks102 = 0
ks103 = 0
ks104 = 0
ks105 = 0
ks201 = 0
ks202 = 0
ks203 = 0
ks204 = 0
ks205 = 0
ks301 = 0
ks302 = 0
ks303 = 0
ks304 = 0
ks305 = 0
ks401 = 0
ks402 = 0
ks403 = 0
ks404 = 0
ks405 = 0
ks501 = 0
ks502 = 0
ks503 = 0
ks504 = 0
ks505 = 0
ks340 = 0 ;drum sensor 3 + 4
ks034 = 0
iport00 = 4 ;digital port 1 IN DRUM 1 Sensor 1
iport01 = 3 ;digital port 2 IN DRUM 1 Sensor 2
iport02 = 2 ;digital port 3 IN DRUM 1 Sensor 3
iport03 = 1 ;digital port 4 IN DRUM 1 Sensor 4
iport04 = 0 ;digital port 5 IN DRUM 1 Sensor 5
iport08 = 12 ;digital port 7 IN DRUM 2 Sensor 1
iport09 = 11
iport10 = 10
iport11 = 9
iport12 = 8
ks11 digiInBela iport00 ;drum 1
ks12 digiInBela iport01
ks13 digiInBela iport02
ks14 digiInBela iport03
ks15 digiInBela iport04
ks21 digiInBela iport08 ;drum 1
ks22 digiInBela iport09
ks23 digiInBela iport10
ks24 digiInBela iport11
ks25 digiInBela iport12
ihtim = 0.01
ks11 port ks11, ihtim
ks12 port ks12, ihtim
ks13 port ks13, ihtim
ks14 port ks14, ihtim
ks15 port ks15, ihtim
ks21 port ks21, ihtim
ks22 port ks22, ihtim
ks23 port ks23, ihtim
ks24 port ks24, ihtim
ks25 port ks25, ihtim
; CONTROL MATRIX CONTROL MATRIX CONTROL MATRIX CONTROL MATRIX
if (ks11== 1) && (ks21== 1) then ; GROUP 1 ----------
ks101 = 1
elseif (ks11== 1) && (ks23== 1) then
ks103 = 1
elseif (ks13== 1) && (ks21== 1) then ; GROUP 3 ------------
ks301 = 1
elseif (ks13== 1) && (ks23== 1) then
ks303 = 1
elseif (ks13== 1) && (ks14== 1) then
ks340 = 1
elseif (ks23== 1) && (ks24== 1) then
ks034 = 1
endif
;print active instruments
;ktrig metro 1
;schedkwhen ktrig, .1, 1, 66, 0, .1
imin = 0.1
imax = 1
/*
; sensor 1 drum 1 + sensor 3 drum 2 ;STROBOSCOPI ON/OFF +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
kson1123 trigger ks103, 0.5, 0
ksoff1123 trigger ks103, 0.1, 1
idrum1123 = 2
; p4 p5
; drum freq
schedkwhen kson1123, imin, imax, 60, 0, 100, idrum1123, 20
schedkwhen ksoff1123, imin, imax, 61, 0, 0.1 ;stroboscopic off
schedkwhen ksoff1123, imin, imax, 63, 0.1, 0.1, idrum1123 ;stop light
;-----------------------------------------------------------------------------------------------------------------------------
;sensor 3 drum 1 + sensor 1 drum 2 ;STROBOSCOPI ON/OFF+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
kson1321 trigger ks301, 0.5, 0
ksoff1321 trigger ks301, 0.1, 1
idrum1321 = 1
; p4 p5
; drum freq
schedkwhen kson1321, imin, imax, 60, 0, 100, idrum1321, 20
schedkwhen ksoff1321, imin, imax, 61, 0, 0.1 ;stroboscopic off
schedkwhen ksoff1321, imin, imax, 63, 0.1, 0.1, idrum1321 ;stop light
*/
;-----------------------------------------------------------------------------------------------------------------------------
;sensor 2 drum 1 TURN AUDIO IN->OUT ON/OFF ;-------------------------------------------------------------------------------------------------------------
kson1220 trigger ks12, 0.5, 0 ;
ipiezzo1220 = 1
idrum1220 = 1
igain1220 = 2
; piezzo drum input
schedkwhen kson1220, imin, imax, 70, 0, 100, ipiezzo1220, idrum1220, igain1220
ksoff1220 trigger ks12, 0.1, 1
schedkwhen ksoff1220, imin, imax, 71, 0, 0.1
;-------------------------------------------------------------------------------------------------------------
;sensor 2 drum 2 TURN AUDIO IN->OUT ON/OFF ;-------------------------------------------------------------------------------------------------------------
kson1022 trigger ks22, 0.5, 0
;turn audio on
ipiezzo1022 = 2
idrum1022 = 2
igain1022 = .5
; piezzo drum input
schedkwhen kson1022, imin, imax, 70, 0, 100, ipiezzo1022, idrum1022, igain1022
ksoff1022 trigger ks22, 0.1, 1
schedkwhen ksoff1022, imin, imax, 71, 0, 0.1
;-------------------------------------------------------------------------------------------------------------
;sensor 4 drum 1 / TURN LIGHT ON on drum 2;-------------------------------------------------------------------------------------------------------------
kson1420 trigger ks14, 0.5, 0
idrum1420 = 2
; drum
schedkwhen kson1420, imin, 2, 62, 0, 100, idrum1420
;sensor 5 drum 1 / TURN LIGHT OFF on drum 2;-------------------------------------------------------------------------------------------------------------
idrum1520 = 2
kson1520 trigger ks15, 0.1, 0
schedkwhen kson1520, imin, 2, 63, 0.1, 0.1, idrum1520 ;turn off light
schedkwhen kson1520, imin, imax, 66, 0.1, 0.1 ;turn off rhythmic light
;-------------------------------------------------------------------------------------------------------------
;sensor 4 drum 2 / TURN LIGHT ON on drum 1
kson1024 trigger ks24, 0.5, 0
idrum1024 = 1
; drum
schedkwhen kson1024, imin, 2, 62, 0, 100, idrum1024
;sensor 5 drum 2 / TURN LIGHT OFF on drum 1
idrum1025 = 1
kson1025 trigger ks25, 0.1, 0
schedkwhen kson1025, imin, 2, 63, 0.1, 0.1, idrum1025
schedkwhen kson1025, imin, imax, 66, 0.1, 0.1 ;turn off rhythmic light
;-------------------------------------------------------------------------------------------------------------
;sensor 3 + 4 drum 1 / TURN DELAY ON on drum 2 piezzo 2
kson1314 trigger ks340, 0.5, 0
ipiezzo1314 = 1
idrum1314 = 1
igain1314 = .5
; piezzo drum input gain
schedkwhen kson1314, imin, 2, 73, 0, 100, ipiezzo1314, idrum1314, igain1314
ksoff1314 trigger ks340, 0.5, 1
schedkwhen ksoff1314, imin, 2, 74, 0.1, 0.1
;sensor 3 + 4 drum 2 / TURN DELAY ON on drum 2 piezzo 2
kson2324 trigger ks034, 0.5, 0
ipiezzo2324 = 2
idrum2324 = 2
igain2324 = .125
; piezzo drum input gain
schedkwhen kson2324, imin, 2, 73, 0, 100, ipiezzo2324, idrum2324, igain2324
ksoff2324 trigger ks034, 0.5, 1
schedkwhen ksoff2324, imin, 2, 74, 0.1, 0.1
;sensor 1 drum 1 + sensor 1 drum 2 // RHYTHMIC LIGHT
kson1121 trigger ks101, 0.5, 0
ipan1121 = 0
itempo1121 = 80
; pan tempo
schedkwhen kson1121, imin, 4, 65, 0, 100, ipan1121, itempo1121
endin ;=========================================================
;===============================================================
; \\\\\\\\\\\\\\\\\\\\\\\\\\\\
instr 60 ;stroboscopic light ;stroboscopic light ;stroboscopic light
idrum = p4
ifreq = p5
if idrum == 2 then
iportrelay = giportrelay2
else
iportrelay = giportrelay1
endif
kfreq = ifreq
kstrob poscil 1, kfreq, 2 ;squarewave
digiOutBela kstrob, iportrelay
endin
instr 61 ;stop stroboscopic
;kill instr 1001 stroboscopic
turnoff2 60, 0, 0
endin
instr 62 ;turn light on ;turn light on ;turn light on ;turn light on
idrum = p4
if idrum == 2 then
iportrelay = giportrelay2
else
iportrelay = giportrelay1
endif
digiOutBela 0, iportrelay
endin
instr 63;turn light off ;turn light off ;turn light off ;turn light off
turnoff2 62, 0, 0
idrum = p4
if idrum == 2 then
iportrelay = giportrelay2
else
iportrelay = giportrelay1
endif
digiOutBela 1, iportrelay
endin
instr 64 ;turn both lights off
digiOutBela 1, giportrelay1
digiOutBela 1, giportrelay2
endin
;Rhythmic Light ;Rhythmic Light ;Rhythmic Light ;Rhythmic Light ;Rhythmic Light ;Rhythmic Light
instr 65 ;Rhythmic Light ;Rhythmic Light ;Rhythmic Light ;Rhythmic Light
ipan = p4 ;where is the puls
itempo = p5
if ipan == 0 then
irelay1 = giportrelay1
irelay2 = giportrelay2
else
irelay1 = giportrelay2
irelay2 = giportrelay1
endif
ifreq = itempo/60
kpuls metro ifreq
ktrig1 trigger kpuls, 0.5, 0
ildur = 1/ifreq
imin = 0.01
imax = 8
schedkwhen ktrig1, imin, imax, 67, 0, ildur, irelay1
endin
instr 66
turnoff2 67, 0, 0
turnoff2 65, 0, 0
endin
instr 67 ;light on for a short time RHYTHMIC LIGHT
idur = p3
iportrelay = p4
ilight = 0.1
iatt = 0.001
irest = p3 - ilight- iatt * 2
if (irest <= 0) then
irest = 0.001
endif
klight linseg 1, iatt, 0, ilight, 0, iatt, 1, irest, 1
digiOutBela klight, iportrelay
idel random 0.001, idur*0.5
schedule 67, idel, idur
endin
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
instr 70 ;turn audio on
ipiezzo = p4
idrum = p5
igain = p6
apiezzo inch ipiezzo
outch idrum, apiezzo*igain
endin
instr 71 ;turn audio off
turnoff2 70, 0, 0
endin
instr 73 ;turn delay on
;prints "\n DELAY ON ..."
;turnoff2 70, 0, 0
ifeedback = 0.8
idrum = p4
ipiezzo = p5
igain = p6
ain inch ipiezzo
kdel1 randomh 0.01, 0.1, 1
kdel2 randomh 0.02, 0.05, .9
abuf1 delayr gidel
adel1 deltap kdel1
delayw ain igain + (adel1 ifeedback)
abuf2 delayr gidel
adel2 deltap kdel2
delayw ain igain + (adel2 ifeedback)
aout sum adel1, adel2
outch idrum, aout
endin
instr 74 ;turn delay off
;prints "\n DELAY OFF ..."
turnoff2 73, 0, 0
endin
</CsInstruments>
<CsScore>
f100 0 1024 7 0 24 1 1000 0 ;envelope
f2 0 1024 -7 0 1 1 511 1 1 0 511 0 ;squarewave
; p4 p5
; drum freq
i60 0 .5 1 8
i60 .5 .5 2 8
i61 1 .1
i64 1.5 .1 ;turn both lights off
i10 2 86400 ;play for 24 h
</CsScore>
</CsoundSynthesizer>