On Mittwoch, 7. April 2021 16:31:10 CEST you wrote: > Hi Christian/List, > > I've written and fully tested a working "neighbour notes" round robin > script with some rudimentary logic to avoid "dead" notes at either extreme > of the instrument. > The initial instrument range is for a cello, but can easily be edited for > any instrument range. > > I've uploaded it here (RRCello. LScript): > https://drive.google.com/file/d/18c6iL-zR-tDYNBFyqUS01HnZipwbvPuJ/view?usp=s > haring > > If nothing else, it might serve as a good "real world" example of NKSP in > Linuxsampler.
Just some notes/tips from my side: > on init > {Round robin script for Cello. Version 0.1} > {Written by Andrew Coughlan. Released under GPL v2 or later.} Maybe a more detailed description what the script does would make sense. E.g. "Assumes an instrument with one sample per key; it emulates round robin samples by randomly picking another sample (from another region) and pitching it up or down accordingly." > > declare polyphonic $n > declare polyphonic $RR > declare polyphonic $lokey := 36 {lowest playable note of this instrument} > declare polyphonic $hikey := 76 {highest playable note of this instrument} > > end on You could automate retrieval of $lokey and $hikey, at least for gig sounds: by calling same_region($i, $i) in a loop inside on init .. end on for all 127 possible MIDI note numbers can could check which region does have a sample mapped to a MIDI key: http://doc.linuxsampler.org/Instrument_Scripts/NKSP_Language/Reference/same_region_function/ And no need to make $lokey and $hikey polyphonic, as their values don't ever change during individual note events. > on note > {message ("Note played is number: " & $EVENT_NOTE)} > {uncomment for getting lokey/hikey instrument range numbers} > > ignore_event() > > if ( $EVENT_NOTE +2 > $hikey .and. $EVENT_NOTE <= $hikey ) ".and." is a bitwise and, which is quite special. In this case you would just use the regular logical-and without the dots ("and"). Not that it would make much of a difference in this case though. > > $n := random(0, 2) > > select $n > > case 0 > > $RR := play_note($EVENT_NOTE -2, $EVENT_VELOCITY) > change_tune($RR, 200c) > > case 1 > > $RR := play_note($EVENT_NOTE -1, $EVENT_VELOCITY) > change_tune($RR, 100c) > > case 2 > > $RR := play_note($EVENT_NOTE, $EVENT_VELOCITY) > > end select As $n is used nowhere else, you could also just inline the random() call like: select random(0, 2) ... end select If you want a true round robin behaviour, not a randomized one, then you would probably use a global variable instead and increment it with each note: on init { important: not polyphonic! } declare $rr end on function bumpRoundRobin synchronized $rr := $rr + 1 if ($rr > 2) $rr := -2 end if end synchronized end function on note call bumpRoundRobin() select $rr ... end select end on > > else > > if ( $EVENT_NOTE -2 < $lokey .and. $EVENT_NOTE >= $lokey ) > > $n := random(0, 2) > > select $n > > case 0 > > $RR := play_note($EVENT_NOTE +2, $EVENT_VELOCITY) > change_tune($RR, -200c) > > case 1 > > $RR := play_note($EVENT_NOTE +1, $EVENT_VELOCITY) > change_tune($RR, -100c) > > case 2 > > $RR := play_note($EVENT_NOTE, $EVENT_VELOCITY) > > end select > > else > > if ($EVENT_NOTE -1 > $lokey .and. $EVENT_NOTE +2 < $hikey) > > $n := random(0, 4) > > select $n > > case 0 > > $RR := play_note($EVENT_NOTE -2, $EVENT_VELOCITY) > change_tune($RR, 200c) > > case 1 > > $RR := play_note($EVENT_NOTE -1, $EVENT_VELOCITY) > change_tune($RR, 100c) > > case 2 > > $RR := play_note($EVENT_NOTE +2, $EVENT_VELOCITY) > change_tune($RR, -200c) > > case 3 > > $RR := play_note($EVENT_NOTE +1, $EVENT_VELOCITY) > change_tune($RR, -100c) > > case 4 > > $RR := play_note($EVENT_NOTE, $EVENT_VELOCITY) > > end select > end if > > end if > > end if > > > end on Alternatively you could also reduce the overall amount of code lines tremendously by dropping the select ... end select approach and using arithmetics instead: $n := random(-2, +2) $RR := play_note($EVENT_NOTE + $n, $EVENT_VELOCITY) if ($n) change_tune($RR, $n * -100c) end if CU Christian _______________________________________________ Linuxsampler-devel mailing list Linuxsampler-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linuxsampler-devel