// idea from DimensionalTips.pdf: transpose and repitch complementarily to
// preserve tuning but change the samples used so as to alter the tone

// for each sample, check how many notes above itself have 0 layers and set HIKEY=note+count
// Or check in both directions, set LOKEY=note-(downcount/2) HIKEY=note+(upcount/2) or such
// OR
// for each snote[n],
//   HIKEY[n]=$((snote[n]+7<snote[n+1]?snote[n]+7:snote[n+1]-1))
//   LOKEY[n]=$((HIKEY[n-1]+1)) # heh :p
// #  LOKEY=$((snote[n]-5>snote[n-1]+7?snote[n]-5:snote[n-1]+8)) #???...

<group> // sustain resonance (SF) [CC75 == "Sound Control 6"]
//locc75=1 hicc75=127 locc64=127 hicc64=127 // 1. "resource-saver": don't trigger if silent, or if pedal is up
//xfin_locc64=0 xfin_hicc64=127 // 2. "pedal-fade": always trigger to make sustain always available for pedal-downs
//off_by=1001 // for resource-saver and pedal-fade only
// 3. "cut-only" : triggered and audible, only silenced when special pedalup+keyup regions at bottom trigger
xfin_locc75=0 xfin_hicc75=127 xfcccurve=gain loop_mode=one_shot off_mode=normal ampeg_release=0.1
<region> sample=$SAMPLE pitch_keycenter=$KEY lokey=$LOKEY hikey=$HIKEY off_by=$KEY // cut-only

<group> // release resonance (RF) [CC76 == "Sound Control 7"]
locc76=1 hicc76=127 locc64=0 hicc64=0 // don't trigger if silent, or pedal is down
//xfout_locc64=0 xfout_hicc64=127 // always trigger to make release always available for pedal-ups
xfin_locc76=0 xfin_hicc76=127 xfcccurve=gain trigger=release off_by=1000
<region> sample=$SAMPLE pitch_keycenter=$KEY lokey=$LOKEY hikey=$HIKEY

<group> // action release noise (HN) [CC77 == "Sound Control 8"]
locc77=1 hicc77=127 // don't trigger if silent
xfin_locc77=0 xfin_hicc77=127 trigger=release pitch_keytrack=0
<region> sample=$SAMPLE pitch_keycenter=$KEY lokey=$LOKEY hikey=$HIKEY

<group> // pedal noise [CC78 == "Sound Control 9"]
locc78=1 hicc78=127 // don't trigger if silent
xfin_locc78=0 xfin_hicc78=127 ampeg_release=0.05
hikey=-1 // "must be done" for midi-cc triggering according to http://www.drealm.info/sfz/plj-sfz.xhtml
<region> sample=Boes-Pedal Down.wav on_locc64=127 on_hicc64=127 group=1000 off_by=1001 // pedal down
<region> sample=Boes-Pedal Up.wav on_locc64=0 on_hicc64=0 group=1001 off_by=1000 // pedal up

<group> // "open lid?" MF notes [CC74 == "Sound Brightness"]
locc74=1 hicc74=127 // don't trigger if silent
xfin_locc74=0 xfin_hicc74=127 xfcccurve=gain ampeg_release=0.1
<region> sample=$SAMPLE pitch_keycenter=$KEY lokey=$LOKEY hikey=$HIKEY lovel=$LOVEL hivel=$HIVEL
//[for note in $(ls *MF* | sed -e 's/.*R(\([^)]*\)).*/\1/' | sort -k 1.2 -g | uniq);do printf "$note: $(ls *$note*MF* | wc -l)\n";done]

<group> // "closed lid?" ML notes [CC74 == "Sound Brightness"]
locc74=0 hicc74=126 // don't trigger if silent
xfout_locc74=0 xfout_hicc74=127 xfcccurve=gain
<region> sample=$SAMPLE pitch_keycenter=$KEY lokey=$LOKEY hikey=$HIKEY lovel=$LOVEL hivel=$HIVEL
//[ls *ML* | sed -e 's/.*R(\([^)]*\)).*/\1/' | sort -k 1.2 -g | uniq]

// cut-only: regions to trigger sustain-cuts
<group> trigger=release locc64=0 hicc64=0 // key release while pedal is up
<region> key=$KEY group=$KEY
<group> hikey=-1 on_locc64=0 on_hicc64=0 // pedal release while key is up
<region> sw_lokey=$KEY sw_hikey=$KEY sw_up=$KEY group=$KEY