Re: [Csnd] Problems With If-Then Statements: Switch
| Date | 2012-09-22 19:10 |
| From | David Mooney |
| Subject | Re: [Csnd] Problems With If-Then Statements: Switch |
This doesn't really address your problem, but when using multiple
conditionals as you show I've often thought it would be handy if
Csound had a switch structure, as in C++. Given the variable kval (or
ival), and possible numerical values 1-n for kval, a switch looks like
this:
switch(kval) {
case 1:
|
| Date | 2012-09-22 20:58 |
| From | "Dr. Richard Boulanger" |
| Subject | Re: [Csnd] Problems With If-Then Statements: Switch |
This would be nice. Sent from my iPhone. On Sep 22, 2012, at 2:10 PM, David Mooney |
| Date | 2012-09-22 23:18 |
| From | Jim Aikin |
| Subject | [Csnd] Re: Problems With If-Then Statements: Switch |
Possibly I'm off-base here. (I didn't see the original message, only the response from David.) But it appears that this line: irecord3 = i(krecord3) is going to run (during the init-pass) BEFORE krecord3 has been assigned a value, because krecord3 has not been given an initial value by using the init opcode. That may have nothing to do with the problem, but I'm suspicious of it. -- View this message in context: http://csound.1045644.n5.nabble.com/Re-Problems-With-If-Then-Statements-Switch-tp5716029p5716047.html Sent from the Csound - General mailing list archive at Nabble.com. |
| Date | 2012-09-23 00:19 |
| From | Roger Kelly |
| Subject | Re: [Csnd] Problems With If-Then Statements: Switch |
I am trying to do the exact same thing at this moment. What is the best way to turn on and off this instrument so that it can record and playback using diskin. Someone mentioned using schedwhen instead of turnon/off. Is that the best solution?
instr 500 krec chnget "record_500" kstop chnget "stop_500"
kplay chnget "play_500" karm_1 chnget "arm1_500" karm_2 chnget "arm2_500" karm_3 chnget "arm3_500"
karm_4 chnget "arm4_500" kmonitor_1 chnget "monitor1_500"
kmonitor_2 chnget "monitor2_500" kmonitor_3 chnget "monitor3_500"
kmonitor_4 chnget "monitor4_500" imonitor_1 = i(kmonitor_1)
iarm_1 = 0 iarm_2 = 0
iarm_3 = 0 iarm_4 = 0 ;trac1, trac2, trac3, trac4 a1_l zar 1 a1_r zar 2
a2_l zar 3 a2_r zar 4 a3_l zar 5
a3_r zar 6 a4_l zar 7 a4_r zar 8
; al,ar diskin2 "/mnt/sdcard/testaudio/track1.wav", 1.01 printks "Monitor 1 %f\n", .3, kmonitor_1 if (krec == 1.0 ) then ;all_l,all_r monitor ;fout "/mnt/sdcard/testaudio/master.wav", 14, all_l, all_r
; printks "kmon %f, %f, %f\n", .2, imonitor_1, karm_1, iarm_1
if (karm_1 == 1.0 && iarm_1 == 0.0) then printks "Writig track 1", .2
fout "/mnt/sdcard/testaudio/track1.wav", 14, a1_l, a1_r iarm_1 = 1
endif if (karm_2 == 1.0 && iarm_2 == 0.0) then printks "Writig track 2", .2
fout "/mnt/sdcard/testaudio/track2.wav", 14, a2_l, a2_r iarm_2 = 1
endif if (karm_3 == 1.0 && iarm_3 == 0.0) then printks "Writig track 3", .2
fout "/mnt/sdcard/testaudio/track3.wav", 14, a3_l, a3_r iarm_3 = 1
endif if (karm_4 == 1.0 && iarm_4 == 0.0) then printks "Writig track 4", .2
fout "/mnt/sdcard/testaudio/track4.wav", 14, a4_l, a4_r iarm_4 = 1
endif if (kmonitor_1 == 1.0) then
printks "MONITOR 1 ", .7 al,ar diskin2 "/mnt/sdcard/testaudio/track1.wav", 1.01
outs al, ar endif if (kmonitor_2 == 1.0) then
printks "MONITOR ", .2 al,ar diskin2 "/mnt/sdcard/testaudio/track2.wav", 1.01
outs al, ar endif if (kmonitor_3 == 1.0) then
printks "MONITOR ", .2 al,ar diskin2 "/mnt/sdcard/testaudio/track3.wav", 1.01
outs al, ar endif if (kmonitor_4 == 1.0) then
printks "MONITOR ", .2 al,ar diskin2 "/mnt/sdcard/testaudio/track4.wav", 1.01
outs al, ar endif endif if (kstop == 1 ) then krec = 0
iarm_1 = 0 ;copy current file to the "listen file" chnset 0,"record_500"
;turnoff endif
endin On Sat, Sep 22, 2012 at 1:10 PM, David Mooney <dmooney023@gmail.com> wrote: This doesn't really address your problem, but when using multiple |
| Date | 2012-09-24 17:27 |
| From | joachim heintz |
| Subject | Re: [Csnd] Problems With If-Then Statements: Switch |
sorry for coming late in this thread and not reading everything
carefully (so maybe i will repeat something which has been written
already), but i think the question here is not using sched(k)when or
not, but to understand i- and k-rate conditions, and find out the best
(or one working) architecture of the instruments.
if i understood correctly, you have a control input at k-rate, and you
want to trigger an instrument once a specific control input has been
reached. and you want to turn off this instrument in case another value
has benn reached.
this code ...
> if (krecord1 == 1) then
> turnon "sample1"
> elseif (krecord1 == 0) then
> turnoff2 "sample1",0,0
> endif
... is not far from working, but has two problems:
1. the conditions 'if (krecord1 == 1)' and 'if (krecord1 == 0)' will
usually not be true once (= for one k-cycle), but for several k-cycles.
so, if you then trigger instrument "sample1", you will trigger it
multiple times, this means: you will create multiple instances.
to ensure you trigger it just once, in the moment krecord1 has entered
the value 1 resp. 0, you must add a line like this:
knewval changed krecord1
2. as you are not at the beginning of the instrument invocation (= at
i-rate), but during its performance (= at k-rate), to trigger an
instrument, you must use a k-rate opcode to turn the subinstrument on.
the manual states that the "turnon" opcode just works with an i-rate
input. you must use "event" (or schedkwhen) instead ("turnoff2" is ok -
it works at k-rate).
so this should be a working code:
knewval changed krecord1
if (krecord1 == 1 && knewval == 1) then
event "i", "sample1", 0, 99999
elseif (krecord1 == 0 && knewval == 1) then
turnoff2 "sample1",0,0
endif
does this make sense and help? for further reading, i'd suggest jim
aikin's book, or these articles online:
http://en.flossmanuals.net/csound/a-initialization-and-performance-pass
http://en.flossmanuals.net/csound/e-triggering-instrument-events
joachim
Am 23.09.2012 01:19, schrieb Roger Kelly:
> I am trying to do the exact same thing at this moment. What is the best
> way to turn on and off this instrument so that it can record and
> playback using diskin.
>
> Someone mentioned using schedwhen instead of turnon/off. Is that the
> best solution?
>
>
> instr 500
> krec chnget "record_500"
> kstop chnget "stop_500"
> kplay chnget "play_500"
> karm_1 chnget "arm1_500"
> karm_2 chnget "arm2_500"
> karm_3 chnget "arm3_500"
> karm_4 chnget "arm4_500"
> kmonitor_1 chnget "monitor1_500"
> kmonitor_2 chnget "monitor2_500"
> kmonitor_3 chnget "monitor3_500"
> kmonitor_4 chnget "monitor4_500"
> imonitor_1 = i(kmonitor_1)
> iarm_1 = 0
> iarm_2 = 0
> iarm_3 = 0
> iarm_4 = 0
> ;trac1, trac2, trac3, trac4
> a1_l zar 1
> a1_r zar 2
> a2_l zar 3
> a2_r zar 4
> a3_l zar 5
> a3_r zar 6
> a4_l zar 7
> a4_r zar 8
> ;al,ar diskin2 "/mnt/sdcard/testaudio/track1.wav", 1.01
> printks "Monitor 1 %f\n", .3, kmonitor_1
> if (krec == 1.0 ) then
> ;all_l,all_r monitor
> ;fout "/mnt/sdcard/testaudio/master.wav", 14, all_l, all_r
> ;printks "kmon %f, %f, %f\n", .2, imonitor_1, karm_1, iarm_1
> if (karm_1 == 1.0 && iarm_1 == 0.0) then
> printks "Writig track 1", .2
> fout "/mnt/sdcard/testaudio/track1.wav", 14, a1_l, a1_r
> iarm_1 = 1
> endif
> if (karm_2 == 1.0 && iarm_2 == 0.0) then
> printks "Writig track 2", .2
> fout "/mnt/sdcard/testaudio/track2.wav", 14, a2_l, a2_r
> iarm_2 = 1
> endif
> if (karm_3 == 1.0 && iarm_3 == 0.0) then
> printks "Writig track 3", .2
> fout "/mnt/sdcard/testaudio/track3.wav", 14, a3_l, a3_r
> iarm_3 = 1
> endif
> if (karm_4 == 1.0 && iarm_4 == 0.0) then
> printks "Writig track 4", .2
> fout "/mnt/sdcard/testaudio/track4.wav", 14, a4_l, a4_r
> iarm_4 = 1
> endif
> if (kmonitor_1 == 1.0) then
> printks "MONITOR 1 ", .7
> al,ar diskin2 "/mnt/sdcard/testaudio/track1.wav", 1.01
> outs al, ar
> endif
> if (kmonitor_2 == 1.0) then
> printks "MONITOR ", .2
> al,ar diskin2 "/mnt/sdcard/testaudio/track2.wav", 1.01
> outs al, ar
> endif
> if (kmonitor_3 == 1.0) then
> printks "MONITOR ", .2
> al,ar diskin2 "/mnt/sdcard/testaudio/track3.wav", 1.01
> outs al, ar
> endif
> if (kmonitor_4 == 1.0) then
> printks "MONITOR ", .2
> al,ar diskin2 "/mnt/sdcard/testaudio/track4.wav", 1.01
> outs al, ar
> endif
> endif
> if (kstop == 1 ) then
> krec = 0
> iarm_1 = 0
> ;copy current file to the "listen file"
> chnset 0,"record_500"
> ;turnoff
> endif
> endin
>
> On Sat, Sep 22, 2012 at 1:10 PM, David Mooney |