Sign in to follow this  
Followers 0
Rawox

_SoundPlay and _SoundStop

2 posts in this topic

#1 ·  Posted (edited)

Hey,,

I was trying to make a AlarmClock, I always sleep right through my mobile alarm...

But I have a problem now:

In the script you can tell how many times the sound must be repeated and after how many minutes.

If you click on the set alarm button another GUI comes up with some basic information. I haven't started on the snooze function.

When the sound plays the first time, you can still click on enter. The sound will stop and the main GUI with options will show up.

But when you click on Enter if the sound is playing for the second time, the GUI comes up but the sound keeps playing.

I tried to fix this for around 40 minutes now and I still have no clue. I'm going to bed? Maybe someone can look at it?

#include <ComboConstants.au3>
#include <Date.au3>
#include <EditConstants.au3>
#Include <File.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <Sound.au3>
#include <WindowsConstants.au3>

Opt ( "GUIResizeMode", 802 )
AdlibEnable ( "Updater", 800 )

$Title = "AlarmClock"
$IniDirectory = @MyDocumentsDir & "\AlarmClock.ini"
$i = 0
$x = 0
$n = 0
$q = 0
$w = 0
$p = 0

;;;;;;;;;;;; TO DO ;;;;;;;;;;;;;;
; SNOOZER!                      ;
; Working alarm                 ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

$GUI = GUICreate ( $Title, 360, 345 ) ;65 ;345
#Region Options ///////////////////////////////////////////////////////////////////////////////////////////#
GUICtrlCreateGroup ( "Time", 10, 70, 150, 48 )
GUICtrlCreateLabel ( "Play alarm at:", 23, 90 )
GUICtrlCreateLabel ( ":", 116, 90 )
$Hours = GUICtrlCreateInput ( "07", 95, 88, 20, 20, $ES_NUMBER )
$Minutes = GUICtrlCreateInput ( "30", 120, 88, 20, 20, $ES_NUMBER )
GUICtrlSetLimit ( $Hours, 2, 2 )
GUICtrlSetLimit ( $Minutes, 2, 2 )
GUICtrlSetTip ( $Hours, "Select a number in a range from 00 to 23.", "Hours", 1, 2 )
GUICtrlSetTip ( $Minutes, "Select a number in a range from 00 to 59.", "Minutes", 1, 2 )
GUICtrlCreateGroup ( "Alarm", 170, 70, 180, 48 )
$File = GUICtrlCreateInput ( "No file selected!", 183, 88, 100, 20, $ES_READONLY )
GUICtrlSetTip ( $File, GUICtrlRead ( $File ) )
$Browse = GUICtrlCreateButton ( "Browse", 285, 87, 50, 21 )
GUICtrlSetColor ( $File, 0xFF0000 )
GUICtrlCreateGroup ( "Days", 10, 128, 340, 48 )
$Mon = GUICtrlCreateCheckbox ( "Mon", 23, 146 )
$Tue = GUICtrlCreateCheckbox ( "Tue", 23*2+23, 146 )
$Wed = GUICtrlCreateCheckbox ( "Wed", 23*3+23*2, 146 )
$Thu = GUICtrlCreateCheckbox ( "Thu", 23*4+23*3, 146 )
$Fri = GUICtrlCreateCheckbox ( "Fri", 23*5+23*4, 146 )
$Sat = GUICtrlCreateCheckbox ( "Sat", 23*6+23*5, 146 )
$Sun = GUICtrlCreateCheckbox ( "Sun", 23*7+23*6, 146 )
GUICtrlCreateGroup ( "Repeat", 10, 185, 255, 48 )
GUICtrlCreateLabel ( "Repeat alarm every", 23, 205 )
$RepeatMin = GUICtrlCreateInput ( "5", 120, 203, 20, 20 )
GUICtrlSetLimit ( $RepeatMin, 2 )
$MLabel = GUICtrlCreateLabel ( " minutes for", 145, 205 )
$RepeatNum = GUICtrlCreateInput ( "10", 202, 203, 20, 20 )
GUICtrlSetLimit ( $RepeatNum, 2 )
$TLabel = GUICtrlCreateLabel ( "times.", 226, 205 )
$SetAlarm = GUICtrlCreateButton ( "Set alarm", 270, 191, 80, 41 )
$SWW = GUICtrlCreateCheckbox ( "Start with Windows", 20, 238 )
$POP = GUICtrlCreateCheckbox ( "Reminder when shutting down Windows", 140, 238 )
GUICtrlCreateGroup ( "Volume", 10, 263, 200, 70 )
$VolumeSlider = GUICtrlCreateSlider ( 23, 305, 200-23*2+15, 20 )
$VolumeCheckbox = GUICtrlCreateCheckBox ( "Adjust volume to " & GUICtrlRead ( $VolumeSlider ) & " percent.", 25, 280, 180 )
GUICtrlCreateGroup ( "Snoozer", 220, 263, 130, 70 )
$SnoozeCombo = GUICtrlCreateCombo ( "1 minute", 233, 300, 100, 20, $CBS_DROPDOWNLIST )
GUICtrlSetData ( $SnoozeCombo, "2 minutes|3 minutes|4 minutes|5 minutes|6 minutes|7 minutes|8 minutes|9 minutes|10 minutes|30 minutes|60 minutes" )
GUICtrlCreateLabel ( "Snooze for", 233, 280, 70, 13 )
$SnoozeLabel = GUICtrlCreateLabel ( GUICtrlRead ( $SnoozeCombo ), 286, 280, 60, 12 )
#EndRegion
#Region Dummy //////////////////////////////////////////////////////////////////////////////////////////////#
$Hours2 = GUICtrlCreateLabel ( GUICtrlRead ( $Hours ), 10, 375 )
$Minutes2 = GUICtrlCreateLabel ( GUICtrlRead ( $Minutes ), 30, 375 )
$FileFullPath = GUICtrlCreateLabel ( GUICtrlRead ( $File ), 10, 395, 300, 30 )
$RepeatMin2 = GUICtrlCreateLabel ( GUICtrlRead ( $RepeatMin ), 10, 425 )
$RepeatNum2 = GUICtrlCreateLabel ( GUICtrlRead ( $RepeatNum ), 30, 425 )
#EndRegion
#Region Changes from Ini ///////////////////////////////////////////////////////////////////////////////////#
GUICtrlSetData ( $Hours, IniRead ( $IniDirectory, "Time", "Hours", "07" ) )
GUICtrlSetData ( $Minutes, IniRead ( $IniDirectory, "Time", "Minutes", "30" ) )
GUICtrlSetData ( $File, IniRead ( $IniDirectory, "File", "Name", "No file selected!" ) )
If IniRead ( $IniDirectory, "File", "Name", "No file selected!" ) = "No file selected!" Then
    GUICtrlSetColor ( $File, 0xFF0000 )
