AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Precisely adjust Master and wave with OSD showing the value

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
TheLeO



Joined: 11 Jun 2005
Posts: 160
Location: England ish

PostPosted: Mon Jun 30, 2008 6:40 pm    Post subject: Precisely adjust Master and wave with OSD showing the value Reply with quote

What this is:
Adjust the Master and wave volume, but much more precise than normal.
Master and Wave are displayed on a OSD

You can either Use the keyboard volume wheel/buttons, Shift & arrows(read code) or use the mouse (if you have a 4th mouse button) (read code for instructions)


Adjust this bit, down in the code, to control it's precision...
Quote:
If CurVol > 50
Amount = 5 ;-- Adjust these bits if you want the volume to be more or less sensitive.
else if CurVol > 30
Amount = 3
Else if CurVol > 10
Amount = 2
Else if CurVol > 5
Amount = 1
Else
Amount = 0.2



Why...
I often have the problem that when using the volume rotation nob on my keyboard, the sound is often either too loud or too quite. Especially late at night, I do alot of adjusting inorder no to wake the neighbours..


So i put a few old functions together and made some new once,

I used the example OSD and adjusted it a little, the rest is hand written.

Let me know what you think.
Code:
;---------------------------Keyboard hotkeys


;Simple hotkeys, you press the volume buttons/rotate the wheel on your keyboard, to decrease volume
;Shift + volume to adjust the Wave.
Volume_Down::
  AdjustVolume("Down", "MASTER")
return

~Shift & Volume_Down::
 AdjustVolume("Down", "WAVE")
Return
 
Volume_up::
  AdjustVolume("UP", "MASTER")
Return

~Shift & Volume_up::
 AdjustVolume("Up", "WAVE")
return

Volume_Mute::
SoundSet, +1, , mute  ; Toggle the master mute (set it to the opposite state)
SoundGet, master_mute, , mute
QOSD("Mute is " master_mute)
return


;-For those of us without volume buttons on the keyboard,
;-you may use this, or, any other simple solution.
;shift and arrows = adjust master.
;shift(tap this) + shift(press and hold) & arrow keys to adjust WAVE..

/* just delete the comments :-)
~Shift::DoublePress("")
~Shift & Down::
If DoublePress
 AdjustVolume("Down", "WAVE")
else
  AdjustVolume("Down", "MASTER")
return

~Shift & UP::
If DoublePress
 AdjustVolume("Up", "WAVE")
else
  AdjustVolume("UP", "MASTER")
return
 

~Shift & Right::
If DoublePress
{
SoundSet, +1, , mute  ; Toggle the master mute (set it to the opposite state)

SoundGet, master_mute, , mute
QOSD("Mute is " master_mute)
}
return
*/

;-------------------------------------------------------Mouse hotkeys
/*Usage
personally, I prefere to adjust the volume with my mouse, because i'm often on the sofa,
quite a a distance away from the keyboard.
 I use the 4th mouse button + scroll wheel on my mouse to adjust the volume here.

To adjust MASTER you hold the 4th mouse button down, and then you scroll the mouse wheel up or down.

To adjust WAVE you double press & hold ie( click, and click&Hold)
the 4th mouse button down, and then you scroll the mouse wheel up or down.

To toggle mute, you double press & hold the 4th mouse button and press the middle mouse button.
*/
~xbutton1::DoublePress("")
~Xbutton1 & wheeldown::
If DoublePress
 AdjustVolume("Down", "WAVE")
else
  AdjustVolume("Down", "MASTER")
return

~Xbutton1 & Wheelup::
If DoublePress
 AdjustVolume("Up", "WAVE")
else
  AdjustVolume("UP", "MASTER")
return


~Xbutton1 & MButton::
If DoublePress
{
SoundSet, +1, , mute  ; Toggle the master mute (set it to the opposite state)

SoundGet, master_mute, , mute
QOSD("Mute is " master_mute)
}
;I have sinlge press xbutton1 & Mbtton assigned to play/pause in Itunes.
return




