Skip to content
Eduardo Moguillansky edited this page Apr 20, 2020 · 1 revision

This is a csd to test csound MIDI. Save it as "miditest.csd" and run it as csound miditest.csd

<CsoundSynthesizer>
<CsOptions>
-odac 
-d                 ; supress displays (waveforms, etc)
--messagelevel=0   ; no messages
-+rtmidi=portmidi
-Mall              ; connect to all midi ports

</CsOptions>

<CsInstruments>
ksmps  = 64

opcode strAssign, S, S
  Sin xin
  Sout sprintfk "%s", Sin
  xout Sout
endop

opcode statusString, S, k
  kstatus xin
  if kstatus == 144 then
    Sout strAssign "Noteon"
  elseif kstatus == 176 then
    Sout strAssign "CC"
  elseif kstatus == 128 then
    Sout strAssign "Noteoff"
  elseif kstatus == 192 then
    Sout strAssign "ProgramChange"
  elseif kstatus == 224 then
    Sout strAssign "PitchWheel"
  else
    Sout strAssign "Unknown"
  endif
  xout Sout
endop

instr midi
  kt = timeinstk()
  kstatus, kchan, k1, k2  midiin
  if kstatus == 0 kgoto finish
  Sstatus statusString kstatus
  printf "status: %d (%s), chan: %d, value1: %d, value2: %d \n", \
                  kt, kstatus, Sstatus, kchan, k1, k2
  finish:
endin

</CsInstruments>

<CsScore>

i "midi" 0 3600

</CsScore>
</CsoundSynthesizer>