Else
    GUICtrlSetColor ( $File, 0x000000 )
EndIf
Sleep ( 10 )
GUICtrlSetData ( $FileFullPath, IniRead ( $IniDirectory, "File", "Path", "No file selected!" ) )
GUICtrlSetState ( $Mon, IniRead ( $IniDirectory, "Days", "Mon", 1 ) )
GUICtrlSetState ( $Tue, IniRead ( $IniDirectory, "Days", "Tue", 1 ) )
GUICtrlSetState ( $Wed, IniRead ( $IniDirectory, "Days", "Wed", 1 ) )
GUICtrlSetState ( $Thu, IniRead ( $IniDirectory, "Days", "Thu", 1 ) )
GUICtrlSetState ( $Fri, IniRead ( $IniDirectory, "Days", "Fri", 1 ) )
GUICtrlSetState ( $Sat, IniRead ( $IniDirectory, "Days", "Sat", 4 ) )
GUICtrlSetState ( $Sun, IniRead ( $IniDirectory, "Days", "Sun", 4 ) )
GUICtrlSetData ( $RepeatMin, IniRead ( $IniDirectory, "Repeat", "Minutes", "5" ) )
GUICtrlSetData ( $RepeatNum, IniRead ( $IniDirectory, "Repeat", "Times", "3" ) )
GUICtrlSetState ( $SWW, IniRead ( $IniDirectory, "Options", "Startup", 1 ) )
GUICtrlSetState ( $POP, IniRead ( $IniDirectory, "Options", "Reminder", 1 ) )
GUICtrlSetState ( $VolumeCheckbox, IniRead ( $IniDirectory, "Volume", "Checkbox", 1 ) )
GUICtrlSetData ( $VolumeSlider, IniRead ( $IniDirectory, "Volume", "Slider", 50 ) )
GUICtrlSetData ( $SnoozeCombo, IniRead ( $IniDirectory, "Snooze", "Time", "5 minutes" ) )
#EndRegion
#Region Base //////////////////////////////////////////////////////////////////////////////////////////////#
$ReadHours = GUICtrlRead ( $Hours )
$ReadMinutes = GUICtrlRead ( $Minutes )
GUICtrlCreateLabel ( "Alarm at:", 10, 10, 340, 25, $SS_CENTER )
$InformationLabel = GUICtrlCreateLabel ( $ReadHours & ":" & $ReadMinutes, 60, 23, 240, 30, $SS_CENTER )
$WinPos = WinGetPos ( $Title )
If $WinPos[3] = 91 Then
    $SettingsLabel = GUICtrlCreateLabel ( "Show Settings", 260, 41, 80, 15, $SS_RIGHT )
Else
    $SettingsLabel = GUICtrlCreateLabel ( "Hide Settings", 260, 41, 80, 15, $SS_RIGHT )
EndIf
GUICtrlSetFont ( $InformationLabel, 24, 400, "Arial" )
GUICtrlSetColor ( $SettingsLabel, 0xC0C0C0 )
GUICtrlSetCursor( $SettingsLabel, 0 )
#EndRegion
GUICtrlSetState ( $FileFullPath, $GUI_FOCUS )
Updater()
GUISetState ( @SW_SHOW )

While 1
    Switch GUIGetMsg()
    Case $SetAlarm
        If GUICtrlRead ( $File ) = "No file selected!" Then
            MsgBox ( 48, $Title, "You haven't selected an alarm!" )
        Else
            If GUICtrlRead ( $SetAlarm ) = "Set alarm" Then
                GUICtrlSetData ( $SetAlarm, "Clear Alarm" )
            ElseIf GUICtrlRead ( $SetAlarm ) = "Clear alarm" Then
                GUICtrlSetData ( $SetAlarm, "Set Alarm" )
            EndIf
        EndIf
    Case $GUI_EVENT_CLOSE
        Exit
    Case $SettingsLabel
        $Size = WinGetClientSize ( $Title )
        If $Size[1] = 65 Then
            GUICtrlSetData ( $SettingsLabel, "Hide Settings" )
            $Pos = WinGetPos ( $Title )
            WinMove ( $Title, "", $Pos[0], $Pos[1]-140, $Pos[2], $Pos[3]+280 )
        Else 
            GUICtrlSetData ( $SettingsLabel, "Show Settings" )
            $Pos = WinGetPos ( $Title )
            WinMove ( $Title, "", $Pos[0], $Pos[1]+140, $Pos[2], $Pos[3]-280 )
        EndIf
    Case $Browse
        $SoundFile = FileOpenDialog ( "Select alarm", "", "MP3 files (*.mp3)|WAV files (*.wav)|MID files (*.mid)", 3 )
        If @error <> 1 Then
            GUICtrlSetColor ( $File, 0x000000 )
            Dim $szDrive, $szDir, $szFName, $szExt
            _PathSplit ( $SoundFile, $szDrive, $szDir, $szFName, $szExt )
            GUICtrlSetData ( $File, $szFName & $szExt )
            GUICtrlSetData ( $FileFullPath, $SoundFile )
            GUICtrlSetTip ( $File, GUICtrlRead ( $File ) )
            GUICtrlSetState ( $MLabel, $GUI_FOCUS )
        EndIf
    EndSwitch
