What's new

Scripting sustain pedal noises problem

Hi, I've scripted samples to play when the sustain pedal is released, which works perfectly, but occasionally the samples play when sustain pedal is pressed, which is driving me potty!! Here is the pedal code I've used (some taken from Nils' script), any help much appreciated, thanks!


on note $l := search(%ids, 0) if ($l # -1) %ids[$l] := $EVENT_ID %notes[$l] := $EVENT_NOTE else ignore_event($EVENT_ID) { just a safety precaution in case the polyphony would reach 512 } end if end on on release disallow_group($ALL_GROUPS) if (%CC[64] >= 64) { ignore note-off when sustain pedal is pressed } ignore_event($EVENT_ID) else $l := 0 while ($l <= num_elements(%ids)-1) if (%ids[$l] # $NONE and %notes[$l] = $EVENT_NOTE) note_off(%ids[$l]) %ids[$l] := $NONE end if inc($l) end while end on on controller if (%CC_TOUCHED[64] # 0 and %CC[64] < 64 and ($ENGINE_UPTIME-$last_note_on_time <= 2000)) if ($pedalsqueeks = 1) {keyswitch to activate pedal noises} $randomsqueek := random(84,97) play_note($randomsqueek,100,0,0) end if end if if (%CC_TOUCHED[64] # 0 and %CC[64] < 64) $l := 0 while ($l <= num_elements(%ids)-1) if (%ids[$l] # $NONE and %KEY_DOWN[%notes[$l]] = 0) note_off(%ids[$l]) %ids[$l] := $NONE end if inc($l) end while end if end on
 
I found that writing my own release script this way has made things easier than when I tried to use Nils' script:

Code:
on init
  SET_CONDITION(NO_SYS_SCRIPT_RLS_TRIG)
  declare $i
  declare %key_id[128]
  message("")
end on

on note
  %key_id[$EVENT_NOTE] := $EVENT_ID
  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
  _reset_rls_trig_counter($EVENT_NOTE)
end on

on release
  disallow_group($ALL_GROUPS)
  if (%key_id[$EVENT_NOTE]=$EVENT_ID and (%CC[64]<64))
    $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

I could never get his script to work it just muted all release samples after sustain pedal was released. Sorry I can't help you more with your specific code I haven't ever even used "ignore_event" so I'm already lost haha.

Also I just realized that going to the three dots and selecting "code" formats the code with indents which is nicer. Not sure if vi-control made a change but it is easier to read.
 
Last edited:
I found that writing my own release script this way has made things easier than when I tried to use Nils' script:

Code:
on init
  SET_CONDITION(NO_SYS_SCRIPT_RLS_TRIG)
  declare $i
  declare %key_id[128]
  message("")
end on

on note
  %key_id[$EVENT_NOTE] := $EVENT_ID
  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
  _reset_rls_trig_counter($EVENT_NOTE)
end on

on release
  disallow_group($ALL_GROUPS)
  if (%key_id[$EVENT_NOTE]=$EVENT_ID and (%CC[64]<64))
    $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

I could never get his script to work it just muted all release samples after sustain pedal was released. Sorry I can't help you more with your specific code I haven't ever even used "ignore_event" so I'm already lost haha.

Also I just realized that going to the three dots and selecting "code" formats the code with indents which is nicer. Not sure if vi-control made a change but it is easier to read.
Thanks for that..don't think it will help as it doesn't address my on controller (sustain off triggering samples) code, but thanks anyway!
 
I've solved it...Logic Pro X was throwing in random MIDI CC numbers on the sustain pedal, I changed the on controller code to 'if CC[64] = 0'..thanks Mike! You're quite welcome.
 
if CC[64] = 0

A more correct (also according to MIDI specification) test would be if CC[64] < 64. That means "off", and above and equal 64 means "on".

You could also have a state variable then just change it on the very first occurence of CC #64 value changing from off to on and vice versa (regardless of the range of values received). Example:

Code:
on controller
    if CC_NUM = 64
        if CC[CC_NUM] < 64
            if sus_pedal = 1
                sus_pedal := 0
            end if
        else
            if sus_pedal = 0
                sus_pedal := 1
            end if
        end if
    end if
end on

Then you use sus_pedal elsewhere in your code instead of CC[64] etc.
 
A more correct (also according to MIDI specification) test would be if CC[64] < 64. That means "off", and above and equal 64 means "on".

You could also have a state variable then just change it on the very first occurence of CC #64 value changing from off to on and vice versa (regardless of the range of values received). Example:

Code:
on controller
    if CC_NUM = 64
        if CC[CC_NUM] < 64
            if sus_pedal = 1
                sus_pedal := 0
            end if
        else
            if sus_pedal = 0
                sus_pedal := 1
            end if
        end if
    end if
end on

Then you use sus_pedal elsewhere in your code instead of CC[64] etc.
Great thanks very much again ED!
 
There has been another problem...the play_note() in the 'on controller' code is triggered whenever I click/move the playhead over a related MIDI region in Logic Pro (when not playing or recording), which is obviously not wanted. Please could someone advise on how I can only have this play_note() command triggered during playback or recording?!
 
You could query if NI_TRANSPORT_RUNNING = 1. But then the pedal wouldn't work when you play an armed track with transport stopped.
 
You could query if NI_TRANSPORT_RUNNING = 1. But then the pedal wouldn't work when you play an armed track with transport stopped.
Thanks for the quick reply..that worked but yes the problem is the pedal not working when user is playing with transport stopped...I guess there's no way around that!
 
You could test if the pedal value actually changed and only trigger the note when it did? That means another variable (last_sus_pedal for example), which you change at the end of the CC 64 branch of on controller. Continuing the above example:

Code:
on controller
    if CC_NUM = 64
        if CC[CC_NUM] < 64
            if sus_pedal = 1
                sus_pedal := 0
            end if
        else
            if sus_pedal = 0
                sus_pedal := 1
            end if
        end if

        if sus_pedal # last_sus_pedal
            // do stuff here
        end if

        last_sus_pedal := sus_pedal
    end if
end on
 
You could test if the pedal value actually changed and only trigger the note when it did? That means another variable (last_sus_pedal for example), which you change at the end of the CC 64 branch of on controller. Continuing the above example:

Code:
on controller
    if CC_NUM = 64
        if CC[CC_NUM] < 64
            if sus_pedal = 1
                sus_pedal := 0
            end if
        else
            if sus_pedal = 0
                sus_pedal := 1
            end if
        end if

        if sus_pedal # last_sus_pedal
            // do stuff here
        end if

        last_sus_pedal := sus_pedal
    end if
end on
Brilliant, will try that thanks again!
 
Sorry to say it didn't quite work - still when I click/move the playhead in Logic it triggers the samples, but only when the sustain pedal MIDI data value is above 64, so I'm a bit lost. The on controller code I used is this:

on controller if ($CC_NUM = 64) if ($pedalsqueeks = 1) {user can switch on/off pedal squeaks} if (%CC[$CC_NUM] < 64) if ($sus_pedal = 1) $sus_pedal := 0 end if else if ($sus_pedal = 0) $sus_pedal := 1 end if end if if ($sus_pedal # $last_sus_pedal and %CC[64] < 64) $randomsqueek := random(84,97) play_note($randomsqueek,100,0,0) end if $last_sus_pedal := $sus_pedal end if end if end on
 
Is it possibly just Logic Chase Events resetting controllers when you move the playhead?
File > Project Settings > MIDI > Chase
 
Is it possibly just Logic Chase Events resetting controllers when you move the playhead?
File > Project Settings > MIDI > Chase
Yes that's it thanks, but as the 'control changes' tick box is on by default, I was hoping for a way to stop the triggering happening without asking the user to disable the chase box.
 
Top Bottom