AutoHotkey Community

It is currently May 27th, 2012, 8:12 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Mac OS X Sound OSD
PostPosted: March 8th, 2005, 2:20 pm 
Hello AHK Freaks!

I found one of my last ct-magazines next to my bed last weekend. Because an influenca I was bound to bed and bored too. But the article about AHK was fascinating because it is the tool I was ever searching for. The example by Wolfgang from ct-mag was to open/close the CD-drive with an key. This was the first script I used to see how the syntax and Autohotkey works.
I was inspired by the Idea bringing this Mac Functions and OSD to Windows (And I was bored by the ugly green-bars-OSD shown by my keyboard driver). So I decided to write a volume OSD script with optimized functionality.
The special in my script is the modular system to build the OSD. But there are some questions too. Maybe someone can help me out. I can not interrupt the OSD fadeout by hitting volume_up/volume_down a second time to increase/decrease faster. When hitting volume_down whilst a volume_up script is still running (fadeout) the loop for building the noise-level (bullets) does not work.
But here's the script:
I used the script of Tekl as sample as well as someones(sorry, can't remember his name) mutechecker script
Code:
;_________________________________
; OSD for OS X Volume hotkey declaration

volume_up::

   SoundSet, +100/16
   gosub, buildOSD

return

volume_down::

   SoundSet, -100/16
   gosub, buildOSD

return

volume_mute::

   SoundGet,checkmute,,MUTE
   if checkmute = Off
   {
      quietnow = 1
   }
   else
   {
      quietnow = 0
   }

   SoundSet, +1, , mute
   gosub, buildOSD

return

;______________________
; Build OSD for OS X Volume
; Parameter:
;     quietnow - indicates if mute status is off and should switch to on
;     transparent - the transparency at start of the fading

buildOSD:

   transparent = 192 ; starting transparency
   
   ; calculate position by Tekl
   distY = %A_ScreenHeight%
   posY = %A_ScreenHeight%
   distY /= 4
   posY -= %distY%
   
   ; create OSD background
   Gui, Add, pic,x0 y0, %A_ScriptDir%\area.bmp

   ; create OSD speaker
   SoundGet,checkmute,,MUTE
   if checkmute = On
   {
      if quietnow = 1
      {
         currsnd = 0.0
         currsnd +=0.0
         quietnow = 0
      }
      else
      {
         SoundGet, currsnd
      }
      Gui, Add, pic,x55 y50, %A_ScriptDir%\quiet.bmp
   }
   else
   {
      SoundGet, currsnd
      Gui, Add, pic,x55 y50, %A_ScriptDir%\loud.bmp
   }

   ; create OSD noise level bullets
   bullets = 16
   bullets += 0.0
   dermax = 100.0
   dermax += 0.0
   currbullet = %currsnd%
   currbullet /= %dermax%
   currbullet *= %bullets%
   Transform,currbullet,Round,%currbullet%
   Transform,bullets,Round,%bullets%
   loop, %bullets%
   {
      Transform,xbullet, Round, %bullets%
      xbullet *=9
      xbullet +=24
       ifgreaterorequal,currbullet,%bullets%
       {
         Gui, Add, pic,x%xbullet% y168, %A_ScriptDir%\fullbullet.bmp
       }
       else
       {
         Gui, Add, pic,x%xbullet% y168, %A_ScriptDir%\emptybullet.bmp
       }
       bullets -= 1
   }

   DetectHiddenWindows on
   WinWait, %A_ScriptName%  ; Set the "last found" window to GUI window.
   WinSet, TransColor,FF00FF %transparent%
   WinSet, AlwaysOnTop, On
   Gui, -Caption
   Gui, Show, w211 h206 y%posY%

   ; play the blob sound to hear the noise level
   SoundPlay, %A_ScriptDir%\sound.wav


   ; fade down the OSD by Tekl
   Loop, %transparent%
   {
      transparent -= 1
      WinSet, TransColor,FF00FF %transparent%
   }
   Gui, Destroy

return

You can find the .ahk file and the pictures here http://www.croce.at/jays_foobar/macosx_volume.zip


Report this post
Top
  
Reply with quote  
 Post subject: Re: Mac OS X Sound OSD
PostPosted: March 9th, 2005, 5:55 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
JayS wrote:
I can not interrupt the OSD fadeout by hitting volume_up/volume_down a second time to increase/decrease faster.
This is caused by the fact that by default, each hotkey cannot be launched again while it is already running.

One way to solve this is to use #MaxThreadsPerHotkey to increase the limit for these particular hotkeys to 3, 4, or even higher.

However, in this case it is probably more appropriate not to do this, and instead have your hotkeys use SetTimer to launch a new thread, and then return so that they can be launched again. This is a somewhat advanced technique, but you can see an example of it in the Joystick-to-Mouse script.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 10th, 2005, 9:13 am 
Offline

Joined: November 3rd, 2004, 11:24 am
Posts: 51
Can this help?

Code:
#Persistent
IniRead, vol_Step, %A_SCRIPTDIR%\Finderbar_Engine.ini, SoundVolume, Step, 4
IniRead, vol_DisplayTime, %A_SCRIPTDIR%\Finderbar_Engine.ini, SoundVolume, DisplayTime, 2000
IniRead, vol_BackgroungPic, %A_SCRIPTDIR%\Finderbar_Engine.ini, SoundVolume, BackgroungPic
IniRead, vol_Transparency, %A_SCRIPTDIR%\Finderbar_Engine.ini, SoundVolume, Transparency, 200
IniRead, vol_UpHotkey, %A_SCRIPTDIR%\Finderbar_Engine.ini, SoundVolume, VolumeUpHotkey, #Up
IniRead, vol_DownHotkey, %A_SCRIPTDIR%\Finderbar_Engine.ini, SoundVolume, VolumeDownHotkey, #Down
HotKey, %vol_UpHotkey%, vol_MasterUp
HotKey, %vol_DownHotkey%, vol_MasterDown
Menu,Tray, Add, Mute Sound, Mute
Menu,Tray, Default, Mute Sound
SetTimer, WatchSound, 500
return

Mute:
   SoundSet, +0, , Mute
   Return

WatchSound:
   SoundGet, vol_Mute, , Mute
   If vol_Mute = On
      {
      Menu, Tray, Check, Mute Sound
      Menu, Tray, Icon, %A_ScriptDir%\images\Volume0.ico
      Return
      }
   IfEqual, vol_Mute, Off, Menu, Tray, Uncheck, Mute Sound
   SoundGet, vol_Master, Master
   If vol_Master < 1
      Menu, Tray, Icon, %A_ScriptDir%\images\Volume0.ico
   If vol_Master between 1 and 20
      Menu, Tray, Icon, %A_ScriptDir%\images\Volume1.ico
   If vol_Master between 20 and 50
      Menu, Tray, Icon, %A_ScriptDir%\images\Volume2.ico
   If vol_Master > 50
      Menu, Tray, Icon, %A_ScriptDir%\images\Volume3.ico
   Return

vol_ShowBars:
   IfWinNotExist, %A_ScriptName%
      {
      Gui, 3:Add, Pic, x0 y0 w213 h208, %A_ScriptDir%\%vol_BackgroungPic%
      Gui, 3:Add, Progress, x35 y160 w144 h12 -Smooth, 50
      Gui, 3:+ToolWindow
      DetectHiddenWindows, On
         WinWait, %A_ScriptName%
         WinSet, TransColor,0000FF %vol_Transparency%
         WinSet, AlwaysOnTop, On, %A_ScriptName%
         Gui, 3:-Caption
       Gui, 3:Show, h208 w213
         }
   SoundGet, vol_Master, Master
   GuiControl, 3:, msctls_progress321, %vol_Master%
   SoundPlay, %A_ScriptDir%\images\sound.wav
   SetTimer, vol_BarOff, %vol_DisplayTime%
   Return

vol_BarOff:
   transparent =%vol_Transparency%
   SetTimer, vol_BarOff, off
      Loop, %transparent%
         {
         transparent -= 1
         WinSet, TransColor, 0000FF %transparent%, %A_ScriptName%
         }
      Gui, 3:Destroy
   Return

vol_MasterUp:
   SoundSet, +%vol_Step%
   Gosub, vol_ShowBars
   Return

vol_MasterDown:
   SoundSet, -%vol_Step%
   Gosub, vol_ShowBars
   Return



Based on the code by Rajat and Tekl

Please start this script only when Editors window with this script is closed

Images are here: http://landvermesser.tripod.com/volume.html


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 10th, 2005, 1:20 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
That's nice. I should have remembered that in this case, the Volume OSD scripts are much better examples of SetTimer than the joystick-to-mouse script.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 28th, 2006, 11:25 pm 
hold on...ahk works with Mac OSX? Is this true? I have a mac too, and I didnt think ahk would work with it. It doesnt right? What's OSD?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 1st, 2006, 7:51 am 
Offline

Joined: November 3rd, 2004, 11:24 am
Posts: 51
Mac?!What?!! wrote:
hold on...ahk works with Mac OSX? Is this true? I have a mac too, and I didnt think ahk would work with it. It doesnt right? What's OSD?

OSD = On Screen Display
This script simulates the visual effects of Mac OS X, this supports only Windows XP.

_________________
My AHK project: http://landvermesser.tripod.com/


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 14th, 2006, 12:20 am 
I tried to get this fade-out in my osd, but it doesnt work for me =(

Code:
;OSD Gui
WinYPos := ScHeight - 300
Transparent = 192
Gui, 1:Color, FF00FF
Gui, 1:+Lastfound
WinSet, TransColor, FF00FF %Transparent%
Gui, 1:+ToolWindow
Gui, 1:-Caption
WinSet, AlwaysOnTop, On
Gui, 1:Font, s36 Bold, Verdana
Gui, 1:Add, Text, vODSText w670 Center

Gui, 1:Add, Text, x97 y92,-
Loop,25
{
   Temp=Pic%A_Index%
   Gui, 1:Add, Picture, x+6 y100 w12 h50 Hidden Border v%Temp% , OSD_Green.bmp
}
Gui, 1:Add, Text, x+3 y92,+ ; only +3 cause + is wider than -


...


ShowOSD(Message, Value, BarColor)
{
   If SomethingRunningFullscreen()
      return
   Global OSDTextColor, WinYPos
   Gosub GuiHide
   Gui, 1:Font, c%OSDTextColor%
   GuiControl, 1:Font, ODSText
   GuiControl, 1:Font, +
   GuiControl, 1:Font, -
   GuiControl, 1:, ODSText, %Message%
   Loop,25 {
      TempPic=Pic%A_Index%
      If A_Index <= %Value%
      {
         GuiControl, 1:Font, %TempPic%
         GuiControl,1:, %TempPic%, OSD_%BarColor%.bmp
         GuiControl 1:Show, %TempPic%
      }
      else
         GuiControl Hide, %TempPic%
   }
   Gui, 1:Show, y%WinYPos%
   
   Loop, %transparent%
   {
      Transparent -= 1
      WinSet, TransColor,FF00FF %Transparent%, MSI Hotkeys Script Settings
   }
   SetTimer, GuiHide, 1000
}

GuiHide:
   SetTimer, GuiHide, Off
   Gui, 1:Hide
Return


the whole file is here --> http://phpfi.com/131026

it will not fade =(


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 13 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group