WEnd

Func Updater()
    #Region Alarm
    If GUICtrlRead ( $SetAlarm ) = "Clear Alarm" Then
        AlarmCheck()
    EndIf
    #EndRegion
    #Region Snoozer
    If GUICtrlRead ( $SnoozeCombo ) <> GUICtrlRead ( $SnoozeLabel ) Then
        GUICtrlSetData ( $SnoozeLabel, GUICtrlRead ( $SnoozeCombo ) )
    EndIf
    #EndRegion
    #Region Volume
    If GUICtrlRead ( $VolumeCheckbox ) = $GUI_CHECKED Then
        GUICtrlSetState ( $VolumeSlider, $GUI_ENABLE )
    Else
        GUICtrlSetState ( $VolumeSlider, $GUI_DISABLE )
    EndIf
    GUICtrlSetData ( $VolumeCheckbox, "Adjust volume to " & GUICtrlRead ( $VolumeSlider ) & " percent." )
    #EndRegion
    #Region Filename
    If GUICtrlRead ( $File ) = "" Then
        GUICtrlSetData ( $File, "No file selected!" )
        GUICtrlSetColor ( $File, 0xFF0000 )
    ElseIf GUICtrlRead ( $File ) = "No file selected!" Then
        GUICtrlSetColor ( $File, 0xFF0000 )
    ElseIf $x = 2 Then
        GUICtrlSetColor ( $File, 0x000000 )
    Else 
        $x +=1
    EndIf
    #EndRegion
    #Region Time
    If $i = 2 Then
        $ReadHours = GUICtrlRead ( $Hours )
        $ReadMinutes = GUICtrlRead ( $Minutes )
        $Read = GUICtrlRead ( $Hours )
        $Read2 = GUICtrlRead ( $Hours2 )
        $Read3 = GUICtrlRead ( $Minutes )
        $Read4 = GUICtrlRead ( $Minutes2 )
        If $Read <> $Read2 Then
            If $Read > 23 Then 
                GUICtrlSetData ( $Hours, "23" )
            ElseIf $Read = "" Then
                GUICtrlSetData ( $Hours, "00" )
            ElseIf $Read = "0" Or $Read = "1" Or $Read = "2" Or $Read = "3" Or $Read = "4" Or $Read = "5" Or $Read = "6" Or $Read = "7" Or $Read = "8" Or $Read = "9" Then
                $Read = GUICtrlRead ( $Hours )
                GUICtrlSetData ( $Hours, "0" & $Read )
            EndIf
            $Read = GUICtrlRead ( $Hours )
            GUICtrlSetData ( $Hours2, $Read )
            GUICtrlSetData ( $InformationLabel, $Read & ":" & $ReadMinutes )
        EndIf
        If $Read3 <> $Read4 Then
            If $Read3 > 59 Then 
                GUICtrlSetData ( $Minutes, "59" )
            ElseIf $Read3 = "" Then
                GUICtrlSetData ( $Minutes, "00" )
            ElseIf $Read3 = "0" Or $Read3 = "1" Or $Read3 = "2" Or $Read3 = "3" Or $Read3 = "4" Or $Read3 = "5" Or $Read3 = "6" Or $Read3 = "7" Or $Read3 = "8" Or $Read3 = "9" Then
                $Read3 = GUICtrlRead ( $Minutes )
                GUICtrlSetData ( $Minutes, "0" & $Read3 )
            EndIf
            $Read3 = GUICtrlRead ( $Minutes )
            GUICtrlSetData ( $Minutes2, $Read3 )
            GUICtrlSetData ( $InformationLabel, $ReadHours & ":" & $Read3 )
        EndIf
        $i = 0
    Else
        $i += 1
    EndIf
    #EndRegion
    #Region Repeat
    If GUICtrlRead ( $RepeatMin ) <> GUICtrlRead ( $RepeatMin2 ) Then
        GUICtrlSetData ( $RepeatMin2, GUICtrlRead ( $RepeatMin ) )
    EndIf
    If GUICtrlRead ( $RepeatNum ) <> GUICtrlRead ( $RepeatNum2 ) Then
        GUICtrlSetData ( $RepeatNum2, GUICtrlRead ( $RepeatNum ) )
    EndIf
    If GUICtrlRead ( $RepeatNum ) < 2 Then
        GUICtrlSetState ( $RepeatMin, $GUI_DISABLE )
    Else
        GUICtrlSetState ( $RepeatMin, $GUI_ENABLE )     
    EndIf
    If GUICtrlRead ( $RepeatMin ) < 1 Then
        GUICtrlSetData ( $RepeatMin, 1 )
    EndIf
    If GUICtrlRead ( $RepeatNum ) < 1 Then
        GUICtrlSetData ( $RepeatNum, 1 )
    EndIf
    If GUICtrlRead ( $RepeatMin ) = 1 Then
        GUICtrlSetData ( $MLabel, " minute for" )
    Else
        GUICtrlSetData ( $MLabel, " minutes for" )
    EndIf
    If GUICtrlRead ( $RepeatNum ) = 1 Then
        GUICtrlSetData ( $TLabel, "time." )
    Else
        GUICtrlSetData ( $TLabel, "times." )
    EndIf
    #EndRegion
    #Region IniWrite
    IniWrite ( $IniDirectory, "Time", "Hours", GUICtrlRead ( $Hours ) )
    IniWrite ( $IniDirectory, "Time", "Minutes", GUICtrlRead ( $Minutes ) )
    IniWrite ( $IniDirectory, "File", "Name", GUICtrlRead ( $File ) )
    IniWrite ( $IniDirectory, "File", "Path", GUICtrlRead ( $FileFullPath ) )
    IniWrite ( $IniDirectory, "Days", "Mon", GUICtrlRead ( $Mon ) )
    IniWrite ( $IniDirectory, "Days", "Tue", GUICtrlRead ( $Tue ) )
    IniWrite ( $IniDirectory, "Days", "Wed", GUICtrlRead ( $Wed ) )
    IniWrite ( $IniDirectory, "Days", "Thu", GUICtrlRead ( $Thu ) )
    IniWrite ( $IniDirectory, "Days", "Fri", GUICtrlRead ( $Fri ) )
    IniWrite ( $IniDirectory, "Days", "Sat", GUICtrlRead ( $Sat ) )
    IniWrite ( $IniDirectory, "Days", "Sun", GUICtrlRead ( $Sun ) )
    IniWrite ( $IniDirectory, "Repeat", "Minutes", GUICtrlRead ( $RepeatMin ) )
    IniWrite ( $IniDirectory, "Repeat", "Times", GUICtrlRead ( $RepeatNum ) )
    IniWrite ( $IniDirectory, "Options", "Startup", GUICtrlRead ( $SWW ) )
    IniWrite ( $IniDirectory, "Options", "Reminder", GUICtrlRead ( $POP ) )
    IniWrite ( $IniDirectory, "Volume", "Checkbox", GUICtrlRead ( $VolumeCheckbox ) )
    IniWrite ( $IniDirectory, "Volume", "Slider", GUICtrlRead ( $VolumeSlider ) )
    IniWrite ( $IniDirectory, "Snooze", "Time", GUICtrlRead ( $SnoozeCombo ) )
    #EndRegion
