1. IMPORTANT:
    We launched a new online community and this space is now closed. This community will be available as a read-only resources until further notice.
    JOIN US HERE

Trying to trigger kick drum with sustain pedal!!

Discussion in 'Scripting Workshop' started by jake369, Dec 17, 2014.

  1. jake369

    jake369 New Member

    Messages:
    23
    Hello, I have been trying to figure this one out for several days. I'm generally new to producing (about 1-2 years). I am attempting to map my sustain pedal to an instrument note (in my case a kick drum). So far from feedback elsewhere, I've been told to enter this into the script. Problem is..... (see below)

    on init
    declare $id := -1
    declare const $NOTE := 60 { <-- C3, change this }
    declare const $VELOCITY := 100 { <-- change this }
    end on

    on controller
    if ($id = -1 and %CC[64]>64+5) { play note }
    $id := play_note($NOTE, $VELOCITY, 0, -1)
    else
    if ($id # -1 and %CC[64]<64-5)
    note_off($id)
    $id := -1
    end if
    end if
    end on

    ...........when I copy and paste it into the script I always receive the message "ERROR (line 9): play_note is not allowed in this callback type!"

    I very much appreciate your assistance with this...
     
  2. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    This script works over here...
     
  3. jake369

    jake369 New Member

    Messages:
    23
    I cant fathom why it wouldnt work for me then...
     
  4. David Das

    David Das Moderator Moderator

    Messages:
    7,060
    Moved to scripting forum.
     
  5. Tangra

    Tangra Member

    Messages:
    35
    Because it is an Instrument Script which you try to paste into the Kontakt Multi Script Editor. As a result you have:
    "ERROR (line 9): play_note is not allowed in this callback type!".
    I just made a new Multi Script for you which will work in the Multi Script Editor. Copy & Paste it there. Assign the Input Channel, Input CC# (in your scenario CC64), Out MIDI Channel of the target Instrument you want to control, Note Number/Pitch and the Velocity in the provided value edit UIs.
    Code:
    on init
    set_script_title("A.G  :::  CC# to Note")
    declare $flag :=0
    declare ui_value_edit $In_Ch(1,16,1)
    set_text($In_Ch,"Input Ch")
    declare ui_value_edit $In_CC(-1,127,1)
    set_text($In_CC,"Input CC#")
    declare ui_value_edit $Out_Ch(1,16,1)
    set_text($Out_Ch,"Out Ch")
    declare ui_value_edit $Out_Note(0,127,0)
    set_text($Out_Note,"Out Note#")
    declare ui_value_edit $Out_Vel(0,127,1)
    set_text($Out_Vel,"Out Vel.")
    make_persistent($In_Ch)
    make_persistent($In_CC)
    make_persistent($Out_Ch)
    make_persistent($Out_Note)
    make_persistent($Out_Vel)
    end on
    
    on midi_in
    if ($In_CC>-1 and $flag=0 and $MIDI_CHANNEL=$In_Ch-1...
     and $MIDI_COMMAND=$MIDI_COMMAND_CC and...
      $MIDI_BYTE_1=$In_CC and $MIDI_BYTE_2>64)
    set_midi($Out_Ch-1,$MIDI_COMMAND_NOTE_ON,$Out_Note,$Out_Vel)
    $flag:=1
    else
    if ($MIDI_CHANNEL=$In_Ch-1 and $MIDI_BYTE_1=$In_CC and $MIDI_BYTE_2<64)
    set_midi($Out_Ch-1,$MIDI_COMMAND_NOTE_OFF,$Out_Note,0)
    $flag:=0
    end if
    end if   
    end on
     
    Last edited: Dec 18, 2014
  6. jake369

    jake369 New Member

    Messages:
    23
    Thank you very much for your time!! I'll try it out..
     
  7. Grégoire Durand

    Grégoire Durand New Member

    Messages:
    2
    Hello Guys!!!
    That look amazing! I have just one question, where to copy that code? I am on Mac. I tryed Terminal but it didn't work. Do you have a script editor in maschine?

    thanks you really much for your help!
     
  8. Lindon

    Lindon NI Product Owner

    Messages:
    322
    "maschine"? - this is a group dealing with coding in KSP in Kontakt,not Maschine.
     
  9. Grégoire Durand

    Grégoire Durand New Member

    Messages:
    2
    Yes i just saw that later... anyways, I had research for weeks to found a way to do it! Do you have any idea?
     
  10. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    You need Kontakt.
     
  11. Lindon

    Lindon NI Product Owner

    Messages:
    322
    Well, we are a bit biased...:)
     
  12. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    Haha, true. Well it does answer the question - above code will only work in Kontakt. :p