Jump to content

New Winamp, need help with volume


Recommended Posts

Okay since this volume thing came up, i tried making my own simple winamp, but i ran into trouble.. i want this volume control, but also for each speaker.. and here comes my problem, how can i calculate so when moving the second slider from the middle and to the left, the left speaker gets the sound, and vice versa...

#include <GUIConstants.au3>
#include <GuiListView.au3>

GUICreate("Winamp",250,370)
GUISetBkColor (0x330099) 
$FileInput = GUICtrlCreateInput("",5,25,155,17,$ES_Readonly)
$Play = GUICtrlCreateButton("Play",164,24,40,19)
$Stop = GUICtrlCreateButton("Stop",205,24,40,19)
$slider1 = GUICtrlCreateSlider (0,45,165,18,$TBS_NOTICKS)
$slider2 = GUICtrlCreateSlider (160,45,90,18,$TBS_NOTICKS)
$MusicList = GUICtrlCreateListView("Filename:",5,75,240,270)
$Browse = GUICtrlCreateButton("Add folder",5,347,70,19)
$ClearList = GUICtrlCreateButton("Clear List",77,347,70,19)
_GUICtrlListViewSetColumnWidth ($MusicList,0,235)
_GUICtrlListViewSetBkColor ($MusicList, 0xCC0000)
_GUICtrlListViewSetTextBkColor ($MusicList, 0xCC0000)

GUISetState()
GUICtrlSetData($slider2,50)
GUICtrlSetLimit($slider2,100,0)

SetVolume()
$procent = 100
$last = 100

while 1
    $msg = GuiGetMsg()
Select
    Case $msg = $GUI_EVENT_CLOSE 
        Exit
    
    Case $msg = $Browse
        $BrowseFile = FileSelectFolder("", "", "Music files (*.mp3;*.wav)", 1 + 4 )
        $Currentpath = $BrowseFile &"\"
        If $BrowseFile = "" Then
        Else
            _GUICtrlListViewDeleteAllItems($MusicList) 
            $a = _FileSearch("*.*",$BrowseFile & "\",1)
            For $i = 1 To $a[0]
                $FileGetName = StringTrimLeft($a[$i], StringInStr($a[$i], "\", 0, -1))
                GUIctrlCreateListViewItem($FileGetName,$MusicList)
            Next
        EndIf

    Case $msg = $ClearList
        _GUICtrlListViewDeleteAllItems($MusicList)
        
    Case $msg = $Stop
        SoundPlay(GUICtrlRead($BrowseFile))
        GUICtrlSetData($FileInput,"")
    
    Case $msg = $Play
        $GetSelected = _GUICtrlListViewGetItemText($MusicList)
        GUICtrlSetData($FileInput,$GetSelected)
        SoundPlay($Currentpath & $GetSelected)
        
EndSelect
$procent = GuictrlRead($slider1)
    If $last = $procent Then
    Else
        $omrg = $procent / 2.55
        $Round = Round ( $omrg, 0 )
        SoundSetWaveVolume (GuictrlRead($slider1))
        $last = $procent
    EndIf
WEnd



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


Func _FileSearch($szMask,$Thepath,$nOption)
    $szRoot = ""
    $hFile = 06
    $szBuffer = ""
    $szReturn = ""
    $szPathList = "*"
    Dim $aNULL[1]
    If Not StringInStr($szMask,"\") Then
         $szRoot = $Thepath
    Else
         While StringInStr($szMask,"\")
              $szRoot = $szRoot & StringLeft($szMask,StringInStr($szMask,"\"))
              $szMask = StringTrimLeft($szMask,StringInStr($szMask,"\"))
         Wend
    EndIf
    If $nOption = 0 Then
         _FileSearchUtil($szRoot, $szMask, $szReturn)
    Else
         While 1
         sleep(10)           
             $hFile = FileFindFirstFile($szRoot & "*.*")
              If $hFile >= 0 Then
                   $szBuffer = FileFindNextFile($hFile)
                   While Not @ERROR
                        If $szBuffer <> "." And $szBuffer <> ".." And _
                             StringInStr(FileGetAttrib($szRoot & $szBuffer),"D") Then _
                             $szPathList = $szPathList & $szRoot & $szBuffer & "*"
                        $szBuffer = FileFindNextFile($hFile)
                   Wend
                   FileClose($hFile)
              EndIf
              _FileSearchUtil($szRoot, $szMask, $szReturn)
              If $szPathList == "*" Then ExitLoop
              $szPathList = StringTrimLeft($szPathList,1)
              $szRoot = StringLeft($szPathList,StringInStr($szPathList,"*")-1) & "\"
              $szPathList = StringTrimLeft($szPathList,StringInStr($szPathList,"*")-1)
         Wend
    EndIf
    If $szReturn = "" Then
         $aNULL[0] = 0
         Return $aNULL
    Else
         Return StringSplit(StringTrimRight($szReturn,1),"*")
    EndIf
EndFunc

Func _FileSearchUtil(ByRef $ROOT, ByRef $MASK, ByRef $RETURN)
    $hFile = FileFindFirstFile($ROOT & $MASK)
    If $hFile >= 0 Then
         $szBuffer = FileFindNextFile($hFile)
         While Not @ERROR
              If $szBuffer <> "." And $szBuffer <> ".." Then _
                   $RETURN = $RETURN & $ROOT & $szBuffer & "*"
              $szBuffer = FileFindNextFile($hFile)
         Wend
         FileClose($hFile)
    EndIf
EndFunc
Link to comment
Share on other sites

I think you would have to use the 'waveOutSetVolume', as it allows you to set the left/right channel volume individually...

But, I was trying to use that last night after figuring out the 'waveOutGetVolume', and the only response I could get was my wave channel fully unbalanced to the left, and at 81% volume. Regardless of what numbers I sent to it.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...