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

Solved playing a second note later in on note with wait

Discussion in 'Scripting Workshop' started by mindblower23!, Sep 8, 2021.

  1. mindblower23!

    mindblower23! NI Product Owner

    Messages:
    40
    Hi!

    I'd like to call two play_note functions where the second note is played a little later. I've tried to use wait() between the calls but the second note is not played at all when I release the key on the keyboard before the wait cycle has finished. I'd like to play the second note regardless of the duration of the key being held down ... possible?

    Code:
    on note
    
        ignore_event( $EVENT_ID )
        play_note(12, $EVENT_VELOCITY, 0, 1000000)
    
        wait(500000)
        play_note( $EVENT_NOTE, $EVENT_VELOCITY, 0, -1 )
    
    end on
     
  2. soyfabi

    soyfabi NI Product Owner

    Messages:
    26
    just change the code to:
    Code:
    on note
    
        ignore_event( $EVENT_ID )
        play_note(12, $EVENT_VELOCITY, 0, 1000000)
    
        wait(500000)
        play_note( $EVENT_NOTE, $EVENT_VELOCITY, 0, 0 )  {-1 changed to 0. -1 means, that releasing the key stops the sample}
    
    end on
    cheers
    fabi
     
  3. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    If the sample is looped that would play the second note forever.
     
  4. mindblower23!

    mindblower23! NI Product Owner

    Messages:
    40
    What would be the right design pattern if the note is looped?
     
  5. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    I guess doing the same wait in release callback then note_off() on that second play_note()?
     
    • Like Like x 1
  6. soyfabi

    soyfabi NI Product Owner

    Messages:
    26
    ah yeah right forgot to mention that, thanks.

    For example change 0 to desired length, or something like my_id := play_note(...) and then wait and note_off(my_id) in release callback..
     
    • Like Like x 1
  7. mindblower23!

    mindblower23! NI Product Owner

    Messages:
    40
    Thank you soyfabi and ED for pushing me in the right direction!! :)
     
    • Like Like x 1