User Submitted CoyoteScript

Volume Control

Author: Sander

Script Version: 1

Minimum CoyoteMIDI Build: 553

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.

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.
				
					// if the configured hotkey for ignoring the input trigger is pressed
if ($parameters IgnoreKey) && (keystate ($parameters IgnoreKey))
    return

// 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)

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

// change the volume of the target
setvolume $volume $target

// on Windows, update the mute state of the target, if necessary
// (on MacOS, polling the mute state this frequently is currently too CPU intense to be worth it)
if (platform) == Windows
    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

// define the parameters to be displayed in a translation.
event uirefreshed
    if (platform) == Windows
        translationparameter 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.''" "*")
        translationparameter ForegroundKey (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)
    translationparameter IgnoreKey (textbox "Ignore key" "The key to press down for when the script should do nothing while the MIDI input is triggered." SHIFT 0.3)
				
			

25 downloads