Paulie Posted March 21, 2008 Share Posted March 21, 2008 So I've been working on improving the GUI for the "Beep song maker." Unfortunately, I am having a few difficulties. Firstly, the script. I know it's huge and nobody wants to navigate through the whole thing, but this is more for recreation of my problem. expandcollapse popup#include <GUIConstants.au3> #include <Array.au3> #Include <GuiListView.au3> #include <File.au3> #include <String.au3> Opt('GuiOnEventMode',1) Dim $KeySigSharps[8][2] = _ [["C","A"],["G","E"],["D","B"],["A","F#"],["E","C#"],["B","G#"],["F#","D#"],["C#","A#"]] Dim $KeySigFlats[8][2] = _ [["C","A"],["F","D"],["B","G"],["Eb","C"],["Ab","F"],["Db","Bb"],["Gb","Eb"],["Cb","Ab"]] Dim $Pitches = StringSplit( _ "4186.01|3951.07|"& _ "3729.31|3520.00|3322.44|"& _ "3135.96|2959.96|2793.83|"& _ "2637.02|2489.02|2349.32|"& _ "2217.46|2093.00|1975.53|"& _ "1864.66|1760.00|1661.22|"& _ "1567.98|1479.98|1396.91|"& _ "1318.51|1244.51|1174.66|"& _ "1108.73|1046.50|987.767|"& _ "932.328|880.000|830.609|"& _ "783.991|739.989|698.456|"& _ "659.255|622.254|587.330|"& _ "554.365|523.251|493.883|"& _ "466.164|440.000|415.305|"& _ "391.995|369.994|349.228|"& _ "329.628|311.127|293.665|"& _ "277.183|261.626|246.942|"& _ "233.082|220.000|207.652|"& _ "195.998|184.997|174.614|"& _ "164.814|155.563|146.832|"& _ "138.591|130.813|123.471|"& _ "116.541|110.000|103.826|"& _ "97.9989|92.4986|87.3071|"& _ "82.4069|77.7817|73.4162|"& _ "69.2957|65.4064|61.7354|"& _ "58.2705|55.0000|51.9130|"& _ "48.9995|46.2493|43.6536|"& _ "41.2035|38.8909|36.7081|"& _ "34.6479|32.7032|30.8677|"& _ "29.1353|27.5000|", "|") Dim $NoteOctavePitch[89][3] For $i = 1 to 88 For $x = 0 to 2 Switch $x Case 0;Note Name For $y = 0 to 8 If $i = 1+(12*$y) then $NoteOctavePitch[$i][$x] = "A" If $i = 2+(12*$y) then $NoteOctavePitch[$i][$x] = "A#" If $i = 3+(12*$y) then $NoteOctavePitch[$i][$x] = "B" If $i = 4+(12*$y) then $NoteOctavePitch[$i][$x] = "C" If $i = 5+(12*$y) then $NoteOctavePitch[$i][$x] = "C#" If $i = 6+(12*$y) then $NoteOctavePitch[$i][$x] = "D" If $i = 7+(12*$y) then $NoteOctavePitch[$i][$x] = "D#" If $i = 8+(12*$y) then $NoteOctavePitch[$i][$x] = "E" If $i = 9+(12*$y) then $NoteOctavePitch[$i][$x] = "F" If $i = 10+(12*$y) then $NoteOctavePitch[$i][$x] = "F#" If $i = 11+(12*$y) then $NoteOctavePitch[$i][$x] = "G" If $i = 12+(12*$y) then $NoteOctavePitch[$i][$x] = "G#" Next Case 1;Octave If $i <=12 then $NoteOctavePitch[$i][$x]= 1 If $i >12 And $i<=24 then $NoteOctavePitch[$i][$x]= 2 If $i >24 And $i<=36 then $NoteOctavePitch[$i][$x]= 3 If $i >36 And $i<=48 then $NoteOctavePitch[$i][$x]= 4 If $i >48 And $i<=60 then $NoteOctavePitch[$i][$x]= 5 If $i >60 And $i<=72 then $NoteOctavePitch[$i][$x]= 6 If $i >72 And $i<=84 then $NoteOctavePitch[$i][$x]= 7 If $i >84 And $i<=88 then $NoteOctavePitch[$i][$x]= 8 Case 2;Frequency $NoteOctavePitch[$i][$x] = $Pitches[89-$i] EndSwitch Next Next $GUI = GUICreate("Beep Song Creator", 608, 447, 218, 115) GUISetOnEvent($GUI_EVENT_CLOSE,"Quit",$GUI) $Group1 = GUICtrlCreateGroup("General Information", 192, 8, 217, 81) $Title = GUICtrlCreateInput("", 256, 24, 113, 21) GUICtrlCreateLabel("Title:", 200, 24, 27, 17) GUICtrlCreateLabel("Composer:", 200, 56, 54, 17) $Composer = GUICtrlCreateInput("", 256, 56, 113, 21) GUICtrlCreateGroup("", -99, -99, 1, 1) $Group2 = GUICtrlCreateGroup("Pitch Properties", 192, 104, 217, 125) $Pitch = GUICtrlCreateCombo("", 232, 124, 89, 25) GUICtrlSetData(-1, "A|A#|B|C|C#|D|D#|E|F|F#|G|G#", "A") GUICtrlSetBkColor(-1, 0xFFFFFF) GUICtrlSetOnEvent(-1, "UpdatePitch") $Octave = GUICtrlCreateInput("1", 368, 123, 35, 21, BitOR($ES_AUTOHSCROLL,$ES_READONLY,$ES_NUMBER)) GUICtrlSetBkColor(-1, 0xFFFFFF) $UpDwn=GUICtrlCreateUpdown($Octave) GUICtrlSetOnEvent(-1, "UpdatePitch") GUICtrlSetLimit(-1,8,1) $KeyNum = GUICtrlCreateInput("1", 272, 184, 89, 21,$ES_NUMBER) GUICtrlSetOnEvent(-1, "UpdatePitch") GUICtrlSetBkColor(-1, 0xFFFFFF) $UpDwn2=GUICtrlCreateUpdown($KeyNum) GUICtrlSetOnEvent(-1, "UpdatePitch") GUICtrlSetLimit(-1,88,1) GUICtrlCreateLabel("Octave:", 324, 126, 42, 17) GUICtrlCreateLabel("Pitch:", 200, 126, 31, 17) GUICtrlCreateLabel("Key Number:", 201, 186, 65, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) $Group5 = GUICtrlCreateGroup("Duration Properties", 192, 235, 217, 200) $CNoteRadio = GUICtrlCreateRadio("Custom Duration", 200, 254, 121, 25) GUICtrlSetOnEvent(-1, "DurationDepends") GUICtrlSetState(-1,$GUI_CHECKED) $CNoteDur = GUICtrlCreateInput("250", 248, 280, 73, 21, $ES_NUMBER) $BNoteRadio = GUICtrlCreateRadio("Base Duration", 200, 304, 121, 25) GUICtrlSetOnEvent(-1, "DurationDepends") $BNoteDur = GUICtrlCreateInput("250", 248, 334, 81, 21, $ES_NUMBER) $NoteType = GUICtrlCreateCombo("Quarter", 248, 366, 129, 25) GUICtrlSetData(-1, "Sixteenth|Dotted Sixteenth|Eighth|Dotted Eighth|Dotted Quarter|Half|Dotted Half|Whole|Dotted Whole") $AddNote = GUICtrlCreateButton("Add Note", 208, 396, 65, 25, 0) GUICtrlSetOnEvent(-1, "AddNote") $PrevNote = GUICtrlCreateButton("Preview", 288, 396, 65, 25, 0) GUICtrlSetOnEvent(-1, "PreviewNote") GUICtrlCreateLabel("ms", 328, 282, 17, 17) GUICtrlCreateLabel("ms", 338, 335, 17, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) $Group3 = GUICtrlCreateGroup("Key Signature", 16, 8, 161, 121) $KeySigNum = GUICtrlCreateInput("0", 32, 280-248, 49, 21, BitOR($ES_AUTOHSCROLL,$ES_READONLY)) GUICtrlSetBkColor(-1, 0xFFFFFF) $UpDwn3=GUICtrlCreateUpdown($KeySigNum) GUICtrlSetOnEvent(-1, "UpdateKeySig") GUICtrlSetLimit(-1,7,0) $KeySigType = GUICtrlCreateCombo("Sharps", 88, 280-248, 65, 25) GUICtrlSetData(-1, "Flats") GUICtrlSetOnEvent(-1, "UpdateKeySig") $MajorDisp = GUICtrlCreateInput("", 48, 312-248, 97, 21,$ES_READONLY) $MinorDisp = GUICtrlCreateInput("", 48, 344-248, 97, 21,$ES_READONLY) GUICtrlCreateGroup("", -99, -99, 1, 1) $Group4 = GUICtrlCreateGroup("Rest Properties", 16, 240-100, 161, 193) $AddRest = GUICtrlCreateButton("Add Rest", 472-408, 400-100, 57, 25, 0) GUICtrlSetOnEvent(-1, "AddRest") $CRestRadio = GUICtrlCreateRadio("Custom Duration", 434-408, 261-100, 121, 25) GUICtrlSetOnEvent(-1, "RestDepends") GUICtrlSetState(-1,$GUI_CHECKED) $CRestDur = GUICtrlCreateInput("250", 447-408, 287-100, 73, 21, $ES_NUMBER) $BRestRadio = GUICtrlCreateRadio("Base Duration", 435-408, 316-100, 121, 17) GUICtrlSetOnEvent(-1, "RestDepends") $BRestDur = GUICtrlCreateInput("250", 442-408, 340-100, 81, 21, $ES_NUMBER) $RestType = GUICtrlCreateCombo("Quarter", 442-408, 374-100, 129, 25) GUICtrlSetData(-1, "Sixteenth|Dotted Sixteenth|Eighth|Dotted Eighth |Dotted Quarter|Half|Dotted Half|Whole|Dotted Whole") GUICtrlCreateLabel("ms", 528-408, 288-100, 17, 17) GUICtrlCreateLabel("ms", 528-408, 343-100, 17, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) Global $SongView = GUICtrlCreateListView("Key|Note|Duration", 424, 16, 161, 300,BitOR($LVS_SHOWSELALWAYS,$LVS_REPORT), BitOR($LVS_EX_UNDERLINEHOT,$LVS_EX_FULLROWSELECT,$LVS_EX_FLATSB) ) $Copy = GUICtrlCreateButton("Copy selected", 432, 330, 145, 25, 0) GUICtrlSetOnEvent(-1, "CopyNote") $Insert = GUICtrlCreateButton("Insert", 432, 365, 65, 25, 0) GUICtrlSetOnEvent(-1, "InsertNote") $Modify = GUICtrlCreateButton("Modify", 512, 365, 65, 25, 0) GUICtrlSetOnEvent(-1, "ModifyNote") $Clear = GUICtrlCreateButton("Clear", 432, 400, 65, 25, 0) GUICtrlSetOnEvent(-1, "ClearList") $Delete = GUICtrlCreateButton("Delete", 512, 400, 65, 25, 0) GUICtrlSetOnEvent(-1, "Delete") $Open = GUICtrlCreateButton("Open", 20, 365, 145, 25, 0) GUICtrlSetOnEvent(-1, "OpenSong") $Preview = GUICtrlCreateButton("Preview", 20, 400, 65, 25, 0) GUICtrlSetOnEvent(-1, "PreviewSong") $Create = GUICtrlCreateButton("Create", 100, 400, 65, 25, 0) GUICtrlSetOnEvent(-1, "CreateSong") GUISetState(@SW_SHOW) RestDepends() DurationDepends() UpdateKeySig() While 1 Sleep(100) WEnd Func CopyNote() $hwnd = GUICtrlGetHandle ($SongView) $index= _GUICtrlListView_GetSelectedIndices($hwnd,True) Dim $Items[$index[0]+1] $Items[0] = $index[0] For $i = 1 to $index[0] $Items[$i] = ProcessItem($index[$i]) Next For $i = 1 to $Items[0] $info = StringSplit($Items[$i],"|") $idx = _GUICtrlListView_InsertItem($SongView, $info[1]) _GUICtrlListView_SetItemText ($SongView, $idx, $info[2], 1) _GUICtrlListView_SetItemText ($SongView, $idx, $info[3], 2) Next EndFunc func ProcessItem($index) $String = "" $hwnd = GUICtrlGetHandle ($SongView) $array = _GUICtrlListView_GetItemTextArray ($hWnd, $index) For $i = 1 to $array[0] $String &= $Array[$i]&"|" Next Return StringTrimRight($String,1) EndFunc Func ModifyNote() $hwnd = GUICtrlGetHandle ($SongView) $index= _GUICtrlListView_GetSelectedIndices($hwnd) If StringInStr($index, "|") Then $Temp = StringSplit($index,"|") $index = $Temp[1] EndIf $Array= _GUICtrlListView_GetItemTextArray($hwnd, $index) If $index = "" then MsgBox(0,"Error", "Please select a note to modify.") Return ElseIf $Array[1]="R" then Do $Duration = InputBox("Modify","Input duration of the note.", $Array[3]) $Duration = Number($Duration) Until IsNumber($Duration) _GUICtrlListView_SetItemText($hwnd, $index, $Duration,2) ElseIf StringLeft($Array[1], 1) = ";" Then $Comment = InputBox("Modify", "Enter New Commment Text", $Array[1], " M5") If @error then Return _GUICtrlListView_SetItemText($hwnd, $index, $Comment) Else $NewNote = InputBox("Modify", "Input Key Number or Note(with octive)"&@CRLF&'ex. "40" or "C4" or "C#4"', $Array[1]) If @error then Return $NewNote=StringUpper($NewNote) If StringRegExp($NewNote, "[ABCDEFG](#)?(\d){1}") Then $Name = $NewNote For $a = 1 to 88 If $Name=$NoteOctavePitch[$a][0]&$NoteOctavePitch[$a][1] Then $Num=$a Next ElseIf StringRegExp($NewNote, "(\d){1,2}") And $NewNote<88 Then $Num = $NewNote $Name = $NoteOctavePitch[$num][0]&$NoteOctavePitch[$num][1] Else MsgBox(0,"Error", "Unrecognized note. Try again.") ModifyNote() Return EndIf Do $Duration = InputBox("Modify","Input duration of the note.", $Array[3]) $Duration = Number($Duration) Until IsNumber($Duration) _GUICtrlListView_SetItemText($hwnd, $index, $Num) _GUICtrlListView_SetItemText($hwnd, $index, $Name,1) _GUICtrlListView_SetItemText($hwnd, $index, $Duration,2) EndIf EndFunc Func InsertNote() $hwnd = GUICtrlGetHandle ($SongView) $index= _GUICtrlListView_GetSelectedIndices($hwnd) If StringInStr($index, "|") Then $Temp = StringSplit($index,"|") $index = $Temp[1]+1 Else $index+=1 EndIf If $index = "" then MsgBox(0,"Error", "Please select a location, or use ""Add Note"".") Return Else $NewNote = InputBox("Insert", "Input Key Number or Note(with octive)"&@CRLF&'ex. "40" or "C4" or "C#4"',"", " M5") If @error then Return If Not StringLeft($NewNote,1) = ";" then $NewNote = StringUpper($NewNote) If StringRegExp($NewNote, "[ABCDEFG](#)?(\d){1}") Then $Name = $NewNote For $a = 1 to 88 If $Name=$NoteOctavePitch[$a][0]&$NoteOctavePitch[$a][1] Then $Num=$a Next ElseIf StringRegExp($NewNote, "(\d){1,2}") And $NewNote<88 Then $Num = $NewNote $Name = $NoteOctavePitch[$num][0]&$NoteOctavePitch[$Num][1] ElseIf $NewNote = "R" or $Newnote = "Rest" Then $Num = "R" $Name = "Rest" ElseIf StringLeft($NewNote,1) = ";" then _GUICtrlListView_InsertItem($hWnd, $NewNote,$index) Return Elseif Not $NewNote = "" then MsgBox(0,"Error", "Unrecognized note. Try again.") InsertNote() Return Else Return EndIf Do $Duration = InputBox("Insert","Input duration of the note.") $Duration = Number($Duration) Until IsNumber($Duration) _GUICtrlListView_InsertItem($hWnd, $Num,$index) _GUICtrlListView_SetItemText($hwnd, $index, $Name,1) _GUICtrlListView_SetItemText($hwnd, $index, $Duration,2) EndIf EndFunc Func Quit() Exit EndFunc Func RestDepends() If GUICtrlRead($CRestRadio) = $GUI_UNCHECKED Then GUICtrlSetState($CRestDur, $GUI_DISABLE) GUICtrlSetState($BRestDur, $GUI_ENABLE) GUICtrlSetState($RestType, $GUI_ENABLE) Else GUICtrlSetState($CRestDur, $GUI_ENABLE) GUICtrlSetState($BRestDur, $GUI_DISABLE) GUICtrlSetState($RestType, $GUI_DISABLE) EndIf EndFunc Func DurationDepends() If GUICtrlRead($CNoteRadio) = $GUI_UNCHECKED Then GUICtrlSetState($CNoteDur, $GUI_DISABLE) GUICtrlSetState($BNoteDur, $GUI_ENABLE) GUICtrlSetState($NoteType, $GUI_ENABLE) Else GUICtrlSetState($CNoteDur, $GUI_ENABLE) GUICtrlSetState($BNoteDur, $GUI_DISABLE) GUICtrlSetState($NoteType, $GUI_DISABLE) EndIf EndFunc Func UpdateKeySig() If GUICtrlRead($KeySigType) = "Sharps" Then $Num = GUICtrlRead($KeySigNum) $KeyMaj = $KeySigSharps[$Num][0] $KeyMin = $KeySigSharps[$Num][1] GUICtrlSetData($MajorDisp, "Major: "&$KeyMaj) GUICtrlSetData($MinorDisp, "Minor: "&$KeyMin) ElseIf GUICtrlRead($KeySigType) = "Flats" Then $Num = GUICtrlRead($KeySigNum) $KeyMaj = $KeySigFlats[$Num][0] $KeyMin = $KeySigFlats[$Num][1] GUICtrlSetData($MajorDisp, "Major: "&$KeyMaj) GUICtrlSetData($MinorDisp, "Minor: "&$KeyMin) Else GUICtrlSetData($MajorDisp, "Major: Error") GUICtrlSetData($MinorDisp, "Minor: Error") EndIf EndFunc Func UpdatePitch() Switch @GUI_CtrlID Case $UpDwn2,$KeyNum ControlCommand($GUI, "","ComboBox1","SelectString",$NoteOctavePitch[GUICtrlRead($KeyNum)][0]) GUICtrlSetData($Octave, $NoteOctavePitch[GUICtrlRead($KeyNum)][1]) If GuiCtrlRead($Octave) = 8 Then GUICtrlSetData($Pitch, "|A|A#|B|C",$NoteOctavePitch[GUICtrlRead($KeyNum)][0]) Else GUICtrlSetData($Pitch, "|A|A#|B|C|C#|D|D#|E|F|F#|G|G#",$NoteOctavePitch[GUICtrlRead($KeyNum)][0]) EndIf Case $Pitch For $x = 1 to 88 If $NoteOctavePitch[$x][0] = GUICtrlRead($Pitch) AND $NoteOctavePitch[$x][1] = GUICtrlRead($Octave) Then GUICtrlSetData($KeyNum, $x) EndIf Next If GuiCtrlRead($Octave) = 8 And (Not GuiCtrlRead($Pitch) = "A" Or Not GuiCtrlRead($Pitch) = "B" Or Not GuiCtrlRead($Pitch) = "B#" Or Not GuiCtrlRead($Pitch) = "C") Then GUICtrlSetData($Pitch, "|A|A#|B|C","C") Case $UpDwn For $x = 1 to 88 If $NoteOctavePitch[$x][0] = GUICtrlRead($Pitch) AND $NoteOctavePitch[$x][1] = GUICtrlRead($Octave) Then GUICtrlSetData($KeyNum, $x) EndIf Next If GuiCtrlRead($Octave) = 8 Then GUICtrlSetData($Pitch, "|A|A#|B|C",$NoteOctavePitch[GUICtrlRead($KeyNum)][0]) Else GUICtrlSetData($Pitch, "|A|A#|B|C|C#|D|D#|E|F|F#|G|G#",$NoteOctavePitch[GUICtrlRead($KeyNum)][0]) EndIf EndSwitch If GuiCtrlRead($Pitch) = "" then GUICtrlSetData($KeyNum,0) EndFunc Func AddNote() If GuiCtrlRead($KeyNum)= 0 Then MsgBox(0,"Error", "Pitch Settings Invalid.") Return EndIf $Key = GUICtrlRead($KeyNum) $Note = GUICtrlRead($Pitch) $Octave1 = GUICtrlRead($Octave) If GuiCtrlRead($CNoteRadio)= $GUI_CHECKED Then $Duration = GuiCtrlRead($CNoteDur) ElseIf GuiCtrlRead($BNoteRadio)= $GUI_CHECKED Then Switch GUICtrlRead($NoteType) Case "Quarter" $Duration = GuiCtrlRead($BNoteDur) Case "Sixteenth" $Duration = GuiCtrlRead($BNoteDur)/4 Case "Eighth" $Duration = GuiCtrlRead($BNoteDur)/2 Case "Half" $Duration = GuiCtrlRead($BNoteDur)*2 Case "Whole" $Duration = GuiCtrlRead($BNoteDur)*4 Case "Dotted Quarter" $Duration = GuiCtrlRead($BNoteDur)*1.5 Case "Dotted Sixteenth" $Duration = (GuiCtrlRead($BNoteDur)/4)*1.5 Case "Dotted Eighth" $Duration = (GuiCtrlRead($BNoteDur)/2)*1.5 Case "Dotted Half" $Duration = (GuiCtrlRead($BNoteDur)*2)*1.5 Case "Dotted Whole" $Duration = (GuiCtrlRead($BNoteDur)*4)*1.5 EndSwitch EndIf $idx = _GUICtrlListView_InsertItem($SongView, $Key) _GUICtrlListView_SetItemText ($SongView, $idx, $Note&$Octave1, 1) _GUICtrlListView_SetItemText ($SongView, $idx, $Duration, 2) EndFunc Func PreviewNote() $Key = GUICtrlRead($KeyNum) If GuiCtrlRead($CNoteRadio)= $GUI_CHECKED Then $Duration = GuiCtrlRead($CNoteDur) ElseIf GuiCtrlRead($BNoteRadio)= $GUI_CHECKED Then Switch GUICtrlRead($NoteType) Case "Quarter" $Duration = GuiCtrlRead($BNoteDur) Case "Sixteenth" $Duration = GuiCtrlRead($BNoteDur)/4 Case "Eighth" $Duration = GuiCtrlRead($BNoteDur)/2 Case "Half" $Duration = GuiCtrlRead($BNoteDur)*2 Case "Whole" $Duration = GuiCtrlRead($BNoteDur)*4 Case "Dotted Quarter" $Duration = GuiCtrlRead($BNoteDur)*1.5 Case "Dotted Sixteenth" $Duration = (GuiCtrlRead($BNoteDur)/4)*1.5 Case "Dotted Eighth" $Duration = (GuiCtrlRead($BNoteDur)/2)*1.5 Case "Dotted Half" $Duration = (GuiCtrlRead($BNoteDur)*2)*1.5 Case "Dotted Whole" $Duration = (GuiCtrlRead($BNoteDur)*4)*1.5 EndSwitch EndIf Beep($NoteOctavePitch[$Key][2],$Duration) EndFunc Func Delete() $hwnd = GUICtrlGetHandle ($SongView) _GUICtrlListView_DeleteItemsSelected($hwnd) EndFunc Func ClearList() $ans = MsgBox(4, "Clear", "Are your sure you want to delete all notes?") If $ans=6 Then $hwnd = GUICtrlGetHandle ($SongView) _GUICtrlListView_DeleteAllItems($hwnd) EndIf EndFunc Func PreviewSong() $Count = _GUICtrlListView_GetItemCount($SongView) $index = _GUICtrlListView_GetSelectedIndices(GUICtrlGetHandle($SongView)) If Not $index = "" Then If StringInStr($index, "|") Then $Temp = StringSplit($index,"|") $Selected = $Temp[1] Else $Selected = $index EndIf Else $Selected = 0 EndIf For $z = $Selected to $Count-1 _GUICtrlListView_SetItemSelected($Songview, $z) If $z>0 then _GUICtrlListView_SetItemSelected($Songview, $z-1,0) $Item = _GUICtrlListView_GetItemTextArray($SongView, $z) If $Item[1] = "R" then Sleep($Item[3]) Else Beep($NoteOctavePitch[$Item[1]][2], $Item[3]) EndIf Next _GUICtrlListView_SetItemSelected($Songview, $Count,0) EndFunc Func AddRest() If GuiCtrlRead($CRestRadio)= $GUI_CHECKED Then $Duration = GuiCtrlRead($CRestDur) ElseIf GuiCtrlRead($BRestRadio)= $GUI_CHECKED Then Switch GUICtrlRead($RestType) Case "Quarter" $Duration = GuiCtrlRead($BRestDur) Case "Sixteenth" $Duration = GuiCtrlRead($BRestDur)/4 Case "Eighth" $Duration = GuiCtrlRead($BRestDur)/2 Case "Half" $Duration = GuiCtrlRead($BRestDur)*2 Case "Whole" $Duration = GuiCtrlRead($BRestDur)*4 Case "Dotted Quarter" $Duration = GuiCtrlRead($BRestDur)*1.5 Case "Dotted Sixteenth" $Duration = (GuiCtrlRead($BRestDur)/4)*1.5 Case "Dotted Eighth" $Duration = (GuiCtrlRead($BRestDur)/2)*1.5 Case "Dotted Half" $Duration = (GuiCtrlRead($BRestDur)*2)*1.5 Case "Dotted Whole" $Duration = (GuiCtrlRead($BRestDur)*4)*1.5 EndSwitch EndIf $idx = _GUICtrlListView_InsertItem($SongView, "R") _GUICtrlListView_SetItemText ($SongView, $idx, "Rest", 1) _GUICtrlListView_SetItemText ($SongView, $idx, $Duration, 2) EndFunc Func CreateSong() If GUICtrlRead($KeySigType) = "Sharps" Then $Num = GUICtrlRead($KeySigNum) $KeyMaj = $KeySigSharps[$Num][0] ElseIf GUICtrlRead($KeySigType) = "Flats" Then $Num = GUICtrlRead($KeySigNum) $KeyMaj = $KeySigFlats[$Num][0] EndIf $Path = FileSaveDialog("Path", @DesktopDir, "Autoit Script(*.au3)",16, GuiCtrlRead($Title)&"-"&GuiCtrlRead($Composer)&".au3") $Count = _GUICtrlListView_GetItemCount($SongView) $File = FileOpen($Path, 2) FileWrite($File,"#cs"&@CRLF&"Title: "&GuiCtrlRead($Title)&@CRLF&"Composer: "&GuiCtrlRead($Composer)&@CRLF&"Key Signature: "&$KeyMaj&@CRLF&"#ce"&@CRLF) For $z = 0 to $Count-1 $array = _GUICtrlListView_GetItemTextArray($SongView, $z) If $array[1] = "R" then $Line = "Sleep("&$array[3]&");Rest" ElseIf StringLeft($Array[1],1) =";" Then $Line = $Array[1] Else $Line = "Beep("&$NoteOctavePitch[$array[1]][2]&", "&$array[3]&");"&$array[2]&" - "&$array[1] EndIf FileWriteLine($File, $Line) Next FileClose($File) EndFunc Func OpenSong() $hwnd = GUICtrlGetHandle ($SongView) If _GUICtrlListView_GetItemCount($Hwnd) >0 then $ans = MsgBox(4, "Open", "This will delete your current compilation. Continue?") If $ans=6 Then _GUICtrlListView_DeleteAllItems($hwnd) Else Return EndIf EndIf Dim $Lines $Path = FileOpenDialog("Path", @DesktopDir, "Autoit Script(*.au3)",3) If not _FileReadToArray($Path, $Lines) then MsgBox(0,"", "Error Opening File.") Return EndIf $NewTitle = StringTrimLeft($Lines[2], Stringlen("Title: ")) $NewComp = StringTrimLeft($Lines[3], Stringlen("Composer: ")) $NewMajKey = StringTrimLeft($Lines[4], Stringlen("Key Signature: ")) For $i = 6 to $Lines[0] $Lines[$i] = StringStripWS($Lines[$i],8) Switch StringLeft($Lines[$i],1) Case "S" $Temp = _StringBetween($Lines[$i],"(",")") $Dur = $Temp[0] $idx = _GUICtrlListView_AddItem($SongView, "R") _GUICtrlListView_SetItemText ($SongView, $idx, "Rest", 1) _GUICtrlListView_SetItemText ($SongView, $idx, $Dur, 2) Case "B" $Temp = _StringBetween($Lines[$i],",",")") $Pitch = Number(StringRight($Lines[$i],2)) ;MsgBox(0,"",$Pitch) IF not $Pitch Then Msgbox(0,"Error","Error"&@CRLF&"Note line is not properly formatted."&@CRLF&"Line: "&$i&@CRLF&@CRLF&$Lines[$i]) Return EndIf If IsArray($Temp) then $Dur = $Temp[0] Else MsgBox(0,"",$Temp) EndIf $idx = _GUICtrlListView_AddItem($SongView, $Pitch) _GUICtrlListView_SetItemText ($SongView, $idx, $NoteOctavePitch[$Pitch][0]&$NoteOctavePitch[$Pitch][1], 1) _GUICtrlListView_SetItemText ($SongView, $idx, $Dur, 2) Case ";" _GUICtrlListView_AddItem($SongView, $lines[$i]) Case "" Case Else MsgBox(0,"Error", "Error"&@CRLF&"Line is not recognized as a note, rest or comment."&@CRLF&"Line: "&$i&@CRLF&@CRLF&$Lines[$i]) Return EndSwitch Next GUICtrlSetData($Title, $NewTitle) GUICtrlSetData($Composer, $NewComp) EndFunc Now, 1 major problem I am having is this, and it happens seemingly randomly. Occasionally, after creating a file, closing and then reopening the program, the loading the previously created song, when an item in the listview is clicked, another item is added to the end of the list. (usually it is only one item that does this, but which one seems to be random too) Then, on top of that, when that newly added item is clicked, it appears to run the "insertnote()" function. I can't figure out why it does this.... Link to comment Share on other sites More sharing options...
Paulie Posted March 22, 2008 Author Share Posted March 22, 2008 (edited) Nevermind, problem was the listview bug when you mix and match the native and the udf listview functions wish i had seen that before i posted Edited March 22, 2008 by Paulie Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now