Change Midi Channel

Options
Eduardo Gamero
Eduardo Gamero Member Posts: 30 Member

I try to change the midi channel but I don't know what I'm doing wrong...




on midi_in


  if ($MIDI_COMMAND = $MIDI_COMMAND_CC and $MIDI_BYTE_1=1 and $MIDI_BYTE_2<=63)

    ignore_midi

    set_event_par($EVENT_ID,$EVENT_PAR_MIDI_CHANNEL,0)

    exit

  end if


  if ($MIDI_COMMAND = $MIDI_COMMAND_CC and $MIDI_BYTE_1=1 and $MIDI_BYTE_2>=64)

    ignore_midi

    set_event_par($EVENT_ID,$EVENT_PAR_MIDI_CHANNEL,1)

    exit

  end if


end on

Comments

  • stephen24
    stephen24 Member Posts: 296 Pro
    Options

    Not clear what you're trying to do.

    How exactly do you want Kontakt to respond to cc#1 messages?

  • Eduardo Gamero
    Eduardo Gamero Member Posts: 30 Member
    Options

    I'm trying to make the midi channel change, that is...

    If cc1 <=63 the instrument I have on channel 1 is activated and if cc1 >=64 the instrument I have on channel 2 is activated...


  • stephen24
    stephen24 Member Posts: 296 Pro
    Options

    It's probably a good idea to thoroughly master the MIDI protocol before attempting multiscripts. There are loads of articles on the internet.

    To do what you require, every MIDI message has to be changed to your chosen channel. Something like this

    1. Declare an integer variable $Mychannel.
    2. If a cc#1 message comes in, alter this variable accordingly (eg make $Mychannel equal to 2nd byte/64)
    3. Use set_event_par to change the channel of all other incoming MIDI to $Mychannel.

    You won't need ignore_midi or exit.

  • Eduardo Gamero
    Eduardo Gamero Member Posts: 30 Member
    Options

    Could you show me how to do it please? Sorry but I do not know much about the code, what I have achieved so far has been thanks to tutorials and forums like this, and it is the only thing that I need to finish my script, I promise to share it as soon as it is finished. I need to make a switch make me that change between channel 1 and channel 2, I appreciate your help friend.

  • Eduardo Gamero
    Eduardo Gamero Member Posts: 30 Member
    Options

    Oh I already understood how to do it... you were right I was able to make it work, thank you very much for your help friend.

  • stephen24
    stephen24 Member Posts: 296 Pro
    edited January 2023
    Options

    Glad you did it yourself - it's very satisfying to write a working script. You should probably put in a All Notes Off when switching channels, to prevent hanging notes. You may still get hanging pedals. Something like

    on init

     declare $Mychannel := 0

    end on


    on midi_in

     if ($MIDI_COMMAND = $MIDI_COMMAND_CC and $MIDI_BYTE_1 = 1)

      set_midi ($Mychannel,$MIDI_COMMAND_CC,123,0)

      $Mychannel := $MIDI_BYTE_2/64

     else

      set_event_par($EVENT_ID, $EVENT_PAR_MIDI_CHANNEL, $Mychannel)

     end if

    end on

  • Eduardo Gamero
    Eduardo Gamero Member Posts: 30 Member
    Options

    I don't think I know how to put All Notes Off... what would the code look like then?

  • Eduardo Gamero
    Eduardo Gamero Member Posts: 30 Member
    Options

    And how can I activate multiple channels at the same time?

Back To Top