How to get event ids for artificial events?



  • Hi,

    I have quick question: this might be obvious, but I'm wondering, in the onNoteOff callback, how do you get event ids for artificial events? Message.getEventId() just returns real note off event ids.



  • You should be able to record the ID when you generate the event.



  • Do you have any suggestions for how to record the ID's polyphonically? Here is what I was thinking:

    function onNoteOn()
    {   
        Message.ignoreEvent(true);
        eventId = Message.getEventId();
        eventIds[eventId] = Synth.playNote(Message.getNoteNumber(), 64);    
        eventNoteNumber[eventId] = Message.getNoteNumber();
    }
    
    function onNoteOff()
    {
        // if sustain pedal is up then...
        for (i = 0; i < eventIds.length-1; i++) {
            if (Message.getNoteNumber() == eventNoteNumber[i])
                Synth.noteOffByEventId(i);
        };
    }
    

    It takes a lot of iterating, so it seems a bit inefficient. Maybe there's a simpler way that I'm not thinking of.



  • Ok, I'm just realizing, you could iterate backwards through event ids, checking to see if the note event id's key is still pressed, and then you wouldn't be needlessly iterating through every previous event ids.
    Yay, totally efficient cpu-wise!
    Quite a headache to look at though... I'm still wondering if might be over-thinking this though.

    function onNoteOn()
    {   
        Message.ignoreEvent(true);
        keyDown.setValue(Message.getNoteNumber(), 1);
        eventId = Message.getEventId();
        eventIds[eventId] = Synth.playNote(Message.getNoteNumber(), 64);    
        eventNoteNumber[eventId] = Message.getNoteNumber();
    }
    
    function onNoteOff()
    {
        
        keyDown.setValue(Message.getNoteNumber(), 0); // note: keyDown is a MidiList
        i = eventId;
        while (keyDown.getValue(eventNoteNumber[i]) == 1) {
            i--;
            Synth.noteOffByEventId(i);
        };
    }
    


  • Use a MIDI list for storing polyphonic data



  • Would a MidiList work for when you have the pedal down, and have multiple voices happening on the same key?



  • @benosterhouse A MIDI list is just an array that is dedicated to tracking 128 integer values (designed for polyphonic MIDI data).



  • What I'm thinking is: say on a piano library you put the pedal down and played several repeated notes. When you lift the pedal, you'd want to noteoff all the repeated notes, not just the most recent one. How do you keep track of all those previous repeated notes?



  • @benosterhouse Why not just use Engine.allNotesOff();?



  • When you lift the pedal, you don't want to note off notes that you're still playing.



  • @benosterhouse Good point, so why script it at all since this is the default behaviour?



  • A couple reasons, but one of them would be so I can keep track of the play position of notes in the onTimer callback.
    The next question would be why I'm wanting to keep track of the play position of every event.



  • @benosterhouse

    The next question would be why I'm wanting to keep track of the play position of every event.

    Go on 🙂

    On a piano wouldn't a repeated note cancel out the previous note, since it's striking the same string?



  • Basically, I'm seeing if I can port a library to vst using hise.
    It has string swells in it, which are tempo synced. I see that hise doesn't really have timestretching yet, but I was realizing there's another way around it:
    If you play the beginning of the swell, then crossfade into the middle of the swell, you can adjust the length of the swell, so it'd fit into any project tempo (the phasing isn't too bad. I have some ideas to get around that).

    If you're fading together different parts of the swell, the tail end of it needs to be started with an artificial event.
    If you have multiple stiched-together swells (which use artificial events), and they're happening on the same key at the same time, you need a way to note-off all the artificial events when you lift the pedal.



  • @benosterhouse I get it, I'll play around with it a little tomorrow and see if I can come up with a way of managing the sustain/note off thing manually.



  • Ok cool!
    On a sampled piano, if you play a repeated note with the pedal down you want to keep the previous sample going.



  • Ok, that way I was trying to iterate through things before was too complicated and didn't actually work.

    I just added another dimension to the array so I could record more than one event id per key!
    Waaay simpler.



  • How many events do you want to record per key? I'm still thinking that with acoustic instruments in general each repeated note will kill old notes, causing them to decay.



  • That's not completely true. For example if you press down the sustain pedal, play a loud note on the piano, then play a soft note on the same key shortly after it, you would hear that the new note is fading down the old note which sounds really bad.

    That's why in the sampler options you have the "Kill second note" retrigger behaviour which allows you to have at least two notes of the same key ringing at once. This weakens that effect a little bit, but it's still noticeable.



  • @Christoph-Hart Very good point!

    1505a50a-4d81-4d14-9e10-b24425d75489-image.png


Log in to reply
 

18
Online

1.2k
Users

3.9k
Topics

34.4k
Posts