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

Including Release Triggers on Key Release (with Nils RT Script)

Discussion in 'Scripting Workshop' started by Duncan Krummel, Aug 12, 2021.

  1. Duncan Krummel

    Duncan Krummel New Member

    Messages:
    7
    Hi everyone,

    I've adapted Nils Liberg's script to fix release triggers on sustain pedal down in a piano library I'm working on (with some additional guidance from David Hilowitz's great tutorials on piano scripting), however I can't figure out how to re-allow release triggers on key release. The action should be:

    If sustain pedal = up: play release triggers on key release
    If sustain pedal = down: play release triggers on key release (and NOT on pedal release, which it does by default).

    This is my code so far:

    Code:
    on init
    
      load_performance_view("The Paper Piano Main Page.nckp")
      set_skin_offset(0)
    
      SET_CONDITION(NO_SYS_SCRIPT_RLS_TRIG)
      declare $i
      declare polyphonic $rls_on
      declare polyphonic $parent_id
    
      declare const $NUM_MICS := 3
    
      declare %release_trigger_groups[3 * $NUM_MICS] := (20,21,22,54,55,56,88,89,90)
      declare %sus_down_groups[4 * $NUM_MICS]  := (23,24,25,26,57,58,59,60,91,92,93,94)
      declare %una_down_groups[3 * $NUM_MICS]  := (27,28,29,61,62,63,95,96,97)
      declare %pedal_up_groups[4 * $NUM_MICS]  := (30,31,32,33,64,65,66,67,98,99,100,101)
    
      declare $sus_down := num_elements(%sus_down_groups) / $NUM_MICS
      declare $una_down := num_elements(%una_down_groups) / $NUM_MICS
    
      declare $counter
      declare %key_color[128]
    
      $counter:= 0
      while ($counter <= 127)
        %key_color[$counter] := $KEY_COLOR_INACTIVE
        set_key_color($counter, %key_color[$counter])
        inc($counter)
      end while
    
      $counter := 36
      while ($counter <= 47)
        %key_color[$counter] := $KEY_COLOR_RED
        set_key_color($counter, %key_color[$counter])
        inc($counter)
      end while
    
        $counter := 48
      while ($counter <= 84)
        %key_color[$counter] := $KEY_COLOR_DEFAULT
        set_key_color($counter, %key_color[$counter])
        inc($counter)
      end while
    
        $counter := 85
      while ($counter <= 96)
        %key_color[$counter] := $KEY_COLOR_RED
        set_key_color($counter, %key_color[$counter])
        inc($counter)
      end while
    
    end on
    
    on ui_control($main_mic)
      set_engine_par($ENGINE_PAR_VOLUME, $main_mic, -1, -1, $NI_BUS_OFFSET + 0)
      set_engine_par($ENGINE_PAR_VOLUME, $main_mic, -1, -1, $NI_BUS_OFFSET + 3)
      set_engine_par($ENGINE_PAR_VOLUME, $main_mic, -1, -1, $NI_BUS_OFFSET + 6)
    end on
    
    on ui_control($wide_mic)
      set_engine_par($ENGINE_PAR_VOLUME, $wide_mic, -1, -1, $NI_BUS_OFFSET + 1)
      set_engine_par($ENGINE_PAR_VOLUME, $wide_mic, -1, -1, $NI_BUS_OFFSET + 4)
      set_engine_par($ENGINE_PAR_VOLUME, $wide_mic, -1, -1, $NI_BUS_OFFSET + 7)
    end on
    
    on ui_control($room_mic)
      set_engine_par($ENGINE_PAR_VOLUME, $room_mic, -1, -1, $NI_BUS_OFFSET + 2)
      set_engine_par($ENGINE_PAR_VOLUME, $room_mic, -1, -1, $NI_BUS_OFFSET + 5)
      set_engine_par($ENGINE_PAR_VOLUME, $room_mic, -1, -1, $NI_BUS_OFFSET + 8)
    end on
    
    on ui_control ($main_mute)
      if ($main_mute = 1)
        $main_solo := 0
      end if
    
      if ($main_mute = 0)
        $wide_solo := 0
        $room_solo := 0
      end if
    end on
    
    on ui_control ($wide_mute)
      if ($wide_mute = 1)
        $wide_solo := 0
      end if
    
      if ($wide_mute = 0)
        $room_solo := 0
        $main_solo := 0
      end if
    end on
    
    on ui_control($room_mute)
      if ($room_mute = 1)
        $room_solo := 0
      end if
    
      if ($room_mute = 0)
        $main_solo := 0
        $wide_solo := 0
      end if
    end on
    
    on ui_control($main_solo)
      if ($main_solo = 1)
        $main_mute := 0
        $wide_solo := 0
        $wide_mute := 1
        $room_solo := 0
        $room_mute := 1
      end if
    
      if ($main_solo = 0)
        $wide_mute := 0
        $room_mute := 0
      end if
    end on
    
    on ui_control($wide_solo)
      if ($wide_solo = 1)
        $wide_mute := 0
        $main_solo := 0
        $main_mute := 1
        $room_solo := 0
        $room_mute := 1
      end if
    
      if ($wide_solo = 0)
        $main_mute := 0
        $room_mute := 0
      end if
    end on
    
    on ui_control($room_solo)
      if ($room_solo = 1)
        $room_mute := 0
        $wide_solo := 0
        $wide_mute := 1
        $main_solo := 0
        $main_mute := 1
    
      end if
    
      if ($room_solo = 0)
        $wide_mute := 0
        $main_mute := 0
      end if
    end on
    
    on controller
      if ($CC_NUM = 64)
        if (%CC[64] = 127)
          $sus_down := play_note (0, 64, 0, 0)
        end if
      end if
    
      if ($CC_NUM = 67)
        if (%CC[67] = 127)
          $una_down := play_note (1, 64, 0, 0)
        end if
      end if
    
      if ($CC_NUM = 64)
        if (%CC[64] = 0)
          $sus_down := play_note (2, 64, 0, 0)
        end if
      end if
    
      if ($CC_NUM = 67)
        if (%CC[67] = 0)
          $una_down := play_note (2, 64, 0, 0)
        end if
      end if
    end on
    
    on note
      if ($main_mute = 1)
        set_engine_par($ENGINE_PAR_VOLUME, 0, -1, -1, $NI_BUS_OFFSET + 0)
        set_engine_par($ENGINE_PAR_VOLUME, 0, -1, -1, $NI_BUS_OFFSET + 3)
        set_engine_par($ENGINE_PAR_VOLUME, 0, -1, -1, $NI_BUS_OFFSET + 6)
      else
        set_engine_par($ENGINE_PAR_VOLUME, $main_mic, -1, -1, $NI_BUS_OFFSET + 0)
        set_engine_par($ENGINE_PAR_VOLUME, $main_mic, -1, -1, $NI_BUS_OFFSET + 3)
        set_engine_par($ENGINE_PAR_VOLUME, $main_mic, -1, -1, $NI_BUS_OFFSET + 6)
      end if
      if ($wide_mute = 1)
        set_engine_par($ENGINE_PAR_VOLUME, 0, -1, -1, $NI_BUS_OFFSET + 1)
        set_engine_par($ENGINE_PAR_VOLUME, 0, -1, -1, $NI_BUS_OFFSET + 4)
        set_engine_par($ENGINE_PAR_VOLUME, 0, -1, -1, $NI_BUS_OFFSET + 7)
      else
        set_engine_par($ENGINE_PAR_VOLUME, $wide_mic, -1, -1, $NI_BUS_OFFSET + 1)
        set_engine_par($ENGINE_PAR_VOLUME, $wide_mic, -1, -1, $NI_BUS_OFFSET + 4)
        set_engine_par($ENGINE_PAR_VOLUME, $wide_mic, -1, -1, $NI_BUS_OFFSET + 7)
      end if
      if ($room_mute = 1)
        set_engine_par($ENGINE_PAR_VOLUME, 0, -1, -1, $NI_BUS_OFFSET + 2)
        set_engine_par($ENGINE_PAR_VOLUME, 0, -1, -1, $NI_BUS_OFFSET + 5)
        set_engine_par($ENGINE_PAR_VOLUME, 0, -1, -1, $NI_BUS_OFFSET + 8)
      else
        set_engine_par($ENGINE_PAR_VOLUME, $room_mic, -1, -1, $NI_BUS_OFFSET + 2)
        set_engine_par($ENGINE_PAR_VOLUME, $room_mic, -1, -1, $NI_BUS_OFFSET + 5)
        set_engine_par($ENGINE_PAR_VOLUME, $room_mic, -1, -1, $NI_BUS_OFFSET + 8)
      end if
      $parent_id := $EVENT_ID
      if (%CC[64] >= 64)
        $rls_on := 0
      else
        $rls_on := 1
      end if
    
      _reset_rls_trig_counter($EVENT_NOTE)
    
      disallow_group($ALL_GROUPS)
      $i := 0
      while ($i <= $NUM_GROUPS-1)
        if (_get_engine_par($ENGINE_PAR_RELEASE_TRIGGER, $i, -1, -1) = 0)
        allow_group($i)
      end if
      inc($i)
    end while
    end on
    
    on release
      if ($EVENT_ID = $parent_id and $rls_on = 1 and %CC[64] < 64)
        disallow_group($ALL_GROUPS)
        $i := 0
        while ($i <= $NUM_GROUPS-1)
          if (_get_engine_par($ENGINE_PAR_RELEASE_TRIGGER, $i, -1, -1) = 1)
            allow_group($i)
          end if
          inc($i)
        end while
        play_note($EVENT_NOTE, $EVENT_VELOCITY, 0, -1)
      end if
    end on
    
    Any ideas? Thanks!
     
  2. Duncan Krummel

    Duncan Krummel New Member

    Messages:
    7
    Bump (hope that's okay!)