Cabbage Logo
Back to Cabbage Site

Midi cc value to midi channel


Is it possible to convert midi cc value to midi channel ?
For example:
if incoming midi cc32 = 1 then send all incoming notes-on/notes-off to midi channel 1
if incoming midi cc32 = 5 then send all incoming notes-on/notes-off to midi channel 5

Any example will be very appreciate :slight_smile:


I guess it should be possible, although I’ve never tried it myself. I guess the midiin and midiout opcodes are what to look for here.

Hello Rory

What’s wrong with this code. Can’t monitor midi signal. No input or output midi ? :frowning:

-n -d -+rtmidi=NULL -M0 -m0d
; Initialize the global variables. 
ksmps = 32
nchnls = 0
0dbfs = 1

instr 1
    kOutputChannel init 1
    kNoteOnChan[] init 127
    ; read midi input data
    kStatus, kChannel, kData1, kData2 midiin

    ; if midicc signal and midicc value = 32
    if (kStatus == 176 && kData1 == 32) then
        ; save new midi channel = midicc value
        kOutputChannel = kData2
        ; route new midi channel
        kChannel = kOutputChannel
    ; if midi noteOn
    elseif kData1 = 144 then
        ; midi channel note = kOutputChannel
        kChannel = kOutputChannel
        ; save midi channel for current midi NoteOn (needs for NoteOff later)
        kNoteOnChan[kData1] = kOutputChannel    
    ; if midi noteOff
    elseif kStatus == 128 then
        ; read correspondaing noteOn midi chan used
        kChannel = kNoteOnChan[kData1]

    ; send midi output data
    midiout kStatus, kChannel, kData1, kData2


; Initialize MIDI input
i 1 0 -1

You need to use the -Q CsOptions flag in order to output MIDI. But you should be able to monitor MIDI input? There is a good example here of getting MIDI info from midiin. In fact, the entire chapter on MIDI is a great resource.