Jump to content
Sign in to follow this  
DaLiMan

SoundSetWaveController

Recommended Posts

Hi There,

I way playing with a simple GUI for setting the wave volume.

What I have is working fine but I can't seem to read the current setting back into the slider when opening the GUI.

Does anyone have an idea?

#include <GUIConstants.au3>
Global $WaveSet

GUICreate("slider",220,100, 100,200)
GUISetBkColor (0x00E0FFFF) ; will change background color

$slider1 = GUICtrlCreateSlider (10,10,200,20)
$SetVolume = GUICtrlCreateButton ("Set Volume",65,70,70,20)
$Cancel = GUICtrlCreateButton ("Cancel",140,70,70,20)

GUISetState()
GUICtrlSetData($slider1,45); set cursor

while 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $SetVolume 
      $WaveSet = GUICtrlRead($slider1)
      SoundSetWaveVolume($WaveSet)
      MsgBox(0,"slider1",GUICtrlRead($slider1),2)
      ExitLoop
    Case $msg = $Cancel 
      ExitLoop
    
    EndSelect
WEnd

Exit

Share this post


Link to post
Share on other sites

remove the "Exitloop" and it will work

<{POST_SNAPBACK}>

Thanx for your reply, but I think I was not very clear.

What I mean is that I like my script to read the current value of the wave volume and then set the slider accordingly when opening the GUI.

That way I can set the volume higher or lower than it is at that time.

Otherwise it's just guessing what will be louder or not.

Does anybody have an idea from where or how to read the current wave volume?

Share this post


Link to post
Share on other sites

Const $MMSYSERR_NOERROR = 0


$p = DllStructCreate ("dword")
If @error Then
    MsgBox(0, "", "Error in DllStructCreate " & @error);
    Exit
EndIf
Dim $v
$ret = DllCall("winmm.dll", "long", "waveOutGetVolume", "long", -1, "long", DllStructGetPtr ($p))
If ($ret[0] == $MMSYSERR_NOERROR) Then
    
;The low-order word of this location contains the left-channel volume setting,
;and the high-order word contains the right-channel setting.
;A value of 0xFFFF represents full volume, and a value of 0x0000 is silence.
    ConsoleWrite('0x' & Hex(DllStructGetData ($p, 1), 4) & @LF)
EndIf
DllStructDelete ($p)

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

Const $MMSYSERR_NOERROR = 0
$p = DllStructCreate ("dword")
If @error Then
    MsgBox(0, "", "Error in DllStructCreate " & @error);
    Exit
EndIf
Dim $v
$ret = DllCall("winmm.dll", "long", "waveOutGetVolume", "long", -1, "long", DllStructGetPtr ($p))
If ($ret[0] == $MMSYSERR_NOERROR) Then
    
;The low-order word of this location contains the left-channel volume setting,
;and the high-order word contains the right-channel setting.
;A value of 0xFFFF represents full volume, and a value of 0x0000 is silence.
    ConsoleWrite('0x' & Hex(DllStructGetData ($p, 1), 4) & @LF)
EndIf
DllStructDelete ($p)

<{POST_SNAPBACK}>

Wow, thanx gafrost.

