What's new

Play_note issue, i need help!

Libamaj

New Member
Hi Guys,
I'm not an expert, but in this simplified code there is an array that saves the note numbers when press the key, than play a note - the note number is the last saved position in the array, than message out the played note number, than decrase the counter when releasing the key.

if i delete the play_note line the messages is what i expected, but with the play_note command the first message is ok, but after all is 0.
if i put the message command in the on release than "array index out of bounds..." I don't understand, someone could explan it? Thanks.

Code:
on init
 message("")
  declare $note_id
  declare $counter := -1
  declare %notes[128]
end on

on note
  ignore_event($EVENT_ID)
  $counter := $counter+1
  %notes[$counter] := $EVENT_NOTE
  $note_id := play_note(%notes[$counter], $EVENT_VELOCITY, 0, -1)
  message(%notes[$counter])
end on

on release
  $counter := $counter-1
end on
 
The out of bounds message occurs if message() is called after reducing the counter. You should call it before. Then it should work.
 
the scripted play_note will also increase and decrease the counter

if you want to just keep track of the notes coming INTO Kontakt to increase and decrease the counter, you can use an if statement checking the EVENT PARAMETER SOURCE of the note. If it's -1, then it's from outside Kontakt (ie. keyboard or MIDI sequence or whatever)
 
Actually, it's something else.
The thing that happens is that the $counter is initially set to -1, then increased to 0 in the on note event, but then (and this is strange), in the on release event it is decreased from -1 and set to -2.
 
Actually, it's something else.
The thing that happens is that the $counter is initially set to -1, then increased to 0 in the on note event, but then (and this is strange), in the on release event it is decreased from -1 and set to -2.
$counter set to -1, then increased to 0 in the on note, then in the on release it is decreased from 0 to -1
if you press only one key
 
I was also not aware of this, but I cannot find any references to it in the manual. Can you provide a simple working example? Thanks!
from the manual
Code:
on note
message(get_event_par($EVENT_ID,$EVENT_PAR_SOURCE))
end on
check if the event comes from outside (-1) or if it was created in one of the five script slots (0-4)
 
Yes, of course. I was looking for it like you spelled it, forgetting that PARAMETER should be abbreviated to PAR

so something like this...
Code:
on init
 message("")
  declare $note_id
  declare $counter := -1
  declare %notes[128]
end on

on note
  ignore_event($EVENT_ID)
  if (get_event_par($EVENT_ID,$EVENT_PAR_SOURCE) = -1)
    $counter := $counter+1
    %notes[$counter] := $EVENT_NOTE
    $note_id := play_note(%notes[$counter], $EVENT_VELOCITY, 0, 1000)
  end if
  message(%notes[$counter])
end on

on release
  if (get_event_par($EVENT_ID,$EVENT_PAR_SOURCE) = -1)
    $counter := $counter-1
  end if
  message(%notes[$counter])
end on
 
Last edited:
Thank you guys! It is working now.

Code:
on init
 message("")
  declare $note_id
  declare $counter := -1
  declare %notes[128]
  declare $source
end on

on note
  ignore_event($EVENT_ID)
  $source := get_event_par($EVENT_ID, $EVENT_PAR_SOURCE)
  if $source = -1
    $counter := $counter+1
    %notes[$counter] := $EVENT_NOTE
  end if
  note_off($note_id)
  $note_id := play_note(%notes[$counter], $EVENT_VELOCITY, 0, -1)
  message(%notes[$counter])
end on

on release
    $source := get_event_par($EVENT_ID, $EVENT_PAR_SOURCE)
    if $source = -1
      $counter := $counter-1
    end if
end on
 
$counter set to -1, then increased to 0 in the on note, then in the on release it is decreased from 0 to -1
if you press only one key
Yes, I realize that was the intention, but it's not what actually happened, because there was this interference with the play_note event :)
 
Top Bottom