diff --git a/pro_audio.au3 b/pro_audio.au3 new file mode 100644 index 0000000000000000000000000000000000000000..7f924167406c4c305b067fe198b72065cf734c9d --- /dev/null +++ b/pro_audio.au3 @@ -0,0 +1,251 @@ +#Region ;**** Directives created by AutoIt3Wrapper_GUI **** +#AutoIt3Wrapper_Icon=Icons\wav.ico +#AutoIt3Wrapper_Res_Comment=Converts Audio-Files to 48kHz 24bit. +#AutoIt3Wrapper_Res_Description=Converts Audio-Files to 48kHz 24bit. +#AutoIt3Wrapper_Res_Fileversion=1.0.0.12 +#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y +#AutoIt3Wrapper_Res_LegalCopyright=Conrad Zelck +#AutoIt3Wrapper_Res_Language=1031 +#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** +#include <AutoItConstants.au3> +#include <File.au3> +#include <Array.au3> +#include <TrayCox.au3> +Opt("GuiCoordMode", 0) ;relative position to the start of the last control with "-1" + +Global $bGUI = 1 ; GUI soll angezeigt werden +Global $hEnableGUI = TrayCreateItem("Verstecken", -1, 0) +TrayItemSetOnEvent (-1, "_Hide") +TrayCreateItem("", -1, 1) + +Local $hGUI +Local $sCurTrack, $sCurTrackMinusExt, $sCurTrackNewExt, $sCurTrackName +Local $sOutput, $sOutError, $iPID ; Auslesen STDOUT + STDERR +Local $aOutput, $aBitRate, $iBitRate, $iFaktorFileSize +Local $iOldSize, $iShouldSize, $iTempSize, $iProzent, $iProzentTemp = 0 +Local $aProzent + +FileInstall("H:\_Conrad lokal\Downloads\AutoIt3\_COX\sox\zlib1.dll", @TempDir & "\", 1) +FileInstall("H:\_Conrad lokal\Downloads\AutoIt3\_COX\sox\pthreadgc2.dll", @TempDir & "\", 1) +FileInstall("H:\_Conrad lokal\Downloads\AutoIt3\_COX\sox\libgomp-1.dll", @TempDir & "\", 1) +FileInstall("H:\_Conrad lokal\Downloads\AutoIt3\_COX\sox\libmp3lame.dll", @TempDir & "\", 1) +FileInstall("H:\_Conrad lokal\Downloads\AutoIt3\_COX\sox\libmad.dll", @TempDir & "\", 1) +FileInstall("H:\_Conrad lokal\Downloads\AutoIt3\_COX\sox\sox.exe", @TempDir & "\", 1) + +Local $aCmdLineCopy = $CmdLine +Local $sAttrib +If $CmdLine[0] > 0 Then + For $i = $CmdLine[0] To 1 Step - 1 + $sAttrib = FileGetAttrib($CmdLine[$i]) + If $sAttrib = "" Then ; all parameter not having an attribute are deleted (files and directories stay) + _ArrayDelete($aCmdLineCopy, $i) + EndIf + Next + $aCmdLineCopy[0] = UBound($aCmdLineCopy) - 1 +EndIf + +Local $aOneFolderFileList +Local $aFileList[0] +Local $sChoosenMedia +If $aCmdLineCopy[0] > 0 Then ; if already Files exist + For $i = 1 to $aCmdLineCopy[0] + $sAttrib = FileGetAttrib($aCmdLineCopy[$i]) + If StringInStr($sAttrib, "D") Then + $aOneFolderFileList = _FileListToArrayRec($aCmdLineCopy[$i], "*.*", $FLTAR_FILES + $FLTAR_NOSYSTEM + $FLTAR_NOLINK, $FLTAR_RECUR, $FLTAR_SORT, $FLTAR_FULLPATH) + _ArrayDelete($aOneFolderFileList, 0) ; delete Index + _ArrayAdd($aFileList, $aOneFolderFileList) + Else + _ArrayAdd($aFileList, $aCmdLineCopy[$i]) + EndIf + Next + _ArrayInsert($aFileList, 0, UBound($aFileList)) +Else ; no file in $CmdLine + $hGUI = GUICreate(StringTrimRight(@ScriptName, 4) & " - Auswahl",258,63) + GUISetFont(10) + GUICtrlCreateButton ("Ordner auswählen",10,20,-1,-1,$BS_DEFPUSHBUTTON) + GUICtrlCreateButton ("Dateien auswählen",121,-1) + GUISetState() + Local $msg + While 1 + $msg = GUIGetMsg() + If $msg = $GUI_EVENT_CLOSE Then _Beenden() ; defined at TrayCox.au3 + If $msg = 3 Then ExitLoop + If $msg = 4 Then ExitLoop + WEnd + GUIDelete() + Switch $msg + Case 3 ; choose folder + $sChoosenMedia = FileSelectFolder (StringTrimRight(@ScriptName, 4) & " - Ordner aussuchen", "") + If @error Then + MsgBox(262144,StringTrimRight(@ScriptName, 4) & " - Abbruch","Keine Datei(en) ausgewählt") + Exit + EndIf + $aFileList = _FileListToArrayRec($sChoosenMedia, "*.*", $FLTAR_FILES + $FLTAR_NOSYSTEM + $FLTAR_NOLINK, $FLTAR_RECUR, $FLTAR_SORT, $FLTAR_FULLPATH) + Case 4 ; choose files + $sChoosenMedia = FileOpenDialog(StringTrimRight(@ScriptName, 4),"", "Alle (*.*)","4") + If @error Then + MsgBox(262144,StringTrimRight(@ScriptName, 4) & " - Abbruch","Keine Datei(en) ausgewählt") + Exit + EndIf + $aFileList = StringSplit($sChoosenMedia, "|") + If $aFileList[0] > 1 Then + For $i = 2 To $aFileList[0] + $aFileList[$i] = $aFileList[1] & "\" & $aFileList[$i] + Next + _ArrayDelete($aFileList, 1) + $aFileList[0] = UBound($aFileList) - 1 + EndIf + EndSwitch +EndIf + +If $aFileList[0] <= 0 Then + MsgBox($MB_SYSTEMMODAL + $MB_ICONWARNING, @ScriptName, "Es ist keine zu wandelnde Datei zu finden.") + Exit +EndIf + +Opt("GuiOnEventMode", 1) +Local $iWidthLabel = 400 +$hGUI = GUICreate(StringTrimRight(@ScriptName, 4),$iWidthLabel + 40,150) ; 150 +GUISetFont(10) +GUISetOnEvent($GUI_EVENT_CLOSE, "_Beenden") +Local $hLabelCounter = GUICtrlCreateLabel("Dateien werden gewandelt: ", 20, 20, $iWidthLabel) +Local $hProgress = GUICtrlCreateProgress(-1, 25, $iWidthLabel) +Local $sLabelFile = GUICtrlCreateLabel(".", -1, 32, $iWidthLabel, 80) ; label has to have some text ; 80 +GUICtrlSetFont(-1,9) +GUISetState() + +Local $hTimerStart = TimerInit() + +For $i = 1 To $aFileList[0] + $sCurTrack = $aFileList[$i] + ConsoleWrite("ShortName: " & $sCurTrack & @CRLF) + $sCurTrackMinusExt = StringTrimRight($sCurTrack, 4) + $sCurTrackNewExt = '_48kHz_24bit.wav' + + $sOutput = "" ; für jede Runde löschen + $sOutError = "" ; für jede Runde löschen + $iPID = Run(@TempDir & "\sox.exe --i " & _quotePath($sCurTrack), "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) ; Metadaten auslesen + While ProcessExists($iPID) + $sOutput &= StdoutRead($iPID) + $sOutError &= StderrRead($iPID) + WEnd + + If $sOutput = "" Then ; no Metadata + $sOutError = StringRegExpReplace($sOutError, ".*\\sox.exe", "") + MsgBox($MB_SYSTEMMODAL + $MB_ICONWARNING, @ScriptName, $sCurTrack & ":" & @CRLF & @CRLF & $sOutError) + Else + GUICtrlSetData($sLabelFile, _WordWrapTextForLabel($sCurTrack, 59)) + GUICtrlSetData($hLabelCounter, "Dateien werden gewandelt: " & $i & "/" & $aFileList[0]) + $aOutput = StringSplit($sOutput, @CRLF) + $aBitRate = StringRegExp($aOutput[15], "[\d.]{1,5}", 1) ; Bitrate steht im Metadaten-Array auf Platz 15 + $iBitRate = $aBitRate[0] + If StringInStr($iBitRate,".") Then ; Falls in z.B. 2.31M statt 192k angegeben + $iBitRate *= 1024 ; mbit to kbit + EndIf + ConsoleWrite("BitRate: " & $iBitRate & @CRLF) + $iFaktorFileSize = 2365.44 / $iBitRate ; 2365.44 = Bitrate für 24bit und 48kHz + ConsoleWrite("FaktorFileSize: " & $iFaktorFileSize & @CRLF) + + #cs Alternative für Fortschrittsbalken mit Auslesen StdErr von sox.exe - liest aber immer nur alle 6 Sekunden aus + $iPID = Run(@TempDir & "\sox.exe " & _quotePath($sCurTrack) & " -b 24 -r 48k " & _quotePath($sCurTrackMinusExt & $sCurTrackNewExt) & " -S", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) ; Metadaten auslesen + $hTimerStart = TimerInit() + While ProcessExists($iPID) + ;~ $sOutput &= StdoutRead($iPID) + $sOutError = StderrRead($iPID) + ;~ $sOutput = StderrRead($iPID) + If $sOutError <> "" Then + ;~ ConsoleWrite("New Block:" & @CRLF & $sOutError & @CRLF) + $aProzent = StringRegExp($sOutError, "(?i)In:([\d.]*)%", 3) + If Not @error Then + ;~ _ArrayDisplay($aProzent,"Zeile " & @ScriptLineNumber) + ;~ $sOutput = $aProzent[0] + $iProzent = $aProzent[UBound($aProzent) - 1] + ConsoleWrite($iProzent & @CRLF) + GUICtrlSetData($sLabelFile, $iProzent) + GUICtrlSetData($hProgress,$iProzent) + EndIf + ;~ GUICtrlSetData($sLabelFile, $sOutError) + EndIf + + If $sOutError <> "" Then ; no Metadata + EndIf + ;~ Sleep(100) + WEnd + ConsoleWrite($sOutError & @CRLF) + ConsoleWrite(_Zeit(TimerDiff($hTimerStart), True) & @CRLF) +;~ ClipPut("OUT:" & @CRLF & $sOutput & @CRLF & @CRLF & "ERROR:" & @CRLF & $sOutError ) +;~ MsgBox($MB_SYSTEMMODAL + $MB_ICONWARNING, @ScriptName, $sOutError) + #ce + + $iPID = ShellExecute(@TempDir & "\sox.exe", _quotePath($sCurTrack) & " −b 24 -r 48k " & _quotePath($sCurTrackMinusExt & $sCurTrackNewExt),"","", @SW_HIDE) ; run converter + $iOldSize = FileGetSize($sCurTrack) + ConsoleWrite("OldSize: " & $iOldSize & @CRLF) + $iShouldSize = Round($iOldSize * $iFaktorFileSize) + ConsoleWrite("ShouldSize: " & $iShouldSize & @CRLF) + $sCurTrackName = StringTrimLeft($sCurTrack, StringInStr($sCurTrack, "\", 0, -1)) + While ProcessExists($iPID) + $iTempSize = FileGetSize($sCurTrackMinusExt & $sCurTrackNewExt) + $iProzent = Round(100 * $iTempSize / $iShouldSize) + If $iProzent <> $iProzentTemp Then + ConsoleWrite($iProzent & "% ") + $iProzentTemp = $iProzent + EndIf + GUICtrlSetData($hProgress,$iProzent) + WEnd + ConsoleWrite(@CRLF) ; neue Zeile + Sleep(100) + EndIf + ConsoleWrite(@CRLF) ; neue Zeile +Next +Exit + +Func _quotePath($sPath) ; versieht Pfade mit Anführungszeichen " - nötig für Run sowie die Parameter in ShellExecute + $sPath = '"' & $sPath & '"' + Return $sPath +EndFunc + +Func _Hide() ; Fenster verstecken oder anzeigen + If $bGUI = 1 Then + GUISetState(@SW_HIDE,$hGUI ) + TrayItemSetText($hEnableGUI, "Anzeigen") + Else + GUISetState(@SW_SHOW,$hGUI ) + TrayItemSetText($hEnableGUI, "Verstecken") + EndIf + $bGUI = Not $bGUI +EndFunc + +Func _WordWrapTextForLabel($sText, $iCounter) + Local $sResult + Local $iTotalChar = StringLen($sText) + For $i = 1 To Ceiling($iTotalChar / $iCounter) + $sResult &= StringLeft($sText, $iCounter) & " " + $sText = StringTrimLeft($sText, $iCounter) + Next + $sResult = StringTrimRight($sResult, 1) ; cut last " " + Return $sResult +EndFunc + +Func _Zeit($iMs, $bComfortView = False) ; from ms to a format: "12h 36m 56s 13f" (with special space between - ChrW(8239)) + Local $sReturn + $iMs = Int($iMs) + Local $iFrames, $iMSec, $iSec, $iMin, $iHour, $sSign + If $iMs < 0 Then + $iMs = Abs($iMs) + $sSign = '-' + EndIf + $iMSec = StringRight($iMs, 3) + $iFrames = $iMSec / 40 + $iSec = $iMs / 1000 + $iMin = $iSec / 60 + $iHour = $iMin / 60 + $iMin -= Int($iHour) * 60 + $iSec -= Int($iMin) * 60 + If $bComfortView Then ; no hours if not present and no frames + If Not Int($iHour) = 0 Then $sReturn &= StringRight('0' & Int($iHour), 2) & 'h' & ChrW(8239) + $sReturn &= StringRight('0' & Int($iMin), 2) & 'm' & ChrW(8239) & StringRight('0' & Int($iSec), 2) & 's' + Else + $sReturn = $sSign & StringRight('0' & Int($iHour), 2) & 'h' & ChrW(8239) & StringRight('0' & Int($iMin), 2) & 'm' & ChrW(8239) & StringRight('0' & Int($iSec), 2) & 's' & ChrW(8239) & StringRight('0' & Int($iFrames), 2) & 'f' + EndIf + Return $sReturn +EndFunc \ No newline at end of file