User Submitted CoyoteScript

Volume Control

Author: Sander

Script Version: 2

Minimum CoyoteMIDI Build: 771

Allows you to control the volume of your system directly from a MIDI control. On Windows, you can also target a specific process or the foreground process instead.

By default, the script will automatically use the value of the MIDI event that triggered the translation, so that the position of a CC fader or knob, or the velocity of a note, will translate to the volume. When triggering the translation from a control change event, it is best to set the condition of the CC input to ‘any’.

You can also select the ‘increment_volume’ script to add or subtract from your system’s volume by a set amount without using the MIDI input’s value.

It adds the following parameters to a translation:

Target (Windows): The process name to change the volume of, or “*” for the system volume, and “foreground” for the current foreground application.

Foreground Key (Windows): The key to hold down to override the target with the current foreground application.

Ignore Key: The key to hold down for this script to do nothing while the input MIDI is triggered.

Amount (increment_volume subscript only): The amount to increase or decrease the volume with.
				
					// default script, volume by MIDI value
script default
    // if the configured hotkey for ignoring the input trigger is pressed
    if ($parameters IgnoreKey) && (keystate ($parameters IgnoreKey))
        return
    // Get the target process from the parameters
    $target = (runscript default get_target parameters:$parameters)
    // Figure out if the max MIDI value for this event is 127 or 16383 (pitchbend)
    $max = 127
    if ($trigger midievent) == pitchbend
        $max = 16383
    // convert the 0-127 or 0-16383 scale from the MIDI event to a 0-100 scale for setvolume
    $volume = (round ($trigger rawvalue) / $max * 100)
    // set the volume
    runscript default set_volume volume:$volume,target:$target

// Increment_volume for increasing or decreasing the volume by a fixed amount
script increment_volume
    // if the configured hotkey for ignoring the input trigger is pressed
    if ($parameters IgnoreKey) && (keystate ($parameters IgnoreKey))
        return
    // Get the target process from the parameters
    $target = (runscript default get_target parameters:$parameters)
    // get the volume from the target process and add the increment to it
    $volume = (round (getvolume $target) + ($parameters Amount))
    // set the volume
    runscript default set_volume volume:$volume,target:$target

script set_volume hidden
    // change the volume of the target
    setvolume $volume $target
    // update the mute state of the target, if necessary
    if $volume < 3 && !(getmute $target)
        setmute true $target
    if $volume >= 3 && (getmute $target)
        setmute false $target 
    // indicate the volume level on the logo indicator across a range from green to red.
    indicator true (R: $volume * 5.11,G: 5.11 * (100 - $volume), B: 0) 1

script get_target private
    // if 'foreground' is specified as target, or the configured hotkey for the foreground is pressed
    if ($parameters Target) == foreground || (($parameters ForegroundKey) && (keystate ($parameters ForegroundKey)))
        return (getfocusedprocess)
    // if the translation parameters specify a target, use that instead
    else if ($parameters Target) && ($parameters Target) != "*"
        return ($parameters Target)

// define the parameters to be displayed in a translation.
event uirefreshed
    // define common controls
    $target = (textbox "Target" "The process to change the volume of. A blank value or '*' will target the system volume. 'foreground' will target the foreground application.''" "*")
    $foreground = (textbox "Foreground Key" "The key to press down when the script should modify the volume of the foreground app instead of the target." CTRL 0.3)
    $ignore = (textbox "Ignore key" "The key to press down for when the script should do nothing while the MIDI input is triggered." SHIFT 0.3)
    // default script parameters
    if (platform) == Windows
        translationparameter Target $target
        translationparameter ForegroundKey $foreground
    translationparameter IgnoreKey $ignore
    // increment_volume script parameters
    translationparameter Amount (numberbox "Volume Amount" "The amount to increase or decrease the volume with." 5 default false -100 100 5) increment_volume
    if (platform) == Windows
        translationparameter Target $target increment_volume
        translationparameter ForegroundKey $foreground increment_volume
    translationparameter IgnoreKey $ignore increment_volume
				
			

99 downloads