Using a list of numbers as triggers

Hello everybody!

Working through the floss manual i’m getting a better understanding of Csound and how to use in a way i like it more! The score was always a thing what made Csound for me very unattractive!

I’m experimenting a bit with the ‘event’ opcode to trigger a other instrument. What a convenient way to create a lot of sounds! In this example i used a ‘linseg’ line multiplied with random values to make it more ‘human’.
But now i’m asking myself how to use a list of numbers which represents the time of initialization of different instances of one instrument.
So, i wan’t to use Csound combined with Lisp, create a list of numbers there and copy the list into csound as a trigger list.
Is it clear what i mean?
I think i have to use an array, but i don’t know how to work it out.

Here is the example where i want to replace my metro trigger with a list of numbers.


<CsoundSynthesizer>
<CsOptions>
-d -odac -A
</CsOptions>
<CsInstruments>

sr = 44100
ksmps = 128
nchnls = 2
0dbfs = 1.0

giSine ftgen 1, 0, 2^10, 10, 1
;-----------------------------------------------------------
instr 1

kMult linseg 5, 10, 5, 10, 10, 10, 5, 10, 20, 10, 25, 10, 50, 30, 5, 20, 5, 20, 1
kDens random 0.001, 0.5

kTrig metro kDens*kMult
if kTrig == 1 then
	event "i", 2, 0, kDens*kMult, 60, 127
endif 
endin

instr 2
iMaxAmp random 0.001, 0.1
iAtk random 0.05, 0.25
aEnv linseg 0, p3*iAtk, iMaxAmp, p3*0.5, 0

iFreq random p4, p5
iFreq mtof iFreq

aSine poscil aEnv, iFreq, giSine

iPanStart random 0, 1
kPan line iPanStart, p3*0.5, 1-iPanStart	
aOutL, aOutR pan2 aSine, kPan

outs aOutL, aOutR
endin
;-----------------------------------------------------------

</CsInstruments>
<CsScore>
i1 0 130
</CsScore>
</CsoundSynthesizer>

You can use an array:

<CsoundSynthesizer>
<CsOptions>

</CsOptions>
<CsInstruments>
; Initialize the global variables. 
ksmps = 32
nchnls = 2
0dbfs = 1


instr 1
    ;timing of note events..
    iTimes[] fillarray 0, 4, 8, 10, 11, 12, 16, 20, 22, 23, 24, 28, 32
    kIndex init 0
    kBeats init 0

    if metro(4) == 1 then
        if kBeats == iTimes[kIndex] then
            event "i", 2, 0, 5
            kIndex += 1     ;at some point this will try to access indices that don't exist..
        endif
        
        kBeats += 1
    endif

endin


instr 2
    a1 expon 1, p3, 0.001
    a2 oscili a1, 200
    outs a2, a2
endin
</CsInstruments>
<CsScore>
;causes Csound to run for about 7000 years...
f0 z
;starts instrument 1 and runs it for a week
i1 0 [60*60*24*7] 
</CsScore>
</CsoundSynthesizer>

Thanks, Roray!

I will investigate in this!

What ist happening here: metro(4)
Does Metro don’t an k-Variable? What is this thing with the parenthesis?

Edit.: Ok, i thing i got it. It’s functional syntax for “kMetro metro 4”, right?

I understand this example. But i’m still dependent on an metro, which beats regularly. I need something more flexible for a thing like, where the numbers stand for the initialization time in millieseconds.

Edit2:

I tried this and i think this could work, but i need a way to change the numbers from seconds to cps.

instr 1

iTimes[] fillarray 1, 4, 8, 10, 12, 16, 20, 23, 24
kIndex init 0


kTrig metro iTimes[kIndex]
if kTrig == 1 then
	event "i", 2, 0, 5
	kIndex += 1
endif

endin

You can always pass the start times to the event opcode? Then you can be as precise as you like. Sorry, I should have mentioned that, so something like:

iTimes[] fillarray 1, 4, 8, 10, 12, 16, 20, 23, 24
iCnt init 0
while iCnt < lenarray(iTimes) do
   event_i "i", 2, iTimes[iCnt], 10
   iCnt += 1
od

The only issues here is that this will queue up all your notes at i-time. But if they are known at i-time this is the simplest thing to do.

1 Like

Thanks! This works perfect!