Skip to content

Commit

Permalink
Add SoundGet
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 9946a51 commit f15f3c7
Show file tree
Hide file tree
Showing 3 changed files with 33 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 ?% (104/220):
DONE ?% (105/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 ?% (104/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
+ #NoTrayIcon, TrayTip, Random, Shutdown, RunAs, SoundGet

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 ?% (92/220): alphabetically
TO DO ?% (91/220): alphabetically
- BlockInput, Control, ControlFocus, ControlGet, ControlGetFocus,
- ControlMove,
- DetectHiddenText, DetectHiddenWindows, Drive, DriveGet, DriveSpaceFree,
Expand All @@ -100,7 +100,7 @@ TO DO ?% (92/220): alphabetically
- Process, Progress, SetBatchLines,
- SetCapslockState, SetControlDelay, SetDefaultMouseSpeed, SetFormat,
- SetNumlockState, SetScrollLockState, SetStoreCapslockMode, SetTitleMatchMode,
- SetWinDelay, Sort, SoundGet, SoundGetWaveVolume, SoundPlay, SoundSet,
- SetWinDelay, Sort, SoundGetWaveVolume, SoundPlay, SoundSet,
- SoundSetWaveVolume, SplashImage, SplashTextOn, SplashTextOff, SplitPath, StatusBarGetText,
- StatusBarWait, StringCaseSense, StringSplit, StringTrimLeft, StringTrimRight,
- SysGet, Thread, Transform, WinActivateBottom,
Expand Down
16 changes: 8 additions & 8 deletions docs/index.html
Expand Up @@ -546,7 +546,7 @@ <h2>Table of contents </h2>
<a href="#">Sound Commands</a>
<ul>
<li>
<a class="tbd" href="#SoundGet.htm">SoundGet</a>
<a href="#SoundGet.htm">SoundGet</a>
</li>
<li>
<a class="tbd" href="#SoundGetWaveVolume.htm">SoundGetWaveVolume</a>
Expand Down Expand Up @@ -2590,7 +2590,7 @@ <h2 class="calibre9"><span class="calibre23">The "Last Found" Window </span></h2
<td height="16" class="calibre4">Arranges a variable's contents in alphabetical or numerical order.</td>
</tr>
<tr class="calibre3">
<td height="16" class="tbd calibre4"><a href="#SoundGet.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">SoundGet</a></td>
<td height="16" class="calibre4"><a href="#SoundGet.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">SoundGet</a></td>
<td height="16" class="calibre4">Retrieves various settings from a sound device (master mute, master volume, etc.)</td>
</tr>
<tr class="calibre3">
Expand Down Expand Up @@ -11224,7 +11224,7 @@ <h2 id="Examples">Examples</h2>
</table>
</div>
</div>
<div class="calibreMain tbd">
<div class="calibreMain">
<div class="calibreEbookContent">
<a id="SoundGet.htm" href="#SoundGet.htm">#</a> <h2 class="calibre17">SoundGet</h2>
<hr size="2" class="calibre24" />
Expand All @@ -11242,30 +11242,30 @@ <h2 id="Examples">Examples</h2>
<tbody class="calibre2">
<tr class="calibre3">
<td width="15%" class="calibre4">OutputVar</td>
<td width="85%" class="calibre4">The name of the variable in which to store the retrieved setting, which is either a floating point number between 0 and 100 (inclusive) or the word ON or OFF (used only for <em class="calibre21">ControlTypes</em> ONOFF, MUTE, MONO, LOUDNESS, STEREOENH, and BASSBOOST). The variable will be made blank if there was a problem retrieving the setting. The format of the floating point number, such as its decimal places, is determined by <a href="#SetFormat.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">SetFormat</a>.</td>
<td width="85%" class="calibre4">The name of the variable in which to store the retrieved setting, which is either a floating point number between 0 and 100 (inclusive) or the word ON or OFF (used only for <em class="calibre21">ControlTypes</em> ONOFF, MUTE, <span class="tbd">MONO, LOUDNESS, STEREOENH, and BASSBOOST</span>). <span class="tbd">The variable will be made blank if there was a problem retrieving the setting</span>. The format of the floating point number, such as its decimal places, is determined by <a href="#SetFormat.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">SetFormat</a>.</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. If the sound device lacks the specified <em class="calibre21">ComponentType</em>, ErrorLevel will indicate the problem.</span></p>
<p class="calibre8">The component labled 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 second 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. If the specified <em class="calibre21">ComponentType</em> lacks the specified <em class="calibre21">ControlType</em>, ErrorLevel will indicate the problem.</span> </td>
</tr>
<tr class="calibre3">
<td class="calibre4">DeviceNumber</td>
<td class="calibre4">If this parameter is omitted, it defaults to 1 (the first sound device), which is usually the system's default device for recording and playback. Specify a number higher than 1 to operate upon a different sound device.</td>
<td class="calibre4 tbd">If this parameter is omitted, it defaults to 1 (the first sound device), which is usually the system's default device for recording and playback. Specify a number higher than 1 to operate upon a different sound device.</td>
</tr>
</tbody>
</table>
<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
21 changes: 21 additions & 0 deletions src/cmd/misc/sound-get.cr
@@ -0,0 +1,21 @@
# SoundGet, OutputVar [, ComponentType, ControlType, DeviceNumber]
class Cmd::Misc::SoundGet < 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)
out_var = args[0]
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"
is_on = ! is_on
end
value = is_on ? "ON" : "OFF"
else
value = `awk -F"[][]" '/Left:/ { print $2 }' <(amixer sget Master)`.strip.[...-1]
end
thread.runner.set_user_var(out_var, value)
"0"
end
end

0 comments on commit f15f3c7

Please sign in to comment.