本帖最后由 molly_kang 于 18-7-8 21:38 编辑
累死了,对于我这个新手做乐器到处都不知道咋搞,就是修一个release的bug自己还参考了好多程序,最终我自己搞出了一个还可以用的。
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
里面是使用双数组法,一个存音的id,一个存id对应音符对应的音符。重构了音的行为,让音只能在踏板外才可以使用。但原版的程序对于多个音叠加就会出现release采样的叠加出现音爆。我自己加了一个函数先让它除了release去延音,但里面自动抵消它的release的个数,每次新的音过来后就把新的音其他重复的音全部清空(但没有release采样播放),其他行为和原版的那个代码一样。
on init
declare const $NONE := 0
declare $i
declare %ids[512] { active event IDs in no particular order, NONE for unused elements }
declare %notes[512] { note number for each of the above events }
{ turn off Kontakt's builtin sustain pedal script }
SET_CONDITION(NO_SYS_SCRIPT_PEDAL)
end on
on note
if (%CC[64] >= 64)
{ clean up all release event except itself }
$i := 0
while ($i < num_elements(%ids))
if (%ids[$i] # $NONE and %notes[$i] = $EVENT_NOTE)
note_off(%ids[$i])
%ids[$i] := $NONE
end if
inc($i)
end while
{ disallow all groups, only allow non-release sample trigger }
disallow_group($ALL_GROUPS)
$i := 0
while ($i < $NUM_GROUPS)
if (_get_engine_par($ENGINE_PAR_RELEASE_TRIGGER, $i, -1, -1) = 0)
allow_group($i)
end if
inc($i)
end while
end if
{ add this note event to the first empty array slot }
$i := search(%ids, 0)
if ($i # -1)
%ids[$i] := $EVENT_ID
%notes[$i] := $EVENT_NOTE
else
ignore_event($EVENT_ID) { just a safety precaution in case the polyphony would reach 512 }
end if
end on
on release
note_off ($EVENT_ID)
if (%CC[64] >= 64)
{ ignore note-off when sustain pedal is pressed }
ignore_event($EVENT_ID)
else
$i := 0
while ($i < num_elements(%ids))
if (%ids[$i] # $NONE and %notes[$i] = $EVENT_NOTE)
note_off(%ids[$i])
%ids[$i] := $NONE
end if
inc($i)
end while
end if
end on
on controller
{ if sustain pedal released }
if (%CC_TOUCHED[64] # 0 and %CC[64] < 64)
{ release all events for which the key is no longer held pressed }
$i := 0
while ($i < num_elements(%ids))
if (%ids[$i] # $NONE and %KEY_DOWN[%notes[$i]] = 0)
note_off(%ids[$i])
%ids[$i] := $NONE
end if
inc($i)
end while
end if
end on