Csound Csound-dev Csound-tekno Search About

Re: documentation: schedkwhen

Date1999-10-12 12:44
Fromrasmus ekman
SubjectRe: documentation: schedkwhen
schedkwhen DOCUMENTATION:
------------------------

Ignite Instrument Events

        schedkwhen ktrigger, kmintime, kmaxinst, kinsnum, kwhen, kdur[, kp4, ... kpN] 


Generate new instrument events from orchestra at k-rate.

This opcode may be useful eg for certain kinds of algorithmic composition.


PERFORMANCE 
schedkwhen adds new instrument events to the Csound performance 
whenever the k-rate value ktrigger is non-zero. Event generation 
may be limited by the kmintime and kmaxinst arguments.

ktrigger - when non-zero, signal that an instrument instance 
should be started.

kmintime - controls the minimal time which is to elapse between 
generated events, in seconds. If kmintime <= 0, no time limit is 
used. If the kinstr instrument number is negative (to turn off 
an instrument), this test is bypassed.

kmaxinst - ceiling for the number of simultaneous instances of 
instrument kinstr. If number of existant instances of kinstr 
is >= kmaxinst, no event is generated. If kmaxinst is <= 0, it is 
not used to limit event generation. If the kinstr instrument 
number is negative (to turn off an instrument), this test is 
bypassed.

kinsnum, kwhen, kdur, ... - same arguments as in score i-statements. 
The kwhen start time (p2) is measured from the time of the triggering 
event, and must be a positive value (or zero). 
If an event is deferred by a p2 offset value, the instrument will 
not be initialized until the actual time when it should start performing.
If kdur (p3) is zero the instrument will only do an initialization 
pass without performance. A negative kdur value will initiate a held note 
(see also ihold and i-statements).

Note that while waiting for delayed events, the performance must 
be kept going, or Csound may quit if no score events are expected. 
To guarantee continued performance, the f0 statement may be used 
in score (same as eg when playing midi files, or to pad score sections 
with silence).


EXAMPLES

The offset value is useful for triggering multiple instruments
in fixed relations. Here, two alternating metronomes:

instr 5 ; tick-tock, tick-tock
    iBPM init p4
    ; Instr's 6 and 7 could be eg simple sample players
    schedkwhen 1, 60/iBPM, 0, 6, 0, .5
    schedkwhen 1, 60/iBPM, 0, 7, 30/iBPM, .5
endin

;Score
; Generate events at 150 BPM for 10 secs
i1 0 10 150
e


This example will create a strumming gesture of p5 notes in p6 seconds

instr 10 ; Strummer
        ; Pass some values to the strummed instr
        koct init p4
        iamp init 12000
        
        ; Init strum delay so p5 events start in (roughly) p6 seconds
        iNumEvts init p5
        knum init 0 
        iDelBase init (p6 / sqrt(iNumEvts)) * 1.7
        kdel init 0
        ; Generate p5 events in the first p5 k-cycles
        knum = knum + 1
        ktrig = (knum <= iNumEvts ? 1 : 0)
        ; Strum instr 11, passing pitch and "intended pitch" to pluck
        ;   for some spectral variation. (knum is also passed for diagnostics)
        schedkwhen ktrig, 0, 0, 11, kdel, .5, iamp, cpspch(koct), cpspch(koct) * (knum+2), knum

        ; Increase delay for next events
        kdel = kdel + iDelBase / (knum+1)
        
        ; and play a chord (just to do something)
        koct = koct +.03

        ; Don't need this instr after the evts generated, so turn off
        if knum < iNumEvts kgoto continue
                turnoff
  continue:
endin


instr 11 ; Strummed instrument
        ; print p2, pchoct(octcps(p5)), p6, p7
        kamp linseg p4, p3-.1, p4, .1, 0
        ar pluck kamp, p5, p6, 0, 1
                out ar
endin


; Score

i10 0    .1  6.10   6   .6
i10 1.5  .3  7.00   6   .7
i10 3    .3  6.03  11  1.5

f0 5

e


This example uses xyin to provide gestural control of event generation:

; Orchestra
sr = 22050
kr  =  882
ksmps = 25
nchnls = 2

instr 9 ; Generate 1-50 events per sec (max 20 simultaneous)
        kX, kY xyin .03, .02, 1, 0, 3000, 1, 100
        schedkwhen 1, kX/2, 20, 2, 0, .7, kY, kY/(kX*.5)
endin


instr 12
        kamp linseg 15000, p3-.05, 15000, .05, 0
        kcps line p4, p3, p5
        ar pluck kamp, p4, p5, 0, 1 pan
        
        ; Random stereo distribution
        a1, a2 locsig ar, rnd(360), 1, 0
        
            outs a1, a2
endin

; Score
f1 0 8192 10 1               ; Sine

i9 0 15