-
Notifications
You must be signed in to change notification settings - Fork 29
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think it is more clear when 2 separate examples are used on this manual page. Combining it to 1 long example makes a lot less clear as to what is doing what.
I'd like to propose the following example- it will be a separate example number 2.
I changed a few things.
Can you check please if all works as expected?
<CsoundSynthesizer>
<CsOptions>
; Select audio/midi flags here according to platform
; Audio out
-odac
; For Non-realtime ouput leave only the line below:
; -o nstance2.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>
sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1
; by Eduardo Moguillansky
; nstance can be used to control the lifetime of a launched event
instr sineoscil
ifreq = p4
a0 poscil 0.5, ifreq
aenv linsegr 0, 0.1, 1, 0.1, 0
a0 *= aenv
outs a0, a0
endin
instr turnoff
iid = p4
prints "\nturning 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, 200
; 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", 3, 0, ksynth
endif
endin
</CsInstruments>
<CsScore>
i "sineoscil" 1 1 1000 ; start at 1 second
i "master" 0 10
e
</CsScore>
</CsoundSynthesizer>
I would propose: I would propose:
```csound
<CsoundSynthesizer>
<CsOptions>
; Select audio/midi flags here according to platform
; Audio out
-odac
; For Non-realtime ouput leave only the line below:
; -o nstance2.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>
sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1
; by Eduardo Moguillansky
; nstance can be used to control the lifetime of a launched event
instr sineoscil
ifreq = p4
a0 poscil 0.5, ifreq
aenv linsegr 0, 0.1, 1, 0.1, 0
a0 *= aenv
outs a0, a0
endin
; an alarm clock; will trigger at `itime`, only once
opcode alarmclock, k, i
itime xin
kt = timeinsts()
kout = (kt >= itime && kt < itime + ksmps/sr) ? 1 : 0
xout kout
endop
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, 200
; Stock the scheduled event after 2 seconds
if alarmclock(2) == 1 then
println "turning off instrument with id %d", isynth
; notice that we convert isynth to ksynth to call turnoff at
; ktime.
ksynth = isynth
turnoff ksynth
endif
endin
</CsInstruments>
<CsScore>
i "sineoscil" 1 3 1000 ; start at 1 second
i "master" 0 10
e
</CsScore>
</CsoundSynthesizer>
|
it is not an easy example for me. I like that in this example the handle of nstance is used, the first example on the manual page does not use the handle. I've come up with this result, please tell me if you think this covers it all:
|
this version worked better for me - the other didn't seem to work.
If possible, could you have it turn on and off more notes over time?
- for me, that might give more insight in how to use all these related
opcodes
*- Dr.B*
*Dr. Richard Boulanger*
Professor
Electronic Production and Design
*Berklee College of Music*
Professional Writing & Technology Division
…On Mon, Aug 1, 2022 at 7:29 AM Menno Knevel ***@***.***> wrote:
it is not an easy example for me.
I've tried to put it in a more transparent order (for me) , and moved the
comments, where possible, to other places so the total overview of the
example becomes more transparent. Also i moved the UDO to the instr 0 space.
I like that in this example the handle of nstance is used, the first
example on the manual page does not use the handle.
I've come up with this result, please tell me if you think this covers it
all:
<CsoundSynthesizer>
<CsOptions>
; Select audio/midi flags here according to platform
; Audio out
-odac
; For Non-realtime ouput leave only the line below:
; -o nstance2.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>
sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1
; example by Eduardo Moguillansky
; nstance can be used to control the lifetime of a launched event
opcode alarmclock, k, i ; an alarm clock; will trigger at `itime`, only once
itime xin
kt = timeinsts()
kout = (kt >= itime && kt < itime + ksmps/sr) ? 1 : 0
xout kout
endop
instr sineoscil
ifreq = p4
a0 poscil 0.3, ifreq
aenv linsegr 0, 0.1, 1, 0.1, 0
a0 *= aenv
outs a0, a0
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, 200 ; p3: negative value is used for 'always on'
if alarmclock(2) == 1 then ; Stock the scheduled event after 2 seconds
println "\nturning off instrument with id %d\n", isynth
ksynth = isynth ; notice that we convert isynth to ksynth to call turnoff at ktime
turnoff ksynth
endif
endin
</CsInstruments>
<CsScore>
i "sineoscil" 1 2 1000 ; start at 1 second
i "master" 0 10
e
</CsScore>
</CsoundSynthesizer>
—
Reply to this email directly, view it on GitHub
<https://us-west-2.protection.sophos.com?d=github.com&u=aHR0cHM6Ly9naXRodWIuY29tL2Nzb3VuZC9tYW51YWwvcHVsbC82MjQjaXNzdWVjb21tZW50LTEyMDEwNzY5MTI=&i=NWYxNzBkMDNiNTVmZGEwZmIyNjczYmRm&t=RWtzamZRc3Fid1NzakhNYnh0dS9QQ29vN3prYlBET1dSQStMOFVBVVBCZz0=&h=7619d154c25c4afe8bafdbfed2c6e387>,
or unsubscribe
<https://us-west-2.protection.sophos.com?d=github.com&u=aHR0cHM6Ly9naXRodWIuY29tL25vdGlmaWNhdGlvbnMvdW5zdWJzY3JpYmUtYXV0aC9BQUxXWUZTV1FISkZYUEpZWFVaRTNWM1ZXNllLRkFOQ05GU001NENaQkQzUQ==&i=NWYxNzBkMDNiNTVmZGEwZmIyNjczYmRm&t=NjE4OFR5UDZsS3lQczc1NzJSelVPLzhYVDFuM01ENlpuYmw0em9xdGdLRT0=&h=7619d154c25c4afe8bafdbfed2c6e387>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
No description provided.