EndFunc

Func AlarmCheck()
    If @HOUR = GUICtrlRead ( $Hours ) And @MIN = GUICtrlRead ( $Minutes ) Then
        If @WDAY = 1 And GUICtrlRead ( $Sun ) = $GUI_CHECKED Then
            Alarm()
        EndIf
        If  @WDAY = 2 And GUICtrlRead ( $Mon ) = $GUI_CHECKED Then
            Alarm()
        EndIf
        If  @WDAY = 3 And GUICtrlRead ( $Tue ) = $GUI_CHECKED Then
            Alarm()
        EndIf
        If  @WDAY = 4 And GUICtrlRead ( $Wed ) = $GUI_CHECKED Then
            Alarm()
        EndIf
        If  @WDAY = 5 And GUICtrlRead ( $Thu ) = $GUI_CHECKED Then
            Alarm()
        EndIf
        If  @WDAY = 6 And GUICtrlRead ( $Fri ) = $GUI_CHECKED Then
            Alarm()
        EndIf
        If  @WDAY = 7 And GUICtrlRead ( $Sat ) = $GUI_CHECKED Then
            Alarm()
        EndIf
    EndIf
EndFunc

Func Alarm()
    If Not WinExists ( "Wake up!" ) Then
        HotKeySet ( "{SPACE}", "Snoozer" )
        HotKeySet ( "{ENTER}", "Stop" )
        GUISetState ( $Title, @SW_HIDE )
        Global $AlarmGUI = GUICreate ( "Wake up!", 420, 70, -1, -1, $DS_SETFOREGROUND )
        GUISetStyle ( $WS_POPUPWINDOW, $WS_EX_TOPMOST )
        GUISetState ( @SW_SHOW, $AlarmGUI )
        Global $AlarmLabel = GUICtrlCreateLabel ( "Press Space to snooze the alarm and Enter to stop and return.", 0, 10, 420, 20, $SS_CENTER )
        Global $DAlarmLabel = GUICtrlCreateLabel ( GUICtrlRead ( $RepeatMin ), 0, 40, 420, 20, $SS_CENTER )
        Global $DTimesLabel = GUICtrlCreateLabel ( GUICtrlRead ( $RepeatNum ), 0, 40, 30, 20, $SS_CENTER )
        WinSetOnTop ( "Wake up!", "", 1 )
        Do
            $Read = GUICtrlRead ( $FileFullPath )
            Global $Song = _SoundOpen ( $Read )
            _SoundPlay ( $Song, 0 )
            Do 
                If $p = 120 Then
                    $Reader = GUICtrlRead ( $DAlarmLabel )
                    GUICtrlSetData ( $DAlarmLabel, $Reader - 1 )
                    $p = 0
                Else
                    Sleep ( 500 )
                    $p += 1
                EndIf
            Until GUICtrlRead ( $DAlarmLabel ) = 0
        Until GUICtrlRead ( $DTimesLabel ) = 0
    EndIf
EndFunc

Func Snoozer()
    
EndFunc

Func Stop()
    HotKeySet ( "{ENTER}" )
    _SoundStop ( $Song )
    GUIDelete ( $AlarmGUI )
    GUICtrlSetData ( $SetAlarm, "Set alarm" )
    GUISetState ( @SW_SHOW, $GUI )
EndFunc

Func exitprog()
    Exit
EndFunc

Edit: NOTE that an ini file will be created in the my documents dir (AlarmClock.ini)

Edited by Rawox

Share this post


Link to post
Share on other sites



Rawox,

You were reopening the sound file each time the alarm repeated.

