Discussion:
[Linuxsampler-devel] [linuxsampler-devel] New note object should be created when play_note() is called
Andrew C
2017-05-27 19:53:42 UTC
Permalink
I was looking through other KSP scripts and one feature I noticed is that
you can use ignore_event($EVENT_ID), but still use play_note to generate
notes as needed (Currently if you use ignore_event and call play_note,
play_note has no Note object).

You can also access the $EVENT_NOTE and $EVENT_VELOCITY values too.

Could this be implemented into NKSP?
Christian Schoenebeck
2017-05-27 23:14:40 UTC
Permalink
Post by Andrew C
I was looking through other KSP scripts and one feature I noticed is that
you can use ignore_event($EVENT_ID), but still use play_note to generate
notes as needed (Currently if you use ignore_event and call play_note,
play_note has no Note object).
You can also access the $EVENT_NOTE and $EVENT_VELOCITY values too.
Could this be implemented into NKSP?
Hmm, I just tested this:

on note
declare $foo

ignore_event($EVENT_ID)
$foo := play_note($EVENT_NOTE)
message($foo)
end on

Note was played, and play_note() also returns a valid note ID.

CU
Christian
Andrew C
2017-05-29 06:28:19 UTC
Permalink
$foo := play_note($EVENT_NOTE)

Damn, I didn't see this in the NKSP docs and I didn't have the programming
chops to infer it. My bad. >.<

I was trying to ignore_event and then just call 'play_note' without making
it an object.

Thanks for clearing this up, Christian.

On Sun, May 28, 2017 at 12:14 AM, Christian Schoenebeck <
Post by Christian Schoenebeck
Post by Andrew C
I was looking through other KSP scripts and one feature I noticed is that
you can use ignore_event($EVENT_ID), but still use play_note to generate
notes as needed (Currently if you use ignore_event and call play_note,
play_note has no Note object).
You can also access the $EVENT_NOTE and $EVENT_VELOCITY values too.
Could this be implemented into NKSP?
on note
declare $foo
ignore_event($EVENT_ID)
$foo := play_note($EVENT_NOTE)
message($foo)
end on
Note was played, and play_note() also returns a valid note ID.
CU
Christian
------------------------------------------------------------
------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Linuxsampler-devel mailing list
https://lists.sourceforge.net/lists/listinfo/linuxsampler-devel
Andrew C
2017-05-29 06:35:50 UTC
Permalink
Actually, what am I doing wrong here?

on note
declare $foo

ignore_event($EVENT_ID)
$foo := play_note($EVENT_NOTE, $EVENT_VELOCITY, 0, -1)
message($foo)
end on

This produces:
[ScriptVM] -2147483648
gig::Engine: No Note object for triggering new voices!
Post by Christian Schoenebeck
$foo := play_note($EVENT_NOTE)
Damn, I didn't see this in the NKSP docs and I didn't have the programming
chops to infer it. My bad. >.<
I was trying to ignore_event and then just call 'play_note' without making
it an object.
Thanks for clearing this up, Christian.
On Sun, May 28, 2017 at 12:14 AM, Christian Schoenebeck <
Post by Christian Schoenebeck
Post by Andrew C
I was looking through other KSP scripts and one feature I noticed is
that
Post by Andrew C
you can use ignore_event($EVENT_ID), but still use play_note to generate
notes as needed (Currently if you use ignore_event and call play_note,
play_note has no Note object).
You can also access the $EVENT_NOTE and $EVENT_VELOCITY values too.
Could this be implemented into NKSP?
on note
declare $foo
ignore_event($EVENT_ID)
$foo := play_note($EVENT_NOTE)
message($foo)
end on
Note was played, and play_note() also returns a valid note ID.
CU
Christian
------------------------------------------------------------
------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Linuxsampler-devel mailing list
https://lists.sourceforge.net/lists/listinfo/linuxsampler-devel
Christian Schoenebeck
2017-05-29 10:30:57 UTC
Permalink
Post by Andrew C
Actually, what am I doing wrong here?
on note
declare $foo
ignore_event($EVENT_ID)
$foo := play_note($EVENT_NOTE, $EVENT_VELOCITY, 0, -1)
message($foo)
end on
The difference is the -1 argument passed by you:

http://doc.linuxsampler.org/Instrument_Scripts/NKSP_Language/Reference/play_note_function/

"-1: The note will be stopped when the event handler's note stops"

You already stopped the note, to which you wanted the new note to stick to. So
from my perspective the behavior you get is the logical consequence. Probably
the precise result value of play_note() should deliberately be zero in this
case instead, but except of that the behavior seems to be correct to me.

