Hello ,
I am trying to implement the aftertouh function with csound… The opcode aftouch behaves strangely.
I get from time to time an error message :undefined sys_common msg f4 do you have any idea of what it is ?
Also , the opcode aftouch seems to be badly updated : I compare it with Pure data : when pure data starts at zero and respond very well to the pressure on my keyboard, the Csound opcode can stay on a value it has received previously.
Does anyone know how to implement aftertouch correctly with Csound ? or is this opcode buggy ?
Thank you for help.
I think @iainmccurdy is the best one to comment on this. I’ve never used after touch with Csound.
I haven’t used aftouch in a long time but I give it a go when I get to a keyboard with aftertouch.
An alternative approach would be to read the data in using midiin and filter into the aftertouch data by using its status byte and channel (I can’t remember what the status byte for aftertouch will be but you could easily test to find out what this is by using midiin and print messages.
The status byte value appears to be 208 so you can try this and see if it works any better:
kstatus,kchan,kdata1,kdata2 midiin
if (kstatus==208 && kchan==1) then
kAftouch = kdata1
endif
printk2 kAftouch
Thank you @iainmccurdy . I encounter the same trouble : whn the note is released, then the aftertouch remains sometimes at the previous value and also some error messages : undefined sys-realtime msg XX XX being a value : fd, f4, f9 etc…
Also, from time to time, a note remains playing on for ever… which is annoying.
I am wondering how much compatible is midiin with the flags on csound option from cabbbage -n -d -+rtmidi=NULL -M0 -m0d --midi-key-cps=4 --midi-velocity-amp=5 . Is there a risk of double messages ?
Here is the code, what do I do wrong ? Thank you for your help :
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d --midi-key-cps=4 --midi-velocity-amp=5
</CsOptions>
<CsInstruments>
; Initialize the global variables.
sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1
instr 130
iNum notnum
kstatus,kchan,kdata1,kdata2 midiin
if (kstatus==144 && kchan==1) then
if kdata2==0 then
kAft=0
endif
elseif (kstatus==208 && kchan==1) then
kAft = kdata1
endif
if kAft !=0 then
kAft_LFO lfo kAft/128, kAft/12.8
else
kAft_LFO =0
endif
kPitch = cpsmidinn(iNum+kAft_LFO)
kEnv madsr 0.1,0.2,.85,0.3
asig oscil p5, kPitch, 1
outs asig*kEnv, asig*kEnv
endin
</CsInstruments>
<CsScore>
;sine wave.
f 1 0 16384 10 1
i 130 0 z
</CsScore>
</CsoundSynthesizer>
Hello Iain, @iainmccurdy
Did you have the opportunity to dig into the aftertouch problem ?
I checked it today again : it seems that there is something wrong with the way the message are interpreted/updated at k-rate . The following code is included into cabbage instrument
; -- aftertouch --
kAfttch aftouch 0,0.9 ; read in aftertouch (range 0 to 0.9)
printks "aft : %f \n",0,kAfttch
First key is pressed : here is the output with aftertouch :
then
Cabbage console shows the following until the key is released :
aft : 0.900000
aft : 0.900000
aft : 0.900000
...
aft : 0.900000
then pressing a new key deeper to unlock the aftouch shows :
aft : 0.900000
aft : 0.481890
aft : 0.481890
aft : 0.481890
aft : 0.481890
...
aft : 0.481890
aft : 0.481890
Comparing with midi-ox log clearly shows that aftertouch is either wrong or I can figure how to use it (most likely):
===> MIDI-OX Version: 7.0.2.372
===> Log Opened: Mon 02-Oct-2017 17:57:34 ===>
TIMESTAMP IN PORT STATUS DATA1 DATA2 CHAN NOTE EVENT
2373046 1 4 144 77 30 1 F 5 Note On
2373085 1 4 208 8 --- 1 --- Channel Aft
2373085 1 4 208 22 --- 1 --- Channel Aft
2373085 1 4 208 32 --- 1 --- Channel Aft
2373086 1 4 208 37 --- 1 --- Channel Aft
2373086 1 4 208 42 --- 1 --- Channel Aft
2373087 1 4 208 47 --- 1 --- Channel Aft
2373088 1 4 208 54 --- 1 --- Channel Aft
2373089 1 4 208 58 --- 1 --- Channel Aft
2373089 1 4 208 63 --- 1 --- Channel Aft
2373090 1 4 208 70 --- 1 --- Channel Aft
2373091 1 4 208 74 --- 1 --- Channel Aft
2373092 1 4 208 78 --- 1 --- Channel Aft
2373092 1 4 208 82 --- 1 --- Channel Aft
2373093 1 4 208 86 --- 1 --- Channel Aft
2373095 1 4 208 89 --- 1 --- Channel Aft
2373097 1 4 208 93 --- 1 --- Channel Aft
2373098 1 4 208 96 --- 1 --- Channel Aft
2373100 1 4 208 100 --- 1 --- Channel Aft
2373102 1 4 208 104 --- 1 --- Channel Aft
2373104 1 4 208 108 --- 1 --- Channel Aft
2373107 1 4 208 111 --- 1 --- Channel Aft
2373109 1 4 208 115 --- 1 --- Channel Aft
2373113 1 4 208 119 --- 1 --- Channel Aft
2373119 1 4 208 122 --- 1 --- Channel Aft
2373124 1 4 208 126 --- 1 --- Channel Aft
2373125 1 4 208 127 --- 1 --- Channel Aft
2373461 1 4 208 126 --- 1 --- Channel Aft
2373462 1 4 208 121 --- 1 --- Channel Aft
2373465 1 4 208 118 --- 1 --- Channel Aft
2373468 1 4 208 114 --- 1 --- Channel Aft
2373471 1 4 208 111 --- 1 --- Channel Aft
2373473 1 4 208 107 --- 1 --- Channel Aft
2373476 1 4 208 103 --- 1 --- Channel Aft
2373477 1 4 208 99 --- 1 --- Channel Aft
2373478 1 4 208 95 --- 1 --- Channel Aft
2373480 1 4 208 91 --- 1 --- Channel Aft
2373481 1 4 208 87 --- 1 --- Channel Aft
2373482 1 4 208 83 --- 1 --- Channel Aft
2373483 1 4 208 79 --- 1 --- Channel Aft
2373484 1 4 208 75 --- 1 --- Channel Aft
2373485 1 4 208 71 --- 1 --- Channel Aft
2373486 1 4 208 66 --- 1 --- Channel Aft
2373486 1 4 208 60 --- 1 --- Channel Aft
2373487 1 4 208 54 --- 1 --- Channel Aft
2373487 1 4 208 49 --- 1 --- Channel Aft
2373488 1 4 208 45 --- 1 --- Channel Aft
2373489 1 4 208 37 --- 1 --- Channel Aft
2373489 1 4 208 28 --- 1 --- Channel Aft
2373490 1 4 208 20 --- 1 --- Channel Aft
2373490 1 4 208 13 --- 1 --- Channel Aft
2373491 1 4 208 0 --- 1 --- Channel Aft
2373533 1 4 128 77 30 1 F 5 Note Off
2381763 1 4 144 76 30 1 E 5 Note On
2382081 1 4 128 76 30 1 E 5 Note Off
<=== MIDI-OX Log Closed: Mon 02-Oct-2017 17:59:17 <===
I didn’t get a chance to look at this yet! I’m still in Uruguay at the conference but I’ll try to investigate when I get back.
I finally got a chance to test this. I found the data output by aftouch within Cabbage 2 (Mac) to match that shown by a MIDI monitor program equivalent to MIDI-Ox. The only issue I encountered was that until aftouch receives some information from the aftertouch hardware it outputs its maximum value (127). I suspect this is an issue with the opcode but a workaround is to not use aftouch at all but instead take in aftertouch data in a separate always-on instrument using midiin as I think I suggested earlier and as you were trying also. Channel aftertouch uses status byte value 208 and it then uses data1 as its value. I am assuming you are using channel aftertouch as keyboards with polyphonic aftertouch are like unicorns. Here is the code:
instr AlwaysOn
kstatus,kchan,kdata1,kdata2 midiin
if kstatus==208 then
gkAftouch = kdata1
endif
endin
This also assumes you aren’t concerned about what channel it comes in on.
I am not getting any of the problems with “undefined sys-realtime…” errors that you mentioned previously, nor I am getting problems with stuck notes. The problem you mentioned with aftouch where is holds its previous value is slightly expected as new MIDI data is only generated when that type of data changes. Having said this, my MIDI notes always end on a zero when I use aftertouch, which is what would be expected as releasing a note means releasing pressure. Can you test your code that produces errors with alternative hardware?
Referring to a previous bit of code you posted, maybe printks2 is preferrable to printks with zero seconds between printings. Cabbage has always struggled a bit with printing to its terminal, although I think this has been improved recently. So instead of:
printks "aft : %f \n",0,kAfttch
use:
printks2 "aft : %f \n",kAfttch