User Submitted CoyoteScript

Run Generator

Author: Sander

Script Version: 2

Minimum CoyoteMIDI Build: 557

Generates a musical run every time a note is pressed, starting at the note that was pressed.
Running the script from a translation will toggle the run generator on or off. While it is on, it will continuously generate runs for every note pressed.
The scale, key, and interval can be configured with parameters in the translation that toggles the script.
When the sustain pedal is pressed down, the run will move downwards across the scale.

Parameters:

Scale: The musical scale that the run will follow, where each step in the scale is a number ranging from 0 to 12, separated by commas.

Key: The key in which the run will be performed, ranging from 0 to 12, 0 is C and 12 is B.

Interval: The interval of each note in the run. For example: 4 for quarter notes.
				
					// default entrypoint for script. sets the parameters and toggles the enabled state of the generator
%run_generator_enabled = !%run_generator_enabled
if %run_generator_enabled
    // The scale of the run, where 0 is C and 12 is B
    %run_generator_scale = (split (replace ($parameters Scale) " ") ",")
    // The key of the run, where 0 is C and 12 is B
    %run_generator_key = ($parameters Key)
    // The direction of the run, 1 is upwards and -1 downwards. Sustain will still act the same.
    %run_generator_direction = 1
    // The speed of the run
    %run_generator_speed = 1 / ($parameters Interval)

// Performs a run at a given note $start for as long as the note is held down and the run generator is enabled
script perform_run private
    // find at which point in the scale the start note is 
    $startpos = (find %run_generator_scale (mod ($start - %run_generator_key) 12)) - 1
    $keyoffset = 0
    // If the note at the given key is not in the scale, simply perform the scale starting at the beginning, in the key of the played note
    if $startpos == -1
        $startpos = 0
        $keyoffset = (mod ($start - %run_generator_key) 12)
    // If the start note is below the key root note in the same octave, make sure it doesn't start playing at the higher octave
    if %run_generator_key > (mod $start 12)
        $keyoffset - 12
    $steps = (count %run_generator_scale)
    $i = 0
    while (heldnotes false) contains $start && %run_generator_enabled
        // Determine which note has to be played based on the loop count, the scale, the octave, and the key.
        $note = $start + (%run_generator_scale ((mod ($i + $startpos) $steps) + 1)) - (mod $start 12) + ((floor ($i + $startpos) / $steps) * 12) + $keyoffset + %run_generator_key
        // play the note, rest, and release the note
        midi note $note (max 1 ($velocity + (random -25 25))) true
        rest %run_generator_speed
        midi note $note 0 true
        // Colour the indicator to show that the generator is enabled
        indicator true R:200,G:200,B:100 1 200
        // increment the loop counter in the appropriate direction
        $i + %run_generator_direction
    
event startup
    %run_generator_enabled = false

// If the run generator is enabled, cancel any notes and generate a run for them instead
event midi note
    if ($trigger velocity) != 0 && %run_generator_enabled
        runscript default perform_run start:($trigger note),velocity:($trigger velocity) false
        return true

// Switch the direction of the run (ascending or descending) based on the sustain pedal
event midi controlchange 64
    if %run_generator_enabled
        // the direction is now -1 for cc value 127 and 1 for <127
        %run_generator_direction = ((floor ($trigger controlvalue) * 2 / 127) - 1) * -1
        return true

event uirefreshed
    translationparameter Scale (textbox Scale "The scale of the run, where 0 is C and 12 is B." "0,2,3,5,7,8,10" 0.7)
    translationparameter Key (numberbox Key "The key of the run, where 0 is C and 12 is B" 2 default false 0 12 1)
    translationparameter Interval (numberbox Interval "The interval of each note being ran. For example: 4 for quarter notes." 32 default false 0 128 4)
				
			

12 downloads