Do
            $Read = GUICtrlRead ( $FileFullPath )
            Global $Song = _SoundOpen ( $Read )   ;  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            _SoundPlay ( $Song, 0 )
            Do 
                If $p = 120 Then
                    $Reader = GUICtrlRead ( $DAlarmLabel )
                    GUICtrlSetData ( $DAlarmLabel, $Reader - 1 )
                    $p = 0
                Else
                    Sleep ( 500 )
                    $p += 1
                EndIf
            Until GUICtrlRead ( $DAlarmLabel ) = 0
        Until GUICtrlRead ( $DTimesLabel ) = 0

I have removed the _SoundOpen line from there and put it where you read the ini file. I have also added some code to reset the active Soundfile when you choose a new one. Look for the <<<<<<<<<<<<<<<<<<<<<<<<<<<< lines. It all seems to work now.

#include <ComboConstants.au3>
#include <Date.au3>
#include <EditConstants.au3>
#Include <File.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <Sound.au3>
#include <WindowsConstants.au3>

Opt ( "GUIResizeMode", 802 )
AdlibEnable ( "Updater", 800 )

Global $AlarmGUI
Global $Song

$Title = "AlarmClock"
$IniDirectory = @ScriptDir & "\AlarmClock.ini"
$i = 0
$x = 0
$n = 0
$q = 0
$w = 0
$p = 0

;;;;;;;;;;;; TO DO ;;;;;;;;;;;;;;
; SNOOZER!                      ;
; Working alarm                 ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

$GUI = GUICreate ( $Title, 360, 345 ) ;65 ;345
#Region Options ///////////////////////////////////////////////////////////////////////////////////////////#
GUICtrlCreateGroup ( "Time", 10, 70, 150, 48 )
GUICtrlCreateLabel ( "Play alarm at:", 23, 90 )
GUICtrlCreateLabel ( ":", 116, 90 )
$Hours = GUICtrlCreateInput ( "07", 95, 88, 20, 20, $ES_NUMBER )
$Minutes = GUICtrlCreateInput ( "30", 120, 88, 20, 20, $ES_NUMBER )
GUICtrlSetLimit ( $Hours, 2, 2 )
GUICtrlSetLimit ( $Minutes, 2, 2 )
GUICtrlSetTip ( $Hours, "Select a number in a range from 00 to 23.", "Hours", 1, 2 )
GUICtrlSetTip ( $Minutes, "Select a number in a range from 00 to 59.", "Minutes", 1, 2 )
GUICtrlCreateGroup ( "Alarm", 170, 70, 180, 48 )
$File = GUICtrlCreateInput ( "No file selected!", 183, 88, 100, 20, $ES_READONLY )
GUICtrlSetTip ( $File, GUICtrlRead ( $File ) )
$Browse = GUICtrlCreateButton ( "Browse", 285, 87, 50, 21 )
GUICtrlSetColor ( $File, 0xFF0000 )
GUICtrlCreateGroup ( "Days", 10, 128, 340, 48 )
$Mon = GUICtrlCreateCheckbox ( "Mon", 23, 146 )
$Tue = GUICtrlCreateCheckbox ( "Tue", 23*2+23, 146 )
$Wed = GUICtrlCreateCheckbox ( "Wed", 23*3+23*2, 146 )
$Thu = GUICtrlCreateCheckbox ( "Thu", 23*4+23*3, 146 )
$Fri = GUICtrlCreateCheckbox ( "Fri", 23*5+23*4, 146 )
$Sat = GUICtrlCreateCheckbox ( "Sat", 23*6+23*5, 146 )
$Sun = GUICtrlCreateCheckbox ( "Sun", 23*7+23*6, 146 )
GUICtrlCreateGroup ( "Repeat", 10, 185, 255, 48 )
GUICtrlCreateLabel ( "Repeat alarm every", 23, 205 )
$RepeatMin = GUICtrlCreateInput ( "5", 120, 203, 20, 20 )
GUICtrlSetLimit ( $RepeatMin, 2 )
$MLabel = GUICtrlCreateLabel ( " minutes for", 145, 205 )
$RepeatNum = GUICtrlCreateInput ( "10", 202, 203, 20, 20 )
GUICtrlSetLimit ( $RepeatNum, 2 )
$TLabel = GUICtrlCreateLabel ( "times.", 226, 205 )
$SetAlarm = GUICtrlCreateButton ( "Set alarm", 270, 191, 80, 41 )
$SWW = GUICtrlCreateCheckbox ( "Start with Windows", 20, 238 )
$POP = GUICtrlCreateCheckbox ( "Reminder when shutting down Windows", 140, 238 )
GUICtrlCreateGroup ( "Volume", 10, 263, 200, 70 )
$VolumeSlider = GUICtrlCreateSlider ( 23, 305, 200-23*2+15, 20 )
$VolumeCheckbox = GUICtrlCreateCheckBox ( "Adjust volume to " & GUICtrlRead ( $VolumeSlider ) & " percent.", 25, 280, 180 )
GUICtrlCreateGroup ( "Snoozer", 220, 263, 130, 70 )
$SnoozeCombo = GUICtrlCreateCombo ( "1 minute", 233, 300, 100, 20, $CBS_DROPDOWNLIST )
GUICtrlSetData ( $SnoozeCombo, "2 minutes|3 minutes|4 minutes|5 minutes|6 minutes|7 minutes|8 minutes|9 minutes|10 minutes|30 minutes|60 minutes" )
GUICtrlCreateLabel ( "Snooze for", 233, 280, 70, 13 )
$SnoozeLabel = GUICtrlCreateLabel ( GUICtrlRead ( $SnoozeCombo ), 286, 280, 60, 12 )
#EndRegion
#Region Dummy //////////////////////////////////////////////////////////////////////////////////////////////#
$Hours2 = GUICtrlCreateLabel ( GUICtrlRead ( $Hours ), 10, 375 )
$Minutes2 = GUICtrlCreateLabel ( GUICtrlRead ( $Minutes ), 30, 375 )
$FileFullPath = GUICtrlCreateLabel ( GUICtrlRead ( $File ), 10, 395, 300, 30 )
$RepeatMin2 = GUICtrlCreateLabel ( GUICtrlRead ( $RepeatMin ), 10, 425 )
$RepeatNum2 = GUICtrlCreateLabel ( GUICtrlRead ( $RepeatNum ), 30, 425 )
#EndRegion
#Region Changes from Ini ///////////////////////////////////////////////////////////////////////////////////#
GUICtrlSetData ( $Hours, IniRead ( $IniDirectory, "Time", "Hours", "07" ) )
GUICtrlSetData ( $Minutes, IniRead ( $IniDirectory, "Time", "Minutes", "30" ) )
GUICtrlSetData ( $File, IniRead ( $IniDirectory, "File", "Name", "No file selected!" ) )
If IniRead ( $IniDirectory, "File", "Name", "No file selected!" ) = "No file selected!" Then
    GUICtrlSetColor ( $File, 0xFF0000 )
