From 07608fb98196d4497ca5f41ee43e3886e34d5fc6 Mon Sep 17 00:00:00 2001 From: phil294 Date: Thu, 20 Jul 2023 11:02:01 +0200 Subject: [PATCH] Add SoundSet only Master volume and ON/OFF / MUTE for now --- README.md | 8 ++++---- docs/index.html | 14 +++++++------- src/cmd/misc/sound-get.cr | 2 +- src/cmd/misc/sound-set.cr | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 46 insertions(+), 12 deletions(-) create mode 100644 src/cmd/misc/sound-set.cr diff --git a/README.md b/README.md index 772f04a..0a9c347 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ AHK_X11 can be used completely without a terminal. You can however if you want u
CLICK TO SEE WHICH COMMANDS ARE IMPLEMENTED AND WHICH ARE MISSING. Note however that this is not very representative. For example, no `Gui` sub command is included in the listing. For a better overview on what is already done, skim through the FULL DOCUMENTATION HERE. ```diff -DONE ?% (105/220): +DONE ?% (106/220): + Else, { ... }, Break, Continue, Return, Exit, GoSub, GoTo, IfEqual, Loop, SetEnv, Sleep, FileCopy, + SetTimer, WinActivate, MsgBox, Gui, SendRaw, #Persistent, ExitApp, + EnvAdd, EnvSub, EnvMult, EnvDiv, ControlSendRaw, IfWinExist/IfWinNotExist, SetWorkingDir, @@ -70,7 +70,7 @@ DONE ?% (105/220): + WinGetTitle, WinGetClass, PixelGetColor, CoordMode, GuiControl, ControlGetPos, ControlGetText, + WinGet, Input, Loop (parse a string), ToolTip, If var [not] in/contains MatchList, ControlSetText, + PixelSearch, #Include, InputBox, ClipWait, EnvSet, SetKeyDelay, SetMouseDelay, MouseClickDrag, -+ #NoTrayIcon, TrayTip, Random, Shutdown, RunAs, SoundGet ++ #NoTrayIcon, TrayTip, Random, Shutdown, RunAs, SoundGet, SoundSet NEW ?% (9/220): (not part of spec or from a more recent version) @@ Echo, ahk_x11_print_vars, FileRead, RegExGetPos, RegExReplace, EnvGet, Click @@ @@ -85,7 +85,7 @@ REMOVED ?% (11/220): # AutoTrim: It's always Off. It would not differentiate between %a_space% and %some_var%. # It's possible but needs significant work. -TO DO ?% (91/220): alphabetically +TO DO ?% (90/220): alphabetically - BlockInput, Control, ControlFocus, ControlGet, ControlGetFocus, - ControlMove, - DetectHiddenText, DetectHiddenWindows, Drive, DriveGet, DriveSpaceFree, @@ -100,7 +100,7 @@ TO DO ?% (91/220): alphabetically - Process, Progress, SetBatchLines, - SetCapslockState, SetControlDelay, SetDefaultMouseSpeed, SetFormat, - SetNumlockState, SetScrollLockState, SetStoreCapslockMode, SetTitleMatchMode, -- SetWinDelay, Sort, SoundGetWaveVolume, SoundPlay, SoundSet, +- SetWinDelay, Sort, SoundGetWaveVolume, SoundPlay, - SoundSetWaveVolume, SplashImage, SplashTextOn, SplashTextOff, SplitPath, StatusBarGetText, - StatusBarWait, StringCaseSense, StringSplit, StringTrimLeft, StringTrimRight, - SysGet, Thread, Transform, WinActivateBottom, diff --git a/docs/index.html b/docs/index.html index a3c09f9..40f747c 100644 --- a/docs/index.html +++ b/docs/index.html @@ -555,7 +555,7 @@

Table of contents

SoundPlay
  • - SoundSet + SoundSet
  • SoundSetWaveVolume @@ -2602,7 +2602,7 @@

    The "Last Found" Window

    Play a sound, video, or other supported file type. - SoundSet + SoundSet Changes various settings of a sound device (master mute, master volume, etc.) @@ -11398,7 +11398,7 @@

    Examples

    SoundPlay, %SystemRoot%\Media\ding.wav

    -
    +
    #

    SoundSet


    @@ -11418,20 +11418,20 @@

    Examples

    NewSetting

    Percentage number between -100 and 100 inclusive (it can be a floating point number). If the number begins with a plus or minus sign, the current setting will be adjusted up or down by the indicated amount. Otherwise, the setting will be set explicitly to the level indicated by NewSetting.

    -

    For ControlTypes with only two possible settings -- namely ONOFF, MUTE, MONO, LOUDNESS, STEREOENH, and BASSBOOST -- any positive number will turn on the setting and a zero will turn it off. However, if the number begins with a plus or minus sign, the setting will be toggled (set to the opposite of its current state).

    +

    For ControlTypes with only two possible settings -- namely ONOFF, MUTE, MONO, LOUDNESS, STEREOENH, and BASSBOOST -- any positive number will turn on the setting and a zero will turn it off. However, if the number begins with a plus or minus sign, the setting will be toggled (set to the opposite of its current state).

    ComponentType -

    If omitted or blank, it defaults to the word MASTER. Otherwise, it can be one of the following words: MASTER (synonymous with SPEAKERS), DIGITAL, LINE, MICROPHONE, SYNTH, CD, TELEPHONE, PCSPEAKER, WAVE, AUX, or ANALOG. If the sound device lacks the specified ComponentType, ErrorLevel will indicate the problem.

    +

    If omitted or blank, it defaults to the word MASTER. Otherwise, it can be one of the following words: MASTER (synonymous with SPEAKERS), DIGITAL, LINE, MICROPHONE, SYNTH, CD, TELEPHONE, PCSPEAKER, WAVE, AUX, or ANALOG. If the sound device lacks the specified ComponentType, ErrorLevel will indicate the problem.

    The component labeled Auxiliary in some mixers might be accessible as ANALOG rather than AUX.

    If a device has more than one instance of ComponentType (two of type LINE, for example) and you wish to use one other than the first, append a colon and a number to this parameter. For example: Analog:2 is the 2nd analog input.

    ControlType - If omitted or blank, it defaults to VOLUME. Otherwise, it can be one of the following words: VOLUME (or VOL), ONOFF, MUTE, MONO, LOUDNESS, STEREOENH, BASSBOOST, PAN, QSOUNDPAN, BASS, TREBLE, or EQUALIZER. If the specified ComponentType lacks the specified ControlType, ErrorLevel will indicate the problem. + If omitted or blank, it defaults to VOLUME. Otherwise, it can be one of the following words: VOLUME (or VOL), ONOFF, MUTE, MONO, LOUDNESS, STEREOENH, BASSBOOST, PAN, QSOUNDPAN, BASS, TREBLE, or EQUALIZER. If the specified ComponentType lacks the specified ControlType, ErrorLevel will indicate the problem. DeviceNumber @@ -11442,7 +11442,7 @@

    Examples

     

    ErrorLevel

    ErrorLevel is set to 0 if the command succeeded. Otherwise, it is set to one of the following phrases:

    - +
    diff --git a/src/cmd/misc/sound-get.cr b/src/cmd/misc/sound-get.cr index a796725..8922ae8 100644 --- a/src/cmd/misc/sound-get.cr +++ b/src/cmd/misc/sound-get.cr @@ -5,7 +5,7 @@ class Cmd::Misc::SoundGet < Cmd::Base def self.sets_error_level; true end def run(thread, args) out_var = args[0] - on_off = args[2] && ["onoff","mute"].includes?(args[2].downcase) + on_off = args[2]? && ["onoff","mute"].includes?(args[2].downcase) if on_off is_on = `amixer get Master | tail -2 | grep -c '\\[on\\]'`.strip != "0" if args[2].downcase == "mute" diff --git a/src/cmd/misc/sound-set.cr b/src/cmd/misc/sound-set.cr new file mode 100644 index 0000000..7442718 --- /dev/null +++ b/src/cmd/misc/sound-set.cr @@ -0,0 +1,34 @@ +# SoundSet, NewSetting [, ComponentType, ControlType, DeviceNumber] +class Cmd::Misc::SoundSet < Cmd::Base + def self.min_args; 1 end + def self.max_args; 4 end + def self.sets_error_level; true end + def run(thread, args) + value = args[0] + on_off = args[2]? && ["onoff","mute"].includes?(args[2].downcase) + if on_off + if value.starts_with?('+') || value.starts_with?('-') + `amixer sset Master toggle` + else + turn_on = value == "0" + if args[2].downcase == "mute" + turn_on = ! turn_on + end + if turn_on + `amixer sset Master mute` + else + `amixer sset Master unmute` + end + end + else + if value.starts_with?('+') || value.starts_with?('-') + sign = value[0] + rel = value[1..] + `amixer sset Master -- #{rel}%#{sign}` + else + `amixer sset Master -- #{value}%` + end + end + "0" + end +end \ No newline at end of file
    Invalid Control Type or Component Type