Ive cut this out of a larger ensemble, so there may be some redundant / wierd code, or slightly idiosyncratic things going on, but it should give you another example to pour over & hopefully find some useful ideas.
it uses cc1 (modwheel) to model what would happen when controlled by cc2 breath control. just change the appropraite cc number - there's a note to this effect in the code.
you'll no doubt have to fiddle around with it. take & use what is of any use.
hope it helps / is of interest.
;;;************************
;;;************************
;;;************************
<CsoundSynthesizer>
<CsOptions>
;;; --midi-device=0
-d
</CsOptions>
<CsInstruments>
sr = 48000
ksmps = 16
nchnls = 2
0dbfs = 1
gicctodBmap ftgen 1,0,128,-7,-50,128,0
gamp init 0
gktakeover init 0 ;;;soft takeover release start for notes
;;;truncated during atk phase
gkPORTOtakeover init 0
gisine ftgen 100, 0, 16384, 10, 1
zakinit 2,1
massign 0,0
;;;************************
;;;************************
;;;************************
;;;DEFINE UDOS
opcode tieStatus,i,0
itie tival
if (itie == 0 && p3 < 0) ithen
; this is an initial note within a group of tied notes
itiestatus = 0
elseif (p3 < 0 && itie == 1) ithen
; this is a middle note within a group of tied notes
itiestatus = 1
elseif (p3 > 0 && itie == 1) ithen
; this is an end note out of a group of tied notes
itiestatus = 2
elseif (p3 > 0 && itie == 0) ithen
; this note is a standalone note
itiestatus = -1
endif
xout itiestatus
endop
opcode MIDI2cpsi, i, i
imidi xin
inotexpo = (imidi-69)/12
i2x = powoftwo (inotexpo)
icps = i2x*440
xout icps
endop
opcode MIDI2cpsk, k, k
kmidi xin
knotexpo = (kmidi-69)/12
k2x = powoftwo (knotexpo)
kcps = k2x*440
xout kcps
endop
;;;************************
;;;************************
;;;************************
;;;USER MIDI INPUT
instr 01
kactivenote init -1
kinsttarget = 100
;;;**************
;;; raw midi input
kstatus, kchan, kdata1, kdata2 midiin
if (kstatus == 144) then
;;noteon
if (kdata2 != 0) then
if kactivenote != -1 then
;;;switch off currently active note
event "i", kinsttarget, 0, .01, kactivenote
endif
;;;transmit new note
knote = kdata1
event "i", kinsttarget, 0, -.1, kdata1
;;;log new note as active note
kactivenote = kdata1
printk2 kactivenote
endif
endif
;;;**************
;;; test using modwheel (icc = 1)
;;;change to cc2 for breath control (icc = 2)
icc = 1
kbreath ctrl7 1,icc,0,127
;;;**************
;;;breath control Xing conditional triggers
koffflag trigger kbreath, 1, 1
konflag trigger kbreath, 0.5, 0
printk2 koffflag,10
printk2 konflag,5
if koffflag == 1 && kactivenote != -1 then
;;;switch off currently active note
event "i", kinsttarget, 0, .01, kactivenote
elseif konflag == 1 && kactivenote != -1 then
event "i", kinsttarget, 0, -.1, kactivenote
endif
kdB table kbreath, 1
kdB port kdB,.02
kamp = ampdb(kdB)
adB = a(kdB)
aamp = ampdb(adB)
gamp = aamp
endin
;;; *********
;;; INSTR 100
;;; SIMPLE SINE SYNTH
instr 100
imidi = p4
icps MIDI2cpsi imidi
kmidi init imidi
iportostart = i(gkPORTOtakeover)
;;;TIED NOTE?
itie tieStatus
itakeover = i(gktakeover)
if itie == 0 then ;; initial tied note
iphase = 1
aenv linseg 0,.005,1,0,1
;aenv = 1
kenv linseg 0,.005,1,0,1 ;;;for soft takeover purposes
gktakeover = kenv
kporto init imidi
elseif itie == 1 then
iphase = -1
aenv = a(gktakeover)
;aenv = 1
kporto linseg iportostart,.25,imidi,0,imidi ;;;for soft takeover purposes
elseif itie == 2 then
iphase = -1
aenv linseg itakeover,.01,0,0,1
kporto linseg iportostart,.25,imidi,0,imidi ;;;for soft takeover purposes
endif
;print itie
gkPORTOtakeover = kporto
kcps MIDI2cpsk kporto
asig oscili aenv, kcps, 100, iphase
zawm asig, 0
endin
;;;************************
;;;************************
;;;************************
;;;global amplitude control
instr 10000
ain zar 0
aout = ain*gamp
aout = aout*.5
outs aout,aout
zacl 0, 1
endin
;;;************************
;;;************************
;;;************************
</CsInstruments>
<CsScore>
i 1 0 360
i 10000 0 360
e
</CsScore>
</CsoundSynthesizer>