Else
    GUICtrlSetColor ( $File, 0x000000 )
    $Song = _SoundOpen ( IniRead ( $IniDirectory, "File", "Path", "" ))  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
EndIf
Sleep ( 10 )
GUICtrlSetData ( $FileFullPath, IniRead ( $IniDirectory, "File", "Path", "No file selected!" ) )
GUICtrlSetState ( $Mon, IniRead ( $IniDirectory, "Days", "Mon", 1 ) )
GUICtrlSetState ( $Tue, IniRead ( $IniDirectory, "Days", "Tue", 1 ) )
GUICtrlSetState ( $Wed, IniRead ( $IniDirectory, "Days", "Wed", 1 ) )
GUICtrlSetState ( $Thu, IniRead ( $IniDirectory, "Days", "Thu", 1 ) )
GUICtrlSetState ( $Fri, IniRead ( $IniDirectory, "Days", "Fri", 1 ) )
GUICtrlSetState ( $Sat, IniRead ( $IniDirectory, "Days", "Sat", 4 ) )
GUICtrlSetState ( $Sun, IniRead ( $IniDirectory, "Days", "Sun", 4 ) )
GUICtrlSetData ( $RepeatMin, IniRead ( $IniDirectory, "Repeat", "Minutes", "5" ) )
GUICtrlSetData ( $RepeatNum, IniRead ( $IniDirectory, "Repeat", "Times", "3" ) )
GUICtrlSetState ( $SWW, IniRead ( $IniDirectory, "Options", "Startup", 1 ) )
GUICtrlSetState ( $POP, IniRead ( $IniDirectory, "Options", "Reminder", 1 ) )
GUICtrlSetState ( $VolumeCheckbox, IniRead ( $IniDirectory, "Volume", "Checkbox", 1 ) )
GUICtrlSetData ( $VolumeSlider, IniRead ( $IniDirectory, "Volume", "Slider", 50 ) )
GUICtrlSetData ( $SnoozeCombo, IniRead ( $IniDirectory, "Snooze", "Time", "5 minutes" ) )
#EndRegion
#Region Base //////////////////////////////////////////////////////////////////////////////////////////////#
$ReadHours = GUICtrlRead ( $Hours )
$ReadMinutes = GUICtrlRead ( $Minutes )
GUICtrlCreateLabel ( "Alarm at:", 10, 10, 340, 25, $SS_CENTER )
$InformationLabel = GUICtrlCreateLabel ( $ReadHours & ":" & $ReadMinutes, 60, 23, 240, 30, $SS_CENTER )
$WinPos = WinGetPos ( $Title )
If $WinPos[3] = 91 Then
    $SettingsLabel = GUICtrlCreateLabel ( "Show Settings", 260, 41, 80, 15, $SS_RIGHT )
Else
    $SettingsLabel = GUICtrlCreateLabel ( "Hide Settings", 260, 41, 80, 15, $SS_RIGHT )
EndIf
GUICtrlSetFont ( $InformationLabel, 24, 400, "Arial" )
GUICtrlSetColor ( $SettingsLabel, 0xC0C0C0 )
GUICtrlSetCursor( $SettingsLabel, 0 )
#EndRegion
GUICtrlSetState ( $FileFullPath, $GUI_FOCUS )
Updater()
GUISetState ( @SW_SHOW )

While 1
    Switch GUIGetMsg()
    Case $SetAlarm
        If GUICtrlRead ( $File ) = "No file selected!" Then
            MsgBox ( 48, $Title, "You haven't selected an alarm!" )
        Else
            If GUICtrlRead ( $SetAlarm ) = "Set alarm" Then
                GUICtrlSetData ( $SetAlarm, "Clear Alarm" )
            ElseIf GUICtrlRead ( $SetAlarm ) = "Clear alarm" Then
                GUICtrlSetData ( $SetAlarm, "Set Alarm" )
            EndIf
        EndIf
    Case $GUI_EVENT_CLOSE
        Exit
    Case $SettingsLabel
        $Size = WinGetClientSize ( $Title )
        If $Size[1] = 65 Then
            GUICtrlSetData ( $SettingsLabel, "Hide Settings" )
            $Pos = WinGetPos ( $Title )
            WinMove ( $Title, "", $Pos[0], $Pos[1]-140, $Pos[2], $Pos[3]+280 )
        Else
            GUICtrlSetData ( $SettingsLabel, "Show Settings" )
            $Pos = WinGetPos ( $Title )
            WinMove ( $Title, "", $Pos[0], $Pos[1]+140, $Pos[2], $Pos[3]-280 )
        EndIf
    Case $Browse
        $SoundFile = FileOpenDialog ( "Select alarm", "", "MP3 files (*.mp3)|WAV files (*.wav)|MID files (*.mid)", 3 )

        If @error <> 1 Then

            ; Clear current selection   <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            GUICtrlSetData ( $FileFullPath, $SoundFile )
            _SoundClose($Song)
            ; Open new song
            $Song = _SoundOpen ( $SoundFile ) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

            GUICtrlSetColor ( $File, 0x000000 )
            Dim $szDrive, $szDir, $szFName, $szExt
            _PathSplit ( $SoundFile, $szDrive, $szDir, $szFName, $szExt )
            GUICtrlSetData ( $File, $szFName & $szExt )
            GUICtrlSetData ( $FileFullPath, $SoundFile )
            GUICtrlSetTip ( $File, GUICtrlRead ( $File ) )
            GUICtrlSetState ( $MLabel, $GUI_FOCUS )
        EndIf
    EndSwitch
