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 event_status() doesn't work

Discussion in 'Scripting Workshop' started by Reid115, Dec 16, 2021.

  1. Reid115

    Reid115 NI Product Owner

    Messages:
    40
    I noticed in a project I'm working on that get_event_ids() is returning events that have already been killed with fade_out(..., ..., 1) -- so long as there is still time left on the duration passed to play_note(). I wrote this dummy code to figure some stuff out, but it's only confused me more.
    Code:
    on init
        declare $new_id
    end on
    
    on note
        message("")
        ignore_event($EVENT_ID)
        $new_id := play_note($EVENT_NOTE, $EVENT_VELOCITY, 0, 1000000) { change last param }
    end on
    
    on release
        fade_out($new_id, 1, 1)
        wait(10000)
        if (event_status($new_id) = $EVENT_STATUS_NOTE_QUEUE)
            message("active")
        end if
    end on
    
    Every time I press and release a key, it prints "active", even though it should have been killed by the fade-out. If I changed the last parameter of play_note() to -1, it still prints out "active". If I change the last parameter to 0, it will randomly print out "active" sometimes, and nothing (inactive) other times -- and the sample being played is much longer than the time I'm holding the key. Can anyone explain this behavior? What is the proper way to immediately kill an event such that it doesn't show up with get_event_ids()?
     
  2. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    So, when you ignore_event(), that event is ignored but it is NOT killed/removed/deleted from the event queue. You can see that in Expert->Engine tab, like so:

    upload_2021-12-16_13-1-24.png

    So, what you CAN do here is, if you want to respond only to your generated event, wrap your release callback with this condition:

    Code:
    if (get_event_par($EVENT_ID, $EVENT_PAR_SOURCE) # -1)
     
  3. Reid115

    Reid115 NI Product Owner

    Messages:
    40
    Ah, I see. I realized that active voices is like a subset of active events, and that fade_out(..., ..., 1) specifically kills voices, not events. I think an event is only truly dead when its RCB is completed, which is why the following code still prints "active":
    Code:
    on note
        message("")
        ignore_event($EVENT_ID)
        play_note($EVENT_NOTE, $EVENT_VELOCITY, 0, -1)
    end on
    
    on release
        if (get_event_par($EVENT_ID, $EVENT_PAR_SOURCE) # -1)
            fade_out($EVENT_ID, 1, 1)
            wait(1000000)
            if (event_status($EVENT_ID) = $EVENT_STATUS_NOTE_QUEUE)
                message("active")
            end if
        end if
    end on
    I guess if I really needed to know if an active event's *voice* was active, I could set a custom event parameter to 1 after play_note() and to 0 after any call to fade_out(..., ..., 1). Thanks for your help.