Leaderboard
Popular Content
Showing content with the highest reputation on 05/28/2013 in all areas
-
Resource project Second Version
argumentum and one other reacted to wolf9228 for a topic
In the new versions of the autoit language, constant variables have been added in its reference that disrupt the work of the code and these variables are Global Const $RT_ACCELERATOR = 9 Global Const $RT_ANICURSOR = 21 Global Const $RT_ANIICON = 22 Global Const $RT_BITMAP = 2 Global Const $RT_CURSOR = 1 Global Const $RT_DIALOG = 5 Global Const $RT_DLGINCLUDE = 17 Global Const $RT_FONT = 8 Global Const $RT_FONTDIR = 7 Global Const $RT_GROUP_CURSOR = ($RT_CURSOR + 11) Global Const $RT_ICON = 3 Global Const $RT_GROUP_ICON = ($RT_ICON + 11) Global Const $RT_HTML = 23 Global Const $RT_MANIFEST = 24 Global Const $RT_MENU = 4 Global Const $RT_MESSAGETABLE = 11 Global Const $RT_PLUGPLAY = 19 Global Const $RT_RCDATA = 10 Global Const $RT_STRING = 6 Global Const $RT_VERSION = 16 Global Const $RT_VXD = 20 Since these variables already exist in the code The code has been updated and now it works...thanks. New Project Files New_Resource.zip Resource.au3 #include <Constants.au3> #include <WinAPI.au3> #include <Memory.au3> Func ResGet($ResType,$ResName,$ResLanguage = -1,$ModuleName = "") Local $DataType1 = "LONG",$DataType2 = "LONG" Local $LPVOID,$HRSRC,$ResSize,$HGLOBAL if IsString($ResName) Then $ResName = StringUpper($ResName) $DataType1 = "WSTR" EndIf If IsString($ResType) Then $ResType = StringUpper($ResType) $DataType2 = "WSTR" EndIf if StringLen($ModuleName) Then $HModule = _WinAPI_LoadLibraryEx($ModuleName,$LOAD_LIBRARY_AS_DATAFILE) if $HModule = 0 Then Return SetError(1,0,0) Else $HModule = 0 EndIf if ($ResLanguage <> -1) Then $HRSRC = DllCall("Kernel32.dll","ptr","FindResourceExW","ptr",$HModule, _ $DataType2,$ResType,$DataType1,$ResName,"WORD",$ResLanguage) if @error Or $HRSRC[0] = 0 Then Return SetError(2,0,0) Else $HRSRC = DllCall("Kernel32.dll","ptr","FindResourceW","ptr",$HModule, _ $DataType1,$ResName,$DataType2,$ResType) if @error Or $HRSRC[0] = 0 Then Return SetError(2,0,0) EndIf $HRSRC = $HRSRC[0] $ResSize = DllCall("Kernel32.dll","DWORD","SizeofResource","ptr",$HModule,"ptr",$HRSRC) if (@error Or $ResSize[0] = 0) Then Return SetError(3,0,0) $ResSize = $ResSize[0] $HGLOBAL = DllCall("Kernel32.dll","ptr","LoadResource","ptr",$HModule,"ptr",$HRSRC) if @error Or $HGLOBAL[0] = 0 Then Return SetError(4,0,0) $HGLOBAL = $HGLOBAL[0] $LPVOID = DllCall("Kernel32.dll","ptr","LockResource","ptr",$HGLOBAL) if @error Or $LPVOID[0] = 0 Then $BOOL = DllCall("Kernel32.dll","BOOL","FreeResource","ptr",$HGLOBAL) Return SetError(5,0,0) EndIf $LPVOID = $LPVOID[0] $ByteStruct = DllStructCreate("BYTE[" & $ResSize & "]") _MemMoveMemory($LPVOID,DllStructGetPtr($ByteStruct),$ResSize) $BOOL = DllCall("Kernel32.dll","BOOL","FreeResource","ptr",$HGLOBAL) if ($HModule) Then _WinAPI_FreeLibrary($HModule) Return SetError(0,$ResSize,$ByteStruct) EndFunc Func ResToFile($FileName,$ResType,$ResName,$ResLanguage = -1,$ModuleName = "",$Mode = 10) $ByteStruct = ResGet($ResType,$ResName,$ResLanguage,$ModuleName) if @error Then Return SetError(1,0,False) $OpeFile = FileOpen($FileName,$Mode) if @error Then Return SetError(2,0,False) FileWrite($OpeFile,Binary(DllStructGetData($ByteStruct,1))) if @error Then Return SetError(3,0,False) FileClose($OpeFile) Return SetError(0,0,True) EndFunc Func StringResGet($ResType,$ResName,$ResLanguage = -1,$Unicode = False,$ModuleName = "") Local $DtatType = "CHAR" $ByteStruct = ResGet($ResType,$ResName,$ResLanguage,$ModuleName) if @error Then Return SetError(1,0,0) $ResSize = @extended $LPVOID = DllStructGetPtr($ByteStruct) if ($Unicode) Then $DtatType = "WCHAR" $ResSize = Int($ResSize/2) EndIf $StrStruct = DllStructCreate($DtatType & "[" & $ResSize & "]",$LPVOID) if @error Then Return SetError(2,0,0) $nString = DllStructGetData($StrStruct,1) Return SetError(0,StringLen($nString),$nString) EndFunc Func ResGetImage($ResType,$ResName,$ResLanguage = -1,$ModuleName = "") Switch $ResType Case $RT_BITMAP $hImage = LoadBitmap($ResName,$ModuleName) if @error Then Return SetError(1,0,0) Return SetError(0,1,$hImage) Case $RT_GROUP_ICON $hImage = LoadIcon($ResName,$ModuleName) if @error Then Return SetError(2,0,0) Return SetError(0,3,$hImage) Case $RT_GROUP_CURSOR $hImage = LoadCursor($ResName,$ModuleName) if @error Then Return SetError(3,0,0) Return SetError(0,5,$hImage) Case Else $ByteStruct = ResGet($ResType,$ResName,$ResLanguage,$ModuleName) if @error Then Return SetError(4,0,0) $ResSize = @extended $hMemory = _MemGlobalAlloc($ResSize,$GHND) if Not($hMemory) Then Return SetError(5,0,0) $hLock = _MemGlobalLock($hMemory) if Not($hLock) Then _MemGlobalFree($hMemory) Return SetError(6,0,0) EndIf _MemMoveMemory(DllStructGetPtr($ByteStruct),$hLock,$ResSize) $lpstream = CreateStreamOnHGlobal($hLock,True) if @error Then _MemGlobalFree($hMemory) Return SetError(7,0,0) EndIf $riid = _WinAPI_GUIDFromString("{7BF80981-BF32-101A-8BBB-00AA00300CAB}") if @error Then _MemGlobalFree($hMemory) Return SetError(8,0,0) EndIf $HRESULT = DllCall("OleAut32.dll","LONG","OleLoadPicture","PTR",$lpstream,"LONG", _ $ResSize,"BOOL",True,"ptr",DllStructGetPtr($riid),"idispatch*",0) if @error Or $HRESULT[0] <> 0 Then _MemGlobalFree($hMemory) Return SetError(9,0,0) EndIf $iPicture = $HRESULT[5] _MemGlobalFree($hMemory) Return SetError(0,Int($iPicture.Type()),Ptr($iPicture.Handle())) EndSwitch ;PICTYPE_UNINITIALIZED (-1) ;The picture object is currently uninitialized. This value is only valid as a return value ;from IPicture::get_Type and is not valid with the PICTDESC structure. ;PICTYPE_NONE = 0 ;A new picture object is to be created without an initialized state. This ;value is valid only in the PICTDESC structure. ;PICTYPE_BITMAP = 1 ;The picture type is a bitmap. When this value occurs in the PICTDESC structure, ;it means that the bmp field of that structure contains the relevant initialization parameters. ;PICTYPE_METAFILE = 2 ;The picture type is a metafile. When this value occurs in the PICTDESC structure, ;it means that the wmf field of that structure contains the relevant initialization parameters. ;PICTYPE_ICON = 3 ;The picture type is an icon. When this value occurs in the PICTDESC structure, ;it means that the icon field of that structure contains the relevant initialization parameters. ;PICTYPE_ENHMETAFILE = 4 ;The picture type is an enhanced metafile. When this value occurs in the PICTDESC structure, ;it means that the emf field of that structure contains the relevant initialization parameters. EndFunc Func LoadBitmap($lpBitmapName,$ModuleName = "") Local $DataType = "LONG" , $TestModule = StringLen($ModuleName) <> 0 if ($TestModule) Then $HModule = _WinAPI_LoadLibraryEx($ModuleName,$LOAD_LIBRARY_AS_DATAFILE) if $HModule = 0 Then Return SetError(1,0,0) Else $HModule = _WinAPI_GetModuleHandle(0) EndIf if IsString($lpBitmapName) Then $lpBitmapName = StringUpper($lpBitmapName) $DataType = "WSTR" EndIf $HBITMAP = DllCall("User32.dll","PTR","LoadBitmapW","PTR",$HModule,$DataType,$lpBitmapName) if @error Or $HBITMAP[0] = 0 Then if ($TestModule) Then _WinAPI_FreeLibrary($HModule) Return SetError(2,0,0) EndIf if ($TestModule) Then _WinAPI_FreeLibrary($HModule) Return SetError(0,0,$HBITMAP[0]) EndFunc Func LoadIcon($lpIconName,$ModuleName = "") Local $DataType = "LONG" , $TestModule = StringLen($ModuleName) <> 0 if ($TestModule) Then $HModule = _WinAPI_LoadLibraryEx($ModuleName,$LOAD_LIBRARY_AS_DATAFILE) if $HModule = 0 Then Return SetError(1,0,0) Else $HModule = _WinAPI_GetModuleHandle(0) EndIf if IsString($lpIconName) Then $lpIconName = StringUpper($lpIconName) $DataType = "WSTR" EndIf $HICON = DllCall("User32.dll","PTR","LoadIconW","PTR",$HModule,$DataType,$lpIconName) if @error Or $HICON[0] = 0 Then if ($TestModule) Then _WinAPI_FreeLibrary($HModule) Return SetError(2,0,0) EndIf if ($TestModule) Then _WinAPI_FreeLibrary($HModule) Return SetError(0,0,$HICON[0]) EndFunc Func LoadCursor($lpCursorName,$ModuleName = "") Local $DataType = "LONG" , $TestModule = StringLen($ModuleName) <> 0 if ($TestModule) Then $HModule = _WinAPI_LoadLibraryEx($ModuleName,$LOAD_LIBRARY_AS_DATAFILE) if $HModule = 0 Then Return SetError(1,0,0) Else $HModule = _WinAPI_GetModuleHandle(0) EndIf if IsString($lpCursorName) Then $lpCursorName = StringUpper($lpCursorName) $DataType = "WSTR" EndIf $HCURSOR= DllCall("User32.dll","PTR","LoadCursorW","PTR",$HModule,$DataType,$lpCursorName) if @error Or $HCURSOR[0] = 0 Then if ($TestModule) Then _WinAPI_FreeLibrary($HModule) Return SetError(2,0,0) EndIf if ($TestModule) Then _WinAPI_FreeLibrary($HModule) Return SetError(0,0,$HCURSOR[0]) EndFunc Func CreateStreamOnHGlobal($hGlobal,$fDeleteOnRelease) $WINOLE = DllCall("Ole32.dll","PTR","CreateStreamOnHGlobal","ptr", _ $hGlobal,"BOOL",$fDeleteOnRelease,"PTR*",0) if @error Or $WINOLE[0] <> 0 Then Return SetError(1,0,0) Return SetError(0,0,$WINOLE[3]) EndFunc Res_Ctrl.au3 #include <Constants.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> #include <Memory.au3> #include "Resource.au3" Global $Global_BackGroundArray[4][1] Func ResCtrlCreatePic($L,$T,$W,$H,$ResType,$ResName, _ $ResLanguage = -1,$ModuleName = "",$Style = 0,$ExStyle = 0) $ImageHandle = ResGetImage($ResType,$ResName,$ResLanguage,$ModuleName) if @error Then Return SetError(1,0,0) $ImageType = @extended $ControlID = CtrlCreatePic($ImageHandle,$ImageType,$L,$T,$W,$H,$Style,$ExStyle) if @error Then Return SetError(2,0,0) Return SetError(0,$ImageType,$ControlID) EndFunc Func ResCtrlCreatePicEx($L,$T,$W,$H,$Text,$ResType,$ResName,$ResLanguage = -1, _ $ModuleName = "",$Style = 0,$ExStyle = 0,$FontColor=0,$FontSize=8.5,$FomtWeight=400 _ ,$FontAttribute=2,$Fontname="",$FontQuality=2) $ImageHandle = ResGetImage($ResType,$ResName,$ResLanguage,$ModuleName) if @error Then Return SetError(1,0,0) $ImageType = @extended $ControlID = CtrlCreatePicEx($ImageHandle,$ImageType,$L,$T,$W,$H,$Text,$Style, _ $ExStyle,$FontColor,$FontSize,$FomtWeight,$FontAttribute,$Fontname,$FontQuality) if @error Then Return SetError(2,0,0) Return SetError(0,$ImageType,$ControlID) EndFunc Func ResCtrlCreate_Button($L,$T,$W,$H,$ResType,$ResName, _ $ResLanguage = -1,$ModuleName = "",$Style = 0,$ExStyle = 0,$ReSize = False) $ImageHandle = ResGetImage($ResType,$ResName,$ResLanguage,$ModuleName) if @error Then Return SetError(1,0,0) $ImageType = @extended if ($ReSize) Then $SizeArray = GetImageSize($ImageHandle) if @error Then DeleteObj($ImageHandle,$ImageType) Return SetError(2,0,0) EndIf $W = $SizeArray[0] $H = $SizeArray[1] EndIf $ControlID = CtrlCreate_Button($ImageHandle,$ImageType,$L,$T,$W,$H,$Style,$ExStyle) if @error Then Return SetError(3,0,0) Return SetError(0,$ImageType,$ControlID) EndFunc Func ResSetBackGroundBmp($hWnd,$ResType,$ResName,$ResLanguage = -1 _ ,$ModuleName = "",$DeletOldImage = True) $hImage = ResGetImage($ResType,$ResName,$ResLanguage,$ModuleName) if @error Then Return SetError(1,0,False) Local $ImageType = @extended if ($ImageType <> 1) Then DeleteObj($hImage,$ImageType) $SizeArray = GetImageSize($hImage) if @error Then DeleteObj($hImage,$ImageType) Return SetError(2,0,False) EndIf $BmpWidth = $SizeArray[0] $BmpHeight = $SizeArray[1] SetBackGroundBmp($hWnd,$hImage,$BmpWidth,$BmpHeight,$DeletOldImage) if @error Then DeleteObj($hImage,$ImageType) Return SetError(3,0,False) EndIf Return SetError(0,0,True) EndFunc Func ResSndPlaySound($ResType,$ResName,$ResLanguage = -1,$ModuleName = "",$LOOP = False) $ByteStruct = ResGet($ResType,$ResName,$ResLanguage,$ModuleName) if @error Then Return SetError(1,0,False) $LPVOID = DllStructGetPtr($ByteStruct) SndPlaySound($LPVOID,$LOOP) if @error Then Return SetError(2,0,False) Return SetError(0,0,True) EndFunc Func CtrlCreatePic($ImageHandle,$ImageType,$L,$T,$W,$H,$Style = 0,$ExStyle = 0) Local $SS_ICON_RES = 0x00000003,$SS_ENHMETAFILE_RES = 0x0000000F Local $SS_BITMAP_RES = 0x0000000E,$SS_REALSIZECONTROL_RES = 0x00000040 Switch $ImageType Case 1 ;BITMAP $ImageStyle = BitOR($Style,$SS_BITMAP_RES,$SS_REALSIZECONTROL_RES) Case 4 ;ENHMETAFILE $ImageStyle = BitOR($Style,$SS_ENHMETAFILE_RES,$SS_REALSIZECONTROL_RES) Case 3,5 ;INCON OR CURSOR $ImageStyle = BitOR($Style,$SS_ICON_RES,$SS_REALSIZECONTROL_RES) Case Else Return SetError(1,0,0) EndSwitch $ControlID = GUICtrlCreateLabel("",$L,$T,$W,$H,$ImageStyle,$ExStyle) CtrlSetImage($ControlID,$ImageHandle,$ImageType) if @error Then Return SetError(2,0,0) Return SetError(0,$ImageType,$ControlID) EndFunc Func CtrlCreatePicEx($ImageHandle,$ImageType,$L,$T,$W,$H,$Text,$Style = 0,$ExStyle = 0, _ $FontColor=0,$FontSize=8.5,$FomtWeight=400,$FontAttribute=0,$Fontname="",$FontQuality=2) Local $SS_BITMAP_RES = 0x0000000E,$SS_REALSIZECONTROL_RES = 0x00000040 Local $SS_ICON_RES = 0x00000003,$SS_CENTER_RES = 0x01,$SS_CENTERIMAGE_RES = 0x0200 Local $SS_ENHMETAFILE_RES = 0x0000000F Switch $ImageType Case 1 ;BITMAP $ImageStyle = BitOR($Style,$SS_BITMAP_RES,$SS_REALSIZECONTROL_RES) Case 4 ;ENHMETAFILE $ImageStyle = BitOR($Style,$SS_ENHMETAFILE_RES,$SS_REALSIZECONTROL_RES) Case 3,5 ;INCON OR CURSOR $ImageStyle = BitOR($Style,$SS_ICON_RES,$SS_REALSIZECONTROL_RES) Case Else Return SetError(1,0,0) EndSwitch $ControlID1 = GUICtrlCreateLabel("",$L,$T,$W,$H,$ImageStyle,$ExStyle) CtrlSetImage($ControlID1,$ImageHandle,$ImageType) if @error Then GUICtrlDelete($ControlID1) Return SetError(2,0,0) EndIf $ControlID2 = GUICtrlCreateLabel($Text,$L,$T,$W,$H,BitOR($SS_CENTER_RES,$SS_CENTERIMAGE_RES)) GUICtrlSetColor(-1,$FontColor) GUICtrlSetBkColor(-1,-2);-2 $GUI_BKCOLOR_TRANSPARENT GUICtrlSetFont(-1,$FontSize,$FomtWeight,$FontAttribute,$Fontname,$FontQuality) Return SetError(0,$ImageType,$ControlID1) EndFunc Func DeletePicEx($ControlID) GUICtrlDelete($ControlID) GUICtrlDelete($ControlID + 1) EndFunc Func SetPosPicEx($ControlID,$L,$T,$W,$H) GUICtrlSetPos($ControlID,$L,$T,$W,$H) GUICtrlSetPos($ControlID + 1,$L,$T,$W,$H) EndFunc Func SetStatePicEx($ControlID,$State) GUICtrlSetState($ControlID,$State) GUICtrlSetState($ControlID + 1,$State) EndFunc Func SetStylePicEx($ControlID,$Style,$ExStyle) GUICtrlSetStyle($ControlID,$Style,$ExStyle) EndFunc Func CtrlCreate_Button($ImageHandle,$ImageType,$L,$T,$W,$H,$Style = 0,$ExStyle = 0) Local $BS_ICON_RES = 0x0040,$BS_BITMAP_RES = 0x0080 Switch $ImageType Case 1 ;BITMAP $ImageStyle = BitOR($Style,$BS_BITMAP_RES) Case 3 ;ICON $ImageStyle = BitOR($Style,$BS_ICON_RES) Case Else Return SetError(1,0,0) EndSwitch $ControlID = GUICtrlCreateButton("",$L,$T,$W,$H,$ImageStyle,$ExStyle) CtrlSetImage($ControlID,$ImageHandle,$ImageType) if @error Then Return SetError(2,0,0) Return SetError(0,$ImageType,$ControlID) EndFunc Func CtrlSetImage($ControlID,$ImageHandle,$ImageType,$DeletOldImage = False) ;$ImageType ;$ImageType = 1 ==> BITMAP ;$ImageType = 3 ==> ICON ;$ImageType = 4 ==> ENHMETAFILE ;$ImageType = 5 ==> CURSOR ;$ControlID Of STATIC Control Or Button Control Local $ControHandle = $ControlID,$STM_SETIMAGE_RES = 0x0172,$IMAGE_ENHMETAFILE_RES = 3 Local $IMAGE_BITMAP_RES = 0,$IMAGE_ICON_RES = 1,$IMAGE_CURSOR_RES = 2 , $RthImage = 0 Local $BM_SETIMAGE_RES = 0xF7 if Not IsHWnd($ControlID) Then $ControHandle = GUICtrlGetHandle($ControlID) Local $Class = _WinAPI_GetClassName($ControHandle) Select Case $Class == "Button" Switch $ImageType Case 1 ;BITMAP if ($DeletOldImage) Then $OldImage = CtrlGetOldImage($ControlID) Local $OldImageType = @extended $RthImage = _SendMessage($ControHandle,$BM_SETIMAGE_RES,$IMAGE_BITMAP_RES,$ImageHandle) if ($DeletOldImage And $OldImage <> $ImageHandle _ And $OldImage) Then DeleteObj($OldImage,$OldImageType) Case 3 ;ICON if ($DeletOldImage) Then $OldImage = CtrlGetOldImage($ControlID) Local $OldImageType = @extended $RthImage = _SendMessage($ControHandle,$BM_SETIMAGE_RES,$IMAGE_ICON_RES,$ImageHandle) if ($DeletOldImage And $OldImage <> $ImageHandle _ And $OldImage) Then DeleteObj($OldImage,$OldImageType) Case Else Return SetError(3,0,False) EndSwitch Case $Class == "Static" Switch $ImageType Case 1 ;BITMAP if ($DeletOldImage) Then $OldImage = CtrlGetOldImage($ControlID) Local $OldImageType = @extended $RthImage = _SendMessage($ControHandle,$STM_SETIMAGE_RES,$IMAGE_BITMAP_RES,$ImageHandle) if ($DeletOldImage And $OldImage <> $ImageHandle _ And $OldImage) Then DeleteObj($OldImage,$OldImageType) Case 4 ;ENHMETAFILE if ($DeletOldImage) Then $OldImage = CtrlGetOldImage($ControlID) Local $OldImageType = @extended $RthImage = _SendMessage($ControHandle,$STM_SETIMAGE_RES,$IMAGE_ENHMETAFILE_RES,$ImageHandle) if ($DeletOldImage And $OldImage <> $ImageHandle _ And $OldImage) Then DeleteObj($OldImage,$OldImageType) Case 3 ;ICON if ($DeletOldImage) Then $OldImage = CtrlGetOldImage($ControlID) Local $OldImageType = @extended $RthImage = _SendMessage($ControHandle,$STM_SETIMAGE_RES,$IMAGE_ICON_RES,$ImageHandle) if ($DeletOldImage And $OldImage <> $ImageHandle _ And $OldImage) Then DeleteObj($OldImage,$OldImageType) Case 5 ;CURSOR if ($DeletOldImage) Then $OldImage = CtrlGetOldImage($ControlID) Local $OldImageType = @extended $RthImage = _SendMessage($ControHandle,$STM_SETIMAGE_RES,$IMAGE_CURSOR_RES,$ImageHandle) if ($DeletOldImage And $OldImage <> $ImageHandle _ And $OldImage) Then DeleteObj($OldImage,$OldImageType) Case Else Return SetError(3,0,False) EndSwitch if IsHWnd($ControlID) Then $ControlID = _WinAPI_GetDlgCtrlID($ControlID) $ControHandle = GUICtrlGetHandle($ControlID + 1) if ($ControHandle) Then _WinAPI_RedrawWindow($ControHandle,0,0,$RDW_INVALIDATE) Case Else Return SetError(2,0,False) EndSelect if ($RthImage) Then DeleteObj($RthImage,$ImageType) Return SetError(0,0,True) EndFunc Func CtrlGetOldImage($ControlID) ; Return $OldImage Or Zero ;$ImageType = @extended ;$ImageType = 1 ==> BITMAP ;$ImageType = 3 ==> ICON ;$ImageType = 4 ==> ENHMETAFILE ;$ImageType = 5 ==> CURSOR Local $ControHandle = $ControlID,$STM_GETIMAGE_RES = 0x0173,$IMAGE_ENHMETAFILE_RES = 3 Local $IMAGE_BITMAP_RES = 0,$IMAGE_ICON_RES = 1,$IMAGE_CURSOR_RES = 2 , $OldImage = 0 Local $BM_GETIMAGE_RES = 0x00F6 if Not IsHWnd($ControlID) Then $ControHandle = GUICtrlGetHandle($ControlID) Local $Class = _WinAPI_GetClassName($ControHandle) Select Case $Class == "Button" $OldImage = _SendMessage($ControHandle,$BM_GETIMAGE_RES,$IMAGE_BITMAP_RES,0) if ($OldImage) Then Return SetError(0,1,$OldImage) $OldImage = _SendMessage($ControHandle,$BM_GETIMAGE_RES,$IMAGE_ICON_RES,0) if ($OldImage) Then Return SetError(0,3,$OldImage) Return SetError(1,0,0) Case $Class == "Static" $OldImage = _SendMessage($ControHandle,$STM_GETIMAGE_RES,$IMAGE_BITMAP_RES,0) if ($OldImage) Then Return SetError(0,1,$OldImage) $OldImage = _SendMessage($ControHandle,$STM_GETIMAGE_RES,$IMAGE_ICON_RES,0) if ($OldImage) Then Return SetError(0,3,$OldImage) $OldImage = _SendMessage($ControHandle,$STM_GETIMAGE_RES,$IMAGE_CURSOR_RES,0) if ($OldImage) Then Return SetError(0,5,$OldImage) $OldImage = _SendMessage($ControHandle,$STM_GETIMAGE_RES,$IMAGE_ENHMETAFILE_RES,0) if ($OldImage) Then Return SetError(0,4,$OldImage) Return SetError(1,0,0) Case Else Return SetError(2,0,0) EndSelect EndFunc Func SetBackGroundBmp($hWnd,$hBmpImage,$BmpWidth,$BmpHeight,$DeletOldImage = True) Local $GuiTest = False , $UBound = UBound($Global_BackGroundArray) For $i = 0 To $UBound - 1 if ($Global_BackGroundArray[$i][0] = $hWnd) Then $GuiTest = True ExitLoop EndIf Next if ($GuiTest = False) Then ReDim $Global_BackGroundArray[$UBound + 1][4] if ($DeletOldImage) And ($Global_BackGroundArray[$i][1]) _ Then _WinAPI_DeleteObject($Global_BackGroundArray[$i][1]) $Global_BackGroundArray[$i][0] = $hWnd $Global_BackGroundArray[$i][1] = $hBmpImage $Global_BackGroundArray[$i][2] = $BmpWidth $Global_BackGroundArray[$i][3] = $BmpHeight GUIRegisterMsg($WM_ERASEBKGND,"WM_ERASEBKGND") _WinAPI_RedrawWindow($hWnd) EndFunc Func RemoveBackGroundBmp($hWnd,$DeletImage = True) Local $GuiTest = False , $UBound = UBound($Global_BackGroundArray) Local $NewBackGroundArray[$UBound - 1][4] For $i = 0 To $UBound - 1 if ($Global_BackGroundArray[$i][0] = $hWnd) Then $GuiTest = True ExitLoop EndIf Next if ($GuiTest = True) Then For $i = 0 To $UBound - 1 if ($Global_BackGroundArray[$i][0] = $hWnd) Then ContinueLoop $NewBackGroundArray[$i][0] = $Global_BackGroundArray[$i][0] $NewBackGroundArray[$i][1] = $Global_BackGroundArray[$i][1] $NewBackGroundArray[$i][2] = $Global_BackGroundArray[$i][2] $NewBackGroundArray[$i][3] = $Global_BackGroundArray[$i][3] Next $Global_BackGroundArray = $NewBackGroundArray Else Return SetError(1,0,False) EndIf _WinAPI_RedrawWindow($hWnd) Return SetError(0,0,True) EndFunc Func WM_ERASEBKGND($hWnd, $Msg, $wParam, $lParam) Local $GuiTest = False , $UBound = UBound($Global_BackGroundArray) Local $BGhWnd = WindowFromDC($wParam) if Not @error Then For $i = 0 To $UBound - 1 if ($Global_BackGroundArray[$i][0] = $BGhWnd) Then $GuiTest = True ExitLoop EndIf Next if ($GuiTest) Then $Pos = WinGetClientSize($BGhWnd) $hdc = _WinAPI_CreateCompatibleDC($wParam) $HGDIOBJ = _WinAPI_SelectObject($hdc,$Global_BackGroundArray[$i][1]) StretchBlt($wParam,0,0,$Pos[0],$Pos[1],$hdc,0,0,$Global_BackGroundArray[$i][2], _ $Global_BackGroundArray[$i][3],$SRCCOPY) $HGDIOBJ = _WinAPI_SelectObject($hdc,$HGDIOBJ) _WinAPI_DeleteDC($hdc) Return True EndIf EndIf EndFunc Func SndPlaySound($Ptr,$LOOP = False) ;File Type Or Format File.wav Local $SND_MEMORY = 4, $SND_ASYNC = 1 ,$SND_SYNC = 0,$SND_NODEFAULT = 2 , _ $SND_LOOP = 0x0008 , $SND_NOSTOP = 0x0010 ,$SND_FILENAME = 0x00020000 Local $fuSound = BitOR($SND_MEMORY,$SND_ASYNC,$SND_NODEFAULT) if ($LOOP) Then $fuSound = BitOR($fuSound,$SND_LOOP) $BOOL = DllCall("winmm.dll", "int", "sndPlaySound","ptr",$Ptr,"UINT",$fuSound) If @error Or $BOOL[0] = 0 Then Return SetError(1,0,False) Return SetError(0,0,True) EndFunc Func DeleteObj($Object,$ObjectType) Switch $ObjectType Case 1 if (_WinAPI_DeleteObject($Object)) Then Return True Case 2 if (DeleteMetaFile($Object)) Then Return True Case 3 if (_WinAPI_DestroyIcon($Object)) Then Return True Case 4 if (DeleteEnhMetaFile($Object)) Then Return True Case 5 if (DestroyCursor($Object)) Then Return True EndSwitch Return SetError(1,0,False) EndFunc Func StretchBlt($hdcDest,$nXOriginDest,$nYOriginDest,$nWidthDest,$nHeightDest,$hdcSrc,$nXOriginSrc, _ $nYOriginSrc,$nWidthSrc,$nHeightSrc,$dwRop) $Rt = DllCall("Gdi32.dll" ,"BOOL","StretchBlt","ptr",$hdcDest,"int",$nXOriginDest,"int",$nYOriginDest,"int",$nWidthDest , _ "int",$nHeightDest,"ptr",$hdcSrc,"int",$nXOriginSrc,"int",$nYOriginSrc,"int",$nWidthSrc,"int",$nHeightSrc,"DWORD",$dwRop) if @error Or $Rt[0] = 0 Then Return SetError(1,0,0) Return SetError(0,0,$Rt[0]) EndFunc Func WindowFromDC($hDC) $HWND = DllCall("User32.dll","ptr","WindowFromDC","ptr",$hdc) if @error Or $HWND[0] = 0 Then Return SetError(1,0,0) Return SetError(0,0,$HWND[0]) EndFunc Func GetImageSize($hBmp) Local $ntagBITMAPINFO = "DWORD biSize;LONG biWidth;LONG biHeight;USHORT biPlanes;" & _ "USHORT biBitCount;DWORD biCompression;DWORD biSizeImage;LONG biXPelsPerMeter;" & _ "LONG biYPelsPerMeter;DWORD biClrUsed;DWORD biClrImportant;BYTE RGBQUAD[4]" Local $vBITMAPINFO = DllStructCreate($ntagBITMAPINFO) DllStructSetData($vBITMAPINFO,"biSize",(DllStructGetSize($vBITMAPINFO) - 4)) Local $hDC = _WinAPI_CreateCompatibleDC(0) if @error Then _WinAPI_DeleteDC($hDC) Return SetError(1,0,0) EndIf _WinAPI_GetDIBits($hDC,$hBmp,0,0,0,DllStructGetPtr($vBITMAPINFO),0) if @error Then _WinAPI_DeleteDC($hDC) Return SetError(2,0,0) EndIf _WinAPI_DeleteDC($hDC) Local $biWidth = DllStructGetData($vBITMAPINFO,"biWidth") Local $biHeight = DllStructGetData($vBITMAPINFO,"biHeight") Local $SizeArray[2] $SizeArray[0] = $biWidth $SizeArray[1] = $biHeight Return $SizeArray EndFunc Func DeleteMetaFile($hmf) $BOOL = DllCall("Gdi32.dll","BOOL","DeleteMetaFile","ptr",$hmf) if @error Or $BOOL[0] = 0 Then Return SetError(1,0,False) Return SetError(0,0,True) EndFunc Func DeleteEnhMetaFile($hemf) $BOOL = DllCall("Gdi32.dll","BOOL","DeleteEnhMetaFile","ptr",$hemf) if @error Or $BOOL[0] = 0 Then Return SetError(1,0,False) Return SetError(0,0,True) EndFunc Func DestroyCursor($hCursor) $BOOL = DllCall("User32.dll","BOOL","DestroyCursor","ptr",$hCursor) if @error Or $BOOL[0] = 0 Then Return SetError(1,0,False) Return SetError(0,0,True) EndFunc Module_Res_Example.au3 #include "Res_Ctrl.au3" #include <WinAPI.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> MsgBox(0,AddRes(),"Success AddRes") $Gui = GUICreate("Gui Example",500,500,0,0) $ClID1 = ResCtrlCreatePicEx(10,10,200,100,"GIF","IMGES","GIF",-1,"Res.Dll",$WS_BORDER,0,0,14,800,0,"MS Sans Serif",2) $ClID2 = ResCtrlCreatePicEx(295,10,200,100,"BMP","IMGES","BMP",-1,"Res.Dll",$WS_BORDER,0,0,14,800,0,"MS Sans Serif",2) $ClID3 = ResCtrlCreatePicEx(10,120,200,100,"JPG","IMGES","JPG",-1,"Res.Dll",$WS_BORDER,0,0,14,800,0,"MS Sans Serif",2) $ClID4 = ResCtrlCreatePicEx(295,120,200,100,"ICO","IMGES","ICO",-1,"Res.Dll",$WS_BORDER,0,0,14,800,0,"MS Sans Serif",2) $ClID5 = ResCtrlCreatePicEx(10,230,480,160,"EMF","IMGES","EMF",-1,"Res.Dll",$WS_BORDER,0,0,14,800,0,"MS Sans Serif",2) $ClID6 = ResCtrlCreate_Button(214,100,-1,-1,"IMGES","BUTTON",-1,"Res.Dll",0,0,True) ;$W = -1 $H = -1 // $ReSize = True $BOOL = ResSetBackGroundBmp($Gui,"IMGES","BKGND",-1,"Res.Dll") $BOOL = ResSndPlaySound("IMGES","WAV",-1,"Res.Dll",True); LOOP = True GUICtrlCreateLabel(StringResGet("STR","ANSI",-1,False,"Res.Dll"),10,400,480,40,BitOR($WS_BORDER,$SS_CENTER,$SS_CENTERIMAGE)) GUICtrlCreateLabel(StringResGet("STR","UNICODE",-1,True,"Res.Dll"),10,450,480,40,BitOR($WS_BORDER,$SS_CENTER,$SS_CENTERIMAGE)) GUISetState() Do $msg = GUIGetMsg() Until $msg = $GUI_EVENT_CLOSE Func FileToByteStruct($FileName) Local $nBytes $FileSize = FileGetSize($FileName) $FileStruct = DllStructCreate("byte[" & $FileSize & "]") if @error Then Return SetError(1,0,0) $hFile = _WinAPI_CreateFile($FileName,2,2) if @error Then Return SetError(2,0,0) _WinAPI_ReadFile($hFile,DllStructGetPtr($FileStruct),$FileSize,$nBytes) if @error Then Return SetError(3,0,0) _WinAPI_CloseHandle($hFile) Return SetError(0,0,$FileStruct) EndFunc Func AddRes() if Not FileExists(@ScriptDir & "\Res.Dll") Then FileCopy(@SystemDir & "\ole32.dll",@ScriptDir & "\Res.Dll") $DataStruct = FileToByteStruct("Gif.gif") if @error Then Exit(MsgBox(0,"MsgError1","Error ==> " & @error)) UpdateResource("Res.Dll",$DataStruct,"GIF","IMGES") if @error Then Exit(MsgBox(0,"MsgError2","Error ==> " & @error)) $DataStruct = FileToByteStruct("Bmp.bmp") if @error Then Exit(MsgBox(0,"MsgError3","Error ==> " & @error)) UpdateResource("Res.Dll",$DataStruct,"BMP","IMGES") if @error Then Exit(MsgBox(0,"MsgError4","Error ==> " & @error)) $DataStruct = FileToByteStruct("jpg.jpg") if @error Then Exit(MsgBox(0,"MsgError5","Error ==> " & @error)) UpdateResource("Res.Dll",$DataStruct,"JPG","IMGES") if @error Then Exit(MsgBox(0,"MsgError6","Error ==> " & @error)) $DataStruct = FileToByteStruct("Ico.ico") if @error Then Exit(MsgBox(0,"MsgError7","Error ==> " & @error)) UpdateResource("Res.Dll",$DataStruct,"ICO","IMGES") if @error Then Exit(MsgBox(0,"MsgError8","Error ==> " & @error)) $DataStruct = FileToByteStruct("EMF.EMF") if @error Then Exit(MsgBox(0,"MsgError9","Error ==> " & @error)) UpdateResource("Res.Dll",$DataStruct,"EMF","IMGES") if @error Then Exit(MsgBox(0,"MsgError10","Error ==> " & @error)) $DataStruct = FileToByteStruct("BKGND.bmp") if @error Then Exit(MsgBox(0,"MsgError11","Error ==> " & @error)) UpdateResource("Res.Dll",$DataStruct,"BKGND","IMGES") if @error Then Exit(MsgBox(0,"MsgError12","Error ==> " & @error)) $DataStruct = FileToByteStruct("Wav.wav") if @error Then Exit(MsgBox(0,"MsgError13","Error ==> " & @error)) UpdateResource("Res.Dll",$DataStruct,"WAV","IMGES") if @error Then Exit(MsgBox(0,"MsgError14","Error ==> " & @error)) $DataStruct = DllStructCreate("CHAR[" & StringLen("ANSI String") & "]") if @error Then Exit(MsgBox(0,"MsgError15","Error ==> " & @error)) DllStructSetData($DataStruct,1,"ANSI String") UpdateResource("Res.Dll",$DataStruct,"ANSI","STR") if @error Then Exit(MsgBox(0,"MsgError16","Error ==> " & @error)) $DataStruct = DllStructCreate("WCHAR[" & StringLen("UNICODE Wide Character String") & "]") if @error Then Exit(MsgBox(0,"MsgError17","Error ==> " & @error)) DllStructSetData($DataStruct,1,"UNICODE Wide Character String") UpdateResource("Res.Dll",$DataStruct,"UNICODE","STR") if @error Then Exit(MsgBox(0,"MsgError18","Error ==> " & @error)) $DataStruct = FileToByteStruct("Button.bmp") if @error Then Exit(MsgBox(0,"MsgError19","Error ==> " & @error)) UpdateResource("Res.Dll",$DataStruct,"BUTTON","IMGES") if @error Then Exit(MsgBox(0,"MsgError20","Error ==> " & @error)) Return True EndFunc Func UpdateResource($Dll_Exe_FileName,$DataStruct,$lpName,$lpType,$wLanguage = 0) if Not IsDllStruct($DataStruct) Then Return SetError(1,0,False) Local $lpData = DllStructGetPtr($DataStruct),$cbData = DllStructGetSize($DataStruct) $HANDLE = DllCall("kernel32.dll","ptr","BeginUpdateResourceW","wstr",$Dll_Exe_FileName,"BOOL",False) if @error Or $HANDLE[0] = 0 Then Return SetError(2,0,False) $hUpdate = $HANDLE[0] if IsString($lpType) Then $DataType1 = "wstr" $lpType = StringUpper($lpType) ELSE $DataType1 = "long" EndIf if IsString($lpName) Then $DataType2 = "wstr" $lpName = StringUpper($lpName) ELSE $DataType2 = "long" EndIf $BOOL = DllCall("kernel32.dll","BOOL","UpdateResourceW","ptr",$hUpdate,$DataType1 _ ,$lpType,$DataType2,$lpName,"WORD",$wLanguage,"ptr",$lpData,"DWORD",$cbData) if @error Or $BOOL[0] = 0 Then Return SetError(3,0,False) $BOOL = DllCall("kernel32.dll","BOOL","EndUpdateResourceW","HANDLE",$hUpdate,"BOOL",False) if @error Or $BOOL[0] = 0 Then Return SetError(4,0,False) Return SetError(0,0,True) EndFunc Res_Example.au3 #AutoIt3Wrapper_Res_File_Add=Gif.gif,IMGES,GIF,0 #AutoIt3Wrapper_Res_File_Add=Bmp.bmp,IMGES,BMP,0 #AutoIt3Wrapper_Res_File_Add=jpg.jpg,IMGES,JPG,0 #AutoIt3Wrapper_Res_File_Add=Ico.ico,IMGES,ICO,0 #AutoIt3Wrapper_Res_File_Add=EMF.EMF,IMGES,EMF,0 #AutoIt3Wrapper_Res_File_Add=Button.bmp,IMGES,BUTTON,0 #AutoIt3Wrapper_Res_File_Add=BKGND.bmp,IMGES,BKGND,0 #AutoIt3Wrapper_Res_File_Add=ANSI.txt,STR,ANSI,0 #AutoIt3Wrapper_Res_File_Add=UNICODE.txt,STR,UNICODE,0 #include "Res_Ctrl.au3" #include <WinAPI.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> if Not (@Compiled) Then Exit(MsgBox(0,"Err","Must compile the Res_Example.au3 With Options")) $Gui = GUICreate("Gui Example",500,500,0,0) $ClID1 = ResCtrlCreatePicEx(10,10,200,100,"GIF","IMGES","GIF",-1,"",$WS_BORDER,0,0,14,800,0,"MS Sans Serif",2) $ClID2 = ResCtrlCreatePicEx(295,10,200,100,"BMP","IMGES","BMP",-1,"",$WS_BORDER,0,0,14,800,0,"MS Sans Serif",2) $ClID3 = ResCtrlCreatePicEx(10,120,200,100,"JPG","IMGES","JPG",-1,"",$WS_BORDER,0,0,14,800,0,"MS Sans Serif",2) $ClID4 = ResCtrlCreatePicEx(295,120,200,100,"ICO","IMGES","ICO",-1,"",$WS_BORDER,0,0,14,800,0,"MS Sans Serif",2) $ClID5 = ResCtrlCreatePicEx(10,230,480,160,"EMF","IMGES","EMF",-1,"",$WS_BORDER,0,0,14,800,0,"MS Sans Serif",2) $ClID6 = ResCtrlCreate_Button(214,100,-1,-1,"IMGES","BUTTON",-1,"",0,0,True) ;$W = -1 $H = -1 // $ReSize = True $BOOL = ResSetBackGroundBmp($Gui,"IMGES","BKGND",-1,"") $BOOL = ResSndPlaySound("IMGES","WAV",-1,"Res.Dll",True); LOOP = True GUICtrlCreateLabel(StringResGet("STR","ANSI",-1,False,""),10,400,480,40,BitOR($WS_BORDER,$SS_CENTER,$SS_CENTERIMAGE)) GUICtrlCreateLabel(StringResGet("STR","UNICODE",-1,True,""),10,450,480,40,BitOR($WS_BORDER,$SS_CENTER,$SS_CENTERIMAGE)) GUISetState() Do $msg = GUIGetMsg() Until $msg = $GUI_EVENT_CLOSE2 points -
LAST VERSION - 1.0 22-Mar-12 I think many of you would like to combine any data of your project, for example skin images, into a single file (package), and as necessary extract them from it. Moreover, it would be better to avoid creating temporary files on the disk. Yes, of course, you can use a resources of the executable file or native FileInstall() function, but in the first case you can not add data after compilation the script, the second case leads inevitably to write data to disk that is not good. Alternatively, you can use, for example, .zip archives, but here again you are limited to using only the files. For this reason, I decided to invent their own file format (.pkr) for storing any data (it can be a files or a memory data directly), and devoid of all the above shortcomings. Below is the detailed structure of the .pkr file (package). As you can see from the screenshot, the package consists of a header and one or more data packets following one another. The package header has a length of 256 bytes and represents PKHEADER structure that contains a basic information about .pkr file, including a short text comment. Here is a description of the PKHEADER structure. -------------------------------------------------------------------------------------------------- | PKHEADER | |--------------------------------------------------------------------------------------------------| | Offset | Length | Purpose | |--------|--------|--------------------------------------------------------------------------------| | 0 | 4 | The file signature (0x504B5221) | |--------|--------|--------------------------------------------------------------------------------| | 4 | 4 | The package version, 1.0 | |--------|--------|--------------------------------------------------------------------------------| | 8 | 8 | The file size, in bytes | |--------|--------|--------------------------------------------------------------------------------| | 16 | 4 | The number of packets in the package | |--------|--------|--------------------------------------------------------------------------------| | 20 | 4 | Reserved | |--------|--------|--------------------------------------------------------------------------------| | 24 | 8 | The absolute offset, in bytes, of the first packet in package | |--------|--------|--------------------------------------------------------------------------------| | 32 | 224 | The package comment, max 224 bytes (112 characters) | --------------------------------------------------------------------------------------------------The first four bytes of the .pkr file always contain the same sequence of bytes (signature) - 0x504B5221 ("PKR!" in ASCII characters). This allows to uniquely identify the package. Then follows a DWORD value representing the package version, currently 1.0 (0x00000100). Next is the size of the package file (INT64), in bytes. Although the size of the .pkr file is not limited, the length of one packet may not exceed a little more than 4 gigabytes (see below). Note that the value of this member should be equal to the actual file size, otherwise it is assumed that the package is damaged. The next member (DWORD) of the structure contains the number of packets in the package. It should not be zero, since it is not allowed to create empty packages. The next four bytes are reserved for future use. The sixth member (INT64) of the PKHEADER structure is the most important and contains an offset of the first packet in the package from the beginning of a file, in bytes. This means that the first packet does not necessarily follow immediately after the header. The latest in the package header is a comment. The length of the comment is limited to 224 bytes (112 wide characters, including the null-terminating character). After the packet header may be located a Packet Relocation Table (PRT) of variable size that contains information for fast packets searching, but is not currently used and has a zero length. Following the PKHEADER and PRT begins a packets. Each packet consists of its own header and three data sections: Description, Info, and Data. Why three? Because so much easier to classify the data within the package. You will understand this when you try to use the library for their projects. A description of the packet (PKPACKET structure) shown in the following table. -------------------------------------------------------------------------------------------------- | PKPACKET | |--------------------------------------------------------------------------------------------------| | Offset | Length | Purpose | |--------|--------|--------------------------------------------------------------------------------| | 0 | 4 | The size, in bytes, of the packet header structure (40 bytes) | |--------|--------|--------------------------------------------------------------------------------| | 4 | 4 | The size, in bytes, of the description block, max 8192 bytes (4096 characters) | |--------|--------|--------------------------------------------------------------------------------| | 8 | 4 | The size, in bytes, of the information block, max 64 KB | |--------|--------|--------------------------------------------------------------------------------| | 12 | 4 | The size, in bytes, of the data block, max 4 GB | |--------|--------|--------------------------------------------------------------------------------| | 16 | 8 | The 64-bit unique identifier of the packet | |--------|--------|--------------------------------------------------------------------------------| | 24 | 4 | The checksum (CRC32) of the compressed data, or zero if no compression | |--------|--------|--------------------------------------------------------------------------------| | 28 | 4 | The uncompressed data size, in bytes, or zero if no compression | |--------|--------|--------------------------------------------------------------------------------| | 32 | 8 | Reserved | |--------------------------------------------------------------------------------------------------| | Description | |--------------------------------------------------------------------------------------------------| | Information | |--------------------------------------------------------------------------------------------------| | Data | --------------------------------------------------------------------------------------------------The first member (DWORD) of the PKPACKET structure always contains the length, in bytes, of the packet header and currently is 40 bytes, but can be changed in the future. The second, third, and fourth members (DWORD) of the structure contains the lengths of the corresponding data sections, in bytes. If any section is missing, the value of its length is zero. A full packet length, in bytes, can be calculated by summing the four values is listed above. The fifth member (INT64) of the structure represents a unique packet identifier (ID). It is a 64-bit positive number that uniquely identifies a packet within the package. The sixth and seventh members (DWORD) of the PKPACKET structure is used only if a data of the Data sections are compressed, otherwise have a zero values. In the case of compression, the sixth member of the structure contains the exact data size of the Data section, in bytes, after uncompression. The last member (INT64) of the packet header is reserved for future use. Immediately after the packet header begins a three data sections that are described in more detail below. The Description section is the first in the packet and designed to store any text information. It may be, for example, the name of the file, in the case of adding a file into the packet, or just a short description of the data that is in the packet. The maximum length of the this section is 8 kilobytes (8,192 bytes) or 4096 wide characters (including the null-terminating character). The Info section immediately follows after the Description section. Here you can store any auxiliary binary data, for example, the attributes of the file, the date and time that a file was created, last accessed, and last modified., or something else. Alternatively, you can store in this section are small files such as cursors, icons, etc. The length of this section is limited to 64 kilobytes (65,535 bytes). The Data section is the third in the packet, and used to store main packet data. The maximum length of this section may be up to 4 gigabytes (4,294,967,295 bytes). Moreover, the data of this section can be compressed by using the native LZ algorithm (not the most optimal but fast enough). These three data sections represents a one packet, and must follow continuously each other that as shown above. Furthermore, any or all of these sections can be missing in the packet. Then after the first packet immediately begins another packet, if any, etc. As you can see, the .pkr files have a simple structure consisting of the sequential blocks of data. Especially for ease of use of packages, I wrote the UDF library which you can download below. A detailed description of each function you can find inside the library. Also, the archive includes all the examples and supporting files. As an additional example, you can download the Package.pkr file containing the same files as the .zip archive, but only created by using this library. I hope this UDF library will be useful for your projects. Also, if anyone have any questions or comments, please post it in this thread. I will be glad to any feedback and constructive suggestions. Almost forgot, this library requires >WinAPIEx UDF library version 3.7 or later. Available functions Package UDF Library v1.0 Package.zip Examples Extracting file (Simple) Adding binary data (Simple) Extracting binary data (Simple) Addition Extraction GUI (Advanced)2 points
-
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.1 point
-
Refreshing labels
WilliamWhite reacted to Melba23 for a topic
WilliamWhite, Does this help: #include <GUIConstantsEx.au3> Global $oInvoer $iTabelxStart = 10 $yInvoerblok = 10 $hGUI = GUICreate("Test", 515, 500) ; Picka starting size $iTabelBreedte = Random(2, 10, 1) ; Draw the controls _DrawControls($iTabelBreedte) $cButton = GUICtrlCreateButton("Reload", 10, 450, 80, 30) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cButton ; Delete the existing controls For $i = 0 To $iTabelBreedte - 1 For $ii = 0 To $iTabelBreedte - 1 GUICtrlDelete($oInvoer[$ii][$i]) Next Next ; Pick a new number and draw them $iTabelBreedte = Random(2, 10, 1) _DrawControls($iTabelBreedte) EndSwitch WEnd Func _DrawControls($iNumber) Global $oInvoer[$iNumber][$iNumber] For $i = 0 To $iNumber - 1 For $ii = 0 To $iNumber - 1 $oInvoer[$ii][$i] = GUICtrlCreateInput($ii + ($i * 10), $iTabelxStart + $i * 50, $yInvoerblok + $ii * 25, 45, 24) GUICtrlSetFont(-1, 11) Next Next EndFunc Please ask if you have any questions. M231 point -
mus++
mesale0077 reacted to czardas for a topic
You can use any midi instrument by using the number of the instrument if you know it. Look in the midiUDF, you can find it in this forum - example scripts. The numbers range from 0 to 127. Some of the instruments are not really instruments - like helicopter and telephone. For $i = 0 To 127 _MusPlusPlus( "<" & $i & "> ;=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 ") Next1 point -
mus++ for non-musicians It is important to listen to all the examples in this tutorial to understand what is happening. The first thing you need to know is that there are seven letters used to name musical notes A, B, C, D, E, F and G. All note names must be typed using upper case. Let's start with the simplest case. The following note is called A. A This note has a default pitch of 440 Hz and will sound for exactly 600 ms. There are several ways to prolong the duration of our note. Prefixing a plus sign produces a note which lasts twice as long (1200 ms). +A Alternatively a minus sign will shorten the note by half (300 ms). -A All notes inherit the duration of the previous note, so the following sequence will produce four notes lasting 600 ms followed by four faster notes at 300 ms: A A A A -A A A A To return to the default duration you need to use an apostrophe. A A A A -A A A A ;A A A A The symbols used to alter note durations are as follows: o = 2400 ms + = 1200 ms ; = 600 ms default ... quarter note - = 300 ms ~ = 150 ms = 75 ms ? = 37.5 ms In the above list, each note is half the duration of the previous. The values for duration are true when the music is played at the default speed of 100 bpm (100 quarter notes occuring in 1 minute). More about this later. Now lets look at pitch. The following sequence represents a scale (all notes must be separated by at least one space): A B C D E F G A When listening to the scale above, you will notice that the note sequence does not always rise in pitch. To make the notes continue ascending, it is necessary to go up to the next octave. To do this you simply place a single quote after the note name. Each new octave starts with the note C. A B C' D E F G A When there are no quotes attached to a note, it will inherit the octave of the previously encountered note. A quote placed before a note sets the octave range below the default range. G F E D C 'B A To return to the default octave range, use a single quote on both sides of the note name: 'B' as shown below. C D E F G A B +C' ;'B' A G F E D oC In music a note can be raised by a semitone using a sharp (hash sign #): A B C' D E F# G# +A Or lowered by a semitone using the flat symbol (lower case b ). E D 'B Bb G oE Sharps and flats are also attributes inherited from a previous note with the same letter name. In the following sequence all notes containing F will be sharpened. D E F# +G ;F E D C 'B A oG To cancel a sharp or flat you can use a natural sign (lower case z) D E F# +G ;Fz E D C 'B A oG When attached to a note these three symbols (# b z) are called accidentals. Accidentals are cancelled after a bar line - vertical bar |. More about bar lines in the next tutorial. Do not place a single quote between a note and an accidental. 'E'b is incorrect - it should be written 'Eb' Try adding and changing the symbols in the examples and create your own examples using these basic features and you'll quickly be writing mus++. Examples from the above tutorial: _MusPlusPlus("A") Sleep(2000) _MusPlusPlus("+A") Sleep(2000) _MusPlusPlus("-A") Sleep(2000) _MusPlusPlus("A A A A -A A A A") Sleep(2000) _MusPlusPlus("A A A A -A A A A ;A A A A") Sleep(2000) _MusPlusPlus("A B C D E F G A") Sleep(2000) _MusPlusPlus("A B C' D E F G A") Sleep(2000) _MusPlusPlus("G F E D C 'B A") Sleep(2000) _MusPlusPlus("C D E F G A B +C' ;'B' A G F E D oC") Sleep(2000) _MusPlusPlus("A B C' D E F# G# +A") Sleep(2000) _MusPlusPlus("E D 'B Bb G oE") Sleep(2000) _MusPlusPlus("D E F# +G ;F E D C 'B A oG") Sleep(2000) _MusPlusPlus("D E F# +G ;Fz E D C 'B A oG") Sleep(2000)1 point
-
Shocker, If you want to disable/enable controls based on whether or not a process is running it can be done like this (I use Windows Live Mail in the example): #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #AutoIt3Wrapper_Add_Constants=n Local $gui010 = GUICreate('', 100, 100) Local $btn010 = GUICtrlCreateButton('My Button', 10, 20, 80, 50) GUISetState() AdlibRegister("_check_process", 250) While 1 Switch GUIGetMsg() Case $gui_event_close Exit EndSwitch WEnd Func _check_process() Switch ProcessExists('wlcomm.exe') Case 0 If BitAND(GUICtrlGetState($btn010), $gui_disable) = $gui_disable Then GUICtrlSetState($btn010, $gui_enable) Case Else If BitAND(GUICtrlGetState($btn010), $gui_enable) = $gui_enable Then GUICtrlSetState($btn010, $gui_disable) EndSwitch EndFunc ;==>_check_process If you are trying to disable/enable the minimize/maximize gui controls then I have not been able to find anything that will do that. Maybe one of the gui experts will advise. Good Luck, kylomas1 point
-
GUI Testing
PlayHD reacted to JLogan3o13 for a topic
With AutoIt (almost) all things are possible. What is the name of the application you are trying to automate? Try the AutoIt Window Info Tool (AU3Info.exe in the AutoIt install directory) on the program's window and let us know what you come up with.1 point -
Monitor Processes during execution of the .exe
jaberwacky reacted to guinness for a topic
I am a newb to the forum, but have been using Autoit + Help File for a while searching the forums to the questions I have, instead of getting you guys to do the dirty coding for me! Below is a piece of code which monitors the processes during the running of the script (.exe) and when the script (.exe) closes, kills all the processes that were open during that time. The problem is that it works as it should do in XP but when it comes to Vista(!) the closing of the processes that have opened during that time take a while to close. For example if I leave the script running for an hour it will take 5 mins to exit, because of the enormous size of the variable $Snapshot. Could someone with more knowledge than me please shed some light on the whole situation. I realise Vista works differently to that of 2000/XP but ideally I would like a script that can do the above, perhaps filtering the processes might help??? CODE$Temp = ProcessList() $Snapshot = "" For $i = 1 to $Temp[0][0] $Snapshot=$Snapshot&" "&$Temp[$i][1] Next ;CONTINUE SCRIPT $Temp = ProcessList() Dim $Closelist[20] For $i = 1 to $Temp[0][0] If StringInStr( $Snapshot,$Temp[$i][1] )=0 Then ProcessClose( $Temp[$i][1]) ProcessWaitClose( $Temp[$i][1] ) EndIf Next PS I have searched for the answer in the forum but to no avail. Help would be much appreciated.1 point