WEnd

Func Updater()
    #Region Alarm
    If GUICtrlRead ( $SetAlarm ) = "Clear Alarm" Then
        AlarmCheck()
    EndIf
    #EndRegion
    #Region Snoozer
    If GUICtrlRead ( $SnoozeCombo ) <> GUICtrlRead ( $SnoozeLabel ) Then
        GUICtrlSetData ( $SnoozeLabel, GUICtrlRead ( $SnoozeCombo ) )
    EndIf
    #EndRegion
    #Region Volume
    If GUICtrlRead ( $VolumeCheckbox ) = $GUI_CHECKED Then
        GUICtrlSetState ( $VolumeSlider, $GUI_ENABLE )
    Else
        GUICtrlSetState ( $VolumeSlider, $GUI_DISABLE )
    EndIf
    GUICtrlSetData ( $VolumeCheckbox, "Adjust volume to " & GUICtrlRead ( $VolumeSlider ) & " percent." )
    #EndRegion
    #Region Filename
    If GUICtrlRead ( $File ) = "" Then
        GUICtrlSetData ( $File, "No file selected!" )
        GUICtrlSetColor ( $File, 0xFF0000 )
    ElseIf GUICtrlRead ( $File ) = "No file selected!" Then
        GUICtrlSetColor ( $File, 0xFF0000 )
    ElseIf $x = 2 Then
        GUICtrlSetColor ( $File, 0x000000 )
    Else
        $x +=1
    EndIf
    #EndRegion
    #Region Time
    If $i = 2 Then
        $ReadHours = GUICtrlRead ( $Hours )
        $ReadMinutes = GUICtrlRead ( $Minutes )
        $Read = GUICtrlRead ( $Hours )
        $Read2 = GUICtrlRead ( $Hours2 )
        $Read3 = GUICtrlRead ( $Minutes )
        $Read4 = GUICtrlRead ( $Minutes2 )
        If $Read <> $Read2 Then
            If $Read > 23 Then
                GUICtrlSetData ( $Hours, "23" )
            ElseIf $Read = "" Then
                GUICtrlSetData ( $Hours, "00" )
            ElseIf $Read = "0" Or $Read = "1" Or $Read = "2" Or $Read = "3" Or $Read = "4" Or $Read = "5" Or $Read = "6" Or $Read = "7" Or $Read = "8" Or $Read = "9" Then
                $Read = GUICtrlRead ( $Hours )
                GUICtrlSetData ( $Hours, "0" & $Read )
            EndIf
            $Read = GUICtrlRead ( $Hours )
            GUICtrlSetData ( $Hours2, $Read )
            GUICtrlSetData ( $InformationLabel, $Read & ":" & $ReadMinutes )
        EndIf
        If $Read3 <> $Read4 Then
            If $Read3 > 59 Then
                GUICtrlSetData ( $Minutes, "59" )
            ElseIf $Read3 = "" Then
                GUICtrlSetData ( $Minutes, "00" )
            ElseIf $Read3 = "0" Or $Read3 = "1" Or $Read3 = "2" Or $Read3 = "3" Or $Read3 = "4" Or $Read3 = "5" Or $Read3 = "6" Or $Read3 = "7" Or $Read3 = "8" Or $Read3 = "9" Then
                $Read3 = GUICtrlRead ( $Minutes )
                GUICtrlSetData ( $Minutes, "0" & $Read3 )
            EndIf
            $Read3 = GUICtrlRead ( $Minutes )
            GUICtrlSetData ( $Minutes2, $Read3 )
            GUICtrlSetData ( $InformationLabel, $ReadHours & ":" & $Read3 )
        EndIf
        $i = 0
    Else
        $i += 1
    EndIf
    #EndRegion
    #Region Repeat
    If GUICtrlRead ( $RepeatMin ) <> GUICtrlRead ( $RepeatMin2 ) Then
        GUICtrlSetData ( $RepeatMin2, GUICtrlRead ( $RepeatMin ) )
    EndIf
    If GUICtrlRead ( $RepeatNum ) <> GUICtrlRead ( $RepeatNum2 ) Then
        GUICtrlSetData ( $RepeatNum2, GUICtrlRead ( $RepeatNum ) )
    EndIf
    If GUICtrlRead ( $RepeatNum ) < 2 Then
        GUICtrlSetState ( $RepeatMin, $GUI_DISABLE )
    Else
        GUICtrlSetState ( $RepeatMin, $GUI_ENABLE )
    EndIf
    If GUICtrlRead ( $RepeatMin ) < 1 Then
        GUICtrlSetData ( $RepeatMin, 1 )
    EndIf
    If GUICtrlRead ( $RepeatNum ) < 1 Then
        GUICtrlSetData ( $RepeatNum, 1 )
    EndIf
    If GUICtrlRead ( $RepeatMin ) = 1 Then
        GUICtrlSetData ( $MLabel, " minute for" )
    Else
        GUICtrlSetData ( $MLabel, " minutes for" )
    EndIf
    If GUICtrlRead ( $RepeatNum ) = 1 Then
        GUICtrlSetData ( $TLabel, "time." )
    Else
        GUICtrlSetData ( $TLabel, "times." )
    EndIf
    #EndRegion
    #Region IniWrite
    IniWrite ( $IniDirectory, "Time", "Hours", GUICtrlRead ( $Hours ) )
    IniWrite ( $IniDirectory, "Time", "Minutes", GUICtrlRead ( $Minutes ) )
    IniWrite ( $IniDirectory, "File", "Name", GUICtrlRead ( $File ) )
    IniWrite ( $IniDirectory, "File", "Path", GUICtrlRead ( $FileFullPath ) )
    IniWrite ( $IniDirectory, "Days", "Mon", GUICtrlRead ( $Mon ) )
    IniWrite ( $IniDirectory, "Days", "Tue", GUICtrlRead ( $Tue ) )
    IniWrite ( $IniDirectory, "Days", "Wed", GUICtrlRead ( $Wed ) )
    IniWrite ( $IniDirectory, "Days", "Thu", GUICtrlRead ( $Thu ) )
    IniWrite ( $IniDirectory, "Days", "Fri", GUICtrlRead ( $Fri ) )
    IniWrite ( $IniDirectory, "Days", "Sat", GUICtrlRead ( $Sat ) )
    IniWrite ( $IniDirectory, "Days", "Sun", GUICtrlRead ( $Sun ) )
    IniWrite ( $IniDirectory, "Repeat", "Minutes", GUICtrlRead ( $RepeatMin ) )
    IniWrite ( $IniDirectory, "Repeat", "Times", GUICtrlRead ( $RepeatNum ) )
    IniWrite ( $IniDirectory, "Options", "Startup", GUICtrlRead ( $SWW ) )
    IniWrite ( $IniDirectory, "Options", "Reminder", GUICtrlRead ( $POP ) )
    IniWrite ( $IniDirectory, "Volume", "Checkbox", GUICtrlRead ( $VolumeCheckbox ) )
    IniWrite ( $IniDirectory, "Volume", "Slider", GUICtrlRead ( $VolumeSlider ) )
    IniWrite ( $IniDirectory, "Snooze", "Time", GUICtrlRead ( $SnoozeCombo ) )
    #EndRegion