Did you see some KSP code which expects a different behavior here?

CU
Christian
Andrew C
2017-05-30 06:33:18 UTC
Permalink
I saw the following:
"

on note
disallow_group($ALL_GROUPS) { turn all groups off }
allow_group(0) { turn first group on }
ignore_event($EVENT_ID) { inhibit triggering note from being played }
play_note($EVENT_NOTE, $EVENT_VELOCITY, 0, -1) { replay note }
end note
"

It's just a fragment, but yes, it seems like play_note can still
trigger the note and follow the 'note_on/note_off' of the note handler
itself.


On Mon, May 29, 2017 at 11:30 AM, Christian Schoenebeck <
Post by Christian Schoenebeck
Post by Andrew C
Actually, what am I doing wrong here?
on note
declare $foo
ignore_event($EVENT_ID)
$foo := play_note($EVENT_NOTE, $EVENT_VELOCITY, 0, -1)
message($foo)
end on
http://doc.linuxsampler.org/Instrument_Scripts/NKSP_
Language/Reference/play_note_function/
"-1: The note will be stopped when the event handler's note stops"
You already stopped the note, to which you wanted the new note to stick to. So
from my perspective the behavior you get is the logical consequence. Probably
the precise result value of play_note() should deliberately be zero in this
case instead, but except of that the behavior seems to be correct to me.
Did you see some KSP code which expects a different behavior here?
CU
Christian
------------------------------------------------------------
------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Linuxsampler-devel mailing list
https://lists.sourceforge.net/lists/listinfo/linuxsampler-devel
Christian Schoenebeck
2017-05-30 13:16:02 UTC
Permalink
Post by Christian Schoenebeck
"
on note
disallow_group($ALL_GROUPS) { turn all groups off }
allow_group(0) { turn first group on }
ignore_event($EVENT_ID) { inhibit triggering note from being
played } play_note($EVENT_NOTE, $EVENT_VELOCITY, 0, -1) { replay
note } end note
"
It's just a fragment, but yes, it seems like play_note can still
trigger the note and follow the 'note_on/note_off' of the note handler
itself.
Ok, since you say it is just a fragment of the overall code, I can just guess
that this technique might he used as an alternative for calling change_*()
functions for the triggered note.

I do see use cases which were not possible with our implementation of
play_note(), so I just implemented the following behavior changes of the
play_note() function:

* If -1 was passed for the "duration" argument and the parent note is already
gone (i.e. because of a previous call to ignore_event()) then play_note()
silently returns 0 as result value.

* Additionally I added a new special value -2 for argument "duration", which
essentially enables what you demonstrated.

Here the updated docs:

http://doc.linuxsampler.org/Instrument_Scripts/NKSP_Language/Reference/play_note_function/

Now I don't know Kontakt's precise behavior on this one, so I am not
absolutely sure whether these changes are optimal. But let me describe the use
cases for the two special values -1 and -2 and hence the reason why I think we
need both:

* Use case for duration = -1 :
------------------------------

on note
play_note($EVENT_NOTE+12, $EVENT_VELOCITY, -1, -1)
end on

This triggers an additional note (transposed upwards by one octave) each time
you trigger a key on the keyboard. In this case the new note has a different
note number, however you still want the new (transposed) note to be released
when a note-off event arrives on $EVENT_NOTE, not on $EVENT_NOTE+12. So the
new note's life time is sticked to its causing parent note.

In a more complex script of this use case, you might additionally have some
logic code afterwards which might drop the original (parent) note on certain
conditions, then also the already scheduled new (transposed) note should be
dropped automatically as well, which our current behavior does. So this is a
very handy feature in this case.

* Use case for duration = -2 :
------------------------------

on controller
declare $someNoteNr := 60
declare $someNoteVelocity := 127
...
if ($CC_NUM = 1)
play_note($someNoteNr, $someNoteVelocity, -1, -2)
end if
end on

This triggers a new note (i.e. with note number 60) when the modulation wheel
is used (MIDI CC#1), and sticks the life time of the new note to MIDI note/key
number 60. So those new voice(s) shall play until a MIDI note-off arrives on
MIDI note number 60.

As said, I don't know what Kontakt does exactly. It could be that Kontakt's
duration=-1 case is what we now have as duration=-2, and that they don't have
our duration=-1 behavior at all. Or their behavior could also be mix of our
two -1 and -2 cases, such a mix behavior is not desirable IMO though. Maybe
somebody can check what Kontakt really does here.

CU
Christian

Continue reading on narkive:
Loading...