Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add example for nstance to clarify usage together with turnoff #624

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions examples/nstance.csd
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,40 @@ instr 2
endin


; ---------------------------------------------------------------
; nstance can be used to control the lifetime of a launched event


instr sineoscil
ifreq = p4
a0 oscili 0.1, ifreq
aenv linsegr 0, 0.1, 1, 0.1, 0
a0 *= aenv
outch 1, a0
endin

instr turnoff
iid = p4
prints "turning off id %d\n", iid
turnoff(iid)
endin

instr master
; event with a unique p1. Although isynth is a itime variable, at itime
; it has a value of 0!!. Only at performance time it turns valid

isynth nstance nstrnum("sineoscil")+0.01, 0, -1, 442

; At the very first cycle schedule a turnoff using the handle number,
; not the fractional p1. Notice that this operation needs to be done
; at performance time to have a valid handle
if timeinstk() == 1 then
ksynth = isynth
schedulek "turnoff", 2, 0, ksynth
endif
endin


</CsInstruments>
<CsScore>

Expand All @@ -42,6 +76,9 @@ f 1 0 16384 10 1
i 1 0 0.5
; Play Instrument #1 for half a second.
i 1 1 0.5

i "master" 0 10

e


Expand Down