Skip to content

Commit

Permalink
Add SoundSet
Browse files Browse the repository at this point in the history
only Master volume and ON/OFF / MUTE for now
  • Loading branch information
phil294 committed Jul 20, 2023
1 parent f15f3c7 commit 07608fb
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 12 deletions.
8 changes: 4 additions & 4 deletions README.md
Expand Up @@ -55,7 +55,7 @@ AHK_X11 can be used completely without a terminal. You can however if you want u
<details><summary><strong>CLICK TO SEE WHICH COMMANDS ARE IMPLEMENTED AND WHICH ARE MISSING</strong>. 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 <a href="https://phil294.github.io/AHK_X11"><b>FULL DOCUMENTATION HERE</b></a>.</summary>

```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,
Expand All @@ -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 @@
Expand All @@ -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,
Expand All @@ -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,
Expand Down
14 changes: 7 additions & 7 deletions docs/index.html
Expand Up @@ -555,7 +555,7 @@ <h2>Table of contents </h2>
<a class="tbd" href="#SoundPlay.htm">SoundPlay</a>
</li>
<li>
<a class="tbd" href="#SoundSet.htm">SoundSet</a>
<a href="#SoundSet.htm">SoundSet</a>
</li>
<li>
<a class="tbd" href="#SoundSetWaveVolume.htm">SoundSetWaveVolume</a>
Expand Down Expand Up @@ -2602,7 +2602,7 @@ <h2 class="calibre9"><span class="calibre23">The "Last Found" Window </span></h2
<td height="16" class="calibre4">Play a sound, video, or other supported file type. </td>
</tr>
<tr class="calibre3">
<td height="16" class="tbd calibre4"><a href="#SoundSet.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">SoundSet</a></td>
<td height="16" class="calibre4"><a href="#SoundSet.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">SoundSet</a></td>
<td height="16" class="calibre4">Changes various settings of a sound device (master mute, master volume, etc.)</td>
</tr>
<tr class="calibre3">
Expand Down Expand Up @@ -11398,7 +11398,7 @@ <h2 id="Examples">Examples</h2>
<p class="calibre8"> SoundPlay, %SystemRoot%\Media\ding.wav</p>
</div>
</div>
<div class="calibreMain tbd">
<div class="calibreMain">
<div class="calibreEbookContent">
<a id="SoundSet.htm" href="#SoundSet.htm">#</a> <h2 class="calibre17">SoundSet</h2>
<hr size="2" class="calibre24" />
Expand All @@ -11418,20 +11418,20 @@ <h2 id="Examples">Examples</h2>
<td width="15%" class="calibre4">NewSetting</td>
<td width="85%" class="calibre4">
<p class="calibre8">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 <strong class="calibre14">current setting </strong> will be adjusted up or down by the indicated amount. Otherwise, the setting will be set explicitly to the level indicated by <em class="calibre21">NewSetting</em>.</p>
<p class="calibre8">For <em class="calibre21">ControlTypes</em> 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. <strong class="calibre14">However</strong>, if the number begins with a plus or minus sign, the setting will be toggled (set to the opposite of its current state).</p>
<p class="calibre8">For <em class="calibre21">ControlTypes</em> with only two possible settings -- namely ONOFF, MUTE, <span class="tbd">MONO, LOUDNESS, STEREOENH, and BASSBOOST</span> -- any positive number will turn on the setting and a zero will turn it off. <strong class="calibre14">However</strong>, if the number begins with a plus or minus sign, the setting will be toggled (set to the opposite of its current state).</p>
</td>
</tr>
<tr class="calibre3">
<td class="calibre4">ComponentType</td>
<td class="calibre4">
<p class="calibre8">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 <em class="calibre21">ComponentType</em>, ErrorLevel will indicate the problem.</p>
<p class="calibre8">If omitted or blank, it defaults to the word MASTER. Otherwise, it can be one of the following words: MASTER (synonymous with SPEAKERS), <span class="tbd">DIGITAL, LINE, MICROPHONE, SYNTH, CD, TELEPHONE, PCSPEAKER, WAVE, AUX, or ANALOG</span>. If the sound device lacks the specified <em class="calibre21">ComponentType</em>, ErrorLevel will indicate the problem.</p>
<p class="calibre8">The component labeled Auxiliary in some mixers might be accessible as ANALOG rather than AUX.</p>
<p class="calibre8">If a device has more than one instance of <em class="calibre21">ComponentType</em> (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.</p>
</td>
</tr>
<tr class="calibre3">
<td class="calibre4">ControlType</td>
<td class="calibre4">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 <em class="calibre21">ComponentType</em> lacks the specified <em class="calibre21">ControlType</em>, ErrorLevel will indicate the problem. </td>
<td class="calibre4">If omitted or blank, it defaults to VOLUME. Otherwise, it can be one of the following words: VOLUME (or VOL), ONOFF, MUTE, <span class="tbd">MONO, LOUDNESS, STEREOENH, BASSBOOST, PAN, QSOUNDPAN, BASS, TREBLE, or EQUALIZER</span>. If the specified <em class="calibre21">ComponentType</em> lacks the specified <em class="calibre21">ControlType</em>, ErrorLevel will indicate the problem. </td>
</tr>
<tr class="calibre3">
<td class="calibre4">DeviceNumber</td>
Expand All @@ -11442,7 +11442,7 @@ <h2 id="Examples">Examples</h2>
<p class="calibre8"> </p>
<p class="calibre8"><strong class="calibre14">ErrorLevel</strong></p>
<p class="calibre8"><a href="#ErrorLevel.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">ErrorLevel</a> is set to 0 if the command succeeded. Otherwise, it is set to one of the following phrases:</p>
<table border="1" class="calibre1">
<table border="1" class="calibre1 tbd">
<tbody class="calibre2">
<tr class="calibre3">
<td class="calibre4">Invalid Control Type or Component Type</td>
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/misc/sound-get.cr
Expand Up @@ -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"
Expand Down
34 changes: 34 additions & 0 deletions 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

0 comments on commit 07608fb

Please sign in to comment.