EndFunc

Func AlarmCheck()
    If @HOUR = GUICtrlRead ( $Hours ) And @MIN = GUICtrlRead ( $Minutes ) Then
        If @WDAY = 1 And GUICtrlRead ( $Sun ) = $GUI_CHECKED Then
            Alarm()
        EndIf
        If  @WDAY = 2 And GUICtrlRead ( $Mon ) = $GUI_CHECKED Then
            Alarm()
        EndIf
        If  @WDAY = 3 And GUICtrlRead ( $Tue ) = $GUI_CHECKED Then
            Alarm()
        EndIf
        If  @WDAY = 4 And GUICtrlRead ( $Wed ) = $GUI_CHECKED Then
            Alarm()
        EndIf
        If  @WDAY = 5 And GUICtrlRead ( $Thu ) = $GUI_CHECKED Then
            Alarm()
        EndIf
        If  @WDAY = 6 And GUICtrlRead ( $Fri ) = $GUI_CHECKED Then
            Alarm()
        EndIf
        If  @WDAY = 7 And GUICtrlRead ( $Sat ) = $GUI_CHECKED Then
            Alarm()
        EndIf
    EndIf
EndFunc

Func Alarm()
    If Not WinExists ( "Wake up!" ) Then
        HotKeySet ( "{SPACE}", "Snoozer" )
        HotKeySet ( "{ENTER}", "Stop" )
        GUISetState ( $Title, @SW_HIDE )
        $AlarmGUI = GUICreate ( "Wake up!", 420, 170, -1, -1, $DS_SETFOREGROUND )  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        GUISetStyle ( $WS_POPUPWINDOW, $WS_EX_TOPMOST )
        GUISetState ( @SW_SHOW, $AlarmGUI )
        Global $AlarmLabel = GUICtrlCreateLabel ( "Press Space to snooze the alarm and Enter to stop and return.", 0, 10, 420, 20, $SS_CENTER )
        Global $DAlarmLabel = GUICtrlCreateLabel ( GUICtrlRead ( $RepeatMin ), 0, 40, 420, 20, $SS_CENTER )
        Global $DTimesLabel = GUICtrlCreateLabel ( GUICtrlRead ( $RepeatNum ), 0, 40, 30, 20, $SS_CENTER )
        WinSetOnTop ( "Wake up!", "", 1 )
        Do
            $Read = GUICtrlRead ( $FileFullPath )
            _SoundPlay ( $Song, 0 )
            Do
                If $p = 120 Then
                    $Reader = GUICtrlRead ( $DAlarmLabel )
                    GUICtrlSetData ( $DAlarmLabel, $Reader - 1 )
                    $p = 0
                Else
                    Sleep ( 500 )
                    $p += 1
                EndIf
            Until GUICtrlRead ( $DAlarmLabel ) = 0
        Until GUICtrlRead ( $DTimesLabel ) = 0
    EndIf
EndFunc

Func Snoozer()

EndFunc

Func Stop()
    HotKeySet ( "{ENTER}" )
    _SoundStop ( $Song )
    GUIDelete ( $AlarmGUI )
    GUICtrlSetData ( $SetAlarm, "Set alarm" )
    GUISetState ( @SW_SHOW, $GUI )
EndFunc

Func exitprog()
    Exit
EndFunc

A couple of suggestions:

1. Your script traps the Space and Enter keys while waiting for the repeat alarms which means they cannot be used while waiting. If I am ignoring the alarm, it might be because I need to finish something. Perhaps release the keys until the timer runs again?

2. The inputs for setting the alarm time are quite small - why not use the big ones at the top directly? You might also think of using Updowns to help here.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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  
Followers 0