Jump to content

Search the Community

Showing results for tags 'music'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • Announcements and Site News
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • Forum
  • AutoIt

Calendars

  • Community Calendar

Found 13 results

  1. FModMem UDF build 2017-01-30

    Version

    155 downloads

    A FMOD UDF to play music whereas the DLL calls are done from memory. Supported formats: - .MOD (protracker/fasttracker modules) - .S3M (screamtracker 3 modules) - .XM (fasttracker 2 modules) - .IT (impulse tracker modules) - .MID (MIDI files) - .RMI (MIDI files) - .SGT (DirectMusic segment files) - .FSB (FMOD Sample Bank files) - .MP3 - .OGG - .WAV - .MP2 - .RAW Click the forum URL to the right for more information.
  2. Hi, I created a FMOD UDF whereas the DLL calls are done from memory. Credits to trancexx for the Subrogation functions! Supported formats: - .MOD (protracker/fasttracker modules) - .S3M (screamtracker 3 modules) - .XM (fasttracker 2 modules) - .IT (impulse tracker modules) - .MID (MIDI files) - .RMI (MIDI files) - .SGT (DirectMusic segment files) - .FSB (FMOD Sample Bank files) - .MP3 - .OGG - .WAV - .MP2 - .RAW Current added function list (sum = 70): FMUSICMEM_FreeSong FMUSICMEM_GetBPM FMUSICMEM_GetGlobalVolume FMUSICMEM_GetMasterVolume FMUSICMEM_GetName FMUSICMEM_GetNumChannels FMUSICMEM_GetNumInstruments FMUSICMEM_GetNumOrders FMUSICMEM_GetNumPatterns FMUSICMEM_GetNumSamples FMUSICMEM_GetOrder FMUSICMEM_GetPaused FMUSICMEM_GetRow FMUSICMEM_GetSpeed FMUSICMEM_GetTime FMUSICMEM_GetType FMUSICMEM_IsFinished FMUSICMEM_LoadSong FMUSICMEM_LoadSongEx FMUSICMEM_OptimizeChannels FMUSICMEM_PlaySong FMUSICMEM_SetMasterVolume FMUSICMEM_SetOrder FMUSICMEM_SetPaused FMUSICMEM_StopAllSongs FMUSICMEM_StopSong FSOUNDMEM_Close FSOUNDMEM_DSP_Create FSOUNDMEM_DSP_Free FSOUNDMEM_DSP_GetActive FSOUNDMEM_DSP_GetFFTUnit FSOUNDMEM_DSP_GetSpectrum FSOUNDMEM_DSP_SetActive FSOUNDMEM_DSP_SetPriority FSOUNDMEM_GetAmplitude FSOUNDMEM_GetChannelsPlaying FSOUNDMEM_GetCPUUsage FSOUNDMEM_GetCurrentLevels FSOUNDMEM_GetError FSOUNDMEM_GetFrequency FSOUNDMEM_GetGetSurround FSOUNDMEM_GetMaxChannels FSOUNDMEM_GetPan FSOUNDMEM_GetPaused FSOUNDMEM_GetVolume FSOUNDMEM_Init FSOUNDMEM_SetPaused FSOUNDMEM_SetSpeakerMode FSOUNDMEM_SetSurround FSOUNDMEM_SetVolume FSOUNDMEM_SetVolumeAbsolute FSOUNDMEM_Stream_Close FSOUNDMEM_Stream_FindTagField FSOUNDMEM_Stream_GetLength FSOUNDMEM_Stream_GetLengthMs FSOUNDMEM_Stream_GetNumTagFields FSOUNDMEM_Stream_GetOpenState FSOUNDMEM_Stream_GetPosition FSOUNDMEM_Stream_GetTagField FSOUNDMEM_Stream_GetTime FSOUNDMEM_Stream_Net_GetStatus FSOUNDMEM_Stream_Net_SetMetadataCallback FSOUNDMEM_Stream_Net_SetProxy FSOUNDMEM_Stream_Open FSOUNDMEM_Stream_Play FSOUNDMEM_Stream_PlayEx FSOUNDMEM_Stream_SetLoopCount FSOUNDMEM_Stream_SetPosition FSOUNDMEM_Stream_SetTime FSOUNDMEM_Stream_Stop In the zip archive you can find 6 examples. Download at download section: If you have created additional examples, feel free to post it here.
  3. AutoIt Radio Player Last : v0.0.0.8 Tested only on W7X64 Changelog : ==========> AutoIt Radio Player v0.0.0.8.zip <========== Personal Message : This is my first script posted. Any comment are welcome. Give me your best web radio i will try add them ! Install/Use : Add a station : Unsolved problem : When the coverGUI go outside the monitor and comeback inside, a part of current cover disapear : I have no idea how fix that TODO : Make coverGUI mouse resizable (while script running) : any idea are welcome Crop some pixel of cover : any idea are welcome Related Posts/Bin : ArrayMultiColSort MouseWheelDelta Sample1 MouseWheelDelta Sample2 ContextMenu Fix ReduceMemory MemGlobalAllocFromBinary Curl.au3 (AutoIt binary code) Main Code : ;#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7;All Warning ;-w 5 = local var declared but not used : Removed for Curl.au3 ;-d = as Opt("MustDeclareVars", 1) : Removed for Bass.au3 #AutoIt3Wrapper_Au3Check_Parameters=-w 1 -w 2 -w 3 -w- 4 -w 6 -w- 7 #Region ;==> #include #include <Array.au3>;_ArrayAdd #include <GuiButton.au3>;_GUICtrlButton_SetImage() #include <GuiMenu.au3>;$MNS_MODELESS #include <GUIConstants.au3>;$WS_POPUP #include <GDIplus.au3>;_GDIPlus_BitmapCreateFromStream() #include <Memory.au3>;$GMEM_MOVEABLE #include <String.au3>;_StringBetween() #include <AutoIt Radio Player\include\Bass.au3>;_BASS_ChannelPlay() #include <AutoIt Radio Player\include\BassConstants.au3>;$BASS_CONFIG_NET_PLAYLIST #include <AutoIt Radio Player\include\Curl.au3>;Curl_Data_Get() #EndRegion ;==> #include #Region ;==> Func for Bass.au3 Local $MusicHandle Func _Audio_play($MusicHandle) _BASS_ChannelPlay($MusicHandle, 1) EndFunc Func _Audio_stop($MusicHandle) _BASS_ChannelStop($MusicHandle) EndFunc Func _Audio_init_stop($MusicHandle) _BASS_StreamFree($MusicHandle) _BASS_Free() EndFunc Func _Audio_init_start() If _BASS_STARTUP(@ScriptDir & "\AutoIt Radio Player\include\bass.dll") Then If _BASS_Init(0, -1, 44100, 0) Then If _BASS_SetConfig($BASS_CONFIG_NET_PLAYLIST, 1) = 0 Then SetError(3) EndIf Else SetError(2) EndIf Else SetError(@error) EndIf EndFunc Func _Set_volume($volume) _BASS_SetConfig($BASS_CONFIG_GVOL_STREAM, $volume * 100) EndFunc Func _Set_url($file) If FileExists($file) Then $MusicHandle = _BASS_StreamCreateFile(False, $file, 0, 0, 0) Else $MusicHandle = _BASS_StreamCreateURL($file, 0, 1) EndIf If @error Then Return SetError(1) EndIf Return $MusicHandle EndFunc #EndRegion ;==> Func for Bass.au3 Global Const $SC_DRAGMOVE = 0xF012;Global #Region ;==> Func from AutoIt Forum ; #FUNCTION# ==================================================================================================================== ; Name...........: _ArrayMultiColSort ; Description ...: Sort 2D arrays on several columns ; Syntax.........: _ArrayMultiColSort(ByRef $aArray, $aSortData[, $iStart = 0[, $iEnd = 0]]) ; Parameters ....: $aArray - The 2D array to be sorted ; $aSortData - 2D array holding details of the sort format ; Format: [Column to be sorted, Sort order] ; Sort order can be either numeric (0/1 = ascending/descending) or a ordered string of items ; Any elements not matched in string are left unsorted after all sorted elements ; $iStart - Element of array at which sort starts (default = 0) ; $iEnd - Element of array at which sort endd (default = 0 - converted to end of array) ; Requirement(s).: v3.3.8.1 or higher ; Return values .: Success: No error ; Failure: @error set as follows ; @error = 1 with @extended set as follows (all refer to $sIn_Date): ; 1 = Array to be sorted not 2D ; 2 = Sort data array not 2D ; 3 = More data rows in $aSortData than columns in $aArray ; 4 = Start beyond end of array ; 5 = Start beyond End ; @error = 2 with @extended set as follows: ; 1 = Invalid string parameter in $aSortData ; 2 = Invalid sort direction parameter in $aSortData ; Author ........: Melba23 ; Remarks .......: Columns can be sorted in any order ; Example .......; Yes ; =============================================================================================================================== Func _ArrayMultiColSort(ByRef $aArray, $aSortData, $iStart = 0, $iEnd = 0) ; Errorchecking ; 2D array to be sorted If UBound($aArray, 2) = 0 Then Return SetError(1, 1, "") EndIf ; 2D sort data If UBound($aSortData, 2) <> 2 Then Return SetError(1, 2, "") EndIf If UBound($aSortData) > UBound($aArray) Then Return SetError(1, 3) EndIf ; Start element If $iStart < 0 Then $iStart = 0 EndIf If $iStart >= UBound($aArray) - 1 Then Return SetError(1, 4, "") EndIf ; End element If $iEnd <= 0 Or $iEnd >= UBound($aArray) - 1 Then $iEnd = UBound($aArray) - 1 EndIf ; Sanity check If $iEnd <= $iStart Then Return SetError(1, 5, "") EndIf Local $iCurrCol, $iChunk_Start, $iMatchCol ; Sort first column __AMCS_SortChunk($aArray, $aSortData, 0, $aSortData[0][0], $iStart, $iEnd) If @error Then Return SetError(2, @extended, "") EndIf ; Now sort within other columns For $iSortData_Row = 1 To UBound($aSortData) - 1 ; Determine column to sort $iCurrCol = $aSortData[$iSortData_Row][0] ; Create arrays to hold data from previous columns Local $aBaseValue[$iSortData_Row] ; Set base values For $i = 0 To $iSortData_Row - 1 $aBaseValue[$i] = $aArray[$iStart][$aSortData[$i][0]] Next ; Set start of this chunk $iChunk_Start = $iStart ; Now work down through array For $iRow = $iStart + 1 To $iEnd ; Match each column For $k = 0 To $iSortData_Row - 1 $iMatchCol = $aSortData[$k][0] ; See if value in each has changed If $aArray[$iRow][$iMatchCol] <> $aBaseValue[$k] Then ; If so and row has advanced If $iChunk_Start < $iRow - 1 Then ; Sort this chunk __AMCS_SortChunk($aArray, $aSortData, $iSortData_Row, $iCurrCol, $iChunk_Start, $iRow - 1) If @error Then Return SetError(2, @extended, "") EndIf EndIf ; Set new base value $aBaseValue[$k] = $aArray[$iRow][$iMatchCol] ; Set new chunk start $iChunk_Start = $iRow EndIf Next Next ; Sort final section If $iChunk_Start < $iRow - 1 Then __AMCS_SortChunk($aArray, $aSortData, $iSortData_Row, $iCurrCol, $iChunk_Start, $iRow - 1) If @error Then Return SetError(2, @extended, "") EndIf EndIf Next EndFunc ;==>_ArrayMultiColSort ; #FUNCTION# ==================================================================================================================== ; Name...........: __AMCS_SortChunk ; Description ...: Sorts array section ; Author ........: Melba23 ; Remarks .......: ; =============================================================================================================================== Func __AMCS_SortChunk(ByRef $aArray, $aSortData, $iRow, $iColumn, $iChunkStart, $iChunkEnd) Local $aSortOrder ; Set default sort direction Local $iSortDirn = 1 ; Need to prefix elements? If IsString($aSortData[$iRow][1]) Then ; Split elements $aSortOrder = StringSplit($aSortData[$iRow][1], ",") If @error Then Return SetError(1, 1, "") EndIf ; Add prefix to each element For $i = $iChunkStart To $iChunkEnd For $j = 1 To $aSortOrder[0] If $aArray[$i][$iColumn] = $aSortOrder[$j] Then $aArray[$i][$iColumn] = StringFormat("%02i-", $j) & $aArray[$i][$iColumn] ExitLoop EndIf Next ; Deal with anything that does not match If $j > $aSortOrder[0] Then $aArray[$i][$iColumn] = StringFormat("%02i-", $j) & $aArray[$i][$iColumn] EndIf Next Else Switch $aSortData[$iRow][1] Case 0, 1 ; Set required sort direction if no list If $aSortData[$iRow][1] Then $iSortDirn = -1 Else $iSortDirn = 1 EndIf Case Else Return SetError(1, 2, "") EndSwitch EndIf ; Sort the chunk Local $iSubMax = UBound($aArray, 2) - 1 __ArrayQuickSort2D($aArray, $iSortDirn, $iChunkStart, $iChunkEnd, $iColumn, $iSubMax) ; Remove any prefixes If IsString($aSortData[$iRow][1]) Then For $i = $iChunkStart To $iChunkEnd $aArray[$i][$iColumn] = StringTrimLeft($aArray[$i][$iColumn], 3) Next EndIf EndFunc ;==>__AMCS_SortChunk Func _ReduceMemory() Local $aReturn = DllCall("psapi.dll", "int", "EmptyWorkingSet", "long", -1) If @error = 1 Then Return SetError(1, 0, 0) EndIf Return $aReturn[0] EndFunc ;==>_ReduceMemory ; #FUNCTION# ==================================================================================================================== ; Name...........: _GDIPlus_ImageLoadFromHGlobal ; Description ...: Creates an Image object based on movable HGlobal memory block ; Syntax.........: _GDIPlus_ImageLoadFromHGlobal($hGlobal) ; Parameters ....: $hGlobal - Handle of a movable HGlobal memory block ; Return values .: Success - Pointer to a new Image object ; Failure - 0 and either: ; |@error and @extended are set if DllCall failed: ; | -@error = 1 if could not create IStream ; | -@error = 2 if DLLCall to create image failed ; |$GDIP_STATUS contains a non zero value specifying the error code ; Author ........: ProgAndy ; Modified.......: ; Remarks .......: After you are done with the object, call _GDIPlus_ImageDispose to release the object resources. ; The HGLOBAL will be owned by the image and freed automatically when the image is disposed. ; Related .......: _GDIPlus_ImageLoadFromStream, _GDIPlus_ImageDispose ; Link ..........: ; Example .......: ; =============================================================================================================================== Func _GDIPlus_ImageLoadFromHGlobal($hGlobal) Local $aResult = DllCall("ole32.dll", "int", "CreateStreamOnHGlobal", "handle", $hGlobal, "bool", True, "ptr*", 0) If @error Or $aResult[0] <> 0 Or $aResult[3] = 0 Then Return SetError(1, @error, 0) Local $hImage = DllCall($__g_hGDIPDll, "uint", "GdipLoadImageFromStream", "ptr", $aResult[3], "int*", 0) Local $error = @error Local $tVARIANT = DllStructCreate("word vt;word r1;word r2;word r3;ptr data; ptr") Local $aCall = DllCall("oleaut32.dll", "long", "DispCallFunc", "ptr", $aResult[3], "dword", 8 + 8 * @AutoItX64, "dword", 4, "dword", 23, "dword", 0, "ptr", 0, "ptr", 0, "ptr", DllStructGetPtr($tVARIANT)) If $error Then Return SetError(2, $error, 0) If $hImage[2] = 0 Then Return SetError(3, 0, $hImage[2]) Return $hImage[2] EndFunc ;==>_GDIPlus_ImageLoadFromHGlobal ; #FUNCTION# ==================================================================================================================== ; Name...........: _MemGlobalAllocFromBinary ; Description ...: Greates a movable HGLOBAL memory block from binary data ; Syntax.........: _MemGlobalAllocFromBinary($bBinary) ; Parameters ....: $bBinary - Binary data ; Return values .: Success - Handle of a new movable HGLOBAL ; Failure - 0 and set @error: ; |1 - no data ; |2 - could not allocate memory ; |3 - could not set data to memory ; Author ........: ProgAndy ; Modified.......: ; Remarks .......: ; Related .......: _MemGlobalAlloc, _MemGlobalFree, _MemGlobalLock ; Link ..........: ; Example .......: ; =============================================================================================================================== Func _MemGlobalAllocFromBinary(Const $bBinary) Local $iLen = BinaryLen($bBinary) If $iLen = 0 Then Return SetError(1, 0, 0) Local $hMem = _MemGlobalAlloc($iLen, $GMEM_MOVEABLE) If @error Or Not $hMem Then Return SetError(2, 0, 0) DllStructSetData(DllStructCreate("byte[" & $iLen & "]", _MemGlobalLock($hMem)), 1, $bBinary) If @error Then _MemGlobalUnlock($hMem) _MemGlobalFree($hMem) Return SetError(3, 0, 0) EndIf _MemGlobalUnlock($hMem) Return $hMem EndFunc ;==>_MemGlobalAllocFromBinary #EndRegion ;==> Func from AutoIt Forum ;INI Location Local $Config_INI = "AutoIt Radio Player\Config.ini" Local $Save_INI = "AutoIt Radio Player\Save.ini" ;Get $aRadio and $aLabel <===========================================That part need improve Local $aINISections = IniReadSectionNames($Config_INI) Local $aRadio[0][8] Local $aLabel[0][11] For $i = 1 To UBound($aINISections) - 1 If $aINISections[$i] <> "GUI" Then ;For $aRadio Local $SoundLink = "", $CoverLink = "", $CoverLinkStart = "", $CoverLinkEnd = "", $CoverLinkBetweenNum = "", $CoverLinkBefore = "", $Default = 0 ;For $aLabel Local $CurrentArtistLink = "", $CurrentArtistStart = "", $CurrentArtistEnd = "", $CurrentArtistBetweenNum = 0, $CurrentArtistSplit = "", $CurrentArtistNumSplit = "" Local $CurrentAlbumLink = "", $CurrentAlbumStart = "", $CurrentAlbumEnd = "", $CurrentAlbumBetweenNum = 0, $CurrentAlbumSplit = "", $CurrentAlbumNumSplit = "" Local $CurrentTitleLink = "", $CurrentTitleStart = "", $CurrentTitleEnd = "", $CurrentTitleBetweenNum = 0, $CurrentTitleSplit = "", $CurrentTitleNumSplit = "" Local $NextArtistLink = "", $NextArtistStart = "", $NextArtistEnd = "", $NextArtistBetweenNum = 0, $NextArtistSplit = "", $NextArtistNumSplit = "" Local $NextAlbumLink = "", $NextAlbumStart = "", $NextAlbumEnd = "", $NextAlbumBetweenNum = 0, $NextAlbumSplit = "", $NextAlbumNumSplit = "" Local $NextTitleLink = "", $NextTitleStart = "", $NextTitleEnd = "", $NextTitleBetweenNum = 0, $NextTitleSplit = "", $NextTitleNumSplit = "" Local $ListenersCountLink = "", $ListenersCountStart = "", $ListenersCountEnd = "", $ListenersCountBetweenNum = 0, $ListenersCountSplit = "", $ListenersCountNumSplit = "" Local $controlID1 = "", $controlID2 = "" Local $Sec = IniReadSection($Config_INI, $aINISections[$i]) For $y = 1 To UBound($Sec) - 1 Assign($Sec[$y][0], $Sec[$y][1]) Next ;$aRadio _ArrayAdd($aRadio, $aINISections[$i] & "|" & $SoundLink & "|" & $CoverLink & "|" & $CoverLinkStart & "|" & $CoverLinkEnd & "|" & $CoverLinkBetweenNum & "|" & $CoverLinkBefore & "|" & $Default) ;$aLabel _ArrayAdd($aLabel, $aINISections[$i] & "|" & "Current" & "|" & "Artist" & "|" & $CurrentArtistLink & "|" & $CurrentArtistStart & "|" & $CurrentArtistEnd & "|" & $CurrentArtistBetweenNum & "|" & $CurrentArtistSplit & "|" & $CurrentArtistNumSplit & "|" & $controlID1 & "|" & $controlID2) _ArrayAdd($aLabel, $aINISections[$i] & "|" & "Current" & "|" & "Album" & "|" & $CurrentAlbumLink & "|" & $CurrentAlbumStart & "|" & $CurrentAlbumEnd & "|" & $CurrentAlbumBetweenNum & "|" & $CurrentAlbumSplit & "|" & $CurrentAlbumNumSplit & "|" & $controlID1 & "|" & $controlID2) _ArrayAdd($aLabel, $aINISections[$i] & "|" & "Current" & "|" & "Title" & "|" & $CurrentTitleLink & "|" & $CurrentTitleStart & "|" & $CurrentTitleEnd & "|" & $CurrentTitleBetweenNum & "|" & $CurrentTitleSplit & "|" & $CurrentTitleNumSplit & "|" & $controlID1 & "|" & $controlID2) _ArrayAdd($aLabel, $aINISections[$i] & "|" & "Next" & "|" & "Artist" & "|" & $NextArtistLink & "|" & $NextArtistStart & "|" & $NextArtistEnd & "|" & $NextArtistBetweenNum & "|" & $NextArtistSplit & "|" & $NextArtistNumSplit & "|" & $controlID1 & "|" & $controlID2) _ArrayAdd($aLabel, $aINISections[$i] & "|" & "Next" & "|" & "Album" & "|" & $NextAlbumLink & "|" & $NextAlbumStart & "|" & $NextAlbumEnd & "|" & $NextAlbumBetweenNum & "|" & $NextAlbumSplit & "|" & $NextAlbumNumSplit & "|" & $controlID1 & "|" & $controlID2) _ArrayAdd($aLabel, $aINISections[$i] & "|" & "Next" & "|" & "Title" & "|" & $NextTitleLink & "|" & $NextTitleStart & "|" & $NextTitleEnd & "|" & $NextTitleBetweenNum & "|" & $NextTitleSplit & "|" & $NextTitleNumSplit & "|" & $controlID1 & "|" & $controlID2) _ArrayAdd($aLabel, $aINISections[$i] & "|" & "Listeners" & "|" & "Count" & "|" & $ListenersCountLink & "|" & $ListenersCountStart & "|" & $ListenersCountEnd & "|" & $ListenersCountBetweenNum & "|" & $ListenersCountSplit & "|" & $ListenersCountNumSplit & "|" & $controlID1 & "|" & $controlID2) EndIf Next Global $aRadio_Sort[][] = [[0, 0], [1, 0]] _ArrayMultiColSort($aRadio, $aRadio_Sort) Local $aLabel2[0][11] For $i = 0 To UBound($aLabel) - 1 If $aLabel[$i][3] <> "" Then Local $fill = $aLabel[$i][0] For $y = 1 To UBound($aLabel, 2) - 1 $fill = $fill & "|" & $aLabel[$i][$y] Next _ArrayAdd($aLabel2, $fill) EndIf Next $aLabel = $aLabel2 ;_ArrayDisplay($aRadio) ;_ArrayDisplay($aLabel) ;Init/Opt Opt("GUIOnEventMode", 1) _Audio_init_start() _GDIPlus_Startup() ;Icon Local $IcoFile = @ScriptDir & "\AutoIt Radio Player\img\icon.ico" Local $IcoNumber = -1 TraySetIcon($IcoFile, $IcoNumber) ;Get Default Station Local $def_selected = 0 For $r = 0 To UBound($aRadio) - 1 If $aRadio[$r][0] = IniRead($Save_INI, @ComputerName, "Default_Radio", "default") Then $def_selected = 1 $aRadio[$r][7] = 1 EndIf Next If $def_selected = 0 Then $aRadio[0][7] = 1 EndIf ;ConsoleWrite("Start" & @CRLF) ;Get $Radio_Name, $Radio_SoundLink, $Radio_CoverLink, $Radio_CoverLink_Start, $Radio_CoverLink_End, $Radio_CoverLink_BetweenNum, $Radio_CoverLink_Before Local $Radio_Name, $Radio_SoundLink, $Radio_CoverLink Local $Radio_CoverLink_Start, $Radio_CoverLink_End, $Radio_CoverLink_BetweenNum, $Radio_CoverLink_Before For $r = 0 To UBound($aRadio) - 1 If $aRadio[$r][7] = 1 Then $Radio_Name = $aRadio[$r][0] $Radio_SoundLink = $aRadio[$r][1] $Radio_CoverLink = $aRadio[$r][2] $Radio_CoverLink_Start = $aRadio[$r][3] $Radio_CoverLink_End = $aRadio[$r][4] $Radio_CoverLink_BetweenNum = $aRadio[$r][5] $Radio_CoverLink_Before = $aRadio[$r][6] EndIf Next ;Declare Local $PlayerGUI, $CoverGUI;GUI Local $PlayPause, $Close;Button Local $Play = 1;PlayStatus ($Play = 1 = Autoplay) Local $Volume_Label, $VolumePercent, $Previous_VolumePercent;Volume Local $Previous_Cover_Read;PreviousRead Local $BASS_ErrorGetCode ;$Config_INI\GUI Local $CoverSize = IniRead($Config_INI, "GUI", "CoverSize", 150) Local $PlayerBorder = IniRead($Config_INI, "GUI", "PlayerBorder", 10) ;ConsoleWrite("Build GUI" & @CRLF) ;Build GUI _Build_PlayerGUI() _Build_CoverGUI() ;ConsoleWrite("Show GUI" & @CRLF) GUISetState(@SW_SHOW, $PlayerGUI) If $Radio_CoverLink <> "" Then GUISetState(@SW_SHOW, $CoverGUI) EndIf _Set_volume(0) ;GetPlayerDATA() - GetCoverDATA() - Start Sound GetPlayerDATA();Start Sound too with resume on disconnect AdlibRegister("GetPlayerDATA", 8000) If $Radio_CoverLink <> "" Then GetCoverDATA() AdlibRegister("GetCoverDATA", 8000) EndIf ;ConsoleWrite("GUIRegisterMsg" & @CRLF) GUIRegisterMsg($WM_MOUSEWHEEL, "_WM_MOUSEWHEEL");for set volume GUIRegisterMsg($WM_LBUTTONDOWN, "_WM_LBUTTONDOWN");for drag gui #Region ;==> Internal Func Func _Build_CoverGUI() ;ConsoleWrite("Build CoverGUI" & @CRLF) If $Radio_CoverLink <> "" Then $CoverGUI = GUICreate("AutoIt Radio Cover", _;Title $CoverSize, _ ;X $CoverSize, _ ;Y IniRead($Save_INI, @ComputerName, "Cover_X", -1), _;Left IniRead($Save_INI, @ComputerName, "Cover_Y", -1), _;Top $WS_POPUP, $WS_EX_TOPMOST);Style GUISetBkColor(0x000000, $CoverGUI);Black BkColor GUISetIcon($IcoFile, $IcoNumber, $CoverGUI) Else $CoverGUI = "" EndIf EndFunc ;==>_Build_CoverGUI Func _Build_PlayerGUI() ;ConsoleWrite("Build PlayerGUI" & @CRLF) ;Clean previous stored ControlID For $r = 0 To UBound($aLabel) - 1 $aLabel[$r][9] = "" $aLabel[$r][10] = "" Next ;$LabelCount Local $LabelCount = 0 For $r = 0 To UBound($aLabel) - 1 If $Radio_Name = $aLabel[$r][0] Then $LabelCount = $LabelCount + 1 EndIf Next ;$LabelY If $LabelCount * 13 + $PlayerBorder * 2 < 50 Then Local $LabelY = 10 * 3 Else $LabelY = $LabelCount * 13 EndIf ;$PlayerGUI $PlayerGUI = GUICreate("AutoIt Radio Player", _ $PlayerBorder + 260 + 50 + 10 + $PlayerBorder * 2, _;X $PlayerBorder + $LabelY + $PlayerBorder, _;Y IniRead($Save_INI, @ComputerName, "Title_X", -1), _;Left IniRead($Save_INI, @ComputerName, "Title_Y", -1), _;Top $WS_POPUP, $WS_EX_TOPMOST);Style GUISetBkColor(0x000000, $PlayerGUI);Black BkColor GUISetIcon($IcoFile, $IcoNumber, $PlayerGUI) ;$Contextmenu Local $ContextMenu = GUICtrlCreateContextMenu(-1) Local $hCM = GUICtrlGetHandle($ContextMenu) _GUICtrlMenu_SetMenuStyle($hCM, BitXOR(_GUICtrlMenu_GetMenuStyle($hCM), $MNS_MODELESS)) Local $ContextMenu_Item1 = GUICtrlCreateMenuItem($Radio_Name, $ContextMenu) GUICtrlSetOnEvent($ContextMenu_Item1, "ContextMenu_ChangeRadio") GUICtrlCreateMenuItem("", $ContextMenu);Add separator For $r = 0 To UBound($aRadio) - 1 If $aRadio[$r][7] = 0 Then GUICtrlCreateMenuItem($aRadio[$r][0], $ContextMenu) GUICtrlSetOnEvent(-1, "ContextMenu_ChangeRadio") EndIf Next ;GUICtrlCreateLabel $LabelCount = 0 Local $Previous_Type = "" For $r = 0 To UBound($aLabel) - 1 If $Radio_Name = $aLabel[$r][0] Then If $Previous_Type <> $aLabel[$r][1] Then $Previous_Type = $aLabel[$r][1] $aLabel[$r][10] = GUICtrlCreateLabel($aLabel[$r][1], $PlayerBorder, 13 * $LabelCount + $PlayerBorder, 50, 13, $SS_CENTERIMAGE) GUICtrlSetColor($aLabel[$r][10], 0xFFFFFF);White TextColor GUICtrlSetOnEvent($aLabel[$r][10], "_WM_LBUTTONDOWN") $ContextMenu = GUICtrlCreateContextMenu($aLabel[$r][10]) $hCM = GUICtrlGetHandle($ContextMenu) _GUICtrlMenu_SetMenuStyle($hCM, BitXOR(_GUICtrlMenu_GetMenuStyle($hCM), $MNS_MODELESS)) $ContextMenu_Item1 = GUICtrlCreateMenuItem($Radio_Name, $ContextMenu) GUICtrlSetOnEvent(-1, "ContextMenu_ChangeRadio") GUICtrlCreateMenuItem("", $ContextMenu);Add separator For $r2 = 0 To UBound($aRadio) - 1 If $aRadio[$r2][7] = 0 Then GUICtrlCreateMenuItem($aRadio[$r2][0], $ContextMenu) GUICtrlSetOnEvent(-1, "ContextMenu_ChangeRadio") EndIf Next EndIf $aLabel[$r][9] = GUICtrlCreateLabel("", $PlayerBorder + 50, 13 * $LabelCount + $PlayerBorder, 260, 13, $SS_CENTERIMAGE) $LabelCount = $LabelCount + 1 GUICtrlSetColor($aLabel[$r][9], 0xFFFFFF);White TextColor GUICtrlSetOnEvent($aLabel[$r][9], "_WM_LBUTTONDOWN") $ContextMenu = GUICtrlCreateContextMenu($aLabel[$r][9]) $hCM = GUICtrlGetHandle($ContextMenu) _GUICtrlMenu_SetMenuStyle($hCM, BitXOR(_GUICtrlMenu_GetMenuStyle($hCM), $MNS_MODELESS)) $ContextMenu_Item1 = GUICtrlCreateMenuItem($Radio_Name, $ContextMenu) GUICtrlSetOnEvent(-1, "ContextMenu_ChangeRadio") GUICtrlCreateMenuItem("", $ContextMenu);Add separator For $r2 = 0 To UBound($aRadio) - 1 If $aRadio[$r2][7] = 0 Then GUICtrlCreateMenuItem($aRadio[$r2][0], $ContextMenu) GUICtrlSetOnEvent(-1, "ContextMenu_ChangeRadio") EndIf Next EndIf Next ;GUICtrlCreateLabel Volume $Volume_Label = GUICtrlCreateLabel("0", $PlayerBorder, $PlayerBorder, 260 + 50, $LabelY, "") GUICtrlSetColor($Volume_Label, 0xFFFFFF);White TextColor GUICtrlSetOnEvent($Volume_Label, "_WM_LBUTTONDOWN") GUICtrlSetState($Volume_Label, $GUI_HIDE) ;$Volume_Label Contextmenu $ContextMenu = GUICtrlCreateContextMenu($Volume_Label) $hCM = GUICtrlGetHandle($ContextMenu) _GUICtrlMenu_SetMenuStyle($hCM, BitXOR(_GUICtrlMenu_GetMenuStyle($hCM), $MNS_MODELESS)) $ContextMenu_Item1 = GUICtrlCreateMenuItem($Radio_Name, $ContextMenu) GUICtrlSetOnEvent(-1, "ContextMenu_ChangeRadio") GUICtrlCreateMenuItem("", $ContextMenu);Add separator For $r = 0 To UBound($aRadio) - 1 If $aRadio[$r][7] = 0 Then Local $Item = GUICtrlCreateMenuItem($aRadio[$r][0], $ContextMenu) GUICtrlSetOnEvent(-1, "ContextMenu_ChangeRadio") EndIf Next ;$Close $Close = GUICtrlCreateButton("Close", _ $PlayerBorder * 2 + 260 + 50, _;Left $PlayerBorder, _;Top 10, _;X 10, _;Y $BS_BITMAP);Style _GUICtrlButton_SetImage($Close, @ScriptDir & "\AutoIt Radio Player\Img\Close.bmp") GUICtrlSetOnEvent($Close, "_Close") GUICtrlSetOnEvent($GUI_EVENT_CLOSE, "_Close") ;$PlayPause $PlayPause = GUICtrlCreateButton("Play/Pause", _ $PlayerBorder * 2 + 260 + 50, _;Left $PlayerBorder + 10 + 10, _;Top 10, _;X 10, _;Y $BS_BITMAP);Style _GUICtrlButton_SetImage($PlayPause, @ScriptDir & "\AutoIt Radio Player\Img\Stop.bmp") GUICtrlSetOnEvent($PlayPause, "_PlayPause") EndFunc ;==>_Build_PlayerGUI Func _Close() _Audio_init_stop($MusicHandle) _GDIPlus_Shutdown() Exit EndFunc ;==>_Close Func _PlayPause() ;Change $Play If $Play = 1 Then $Play = 0 Else $Play = 1 EndIf Local $Msg = GUIGetCursorInfo($PlayerGUI) ;Change Button Image If $Play = 1 Then If $Msg[4] = $PlayPause Then If $Msg[2] = 1 Then _GUICtrlButton_SetImage($PlayPause, @ScriptDir & "\AutoIt Radio Player\Img\stopp.bmp");Mouse Pressed Else _GUICtrlButton_SetImage($PlayPause, @ScriptDir & "\AutoIt Radio Player\Img\stopo.bmp");Mouse Over EndIf Else _GUICtrlButton_SetImage($PlayPause, @ScriptDir & "\AutoIt Radio Player\Img\stop.bmp");Nothing EndIf Else If $Msg[4] = $PlayPause Then If $Msg[2] = 1 Then _GUICtrlButton_SetImage($PlayPause, @ScriptDir & "\AutoIt Radio Player\Img\playp.bmp");Mouse Pressed Else _GUICtrlButton_SetImage($PlayPause, @ScriptDir & "\AutoIt Radio Player\Img\playo.bmp");Mouse Over EndIf Else _GUICtrlButton_SetImage($PlayPause, @ScriptDir & "\AutoIt Radio Player\Img\play.bmp");Nothing EndIf EndIf ;Play Sound If $Play = 0 Then _Audio_stop($MusicHandle) Else $MusicHandle = _Set_url($Radio_SoundLink) _Audio_play($MusicHandle) EndIf EndFunc ;==>_PlayPause Func _RemoveVolumeLabel() AdlibUnRegister("_RemoveVolumeLabel") ;Show Others Label For $i = 0 To UBound($aLabel) - 1 If $Radio_Name = $aLabel[$i][0] Then GUICtrlSetState($aLabel[$i][9], $GUI_SHOW) EndIf Next Local $Previous_Type = "" For $i = 0 To UBound($aLabel) - 1 If $Radio_Name = $aLabel[$i][0] Then If $Previous_Type <> $aLabel[$i][1] Then $Previous_Type = $aLabel[$i][1] GUICtrlSetState($aLabel[$i][10], $GUI_SHOW) EndIf GUICtrlSetState($aLabel[$i][9], $GUI_SHOW) EndIf Next ;Hide Volume Label GUICtrlSetState($Volume_Label, $GUI_HIDE) EndFunc ;==>_RemoveVolumeLabel Func _Save_Change_Volume() AdlibUnRegister("_Save_Change_Volume") _Set_volume($VolumePercent);Set IniWrite($Save_INI, @ComputerName, "Volume", $VolumePercent);Save EndFunc ;==>_Save_Change_Volume Func _WM_LBUTTONDOWN() ;Move GUI If WinActive("AutoIt Radio Cover") Then _SendMessage($CoverGUI, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0) Else _SendMessage($PlayerGUI, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0) EndIf ;Save GUI pos Local $Player_pos = WinGetPos("AutoIt Radio Player") Local $Cover_pos = WinGetPos("AutoIt Radio Cover") IniWrite($Save_INI, @ComputerName, "Title_X", $Player_pos[0]) IniWrite($Save_INI, @ComputerName, "Title_Y", $Player_pos[1]) If $Radio_CoverLink <> "" Then IniWrite($Save_INI, @ComputerName, "Cover_X", $Cover_pos[0]) IniWrite($Save_INI, @ComputerName, "Cover_Y", $Cover_pos[1]) EndIf EndFunc ;==>_WM_LBUTTONDOWN Func _WM_MOUSEWHEEL($hWnd, $iMsg, $wParam, $lParam) AdlibUnRegister("_RemoveVolumeLabel") If GUICtrlGetState($Volume_Label) <> 80 Then ;Show $Volume_Label GUICtrlSetState($Volume_Label, $GUI_SHOW) ;Hide Others Label Local $Previous_Type = "" For $i = 0 To UBound($aLabel) - 1 If $Radio_Name = $aLabel[$r][0] Then If $Previous_Type <> $aLabel[$i][1] Then $Previous_Type = $aLabel[$i][1] GUICtrlSetState($aLabel[$i][10], $GUI_HIDE) EndIf GUICtrlSetState($aLabel[$i][9], $GUI_HIDE) EndIf Next EndIf ;Change $VolumePercent Local $WheelDelta = BitShift($wParam, 16) / 120 $VolumePercent = $VolumePercent + 4 * $WheelDelta If $WheelDelta > 0 Then If $VolumePercent > 100 Then $VolumePercent = 100 Else If $VolumePercent < 0 Then $VolumePercent = 0 EndIf If $Previous_VolumePercent <> $VolumePercent Then $Previous_VolumePercent = $VolumePercent GUICtrlSetData($Volume_Label, $VolumePercent) EndIf ;Change\Save Sound AdlibRegister("_Save_Change_Volume", 50) ;Hide $Volume_Label in 3s AdlibRegister("_RemoveVolumeLabel", 3000) Return $GUI_RUNDEFMSG EndFunc ;==>_WM_MOUSEWHEEL Func ContextMenu_ChangeRadio() $Previous_Cover_Read = "" Local $NewRadioName = GUICtrlRead(@GUI_CtrlId, 1) ;Maybe the next radio have no cover so delete it If $Radio_CoverLink <> "" Then GUIDelete($CoverGUI) AdlibUnRegister("GetCoverDATA") EndIf ;Maybe the $PlayerGUI need resize so delete it GUIDelete($PlayerGUI) AdlibUnRegister("GetPlayerDATA") _Audio_stop($MusicHandle) ;Remove Default Radio Tag For $r = 0 To UBound($aRadio) - 1 $aRadio[$r][7] = 0 Next ;Set $NewRadioName to Default For $r = 0 To UBound($aRadio) - 1 If $aRadio[$r][0] = $NewRadioName Then $aRadio[$r][7] = 1 IniWrite($Save_INI, @ComputerName, "Default_Radio", $aRadio[$r][0]) EndIf Next ;Get $Radio_Name, $Radio_SoundLink, $Radio_CoverLink, $Radio_CoverLink_Start, $Radio_CoverLink_End, $Radio_CoverLink_BetweenNum, $Radio_CoverLink_Before For $r = 0 To UBound($aRadio) - 1 If $aRadio[$r][7] = 1 Then $Radio_Name = $aRadio[$r][0] $Radio_SoundLink = $aRadio[$r][1] $Radio_CoverLink = $aRadio[$r][2] $Radio_CoverLink_Start = $aRadio[$r][3] $Radio_CoverLink_End = $aRadio[$r][4] $Radio_CoverLink_BetweenNum = $aRadio[$r][5] $Radio_CoverLink_Before = $aRadio[$r][6] EndIf Next ;ConsoleWrite("Build GUI" & @CRLF) ;Build GUI _Build_PlayerGUI() _Build_CoverGUI() ;ConsoleWrite("Show GUI" & @CRLF) GUISetState(@SW_SHOW, $PlayerGUI) If $Radio_CoverLink <> "" Then GUISetState(@SW_SHOW, $CoverGUI) EndIf ;GetPlayerDATA() - GetCoverDATA() GetPlayerDATA() AdlibRegister("GetPlayerDATA", 8000) If $Radio_CoverLink <> "" Then GetCoverDATA() AdlibRegister("GetCoverDATA", 8000) EndIf EndFunc ;==>ContextMenu_ChangeRadio Func UseCurl($Link, $Timeout, $binary = 0, $write = 0, $file = "") Local $Error = "" Local $Data = "" Local $Curl = Curl_Easy_Init() If Not $Curl Then Return If $write = 0 Then ;Read Mode ; How to get html or header data? ; 1. Set $CURLOPT_WRITEFUNCTION and $CURLOPT_HEADERFUNCTION to Curl_DataWriteCallback() ; 2. Set $CURLOPT_WRITEDATA or $CURLOPT_HEADERDATA to any number as identify ; 3. Use Curl_Data_Get() to read the returned data in binary format ; 4. Use Curl_Data_Cleanup() to remove the data Local $Html = $Curl ; any number as identify Local $Header = $Curl + 1 ; any number as identify Curl_Easy_Setopt($Curl, $CURLOPT_URL, $Link) Curl_Easy_Setopt($Curl, $CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/7046A194A') Curl_Easy_Setopt($Curl, $CURLOPT_FOLLOWLOCATION, 1) Curl_Easy_Setopt($Curl, $CURLOPT_ACCEPT_ENCODING, "") Curl_Easy_Setopt($Curl, $CURLOPT_WRITEFUNCTION, Curl_DataWriteCallback()) Curl_Easy_Setopt($Curl, $CURLOPT_WRITEDATA, $Html) Curl_Easy_Setopt($Curl, $CURLOPT_HEADERFUNCTION, Curl_DataWriteCallback()) Curl_Easy_Setopt($Curl, $CURLOPT_HEADERDATA, $Header) Curl_Easy_Setopt($Curl, $CURLOPT_COOKIE, "tool=curl; script=autoit; fun=yes;") Curl_Easy_Setopt($Curl, $CURLOPT_TIMEOUT, $Timeout) Curl_Easy_Setopt($Curl, $CURLOPT_SSL_VERIFYPEER, 0) Local $Code = Curl_Easy_Perform($Curl) If $Code = $CURLE_OK Then ;ConsoleWrite("Content Type: " & Curl_Easy_GetInfo($Curl, $CURLINFO_CONTENT_TYPE) & @LF) ;ConsoleWrite("Download Size: " & Curl_Easy_GetInfo($Curl, $CURLINFO_SIZE_DOWNLOAD) & @LF) $Data = BinaryToString(Curl_Data_Get($Html)) $Error = "" ;MsgBox(0, 'Header', BinaryToString(Curl_Data_Get($Header))) ;MsgBox(0, 'Html', BinaryToString(Curl_Data_Get($Html))) Else ;ConsoleWrite(Curl_Easy_StrError($Code) & @LF) $Data = "" $Error = Curl_Easy_StrError($Code) EndIf Curl_Easy_Cleanup($Curl) Curl_Data_Cleanup($Header) Curl_Data_Cleanup($Html) Else ;Write Mode EndIf Local $aray[2] = [$Data,$Error] return $aray EndFunc Func GetCoverDATA() ;ConsoleWrite("GetCoverDATA (Start)" & @CRLF) ;Get $RealCoverLink If $Radio_CoverLink_Start = "" Then ;ConsoleWrite("$RealCoverLink = $Radio_CoverLink" & @CRLF) Local $RealCoverLink = $Radio_CoverLink Else ;ConsoleWrite("$RealCoverLink <> $Radio_CoverLink" & @CRLF) ;UseCurl($Link, $Timeout, $binary = 0, $write = 0, $file = "") Local $aray = UseCurl($Radio_CoverLink, 5) Local $Data = $aray[0] Local $Error = $aray[1] If $Error <> "" then ;ConsoleWrite("$Error = " & $Error & @CRLF) EndIf Local $Between = _StringBetween($Data, $Radio_CoverLink_Start, $Radio_CoverLink_End) If @error <> 0 Then $Between = "" Else $Between = $Between[$Radio_CoverLink_BetweenNum] EndIf $RealCoverLink = $Radio_CoverLink_Before & $Between $RealCoverLink = StringReplace($RealCoverLink, " ","%20") EndIf ;ConsoleWrite("$RealCoverLink = " & $RealCoverLink & @CRLF) ;UseCurl($Link, $Timeout, $binary = 0, $write = 0, $file = "") Local $Cover_Read = UseCurl($RealCoverLink, 5, 1) $Cover_Read = $Cover_Read[0] If $Cover_Read <> $Previous_Cover_Read and $Cover_Read <> "" Then $Previous_Cover_Read = $Cover_Read Local $hMem = _MemGlobalAllocFromBinary($Cover_Read) Local $hImage = _GDIPlus_ImageLoadFromHGlobal($hMem) Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($CoverGUI) _GDIPlus_GraphicsDrawImageRect($hGraphics, $hImage, 0, 0, $CoverSize, $CoverSize) _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_ImageDispose($hImage) EndIf ;ConsoleWrite("GetCoverDATA (End)" & @CRLF) EndFunc ;==>GetCoverDATA() Func GetPlayerDATA() _ReduceMemory() ;ConsoleWrite("GetPlayerDATA (Start)" & @CRLF) ;Assign Local $Previous_Data, $Previous_DataLink For $i = 0 To UBound($aLabel) - 1 If $Radio_Name = $aLabel[$i][0] Then If $Previous_DataLink <> $aLabel[$i][3] Then Local $aray = UseCurl($aLabel[$i][3], 5) Local $Data = $aray[0] Local $Error = $aray[1] $Previous_Data = $Data $Previous_DataLink = $aLabel[$i][3] Else $Data = $Previous_Data $Previous_DataLink = $aLabel[$i][3] EndIf Local $Between = _StringBetween($Data, $aLabel[$i][4], $aLabel[$i][5]) If @error <> 0 Then $Between = "" Else If Not ($aLabel[$i][6] > Ubound($Between)-1) Then $Between = $Between[$aLabel[$i][6]] Else $Between = "" EndIf EndIf If $aLabel[$i][7] <> "" Then Local $Split = StringSplit($Between, $aLabel[$i][7], 1) If $Split[0] < $aLabel[$i][8] Then Local $Info = "" Else $Info = $Split[$aLabel[$i][8]] EndIf Else $Info = $Between EndIf If $Data = "" Then $Info = $Error EndIf $Info = StringReplace($Info, "â·", "·") $Info = StringReplace($Info, "apos;", "'") Assign($aLabel[$i][1] & $aLabel[$i][2], $Info) EndIf Next If _BASS_ChannelIsActive($MusicHandle) <> 1 and $Play = 1 Then _Audio_stop($MusicHandle) ;ConsoleWrite("Start playing sound" & @CRLF) $Play = 1 $MusicHandle = _Set_url($Radio_SoundLink) _Audio_play($MusicHandle) ;ConsoleWrite("Set Volume" & @CRLF) $VolumePercent = IniRead($Save_INI, @ComputerName, "Volume", 4) $Previous_VolumePercent = $VolumePercent _Set_volume($VolumePercent) EndIf ;Update Ctrl For $i = 0 To UBound($aLabel) - 1 If $Radio_Name = $aLabel[$i][0] Then If Eval($aLabel[$i][1] & $aLabel[$i][2]) <> GUICtrlRead($aLabel[$i][9]) Then GUICtrlSetData($aLabel[$i][9], Eval($aLabel[$i][1] & $aLabel[$i][2])) EndIf EndIf Next ;ConsoleWrite("GetPlayerDATA (End)" & @CRLF) EndFunc ;==>GetPlayerDATA() #EndRegion ;==> Internal Func While 1 Local $Msg = GUIGetCursorInfo($PlayerGUI) If $Msg[4] = $Close Then If $Msg[2] = 1 Then _GUICtrlButton_SetImage($Close, @ScriptDir & "\AutoIt Radio Player\Img\Closep.bmp");MousePressed Else _GUICtrlButton_SetImage($Close, @ScriptDir & "\AutoIt Radio Player\Img\Closeo.bmp");MouseOver EndIf Else _GUICtrlButton_SetImage($Close, @ScriptDir & "\AutoIt Radio Player\Img\Close.bmp");Nothing EndIf If $Play = 1 Then If $Msg[4] = $PlayPause Then If $Msg[2] = 1 Then _GUICtrlButton_SetImage($PlayPause, @ScriptDir & "\AutoIt Radio Player\Img\stopp.bmp");MousePressed Else _GUICtrlButton_SetImage($PlayPause, @ScriptDir & "\AutoIt Radio Player\Img\stopo.bmp");MouseOver EndIf Else _GUICtrlButton_SetImage($PlayPause, @ScriptDir & "\AutoIt Radio Player\Img\stop.bmp");Nothing EndIf Else If $Msg[4] = $PlayPause Then If $Msg[2] = 1 Then _GUICtrlButton_SetImage($PlayPause, @ScriptDir & "\AutoIt Radio Player\Img\playp.bmp");MousePressed Else _GUICtrlButton_SetImage($PlayPause, @ScriptDir & "\AutoIt Radio Player\Img\playo.bmp");MouseOver EndIf Else _GUICtrlButton_SetImage($PlayPause, @ScriptDir & "\AutoIt Radio Player\Img\play.bmp");Nothing EndIf EndIf Sleep(100) WEnd ;1075 v0.0.0.8 30/04/2016 01:55
  4. Here's a hacky script I made to make the music key on my keyboard click the back button on my Chrome browser. You need to compile the script in to an exe, and associate "cda" file extension to the executable. Note- this also means you can reassign the music key on your keyboard to whatever executable you want using this method! AutoItSetOption("WinTitleMatchMode", 2) HotKeySet("{Escape}", "exitScript") $chromePos = WinGetPos("Chrome") If (@error <> 0) Then ConsoleWriteError("Can not find Chrome window - WinGetPos returned @error: " & @error & @CRLF) Exit EndIf $originalMousePos = MouseGetPos() MouseClick("primary", $chromePos[0] + 20, $chromePos[1] + 45, 1, 2) MouseMove($originalMousePos[0], $originalMousePos[1], 2) Func exitScript() ConsoleWrite("Exiting script..." & @CRLF) Exit EndFuncYay AutoIt3 community. Unfortunately, for the most part at work I've moved on to OSX machines (meh). Seems like that's what all the companies are developing on lately.
  5. MusicIt

    Version Source 1.0.0

    120 downloads

    This is a Musicplayer, with streamingfunction, 2 decks and 2 playlists, so you can play 3 audiolines to 3 different audiooutputs. there is also a livesearch (searching while typing) and the fileexplorer treeview/listview udf (written by me) is used (littlebit modified for playlists entry). There is also a simple mode with just one playlist. Also there is a full colormanagement to personalize it.
  6. MusicIt

    This is a Musicplayer, with streamingfunction, 2 decks and 2 playlists, so you can play 3 audiolines to 3 different audiooutputs. there is also a livesearch (searching while typing) and the fileexplorer treeview/listview udf (written by me) is used (littlebit modified for playlists entry). There is also a simple mode with just one playlist. Also there is a full colormanagement to personalize it. I translated the Programm in english to post it here. If you like it, please leave me a comment, also if you have any suggestions to make it better or if you found bugs. Example Images: For more information and direct executables, please visit my website: http://kanashius.de/?page=musicIt MusicIt_source.zip
  7. libZPlay UDF

    Hi all. some time without share something. today I made this UDF because I really like this library so I wanted to share with all you. libZPlay (Win32) Version 2.02 06. May, 2010. This is multimedia library for playing mp3, mp2, mp1, ogg, flac, ac3, aac, oga, wav and pcm files and streams. New: version 2.02 can also record sound from soundcard and encode into disk file with mp3, ogg, flac, aac or wav encoder. For more information look into the LibzPlay Page.txt file into the zip file. About the libZPlay UDF supports playing mp3, ogg, AAC, AC-3, flac, wav, pcmUNICODE support for functions using strings ( filename, error messages, ID3 info, ... ) REVERSE PLAYING (you can play song backward in real time, "real" backward playing without predecoding in PCM) built in echo and reverb sound processor internal volume control (without affecting wave out device volume) pulling VU meter data (you can simply create VU meter) built in FFT spectrum graph, library will draw complete spectrum graph on your window ibzPlayExample.au3 Capture: LibzPlayAU3.zip File contents libZPlay.au3libzPlayExample.au3libZPlayform.kxf LibzPlay Page.txt License.txt- From the libZPlay SDKReadme.txt - From the libZPlay SDKChangeLog.txt - From the libZPlay SDKlibzplay.dll - From the libZPlay SDKlibzplay.chm - From the libZPlay SDKlibzplay.chw - From the libZPlay SDK Download: LibzPlayAU3.zip Saludos
  8. Check out this online jukebox that I created with autoit. <snip>
  9. Subsonic jukebox control

    Here is the result of my playing around with Subsonic's REST API tonight. This script searches for a song in the Subsonic library, queues it in the jukebox playlist, starts it playing on the server, then stops it and clears the playlist. This requires Subsonic. At present, they include the REST API that this script uses in the 30-day trial, but then it goes away unless you upgrade to Subsonic Premium. Change the variables at the beginning to represent your server URL and user account. (My server happened to be running on the same machine on port 85.) The account must exist in Subsonic and must have permission to play files in jukebox mode (which is not a default permission). Lastly, you probably want to change the parameters in the _SubsonicJukeboxAddSong function call to represent a song that is actually on the server. #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.12.0 Author: ToasterKing Script Function: #ce ---------------------------------------------------------------------------- #Region ; --- Include files #include <Array.au3> #include <FileConstants.au3> #include <StringConstants.au3> #include <_XMLDomWrapper.au3> #EndRegion ; --- Include files Global $sSubsonicAddr = "http://localhost:85" Local $sSubsonicJukeboxName = "BlabberBox" Local $sSubsonicUsername = "jukeboxuser" Local $sSubsonicPassword = "j00kthis!" Global $sSubsonicBaseParams = "u=" & $sSubsonicUsername & "&p=" & $sSubsonicPassword & "&c=" & $sSubsonicJukeboxName ; Add a song to the jukebox playlist _SubsonicJukeboxAddSong("catch a fire","haddaway") ; Start playing _SubsonicCmd($sSubsonicAddr & "/rest/jukeboxControl.view?" & $sSubsonicBaseParams & "&v=1.10.2&action=start") ; Wait Sleep(15000) For $x = 1 To 5 If _SubsonicJukeboxIsPlaying() Then MsgBox(0,"","Subsonic jukebox is still playing!",2) Else MsgBox(0,"","Subsonic jukebox is no longer playing.",2) Exit EndIf If $x = 3 Then _SubsonicCmd($sSubsonicAddr & "/rest/jukeboxControl.view?" & $sSubsonicBaseParams & "&v=1.10.2&action=clear") ; Clear playlist and stop playing Sleep(5000) Next ; #FUNCTION# ==================================================================================================================== ; Name ..........: _SubsonicCmd ; Description ...: Makes a general REST API request. ; Syntax ........: _SubsonicCmd($sRequest) ; Parameters ....: $sRequest - The complete request URL. ; Return values .: Success: 1 ; Failure: 0 and sets @error to 1 ; Author ........: Your Name ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _SubsonicCmd($sRequest) Local $bSubsonicResult,$sSubsonicResult,$sSubsonicReqStatus ConsoleWrite("Sending REST API request: " & $sRequest & @CRLF) $bSubsonicResult = InetRead($sRequest,1) If @error Then ConsoleWrite("Error " & @error & " in InetRead." & @CRLF) Return SetError(1,0,"") EndIf $sSubsonicResult = BinaryToString($bSubsonicResult,4) ; Convert the XML response to a string so it can be parsed ;~ ConsoleWrite("REST API response from Subsonic:" & @CRLF & $sSubsonicResult & @CRLF) ; Remove the first "xmlns" attribute for the namespace because I can't figure out how to make the XML parse otherwise Local $iToRemovePosStart = StringInStr($sSubsonicResult," xmlns=""") Local $iToRemovePosEnd = StringInStr($sSubsonicResult,"""",0,1,$iToRemovePosStart + 8) Local $sSubsonicResultEdited = StringLeft($sSubsonicResult,$iToRemovePosStart - 1) & StringTrimLeft($sSubsonicResult,$iToRemovePosEnd) ConsoleWrite("REST API response from Subsonic after editing:" & @CRLF & StringStripWS($sSubsonicResultEdited,$STR_STRIPTRAILING) & @CRLF) ;~ _Setdebug(True) ; Turn on XML debugging _XMLLoadXML($sSubsonicResultEdited) ; Load the XML response for parsing If @error Then ConsoleWrite("Error " & @error & " in _XMLLoadXML" & @CRLF) Return SetError(1,0,"") EndIf ConsoleWrite("Using MSXML version " & _XMLGetDomVersion() & " for parsing." & @CRLF) $sSubsonicReqStatus = _XMLGetAttrib("//subsonic-response","status") ; Get the "status" attribute to see if the command worked. If $sSubsonicReqStatus = "ok" Then ConsoleWrite("The REST API returned success for this request!" & @CRLF) Else ConsoleWrite("Status 'ok' not found in response! See the debug entries for the full XML response." & @CRLF) Return SetError(1,0,"") EndIf Return SetError(0,0,1) ; Success! EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _SubsonicJukeboxAddSong ; Description ...: Searches for a song on the Subsonic server and adds it/them to the jukebox playlist. ; Syntax ........: _SubsonicJukeboxAddSong($sSong[, $sArtist = ""[, $sAlbum = ""[, $iSongsToAddMax = 1]]]) ; Parameters ....: $sSong - Complete, exact name of the song to find (case insensitive) ; $sArtist - [optional] Complete name of the artist name to match (case insensitive) ; $sAlbum - [optional] Complete name of the album name to match (case insensitive) ; $iSongsToAddMax - [optional] Maximum number of songs to match and add to the playlist. Default is 1. ; 0 means no limit, although there is a hardcoded limit on number of search results ; returned in the function. ; Return values .: Success: 1 ; Failure: 0 and sets @error: ; 1 - General error (check the log) ; 2 - Zero search results ; Author ........: ToasterKing ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _SubsonicJukeboxAddSong($sSong,$sArtist = "",$sAlbum = "",$iSongsToAddMax = 1) Local $bSubsonicResult,$sSubsonicResult,$sRequest,$sSubsonicReqStatus ConsoleWrite("Searching for requested song '" & $sSong & "', artist '" & $sArtist & "', album '" & $sAlbum & "'." & @CRLF) ; Assemble the request URL (note: hardcoded here to 50 search results) $sRequest = $sSubsonicAddr & "/rest/search3.view?" & $sSubsonicBaseParams & "&v=1.10.2&query=%22" & _URLEncode($sSong) & "%22&songCount=50&artistCount=0&albumCount=0" ConsoleWrite("Sending REST API request: " & $sRequest & @CRLF) ; Make the HTTP request $bSubsonicResult = InetRead($sRequest,1) If @error Then ConsoleWrite("Error " & @error & " in InetRead." & @CRLF) Return SetError(1,0,"") EndIf $sSubsonicResult = BinaryToString($bSubsonicResult,4) ; Convert the XML response to a string so it can be parsed ;~ ConsoleWrite("REST API response from Subsonic:" & @CRLF & $sSubsonicResult & @CRLF) ; Remove the first "xmlns" attribute for the namespace because I can't figure out how to make the XML parse otherwise Local $iToRemovePosStart = StringInStr($sSubsonicResult," xmlns=""") Local $iToRemovePosEnd = StringInStr($sSubsonicResult,"""",0,1,$iToRemovePosStart + 8) Local $sSubsonicResultEdited = StringLeft($sSubsonicResult,$iToRemovePosStart - 1) & StringTrimLeft($sSubsonicResult,$iToRemovePosEnd) ConsoleWrite("REST API response from Subsonic after editing:" & @CRLF & StringStripWS($sSubsonicResultEdited,$STR_STRIPTRAILING) & @CRLF) ;~ _Setdebug(True) ; Turn on XML debugging _XMLLoadXML($sSubsonicResultEdited) ; Load the XML response for parsing If @error Then ConsoleWrite("Error " & @error & " in _XMLLoadXML" & @CRLF) Return SetError(1,0,"") EndIf ConsoleWrite("Using MSXML version " & _XMLGetDomVersion() & " for parsing." & @CRLF) $sSubsonicReqStatus = _XMLGetAttrib("//subsonic-response","status") ; Get the "status" attribute to see if the command worked. If $sSubsonicReqStatus = "ok" Then ConsoleWrite("The REST API returned success for this request!" & @CRLF) Else ConsoleWrite("Status 'ok' not found in response! See the debug entries for the full XML response." & @CRLF) Return SetError(1,0,"") EndIf ; Get ready to loop through all the search results. Dim $aAttrName[1], $aAttrValue[1], $aStats[0][5], $iCurrentId, $iSongMatched = 0 for $x = 1 to 5000 _XMLGetAllAttrib ("//subsonic-response/searchResult3/*["&$x&"]",$aAttrName,$aAttrValue ); by index, show all attribs. xml indexes are 0 based. if @error Then ExitLoop ; No more results found. ;~ _ArrayDisplay($aAttrName,"Attrib Names") ;~ _ArrayDisplay($aAttrValue,"Attrib Value") $iCurrentId = _XMLGetAttrib("//subsonic-response/searchResult3/*["&$x&"]","id") ; Get the ID attribute of the current search result. ; Compare song of the attributes of the search result to the ones specified. If _XMLGetAttrib("//subsonic-response/searchResult3/*["&$x&"]","type") = "music" And _ _XMLGetAttrib("//subsonic-response/searchResult3/*["&$x&"]","title") = $sSong And _ ($sArtist = "" Or _XMLGetAttrib("//subsonic-response/searchResult3/*["&$x&"]","artist") = $sArtist) And _ ($sAlbum = "" Or _XMLGetAttrib("//subsonic-response/searchResult3/*["&$x&"]","album") = $sAlbum) And _ _XMLGetAttrib("//subsonic-response/searchResult3/*["&$x&"]","type") = "music" Then ConsoleWrite("Song " & $iCurrentId & " matches the criteria." & @CRLF) $iSongMatched += 1 ; Increment the counter If _SubsonicCmd($sSubsonicAddr & "/rest/jukeboxControl.view?" & $sSubsonicBaseParams & "&v=1.10.2&action=add&id=" & $iCurrentId) Then ConsoleWrite("Song " & $iCurrentId & " added to the jukebox playlist." & @CRLF) Else ConsoleWrite("Song " & $iCurrentId & " could not be added to the jukebox playlist." & @CRLF) EndIf If $iSongsToAddMax > 0 And $iSongMatched >= $iSongsToAddMax Then ExitLoop ; If the number of matching songs to add has been satisfied, stop adding. Else ConsoleWrite("Song " & $iCurrentId & " doesn't match the criteria; continuing." & @CRLF) EndIf next If $iSongMatched Then Return SetError(0,0,1) Else ConsoleWrite("No songs were found matching the criteria." & @CRLF) Return SetError(2,0,0) EndIf EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _SubsonicJukeboxIsPlaying ; Description ...: Check whether Subsonic jukebox is playing music. ; Syntax ........: _SubsonicJukeboxIsPlaying() ; Parameters ....: ; Return values .: Success: 1 - Playing ; 0 - Paused/stopped ; Failure: 0 and sets @error to 1. ; Author ........: ToasterKing ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _SubsonicJukeboxIsPlaying() Local $bSubsonicResult,$sSubsonicResult,$sRequest,$sSubsonicReqStatus ConsoleWrite("Querying whether Subsonic jukebox is playing." & @CRLF) ; Assemble the request URL (note: hardcoded here to 50 search results) $sRequest = $sSubsonicAddr & "/rest/jukeboxControl.view?" & $sSubsonicBaseParams & "&v=1.10.2&action=status" ConsoleWrite("Sending REST API request: " & $sRequest & @CRLF) ; Make the HTTP request $bSubsonicResult = InetRead($sRequest,1) If @error Then ConsoleWrite("Error " & @error & " in InetRead." & @CRLF) Return SetError(1,0,"") EndIf $sSubsonicResult = BinaryToString($bSubsonicResult,4) ; Convert the XML response to a string so it can be parsed ;~ ConsoleWrite("REST API response from Subsonic:" & @CRLF & $sSubsonicResult & @CRLF) ; Remove the first "xmlns" attribute for the namespace because I can't figure out how to make the XML parse otherwise Local $iToRemovePosStart = StringInStr($sSubsonicResult," xmlns=""") Local $iToRemovePosEnd = StringInStr($sSubsonicResult,"""",0,1,$iToRemovePosStart + 8) Local $sSubsonicResultEdited = StringLeft($sSubsonicResult,$iToRemovePosStart - 1) & StringTrimLeft($sSubsonicResult,$iToRemovePosEnd) ConsoleWrite("REST API response from Subsonic after editing:" & @CRLF & StringStripWS($sSubsonicResultEdited,$STR_STRIPTRAILING) & @CRLF) ;~ _Setdebug(True) ; Turn on XML debugging _XMLLoadXML($sSubsonicResultEdited) ; Load the XML response for parsing If @error Then ConsoleWrite("Error " & @error & " in _XMLLoadXML" & @CRLF) Return SetError(1,0,"") EndIf ConsoleWrite("Using MSXML version " & _XMLGetDomVersion() & " for parsing." & @CRLF) $sSubsonicReqStatus = _XMLGetAttrib("//subsonic-response","status") ; Get the "status" attribute to see if the command worked. If $sSubsonicReqStatus = "ok" Then ConsoleWrite("The REST API returned success for this request!" & @CRLF) Else ConsoleWrite("Status 'ok' not found in response! See the debug entries for the full XML response." & @CRLF) Return SetError(1,0,"") EndIf If _XMLGetAttrib("//subsonic-response/jukeboxStatus","playing") = "true" Then ConsoleWrite("Subsonic Jukebox is playing." & @CRLF) Return SetError(0,0,1) Else ConsoleWrite("Subsonic Jukebox is not playing." & @CRLF) Return SetError(0,0,0) EndIf EndFunc ;=============================================================================== ; _URLEncode() ; Description: : Encodes a string to be URL-friendly ; Parameter(s): : $toEncode - The String to Encode ; : $encodeType = 0 - Practical Encoding (Encode only what is necessary) ; : = 1 - Encode everything ; : = 2 - RFC 1738 Encoding - http://www.ietf.org/rfc/rfc1738.txt ; Return Value(s): : The URL encoded string ; Author(s): : nfwu ; Note(s): : - ; ;=============================================================================== Func _URLEncode($toEncode, $encodeType = 0) Local $strHex = "", $iDec Local $aryChar = StringSplit($toEncode, "") If $encodeType = 1 Then;;Encode EVERYTHING For $i = 1 To $aryChar[0] $strHex = $strHex & "%" & Hex(Asc($aryChar[$i]), 2) Next Return $strHex ElseIf $encodeType = 0 Then;;Practical Encoding For $i = 1 To $aryChar[0] $iDec = Asc($aryChar[$i]) if $iDec <= 32 Or $iDec = 37 Then $strHex = $strHex & "%" & Hex($iDec, 2) Else $strHex = $strHex & $aryChar[$i] EndIf Next Return $strHex ElseIf $encodeType = 2 Then;;RFC 1738 Encoding For $i = 1 To $aryChar[0] If Not StringInStr("$-_.+!*'(),;/?:@=&abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890", $aryChar[$i]) Then $strHex = $strHex & "%" & Hex(Asc($aryChar[$i]), 2) Else $strHex = $strHex & $aryChar[$i] EndIf Next Return $strHex EndIf EndFunc This script uses _XMLDomWrapper.au3 by Stephen Podhajecki. Since it's been a bit hard to track down a working link to this in the past, I've just included the version I used here. #include-once ; #INDEX# ====================================================================== ; Title .........: _XMLDomWrapper ; AutoIt Version : 3.2.3++ ; Language ......: English ; Description ...: Functions to use for reading and writing XML using msxml. ; Author ........: Stephen Podhajecki Eltorro ; ============================================================================== ; XML DOM Wrapper functions #cs defs to add to au3.api _XMLCreateFile Creates an XML file with the given name and root. _XMLFileOpen Creates an instance of an XML file. _XMLSaveDoc Save the xml doc, use $iForce = 1 to force save if AutoSave is off. ; ========================================================================== _XMLGetChildNodes Selects XML child Node(s) of an element based on XPath input from root node. _XMLGetNodeCount Get node count for specified path and type. _XMLGetPath Returns a nodes full path based on XPath input from root node. ; ========================================================================== _XMLSelectNodes Selects XML Node(s) based on XPath input from root node. _XMLGetField Get XML Field(s) based on XPath input from root node. _XMLGetValue Get XML Field based on XPath input from root node. _XMLGetChildText Selects XML child Node(s) of an element based on XPath input from root node. _XMLUpdateField Update existing node(s) based on XPath specs. _XMLReplaceChild Replaces a node with a new node. ; ========================================================================== _XMLDeleteNode Delete specified XPath node. _XMLDeleteAttr Delete attribute for specified XPath _XMLDeleteAttrNode Delete attribute node for specified XPath ; ========================================================================== _XMLGetAttrib Get XML attribute based on XPath input from root node. _XMLGetAllAttrib Get all XML Field(s) attributes based on XPath input from root node. _XMLGetAllAttribIndex Get all XML Field(s) attributes based on Xpathn and specific index. _XMLSetAttrib Set XML Field(s) attributes based on XPath input from root node. ; ========================================================================== _XMLCreateCDATA Create a CDATA SECTION node directly under root. _XMLCreateComment Create a COMMENT node at specified path. _XMLCreateAttrib Creates an attribute for the specified node. ; ========================================================================== _XMLCreateRootChild Create node directly under root. _XMLCreateRootNodeWAttr Create a child node under root node with attributes. _XMLCreateChildNode Create a child node under the specified XPath Node. _XMLCreateChildWAttr Create a child node under the specified XPath Node with Attributes. ; ========================================================================== _XMLSchemaValidate Validate a document against a DTD. _XMLGetDomVersion Returns the XSXML version currently in use. _XMLError Sets or Gets XML error message generated by XML functions. _XMLUDFVersion Returns the UDF Version number. _XMLTransform Transfroms the document using built-in sheet or xsl file passed to function. _XMLNodeExists Checks for the existence of the specified path. ; ========================================================================== _XMLSetAutoFormat Turn auto indenting on or off. _XMLSetAutoSave Set the automatic save to on or off. #ce ; #VARIABLES# ================================================================== Global Const $_XMLUDFVER = "1.0.3.97" Global Const $NODE_ELEMENT = 1 Global Const $NODE_ATTRIBUTE = 2 Global Const $NODE_TEXT = 3 Global Const $NODE_CDATA_SECTION = 4 Global Const $NODE_ENTITY_REFERENCE = 5 Global Const $NODE_ENTITY = 6 Global Const $NODE_PROCESSING_INSTRUCTION = 7 Global Const $NODE_COMMENT = 8 Global Const $NODE_DOCUMENT = 9 Global Const $NODE_DOCUMENT_TYPE = 10 Global Const $NODE_DOCUMENT_FRAGMENT = 11 Global Const $NODE_NOTATION = 12 Global $strFile Global $oXMLMyError ;COM error handler OBJ ; Initialize SvenP 's error handler Global $sXML_error Global $fDEBUGGING Global $DOMVERSION = -1 Global $objDoc Global $fXMLAUTOSAVE = True ;auto save updates Global $fADDFORMATTING = True ;auto indent ; ============================================================================== ; #FUNCTION# =================================================================== ; Name ..........: _XMLFileOpen ; Description ...: Creates an instance of an XML file. ; Syntax.........: _XMLFileOpen($strXMLFile[, $strNameSpc = ""[, $iVer = -1[, $fValOnParse = True]]]) ; Parameters ....: $strXMLFile - the XML file to open ; $strNameSpc - the namespace to specifiy if the file uses one. ; $iVer - specifically try to use the version supplied here. ; $fValOnParse - validate the document as it is being parsed ; Return values .: Success - 1 ; Failure - -1 and set @error to: ; |0 - No error ; |1 - Parse error, @Extended = MSXML reason ; |2 - No object ; Author ........: Stephen Podhajecki <gehossafats@netmdc.com> ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; [yes/no] ; ============================================================================== Func _XMLFileOpen($strXMLFile, $strNameSpc = "", $iVer = -1, $fValOnParse = True) ;==== pick your poison If $iVer <> -1 Then If $iVer > -1 And $iVer < 7 Then $objDoc = ObjCreate("Msxml2.DOMDocument." & $iVer & ".0") If IsObj($objDoc) Then $DOMVERSION = $iVer EndIf Else MsgBox(266288, "Error:", "Failed to create object with MSXML version " & $iVer) SetError(1) Return 0 EndIf Else For $x = 8 To 0 Step -1 If FileExists(@SystemDir & "\msxml" & $x & ".dll") Then $objDoc = ObjCreate("Msxml2.DOMDocument." & $x & ".0") If IsObj($objDoc) Then $DOMVERSION = $x ExitLoop EndIf EndIf Next EndIf If Not IsObj($objDoc) Then _XMLError("Error: MSXML not found. This object is required to use this program.") SetError(2) Return -1 EndIf ;Thanks Lukasz Suleja $oXMLMyError = ObjEvent("AutoIt.Error") If $oXMLMyError = "" Then $oXMLMyError = ObjEvent("AutoIt.Error", "_XMLCOMEerr") ; ; Initialize SvenP 's error handler EndIf $strFile = $strXMLFile $objDoc.async = False $objDoc.preserveWhiteSpace = True $objDoc.validateOnParse = $fValOnParse If $DOMVERSION > 4 Then $objDoc.setProperty("ProhibitDTD", False) $objDoc.Load($strFile) $objDoc.setProperty("SelectionLanguage", "XPath") $objDoc.setProperty("SelectionNamespaces", $strNameSpc) If $objDoc.parseError.errorCode > 0 Then ConsoleWrite($objDoc.parseError.reason & @LF) If $objDoc.parseError.errorCode <> 0 Then _XMLError("Error opening specified file: " & $strXMLFile & @CRLF & $objDoc.parseError.reason) ;Tom Hohmann 2008/02/29 SetError(1, $objDoc.parseError.errorCode, -1) $objDoc = 0 Return -1 EndIf ;Tom Hohmann 2008/02/29 Return 1 EndFunc ;==>_XMLFileOpen ; ; #FUNCTION# =================================================================== ; Name ..........: _XMLLoadXML ; Description ...: Creates an instance for a string of XML . ; Syntax.........: _XMLLoadXML($strXML[,$strNameSpc=""[, $iVer = -1[, $fValOnParse = True]]]) ; Parameters ....: $strXML - The XML to load into the document ; $strNameSpc - the namespace to specifiy if the file uses one. ; $iVer - specifically try to use the version supplied here. ; $fValOnParse - Set the MSXML ValidateOnParse property ; Return values .: Success - 1 ; Failure - -1 and set @error to ; |1 - failed to create object, @Extended = MSXML reason ; |2 - no object found (MSXML required for _XML functions ; Author ........: Stephen Podhajecki <gehossafats@netmdc.com>,Lukasz Suleja,Tom Hohmann ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; [yes/no] ; ============================================================================== Func _XMLLoadXML($strXML, $strNameSpc = "", $iVer = -1, $fValOnParse = True) If $iVer <> -1 Then If $iVer > -1 And $iVer < 7 Then $objDoc = ObjCreate("Msxml2.DOMDocument." & $iVer & ".0") If IsObj($objDoc) Then $DOMVERSION = $iVer EndIf Else MsgBox(266288, "Error:", "Failed to create object with MSXML version " & $iVer) SetError(1) Return 0 EndIf Else For $x = 8 To 0 Step -1 If FileExists(@SystemDir & "\msxml" & $x & ".dll") Then $objDoc = ObjCreate("Msxml2.DOMDocument." & $x & ".0") If IsObj($objDoc) Then $DOMVERSION = $x ExitLoop EndIf EndIf Next EndIf If Not IsObj($objDoc) Then _XMLError("Error: MSXML not found. This object is required to use this program.") SetError(2) Return -1 EndIf ;Thanks Lukasz Suleja $oXMLMyError = ObjEvent("AutoIt.Error") If $oXMLMyError = "" Then $oXMLMyError = ObjEvent("AutoIt.Error", "_XMLCOMEerr") ; ; Initialize SvenP 's error handler EndIf $objDoc.async = False $objDoc.preserveWhiteSpace = True $objDoc.validateOnParse = $fValOnParse If $DOMVERSION > 4 Then $objDoc.setProperty("ProhibitDTD", False) $objDoc.LoadXml($strXML) $objDoc.setProperty("SelectionLanguage", "XPath") $objDoc.setProperty("SelectionNamespaces", $strNameSpc); "xmlns:ms='urn:schemas-microsoft-com:xslt'" If $objDoc.parseError.errorCode <> 0 Then _XMLError("Error loading the XML data: " & @CRLF & $objDoc.parseError.reason) ;Tom Hohmann 2008/02/29 SetError(1, $objDoc.parseError.errorCode, -1) Return -1 EndIf ;Tom Hohmann 2008/02/29 Return 1 EndFunc ;==>_XMLLoadXML ; #FUNCTION# =================================================================== ; Name ..........: _XMLCreateFile ; Description ...: Create a new blank metafile with header. ; Syntax.........: _XMLCreateFile($strPath, $strRoot[, $fOverwrite = False[, $fUTF8 = False[, $ver = -1]]]) ; Parameters ....: $strPath - The xml filename with full path to create ; $strRoot - The root of the xml file to create ; $fOverwrite - boolean flag to auto overwrite existing file of same name. ; $fUTF8 - boolean flag to specify UTF-8 encoding in header. ; $iVer - specifically try to use the version supplied here. ; Return values .: Success - 1 ; Failure - -1 and sets @Error to: ; |0 - No error ; |1 - Failed to create file ; |2 - No object ; |3 - File creation failed MSXML error ; |4 - File exists ; Author ........: Stephen Podhajecki <gehossafats@netmdc.com> ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; [yes/no] ; ============================================================================== Func _XMLCreateFile($strPath, $strRoot, $fOverwrite = False, $fUTF8 = False, $ver = -1) Local $retval, $fe, $objPI, $rootElement $fe = FileExists($strPath) If $fe And Not $fOverwrite Then $retval = (MsgBox(4097, "File Exists:", "The specified file exits." & @CRLF & "Click OK to overwrite file or cancel to exit.")) If $retval = 1 Then FileCopy($strPath, $strPath & @YEAR & "-" & @MON & "-" & @MDAY & "_" & @HOUR & "-" & @MIN & "-" & @SEC & ".bak", 1) FileDelete($strPath) $fe = False Else _XMLError("Error failed to create file: " & $strPath & @CRLF & "File exists.") SetError(4) Return -1 EndIf Else FileCopy($strPath, $strPath & ".old", 1) FileDelete($strPath) $fe = False EndIf If $fe = False Then If $ver <> -1 Then If $ver > -1 And $ver < 7 Then $objDoc = ObjCreate("Msxml2.DOMDocument." & $ver & ".0") If IsObj($objDoc) Then $DOMVERSION = $ver EndIf Else MsgBox(266288, "Error:", "Failed to create object with MSXML version " & $ver) SetError(3) Return 0 EndIf Else For $x = 8 To 0 Step -1 If FileExists(@SystemDir & "\msxml" & $x & ".dll") Then $objDoc = ObjCreate("Msxml2.DOMDocument." & $x & ".0") If IsObj($objDoc) Then $DOMVERSION = $x ExitLoop EndIf EndIf Next EndIf If Not IsObj($objDoc) Then Return SetError(2) EndIf If $fUTF8 Then $objPI = $objDoc.createProcessingInstruction("xml", "version=""1.0"" encoding=""UTF-8""") Else $objPI = $objDoc.createProcessingInstruction("xml", "version=""1.0""") EndIf $objDoc.appendChild($objPI) $rootElement = $objDoc.createElement($strRoot) $objDoc.documentElement = $rootElement $objDoc.save($strPath) ;_XMLSaveDoc (,1) If $objDoc.parseError.errorCode <> 0 Then _XMLError("Error Creating specified file: " & $strPath) ; Tom Hohmann 2008/02/29 SetError(1, $objDoc.parseError.errorCode, -1) Return -1 EndIf Return 1 Else _XMLError("Error! Failed to create file: " & $strPath) SetError(1) Return 0 EndIf Return 1 EndFunc ;==>_XMLCreateFile ; #FUNCTION# =================================================================== ; Name ..........: _XMLSelectNodes ; Description ...: Selects XML Node(s) based on XPath input from root node. ; Syntax.........: _XMLSelectNodes($strXPath) ; Parameters ....: $strXPath - xml tree path from root node (root/child/child..) ; Return values .: Success - An array of Nodes(count is in first element) ; Failure - -1 and set @Error = 1 ; Author ........: Stephen Podhajecki <gehossafats@netmdc.com> ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; [yes/no] ; ============================================================================== Func _XMLSelectNodes($strXPath) If Not IsObj($objDoc) Then _XMLError("No object passed to function _XMLSelectNodes") Return SetError(2, 0, -1) EndIf Local $objNode, $objNodeList, $arrResponse[1], $xmlerr $objNodeList = $objDoc.selectNodes($strXPath) If Not IsObj($objNodeList) Then _XMLError("\nNo matching nodes found") Return SetError(1, 0, -1) EndIf If $objNodeList.length < 1 Then _XMLError("\nNo matching nodes found") Return SetError(1, 0, -1) EndIf For $objNode In $objNodeList _XMLArrayAdd($arrResponse, $objNode.nodeName) _DebugWrite($objNode.nodeName) _DebugWrite($objNode.namespaceURI) Next $arrResponse[0] = $objNodeList.length Return $arrResponse _XMLError("Error Selecting Node(s): " & $strXPath & $xmlerr) Return SetError(1, 0, -1) EndFunc ;==>_XMLSelectNodes ; #FUNCTION# =================================================================== ; Name ..........: _XMLGetField ; Description ...: Get XML Field(s) based on XPath input from root node. ; Syntax.........: _XMLGetField($strXPath) ; Parameters ....: $strXPath - The XML tree path from root node (root/child/child..) ; Return values .: Success - An array of fields text values(count is in first element) ; Failure - -1 and sets @Error = 1 ; Author ........: Stephen Podhajecki <gehossafats@netmdc.com> ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; [yes/no] ; ============================================================================== Func _XMLGetField($strXPath) If Not IsObj($objDoc) Then _XMLError("No object passed to function _XMLGetField") Return SetError(1, 2, -1) EndIf Local $objNodeList, $arrResponse[1], $xmlerr, $szNodePath $objNodeList = $objDoc.selectSingleNode($strXPath) If Not IsObj($objNodeList) Then _XMLError("\nNo Matching Nodes found") $arrResponse[0] = 0 Return SetError(2, 0, -1) EndIf If $objNodeList.hasChildNodes() Then Local $count = $objNodeList.childNodes.length For $x = 1 To $count $objChild = $objNodeList.childNodes($x) _DebugWrite("ParentNode=" & $objNodeList.parentNode.nodeType) If $objNodeList.parentNode.nodeType = $NODE_DOCUMENT Then $szNodePath = "/" & $objNodeList.baseName & "/*[" & $x & "]" Else $szNodePath = $objNodeList.baseName & "/*[" & $x & "]" EndIf $aRet = _XMLGetValue($szNodePath) If IsArray($aRet) Then If UBound($aRet) > 1 Then _XMLArrayAdd($arrResponse, $aRet[1]) _DebugWrite("GetField>Text:" & $aRet[1]) EndIf Else _XMLArrayAdd($arrResponse, "") _DebugWrite("GetField>Text:" & "") EndIf Next $arrResponse[0] = UBound($arrResponse) - 1 Return $arrResponse Else $arrResponse[0] = 0 _XMLError("\nNo Child Nodes found") Return SetError(1, 0, -1) EndIf _XMLError("Error Selecting Node(s): " & $strXPath & $xmlerr) Return SetError(1, 0, -1) EndFunc ;==>_XMLGetField ; #FUNCTION# =================================================================== ; Name ..........: _XMLGetValue ; Description ...: Get XML values based on XPath input from root node. ; Syntax.........: _XMLGetValue($strXPath) ; Parameters ....: $strXPath - xml tree path from root node (root/child/child..) ; Return values .: Success - An array of fields text values(count is in first element) ; Failure - -1 and sets @Error = 1, @Extended to: ; |0 - No matching node. ; |1 - No object passed. ; Author ........: Stephen Podhajecki <gehossafats@netmdc.com> ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; [yes/no] ; ============================================================================== Func _XMLGetValue($strXPath) If Not IsObj($objDoc) Then _XMLError("No object passed to function _XMLGetValue") Return SetError(1, 1, -1) EndIf Local $objNodeList, $arrResponse[1], $objNodeChild, $xmlerr _DebugWrite("GetValue>$strXPath:" & $strXPath) $objNodeList = $objDoc.documentElement.selectNodes($strXPath) If $objNodeList.length > 0 Then _DebugWrite("GetValue list length:" & $objNodeList.length) For $objNode In $objNodeList If $objNode.hasChildNodes() = False Then _XMLArrayAdd($arrResponse, $objNode.nodeValue) Else For $objNodeChild In $objNode.childNodes() If $objNodeChild.nodeType = $NODE_CDATA_SECTION Then _XMLArrayAdd($arrResponse, $objNodeChild.data) _DebugWrite("GetValue>CData:" & $objNodeChild.data) ElseIf $objNodeChild.nodeType = $NODE_TEXT Then _XMLArrayAdd($arrResponse, $objNodeChild.Text) _DebugWrite("GetValue>Text:" & $objNodeChild.Text) EndIf Next EndIf Next $arrResponse[0] = UBound($arrResponse) - 1 Return $arrResponse Else $xmlerr = @CRLF & "No matching node(s)found!" Return SetError(1, 0, -1) EndIf _XMLError("Error Retrieving: " & $strXPath & $xmlerr) Return SetError(1, 0, -1) EndFunc ;==>_XMLGetValue ; #FUNCTION# =================================================================== ; Name ..........: _XMLDeleteNode ; Description ...: Deletes XML Node based on XPath input from root node. ; Syntax.........: _XMLDeleteNode($strXPath) ; Parameters ....: $strXPath - The XML tree path from root node (root/child/child..) ; Return values .: Success - 1 ; Failure - -1 and sets @Error to: ; |0 - No error ; |1 - Deletion error ; |2 - No object passed ; Author ........: Stephen Podhajecki <gehossafats@netmdc.com> ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; [yes/no] ; ============================================================================== Func _XMLDeleteNode($strXPath) If Not IsObj($objDoc) Then _XMLError("No object passed to function _XMLDeleteNode") Return SetError(2, 0, -1) EndIf Local $objNode, $xmlerr $objNode = $objDoc.selectNodes($strXPath) If Not IsObj($objNode) Then $xmlerr = @CRLF & "Node Not found" If @error = 0 Then For $objChild In $objNode If $objChild.hasChildNodes Then For $objGrandChild in $objChild.childNodes If $objGrandChild.nodeType = $NODE_TEXT Then If StringStripWS($objGrandChild.text,7) = "" Then $objChild.removeChild($objGrandChild) EndIf EndIf Next EndIf $objChild.parentNode.removeChild($objChild) Next _XMLSaveDoc($strFile) Return 1 EndIf _XMLError("Error Deleting Node: " & $strXPath & $xmlerr) Return SetError(1, 0, -1) EndFunc ;==>_XMLDeleteNode ; #FUNCTION# =================================================================== ; Name ..........: _XMLDeleteAttr ; Description ...: Delete XML Attribute based on XPath input from root node. ; Syntax.........: _XMLDeleteAttr($strXPath, $strAttrib) ; Parameters ....: $strXPath - The XML tree path from root node (root/child/child..) ; $strAttribute - The attribute node to delete ; Return values .: Success - 1 ; Failure - -1 and sets @Error to: ; |0 - No error ; |1 - Error removing attribute ; |2 - No object ; Author ........: Stephen Podhajecki <gehossafats@netmdc.com> ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; [yes/no] ; ============================================================================== Func _XMLDeleteAttr($strXPath, $strAttrib) If Not IsObj($objDoc) Then _XMLError("No object passed to function _XMLDeleteAttr") Return SetError(2, 0, -1) EndIf Local $objNode, $objAttr, $xmlerr $objNode = $objDoc.selectSingleNode($strXPath) If IsObj($objNode) Then $objAttr = $objNode.getAttributeNode($strAttrib) If Not (IsObj($objAttr)) Then _XMLError("Attribute " & $strAttrib & " does not exist!") Return SetError(2, 0, -1) EndIf $objAttr = $objNode.removeAttribute($strAttrib) _XMLSaveDoc($strFile) Return 1 EndIf _XMLError("Error Removing Attribute: " & $strXPath & " - " & $strAttrib & @CRLF & $xmlerr) $xmlerr = "" Return SetError(1, 0, -1) EndFunc ;==>_XMLDeleteAttr ; #FUNCTION# =================================================================== ; Name ..........: _XMLDeleteAttrNode ; Description ...: Delete XML Attribute node based on XPath input from root node. ; Syntax.........: _XMLDeleteAttrNode($strXPath, $strAttrib) ; Parameters ....: $strXpath - XML tree path from root node (root/child/child..) ; $strAttrib - The attribute node to delete ; Return values .: Success - 1 ; Failure - -1 and sets @Error to: ; |0 - No error ; |1 - Error removing node ; |2 - No object ; Author ........: Stephen Podhajecki <gehossafats@netmdc.com> ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; [yes/no] ; ============================================================================== Func _XMLDeleteAttrNode($strXPath, $strAttrib) If Not IsObj($objDoc) Then _XMLError("No object passed to function _XMLDeleteAttrNode") Return SetError(2, 0, -1) EndIf Local $objNode, $objAttr, $xmlerr $objNode = $objDoc.selectSingleNode($strXPath) If Not IsObj($objNode) Then _XMLError("\nSpecified node not found!") Return SetError(2, 0, -1) EndIf $objAttr = $objNode.removeAttributeNode($objNode.getAttributeNode($strAttrib)) _XMLSaveDoc($strFile) If Not (IsObj($objAttr)) Then _XMLError("\nUnspecified error:!") Return SetError(1, 0, -1) EndIf Return 1 EndFunc ;==>_XMLDeleteAttrNode ; #FUNCTION# =================================================================== ; Name ..........: _XMLGetAttrib ; Description ...: Get XML Field based on XPath input from root node. ; Syntax.........: _XMLGetAttrib($strXPath, $strAttrib[, $strQuery = ""]) ; Parameters ....: $strXPath - XML tree path from root node (root/child/child..) ; $strAttrib - The attribute node to read. ; $strQuery - The query string in xml format ; Return values .: Success - The attribute value. ; Failure - -1 and sets @Error to: ; |0 - No error ; |1 - Attribute not found. ; |2 - No object ; Author ........: Stephen Podhajecki <gehossafats@netmdc.com> ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; [yes/no] ; ============================================================================== Func _XMLGetAttrib($strXPath, $strAttrib, $strQuery = "") If Not IsObj($objDoc) Then _XMLError("No object passed to function _XMLGetAttrib") Return SetError(2, 0, -1) EndIf ;Local $objNodeList, $arrResponse[1], $i, $xmlerr, $objAttr Local $objNodeList, $arrResponse, $i, $xmlerr, $objAttr $objNodeList = $objDoc.documentElement.selectNodes($strXPath & $strQuery) _DebugWrite("Get Attrib length= " & $objNodeList.length) If $objNodeList.length > 0 Then For $i = 0 To $objNodeList.length - 1 $objAttr = $objNodeList.item($i).getAttribute($strAttrib) $arrResponse = $objAttr _DebugWrite("RET>>" & $objAttr) Next Return $arrResponse EndIf $xmlerr = "\nNo qualified items found" _XMLError("Attribute " & $strAttrib & " not found for: " & $strXPath & $xmlerr) Return SetError(1, 0, -1) EndFunc ;==>_XMLGetAttrib ; #FUNCTION# =================================================================== ; Name ..........: _XMLSetAttrib ; Description ...: Set XML Field(s) based on XPath input from root node. ; Syntax.........: _XMLSetAttrib($strXPath, $strAttrib[, $strValue = ""[, $iIndex =-1]]) ; Parameters ....: $strXPath - Xml tree path from root node (root/child/child..) ; $strAttrib - The attribute to set. ; $strValue - The value to give the attribute defaults to "" ; $iIndex - Used to specify a specific index for "same named" nodes. ; Return values .: Success - Anarray of fields text values ; Failure - -1 and sets @error to 1 ; Author ........: Stephen Podhajecki <gehossafats@netmdc.com> ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; [yes/no] ; ============================================================================== Func _XMLSetAttrib($strXPath, $strAttrib, $strValue = "", $iIndex = -1) If Not IsObj($objDoc) Then _XMLError("No object passed to function _XMLSetAttrib") Return SetError(1, 8, -1) EndIf Local $objNodeList, $arrResponse[1], $i $objNodeList = $objDoc.selectNodes($strXPath) _DebugWrite(" Node list Length: " & $objNodeList.length) If @error = 0 And $objNodeList.length > 0 Then If $iIndex > 0 Then $arrResponse[0] = $objNodeList.item($iIndex).SetAttribute($strAttrib, $strValue) Else ReDim $arrResponse[$objNodeList.length] For $i = 0 To $objNodeList.length - 1 $arrResponse[$i] = $objNodeList.item($i).SetAttribute($strAttrib, $strValue) If $objDoc.parseError.errorCode <> 0 Then ExitLoop Next EndIf If $objDoc.parseError.errorCode <> 0 Then _XMLError("Error setting attribute for: " & $strXPath & @CRLF & $objDoc.parseError.reason) Return SetError(1, $objDoc.parseError.errorCode, -1) EndIf _XMLSaveDoc($strFile) Return $arrResponse EndIf _XMLError("Error failed to set attribute for: " & $strXPath & @CRLF) SetError(1) Return -1 EndFunc ;==>_XMLSetAttrib ; #FUNCTION# =================================================================== ; Name ..........: _XMLGetAllAttrib ; Description ...: Get all XML Field(s) attributes based on XPath input from root node. ; Syntax.........: _XMLGetAllAttrib($strXPath, ByRef $aName, ByRef $aValue[, $strQry = ""]) ; Parameters ....: $strXPath - XML tree path from root node (root/child/child..) ; $aName - The array to return the attrib names ; $aValue - The array to return the attrib values ; $strQuery - DOM compliant query string (not really necessary as it becomes part of the path) ; Return values .: Success - array of fields text values(number of items is in [0][0]) ; Failure - @error set to 1 and returns -1 ; Author ........: Stephen Podhajecki <gehossafats@netmdc.com> ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; [yes/no] ; ============================================================================== Func _XMLGetAllAttrib($strXPath, ByRef $aName, ByRef $aValue, $strQry = "") If Not IsObj($objDoc) Then _XMLError("No object passed to function _XMLGetAllAttrib") Return SetError(1, 9, -1) EndIf Local $objNodeList, $objQueryNodes, $objNode, $arrResponse[2][1], $i $objQueryNodes = $objDoc.selectNodes($strXPath & $strQry) If $objQueryNodes.length > 0 Then For $objNode In $objQueryNodes $objNodeList = $objNode.attributes If ($objNodeList.length) Then _DebugWrite("Get all attrib " & $objNodeList.length) ReDim $arrResponse[2][$objNodeList.length + 2] ReDim $aName[$objNodeList.length] ReDim $aValue[$objNodeList.length] For $i = 0 To $objNodeList.length - 1 $arrResponse[0][$i + 1] = $objNodeList.item($i).nodeName $arrResponse[1][$i + 1] = $objNodeList.item($i).Value $aName[$i] = $objNodeList.item($i).nodeName $aValue[$i] = $objNodeList.item($i).Value Next Else _XMLError("No Attributes found for node") Return SetError(1, 0, -1) EndIf Next $arrResponse[0][0] = $objNodeList.length Return $arrResponse EndIf _XMLError("Error retrieving attributes for: " & $strXPath & @CRLF) Return SetError(1, 0, -1) ; EndIf EndFunc ;==>_XMLGetAllAttrib ; #FUNCTION# =================================================================== ; Name ..........: _XMLUpdateField ; Description ...: Update existing node(s) based on XPath specs. ; Syntax.........: _XMLUpdateField($strXPath, $strData) ; Parameters ....: $strXPath - Path from root node. ; $strData - The data to update the node with. ; Return values .: Success - 1 ; Failure - -1 and sets @error to 1. ; Author ........: Stephen Podhajecki <gehossafats@netmdc.com> ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; [yes/no] ; ============================================================================== Func _XMLUpdateField($strXPath, $strData) If Not IsObj($objDoc) Then _XMLError("No object passed to function _XMLUpdateField") Return SetError(1, 9, -1) EndIf Local $objField, $fUpdate, $objNode #forceref $objField $objField = $objDoc.selectSingleNode($strXPath) If IsObj($objField) Then If $objField.hasChildNodes Then For $objChild In $objField.childNodes() If $objChild.nodetype = $NODE_TEXT Then $objChild.Text = $strData $fUpdate = True ExitLoop EndIf Next EndIf If $fUpdate = False Then $objNode = $objDoc.createTextNode($strData) $objField.appendChild($objNode) EndIf _XMLSaveDoc($strFile) $objField = "" Return 1 EndIf _XMLError("Failed to update field for: " & $strXPath & @CRLF) Return SetError(1, 0, -1) EndFunc ;==>_XMLUpdateField ; #FUNCTION# =================================================================== ; Name ..........: _XMLCreateCDATA ; Description ...: Create a CDATA SECTION node directly under root. ; Syntax.........: _XMLCreateCDATA($strNode, $strCDATA[, $strNameSpc = ""]) ; Parameters ....: $strNode - name of node to create ; $strData - CDATA value ; $strNameSpc - the namespace to specifiy if the xml uses one. ; Return values .: Success - 1 ; Failure - 1 and sets @Error to 1. ; Author ........: Stephen Podhajecki <gehossafats@netmdc.com> ; Modified ......: ; Remarks .......: fixme, won't append to exisiting node. must create new node. ; Related .......: ; Link ..........; ; Example .......; [yes/no] ; ============================================================================== Func _XMLCreateCDATA($strNode, $strCDATA, $strNameSpc = "") If Not IsObj($objDoc) Then _XMLError("No object passed to function _XMLCreateCDATA") Return SetError(1, 10, -1) EndIf Local $objChild, $objNode $objNode = $objDoc.createNode($NODE_ELEMENT, $strNode, $strNameSpc) If IsObj($objNode) Then If Not ($objNode.hasChildNodes()) Then _AddFormat($objDoc, $objNode) EndIf $objChild = $objDoc.createCDATASection($strCDATA) $objNode.appendChild($objChild) $objDoc.documentElement.appendChild($objNode) _XMLSaveDoc($strFile) _AddFormat($objDoc) $objChild = "" Return 1 EndIf _XMLError("Failed to create CDATA Section: " & $strNode & @CRLF) Return SetError(1, 0, -1) EndFunc ;==>_XMLCreateCDATA ; #FUNCTION# =================================================================== ; Name ..........: _XMLCreateComment ; Description ...: Create a COMMENT node at specified path. ; Syntax.........: _XMLCreateComment($strNode, $strComment) ; Parameters ....: $strNode - The name of node to create. ; $strComment - The comment to add the to the xml file. ; Return values .: Success - 1 ; Failure - -1 and @error set to 1. ; Author ........: Stephen Podhajecki <gehossafats@netmdc.com> ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; [yes/no] ; ============================================================================== Func _XMLCreateComment($strNode, $strComment) If Not IsObj($objDoc) Then _XMLError("No object passed to function _XMLCreateComment") Return SetError(1, 11, -1) EndIf Local $objChild, $objNode $objNode = $objDoc.selectSingleNode($strNode) If IsObj($objNode) Then If Not ($objNode.hasChildNodes()) Then _AddFormat($objDoc, $objNode) EndIf $objChild = $objDoc.createComment($strComment) $objNode.insertBefore($objChild, $objNode.childNodes(0)) _XMLSaveDoc($strFile) _AddFormat($objDoc) $objChild = "" Return 1 EndIf _XMLError("Failed to root child: " & $strNode & @CRLF) Return SetError(1, 0, -1) EndFunc ;==>_XMLCreateComment ; #FUNCTION# =================================================================== ; Name ..........: _XMLCreateAttribute ; Description ...: Adds an XML Attribute to specified node. ; Syntax.........: _XMLCreateAttrib($strXPath, $strAttrName[, $strAttrValue = ""]) ; Parameters ....: $strXPath - The XML tree path from root node (root/child/child..) ; $strAttrName - The attribute to set. ; $strAttrValue - The value to give the attribute, defaults to "". ; Return values .: Success - 1 ; Failure - 0 or @error set to 0 and return -1 ; Author ........: Stephen Podhajecki <gehossafats@netmdc.com> ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; [yes/no] ; ============================================================================== Func _XMLCreateAttrib($strXPath, $strAttrName, $strAttrValue = "") If Not IsObj($objDoc) Then _XMLError("No object passed to function _XMLCreateAttrib") Return SetError(1, 12, -1) EndIf Local $objNode, $objAttr, $objAttrVal, $err $objNode = $objDoc.selectSingleNode($strXPath) If IsObj($objNode) Then $objAttr = $objDoc.createAttribute($strAttrName);, $strNameSpc) $objNode.SetAttribute($strAttrName, $strAttrValue) _XMLSaveDoc($strFile) $objAttr = 0 $objAttrVal = 0 $objNode = 0 $err = $objDoc.parseError.errorCode If $err = 0 Then Return 1 EndIf _XMLError("Error creating Attribute: " & $strAttrName & @CRLF & $strXPath & " does not exist." & @CRLF) Return 0 EndFunc ;==>_XMLCreateAttrib ; #FUNCTION# =================================================================== ; Name ..........: _XMLCreateRootChild ; Description ...: Create node directly under root. ; Syntax.........: _XMLCreateRootChild($strNode[, $strData = ""[, $strNameSpc = ""]]) ; Parameters ....: $strNode - The name of node to create. ; $strData - The optional value to create ; $$strNameSpc - the namespace to specifiy if the file uses one. ; Return values .: Success - 1 ; Failure - -1 and @error set to 1. ; Author ........: Stephen Podhajecki <gehossafats@netmdc.com> ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; [yes/no] ; ============================================================================== Func _XMLCreateRootChild($strNode, $strData = "", $strNameSpc = "") If Not IsObj($objDoc) Then _XMLError("No object passed to function _XMLCreateRootChild") Return SetError(1, 14, -1) EndIf ;ConsoleWrite("_XMLCreateRootChild:"&$strNode&@LF) Local $objChild If Not ($objDoc.documentElement.hasChildNodes()) Then _AddFormat($objDoc) EndIf $objChild = $objDoc.createNode($NODE_ELEMENT, $strNode, $strNameSpc) If IsObj($objChild) Then If $strData <> "" Then $objChild.text = $strData $objDoc.documentElement.appendChild($objChild) _XMLSaveDoc($strFile) _AddFormat($objDoc) $objChild = 0 Return 1 EndIf _XMLError("Failed to root child: " & $strNode & @CRLF) Return SetError(1, 0, -1) EndFunc ;==>_XMLCreateRootChild ; #FUNCTION# =================================================================== ; Name ..........: _XMLCreateRootNodeWAttr ; Description ...: Create a child node under root node with attributes. ; Syntax.........: _XMLCreateRootNodeWAttr($strNode, $aAttr, $aVal[, $strData = ""[, $strNameSpc = ""]]) ; Parameters ....: $strNode - The node to add with attibute(s) ; $aAttr - The attribute name(s) -- can be array ; $aVal - The attribute value(s) -- can be array ; $strData - The optional value to give the node. ; Return values .: Success - 1 ; Failure - -1 and @error set to: ; |1 - Could not create node. ; |2 - Mismatch between attribute name and value counts. ; Author ........: Stephen Podhajecki <gehossafats@netmdc.com> ; Modified ......: ; Remarks .......: This function requires that each attribute name has a corresponding value. ; Related .......: ; Link ..........; ; Example .......; [yes/no] ; ============================================================================== Func _XMLCreateRootNodeWAttr($strNode, $aAttr, $aVal, $strData = "", $strNameSpc = "") If Not IsObj($objDoc) Then _XMLError("No object passed to function _XMLCreateRootNodeWAttr") Return SetError(1, 15, -1) EndIf Local $objChild, $objAttr, $objAttrVal $objChild = $objDoc.createNode($NODE_ELEMENT, $strNode, $strNameSpc) If IsObj($objChild) Then If $strData <> "" Then $objChild.text = $strData If Not ($objDoc.documentElement.hasChildNodes()) Then _AddFormat($objDoc) EndIf If IsArray($aAttr) And IsArray($aVal) Then If UBound($aAttr) <> UBound($aVal) Then _XMLError("Attribute and value mismatch" & @CRLF & "Please make sure each attribute has a matching value.") Return SetError(2, 15, -1) Else Local $i For $i = 0 To UBound($aAttr) - 1 If $aAttr[$i] = "" Then _XMLError("Error creating child node: " & $strNode & @CRLF & " Attribute Name Cannot be NULL." & @CRLF) Return SetError(1, 0, -1) EndIf $objAttr = $objDoc.createAttribute($aAttr[$i]);, $strNameSpc) $objChild.SetAttribute($aAttr[$i], $aVal[$i]) Next EndIf Else $objAttr = $objDoc.createAttribute($aAttr) $objChild.SetAttribute($aAttr, $aVal) EndIf $objDoc.documentElement.appendChild($objChild) _XMLSaveDoc($strFile) _AddFormat($objDoc) $objChild = 0 Return 1 EndIf _XMLError("Failed to create root child with attributes: " & $strNode & @CRLF) Return SetError(1, 0, -1) EndFunc ;==>_XMLCreateRootNodeWAttr ; #FUNCTION# =================================================================== ; Name ..........: _XMLCreateChildNode ; Description ...: Create a child node under the specified XPath Node. ; Syntax.........: _XMLCreateChildNode($strXPath, $strNode[, $strData = ""[, $strNameSpc = ""]]) ; Parameters ....: $strXPath - The node from root. ; $strNode - Node name to add. ; $strData - Value to give the node ; Return values .: Success - 1 ; Failure - -1 and @error set to 1. ; Author ........: Stephen Podhajecki <gehossafats@netmdc.com> ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; [yes/no] ; ============================================================================== Func _XMLCreateChildNode($strXPath, $strNode, $strData = "", $strNameSpc = "") If Not IsObj($objDoc) Then _XMLError("No object passed to function _XMLCreateChildNode") Return SetError(1, 16, -1) EndIf Local $objParent, $objChild, $objNodeList $objNodeList = $objDoc.selectNodes($strXPath) If IsObj($objNodeList) And $objNodeList.length > 0 Then For $objParent In $objNodeList If Not ($objParent.hasChildNodes()) Then _AddFormat($objDoc, $objParent) EndIf If $strNameSpc = "" Then If Not ($objParent.namespaceURI = 0 Or $objParent.namespaceURI = "") Then $strNameSpc = $objParent.namespaceURI EndIf ;ConsoleWrite("$strNameSpc=" & $strNameSpc & @LF) $objChild = $objDoc.createNode($NODE_ELEMENT, $strNode, $strNameSpc) If $strData <> "" Then $objChild.text = $strData $objParent.appendChild($objChild) _AddFormat($objDoc, $objParent) Next _XMLSaveDoc($strFile) $objParent = "" $objChild = "" Return 1 EndIf _XMLError("Error creating child node: " & $strNode & @CRLF & $strXPath & " does not exist." & @CRLF) Return SetError(1, 0, -1) EndFunc ;==>_XMLCreateChildNode ; #FUNCTION# =================================================================== ; Name ..........: _XMLCreateChildWAttr ; Description ...: Create a child node(s) under the specified XPath Node with attributes. ; Syntax.........: _XMLCreateChildWAttr($strXPath, $strNode, $aAttr, $aVal[, $strData = ""[, $strNameSpc = ""]]) ; Parameters ....: $sPath - Path from root ; $sNode - The node to add with attibute(s) ; $aAttr - The attribute name(s) -- can be array ; $aVal - The attribute value(s) -- can be array ; $strData - The optional value to give the child node. ; Return values .: Success - 1 ; Failure - -1, @error set to: ; |1 - Could not create node. ; |2 - Mismatch between attribute name and value counts. ; |3 - Attribute Name cannot be empty string. ; Author ........: Stephen Podhajecki <gehossafats@netmdc.com> ; Modified ......: ; Remarks .......: This function requires that each attribute name has a corresponding value. ; Related .......: ; Link ..........; ; Example .......; [yes/no] ; ============================================================================== Func _XMLCreateChildWAttr($strXPath, $strNode, $aAttr, $aVal, $strData = "", $strNameSpc = "") If Not IsObj($objDoc) Then _XMLError("No object passed to function _XMLCreateChildWAttr") Return SetError(1, 18, -1) EndIf Local $objParent, $objChild, $objAttr, $objAttrVal, $objNodeList $objNodeList = $objDoc.selectNodes($strXPath) _DebugWrite("Node Selected") If IsObj($objNodeList) And $objNodeList.length <> 0 Then _DebugWrite("Entering if") For $objParent In $objNodeList If Not ($objParent.hasChildNodes()) Then _AddFormat($objDoc, $objParent) EndIf _DebugWrite("Entering for") If $strNameSpc = "" Then If Not ($objParent.namespaceURI = 0 Or $objParent.namespaceURI = "") Then $strNameSpc = $objParent.namespaceURI EndIf $objChild = $objDoc.createNode($NODE_ELEMENT, $strNode, $strNameSpc) If @error Then Return -1 If $strData <> "" Then $objChild.text = $strData If IsArray($aAttr) And IsArray($aVal) Then If UBound($aAttr) <> UBound($aVal) Then _XMLError("Attribute and value mismatch" & @CRLF & "Please make sure each attribute has a matching value.") Return SetError(2, 0, -1) Else Local $i For $i = 0 To UBound($aAttr) - 1 _DebugWrite("Entering inside for") If $aAttr[$i] = "" Then _XMLError("Error creating child node: " & $strNode & @CRLF & " Attribute Name Cannot be NULL." & @CRLF) Return SetError(1, 0, -1) EndIf _DebugWrite($aAttr[$i] & " " & $strNameSpc) $objAttr = $objDoc.createAttribute($aAttr[$i]);, $strNameSpc) If @error Then ExitLoop $objChild.SetAttribute($aAttr[$i], $aVal[$i]) If @error <> 0 Then _XMLError("Error creating child node: " & $strNode & @CRLF & $strXPath & " does not exist." & @CRLF) Return SetError(1, 0, -1) EndIf _DebugWrite("Looping inside for") Next EndIf Else If IsArray($aAttr) Or IsArray($aVal) Then _XMLError("Type non-Array and Array detected" & @LF) Return SetError(1, 0, -1) EndIf If $aAttr = "" Then _XMLError("Attribute Name cannot be empty string." & @LF) Return SetError(3, 0, -1) EndIf _DebugWrite($aAttr & " " & $strNameSpc) $objAttr = $objDoc.createAttribute($aAttr);, $strNameSpc) $objChild.SetAttribute($aAttr, $aVal) EndIf $objParent.appendChild($objChild) _DebugWrite("Looping for") Next _AddFormat($objDoc, $objParent) _XMLSaveDoc($strFile) _DebugWrite("Saved") $objParent = "" $objChild = "" _DebugWrite("Returning") Return 1 EndIf _XMLError("Error creating child node: " & $strNode & @CRLF & $strXPath & " does not exist." & @CRLF) Return SetError(1, 0, -1) EndFunc ;==>_XMLCreateChildWAttr ; #FUNCTION# =================================================================== ; Name ..........: _XMLGetChildText ; Description ...: Selects XML child Node(s) of an element based on XPath input from root node. ; Syntax.........: _XMLGetChildText($strXPath) ; Parameters ....: $strXPath - The xml tree path from root node (root/child/child..) ; Return values .: Success - An array of Nodes. ; Failure - -1 and @error set to 1. ; Author ........: Stephen Podhajecki <gehossafats@netmdc.com> ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; [yes/no] ; ============================================================================== Func _XMLGetChildText($strXPath) If Not IsObj($objDoc) Then _XMLError("No object passed to function _XMLGetChildText") Return SetError(1, 19, -1) EndIf Local $objNodeList, $arrResponse[1], $xmlerr $objNodeList = $objDoc.selectSingleNode($strXPath) If Not IsObj($objNodeList) Then _XMLError(@CRLF & "No Matching Nodes found") $arrResponse[0] = 0 Return SetError(1, 0, -1) EndIf If $objNodeList.hasChildNodes() Then For $objChild In $objNodeList.childNodes() If $objChild.nodeType = $NODE_ELEMENT Then _XMLArrayAdd($arrResponse, $objChild.baseName) ElseIf $objChild.nodeType = $NODE_TEXT Then _XMLArrayAdd($arrResponse, $objChild.text) EndIf Next $arrResponse[0] = UBound($arrResponse) - 1 Return $arrResponse EndIf $arrResponse[0] = 0 $xmlerr = @CRLF & "No Child Text Nodes found" _XMLError("Error Selecting Node(s): " & $strXPath & $xmlerr) Return SetError(1, 0, -1) EndFunc ;==>_XMLGetChildText ; #FUNCTION# =================================================================== ; Name ..........: _XMLGetChildNodes ; Description ...: Selects XML child Node(s) of an element based on XPath input from root node. ; Syntax.........: _XMLGetChildNodes($strXPath) ; Parameters ....: $strXPath - The xml tree path from root node (root/child/child..) ; Return values .: Success - An array of Nodes, count in [0] element. ; Failure - -1 and @error set to 1. ; Author ........: Stephen Podhajecki <gehossafats@netmdc.com> ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; [yes/no] ; ============================================================================== Func _XMLGetChildNodes($strXPath) If Not IsObj($objDoc) Then _XMLError("No object passed to function _XMLGetChildNodes") Return SetError(1, 20, -1) EndIf Local $objNodeList, $arrResponse[1], $xmlerr $objNodeList = $objDoc.selectSingleNode($strXPath) If Not IsObj($objNodeList) Then _XMLError(@LF & "No Matching Nodes found") $arrResponse[0] = 0 Return SetError(1, 0, -1) EndIf If $objNodeList.hasChildNodes() Then For $objChild In $objNodeList.childNodes() If $objChild.nodeType() = $NODE_ELEMENT Then _DebugWrite($objChild.NamespaceURI & "::" & $objChild.baseName & @LF) _XMLArrayAdd($arrResponse, $objChild.baseName) EndIf Next $arrResponse[0] = UBound($arrResponse) - 1 Return $arrResponse EndIf $arrResponse[0] = 0 $xmlerr = @LF & "No Child Nodes found" _XMLError("Error Selecting Node(s): " & $strXPath & $xmlerr) Return SetError(1, 0, -1) EndFunc ;==>_XMLGetChildNodes ; #FUNCTION# =================================================================== ; Name ..........: _XMLGetChildren ; Description ...: Selects XML child Node(s) of an element based on XPath input from root node and returns there text values. ; Syntax.........: _XMLGetChildren($strXPath) ; Parameters ....: $strXPath - The XML tree path from root node (root/child/child..) ; Return values .: Success - An array where: ; |$array[0][0] = Size of array ; |$array[1][0] = Name ; |$array[1][1] = Text ; |$array[1][2] = NameSpaceURI ; |... ; |$array[n][0] = Name ; |$array[n][1] = Text ; |$array[n][2] = NamespaceURI ; Failure - -1 and @error set to 1. ; Author ........: Stephen Podhajecki <gehossafats@netmdc.com> ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; [yes/no] ; ============================================================================== Func _XMLGetChildren($strXPath) If Not IsObj($objDoc) Then _XMLError("No object passed to function _XMLGetChildren") Return SetError(1, 21, -1) EndIf Local $objNodeList, $arrResponse[1][3], $xmlerr $objNodeList = $objDoc.selectSingleNode($strXPath) If Not IsObj($objNodeList) Then _XMLError(@LF & "No Matching Nodes found") $arrResponse[0][0] = 0 Return SetError(1, 0, -1) EndIf If $objNodeList.hasChildNodes() Then For $objChild In $objNodeList.childNodes() If $objChild.nodeType() = $NODE_ElEMENT Then If $objChild.hasChildNodes() Then For $objChildNode in $objChild.childNodes() If $objChildNode.nodeType() = $NODE_TEXT Then Local $dims = UBound($arrResponse, 1) ReDim $arrResponse[$dims + 1][3] $arrResponse[$dims][0] = $objChildNode.parentNode.baseName $arrResponse[$dims][1] = $objChildNode.text $arrResponse[$dims][2] = $objChildNode.NamespaceURI ;_XMLArrayAdd($arrResponse, $objChild.baseName) EndIf Next EndIf EndIf Next $arrResponse[0][0] = UBound($arrResponse, 1) - 1 Return $arrResponse EndIf $arrResponse[0][0] = 0 $xmlerr = @LF & "No Child Nodes found" _XMLError("Error Selecting Node(s): " & $strXPath & $xmlerr) Return SetError(1, 0, -1) EndFunc ;==>_XMLGetChildren ; #FUNCTION# =================================================================== ; Name ..........: _XMLGetNodeCount ; Description ...: Get Node Count based on XPath input from root node. ; Syntax.........: _XMLGetNodeCount($strXPath[, $strQry = ""[, $iNodeType = 1]]) ; Parameters ....: $strXPath - The XML tree path from root node (root/child/child.. ; $strQry - A DOM compliant query string (not really necessary as it becomes part of the path ; $iNodeType - The type of node to count. (element, attrib, comment etc.) ; Return values .: Success - Number of nodes found (can be 0) ; Failure - -1 and @error set to 1. ; Author ........: Stephen Podhajecki <gehossafats@netmdc.com> & DickB ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; [yes/no] ; ============================================================================== Func _XMLGetNodeCount($strXPath, $strQry = "", $iNodeType = 1) If Not IsObj($objDoc) Then _XMLError("No object passed to function _XMLGetNodeCount") Return SetError(1, 22, -1) EndIf Local $objQueryNodes, $objNode, $nodeCount = 0, $errMsg $objQueryNodes = $objDoc.selectNodes($strXPath & $strQry) If @error = 0 And $objQueryNodes.length > 0 Then For $objNode In $objQueryNodes If $objNode.nodeType = $iNodeType Then $nodeCount = $nodeCount + 1 Next Return $nodeCount Else $errMsg = "No nodes of specified type found." EndIf _XMLError("Error retrieving node count for: " & $strXPath & @CRLF & $errMsg & @CRLF) SetError(1) Return -1 ; EndIf EndFunc ;==>_XMLGetNodeCount ; #FUNCTION# =================================================================== ; Name ..........: _XMLGetAllAttribIndex ; Description ...: Get all XML Field(s) attributes based on Xpath and specific index. ; Syntax.........: _XMLGetAllAttribIndex($strXPath, ByRef $aName, ByRef $aValue[, $strQry = ""[, $iNodeIndex = 0]]) ; Parameters ....: $strXpath - The xml tree path from root node (root/child/child..) ; $aNames - The array to return the attrib names in. ; $aValue - The array to return the attrib values in. ; $strQry - DOM compliant query string (not really necessary as it becomes ; $iNodeIndex - The index of node to retrieve. ; Return values .: Success - The number of elements. ; Failure - -1 and @error set to 1. ; Author ........: Stephen Podhajecki <gehossafats@netmdc.com> ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; [yes/no] ; ============================================================================== Func _XMLGetAllAttribIndex($strXPath, ByRef $aName, ByRef $aValue, $strQry = "", $iNodeIndex = 0) If Not IsObj($objDoc) Then _XMLError("No object passed to function _XMLGetAllAttribIndex") Return SetError(1, 23, -1) EndIf Local $objNodeList, $objQueryNodes, $i ;, $arrResponse[2][1] $objQueryNodes = $objDoc.selectNodes($strXPath & $strQry) If $objQueryNodes.length > 0 Then $objNodeList = $objQueryNodes.item($iNodeIndex).attributes _DebugWrite("GetAllAttribIndex " & $objNodeList.length) ;ReDim $arrResponse[2][$objNodeList.length + 1] ReDim $aName[$objNodeList.length] ReDim $aValue[$objNodeList.length] For $i = 0 To $objNodeList.length - 1 ;$arrResponse[0][$i] = $objNodeList.item ($i).nodeName ;$arrResponse[1][$i] = $objNodeList.item ($i).Value $aName[$i] = $objNodeList.item($i).nodeName $aValue[$i] = $objNodeList.item($i).Value Next ;Return $arrResponse Return $objNodeList.length EndIf _XMLError("Error retrieving attributes for: " & $strXPath & @CRLF) Return SetError(1, 0, -1) EndFunc ;==>_XMLGetAllAttribIndex ; #FUNCTION# =================================================================== ; Name ..........: _XMLGetPath ; Description ...: Return a nodes full path based on XPath input from root node. ; Syntax.........: _XMLGetPath($strXPath) ; Parameters ....: $strXPath - The XML tree path from root node (root/child/child..) ; Return values .: Success - An array of node names from root, count in [0] element. ; Failure - -1 and @error set to 1. ; Author ........: Stephen Podhajecki <gehossafats@netmdc.com> ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; [yes/no] ; ============================================================================== Func _XMLGetPath($strXPath) If Not IsObj($objDoc) Then _XMLError("No object passed to function _XMLGetPath") Return SetError(1, 24, -1) EndIf If $DOMVERSION < 4 Then _XMLError("Error DOM Version: " & "MSXML Version 4 or greater required for this function") Return SetError(1, 0, -1) EndIf Local $objNodeList, $arrResponse[1], $objNodeChild, $xmlerr, $nodepath, $ns $objNodeList = $objDoc.selectNodes($strXPath) If $objNodeList.length > 0 Then _DebugWrite("GetPath list length:" & $objNodeList.length) For $objNode In $objNodeList Local $objNode1 = $objNode $nodepath = "" $nodepathtag = "" If $objNode.nodeType <> $NODE_DOCUMENT Then $ns = $objNode.namespaceURI() If $ns <> "" Then $ns = StringRight($ns, StringLen($ns) - StringInStr($ns, "/", 0, -1)) & ":" EndIf If $ns = 0 Then $ns = "" $nodepath = "/" & $ns & $objNode.nodeName() & $nodepath EndIf Do $objParent = $objNode1.parentNode() _DebugWrite("parent " & $objParent.nodeName() & @LF) If $objParent.nodeType <> $NODE_DOCUMENT Then $ns = $objParent.namespaceURI() If $ns <> "" Then ;$ns = StringRight($ns, StringLen($ns) - StringInStr($ns, "/", 0, -1)) & ":" $ns &= ":" EndIf If $ns = 0 Then $ns = "" $nodepath = "/" & $ns & $objParent.nodeName() & $nodepath $objNode1 = $objParent Else $objNode1 = 0 EndIf $objParent = 0 Until (Not (IsObj($objNode1))) _DebugWrite("Path node> " & $nodepath & @LF) _XMLArrayAdd($arrResponse, $nodepath) Next $arrResponse[0] = UBound($arrResponse) - 1 Return $arrResponse EndIf $xmlerr = @CRLF & "No matching node(s)found!" _XMLError("Error Retrieving: " & $strXPath & $xmlerr) Return SetError(1, 0, -1) EndFunc ;==>_XMLGetPath ; #FUNCTION# =================================================================== ; Function Name : _XMLGetPathInternal ; Description ...: Returns the path of a valid node object. ; Syntax ........: _XMLGetPathInternal($objNode) ; Parameters ....: $objNode - A valid node object ; Return values .: Success - Path from root as string. ; Failure - An empty string and @error set to 1. ; Author ........: Stephen Podhajecki <gehossafats at netmdc.com/> ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; [yes/no] ; ============================================================================== Func _XMLGetPathInternal($objNode) If Not IsObj($objDoc) Then _XMLError("No object passed to function _XMLGetPathInternal") Return SetError(1, 25, "") EndIf Local $nodepath, $na, $objParent If IsObj($objNode) Then $nodepath = "/" & $objNode.baseName Do $objParent = $objNode.parentNode() _DebugWrite("parent" & $objParent.nodeName() & ">" & @LF) If $objParent.nodeType <> $NODE_DOCUMENT Then $ns = $objParent.namespaceURI() If $ns = 0 Then $ns = "" If $ns <> "" Then $ns = StringRight($ns, StringLen($ns) - StringInStr($ns, "/", 0, -1)) & ":" EndIf $nodepath = "/" & $ns & $objParent.nodeName() & $nodepath $objNode = $objParent Else $objNode = 0 EndIf $objParent = 0 Until (Not (IsObj($objNode))) _DebugWrite("Path node>" & $nodepath & @LF) Return ($nodepath) Else Return SetError(1, 0, "") EndIf EndFunc ;==>_XMLGetPathInternal ; #FUNCTION# =================================================================== ; Name ..........: _XMLReplaceChild ; Description ...: Replaces a node with another ; Syntax.........: _XMLReplaceChild($objOldNode, $objNewNode[, $ns = ""]) ; Parameters ....: $objOldNode - The node to replace ; $objNewNode - The replacement node. ; Return values .: Success - 1. ; Failure - -1 and @error set to 1. ; Author ........: Stephen Podhajecki <gehossafats@netmdc.com> adapted from ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; [yes/no] ; ============================================================================== Func _XMLReplaceChild($objOldNode, $objNewNode, $ns = "") If Not IsObj($objDoc) Then _XMLError("No object passed to function _XMLReplaceChild") Return SetError(1, 26, -1) EndIf If $objOldNode = "" Or $objNewNode = "" Then Return SetError(1) Local $nodeRoot Local $nodeOld Local $nodeNew Local $nodeTemp Local $fSuccess = False ;No error handling done With $objDoc ;;.Load "c:\books.xml" $nodeRoot = .documentElement $oldNodes = $nodeRoot.selectNodes($objOldNode) ;'For each Node For $nodeOld In $oldNodes ;Create a New element $nodeNew = .createNode($NODE_ELEMENT, $objNewNode, $ns) ;Copy attributes For $nodeTemp In $nodeOld.Attributes $nodeNew.Attributes.setNamedItem($nodeTemp.cloneNode(True)) Next ;Copy Child Nodes For $nodeTemp In $nodeOld.childNodes $nodeNew.appendChild($nodeTemp) Next ;Replace with the renamed node If IsObj($nodeOld.parentNode.replaceChild($nodeNew, $nodeOld)) Then $fSuccess = 1 If Not ($objDoc.parseError.errorCode = 0) Then _XMLError("_XMLReplaceChild:" & @LF & "Error Replacing Child: " & _ $objDoc.parseError.errorCode & _ " " & $objDoc.parseError.reason) $fSuccess = False ExitLoop Else $fSuccess = True EndIf Next .save($strFile) EndWith $nodeRoot = 0 $nodeOld = 0 $nodeNew = 0 $nodeTemp = 0 If ($fSuccess = False) Then Return SetError(1, 0, -1) Return 1 EndFunc ;==>_XMLReplaceChild ; #FUNCTION# =================================================================== ; Name ..........: _XMLSchemaValidate ; Description ...: Validates a document against a dtd. ; Syntax.........: _XMLSchemaValidate($sXMLFile, $strNameSpc, $sXSDFile) ; Parameters ....: $sXMLFile - The file to validate ; $strNameSpc - xml namespace ; $sXSDFile - DTD file to validate against. ; Return values .: Success - 1 ; Failure - -1 and @error set to 1. ; Author ........: Stephen Podhajecki <gehossafats@netmdc.com> ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; [yes/no] ; ============================================================================== Func _XMLSchemaValidate($sXMLFile, $strNameSpc, $sXSDFile) Local $cache, $xmldoc $cache = ObjCreate("Msxml2.XMLSchemaCache." & $DOMVERSION & ".0") If Not IsObj($cache) Then MsgBox(266288, "XML Error", "Unable to instantiate the XML object" & @LF & "Please check your components.") Return SetError(1, 0, -1) EndIf $cache.add($strNameSpc, $sXSDFile) $xmldoc = ObjCreate("Msxml2.DOMDocument." & $DOMVERSION & ".0") If Not IsObj($xmldoc) Then MsgBox(266288, "XML Error", "Unable to instantiate the XML object" & @LF & "Please check your components.") Return SetError(1, 0, -1) EndIf $xmldoc.async = False $xmldoc.schemas = $cache $xmldoc.load($sXMLFile) If Not ($xmldoc.parseError.errorCode = 0) Then _XMLError("_XMLSchemaValidate:" & @LF & "Error: " & $xmldoc.parseError.errorCode & " " & $xmldoc.parseError.reason) Return SetError($xmldoc.parseError.errorCode) EndIf Return 1 EndFunc ;==>_XMLSchemaValidate ; #FUNCTION# =================================================================== ; Name ..........: _XMLGetDomVersion ; Description ...: Returns the version of msxml that is in use for the document. ; Syntax.........: _XMLGetDomVersion() ; Parameters ....: none ; Return values .: Success - msxml version ; Failure - 0 ; Author ........: Stephen Podhajecki <gehossafats@netmdc.com> ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; [yes/no] ; ============================================================================== Func _XMLGetDomVersion() Return $DOMVERSION EndFunc ;==>_XMLGetDomVersion ; #FUNCTION# =================================================================== ; Name ..........: _XMLError ; Description ...: Sets or Gets error message that may be generated by the UDF functs. ; Syntax.........: _XMLError($sError = "") ; Parameters ....: $sError - Error message to set. ; Return values .: Success - one of the following: ; |$sError <> "" - Nothing. ; |$sError = "" - Last error set. ; Failure - Nothing. ; Author ........: Stephen Podhajecki <gehossafats@netmdc.com> ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; [yes/no] ; ============================================================================== Func _XMLError($sError = "") If $sError = "" Then $sError = $sXML_error $sXML_error = "" Return $sError Else $sXML_error = StringFormat($sError) EndIf _DebugWrite($sXML_error) EndFunc ;==>_XMLError ; #FUNCTION# =================================================================== ; Name ..........: _XMLCOMEerr ; Description ...: Displays a message box with the COM Error. ; Syntax.........: _XMLCOMEerr() ; Parameters ....: None ; Return values .: ; Author ........: SvenP 's error handler ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; [yes/no] ; ============================================================================== Func _XMLCOMEerr() _ComErrorHandler() Return EndFunc ;==>_XMLCOMEerr ; #FUNCTION# =================================================================== ; Name ..........: _ComErrorHandler ; Description ...: A COM error handling routine. ; Syntax.........: _ComErrorHandler($quiet = "") ; Parameters ....: $quiet - Work silently ; Return values .: None ; Author ........: ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; [yes/no] ; ============================================================================== Func _ComErrorHandler($quiet = "") Local $COMErr_Silent, $HexNumber ; ============================================================================== ;added silent switch to allow the func returned to the option to display custom ;error messages If $quiet = True Or $quiet = False Then $COMErr_Silent = $quiet $quiet = "" EndIf ; ============================================================================== $HexNumber = Hex($oXMLMyError.number, 8) If @error Then Return Local $msg = "COM Error with DOM!" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $oXMLMyError.description & @CRLF & _ "err.windescription:" & @TAB & $oXMLMyError.windescription & @CRLF & _ "err.number is: " & @TAB & $HexNumber & @CRLF & _ "err.lastdllerror is: " & @TAB & $oXMLMyError.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $oXMLMyError.scriptline & @CRLF & _ "err.source is: " & @TAB & $oXMLMyError.source & @CRLF & _ "err.helpfile is: " & @TAB & $oXMLMyError.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $oXMLMyError.helpcontext If $COMErr_Silent <> True Then MsgBox(0, @AutoItExe, $msg) Else _XMLError($msg) EndIf SetError(1) EndFunc ;==>_ComErrorHandler ; #FUNCTION# =================================================================== ; Name ..........: _DebugWrite ; Description ...: Writes a message to console with a crlf on the end ; Syntax.........: _DebugWrite($strMsg[, $sLineEnding = @LF]) ; Parameters ....: $strMsg - The message to display ; $sLineEnding - Line ending to add ; Return values .: On Succes - None. ; Failure - None. ; Author ........: ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; [yes/no] ; ============================================================================== Func _DebugWrite($strMsg, $sLineEnding = @LF) If $fDEBUGGING Then ConsoleWrite(StringFormat($strMsg) & $sLineEnding) EndIf EndFunc ;==>_DebugWrite ; #FUNCTION# =================================================================== ; Name ..........: _SetDebug ; Description ...: Turn debugging info on or off ; Syntax.........: _SetDebug($fDbug = True) ; Parameters ....: $fDbug - Boolean value for debugging. ; Return values .: Success - The debugging state. ; Author ........: ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; [yes/no] ; ============================================================================== Func _SetDebug($fDbug = True) $fDEBUGGING = $fDbug _DebugWrite("Debug = " & $fDEBUGGING) Return $fDEBUGGING EndFunc ;==>_SetDebug ; #FUNCTION# =================================================================== ; Name ..........: _XMLUDFVersion ; Description ...: Returns UDF version number ; Syntax.........: _XMLUDFVersion() ; Parameters ....: None ; Return values .: Success - The UDF version number ; Author ........: Stephen Podhajecki ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; [yes/no] ; ============================================================================== Func _XMLUDFVersion() Return $_XMLUDFVER EndFunc ;==>_XMLUDFVersion ; #FUNCTION# =================================================================== ; Name ..........: _XMLTransform ; Description ...: ; Syntax.........: _XMLTransform([$oXMLDoc = ""[, $Style = ""[, $szNewDoc = ""]]]) ; Parameters ....: $oXMLDoc - The document to transform ; $Style - The stylesheet to use ; $szNewDoc - Save to this file. ; Return values .: Success - Returns True ; Failure - -1 and @error set to 1. ; Author ........: Stephen Podhajecki <gehossafats at netmdc dot com>, Modified by WeaponX ; Modified ......: ; Remarks .......: Default stylesheet is used for indenting. ; Related .......: ; Link ..........; ; Example .......; [yes/no] ; ============================================================================== Func _XMLTransform($oXMLDoc = "", $Style = "", $szNewDoc = "") If $oXMLDoc = "" Then $oXMLDoc = $objDoc EndIf If Not IsObj($oXMLDoc) Then _XMLError("No object passed to function _XMLTransform") Return SetError(1, 29, -1) EndIf Local $fIndented = False Local $xslt = ObjCreate("MSXML2.XSLTemplate." & $DOMVERSION & ".0") Local $xslDoc = ObjCreate("MSXML2.FreeThreadedDOMDocument." & $DOMVERSION & ".0") Local $xmldoc = ObjCreate("MSXML2.DOMDocument." & $DOMVERSION & ".0") Local $xslProc $xslDoc.async = False If FileExists($Style) Then _DebugWrite("LoadXML:1:" & $xslDoc.load($Style) & @LF) Else _DebugWrite("LoadXML2:" & $xslDoc.loadXML(_GetDefaultStyleSheet()) & @LF) EndIf If $xslDoc.parseError.errorCode <> 0 Then _XMLError("Error Transforming NodeToObject: " & $xslDoc.parseError.reason) EndIf $xslt.stylesheet = $xslDoc $xslProc = $xslt.createProcessor() $xslProc.input = $objDoc $oXMLDoc.transformNodeToObject($xslDoc, $xmldoc) If $oXMLDoc.parseError.errorCode <> 0 Then _XMLError("_XMLTransform:" & @LF & "Error Transforming NodeToObject: " & $oXMLDoc.parseError.reason) $fIndented = False Else $fIndented = True EndIf If $fIndented Then ;Write transformed xml to a file if a filename is given If $szNewDoc <> "" Then $xmldoc.save($szNewDoc) If $xmldoc.parseError.errorCode <> 0 Then _XMLError("_XMLTransform:" & @LF & "Error Saving: " & $xmldoc.parseError.reason) $fIndented = False EndIf Else ;Overwrite original object with transformed object $objDoc = $xmldoc _XMLSaveDoc($strFile) If $oXMLDoc.parseError.errorCode <> 0 Then _XMLError("_XMLTransform:" & @LF & "Error Saving: " & $oXMLDoc.parseError.reason) $fIndented = False EndIf EndIf EndIf $xslProc = 0 $xslt = 0 $xslDoc = 0 $xmldoc = 0 If $fIndented = False Then Return SetError(1, 0, -1) Return $fIndented EndFunc ;==>_XMLTransform ; #INTERNAL_USE_ONLY#========================================================== ; Name ..........: _GetDefaultStyleSheet ; Description ...: Internal function, returns the default indenting style sheet. ; Syntax.........: _GetDefaultStyleSheet() ; Parameters ....: ; Return values .: Success - The default stylesheet. ; Failure - Nothing. ; Author ........: Hew Wolff - Art & Logic, Inc. ; Modified ......: ; Remarks .......: Posted all over the web. ; Related .......: ; Link ..........; ; Example .......; [yes/no] ; ============================================================================== Func _GetDefaultStyleSheet() Return '<?xml version="1.0" encoding="UTF-8"?>' & _ '<!--' & _ 'Converts XML into a nice readable format.' & _ 'Tested with Saxon 6.5.3.' & _ 'As a test, this stylesheet should not change when run on itself.' & _ 'But note that there are no guarantees about attribute order within an' & _ 'element (see http://www.w3.org/TR/xpath#dt-document-order), or about' & _ 'which characters are escaped (see' & _ 'http://www.w3.org/TR/xslt#disable-output-escaping).' & _ 'I did not test processing instructions, CDATA sections, or' & _ 'namespaces.' & _ 'Hew Wolff' & _ 'Senior Engineer' & _ 'Art & Logic, Inc.' & _ 'www.artlogic.com' & _ '-->' & _ '<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">' & _ '<!-- Take control of the whitespace. -->' & _ '<xsl:output method="xml" indent="no" encoding="UTF-8"/>' & _ '<xsl:strip-space elements="*"/>' & _ '<xsl:preserve-space elements="xsl:text"/>' & _ '<!-- Copy comments, and elements recursively. -->' & _ '<xsl:template match="*|comment()">' & _ '<xsl:param name="depth">0</xsl:param>' & _ '<!--' & _ 'Set off from the element above if one of the two has children.' & _ 'Also, set off a comment from an element.' & _ 'And set off from the XML declaration if necessary.' & _ '-->' & _ '<xsl:variable name="isFirstNode" select="count(../..) = 0 and position() = 1"/>' & _ '<xsl:variable name="previous" select="preceding-sibling::node()[1]"/>' & _ '<xsl:variable name="adjacentComplexElement" select="count($previous/*) &gt; 0 or count(*) &gt; 0"/>' & _ '<xsl:variable name="adjacentDifferentType" select="not(($previous/self::comment() and self::comment()) or ($previous/self::* and self::*))"/>' & _ '<xsl:if test="$isFirstNode or ($previous and ($adjacentComplexElement or $adjacentDifferentType))">' & _ '<xsl:text>&#xA;</xsl:text>' & _ '</xsl:if>' & _ '<!-- Start a new line.' & _ '<xsl:text>&#xA;</xsl:text> -->' & _ '<xsl:call-template name="indent">' & _ '<xsl:with-param name="depth" select="$depth"/>' & _ '</xsl:call-template>' & _ '<xsl:copy>' & _ '<xsl:if test="self::*">' & _ '<xsl:copy-of select="@*"/>' & _ '<xsl:apply-templates>' & _ '<xsl:with-param name="depth" select="$depth + 1"/>' & _ '</xsl:apply-templates>' & _ '<xsl:if test="count(*) &gt; 0">' & _ '<xsl:text>&#xA;</xsl:text>' & _ '<xsl:call-template name="indent">' & _ '<xsl:with-param name="depth" select="$depth"/>' & _ '</xsl:call-template>' & _ '</xsl:if>' & _ '</xsl:if>' & _ '</xsl:copy>' & _ '<xsl:variable name="isLastNode" select="count(../..) = 0 and position() = last()"/>' & _ '<xsl:if test="$isLastNode">' & _ '<xsl:text>&#xA;</xsl:text>' & _ '</xsl:if>' & _ '</xsl:template>' & _ '<xsl:template name="indent">' & _ '<xsl:param name="depth"/>' & _ '<xsl:if test="$depth &gt; 0">' & _ '<xsl:text> </xsl:text>' & _ '<xsl:call-template name="indent">' & _ '<xsl:with-param name="depth" select="$depth - 1"/>' & _ '</xsl:call-template>' & _ '</xsl:if>' & _ '</xsl:template>' & _ '<!-- Escape newlines within text nodes, for readability. -->' & _ '<xsl:template match="text()">' & _ '<xsl:call-template name="escapeNewlines">' & _ '<xsl:with-param name="text">' & _ '<xsl:value-of select="."/>' & _ '</xsl:with-param>' & _ '</xsl:call-template>' & _ '</xsl:template>' & _ '<xsl:template name="escapeNewlines">' & _ '<xsl:param name="text"/>' & _ '<xsl:if test="string-length($text) &gt; 0">' & _ '<xsl:choose>' & _ '<xsl:when test="substring($text, 1, 1) = ' & "'#xA;'" & '">' & _ '<xsl:text disable-output-escaping="yes">&amp;#xA;</xsl:text>' & _ '</xsl:when>' & _ '<xsl:otherwise>' & _ '<xsl:value-of select="substring($text, 1, 1)"/>' & _ '</xsl:otherwise>' & _ '</xsl:choose>' & _ '<xsl:call-template name="escapeNewlines">' & _ '<xsl:with-param name="text" select="substring($text, 2)"/>' & _ '</xsl:call-template>' & _ '</xsl:if>' & _ '</xsl:template>' & _ '</xsl:stylesheet>' EndFunc ;==>_GetDefaultStyleSheet ; #INTERNAL_USE_ONLY#========================================================== ; Name ..........: _AddFormat ; Description ...: ; Syntax.........: _AddFormat($objDoc[, $objParent = ""]) ; Parameters ....: $objDoc - Document to format ; $objParent - Optional node to add formatting to ; Return values .: Success - 1 ; Failure - -1 and @error set to 1. ; Author ........: Stephen Podhajecki <gehossafats a t netmdc.com> ; Modified ......: ; Remarks .......: Just break up the tags, no indenting is done here. ; Related .......: ; Link ..........; ; Example .......; [yes/no] ; ============================================================================== Func _AddFormat($objDoc, $objParent = "") If $fADDFORMATTING = True Then If Not IsObj($objDoc) Then _XMLError("No object passed to function _XMLAddFormat") Return SetError(1, 30, -1) EndIf Local $objFormat = $objDoc.createTextNode(@CR) If IsObj($objParent) Then $objParent.appendChild($objFormat) Else $objDoc.documentElement.appendChild($objFormat) EndIf _XMLSaveDoc($strFile) EndIf Return 1 EndFunc ;==>_AddFormat ; #FUNCTION# =================================================================== ; Name ..........: _XMLSetAutoSave ; Description ...: Set the automatic save to on or off ; Syntax.........: _XMLSetAutoSave($fSave = True) ; Parameters ....: $fSave - Boolean value to set automatic saving. ; Return values .: Success - Previous state of autosave. ; Author ........: Stephen Podhajecki <gehossafats a t netmdc.com> ; Modified ......: ; Remarks .......: Defaults to true. ; Related .......: ; Link ..........; ; Example .......; [yes/no] ; ============================================================================== Func _XMLSetAutoSave($fSave = True) Local $oldSave = $fXMLAUTOSAVE $fXMLAUTOSAVE = $fSave Return $oldSave EndFunc ;==>_XMLSetAutoSave ; #FUNCTION# =================================================================== ; Name ..........: _XMLSetAutoFormat ; Description ...: Turn auto formatting on or off ; Syntax.........: _XMLSetAutoFormat($fAutoFormat = True) ; Parameters ....: $fAutoFormat - Boolean flag for automatic formatting ; Return values .: Success - The previous state. ; Failure - Nothing. ; Author ........: Stephen Podhajecki {gehossafats at netmdc. com} ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; [yes/no] ; ============================================================================== Func _XMLSetAutoFormat($fAutoFormat = True) Local $oldFormat = $fADDFORMATTING $fADDFORMATTING = $fAutoFormat Return $oldFormat EndFunc ;==>_XMLSetAutoFormat ; #FUNCTION# =================================================================== ; Name ..........: _XMLSaveDoc ; Description ...: Save the current xml doc ; Syntax.........: _XMLSaveDoc([$sFile=""[,$iForce = 0]]) ; Parameters ....: $sFile - The filename to save the xml doc as. ; $iForce - If true, save the file regardless of autosave state. ; Return values .: Success - 1 ; Failure - -1 and @error set to the following: ; |1 - error trying to save. ; |2 - Autosave is off. ; |3 - No filename given for save and default is blank. ; Author ........: Stephen Podhajecki {gehossafats at netmdc. com} ; Modified ......: ; Remarks .......: Defaults to the current filename. ; Related .......: ; Link ..........; ; Example .......; [yes/no] ; ============================================================================== Func _XMLSaveDoc($sFile = "", $iForce = 0) If ($fXMLAUTOSAVE = True) Or ($iForce = 1) Then If $sFile = "" Then $sFile = $strFile If $sFile <> "" Then $objDoc.save($sFile) If $objDoc.parseError.errorCode <> 0 Then _XMLError("_XMLSaveDoc: Saving " & $sFile & " failed.:" & @LF & _ $objDoc.parseError.errorCode & _ " " & $objDoc.parseError.reason) Return SetError(1, 0, -1) EndIf Return 1 Else _XMLError("_XMLSaveDoc:" & " Error Saving: No Filename given") Return SetError(3, 0, -1) EndIf EndIf Return SetError(2, 0, 1) EndFunc ;==>_XMLSaveDoc ; #FUNCTION# =================================================================== ; Name ..........: _XMLNodeExists ; Description ...: Checks for the existence of a node or nodes matching the specified path ; Syntax.........: _XMLNodeExists($strXPath) ; Parameters ....: $strXPath - Path to check for. ; Return values .: Success - 1 or Higher , 0 ; Failure - 0 and @Error set to: ; |0 - No error. ; |1 - No XML object @extended = 31. ; |2 - Node not found. ; Author ........: Stephen Podhajecki <gehossafats a t netmdc.com> ; Modified ......: ; Remarks .......: Returns the number of nodes found (could be greater than 1) ; Related .......: ; Link ..........; ; Example .......; [yes/no] ; ============================================================================== Func _XMLNodeExists($strXPath) If Not IsObj($objDoc) Then _XMLError("No object passed to function _XMLNodeExists") Return SetError(1, 31, 0) EndIf Local $objNode, $iCount Local $objNode = $objDoc.SelectNodes($strXPath) If IsObj($objNode) Then $iCount = $objNode.length $objNode = 0 If $iCount Then Return $iCount Return SetError(2, 0, 0) EndFunc ;==>_XMLNodeExists ; #INTERNAL_USE_ONLY#========================================================== ; Name ..........: _XMLArrayAdd ; Description ...: Adds an item to an array. ; Syntax.........: _XMLArrayAdd(ByRef $avArray, $sValue) ; Parameters ....: $avArray - The array to modify. ; $sValue - The value to add to the array. ; Return values .: Success - 1 and value added to array. ; Failure - 0 and @error set to 1 ; Author ........: ; Modified ......: ; Remarks .......: Local version of _ArrayAdd to remove dependency on Array.au3 ; Related .......: ; Link ..........; ; Example .......; [yes/no] ; ============================================================================== Func _XMLArrayAdd(ByRef $avArray, $sValue) If IsArray($avArray) Then ReDim $avArray[UBound($avArray) + 1] $avArray[UBound($avArray) - 1] = $sValue SetError(0) Return 1 Else SetError(1) Return 0 EndIf EndFunc ;==>_XMLArrayAdd EDIT: Removed a script comment related to one of my other projects.
  10. Chiptunes Players

    I love chiptune music, but BASS only support XM, IT, S3M, MOD, MTM, UMX and MO3 file format for MOD music. 1 | Nintendo NES and SNES Sound File Players May be you already have some files with extension nsf, nsfe, spc or rsn (unzip rsn files for get spc collection files inside) but you can't play them in a AutoIt script ? So I searched around a bit, and found 2 DLL ( nsf_player.dll and spc_player.dll ) for play Nintendo NES and SNES Sound Files. Interest of those DLL is that they can play from file path or binary data, avoiding temp files. Dll and audio files are embedded in scripts for permit you to test them right away. Some info/download links are in front of each script. 2 | ModPlug Player Another dll found : npmod32.dll who support mod, s3m, xm, med, it, s3z, mdz, itz, xmz and wav files. Interest : it can play some rares chiptune formats, you can also pause, set volume and set position. Inconvenient : do not load from binary datas. Dll and audio files are embedded in script and i have added a gui for permit you to try right away ! Warning : Do not work on Win8. 3 | ZXTune Player 2 (basszxtune.dll v2.4.5) UPDATE of 23 DEC 2016 Using BASSZXTUNE chiptune support for BASS ( Support as0, asc, ay, ftc, gtr, psc, psg, psm, pt1, pt2, pt3, sqt, st1, s, st3, stc, stp, ts, txt, vtx, ym, chi, dmm, dst, m, sqd, str, sid, cop, tf0, tfc, tfd, tfe, $b, $m, ahx, ayc, bin, cc3, d, dsq, esv, fdi, gam, gamplus, gbs, gym, hes, hrm, hrp, lzs, msp, mtc, nsf, nsfe, p, pcd, sap, scl, spc, szx, td0, tlz, tlzp, trd, trs, vgm ) Interest : it can play lot of rares chiptune formats, while benefiting from all bass functions. Inconvenient : dll size.(5860ko) Dll and audio files are embedded in script. 4 | TitchySID Player Files and dll are loaded in memory. Interest : dll size (8ko), you can Play/Stop/Pause/Resume and choose which subsong to play. Inconvenient : only SID audio files supported ( PSID & RSID) Dll and audio files are embedded in script. Tested under Win7 and Win8. Edit : added a Sid header viewer : SidHeaderViewer.au3 5 | MiniFmod Player Interest : dll size (20ko) Inconvenient : only xm audio files supported. 6 | Npnez Player Using npnez.dll (88ko) for play Gameboy Sound System audio files and some others ( kss, hes, nsf, ay, gbr, gbs, gb, nsd, sgc ) Interest : Can be loaded in memory, subsong can be set and volume can be adjusted ( perfect for create a fade when exiting ) Inconvenient : for an unknow reason, only 20% of my hes collection is playable... 7 | µFMOD Player Interest : dll size (10ko), can be loaded in memory, support Play/Stop/Pause/Resume actions and volume can be adjusted ( perfect for create a fade when exiting ) Inconvenient : only xm audio files supported. 8 | MagicV2m Player Interest : dll size (20ko), Play/Stop/IsPlay/SetAutoRepeat/Progress Inconvenient : only v2m audio files supported, V2mPlayStream is not reliable, so prefer V2mPlayFile instead. 9 | OSMEngine Player OSMEngine.dll (80 ko)(Oldskool Musics Engine) permit to play snd, sndh, fc, fc4, fc14 and some rare jam audio files from Amiga/Atari ST(E) Interest : audio can be loaded in memory, and Pause/Resume/SetVolume/GetInfos are available Inconvenient : none at the moment. 10 | Ayfly Player Ayfly.dll (268 ko) is a AY-891x emulator and player who support the following tracker formats : aqt, asc, ay, fxm, gtr, psc, psg, pt1, pt2, pt3, sqt, stc, stp, vtx, ym and zxs (ZX Spectrum Emulator Snapshot) files. Interest : SetVolume/GetInfos are available Inconvenient : a function named "ay_initsongindirect" for load module in memory exists, but due to the poor documentation provided i do not succeed to get it to work... 11 | GMGME Player GMGME.dll is a emulated music DLL that allows you to play ay, gbs, gym, hes, kss, nsf/nsfe, sap, spc and vgm files. Interest : Can play ATARI SAP files (only type B and C) , Set Volume and Set Tempo are available Inconvenient : Dll Size (and his imports) , and audio files can not be loaded in memory. 12 | SC68 Player sc68replay.dll (166 ko) is a Freebasic DLL compiled from "sc68replay" src that allows you to play SC68 (Atari ST and Amiga audio formats) files. Interest : Can play from file and memory Inconvenient : Unfortunatelly for an unknown reason not all sc68 files are supported. 13 | Extended Module Player LibXmp.dll (272 ko) can "read" xm, mod, it, s3m, med, 669 but also some rares formats abk, amd, amf, dbm, digi, dtm, emod, far, flx, fnk, gdm, hsc, imf, j2b, liq, m15, mdl, mfp, mgt, mtm, mtn, okt, psm, ptm, rad, rtm, sfx, smp, stim, stm, stx, ult, umx, wow, ym3812 Despite its name, it's not a "player" but a library that renders module files to RAW PCM data. So the interest in this script was to find a way to convert those raw datas into a "playable" sound. With Waveform Audio Interface i create a pseudo Wav header who permit to play datas as a Wav file. Interest : Can play from file and memory Inconvenient : Time to render datas (depends of file size) 14 | LibModPlug Player LibModPlug.dll (102 ko) can "read" xm, it, mod, s3m, med, 669 and also amf, ams, dbm, dmf, dsm, far, j2b, mdl, mt2, mtm, okt, psm, ptm, stm, ult, umx. As LibXmp.dll, it's a library that renders module files to RAW PCM data. For this one, i create a real binary wave header for be able to play it easily from memory with winmm.dll PlaySoundW function. Interests : Can play from file and memory, and have some nice sound effects : Surround, MegaBass and Reverb (used in script example) It can also replace modplug player(2) for Win 8+ users Inconvenient : Time to render datas (depends of file size) 15 | AdPlug Player AdPlug.dll ( 69ko ) is an AdLib sound player library who is able to play the following files type : A2M, ADL, AMD, BAM, CFF, CMF, D00, DFM, DMO, DRO, DTM, HSC, HSP, IMF, KSM, LAA, LDS, M, MAD, MID, MKJ, MSC, MTK, RAD, RAW, RIX, ROL, S3M, SA2, SAT, SCI, SNG, XAD, XMS, XSM For this one, time to render datas is to long, so i needed to find an other way for play modules. Using Bass.dll and particulary the "BASS_StreamPutData" function i succeeded to play module in loop while rendering it. Both DLL are loaded in memory, and 16 different module types are available in the script. No includes/files needed. Just run it. Warning : for a unique file extension (example .sng), it's sometimes possible to have several filetypes from different trackers ! AdPlug.dll Imports : msvcp71.dll, msvcr71.dll in C:\Windows\SysWOW64 ( VC Redist Installer ) Interests : Can read some obscure rare formats. Inconvenient : Can not read from memory 16 | LibMikmod Player LibMikmod.dll (85ko) will currently play the following common and not so common formats : 669, AMF, DSM, FAR, GDM, IMF, IT, MED, MOD, MTM, S3M, STM, STX, ULT, UNI, XM Interests : Can load from memory Inconvenient : only for full-screen applications, because if the application has not the focus sound is muted Downloads are available in the download section Dedicated to chiptune Lovers ! Music Links : asma.atari.org woolyss.com chipmusic.org demozoo.org modarchive.org modules.pl keygenmusic.net zxtunes.com mazemod.org amigaremix.com pouet.net plopbox.eu Modland
  11. Hi I wanted to share with you guys this automatic lyric snippet grabber that uses mainly LyricWiki API to get lyrics for you music. It can also identify your untagged music by the song's unique acoustic fingerprint using the AcoustID database and API. Additionally it will write the lyrics snippets and any missing artist and title ID3 tags to the mp3 files. This script will only get you a small part of the full lyrics for each song. This is because the LyricWiki API only returns part of the lyrics due to licensing restrictions. In order to view the full lyrics you have to click the "View full lyrics" button which will take you the lyric.wikia song page with the full lyrics. It *might* be possible to allows this script to fetch the whole lyrics if I show the mobile version of the lyric.wikia lyrics page inside a web panel in the script (source: link). But I have no experience with the IE commands in autoit so I won't be working on that any time soon. That's it, hope you like what you see Screenshot Credits LyricWiki API AcoustID API + fpcalc tool >GUIFrame by Melba >ID3 by joeyb1275 >JSMN by Ward WinHttp by trancexx and ProgAndy Silk icons by famfamfam Linecons by Designmodo Others included in source files Download here
  12. mus++

    mus++ is a new scripting language written in ASCII which can be typed on most computer keyboards. The whole concept is based on the rules and syntax of written music, so the code can be directly transfered to a standard score without having to calculate the milisecond duration of some complicated binary variant, or having to deal with any other non-musical code elements. The language itself is much better than the interpreter, but that's hopefully going to change in the future. There are some problems which I have not yet managed to solve. Even so, this current interpreter is just about good enough for my own purposes. The deficiencies in the interpreter have no bearing whatsoever on the dynamic flexibility of mus++. #include-once #include <Array.au3> ; Example 1 - Happy Birthday Local $source = "<pno> ;=125 (G -G) Q | ;A G 1, C' | +'B' :| 2, D' | +C DC | Q ;G' E C | 'B' A (F' -F) | ;E C D | +C " _MusPlusPlus($source) Sleep(600) ; Example 2 - Mozart $source = @CRLF & "<fl> ;=146 3/4 |: G | C' E C | G B G | +.C'' | +B' ;G | G -G G ;G |" $source &= @CRLF & "<fl> ;=146 3/4 |: ; | E +G | ;B D' 'B' | -C' 'B' C' D E F# | ;G 'G' B | C' -C 'B' ;C'' |" $source &= @CRLF & "<cl> ;=146 3/4 |: ; | +. | +G ; | +. | +. | ;E' -E D ;E |" $source &= @CRLF & "<tpt> ;=146 3/4 |: 'G | 'C' E C | ;'G ; 'G' | C ; C' | 'G' + | ;G -G G ;G |" $source &= @CRLF & "<timp> ;=146 3/4 |: ''G | +'C ;C | +''G ;G | A A A | G -G G G G | +.G |" $source &= @CRLF ; Line Breaks are represented by empty lines $source &= @CRLF & " ;G -G G ;G | G A B | C'' ; fin :| D' | +'B' ;C' | -D G F# G F G | +'B' ;C' | D ; DC " $source &= @CRLF & " D -D C ;D | 'B' C' D | C ; fin :| 'B' | +G ;A | +. | +G ;A | B ; DC " $source &= @CRLF & " F -F E ;F | 'G' A B | G ; fin :| ; | +.G' | _;G + | +.G' | _;G 'G' DC " $source &= @CRLF & " ;G -G G ;G | 'G G G |'C' ; fin :| ; | 'G G G | +.'G' | ;'G G G | G ; DC " $source &= @CRLF & " G | ;G G G | +''C fin :| ; | +.''G | ;G G G | +.G | ;G G DC " _MusPlusPlus($source) Func _MusPlusPlus($sSource) ; Parse mus++ $sSource = _InitialTidySource($sSource) If @error Then Return SetError(1, 0, 0) Local $iParts = 8, $aSystems = StringSplit($sSource, @LF & @LF, 1) Local $aVoices[$iParts] = ["","","","","","","",""], $aStaves For $i = 1 To $aSystems[0] $aStaves = StringSplit($aSystems[$i], @LF) If $i = 1 And $aStaves[0] <= 8 Then $iParts = $aStaves[0] ReDim $aVoices [$iParts] ElseIf $iParts <> $aStaves[0] Then Return SetError (2, 0, 0) ; Inconsistant number of voices EndIf For $j = 0 To $iParts -1 $aVoices[$j] &= " " & $aStaves[$j +1] Next Next Local $aTimeLine, $aRepeat[1][11], $iInstance, $vCurrInstrument, $vCurrKey, $sCurrNote, $iCurrOctave, $sLookFor, $sSegnoInstrument, _ $sSegnoKey, $iSegnoOctave, $sSegnoNote, $iLatestInstrument, $iLatestKey, $iCurrRepeat, $iEndings, $iSegno, $iDalSegno, $iDaCapo, _ $aAccidentals[7], $sSegnoAccidentals, $sAtTempo, $vCurrTempo, $aNotePart, $sSkipIndex, $sWarnings = "", $sErrors = "", $iTuplet, _ $bTie, $bRest, $iPitch, $iBound =1, $aInstrument[$iParts], $iHangCheck, $iRepeats, $iCurrTime, $aMessage[$iParts][1][2] ;==> voice|instance|params=time/msg Local Enum $iEntry = 0, $iEntryInstrument, $iEntryKey, $iEntryOctave, $iEntryNote, $iFirstExit, $iFirstExitOctave, _ $iFirstExitNote, $iFinalExit, $iFinalExitInstrument, $iFinalExitKey For $i = 0 To $iParts -1 $aInstrument[$i] = 0xC0 Next ; Parsing begins here For $i = 0 To $iParts -1 _ClearAccidentals($aAccidentals) $aVoices[$i] = StringStripWS($aVoices[$i], 3) StringReplace($aVoices[$i], "|:", "") ; Get loop entry points If @extended Then ReDim $aRepeat[@extended +1][11] $iInstance = 0 ; bar repeat sections encountered $vCurrInstrument = "<pno>" ; piano $vCurrKey = "0#" ; C major / A minor $sCurrNote = ";" ; quarter note $iCurrOctave = 4 $sLookFor = "" ; Look for Q or fin within a DC or DS section repeat ; Bar repeat data $aRepeat[$iInstance][$iEntry] = $iInstance $aRepeat[$iInstance][$iEntryInstrument] = $vCurrInstrument $aRepeat[$iInstance][$iEntryKey] = $vCurrKey $aRepeat[$iInstance][$iEntryOctave] = $iCurrOctave $aRepeat[$iInstance][$iEntryNote] = $sCurrNote $aRepeat[$iInstance][$iFirstExit] = $iInstance $aRepeat[$iInstance][$iFirstExitOctave] = $iCurrOctave $aRepeat[$iInstance][$iFirstExitNote] = $sCurrNote $aRepeat[$iInstance][$iFinalExit] = "" $aRepeat[$iInstance][$iFinalExitInstrument] = $vCurrInstrument $aRepeat[$iInstance][$iFinalExitKey] = $vCurrKey $iCurrRepeat = 1 ; First iteration of a bar repeat sequence $iEndings = 1 ; no separate bar repeat endings encountered yet $aTimeLine = StringRegExp($aVoices[$i], "[^\h]+", 3) $aVoices[$i] = "" $sSegnoInstrument = $vCurrInstrument ; Section repeat data $sSegnoKey = $vCurrKey ; Section repeat data => $iSegnoOctave = $iCurrOctave $sSegnoNote = $sCurrNote $sSegnoAccidentals = ",,,,,," ; array is needed when $ occurs after an accidental $iLatestInstrument = 0 ; position in timeline $iLatestKey = 0 ; position in timeline $iSegno = -1 ; position of $ $iDalSegno = -1 ; position of DS $iDaCapo = -1 ; position of DC $sAtTempo = -1 $vCurrTempo = ";=100" $sSkipIndex = "|" For $j = 0 To UBound($aTimeLine) -1 If StringInStr($sSkipIndex, "|" & $j & "|") Then ContinueLoop $iHangCheck = $j -1 Select Case _IsInstrument($aTimeLine[$j]) If $j > $iLatestInstrument Then $iLatestInstrument = $j _UpdateCurrentAttrib($vCurrInstrument, $aVoices, $aTimeLine[$j], $i) $aRepeat[$iInstance][$iEntryInstrument] = $vCurrInstrument ; Temporary Patch Case _IsKeySig($aTimeLine[$j]) If $j > $iLatestKey Then $iLatestKey = $j _UpdateCurrentAttrib($vCurrKey, $aVoices, $aTimeLine[$j], $i) Case _IsTempoMark($aTimeLine[$j]) If Not StringRegExp($aVoices[$i], "[A-Go\+;\-~\\\?]") Then $sAtTempo = $aTimeLine[$j] EndIf _UpdateCurrentAttrib($vCurrTempo, $aVoices, $aTimeLine[$j], $i) Case _IsAtTempo($aTimeLine[$j]) _UpdateCurrentAttrib($vCurrTempo, $aVoices, $sAtTempo, $i) Case _IsSegno($aTimeLine[$j]) $sSegnoKey = $vCurrKey $sSegnoInstrument = $vCurrInstrument $iSegnoOctave = $iCurrOctave $sSegnoNote = $sCurrNote $iSegno = $j $sSegnoAccidentals = "" For $k = 0 To 5 $sSegnoAccidentals &= $aAccidentals[$k] & "," Next $sSegnoAccidentals &= $aAccidentals[6] Case _IsBarLine($aTimeLine[$j]) _ClearAccidentals($aAccidentals) Case _IsStartRepeat($aTimeLine[$j]) _ClearAccidentals($aAccidentals) $iInstance += 1 If $j > $iDaCapo And $j > $iDalSegno Then $aRepeat[$iInstance][$iEntry] = $j $aRepeat[$iInstance][$iEntryInstrument] = $vCurrInstrument $aRepeat[$iInstance][$iEntryKey] = $vCurrKey $aRepeat[$iInstance][$iEntryOctave] = $iCurrOctave $aRepeat[$iInstance][$iEntryNote] = $sCurrNote $iCurrRepeat = 1 $iEndings = 1 EndIf Case _Is2ndTimeRound($aTimeLine[$j]) If $j > $iDaCapo And $j > $iDalSegno Then If $aRepeat[$iInstance][$iFinalExit] = "" Then $aRepeat[$iInstance][$iFirstExit] = $j $aRepeat[$iInstance][$iFirstExitOctave] = $iCurrOctave $aRepeat[$iInstance][$iFirstExitNote] = $sCurrNote EndIf $iRepeats = StringTrimRight($aTimeLine[$j], 1) ; string to number If $iEndings < $iRepeats Then $iEndings = $iRepeats If $iCurrRepeat > $iRepeats Then If $vCurrKey <> $aTimeLine[$iLatestKey] Then If _IsKeySig($aTimeLine[$iLatestKey]) Then $vCurrKey = $aTimeLine[$iLatestKey] $aVoices[$i] &= $vCurrKey & " " EndIf EndIf _UpdateCurrentAttrib($vCurrInstrument, $aVoices, $aTimeLine[$iLatestInstrument], $i) _ClearAccidentals($aAccidentals) $j = $aRepeat[$iInstance][$iFinalExit] ; Go to the next end repeat mark EndIf Else $j = $aRepeat[$iInstance][$iFinalExit] ; Go directly to the last end section _ClearAccidentals($aAccidentals) _UpdateCurrentAttrib($vCurrKey, $aVoices, $aRepeat[$iInstance][$iFinalExitKey], $i) _UpdateCurrentAttrib($vCurrInstrument, $aVoices, $aRepeat[$iInstance][$iFinalExitInstrument], $i) EndIf Case _IsTie($aTimeLine[$j]) Or _IsStartTuplet($aTimeLine[$j]) Or _IsEndTuplet($aTimeLine[$j]) $aVoices[$i] &= $aTimeLine[$j] & " " Case _IsNote($aTimeLine[$j]) $aNotePart = _NoteSplit($aTimeLine[$j]) If $aNotePart[0] <> "" Then $sCurrNote = _GetCurrNote($aNotePart[0]) EndIf If $aNotePart[1] <> "" Then If StringInStr($aNotePart[1], "'") Then $iCurrOctave = _GetOctave($aNotePart[1]) EndIf If StringRegExp($aNotePart[1], "[#bxz]") Then _UpdateAccidentals($aAccidentals, $aNotePart[1]) Else _GetAccidental($aAccidentals, $aNotePart[1]) EndIf EndIf $aVoices[$i] &= $aNotePart[0] & $aNotePart[1] & " " If $sAtTempo = -1 Then $sAtTempo = $vCurrTempo Case _IsEndRepeat($aTimeLine[$j]) If $j > $iDaCapo And $j > $iDalSegno Then _ClearAccidentals($aAccidentals) If $iCurrRepeat = $iEndings Then $aRepeat[$iInstance][$iFinalExit] = $j $aRepeat[$iInstance][$iFinalExitInstrument] = $vCurrInstrument $aRepeat[$iInstance][$iFinalExitKey] = $vCurrKey EndIf If $iCurrRepeat <= $iEndings Then ; Go back to the start of the loop $j = $aRepeat[$iInstance][$iEntry] ; $j will be incremented on the next pass ^^ $iCurrRepeat += 1 _UpdateCurrentAttrib($vCurrKey, $aVoices, $aRepeat[$iInstance][$iEntryKey], $i) _UpdateCurrentAttrib($vCurrInstrument, $aVoices, $aRepeat[$iInstance][$iEntryInstrument], $i) _UpdateCurrentAttrib($iCurrOctave, $aVoices, $aRepeat[$iInstance][$iEntryOctave], $i, "{", "} ") _UpdateCurrentAttrib($sCurrNote, $aVoices, $aRepeat[$iInstance][$iEntryNote], $i, "{", "} ") EndIf EndIf Case _IsDalSegno($aTimeLine[$j]) If $iDalSegno < $j Then If $iSegno = -1 Then $sWarnings &= "Voice " & $i +1 & " Warning => Expected $ sign before DS " & @CRLF ConsoleWrite($sWarnings) ; deal with this later ExitLoop ; further parsing of this voice is meaningless EndIf $iDalSegno = $j $j = $iSegno $sLookFor = "DS" _UpdateCurrentAttrib($vCurrKey, $aVoices, $sSegnoKey, $i) _UpdateCurrentAttrib($vCurrInstrument, $aVoices, $sSegnoInstrument, $i) _UpdateCurrentAttrib($iCurrOctave, $aVoices, $iSegnoOctave, $i, "{", "} ") _UpdateCurrentAttrib($sCurrNote, $aVoices, $sSegnoNote, $i, "{", "} ") $aAccidentals = StringSplit($sSegnoAccidentals, ",", 2) For $iInstance = $iInstance To 0 Step -1 If $iSegno > $aRepeat[$iInstance][$iEntry] Then ExitLoop Next EndIf Case _IsDaCapo($aTimeLine[$j]) If $iDaCapo < $j Then _ClearAccidentals($aAccidentals) $iDaCapo = $j $j = -1 $sLookFor = "DC" $iInstance = 0 _UpdateCurrentAttrib($vCurrKey, $aVoices, $aRepeat[$iInstance][$iEntryKey], $i) _UpdateCurrentAttrib($vCurrInstrument, $aVoices, $aRepeat[$iInstance][$iEntryInstrument], $i) _UpdateCurrentAttrib($iCurrOctave, $aVoices, $aRepeat[$iInstance][$iEntryOctave], $i, "{", "} ") _UpdateCurrentAttrib($sCurrNote, $aVoices, $aRepeat[$iInstance][$iEntryNote], $i, "{", "} ") EndIf Case _IsCoda($aTimeLine[$j]) If ($sLookFor = "DS" And $j < $iDalSegno) Or ($sLookFor = "DC" And $j < $iDaCapo) Then If $iDalSegno > $iDaCapo Then $j = $iDalSegno Else $j = $iDaCapo EndIf _UpdateCurrentAttrib($vCurrKey, $aVoices, $aTimeLine[$iLatestKey], $i) _UpdateCurrentAttrib($vCurrInstrument, $aVoices, $aTimeLine[$iLatestInstrument], $i) EndIf Case _IsFin($aTimeLine[$j]) If ($sLookFor = "DS" And $j < $iDalSegno) Or ($sLookFor = "DC" And $j < $iDaCapo) Then ExitLoop Case Else If _IsTimeSig($aTimeLine[$j]) Or _IsTechnique($aTimeLine[$j]) Or _IsBarRepeat($aTimeLine[$j]) Or _IsAccel($aTimeLine[$j]) Or _IsDynamicMark($aTimeLine[$j]) Then ContinueLoop ; Currently unsupported performance instructions or features Else $sErrors &= "Voice " & $i +1 & " Syntax Error => " & $aTimeLine[$j] & @CRLF $sSkipIndex &= $j & "|" ConsoleWrite("Voice " & $i +1 & " Syntax Error => " & $aTimeLine[$j] & @LF) EndIf EndSelect If $j = $iHangCheck Then $j += 1 ; Recursion correction Next ;ConsoleWrite($aVoices[$i] & @LF) $aTimeLine = StringRegExp($aVoices[$i], "[^\h]+", 3) $iInstance = UBound($aTimeLine)*2 ; upper limit... variable re-usage If $iInstance > UBound($aMessage, 2) Then ReDim $aMessage [$iParts][$iInstance][2] $vCurrInstrument = 0 $iLatestInstrument = 0 $vCurrKey = 0 ; C major / A minor $iLatestKey = 0 ; C major / A minor $vCurrTempo = 100 $iCurrOctave = 4 $sCurrNote = ";" $sLookFor = -1 ; variable re-usage $bTie = False ; variable re-usage $bRest = True $iInstance = 0 ; message count $iCurrTime = 0 $iTuplet = 1 Local $iDuration For $j = 0 To UBound($aTimeLine) -1 Select Case _IsInstrument($aTimeLine[$j]) $aTimeLine[$j] = StringRegExpReplace($aTimeLine[$j], "(_)(pno|box|org|acc|gtr|bass|tpt|sax|hn|drum|bl)", " " & "$2") $iLatestInstrument = _GetInstrument($aTimeLine[$j]) If @error And Not StringInStr($sErrors, $aTimeLine[$j]) Then $sErrors &= "Voice " & $i +1 & " Instrument not recognized => " & $aTimeLine[$j] & @CRLF ConsoleWrite("Voice " & $i +1 & " Instrument not recognized => " & $aTimeLine[$j] & @LF) ElseIf $vCurrInstrument <> $iLatestInstrument Then $vCurrInstrument = $iLatestInstrument $aMessage[$i][$iInstance][0] = $iCurrTime $aMessage[$i][$iInstance][1] = $vCurrInstrument*256 + 0xC0 $iInstance += 1 EndIf $aInstrument[$i] = $vCurrInstrument*256 + 0xC0 Case _IsKeySig($aTimeLine[$j]) $vCurrKey = _GetKey($aTimeLine[$j]) Case _IsTempoMark($aTimeLine[$j]) $vCurrTempo = _GetQuartNoteBPM($aTimeLine[$j]) Case _IsTie($aTimeLine[$j]) $bTie = True Case _IsStartTuplet($aTimeLine[$j]) $iTuplet = StringReplace($aTimeLine[$j], "(", "") If $iTuplet = "" Then $iTuplet = 3 Case _IsOctave($aTimeLine[$j]) $iCurrOctave = StringRegExpReplace($aTimeLine[$j], "[\{\}]", "") Case _IsCurrentNote($aTimeLine[$j]) $sCurrNote = StringRegExpReplace($aTimeLine[$j], "[\{\}]", "") Case _IsNote($aTimeLine[$j]) $aNotePart = _NoteSplit($aTimeLine[$j]) If $aNotePart[0] <> "" Then $sCurrNote = _GetCurrNote($aNotePart[0]) Else $aNotePart[0] = $sCurrNote EndIf $iDuration = _GetDuration($aNotePart[0], $vCurrTempo, $iTuplet) If $aNotePart[1] <> "" Then If StringInStr($aNotePart[1], "'") Then $iCurrOctave = _GetOctave($aNotePart[1]) EndIf If Not $bTie Then $aMessage[$i][$iInstance][0] = $iCurrTime $iPitch = _GetPitch($aNotePart[1], $vCurrKey, $iCurrOctave) $aMessage[$i][$iInstance][1] = BitOr(($iPitch+0x15)*256, 0x90, 0x400000) ; Midi note on $iInstance += 1 Else If Not $bRest And $sLookFor > -1 Then $aMessage[$i][$sLookFor][0] += $iDuration EndIf EndIf $bRest = False Else $bRest = True EndIf $iCurrTime += $iDuration If Not $bRest And Not $bTie Then ; Now turn note off $aMessage[$i][$iInstance][0] = $iCurrTime $aMessage[$i][$iInstance][1] = BitXOR($aMessage[$i][$iInstance -1][1], 0x400000) ; Midi note off $sLookFor = $iInstance $iInstance += 1 EndIf $bTie = False Case _IsEndTuplet($aTimeLine[$j]) $iTuplet = 1 EndSelect Next If $iInstance > $iBound Then $iBound = $iInstance Next ReDim $aMessage[$iParts][$iBound][2] ;_WalkThrough3D($aMessage) ; Debugging - Requires arratf.au3 $sLookFor = "" For $i = 0 To $iParts -1 For $j = 0 To UBound($aMessage, 2) -1 If $aMessage[$i][$j][0] == "" Then ExitLoop If Not StringInStr($sLookFor, "," & $aMessage[$i][$j][0] & ",") Then $sLookFor &= $aMessage[$i][$j][0] & "," EndIf Next Next $aTimeLine = StringSplit(StringTrimRight($sLookFor, 1), ",", 2) _ArraySortByNumber($aTimeLine) If $aTimeLine[1] = 0 Then _ArrayDelete($aTimeLine, 0) Local $aGrid[UBound($aTimeLine)][$iParts*8 +3] For $i = 0 To UBound($aTimeLine) -1 $aGrid[$i][0] = 1 $aGrid[$i][1] = $aTimeLine[$i] Next For $i = $iParts -1 To 0 Step -1 $iInstance = 0 For $j = 0 To UBound($aMessage, 2) -1 If $aMessage[$i][$j][0] == "" Then ExitLoop If $aMessage[$i][$j][0] == $aTimeLine[$iInstance] Then If BitAND($aMessage[$i][$j][1], 0x400000) = 0x400000 Then If $aGrid[$iInstance][$aGrid[$iInstance][0]] <> $aInstrument[$i] Then $aGrid[$iInstance][0] += 1 $aGrid[$iInstance][$aGrid[$iInstance][0]] = $aInstrument[$i] EndIf EndIf $aGrid[$iInstance][0] += 1 $aGrid[$iInstance][$aGrid[$iInstance][0]] = $aMessage[$i][$j][1] ElseIf $aMessage[$i][$j][0] > $aTimeLine[$iInstance] Then $iInstance += 1 If $iInstance > UBound($aTimeLine) -1 Then ExitLoop $j -= 1 EndIf Next Next ;_ArrayDisplay($aGrid) Local $iTimer, $dOpen = _MidiOutOpen() $iInstance = 0 $iTimer = TimerInit() While 1 If TimerDiff($iTimer) >= $aGrid[$iInstance][1] Then For $i = 2 To $aGrid[$iInstance][0] _MidiOutShortMsg($dOpen, $aGrid[$iInstance][$i]) Next $iInstance += 1 Else Sleep(10) EndIf If $iInstance > UBound($aTimeLine) -1 Then ExitLoop WEnd Sleep(600) _MidiOutClose($dOpen) EndFunc ;==> _MusPlusPlus #region ; conditionals Func _IsInstrument($sInstruction) Return StringRegExp($sInstruction, "(?i)(\A<[a-z \-_0-9]+>\z)") EndFunc ;==> _IsInstrument Func _IsKeySig($sInstruction) Return StringRegExp($sInstruction, "(\A[0-7][#b]\z)") EndFunc ;==> _IsKeySig Func _IsTimeSig($sInstruction) ; Requires accentuation / dynamics Return StringRegExp($sInstruction, "(\A\d+/(1|2|4|8|16|32|64)\z)") EndFunc ;==> _IsTimeSig Func _IsTempoMark($sInstruction) Return StringRegExp($sInstruction, "(\A[o\+;\-~\\\?]\.?=\d*\.?\d+\z)") EndFunc ;==> _IsTempoMark Func _IsAtTempo($sInstruction) Return $sInstruction = "@Tempo" ; not case sensitive EndFunc ;==> _IsAtTempo Func _IsSegno($sInstruction) Return $sInstruction = "$" EndFunc ;==> _IsSegno Func _IsBarLine($sInstruction) Return $sInstruction = "|" EndFunc ;==> _IsBarLine Func _IsStartRepeat($sInstruction) Return $sInstruction = "|:" EndFunc ;==> _IsStartRepeat Func _Is2ndTimeRound($sInstruction) Return StringRegExp($sInstruction, "(\A\d+,\z)") EndFunc ;==> _Is2ndTimeRound Func _IsTie($sInstruction) Return $sInstruction = "_" EndFunc ;==> _IsTie Func _IsStartTuplet($sInstruction) Return StringRegExp($sInstruction, "(\A\d*\(\z)") EndFunc ;==> _IsStartTuplet Func _IsNote($sNote) If StringRegExp($sNote, "(\A'*[A-G](#|b|bb|x|z)?'*\z)") Then Return 1 Return StringRegExp($sNote, "(\A[o\+;\-~\\\?\.]+('*[A-G](#|b|bb|x|z)?'*)?\z)") EndFunc ;==> _IsNote Func _IsEndTuplet($sInstruction) Return $sInstruction == ")" EndFunc ;==> _IsEndTuplet Func _IsEndRepeat($sInstruction) Return $sInstruction = ":|" EndFunc ;==> _IsEndRepeat Func _IsCoda($sInstruction) Return $sInstruction == "Q" EndFunc ;==> _IsCoda Func _IsDalSegno($sInstruction) Return $sInstruction == "DS" EndFunc ;==> _IsDalSegno Func _IsDaCapo($sInstruction) Return $sInstruction == "DC" EndFunc ;==> _IsDaCapo Func _IsFin($sInstruction) Return $sInstruction == "fin" EndFunc ;==> _IsFin Func _IsOctave($sInstruction) Return StringRegExp($sInstruction, "\A\{[0-8]\}\z") EndFunc ;==> _IsOctave Func _IsCurrentNote($sInstruction) Return StringRegExp($sInstruction, "\A\{[o+;=~\?]\.*\}\z") EndFunc ;==> _IsCurrentNote #endregion ;==> conditionals #region ; currently unsupported features Func _IsTechnique($sInstruction) ; Returns an integer - gliss is currently not supported Return StringInStr(" gliss pizz ", " " & $sInstruction & " ", 1) EndFunc ;==> _IsTechnique Func _IsBarRepeat($sInstruction) ; currently unsupported Return StringRegExp($sInstruction, "(\A%\d*\z)") EndFunc ;==> _IsBarRepeat Func _IsAccel($sInstruction) ; currently unsupported Return StringInStr(" accel rit ", " " & $sInstruction & " ", 1) EndFunc ;==> _IsAccel Func _IsDynamicMark($sInstruction) ; Returns an integer - currently unsupported Return StringInStr(" cres dim ppp pp /p mp mf /f ff fff ", " " & $sInstruction & " ", 1) EndFunc ;==> _IsDynamicMark #endregion ;==> currently unsupported features #region ; data requests Func _GetAccidental($aAccidentals, ByRef $sNote) Local $sAlpha = StringReplace($sNote, "'", "") $sNote = StringReplace($sNote, $sAlpha, $sAlpha & $aAccidentals[Asc($sAlpha) - 65], 0, 1) EndFunc ;==> _GetAccidental Func _GetKey($sKey) Local $iSign = 1 If StringInStr($sKey, "b", 1) Then $iSign = -1 Return StringRegExpReplace($sKey, "[#b]", "")*$iSign EndFunc ;==> _GetKey Func _GetQuartNoteBPM($sTempo) Local $aTempo = StringSplit($sTempo, "=", 2) Local $iNote = StringInStr("?\~-;+o", $aTempo[0]) -5 Return $aTempo[1]*2^$iNote EndFunc ;==> _GetQuartNoteBPM Func _GetCurrNote($sNote) Local $sCurrChr, $sRhythm = "" For $i = StringLen($sNote) To 1 Step -1 $sCurrChr = StringMid($sNote, $i, 1) $sRhythm = $sCurrChr & $sRhythm If StringInStr("o+;-~\?", $sCurrChr, 1) Then ExitLoop Next Return $sRhythm EndFunc ;==> _GetCurrNote Func _GetOctave($sNote) Local $iPos, $iOctave = 4 For $i = 65 To 71 $iPos = StringInStr($sNote, Chr($i), 1) If $iPos Then ExitLoop EndIf Next For $i = 1 To $iPos -1 If StringMid($sNote, $i, 1) = "'" Then $iOctave -= 1 Next For $i = $iPos +1 To StringLen($sNote) If StringMid($sNote, $i, 1) = "'" Then $iOctave += 1 Next Return $iOctave EndFunc ;==> _GetOctave Func _GetPitch($sName, $iKey = 0, $iOctave = 4) Local $iPitch, $sAlpha Select Case StringInStr($sName, "C", 1) $sAlpha = "C" $iPitch = 39 Case StringInStr($sName, "D", 1) $sAlpha = "D" $iPitch = 41 Case StringInStr($sName, "E", 1) $sAlpha = "E" $iPitch = 43 Case StringInStr($sName, "F", 1) $sAlpha = "F" $iPitch = 44 Case StringInStr($sName, "G", 1) $sAlpha = "G" $iPitch = 46 Case StringInStr($sName, "A", 1) $sAlpha = "A" $iPitch = 48 Case StringInStr($sName, "B", 1) $sAlpha = "B" $iPitch = 50 EndSelect Select Case StringInStr($sName, "bb", 1) $iPitch -= 2 Case StringInStr($sName, "b", 1) $iPitch -= 1 Case StringInStr($sName, "z", 1) $iPitch += 0 Case StringInStr($sName, "#", 1) $iPitch += 1 Case StringInStr($sName, "x", 1) $iPitch += 2 Case $iKey If $iKey > 0 Then If StringInStr(StringLeft("FCGDAEB", $iKey), $sAlpha) Then $iPitch += 1 Else If StringInStr(StringRight("FCGDAEB", -$iKey), $sAlpha) Then $iPitch -= 1 EndIf EndSelect $iOctave -= 4 $iPitch += $iOctave*12 If $iPitch < 0 Or $iPitch > 87 Then Return SetError (2, 0, "") ; Out of range pitch Return $iPitch ; values range from 0 to 87 EndFunc ;==> _GetPitch Func _GetDuration($sNote, $iTempo = 100, $iTuplet = 1) Local $sLen = StringLen($sNote) If Not $sLen Then Return Default If StringLeft($sNote, 1) = "." Then Return SetError(1, 0, 0) ; Syntax error - Dot not preceeded by a note value Local $iDuration = 0, $iDots = 0, $sCurrChr = "", $iID, $iNote = 0 For $i = 1 To $sLen $sCurrChr = StringMid($sNote, $i, 1) $iID = StringInStr("?\~-;+o.", $sCurrChr) -1 Switch $iID Case 0 To 6 $iDuration += $iNote $iNote = 6930 * 2^$iID Case 7 While $sCurrChr = "." $iDots += 1 $i += 1 $sCurrChr = StringMid($sNote, $i, 1) WEnd $iNote *= (2^($iDots +1) -1)/2^$iDots $i -= 1 $iDots = 0 EndSwitch Next $iDuration += $iNote If $iTuplet > 1 Then Switch $iTuplet Case 2, 4, 8, 16, 32, 64 ; In mus - only 2 and 4 appear, and then only in compound time $iDuration *= 3/2 ; it's the same result in all cases Case 3 ; triplets are the most common tuplet division $iDuration *= 2/3 Case 5 To 7 $iDuration *= 4/$iTuplet Case 9 To 15 ; In mus - tuplets greater than 12 almost never appear $iDuration *= 8/$iTuplet Case 17 To 31 $iDuration *= 16/$iTuplet Case 33 To 63 $iDuration *= 32/$iTuplet Case 65 To 127 $iDuration *= 64/$iTuplet Case Else Return SetError (2, 0, 0) ; Unsupported out of range tuplet value EndSwitch EndIf Return $iDuration*125/(231*$iTempo) EndFunc ;==> _GetDuration Func _GetInstrument($vInstrument) $vInstrument = StringRegExpReplace($vInstrument, "[<>]", "") Local $aMIDIInst[72][4] _ ; A selection of available MIDI imstruments = _ ; Name , ##,Mn,Mx [["pno" , 0, 0,87], _ ; Acoustic Grand Piano ... KEYBOARDS ["br pno" , 1, 0,87], _ ; Bright Piano ["e pno" , 2, 0,87], _ ; Electric Grand Piano ["h-t pno" , 3, 0,87], _ ; Honky-tonk piano ["hpsd" , 6, 0,87], _ ; Harpsichord ["clav" , 7, 0,87], _ ; Clavichord ["cel" , 8, 0,87], _ ; Celesta ["glock" , 9, 0,87], _ ; Glockenspiel ... PITCHED PERCUSSION ["mus box" , 10, 0,87], _ ; Music Box ["vib" , 11, 0,87], _ ; Vibraphone ["marim" , 12, 0,87], _ ; Marimba ["xyl" , 13, 0,87], _ ; Xylophone ["chimes" , 14, 0,87], _ ; Tubular Bells ["dulc" , 15, 0,87], _ ; Dulcimer ["ham org" , 16, 0,87], _ ; Drawbar Organ ... ORGAN ["perc org" , 17, 0,87], _ ; Percussive Organ ["org" , 19, 0,87], _ ; Church Organ ["harm" , 20, 0,87], _ ; Harmonium Reed Organ ["accord" , 21, 0,87], _ ; Accordion ["mouth org", 22, 0,87], _ ; Harmonica ["tango acc", 23, 0,87], _ ; Bandoneon ["gtr" , 24, 0,87], _ ; Classical Guitar ... GUITAR ["a gtr" , 25, 0,87], _ ; Accoustic Guitar ["jazz gtr" , 26, 0,87], _ ; Jazz Guitar ["e gtr" , 27, 0,87], _ ; Electric Guitar ["mut gtr" , 28, 0,87], _ ; Muted Electric Guitar ["fuzz gtr" , 30, 0,87], _ ; Distortion Guitar ["a bass" , 32, 0,87], _ ; Acoustic Bass ... BASS ["e bass" , 33, 0,87], _ ; Electric Bass ["bass" , 34, 0,87], _ ; Upright Bass ["f bass" , 35, 0,87], _ ; Fretless Bass ["sl bass" , 36, 0,87], _ ; Slap Bass ["vln" , 40, 0,87], _ ; Violin ... STRINGS ["vla" , 41, 0,87], _ ; Viola ["vc" , 42, 0,87], _ ; Cello ["db" , 43, 0,87], _ ; Double Bass ["hp" , 46, 0,87], _ ; Harp ["timp" , 47, 0,87], _ ; Timpani (perc) ["tpt" , 56, 0,87], _ ; Trumpet ... BRASS ["tbn" , 57, 0,87], _ ; Trombone ["tba" , 58, 0,87], _ ; Tuba ["mut tpt" , 59, 0,87], _ ; Muted Trumpet ["hn" , 60, 0,87], _ ; French Horn ["s sax" , 64, 0,87], _ ; Soprano Sax ... REED ["a sax" , 65, 0,87], _ ; Alto Sax ["sax" , 66, 0,87], _ ; Tenor Sax ["b sax" , 67, 0,87], _ ; Baritone Sax ["ob" , 68, 0,87], _ ; Oboe ["eng hn" , 69, 0,87], _ ; English Horn ["bsn" , 70, 0,87], _ ; Bassoon ["cl" , 71, 0,87], _ ; Clarinet ["picc" , 72, 0,87], _ ; Piccolo ... PIPE ["fl" , 73, 0,87], _ ; Flute ["rec" , 74, 0,87], _ ; Recorder ["pan" , 75, 0,87], _ ; Panpipes ["bottle" , 76, 0,87], _ ; Bottle ["shaku" , 77, 0,87], _ ; Shakuhachi ["whistle" , 78, 0,87], _ ; Whistle ["oc" , 79, 0,87], _ ; Ocarina ["sitar" ,104, 0,87], _ ; Sitar ... OTHER ["banjo" ,105, 0,87], _ ; Banjo ["shamisen" ,106, 0,87], _ ; Shamisen ["koto" ,107, 0,87], _ ; Koto ["kalimba" ,108, 0,87], _ ; Kalimba (perc) ["bagp" ,109, 0,87], _ ; Bagpipe ["fiddle" ,110, 0,87], _ ; Fiddle ["shanai" ,111, 0,87], _ ; Shanai (woodwind) ["bell" ,112, 0,87], _ ; Tinkle Bell ["st drum" ,114, 0,87], _ ; Steel Drums ["w bl" ,115, 0,87], _ ; Woodblock ["taiko" ,116, 0,87], _ ; Taiko Drum ["tom-t" ,117, 0,87]] ; Tom-tom For $i = 0 To 71 If $aMIDIInst[$i][0] = $vInstrument Then $vInstrument = $aMIDIInst[$i][1] ExitLoop EndIf Next $vInstrument = StringRegExpReplace($vInstrument, "[<>]", "") If StringRegExp($vInstrument, "[^\d]") Or $vInstrument < 0 Or $vInstrument > 127 Then Return SetError(1, 0, 0) ; returns Grand Piano Return $vInstrument ; values range from 0 to 117 EndFunc ;==> _GetInstrument #endregion ;==> data requests #region ; miscellaneous functions Func _InitialTidySource($sSource) If _IllegalDotCheck($sSource) Then Return SetError(1, 0, 0) $sSource = StringReplace($sSource, '"', "''") ; Helmholtz-Wilkinson octaves $sSource = StringReplace($sSource, '(', "( ") ; Add spaces after ( $sSource = StringReplace($sSource, ')', " ) ") ; Add spaces before and after ) $sSource = StringRegExpReplace($sSource, "(<\h+)", " <") ; Remove spaces after < $sSource = StringRegExpReplace($sSource, "(\h+>)", "> ") ; Remove spaces before > $sSource = StringReplace($sSource, '_', " _ ") ; Add spaces before and after underscore $sSource = StringReplace($sSource, '|:', "|: ") ; Add spaces after start repeats $sSource = StringReplace($sSource, ':|', " :|") ; Add spaces before end repeats $sSource = StringReplace($sSource, ':|:', ":||:") ; Convert double repeat marks _ $sSource = StringReplace($sSource, '|', " | ") ; Add spaces before and after bar lines $sSource = StringReplace($sSource, '| :', "|:") ; Restore start repeat marks $sSource = StringReplace($sSource, ': |', ":|") ; Restore end repeat marks $sSource = StringReplace($sSource, ' | | ', " || ") ; Restore double bar lines $sSource = StringRegExpReplace($sSource, "(<[\-\w]+)(\h+)(pno|box|org|acc|gtr|bass|tpt|sax|hn|drum|bl)", "$1" & "_" & "$3") $sSource = StringReplace(StringReplace($sSource, @CRLF, @LF), @CR, @LF) ; Replace all breaks with @LF $sSource = StringRegExpReplace($sSource, "(\n\h*)", @LF) ; Remove spaces after breaks $sSource = StringRegExpReplace($sSource, "[\n]{2,}", @LF & @LF) ; Remove duplicate empty lines $sSource = StringRegExpReplace($sSource, "(\A\n*)", "") ; Remove Preceeding breaks $sSource = StringRegExpReplace($sSource, "(\n*\z)", "") ; Remove Trailing breaks Return $sSource EndFunc ;==> _InitialTidySource Func _UpdateCurrentAttrib(ByRef $vCurrAttrib, ByRef $aVoices, $vNewAttrib, $iIndex, $sPadLeft = "", $sPadRight = " ") If $vCurrAttrib <> $vNewAttrib Then $vCurrAttrib = $vNewAttrib $aVoices[$iIndex] &= $sPadLeft & $vCurrAttrib & $sPadRight EndIf EndFunc ;==> _UpdateCurrentAttrib Func _ClearAccidentals(ByRef $aAccidentals) For $i = 0 To 6 $aAccidentals[$i] = "" Next EndFunc ;==> _ClearAccidentals Func _UpdateAccidentals(ByRef $aAccidentals, $sNote) $sNote = StringReplace($sNote, "'", "") Local $sAlpha = StringLeft($sNote, 1) $aAccidentals[Asc($sAlpha) - 65] = StringTrimLeft($sNote, 1) EndFunc ;==> _UpdateAccidentals Func _NoteSplit($sNote) Local $aNotePart[2] = ["", ""] $aNotePart[1] = StringRegExpReplace($sNote, "[o\+;\-~\\\?\.]+", "") ; Remove rhthmic values $aNotePart[0] = StringLeft($sNote, StringLen($sNote) - StringLen($aNotePart[1])) Return $aNotePart EndFunc ;==> _NoteSplit Func _IllegalDotCheck($sVoo) Return StringRegExp($sVoo, "(o\.{7}|\+\.{6}|;\.{5}|\-\.{4}|~\.{3}|\\\.\.|\?\.)") ; Warning - detected an unsupported number of dots after a note EndFunc ;==> _IllegalDotCheck #endregion ;==> miscellaneous functions #region ; MIDI functions ;======================================================= ;Retrieves a MIDI handle and Opens the Device ;Parameters(Optional) - Device ID, Window Callback, ; instance, flags ;Author : Eynstyne ;Library : Microsoft winmm.dll ;======================================================= Func _MidiOutOpen($devid = 0, $callback = 0, $instance = 0, $flags = 0) Local $ret = DllCall("winmm.dll", "long", "midiOutOpen", "handle*", 0, "int", $devid, "dword_ptr", $callback, "dword_ptr", $instance, "long", $flags) If @error Then Return SetError(@error,0,0) If $ret[0] Then Return SetError(-1,$ret[0],0) Return $ret[1] EndFunc ;==>_MidiOutOpen ;======================================================= ;Closes Midi Output/Input devices ;Parameters - MidiHandle ;Author : Eynstyne ;Library : Microsoft winmm.dll ;======================================================= Func _MidiOutClose ($hmidiout) Local $ret = DllCall("winmm.dll", "long", "midiOutClose", "handle", $hmidiout) If @error Then Return SetError(@error,0,0) If $ret[0] Then Return SetError(-1,$ret[0],0) Return $ret[0] EndFunc ;==> _MidiOutClose ;======================================================= ;Gets the Mixer Volume for MIDI ;Parameters - None ;Author : Eynstyne ;Library : Microsoft winmm.dll ;======================================================= Func _MidiOutGetVolume ($devid = 0) Local $ret = DllCall("winmm.dll", "long", "midiOutGetVolume", "handle", $devid, "dword*",0) If @error Then Return SetError(@error,0,0) If $ret[0] Then Return SetError(-1,$ret[0],0) Return $ret[2] EndFunc ;==> _MidiOutGetVolume ;======================================================= ;Sets the Mixer Volume for MIDI ;Parameters - Volume (0 - 65535) ;Author : Eynstyne ;Library : Microsoft winmm.dll ;======================================================= Func _MidiOutSetVolume($iVolume = 65535, $devid = 0) Local $iMixVolume=BitAND($iVolume,0xFFFF)+BitShift(BitAND($iVolume,0xFFFF),-16) ; From Ascend4nt Local $ret = DllCall("winmm.dll", "long", "midiOutSetVolume", "handle", $devid, "int", $iMixVolume) If @error Then Return SetError(@error,0,0) If $ret[0] Then Return SetError(-1,$ret[0],0) Return $ret[0] EndFunc ;==> _MidiOutSetVolume ;======================================================= ;MIDI Message Send Function ;Parameters - Message as Hexcode or Constant ;Author : Eynstyne ;Library : Microsoft winmm.dll ;======================================================= Func _MidiOutShortMsg($hmidiout, $msg) Local $ret = DllCall("winmm.dll", "long", "midiOutShortMsg", "handle", $hmidiout, "long", $msg) If @error Then Return SetError(@error,0,0) If $ret[0] Then Return SetError(-1,$ret[0],0) Return $ret[0] EndFunc ;==> _MidiOutShortMsg #endregion ;==> MIDI functions #region ; functions ripped from arrayf.au3 and stringf.au3 ; #FUNCTION# ==================================================================================================================== ; Name...........: _ArraySortByNumber ; Description ...: Sorts a 1D array numerically ascending. ; Syntax.........: _ArraySortByNumber(ByRef $avArray [, $bVulgarFrac = False]) ; Parameters ....: $avArray - [ByRef] The array to sort ; $bVulgarFrac - [Optional] If set to True, vulgar fractions will be also be sorted numerically ; Return values .: Success - Returns 1 ; Failure - Returns zero and sets @error to the following values: ; |@error = 1 : $avArray is not a one dimensional array ; Author ........: czardas ; Modified.......: ; Remarks .......: The array is sorted first by numbers and then by strings. ; Related .......: _ArraySort, _ArraySortByLen ; Link ..........: ; Example .......: ; =============================================================================================================================== Func _ArraySortByNumber(ByRef $avArray, $bVulgarFrac = False) If Not IsArray($avArray) Or UBound($avArray, 0) > 1 Then Return SetError(1, 0, 0) Local $iBound = UBound($avArray) -1 Local $aTemp[$iBound +1][2] For $i = 0 To $iBound $aTemp[$i][0] = $avArray[$i] If _StringIsNumber($avArray[$i], $bVulgarFrac) Then $aTemp[$i][1] = Execute($avArray[$i]) Else $aTemp[$i][1] = "z" & $avArray[$i] EndIf Next _ArraySort($aTemp, 0, 0, 0, 1) For $i = 0 To $iBound $avArray[$i] = $aTemp[$i][0] Next Return 1 EndFunc ;==> _ArraySortByNumber ; #FUNCTION# ==================================================================================================================== ; Name...........: _StringIsNumber ; Description ...: Checks whether a string is a number as recognised by the AutoIt interpreter ; Syntax.........: _StringIsNumber($sString [, $bVulgarFrac]) ; Parameters ....: $sString - The string to test ; $bVulgarFrac - [Optional] if set to True, vulgar fractions will also return True ; Return values .: True or False ; Author ........: czardas ; Remarks .......: Returns True for integers, floats, hexadecimal and scientific notation. ; Related .......: StringIsDigit, StringIsFloat, StringIsInt, StringIsXDigit ; Link ..........: ; Example .......: MsgBox(0, "1.2e-300 is a number", _StringIsNumber("1.2e-300")) ; =============================================================================================================================== Func _StringIsNumber($sString, $bVulgarFrac = False) Local $bReturn = False If StringIsInt($sString) Or StringIsFloat($sString) Then $bReturn = True ; string is integer or float ElseIf StringRegExp($sString, "(?i)(\A[\+\-]?0x[A-F\d]+\z)") Then $bReturn = True ; string is hexadecimal integer ElseIf StringRegExp($sString, "(?i)(\A[\+\-]?\d*\.?\d+e[\+\-]?\d+\z)") Then $bReturn = True ; exponential (or scientific notation) ElseIf $bVulgarFrac And StringRegExp($sString, "(\A[\+\-]?\d+/\d+\z)") Then $bReturn = True ; string is a vulgar fraction EndIf Return $bReturn EndFunc ; _StringIsNumber #endregion ;==> functions ripped from arrayf.au3 and stringf.au3 #cs ; incomplete and unorganized comments note attributes ==> all new notes inherit attributes from the previous note played with the exception of repeats staff attributes ==> affecting all subsequent new notes (mus) ... key, instrument, time signature performance attributes ==> affecting all subsequent notes played including repeats (mus) tempo settings short lived attributes ==> affecting remaining notes within the bar ... accidentals section repeats ==> DC and DS multiple bar repeats ==> |: and :| o ==> Lower case o ..... Whole note ......... open note + ==> Plus symbol ...... Half note .......... open note with a stem ; ==> Apostrophe ....... Quarter note ....... closed note with a stem - ==> Minus sign ....... Eighth note ........ single flag ~ ==> Tilde ............ Sixteenth note ····· double flag \ ==> Back slash ....... Thirty-second note . tripple flag ? ==> Question mark .... Sixty-fourth note .. quadruple flag (very rare) ' ==> 1 octave (above or below) " ==> 2 octaves (above or below) "' ==> 3 octaves (above or below) "" ==> 4 octaves (above or below) Accidentals # ==> sharp b ==> flat x ==> double sharp bb ==> double flat z ==> natural Other symbols _ ==> tie . ==> dot ( ==> start triplet 5( ==> start quintuplet ) ==> end tuplet | ==> bar line |: ==> start repeat :| ==> end repeat 1, ==> first time round 2, ==> second time round DC ==> da capo $ ==> segno DS ==> dal segno fin ==> fine Q ==> coda @Tempo ==> a tempo <instrument name> ==> instrument time signatutes n/2^n 2/4, 3/4, 6/8 etc... tempo markings ;=100 ==> 100 quarter note beats ber minute Key Signatures with sharps 0# ==> C major ==> C D E F G A B C 1# ==> G major ==> G A B C D E F# G 2# ==> D major ==> D E F# G A B C# D 3# ==> A major ==> A B C# D E F# G# A 4# ==> E major ==> E F# G# A B C# D# E 5# ==> B major ==> B C# D# E F# G# A# B 6# ==> F# major ==> F# G# A# B C# D# E# F# 7# ==> C# major ==> C# D# E# F# G# A# B# C# Key Signatures with flats 0b ··· C major ···· C D E F G A B C 1b ··· F major ···· F G A Bb C D E F 2b ··· Bb major ··· Bb C D Eb F G A Bb 3b ··· Eb major ··· Eb F G Ab Bb C D Eb 4b ··· Ab major ··· Ab Bb C Db Eb F G Ab 5b ··· Db major ··· Db Eb F Gb Ab Bb C Db 6b ··· Gb major ··· Gb Ab Bb C Db Eb Fb G 7b ··· Cb major ··· Cb Db Eb Fb Gb Ab Bb Cb Supported tuplet divisions Note Divisions ····································· 3 5to7 9to15 17to31 33to63 65to127 \ ? ~ \ ? - ~ \ ? ; - ~ \ ? + ; - ~ \ ? o + ; - ~ \ ? Supported tuplets for compound time Note Divisions ································ 2 4 8 16 32 64 \. ? ~. \ ? -. ~ \ ? ;. - ~ \ ? +. ; - ~ \ ? o. + ; - ~ \ ? Dotted notes o. == o+ , o.. == o+; +. == +; , +.. == +;- ;. == ;- , ;.. == ;-~ -. == -~ , -.. == -~\ ~. == ~\ , ~.. == ~\? \. == \? o...... == o+;-~\? Illegal sequences o....... +...... ;..... -.... ~... \.. ?. ""C ==> 4th 8va below = sub-contra octave "'C ==> 3rd 8va below "C ==> 2nd 8va below 'C ==> 1st 8va below 'C' ==> Middle C C' ==> 1st 8va above C" ==> 2nd 8va above C"' ==> 3rd 8va above C"" ==> 4th 8va above Full Range = ""A to C"" After DC and DS all repeat marks are ignored on second run. With separate endings the final section is entered immediately. Q or $ do not belong in a separate ending section. Coda occurs in a section which is skipped |: 1, Q :|2, [incorrect] => will miss the coda altogether The continuation from segno is unclear |: 1, $ :|2, [incorrect] => allow rhythmic corruption The following is fine |: $ 1, :|2, Q :| DS |Q Coda should not be placed before segno | Q | $ | DS | Q [incorrect] When entering the coda section repeat marks are reinstated Before DC or DS ignore $, Q and fin After DC go to the start and continue from there After DS look behind for $ and continue from there After DC or DS stop when you see fin or go to final section when you see Q Search for final section Q after DC or DS (whichever is greater) In the final section Q ignore DC DS Q $ - they do not belong in the coda After DC also look for DS and after DS also look for DC After DC or DS repeat marks are ignored within the repeated sequence With repeats that have separate endings, the final ending is entered immediately All other endings are skipped Repeat marks are reinstated after DC (or DS depending which was last encountered) DC DS $ fin may only be used once Q if used must appear twice Illegal characters {}[]&¬` #ce ;==> incomplete and unorganized comments The interpreter contains some unused code sections, some of which may be used in the future. Here's the mus++ source for the second example: <fl> ;=146 3/4 |: G | C' E C | G B G | +.C'' | +B' ;G | G -G G ;G | <fl> ;=146 3/4 |: ; | E +G | ;B D' 'B' | -C' 'B' C' D E F# | ;G 'G' B | C' -C 'B' ;C'' | <cl> ;=146 3/4 |: ; | +. | +G ; | +. | +. | ;E' -E D ;E | <tpt> ;=146 3/4 |: 'G | 'C' E C | ;'G ; 'G' | C ; C' | 'G' + | ;G -G G ;G | <timp> ;=146 3/4 |: ''G | +'C ;C | +''G ;G | A A A | G -G G G G | +.G | ;G -G G ;G | G A B | C'' ; fin :| D' | +'B' ;C' | -D G F# G F G | +'B' ;C' | D ; DC D -D C ;D | 'B' C' D | C ; fin :| 'B' | +G ;A | +. | +G ;A | B ; DC F -F E ;F | 'G' A B | G ; fin :| ; | +.G' | _;G + | +.G' | _;G 'G' DC ;G -G G ;G | 'G G G |'C' ; fin :| ; | 'G G G | +.'G' | ;'G G G | G ; DC G | ;G G G | +''C fin :| ; | +.''G | ;G G G | +.G | ;G G DC All the features of mus++ will be documented in due course. For now just feed it anything you like and if it doesn't produce any sound it's an error. Other kinds of errors also need work - you'll just have to trust your ear. Multiple voices can sometimes interfere with each other, which is one of the problems with the interpreter I mentioned earlier. I know why this happens.
  13. Would you Listen Last 100 Uk Top Charts singles like a JukeBox or Radio in random order and without advertising ? It's possible by getting charts List on charts website http://creativedisc.com/category/top-charts/uk-top-100-singles/ updated weekly and searching songs list on youtube. Changelog 1.0.6.1 Script completly rewrited. All externals fils are includes. New youtube search engine improved for listen the good song ! Blacklist Management improved. Video can be visible. Now flashplayer sound is muted while Ads. User clicks on flashplayer progress bar are now detected for the detection of the end of the song. New Buttons. Changelog 1.0.6.2 Adapted to new AutoIt Version and Youtube changes. Hope you like it ! Previous downloads : 500 source : TinyChartsJukebox v1.0.6.2.au3.html executable : TinyChartsJukebox.exe.html (Once the html file is downloaded, double click on it for start the download)
×