Can you also show me how to use this? :(

Because I don't understand how to insert this into my own script or get the data from your script.

When running this in Beta I get no errors but I also get no value's in my screen.

Please explain so I can learn..... :(

Share this post


Link to post
Share on other sites

Wow, thanx gafrost.

Can you also show me how to use this?  :(

Because I don't understand how to insert this into my own script or get the data from your script.

When running this in Beta I get no errors but I also get no value's in my screen.

Please explain so I can learn..... :(

<{POST_SNAPBACK}>

Now you get the output, calculated into decimal. 0% volume gives 0 and 100& volume gives you 65535, now you have to calcutale it into percent

Const $MMSYSERR_NOERROR = 0
$p = DllStructCreate ("dword")
If @error Then
    MsgBox(0, "", "Error in DllStructCreate " & @error);
    Exit
EndIf
Dim $v
$ret = DllCall("winmm.dll", "long", "waveOutGetVolume", "long", -1, "long", DllStructGetPtr ($p))
If ($ret[0] == $MMSYSERR_NOERROR) Then
     MsgBox(0, "",Dec(Hex(DllStructGetData ($p, 1), 4)));
;The low-order word of this location contains the left-channel volume setting,
;and the high-order word contains the right-channel setting.
;A value of 0xFFFF represents full volume, and a value of 0x0000 is silence.
    ConsoleWrite('0x' & Hex(DllStructGetData ($p, 1), 4) & @LF)
EndIf
DllStructDelete ($p)
Edited by Wb-FreeKill

Share this post


Link to post
Share on other sites

I'm not sure if I properly understand the high-order/low-order word stuff... but I think this will work out.

Const $MMSYSERR_NOERROR = 0
$p = DllStructCreate ("dword")
$ret = DllCall("winmm.dll", "long", "waveOutGetVolume", "long", -1, "long", DllStructGetPtr ($p))
If ($ret[0] == $MMSYSERR_NOERROR) Then
    $s_HexVolume = Hex(DllStructGetData($p, 1), 8)
Else
    MsgBox(32, 'Error', 'Could not retrieve wave volume.')
EndIf
DllStructDelete($p)

$i_VolPercent_L = Round(Dec(StringRight($s_HexVolume, 4)) / 0xFFFF * 100)
$i_VolPercent_R = Round(Dec(StringLeft($s_HexVolume, 4)) / 0xFFFF * 100)

MsgBox(0, 'Wave Channel Volume', 'Left Channel: ' & $i_VolPercent_L & '%' & @LF &_
                                 'Right Channel: ' & $i_VolPercent_R & '%')

Share this post


Link to post
Share on other sites

Try this.. :(

#include <GUIConstants.au3>
Global $WaveSet

GUICreate("slider",220,100, 100,200)
GUISetBkColor (0x00E0FFFF); will change background color

$slider1 = GUICtrlCreateSlider (10,10,200,20)
$SetVolume = GUICtrlCreateButton ("Set Volume",65,70,70,20)
$Cancel = GUICtrlCreateButton ("Cancel",140,70,70,20)

GUISetState()
GUICtrlSetData($slider1,50); set cursor
SetVolume()
while 1
    $msg = GuiGetMsg()
Sleep(10)
SetVolume()

Select
    
    Case $msg = $SetVolume 
        SetVolume()
    Case $msg = $Cancel 
        ExitLoop
    
EndSelect
WEnd

Exit


SetVolume()
Func SetVolume()
Const $MMSYSERR_NOERROR = 0
$p = DllStructCreate ("dword")
$ret = DllCall("winmm.dll", "long", "waveOutGetVolume", "long", -1, "long", DllStructGetPtr ($p))
If ($ret[0] == $MMSYSERR_NOERROR) Then
    $s_HexVolume = Hex(DllStructGetData($p, 1), 8)
Else
    MsgBox(32, 'Error', 'Could not retrieve wave volume.')
EndIf
DllStructDelete($p)

$i_VolPercent_L = Round(Dec(StringRight($s_HexVolume, 4)) / 0xFFFF * 100)
$i_VolPercent_R = Round(Dec(StringLeft($s_HexVolume, 4)) / 0xFFFF * 100)

;~ MsgBox(0, 'Wave Channel Volume', 'Left Channel: ' & $i_VolPercent_L & '%' & @LF &_
;~                                'Right Channel: ' & $i_VolPercent_R & '%')
GUICtrlSetData($slider1,$i_VolPercent_L)
EndFunc

Share this post


Link to post
Share on other sites

OK thanx y'all.

I combined your reply's and came up with this one. :(

#include <GUIConstants.au3>
Global $WaveSet
Global $WaveVol

GUICreate("slider",220,100, 100,200)
GUISetBkColor (0xFFFFFF) ; will change background color


$slider1 = GUICtrlCreateSlider (10, 10, 200, 50)
GUICtrlSetColor ( -1, 0xff0000)

$SetVolume = GUICtrlCreateButton ("Set Volume",65,70,70,20)
$Cancel = GUICtrlCreateButton ("Cancel",140,70,70,20)

_WaveVolGet()
GUISetState()
GUICtrlSetData($slider1,$WaveVol); set current volume

while 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $SetVolume 
      $WaveSet = GUICtrlRead($slider1)
      SoundSetWaveVolume($WaveSet)
      _Say("check volume")
    Case $msg = $Cancel 
      ExitLoop
    
    EndSelect
WEnd

Exit


Func _WaveVolGet()
Const $MMSYSERR_NOERROR = 0
$p = DllStructCreate ("dword")
If @error Then
    MsgBox(0, "", "Error in DllStructCreate " & @error);
    Exit
EndIf
Dim $v
$ret = DllCall("winmm.dll", "long", "waveOutGetVolume", "long", -1, "long", DllStructGetPtr ($p))
If ($ret[0] == $MMSYSERR_NOERROR) Then
;~    MsgBox(0, "",Round(Dec(StringRight(Hex(DllStructGetData($p, 1), 8), 4)) / 0xFFFF * 100));
Global $WaveVol = Round(Dec(StringRight(Hex(DllStructGetData($p, 1), 8), 4)) / 0xFFFF * 100)
EndIf
DllStructDelete ($p)

EndFunc  ;==>_WaveVolGet

Func _Say($text)
    $talk = ObjCreate ('SAPI.SpVoice')
    If Not @error Then $talk.Speak ($text)
    Return
EndFunc  ;==>_Say

Share this post


Link to post
Share on other sites

Sorry been offline, didn't catch the post, glad Wb-FreeKill and Saunders was able to help you.

Minor changes to that function

1. Don't use globals, use return

2. set different error levels

For example:

Func _WaveVolGet()
    Local $WaveVol = -1, $p, $ret
    Const $MMSYSERR_NOERROR = 0
    $p = DllStructCreate ("dword")
    If @error Then
        SetError(2)
        Return -2
    EndIf
    $ret = DllCall("winmm.dll", "long", "waveOutGetVolume", "long", -1, "long", DllStructGetPtr ($p))
    If ($ret[0] == $MMSYSERR_NOERROR) Then
        $WaveVol = Round(Dec(StringRight(Hex(DllStructGetData ($p, 1), 8), 4)) / 0xFFFF * 100)
    Else
        SetError(1)
    EndIf
    DllStructDelete ($p)
    Return $WaveVol
EndFunc  ;==>_WaveVolGet
Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

Sorry been offline, didn't catch the post, glad Wb-FreeKill and Saunders was able to help you.

Minor changes to that function

1. Don't use globals, use return

2. set different error levels

OK, thanx for the advice.

But why use RETURN instead of GLOBALS?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...