Send MIDI to Outside World - Instrument Script Not Sending Correct Note-Off

Options
LydianArt
LydianArt Member Posts: 2 Member
edited August 2023 in Scripting Workshop

I have a problem with Kontakt 6.7.1 where instrument scripts are sending note-off messages, to the outside world, for the incoming note instead of the note changed by the script.

I've tried a couple factory instrument scripts:

  • Randomize Pitch
  • Change Keys

and both exhibit the same incorrect behavior.

After some troubleshooting, I've narrowed down the problem to the instrument script change_note() function. Here's a minimal instrument script to reproduce the problem:

on note
	{ Always play G3 }
	change_note($EVENT_ID, 67)
end on

For example, if the note C3 is received by this instrument script, which always changes the note to G3, a note-off message for C3 instead of G3 is sent to the outside world.

These are the options I have enabled for sending MIDI to the outside world in Kontakt:

Here's a screenshot illustrating this problem with a MIDI monitor in Cubase:

  1. Kontakt is being sent the note C3
  2. The instrument script always sends G3
  3. The MIDI output of Kontakt is being sent to a MIDI track with a MIDI monitor
  4. The MIDI monitor shows note-on G3 and a note-off C3 (the incoming note) instead of G3 (note changed with change_note() function)

This only seems to be a problem with instrument scripts, and multi-scripts behave correctly when sending MIDI to the outside world. If use the factory multi-script:

  • Change Keys

the correct note-off message is sent to the outside world.

Here's a screenshot of the correct MIDI being sent to the outside world when using a multi-script:

It seems like this is a bug, but maybe there's something I'm doing wrong.

Thanks for the help!

Comments

  • noY_T
    noY_T Member Posts: 37 Member
    Options

    Maybe try this:

    on init
     declare $noteID
    end on
    
    on note
     ignore_event($EVENT_ID)
     $noteID := play_note(67,$EVENT_VELOCITY,0, -1)
    end on
    
  • LydianArt
    LydianArt Member Posts: 2 Member
    Options

    Thanks for the help @noY_T !

    Your suggestion led me to find a fix for this issue.

    First, I changed the settings for Send MIDI to Outside World to:

    1. Incoming notes [OFF]
    2. Incoming CCs [OFF]
    3. Script generated notes [ON]
    4. Script generated CCs [ON]

    Finally, I added this minimal script only if the factory instrument script(s) in use don't generate notes/CCs:

    on note
      play_note($EVENT_NOTE, $EVENT_VELOCITY, 0, -1)
    end on
    
    on controller
      set_controller($CC_NUM, %CC[$CC_NUM])
    end on
    

    This combination results in the correct MIDI note on/off (and CC) information being sent to the outside world.

    It seems like this is definitely a bug. I also tested the scenario in Kontakt 7 and the same behavior happens there and the fix also works too.

    Thanks again for the help - I REALLY appreciate it!

Back To Top