;----------------------------------------------Adjust and display volume 
;This bit adjust and displays the Volume for given components
;I'm using Master and wave, but it would be easy to adjust it, just
AdjustVolume(Direction, Component)  ; up/down, Wave/master
{   
SoundGet, CurVol, %Component%
If CurVol > 50
  Amount = 5         ;-- Adjust these bits if you want the volume to be more or less sensitive.
else if CurVol > 30
  Amount = 3
Else if CurVol > 10
  Amount = 2
Else if CurVol > 5
  Amount = 1
Else
    Amount = 0.2

If Direction = Down
 Amount = -%Amount%
Else if Direction = Up
 Amount = +%Amount%
   
SoundSet, %Amount%, %Component%
   
SoundGet, TMPMasterVolume, Master
If TMPMasterVolume = 100.000000
  MasterVolume  = 100
Else If TMPMasterVolume <= 10
  StringLeft, MasterVolume, TMPMasterVolume, 3
Else
  StringLeft, MasterVolume, TMPMasterVolume, 2


SoundGet, TMPWAVEVolume, Wave
If TMPWAVEVolume = 100.000000
  WAVEVolume  = 100
Else If TMPWAVEVolume <= 10
  StringLeft, WAVEVolume, TMPWAVEVolume, 3
Else
  StringLeft, WAVEVolume, TMPWAVEVolume, 2



If Component = Master
VolMsg = >>%MasterVolume%<<    %WAVEVolume%
Else If Component = WAVE
VolMsg =.   %MasterVolume%     >>%WAVEVolume%<<
Else
VolMsg =.   %MasterVolume%     %WAVEVolume% ;add any of your own components...
QOSD(VolMsg)
}





;-----------------------------------------------------------------------On screen Display (OSD)

;quick OSD
QOSD(Input)
{
global qosdStatus

if qosdStatus = on ; I added this bit, so when the function is called while the old osd is open, it'll close it.
Gosub KillOSD

qosdStatus = on
;--Options
xpos = 150
ypos := (A_ScreenHeight - 150)
Colour = Blue
DurationOfStay = 1500
size = 32
myOSDtext = %Input%


CustomColor = EEAA99  ; Can be any RGB color (it will be made transparent below).
Gui 60: +LastFound +AlwaysOnTop -Caption +ToolWindow  ; +ToolWindow avoids a taskbar button and an alt-tab menu item.
Gui, 60:Color, %CustomColor%
Gui, 60:Font, s%size%  ; Set a large font size (32-point).
Gui, 60:Add, Text, c%Colour%, %myOSDtext%  ; XX & YY serve to auto-size the window.
; Make all pixels of this color transparent and make the text itself translucent (150):
WinSet, TransColor, %CustomColor% 150
Gui, 60:Show, x%xpos% y%ypos% NoActivate  ; NoActivate avoids deactivating the currently active window.

SetTimer, KillOSD ,%DurationOfStay%
Return
}

KillOSD:
SetTimer, KILLOSD ,Off, Priority
sleep %DurationOfStay%
gui, 60:destroy
qosdStatus = off
return






;---------------------------------------------------------------------Double press

DoublePress(MonitoredButton)
{
global
If MonitoredButton =
  MonitoredButton = %A_thishotkey%
If MonitoredButton contains #,~,!,^,& 
  MonitoredButton := FilterCharsOutOfInput("~#!&",MonitoredButton)
DoublePress := false ; Re-initialize Doublepress.
KeyWait, %MonitoredButton%,D T0.6 ; ... and the next press.
If Errorlevel ; If it never comes or takes too long, DoublePRess remains false.
   return
Else
DoublePress := true ;

ButtonToMonitor = %MonitoredButton%

SetTimer, DoublePressMonitor , 200
}


DoublePressMonitor:
GetKeyState, ButtonToMonitorState, %ButtonToMonitor%
if ButtonToMonitorState = U
{
  DoublePress := False
  SetTimer, DoublePressMonitor ,Off
}
Return








;----------------------------------------------------------------Character filter
FilterCharsOutOfInput(chars,InputString)
{
  AutoTrim, off
  CharsLength := Strlen(chars)
  CharsStartPos = 1
    InputLength := Strlen(InputString)
  Loop %CharsLength%
  {
  Stringmid, FilterChar, chars, %CharsStartPos%, 1
  CharsStartPos += 1
    InputStartpos = 1
    TempString =
      Loop %InputLength%
        {
        Stringmid, CurrentInputchar, InputString, %InputStartpos%, 1
        InputStartpos += 1
        ;If Currentchar = %A_Space%
        ;  Output = %Output%%A_Space%
        ;If Currentchar = %A_Tab%
        ;  Output = %Output%%A_Tab%
        If CurrentInputchar = %FilterChar%
          Continue
        Else
        ;MsgBox, %TempString%
          TempString = %TempString%%CurrentInputchar%
         ; MsgBox, TempString %TempString% CurrentInputchar %CurrentInputchar%    InputString %InputString%
        }
       
  InputString = %TempString%
  }
AutoTrim, on
return InputString
}

