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

Creating a playback progress indicator with asynchronous waits

Discussion in 'Scripting Workshop' started by rossc, Dec 18, 2021.

  1. rossc

    rossc New Member

    Messages:
    9
    Hi all,

    I'm currently trying to develop an instrument that will feature multiple draggable waveforms (essentially just fancy sliders) that will allow you to adjust the timings between each sample. I'm currently doing this with wait statements inside the on_note callback. I'm also trying to incorporate a playhead to indicate the playback position along the timeline. (See example image attached)

    I have each working independently, but when I attempt to use them together, I lose the delay on the sample start. Can I not run 2 wait statements in parallel, presumably? Any ideas on how I can get this to work? (See code below)

    Thanks guys! :)
    Code:
    on init
    
        message("")
    
        load_performance_view("perfview.nckp")
    
        declare $layer1WaitTime := 0
        declare $counter := 1
    
    end on
    
    function startProgressAnim()
    
        $counter := 1
    
        while ($counter <= 200)
    
            $progressSlider := $counter
            inc($counter)
            wait(100000)
    
        end while
    
    end function
    
    on note
    
        call startProgressAnim()
    
        ignore_event($EVENT_ID)
    
        disallow_group($ALL_GROUPS)
    
        allow_group(0)
        wait($layer1WaitTime)
        play_note($EVENT_NOTE, $EVENT_VELOCITY, 0, -1)
        disallow_group($ALL_GROUPS)
    
    end on
    
    on ui_control($slider)
    
        $layer1WaitTime := $slider
        message("Layer 1 Delay = " & $layer1WaitTime)
    
    end on
    kontaktScreenshot.png