#region 

#NoTrayIcon
#include <GUIConstants.au3>
#include <File.au3>

Dim $Song
Dim $szDrive, $szDir, $szFName, $szExt
Dim $Abtast
Dim $Samp
Dim $Kanal
Dim $Bytes
Dim $Alignment
Dim $AktStatus

Func mciSendString($string)
	Local $iRet
	$iRet = DllCall("winmm.dll", "int", "mciSendStringA", "str", $string, "str", "", "int", 65534, "hwnd", 0)
	If Not @error Then Return $iRet[2]
EndFunc

Func RandomStr($len)
	Local $string
	For $iCurrentPos = 1 To $len
		$string &= Chr(Random(97, 122, 1))
	Next
	Return $string
EndFunc


$AktStatus = "Bereit"

$GUI = GUICreate("My Sound-Recorder",490,120)
$Title = GUICtrlCreateLabel("Sound-Recorder-Setting: ", 20, 10, 200, 20)
GUICtrlSetFont($Title, 10, 600, 4)
$Abtastung1 = GUICtrlCreateLabel("Abtastung: ", 20, 40, 60, 20)
$Abtastung2 = GUICtrlCreateCombo("", 85, 40, 70, 200)
GUICtrlSetData($Abtastung2, "8 -bit|16 -bit","16 -bit") 
$Samplerate1 = GUICtrlCreateLabel("Samplerate: ", 180, 40, 60, 20)
$Samplerate2 = GUICtrlCreateCombo("", 245, 40, 70, 200)
GUICtrlSetData($Samplerate2, "11025 Hz|22050 Hz|44100 Hz|48000 Hz","44100 Hz")
$Channels1 = GUICtrlCreateLabel("Channels: ", 340, 40, 60, 20)
$Channels2 = GUICtrlCreateCombo("", 395, 40, 70, 200)
GUICtrlSetData($Channels2, "Mono|Stereo|Surround","Stereo")
$Status1 = GUICtrlCreateLabel("Status: ", 280, 80, 100, 20)
GUICtrlSetFont($Status1, 10, 600)
$Status2 = GUICtrlCreateLabel($AktStatus, 340, 80, 120, 20)
GUICtrlSetFont($Status2, 10, 400, 2)
GUICtrlSetColor($Status2, 0x008200)
$Record = GUICtrlCreateButton("Record", 40, 80, 70, 20)
$Stop = GUICtrlCreateButton("Stop", 140, 80, 70, 20)


GUISetState (@SW_SHOW)

While 1


$msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
			
		Case $msg = $Record
			If GUICtrlRead($Abtastung2) = "16 -bit" Then
				$Abtast = "16"
			EndIf
			If GUICtrlRead($Abtastung2) = "8 -bit" Then
				$Abtast = "8"
			EndIf
			If GUICtrlRead($Samplerate2) = "11025 Hz" Then
				$Samp = "11025"
			EndIf
			If GUICtrlRead($Samplerate2) = "22050 Hz" Then
				$Samp = "22050"
			EndIf
			If GUICtrlRead($Samplerate2) = "44100 Hz" Then
				$Samp = "44100"
			EndIf
			If GUICtrlRead($Samplerate2) = "48000 Hz" Then
				$Samp = "48000"
			EndIf
			If GUICtrlRead($Channels2) = "Mono" Then
				$Kanal = "1"
			EndIf
			If GUICtrlRead($Channels2) = "Stereo" Then
				$Kanal = "2"
			EndIf
			If GUICtrlRead($Channels2) = "Surround" Then
				$Kanal = "4"
			EndIf
			
			$Bytes = $Abtast / 8 * $Kanal * $Samp
			$Alignment = $Kanal * $Abtast / 8
			
			$Song = FileSaveDialog("Speichere deinen Song!", @WorkingDir, "Musik (*.wav)", 2)
			GUICtrlSetData($Status2, "Recording...")
			GUICtrlSetColor($Status2, 0xFF0000)
			mciSendString("open new type waveaudio alias mysound")
			mciSendString("set mysound time format ms bitspersample " & $Abtast & " channels " & $Kanal & " samplespersec " & $Samp & " BYTESPERSEC " & $Bytes & " ALIGNMENT " & $Alignment)
			mciSendString("break mysound on 27")
			mciSendString("record mysound")
			
		Case $msg = $Stop
			mciSendString("save mysound mysound.wav")
			mciSendString("close mysound")
			FileCopy("mysound.wav", $Song, 1)
			GUICtrlSetData($Status2, "Bereit")
			GUICtrlSetColor($Status2, 0x008200)
			
			
	EndSelect
WEnd
Exit

#endregion
    
