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 sample start on zone level

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

  1. mindblower23!

    mindblower23! NI Product Owner

    Messages:
    40
    Hi!

    What is the correct way to implement a unique sample start per zone?

    I've tried the modulator approach where the sample start is set in the on note callback via setting the
    $ENGINE_PAR_MOD_TARGET_INTENSITY of a constant modulator set to the sample start of a group.

    Like this
    Code:
    on init
      load_performance_view( "perfview" )
      declare %sample_start[100] {store the sample start of individual samples / set via slider}
      declare $last_note := -1
    end on
    
    on note
      set_engine_par( $ENGINE_PAR_MOD_TARGET_INTENSITY, %sample_start[$EVENT_NOTE], 1, find_mod( 1, "MOD SAMPLE START" ), -1 )
      $last_note = $EVENT_NOTE
      set_control_par( get_ui_id( $slider), $CONTROL_PAR_VALUE, %sample_start[$last_note] ) }
    end note
    
    on ui_control($slider)
      if($last_note > -1)
        %sample_start[$last_note] := $slider
      end if
    end on
    
    Which works fine until two or more keys are pressed simultaneously. Than there seems to be some kind of timing problem as the sample start applies to the samples randomly (or maybe to the zone which fires first or last)

    Isn't there a way to set the sample start directly on zone level? Or what's the correct way to approach this?

    Many thanks in advance!
     
    Last edited: Sep 1, 2021
  2. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    The third parameter of play_note() is the startpoint offset in microseconds. You could use that (provided your groups are in sampler mode).
     
  3. mindblower23!

    mindblower23! NI Product Owner

    Messages:
    40
    Thanks!

    I'm on it! How do i get rid of the doubled on release call?
     
  4. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    ignore_event($EVENT_ID) first.
     
  5. mindblower23!

    mindblower23! NI Product Owner

    Messages:
    40
    Ok, did that but on release is getting called twice anyway.
     
  6. mindblower23!

    mindblower23! NI Product Owner

    Messages:
    40
    Code:
    on note
        
        ignore_event( $EVENT_ID )
        play_note( $EVENT_NOTE, $EVENT_VELOCITY, %sample_start[$EVENT_NOTE], -1 )
    
        $last_note := $EVENT_NOTE
        set_control_par( get_ui_id( $p_high_slider_sample_start ), $CONTROL_PAR_VALUE, %sample_start[$last_note] )
    end on
    
    on release
        message("release got called" & $EVENT_ID)
    end on
    on release fires two times with different event ids ...
     
  7. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    Yes, release from original (ignored) event and the play_note() event. If you only care about the original key release, you can make the release callback to only respond to events coming from "outside":

    Code:
    on release
        if (get_event_par($EVENT_ID, $EVENT_PAR_SOURCE) = -1)
     ....
        end if
    end on
     
    • Like Like x 2
  8. mindblower23!

    mindblower23! NI Product Owner

    Messages:
    40
    Wow! Thank you so much!!! You're the man! I would never have figured this out on my own ...