_________________
And i say: where there is a problem , there is a solution.(well some where that is.)
::
I Have Spoken
::
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
TheLeO



Joined: 11 Jun 2005
Posts: 160
Location: England ish

PostPosted: Thu Jul 03, 2008 7:26 pm    Post subject: Reply with quote

and no one seems to care Sad
_________________
And i say: where there is a problem , there is a solution.(well some where that is.)
::
I Have Spoken
::
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
BoBo²
Guest





PostPosted: Thu Jul 03, 2008 8:36 pm    Post subject: Reply with quote

Quote:
Especially late at night, I do alot of adjusting inorder no to wake the neighbours..
Quote:
and no one seems to care
So your neighbours didn't show up to thank you? ShockedWink

Btw, thanks for sharing your script. Cool
Back to top
garry



Joined: 19 Apr 2005
Posts: 1017
Location: switzerland

PostPosted: Thu Jul 03, 2008 8:39 pm    Post subject: Reply with quote

hello TheLeO,
looks very nice , I tried the second example (have no volume key)
I was always missing the volume button on the keyboard
I had new keyboards with bad mechanic
now use an 20 years old keyboard (no WINkey and volume) and a 40 years old portable radio with good sound to listen
meanwhile not missing the volume button, just made a hotkey for mute and sndvol32 (XP)
to record music I use a slider (stereomix and wave) inside the gui (ahk script)
Back to top
View user's profile Send private message
lilalurl.T32



Joined: 17 May 2007
Posts: 41
Location: Titan

PostPosted: Thu Jul 03, 2008 11:44 pm    Post subject: Reply with quote

TheLeO wrote:
and no one seems to care Sad


The idea is nice. It is far more informative than the green OSD bar.

Since I tend to set my volume to 'what sounds right' (not some value) and through either win+mousewheel or the audigy rack knob, I don't have much use for seeing the volume value but as I said the idea is interesting.

I have encountered a small problem though regarding pressing the mute button (my keyboard is a MS natural ergonomic keyboard 4000 if that matters).
I can't seem to find a consistent behaviour. Sometimes I press mute and get 'mute is on'. Then if I press mute again almost immediatly, it still remain on. I can do that a few times until it changes to 'mute is off'. And sometimes even if I wait for the OSD to disappear, pressing the mute button again doesn't change the mute state.
When not using the script every press on the mute button actually toggles the mute state on or off.
Back to top
View user's profile Send private message
TheLeO



Joined: 11 Jun 2005
Posts: 160
Location: England ish

PostPosted: Fri Jul 04, 2008 8:31 pm    Post subject: Reply with quote

Quote:
So your neighbours didn't show up to thank you?


Actually,-- I live in a flat--. Once, my neighbours to the right had such loud music that my neighbours from the left came to me and told me to turn my music down. Surprised




Quote:
now use an 20 years old keyboard

As long as it works heh?




Quote:
I have encountered a small problem though regarding pressing the mute button (my keyboard is a MS natural ergonomic keyboard 4000 if that matters).


thats odd. I can't seem to recreate the error. If i press and hold down the mute button, it mutes or unmutes the volume.

The mute function doesn't use any fancy code, just:

Code:

;The bit below is directly copied from the ahk help file.
SoundSet, +1, , mute  ; Toggle the master mute (set it to the opposite state)

;this bit just retrieves the mute state
SoundGet, master_mute, , mute


;quick on screen display, this bit just shows the mute state.
QOSD("Mute is " master_mute)


I really don't know what could go wrong. Confused



Maybe the keyboard send the button continiously instead of just once.
try to replace the hotkey with this: (it's triggered by the button up event as oppose to button down event.

Code:
Volume_Mute Up::
Question


Or try a different hotkey altogether, see if that makes any difference.
_________________
And i say: where there is a problem , there is a solution.(well some where that is.)
::
I Have Spoken
::
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
lilalurl.T32



Joined: 17 May 2007
Posts: 41
Location: Titan

PostPosted: Tue Jul 08, 2008 11:31 pm    Post subject: Reply with quote

Volume_Mute Up didn't improve things.

I'm almost sure the keyboard (using MS intellitype software) is to blame. It is quite notorious for not behaving 'normally'.

Doesn't matter anyway. If I start using your script on a regular basis, I'll just remove the mute section since what is really interesting is the volume part.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group