Leaderboard
Popular Content
Showing content with the highest reputation on 06/16/2016 in all areas
-
@czardas - I had not seen your mus++ before. That is the craziest most fantastic thing. I am not a musician - nor do I know how to read music but such a cool script. Great job.1 point
-
czardas, Following your recommendation I suggest this #include <Array.au3> $str = "Gm Cm7 F# Bb" & @crlf & _ "Times are hard You're afraid to pay the fee" & @crlf & _ " Eb Ab Bb F/A Eb/G F Eb" & @crlf & _ "So you find yourself somebody Who can do the job for free" & @crlf ;Msgbox(0,"", $str) Msgbox(0,"", _Transpose($str, -2, 1) ) Func _Transpose($song, $step, $mix = 0) If $mix = 0 Then Local $aNotes = ["Bb" , "B" , "C" , "Db" , "D" , "Eb" , "E" , "F" , "Gb" , "G" , "Ab" , "A"] Else Local $aNotes = ["Bb" , "B" , "C" , "C#" , "D" , "Eb" , "E" , "F" , "F#" , "G" , "G#" , "A"] EndIf $pattern = '([A-G][b#]?)(?=\s|/|[45679]|m[45679]?|dim|$)' $tmp = Execute('"' & StringRegExpReplace($song, $pattern, _ '" & $aNotes[Mod(_ArraySearch($aNotes, "$1")+12+$step, 12)] & "') & '"') Return $tmp EndFunc still in the context of the OP's asking "a little Autoit script to be able to just take my text file, find the chords, transpose them by an inputted amount, and then allow me to either rewrite the file or just display it " As you said, the chord transposition is not too difficult by itself, but the text-file-in/text-file-out thing was a pretty tricky challenge BTW your mus++ is ... totally insane, fantastic. Seriously, this deserved a handy user manual and/or a cute gui so the common user could plainly understand and appreciate the power and acuteness of this script1 point
-
Error Checking
232showtime reacted to water for a topic
You need to check the function you call in the help file. Some denote an error in the return value (like WinExists), some other functions set macros @error / @extended. I would simplify your script to: #include <MsgBoxConstants.au3> Local $hWndR = WinExists("[CLASS:CalcFrame]") If $hWndR <> 1 Then MsgBox($MB_SYSTEMMODAL, "Error", "Calculator does not exist!") Else MsgBox($MB_SYSTEMMODAL, "Result", "Calculator does exist!") EndIf Exit1 point -
I think simplest way is to use the func _ArrayUnique: Func _MakeArrayUnique() $aArrayedit = StringSplit(StringStripCR(GUICtrlRead($Edit1)), @LF,2) $aUnique=_ArrayUnique($aArrayedit) _ArraySort($aUnique,0,1) ;element 0 holds the count of IP's ;_ArrayDisplay($aUnique) For $i = 1 To $aUnique[0] GUICtrlSetData($Edit2, $aUnique[$i] & @CRLF, 1) Next EndFunc ;==>_MakeArrayUnique1 point
-
1 point
-
@wysocki I think you would be interested in look here:1 point
-
@czardas Hehe, not so easy to get exactly the wanted result ... Here is my try... the pattern should be better defined of course #include <Array.au3> $str = "Gm Cm7 F Bb" & @crlf & _ "Times are hard You're afraid to pay the fee" & @crlf & _ " Eb Ab Bb F/A Eb/G F Eb" & @crlf & _ "So you find yourself somebody Who can do the job for free" & @crlf Msgbox(0,"", $str) Msgbox(0,"", _Transpose($str, 2) ) Func _Transpose($song, $step) Local $aNotes = ["Bb" , "B" , "C" , "Db" , "D" , "Eb" , "E" , "F" , "Gb" , "G" , "Ab" , "A"] If $step < 0 Then $step = 12 + $step $pattern = '([A-Z]b?)(?=\s|/|m7?|dim|$)' $tmp = Execute('"' & StringRegExpReplace($song, $pattern, '" & $aNotes[Mod(_ArraySearch($aNotes, "$1")+$step, 12)] & "') & '"') Return $tmp EndFunc1 point
-
Champak, Whenever I have used 2-way communication I have created a MailSlot for each of the participants so that messages can be correctly delivered. Here is a short demo script I have put together showing how I have used the UDF in the past. You need to make several copies (changing an index in the title each time; e.g. Test_1, Test_2, etc) and then run them simultaneously (either compiled or as scripts). Once the instances are all open, press each "Update" button to make sure each instance has the addresses for them all and then send/receive to your heart's content! #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #include <EditConstants.au3> #include "MailSlot.au3" ; Create fill to hold MailSlot addresses Global $sMailSlotListFile = @ScriptDir & "\MailSlotList.lst" ; MailSlot title for this instance Global $sMailSlotTitle = StringRegExpReplace(@ScriptName, "\..*$", "") ; Random string to use as MailSlot name Global $sRandomMailSlotname = _RandomStr() ; Form full address for mMilSlot Global Const $sMailSlotName_Receive = "\\.\mailslot\" & $sRandomMailSlotname ; Add ths MailSlot to list file IniWrite($sMailSlotListFile, "MailSlots", $sMailSlotTitle, $sRandomMailSlotname) ; Create the MailSlot Global $hMailSlot = _MailSlotCreate($sMailSlotName_Receive) If @error Then MsgBox($MB_SYSTEMMODAL + $MB_ICONERROR, "MailSlot Error", "Failed to create initial MailSlot account") Exit EndIf ; Global variables Global $iNumberOfMessagesOverall Global $sMailSlotName_Send = "" ; Create GUI Global $hGUI = GUICreate($sMailSlotTitle, 450, 400, 3 * @DesktopWidth / 4 - 225, Default, Default, $WS_EX_TOPMOST) GUICtrlCreateLabel("Message To Send To:", 10, 22, 150, 25) ; Combo to show current address list Global $cSend_Combo = GUICtrlCreateCombo("", 180, 22, 200, 25) ; Update list _UpdateMail() ; Edit to hold message to send Global $cEdit_Send = GUICtrlCreateEdit("", 15, 50, 300, 50, $ES_AUTOVSCROLL) GUICtrlCreateLabel("Message Received:", 10, 122, 150, 25) ; Create edit to hold received messages Global $cEdit_Read = GUICtrlCreateEdit("", 15, 150, 300, 200, $ES_READONLY) ; Create buttons Global $cButtonSend = GUICtrlCreateButton("&Send Mail", 330, 100, 100, 25) Global $cButton_Update = GUICtrlCreateButton("&Update Accounts", 330, 50, 100, 25) Global $cButtonRead = GUICtrlCreateButton("Read &Mail", 330, 150, 100, 25) Global $cButtonCheckCount = GUICtrlCreateButton("&Check Mail Count", 330, 200, 100, 25) Global $cButtonCloseAccount = GUICtrlCreateButton("Close Mail &Account", 330, 250, 100, 25) Global $cButtonRestoreAccount = GUICtrlCreateButton("&Restore Account", 330, 300, 100, 25) Global $cButtonCloseApp = GUICtrlCreateButton("&Exit", 330, 350, 100, 25) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $cButtonCloseApp IniDelete($sMailSlotListFile, "MailSlots", $sMailSlotTitle) Exit Case $cButtonSend If GUICtrlRead($cSend_Combo) = "" Then MsgBox($MB_SYSTEMMODAL + $MB_ICONINFORMATION, "MailSlot demo", "No account selected!", 0, $hGUI) Else $sMailSlotName_Send = "\\.\mailslot\" & IniRead($sMailSlotListFile, "MailSlots", GUICtrlRead($cSend_Combo), "") If $sMailSlotName_Send <> "\\.\mailslot\" Then _SendMail($sMailSlotName_Send) Else MsgBox($MB_SYSTEMMODAL + $MB_ICONWARNING, "MailSlot demo", "Invalid account.", 0, $hGUI) EndIf EndIf Case $cButton_Update _UpdateMail() Case $cButtonRead If $hMailSlot Then _ReadMessage($hMailSlot) Else MsgBox($MB_SYSTEMMODAL + $MB_ICONWARNING, "MailSlot demo", "MailSlot does not exist", 0, $hGUI) EndIf Case $cButtonCheckCount If $hMailSlot Then _CheckCount($hMailSlot) Else MsgBox($MB_SYSTEMMODAL + $MB_ICONWARNING, "MailSlot demo", "MailSlot does not exist", 0, $hGUI) EndIf Case $cButtonCloseAccount If $hMailSlot Then _CloseMailAccount($hMailSlot) Else MsgBox($MB_SYSTEMMODAL + $MB_ICONINFORMATION, "MailSlot demo", "MailSlot does not exist", 0, $hGUI) EndIf Case $cButtonRestoreAccount If $hMailSlot Then MsgBox($MB_SYSTEMMODAL + $MB_ICONINFORMATION, "MailSlot demo", "MailSlot already exists", 0, $hGUI) Else _RestoreAccount($sMailSlotName_Receive) EndIf EndSwitch WEnd ; Wrapper functions: Func _UpdateMail() Local $aMailSlots = IniReadSection($sMailSlotListFile, "MailSlots") If Not IsArray($aMailSlots) Then MsgBox($MB_SYSTEMMODAL + $MB_ICONINFORMATION, "MailSlot demo", "No accounts available!", 0, $hGUI) Local $sMailSlotList = "|" For $i = 1 To $aMailSlots[0][0] If $aMailSlots[$i][1] <> $sRandomMailSlotname Then $sMailSlotList &= $aMailSlots[$i][0] & "|" Next GUICtrlSetData($cSend_Combo, $sMailSlotList) EndFunc Func _SendMail($sMailSlotName) Local $sDataToSend = GUICtrlRead($cEdit_Send) If $sDataToSend Then _MailSlotWrite($sMailSlotName, $sDataToSend);, 1) Switch @error Case 1 MsgBox($MB_SYSTEMMODAL + $MB_ICONWARNING, "MailSlot demo error", "MialSlot does not exist", 0, $hGUI) Case 2 MsgBox($MB_SYSTEMMODAL + $MB_ICONWARNING, "MailSlot demo error", "MailSlot blocked", 0, $hGUI) Case 3 MsgBox($MB_SYSTEMMODAL + $MB_ICONWARNING, "MailSlot demo error", "Message sent but possible errors in future as open handle remains", 0, $hGUI) Case 4 MsgBox($MB_SYSTEMMODAL + $MB_ICONWARNING, "MailSlot demo error", "MailSlot internal error", 0, $hGUI) Case Else MsgBox($MB_SYSTEMMODAL + $MB_ICONINFORMATION, "MailSlot demo", "Message sent", 0, $hGUI) EndSwitch GUICtrlSetData($cEdit_Send, "") Else MsgBox($MB_SYSTEMMODAL + $MB_ICONINFORMATION, "MailSlot demo", "No message to send", 0, $hGUI) EndIf EndFunc ;==>_SendMail Func _ReadMessage($hHandle) Local $iSize = _MailSlotCheckForNextMessage($hHandle) If $iSize Then Local $sData = _MailSlotRead($hMailSlot, $iSize, 1) $iNumberOfMessagesOverall += 1 GUICtrlSetData($cEdit_Read, "Message No" & $iNumberOfMessagesOverall & " , Size = " & $iSize & " :" & @CRLF & @CRLF & $sData) Else MsgBox($MB_SYSTEMMODAL + $MB_ICONINFORMATION, "Nothing read", "MailSlot empty", 0, $hGUI) EndIf EndFunc ;==>_ReadMessage Func _CheckCount($hHandle) Local $iCount = _MailSlotGetMessageCount($hHandle) Switch $iCount Case 0 MsgBox($MB_SYSTEMMODAL + $MB_ICONINFORMATION, "Messages", "No new messages", 0, $hGUI) Case 1 MsgBox($MB_SYSTEMMODAL + $MB_ICONINFORMATION, "Messages", "There is 1 message waiting to be read", 0, $hGUI) Case Else MsgBox($MB_SYSTEMMODAL + $MB_ICONINFORMATION, "Messages", "There are " & $iCount & " messages waiting to be read", 0, $hGUI) EndSwitch EndFunc ;==>_CheckCount Func _CloseMailAccount(ByRef $hHandle) If _MailSlotClose($hHandle) Then $hHandle = 0 MsgBox($MB_SYSTEMMODAL + $MB_ICONINFORMATION, "MailSlot demo", "Account succesfully closed", 0, $hGUI) IniDelete($sMailSlotListFile, "MailSlots", $sMailSlotTitle) Else MsgBox($MB_SYSTEMMODAL + $MB_ICONWARNING, "MailSlot demo error", "Account could not be closed!", 0, $hGUI) EndIf EndFunc ;==>_CloseMailAccount Func _RestoreAccount($sMailSlotName_Receive) Local $hMailSlotHandle = _MailSlotCreate($sMailSlotName_Receive) If @error Then MsgBox($MB_SYSTEMMODAL + $MB_ICONWARNING, "MailSlot demo error", "Account could not be created", 0, $hGUI) Else MsgBox($MB_SYSTEMMODAL + $MB_ICONINFORMATION, "MailSlot demo", "New account with the same address successfully created", 2, $hGUI) $hMailSlot = $hMailSlotHandle ; global var IniWrite($sMailSlotListFile, "MailSlots", $sMailSlotTitle, $sRandomMailSlotname) EndIf EndFunc ;==>_RestoreAccount Func _RandomStr() Local $sString For $i = 1 To 13 $sString &= Chr(Random(97, 122, 1)) Next Return $sString EndFunc ;==>__RandomStrThere is a file created in the same folder which holds the instance name and associated address - think of it as a phone directory. When each instance is created it adds its details to the file - using the buttons on the GUI you can destroy and then recreate the MailSlot for each instance which will be reflected in the directory when you update. Please ask if you have any further questions. M231 point