• Ich präsentiere:
    Chords v0.2
    [Blockierte Grafik: http://www.abload.de/img/chordsuploada50q.png]
    Man kann damit Akkorde im Text transponieren, oder die Auswahl. Die Öffnen- und Speicherfunktion ist einigermaßen ausgereift.
    Bugs: Momentan klappt aus unerfindlichen Gründen das runtertransponieren nicht...
    Außerdem funktioniert Reselektieren nach dem Transponieren nicht, obwohl eigentlich alle Parameter richtig sind...
    Todo:Paralleltonart, AutoScroll (langsames runterscrollen), ...

    EDIT

    ChordGUI.au3
    [autoit]

    #cs
    The following content is licensed under a CC 3.0 by-nc-sa license
    In short, that means, that you are allowed to copy or modify the original file, if you don't do this commercially,
    if you name the author ( L3viathan2142, http://twitter.com/L3viathan2142) and if you redistribute the modification under the
    same attributions. You are never allowed to remove this comment.
    License overview:
    http://creativecommons.org/licenses/by-nc-sa/3.0/de/
    Full license
    http://creativecommons.org/licenses/by-nc-sa/3.0/de/legalcode
    #ce
    #include <Array.au3>
    #include <GuiEdit.au3>
    #include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include "_Chords.au3"
    GLOBAL $savedName="",$savedVersion=""
    $Form1 = GUICreate("Chords - Unbenannter Song", 700, 442)
    $FileMenu=GUICtrlCreateMenu("&Datei")
    $newitem = GUICtrlCreateMenuItem("Neu" & @TAB & "Strg+N", $filemenu)
    $openitem = GUICtrlCreateMenuItem("Öffnen" & @TAB & "Strg+O", $filemenu)
    GUICtrlSetState(-1, $GUI_DEFBUTTON)
    $helpmenu = GUICtrlCreateMenu("?")
    $saveitem = GUICtrlCreateMenuItem("Speichern..." & @TAB & "Strg+S", $filemenu)
    $infoitem = GUICtrlCreateMenuItem("Info", $helpmenu)
    $exititem = GUICtrlCreateMenuItem("Beenden" & @TAB & "Alt+F4", $filemenu)
    $Edit1 = GUICtrlCreateEdit("", 0, 0, 633, 420)
    GUICtrlSetFont(-1,10,Default,Default,"Courier New")
    GUICtrlSetData(-1,"")
    GUICtrlSetBkColor(-1,0xffffff)
    ;Buttons:
    $hTransplus=GUICtrlCreateButton("Transpose +1",633,0,67,67,$BS_ICON)
    GUICtrlSetImage(-1, "plus1.ico",0,1)
    $hTransminus=GUICtrlCreateButton("Transpose -1",633,67,67,67,$BS_ICON)
    GUICtrlSetImage(-1, "minus1.ico",0,1)
    GUICtrlCreateButton("Platzhalter",633,2*67,67,67,$BS_ICON)
    GUICtrlCreateButton("Platzhalter",633,3*67,67,67,$BS_ICON)
    GUICtrlCreateButton("Platzhalter",633,4*67,67,67,$BS_ICON)

    [/autoit] [autoit][/autoit] [autoit]

    Dim $accel[3][2]=[["^n",$newitem],["^o",$openitem],["^s",$saveitem]]
    GUISetAccelerators($accel)
    GUISetState(@SW_SHOW)

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $newitem
    _new()
    Case $openitem
    _open()
    Case $saveitem
    _save()
    Case $exititem, $GUI_EVENT_CLOSE
    If _new() Then Exit
    Case $infoitem
    _info()
    Case $hTransplus
    _transPLUS()
    Case $hTransminus
    _transMINUS()
    EndSwitch
    WEnd
    Func _new()
    If $savedVersion <> GUICtrlRead($Edit1) Then
    $question=MsgBox(32+3,"Chords","Das Dokument hat ungespeicherte Änderungen. Möchten Sie speichern?")
    Switch $question
    Case 2
    Return False
    Case 6
    If not _save() Then Return False
    Case 7
    ;do nothing
    EndSwitch
    EndIf
    GUICtrlSetData($Edit1,"")
    $savedVersion=""
    Return True
    EndFunc
    Func _save()
    $ask=FileSaveDialog("Datei speichern...",@WorkingDir,"Textdateien (*.txt)|Alle Dateien (*.txt)",16,$savedName)
    If not @error Then
    $hFile=FileOpen($ask,2)
    FileWrite($hFile,GUICtrlRead($Edit1))
    FileClose($hFile)
    $savedName=$ask
    WinSetTitle("Chords","","Chords - " & $savedName)
    Else
    Return False
    EndIf
    EndFunc
    Func _open()
    $ask=FileOpenDialog("Datei öffnen...",@WorkingDir,"Textdateien (*.txt)|Alle Dateien (*.txt)",3)
    If @error Then Return False
    If not _new() Then Return False
    $hFile=FileOpen($ask,0)
    GUICtrlSetData($Edit1,FileRead($hFile))
    FileClose($hFile)
    $savedName=$ask
    WinSetTitle("Chords","","Chords - " & $savedName)
    EndFunc
    Func _info()
    MsgBox(64,"Chords","Chords - ein simples Akkordprogramm" & @CRLF & @CRLF & "Ein Programm von L3viathan2142" & @CRLF & "(c) 2010. Alle Rechte vorbehalten.")
    EndFunc
    Func _transPLUS()
    $aTmp=_GUICtrlEdit_GetSel($Edit1)
    $read=GUICtrlRead($Edit1)
    If $aTmp[0] = $aTmp[1] Then Return GUICtrlSetData($Edit1,_TextTranspose($read,1))
    $text=StringTrimLeft(StringLeft($read,$aTmp[1]),$aTmp[0])
    $newText=_TextTranspose($text,1)
    $newlen=StringLen($newText)
    GUICtrlSetData($Edit1,StringLeft($read,$aTmp[0]) & $newText & StringTrimLeft($read,$aTmp[1]))
    _GUICtrlEdit_SetSel($Edit1,$aTmp[0],$aTmp[0]+$newlen);not working
    EndFunc
    Func _transMINUS()
    $aTmp=_GUICtrlEdit_GetSel($Edit1)
    $read=GUICtrlRead($Edit1)
    If $aTmp[0] = $aTmp[1] Then Return GUICtrlSetData($Edit1,_TextTranspose($read,-1))
    $text=StringTrimLeft(StringLeft($read,$aTmp[1]),$aTmp[0])
    $newText=_TextTranspose($text,-1)
    $newlen=StringLen($newText)
    GUICtrlSetData($Edit1,StringLeft($read,$aTmp[0]) & $newText & StringTrimLeft($read,$aTmp[1]))
    _GUICtrlEdit_SetSel($Edit1,$aTmp[0],$aTmp[0]+$newlen);not working
    EndFunc
    ;#TODO:
    #cs
    AutoScroll
    Transpose+1/-1
    Print (HTML <b>)
    Parallele Moll/Dur-Tonart
    #ce

    [/autoit]
    _Chords.au3
    [autoit]

    #cs
    The following content is licensed under a CC 3.0 by-nc-sa license
    In short, that means, that you are allowed to copy or modify the original file, if you don't do this commercially,
    if you name the author ( L3viathan2142, http://twitter.com/L3viathan2142) and if you redistribute the modification under the
    same attributions. You are never allowed to remove this comment.
    License overview:
    http://creativecommons.org/licenses/by-nc-sa/3.0/de/
    Full license
    http://creativecommons.org/licenses/by-nc-sa/3.0/de/legalcode
    #ce
    #include <Array.au3>
    ;Schreibweise:
    #cs
    Großbuchstabe A-G
    optional "m" für moll
    optional Zahlen
    optinal "/" & A-G
    #ce
    ;~ $_REGEXP_CHORD="([A-G](#|b){0,1}m{0,1}\d*(/[A-G]){0,1})"
    $_REGEXP_CHORD="\b(?:[A-G](?:#|b)?m?\d*[^\w ]?\b)\b"
    $_TONE_C=0
    $_TONE_Db=1
    $_TONE_D=2
    $_TONE_Eb=3
    $_TONE_E=4
    $_TONE_F=5
    $_TONE_Gb=6
    $_TONE_G=7
    $_TONE_Ab=8
    $_TONE_A=9
    $_TONE_Bb=10
    $_TONE_B=11
    Func _isChord($sChord)
    Return StringRegExp($sChord,$_REGEXP_CHORD,0)
    EndFunc
    Func _ChordTranspose($sChord,$iTones)
    ;$iTones= +- 11
    $firstTone=_ChordGetBasicTone($sChord,0)
    $append=_ChordGetAppendix($sChord)
    $secondTone=Mod($firstTone+$iTones+12,12)
    Return _NumberToLetter($secondTone) & $append
    EndFunc
    Func _ChordGetBasicTone($sChord, $iFlag=0);iFlag: 0=zahl, 1=Buchstabe
    If not _isChord($sChord) Then
    SetError(1);No Chord
    Return
    EndIf
    $matches=StringRegExp($sChord,"^[A-Z](#|b){0,1}",2)
    $sLetter=$matches[0]
    If $iFlag=1 Then Return $sLetter
    Return _LetterToNumber($sLetter)
    EndFunc
    Func _LetterToNumber($sLetter)
    If Not StringRegExp($sLetter,"^[A-Z](#|b){0,1}$",0) Then
    SetError(1);No Letter
    Return
    EndIf
    Switch $sLetter
    Case "C"
    Return 0
    Case "Db","C#"
    Return 1
    Case "D"
    Return 2
    Case "Eb","D#"
    Return 3
    Case "E"
    Return 4
    Case "F"
    Return 5
    Case "Gb","F#"
    Return 6
    Case "G"
    Return 7
    Case "Ab","G#"
    Return 8
    Case "A"
    Return 9
    Case "Bb","A#"
    Return 10
    Case "B"
    Return 11
    EndSwitch
    EndFunc
    Func _NumberToLetter($iNumber)
    If Not isNumber($iNumber) Then
    SetError(1);No Number
    Return
    EndIf
    Switch $iNumber
    Case 0
    Return "C"
    Case 1
    Return "Db"
    Case 2
    Return "D"
    Case 3
    Return "Eb"
    Case 4
    Return "E"
    Case 5
    Return "F"
    Case 6
    Return "Gb"
    Case 7
    Return "G"
    Case 8
    Return "Ab"
    Case 9
    Return "A"
    Case 10
    Return "Bb"
    Case 11
    Return "B"
    EndSwitch
    EndFunc
    Func _ChordGetAppendix($sChord)
    $matches=StringRegExp($sChord,"m{0,1}\d*(/[A-G]){0,1}$",2)
    Return $matches[0]
    EndFunc
    Func _TextTranspose($sText,$iTones)
    $aTmp = StringRegExp($sText,$_REGEXP_CHORD,3)
    For $i=0 To UBound($aTmp)-1
    $tmp=_ChordTranspose($aTmp[$i],$iTones)
    $TempPattern="\b("&$aTmp[$i]&")\b"; Match nur innerhalb der Wortgenze
    $sText=StringRegExpReplace($sText,$TempPattern,$tmp)
    Next
    Return StringReplace($sText,"q@qq","")
    EndFunc

    [/autoit]


    edit: Problem 1 (-1 transponieren) gelöst

    Twitter: @L3viathan2142
    Benutze AutoIt persönlich nicht mehr, da ich keinen Windows-Rechner mehr besitze.

    Einmal editiert, zuletzt von L3viathan2142 (17. Januar 2010 um 14:39)

  • Zum Testen kriegt ihr mal ne Textdatei von ultimate-guitar.com:

    Spoiler anzeigen

    Twitter: @L3viathan2142
    Benutze AutoIt persönlich nicht mehr, da ich keinen Windows-Rechner mehr besitze.

  • Spoiler anzeigen
    [autoit]


    Func _transPLUS()
    $aTmp=_GUICtrlEdit_GetSel($Edit1)
    $read=GUICtrlRead($Edit1)
    If $aTmp[0] = $aTmp[1] Then Return GUICtrlSetData($Edit1,_TextTranspose($read,1))
    $text=StringTrimLeft(StringLeft($read,$aTmp[1]),$aTmp[0])
    $newText=_TextTranspose($text,1)
    $newlen=StringLen($newText)
    GUICtrlSetData($Edit1,StringLeft($read,$aTmp[0]) & $newText & StringTrimLeft($read,$aTmp[1]))
    ;_GUICtrlEdit_ReplaceSel($Edit1, $newtext) //kürzer, und dürfte auch funktionieren
    GUICtrlSetState($Edit1, $GUI_FOCUS)
    _GUICtrlEdit_SetSel($Edit1,$aTmp[0],$aTmp[0]+$newlen);not working - jetzt vieleicht?
    EndFunc

    [/autoit]