Csound Csound-dev Csound-tekno Search About

Re: [Csnd] how to allocate two different sounds via midi-key-number

Date2014-05-19 18:13
From"Art Hunkins"
SubjectRe: [Csnd] how to allocate two different sounds via midi-key-number
If you don't choose to use the table lookup method Rory suggested, I suspect that the code substitution below might be the most compact coding (since there are fewer black keys than white).
 
Art Hunkins
----- Original Message -----
Sent: Monday, May 19, 2014 12:06 PM
Subject: [Csnd] how to allocate two different sounds via midi-key-number

Dear community,
I want to allocate two different sounds to different midi-keys.
My aim is to get one sound for the black and another sound for the white keys.
I've started with the following code which works.
But my question is:
Is the maybe a more confortabe way to do this? If I use my method the if condition would be very long!
Here is my code:
<CsoundSynthesizer>
<CsOptions>
-odac -Ma -m0d
</CsOptions>
; ==============================================
<CsInstruments>

sr    =    44100
nchnls    =    2
0dbfs    =    1
gisine ftgen 0,0,2^13, 10, 1
alwayson 1
massign 0, 1
instr 1   
    iamp     ampmidi 0.2
    icps     cpsmidi
    inotnum    notnum
    iatt     = 0.01
    idur     = 3
    irel     = 0.1
    aenv     linsegr 0,iatt,1,idur,0,irel,0
    inotnum  = inotnum % 12
    if ( (inotnum == 1) || (inotnum == 3) || (inotnum == 6) || (inotnum == 8) || (inotnum == 10) ) then
    aout    rand    aenv*iamp
    else
    aout    poscil    aenv*iamp,icps
    endif
   
    outs    aout, aout   
    endin

</CsInstruments>
; ==============================================
<CsScore>

</CsScore>
</CsoundSynthesizer>