Jump to content

Recommended Posts

  • Moderators
Posted

DrJeseuss,

As I said earlier I went for trancexx's MailSlot UDF. :D

The forum is not allowing me to upload files at the moment so here are the 2 .au3 files I used:

- Master.au3:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include "MailSlot.au3"

; Create the .a3x file from the one stored within this one
FileInstall("M:\Program\Au3 Scripts\Forum Help Scripts\Halloween\Child.a3x", @ScriptDir & "\Sound.a3x", 1)

Global $sMailSlotListFile = @ScriptDir & "\MailSlotList.lst"

; Start the high file
$sID = "HIGH"
$sPath = '"' & @ScriptDir & '\High.wav"'
$iVolume_HIGH = 20

Run('"' & @ScriptFullPath & '" /AutoIt3ExecuteScript Sound.a3x ' & $sID & " " & $sPath & " " & $iVolume_HIGH & ' "')

Sleep(500)

; Start the low file
$sID = "LOW"
$sPath = '"' & @ScriptDir & '\Low.wav"'
$iVolume_LOW = 100

Run('"' & @ScriptFullPath & '" /AutoIt3ExecuteScript Sound.a3x ' & $sID & " " & $sPath & " " & $iVolume_LOW & ' "')

; Now change the volume as we go along
$iBegin = TimerInit()
While 1
    Sleep(10)

    If TimerDiff($iBegin) > 5000 Then

        ; Change the volume of the HIGH file
        $iVolume_HIGH += 20
        If $iVolume_HIGH = 120 Then
            ; Stop when we get over 100
            $sMailSlotName = "\\.\mailslot\" & IniRead($sMailSlotListFile, "MailSlots", "HIGH_Child", "")
            _MailSlotWrite($sMailSlotName, "-99")
        Else
            $sMailSlotName = "\\.\mailslot\" & IniRead($sMailSlotListFile, "MailSlots", "HIGH_Child", "")
            _MailSlotWrite($sMailSlotName, String($iVolume_HIGH))
        EndIf

        ; And now for the low file
        $iVolume_LOW -= 20
        If $iVolume_LOW = 0 Then
            $sMailSlotName = "\\.\mailslot\" & IniRead($sMailSlotListFile, "MailSlots", "LOW_Child", "")
            _MailSlotWrite($sMailSlotName, "-99")
            MsgBox(0, "Master", "Exiting")
            FileDelete(@ScriptDir & "\Sound.a3x")
        Else
            $sMailSlotName = "\\.\mailslot\" & IniRead($sMailSlotListFile, "MailSlots", "LOW_Child", "")
            _MailSlotWrite($sMailSlotName, String($iVolume_LOW))
        EndIf

        $iBegin = TimerInit()
    EndIf

WEnd

And Child.au3:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile_type=a3x
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <Sound.au3>
#include "MailSlot.au3"

; Read the command line parameters
$sID = $CmdLine[1]
$aSndID = _SoundOpen($CmdLine[2])
SoundSetWaveVolume($CmdLine[3])
$iVolume = $CmdLine[3]
_SoundPlay($aSndId)

; Create the Mailslot
Global $sMailSlotListFile = @ScriptDir & "\MailSlotList.lst"
Global $sMailSlotTitle = $sID & "_Child"
Global $sRandomMailSlotname = _RandomStr()
Global Const $sMailSlotName_Receive = "\\.\mailslot\" & $sRandomMailSlotname
Global $hMailSlot = _MailSlotCreate($sMailSlotName_Receive)
If @error Then
    MsgBox(48, "MailSlot for " & $sID, "Failed to create account!")
    Exit
EndIf
; Add to the master list
IniWrite($sMailSlotListFile, "MailSlots", $sMailSlotTitle, $sRandomMailSlotname)

While 1

    ; Loop the sound if required
    If _SoundStatus($aSndId) = "stopped" Then
        _SoundPlay($aSndId)
    EndIf

    ; Is there a message?
    Local $iSize = _MailSlotCheckForNextMessage($hMailSlot)
    If $iSize Then
        ; If so then read it
        Local $iVol = Number(_MailSlotRead($hMailSlot, $iSize, 1))
        ; Is it a shutdown request
        If $iVol = -99 Then
            _SoundClose($aSndID)
            Exit
        Else
            ; Set the volume
            If $iVol <> $iVolume Then
                $iVolume = $iVol
                SoundSetWaveVolume($iVolume)
            EndIf
        EndIf

    EndIf

    ; Save the CPU
    Sleep(10)

WEnd

Func _RandomStr()
    Local $sString
    For $i = 1 To 13
        $sString &= Chr(Random(97, 122, 1))
    Next
    Return $sString
EndFunc   ;==>__RandomStr

Compile them both and you should get Master.exe and Child.a3x.

I used 2 simple sound files called High.wav and Low.wav - they were each about 10 secs long and played a single high/low note to make it easy to distinguish between them - just create 2 file of your liking, but do call them High/Low.wav. You will also need the MailSlot.au3 UDF in the same folder.

When you execute Master.exe it creates a Sound.a3x file in the folder - that way you only need distribute that one file and not both. It runs 2 instances of the Sound.a3x files, each playing one of the sound files - one loud and one soft. At intervals it alters the volume of the 2 files until the other is louder. It then exists and clears up after itself.

Please ask if you have any questions on the .au3 files - if you have questions on MailSlot then please go and ask trancexx! :oops:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

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
  • Recently Browsing   0 members

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