"change_tune is not Allowed in this callback type" but the script is fine!

Options
Paul1709
Paul1709 Member Posts: 1 Newcomer

hey, im trying to "program" an neighbor round robin script, i had some help in a different forum but its still not working, here is the script:

"on init

  declare $NewNoteID

  declare $RandResult

end on


on note

  ignore_event($EVENT_ID)

  $RandResult := random(1,3)

  select ($RandResult)

    case 1

      play_note($EVENT_NOTE, $EVENT_VELOCITY,0,-1)

    case 2

      $NewNoteID := play_note($EVENT_NOTE + 1, $EVENT_VELOCITY,0,-1)

      change_tune($NewNoteID, -100000,0)

    case 3

      $NewNoteID := play_note($EVENT_NOTE - 1, $EVENT_VELOCITY,0,-1)

      change_tune($NewNoteID, 100000,0)

end select


end on"

Kontakt says "change_tune is not Allowed in this callback type"

Can someone help me??

Im using Kontakt 6.7.1

Comments

  • DimitrisG
    DimitrisG Member Posts: 21 Member
    Options

    The error message you're seeing is due to the fact that change_tune is not allowed to be used within the on note callback in KSP.

    Your logic seems to be to randomly play one of three notes when a key is pressed: the actual note, the note above, or the note below. For the latter two, you're attempting to compensate for the change in pitch with change_tune, but since this function isn't allowed in the on note callback, you'll have to approach this problem differently.

    Instead of adjusting the pitch with change_tune, you can prepare your samples in advance so they match the desired pitches, allowing you to simply trigger the corresponding sample directly. If this is not feasible, you might consider using other methods such as adjusting the group tuning in real-time or employing other real-time pitch manipulation techniques compatible with your Kontakt version.

    However, if the core of your goal is simply to play neighboring notes in a round-robin fashion, you don't need to adjust tuning at all. You can use the play_note function alone to trigger the notes.

    Here's an example that should work:

    on init
       declare $RandResult
    end on
    
    on note
       ignore_event($EVENT_ID)
    
       $RandResult := random(1,3)
    
       select ($RandResult)
           case 1
               play_note($EVENT_NOTE, $EVENT_VELOCITY, 0, -1)
           case 2
               play_note($EVENT_NOTE + 1, $EVENT_VELOCITY, 0, -1)
           case 3
               play_note($EVENT_NOTE - 1, $EVENT_VELOCITY, 0, -1)
       end select
    end on
    


  • stephen24
    stephen24 Member Posts: 303 Pro
    edited November 2023
    Options

    You must have missed something out when you copied your code. What you published is accepted perfectly well in my K5 Script Editor. (I haven't tested the script)

    on init
     declare $NewNoteID
     declare $RandResult
    end on
    
    on note
     ignore_event($EVENT_ID)
     $RandResult := random(1,3)
     select ($RandResult)
       case 1
         play_note($EVENT_NOTE, $EVENT_VELOCITY,0,-1)
       case 2
         $NewNoteID := play_note($EVENT_NOTE + 1, $EVENT_VELOCITY,0,-1)
         change_tune($NewNoteID, -100000,0)
       case 3
         $NewNoteID := play_note($EVENT_NOTE - 1, $EVENT_VELOCITY,0,-1)
         change_tune($NewNoteID, 100000,0)
    end select
    end on
    

    (Sudden thought. This is an instrument script, not a multiscript, right?) Correct me if I'm wrong.

Back To Top