Adding and removing notes from the buffer

  • Hello!

    I'd like to trigger samples at multiple places and multiple times.

    So, first of all, I need to delay the start of samples by a beat.

    I can use this:
    Synth.addNoteOn(channel, noteNumber, velocity, timeStampSamples)

    and set timeStampSamples back by 1 beat.
    This delays the notes. Awesome!

    Now, if you let go of a key after the delayed sample has been started, it stops the note, but if you let go before that, you end up with a stuck note.

    So how do you remove notes from the buffer?
    One way I was thinking is to just change the note's velocity to 0 to change it's note to somewhere no samples are mapped.

    I see there's a function Message.setNoteNumber()

    This acts on Messages rather than events though, so perhaps there's a way to get event id from the addNoteOn into a message.
    I see there's something called a messageholder, and then you can store events in it.

    Using you can put the current event into a messageholder. addNoteOn isn't the current event, so that doesn't work.

    On a side note, I'll definitely want to be able to change the tune and pan of artificial notes in the future, and if you can only do setNoteNumber() to Messages (which are only generated by real events), does that mean you can only setNoteNumber() of real events?
    I think maybe I'm fuzzy on the difference between a Message and an event.

  • I was also adding note offs before, which didn't work for some reason.
    I probably just need to figure out why that wasn't working.

    In the Artificial Events section:
    "As soon as you call Synth.addNoteOffFromEventId() with a real event ID, it will invalidate the note on event (=delete them from the queue)"

    So yeah, that's probably the way to remove notes from the buffer 😛

  • You could also delay the incoming note off message to avoid stuck notes...

  • Ok, so delaying it in onNoteOff using engine uptime?

  • No just delay it by the same amount you've delayed the respective note on and its guaranteed to never get stuck - I have no idea about the context though so I'm not sure if this helps in your situation.

    On a side note, I'll definitely want to be able to change the tune and pan of artificial notes in the future,

    Use Synth.addPitchFade with zero fade time with the event ID you get as return value from Synth.addNoteOn()

  • Yep, that worked. The only thing is it plays the envelope's release.
    I could just get rid of that using a volume fade although I'm not sure that's the best way to do it.

  • @Christoph-Hart If you delay the note off in the onNoteOff using the same offset as when you added the note in the onNoteOn, it will put the note off after the note on.
    I'm trying to make it so that if you let go of the key before the note on, it doesn't play the delayed note on.

    Of course, just use a PitchFade! Thanks for the tip.

Log in to reply