Je me suis servi de l'UDF disponible sur le forum US (MidiUdf.au3) J'ai fais quelques modifications pour qu'il puisse fonctionner.
Et j'ai fait une sorte de piano virtuel, pour l'IHM, je me suis inspiré de Virtual Piano (AnalogX).
Il faut voir votre clavier comme un piano en deux parties :
Code : Tout sélectionner
[color=#000000] q s f g j k l [/color] <- Touches Noires
[color=#CCCCCC]< w x c v b n , ; :[/color] <- Touches Blanches
et
[color=#000000] é " ( - è ç à =[/color] <- Touches Noires
[color=#CCCCCC]a z e r t y u i o p ^ $[/color] <- Touches Blanches
Ce qui nous donne un piano :
[color=#000000] q s f g j k l é " ( - è ç à =[/color] <- Touches Noires
[color=#CCCCCC]< w x c v b n , ; : a z e r t y u i o p ^ $[/color] <- Touches Blanches
Remarque : "!" = "a"
Plus que des mots, voici le script :
► Afficher le textePiano
Code : Tout sélectionner
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=piano.ico
#AutoIt3Wrapper_Outfile=Piano numérique.exe
#AutoIt3Wrapper_Outfile_x64=Piano numérique_x64.exe
#AutoIt3Wrapper_Res_Fileversion=1.2.0
#AutoIt3Wrapper_Res_Language=1036
#AutoIt3Wrapper_Add_Constants=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiEdit.au3>
#include <Midiudf.au3>
#include <Misc.au3>
#include <WindowsConstants.au3>
Opt("MustDeclareVars", 1)
Opt("GUIOnEventMode", 1)
Global $version = "1.2.0"
Global $gui
Global $fichier
Global $option
Global $input[2]
Global $combo
Global $slider
Global $label[4]
Global $bouton
Global $activEdit
Global $edit[2]
Global $accelerator[7][2]
Global $afficherTemps[2]
Global $afficherRelachesTouches[2]
Global $toujoursAfficher[2]
Global $chargerPartition
Global $sauvegarderPartition
Global $jouerPartition
Global $numPart
Global $ajoutTexte
Global $instrumentList = [ "Grand Piano", "Bright Piano", "Electric Grand Piano", "Honky-Tonk Piano", "Electric piano 1", "Electric Piano 2", "Harpsichord", _
"Clavinet", "Celesta", "Glockenspiel", "Music Box", "Vibraphone", "Marimba", "Xylophone", "Tubular bells", "Dulcimer", _
"Drawbar Organ", "Percussive Organ", "Rock Organ", "Church Organ", "Reed Organ", "Accordion", "Harmonica", "Tango Accordion", _
"Nylon String Guitar", "Steel String Guitar", "Jazz Guitar", "Clean Electric Guitar", "Muted Electric Guitar", _
"Overdrive Guitar", "Distortion Guitar", "Guitar Harmonics", "Accoustic Bass", "Fingered Bass", "Picked Bass", _
"Fretless Bass", "Slap Bass 1", "Slap Bass 2", "Synth Bass 1", "Synth Bass 2", "Violin", "Viola", "Cello", "Contrabass", _
"Tremolo Strings", "Pizzicato Strings", "Orchestral Harp", "Timpani", "String Ensemble 1", "String Ensemble 2", _
"Synth Strings 1", "Synth Strings 2", "Choir ahh", "Choir oohh", "Synth Voice", "Orchestral Hit", "Trumpet", "Trombone", _
"Tuba", "Muted Trumpet", "French Horn", "Brass Section", "Synth Brass 1", "Synth Brass 2", "Soprano Sax", "Alto Sax", _
"Tenor Sax", "Baritone Sax", "Oboe", "English Horn", "Bassoon", "Clarinet", "Piccolo", "Flute", "Recorder", "Pan flute", _
"Blown Bottle", "Shakuhachi", "Whistle", "Ocarina", "Square Wave", "Sawtooth Wave", "Caliope", "Chiff", "Charang", "Voice", _
"Fifths", "Bass & Lead", "New Age", "Warm", "PolySynth", "Choir", "Bowed", "Metallic", "Halo", "Sweep", "FX: Rain", _
"FX: Soundtrack", "FX: Crystal", "FX: Atmosphere", "FX: Brightness", "FX: Goblins", "FX: Echo Drops", "FX: Star Theme", _
"Sitar", "Banjo", "Shamisen", "Koto", "Kalimba", "Bagpipe", "Fiddle", "Shanai", "Tinkle bell", "Agogo", "Steel Drums", _
"Woodblock", "Taiko Drum", "Melodic Tom", "Synth Drum", "Reverse Cymbal", "Guitar Fret Noise", "Breath Noise", "Seashore", _
"Bird Tweet", "Telephone Ring", "Helicopter", "Applause", "Gunshot"]
Global $canPlay = False
Global $partition[1][3]
Global $instrument[2] = [0, 0]
Global $volume[2] = [255, 255]
Global $vitesse[2] = [1, 1]
Global $gamme = 1
Global $base = 14
Global $LA = 0x0000
Global $LAD = 0x0100
Global $SI = 0x0200
Global $DO = 0x0300
Global $DOD = 0x0400
Global $RE = 0x0500
Global $RED = 0x0600
Global $MI = 0x0700
Global $FA = 0x0800
Global $FAD = 0x0900
Global $SOL = 0x0A00
Global $SOLD = 0x0B00
Global $midi
Global $temps = -1
Global $touches[38][5] = [["<", "E2", $SOL, 0, True], _
["q", "51", $SOLD, 1, True], _
["w", "57", $LA, 1, True], _
["s", "53", $LAD, 1, True], _
["x", "58", $SI, 1, True], _
["c", "43", $DO, 1, True], _
["f", "46", $DOD, 1, True], _
["v", "56", $RE, 1, True], _
["g", "47", $RED, 1, True], _
["b", "42", $MI, 1, True], _
["n", "4E", $FA, 1, True], _
["j", "4A", $FAD, 1, True], _
[",", "BC", $SOL, 1, True], _
["k", "4B", $SOLD, 1, True], _
[";", "BE", $LA, 2, True], _
["l", "4C", $LAD, 2, True], _
[":", "BF", $SI, 2, True], _
["!", "DF", $DO, 2, True], _
["a", "41", $DO, 2, True], _
["é", "32", $DOD, 2, True], _
["z", "5A", $RE, 2, True], _
['"', "33", $RED, 2, True], _
["e", "45", $MI, 2, True], _
["r", "52", $FA, 2, True], _
["(", "35", $FAD, 2, True], _
["t", "54", $SOL, 2, True], _
["-", "36", $SOLD, 2, True], _
["y", "59", $LA, 3, True], _
["è", "37", $LAD, 3, True], _
["u", "55", $SI, 3, True], _
["i", "49", $DO, 3, True], _
["ç", "39", $DOD, 3, True], _
["o", "4F", $RE, 3, True], _
["à", "30", $RED, 3, True], _
["p", "50", $MI, 3, True], _
["^", "DD", $FA, 3, True], _
["=", "BB", $FAD, 3, True], _
["$", "BA", $SOL, 3, True]]
$gui = GUICreate("Virtual Piano", 440, 165)
$fichier = GUICtrlCreateMenu("&Fichier")
$chargerPartition = GUICtrlCreateMenuItem("Charger partition..." & @TAB & "Ctrl+O", $fichier)
$sauvegarderPartition = GUICtrlCreateMenuItem("Sauvegarder partition..." & @TAB & "Ctrl+S", $fichier)
GUICtrlCreateMenuItem("", $fichier)
$jouerPartition = GUICtrlCreateMenuItem("Jouer partition" & @TAB & "Ctrl+P", $fichier)
$option = GUICtrlCreateMenu("&Options")
$afficherTemps[0] = GUICtrlCreateMenuItem("Afficher les temps" & @TAB & "Ctrl+T", $option)
$afficherRelachesTouches[0] = GUICtrlCreateMenuItem("Afficher les relâchements de touche" & @TAB & "Ctrl+R", $option)
$toujoursAfficher[0] = GUICtrlCreateMenuItem("Toujours afficher" & @TAB & "Ctrl+A", $option)
$afficherTemps[1] = False
$afficherRelachesTouches[1] = False
GUICtrlCreateLabel("", 5, 5, 257, 135, 0x00000007, 0x00000004)
GUICtrlSetState(-1, $GUI_DISABLE)
$activEdit = GUICtrlCreateButton("", -10, -10, 1, 1)
GUICtrlSetState(-1, $GUI_DISABLE)
$input[0] = GUICtrlCreateInput("1", 10, 15, 150, 20, $ES_NUMBER)
GUICtrlCreateUpdown($input[0])
$label[0] = GUICtrlCreateLabel("Chanel (1-16)", 170, 20, 70, 20)
$slider = GUICtrlCreateSlider(6, 38, 160, 25)
GUICtrlSetLimit($slider, 255)
GUICtrlSetData($slider, 255)
$Label[1] = GUICtrlCreateLabel("Volume", 170, 45, 50, 20)
$combo = GUICtrlCreateCombo("", 10, 65, 150, 20, BitOR($CBS_DROPDOWNLIST, $WS_VSCROLL))
GUICtrlSetData(-1, GetInstruments(), $instrumentList[0])
$label[2] = GUICtrlCreateLabel("Instrument (0-127)", 170, 70, 90, 20)
$input[1] = GUICtrlCreateInput($vitesse[0], 10, 90, 150, 20)
$label[3] = GUICtrlCreateLabel("Acceleration", 170, 92, 90, 20)
$bouton = GUICtrlCreateButton("Jouer", 10, 115, 150, 20)
$edit[0] = GUICtrlCreateEdit("", 270, 5, 160, 135, BitOR($ES_AUTOVSCROLL, $WS_VSCROLL))
$edit[1] = GUICtrlCreateEdit("", -100, 0, 95, 135, $ES_AUTOVSCROLL)
GUISetOnEvent($GUI_EVENT_CLOSE, "quit")
GUICtrlSetState($input[0], $GUI_DISABLE)
GUICtrlSetState($label[0], $GUI_DISABLE)
GUICtrlSetState($edit[1], $GUI_FOCUS)
GUICtrlSetOnEvent($chargerPartition, "ChargerPartition")
GUICtrlSetOnEvent($sauvegarderPartition, "SauvegarderPartition")
GUICtrlSetOnEvent($bouton, "JouerPartition")
GUICtrlSetOnEvent($jouerPartition, "JouerPartition")
GUICtrlSetOnEvent($afficherTemps[0], "AfficherTemps")
GUICtrlSetOnEvent($afficherRelachesTouches[0], "AfficherRelachesTouches")
GUICtrlSetOnEvent($toujoursAfficher[0], "ToujoursAfficher")
GUICtrlSetOnEvent($activEdit, "ActivEdit")
$accelerator[0][0] = "{ESC}"
$accelerator[1][0] = "^o"
$accelerator[2][0] = "^s"
$accelerator[3][0] = "^p"
$accelerator[4][0] = "^t"
$accelerator[5][0] = "^r"
$accelerator[6][0] = "^a"
$accelerator[0][1] = $activEdit
$accelerator[1][1] = $chargerPartition
$accelerator[2][1] = $sauvegarderPartition
$accelerator[3][1] = $jouerPartition
$accelerator[4][1] = $afficherTemps[0]
$accelerator[5][1] = $afficherRelachesTouches[0]
$accelerator[6][1] = $toujoursAfficher[0]
GUISetAccelerators($accelerator, $gui)
GUISetState()
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
$midi = _MidiOutOpen()
_MidiOutSetInstrument($midi, $instrument[0])
SetVolume($volume[0])
If($cmdLine[0] = 1) Then
Local $fichier = $cmdLine[1]
If(FileExists($fichier)) Then
ChargerFichier($fichier)
EndIf
EndIf
While(True)
If(WinGetHandle("[ACTIVE]") = $gui) Then
If($canPlay) Then
For $i = 0 To UBound($touches, 1)-1
If(Not(_IsPressed("11"))) Then
If(_IsPressed($touches[$i][1])) Then
If($touches[$i][4]) Then
$touches[$i][4] = False
Play($touches[$i][2], $touches[$i][3])
AjouterTexte(True)
EndIf
Else
If(Not($touches[$i][4])) Then
$touches[$i][4] = True
Stop($touches[$i][2], $touches[$i][3])
AjouterTexte(False)
EndIf
EndIf
EndIf
Next
EndIf
For $i = 70 To 78
If(_IsPressed("" & $i & "")) Then
$gamme = $i-70-2
EndIf
Next
EndIf
Sleep(10)
WEnd
Func ChargerPartition()
Local $fichier = FileOpenDialog("Sélectionner une partition", @ScriptDir, "Partitions (*.*)", 1)
If(Not(@error)) Then
ChargerFichier($fichier)
EndIf
EndFunc
Func ChargerFichier($fichier)
Local $err = False
Local $contenu = FileRead($fichier)
$contenu = StringSplit($contenu, @CRLF, 3)
If($contenu[UBound($contenu, 1)-1] <> "") Then
ReDim $contenu[UBound($contenu, 1)+1]
EndIf
Local $partitionTemp[UBound($contenu, 1)][UBound($partition, 2)]
Local $var
For $i = 0 To UBound($contenu, 1)-2
$var = StringSplit($contenu[$i], "|", 3)
If(UBound($var, 1) <> UBound($partition, 2)) Then
MsgBox(16, "Erreur", "Fichier corrompu.")
$err = True
ExitLoop
EndIf
$partitionTemp[$i][0] = $var[0]
$partitionTemp[$i][1] = $var[1]
If($var[2] = "True") Then
$partitionTemp[$i][2] = True
Else
$partitionTemp[$i][2] = False
EndIf
Next
If(Not($err)) Then
$partition = $partitionTemp
Reload()
EndIf
EndFunc
Func SauvegarderPartition()
Local $fichier = FileSaveDialog("Sélectionner une partition", @ScriptDir, "Partitions (*.*)", 16)
If(Not(@error)) Then
Local $save = ""
For $i = 0 To UBound($partition, 1)-2
$save &= $partition[$i][0] & "|" & $partition[$i][1] & "|" & $partition[$i][2] & @CRLF
Next
Local $file = FileOpen($fichier, 2)
FileWrite($file, $save)
FileClose($file)
EndIf
EndFunc
Func JouerPartition()
For $i = 0 To UBound($partition, 1)-2
Local $code = GetCodeTouche($partition[$i][0])
If($code <> 0) Then
If($partition[$i][2]) Then
Play($touches[$code][2], $touches[$code][3])
Else
Stop($touches[$code][2], $touches[$code][3])
EndIf
EndIf
Local $sleep = Ceiling($partition[$i][1] / GUICtrlRead($input[1]))
If($sleep <= 0) Then
$sleep = 1
EndIf
Sleep($sleep)
Next
EndFunc
Func AfficherTemps()
$afficherTemps[1] = Not $afficherTemps[1]
If($afficherTemps[1]) Then
GUICtrlSetState($afficherTemps[0], $GUI_CHECKED)
Else
GUICtrlSetState($afficherTemps[0], $GUI_UNCHECKED)
EndIf
Reload()
EndFunc
Func AfficherRelachesTouches()
$afficherRelachesTouches[1] = Not $afficherRelachesTouches[1]
If($afficherRelachesTouches[1]) Then
GUICtrlSetState($afficherRelachesTouches[0], $GUI_CHECKED)
Else
GUICtrlSetState($afficherRelachesTouches[0], $GUI_UNCHECKED)
EndIf
Reload()
EndFunc
Func ToujoursAfficher()
$toujoursAfficher[1] = Not $toujoursAfficher[1]
If($toujoursAfficher[1]) Then
GUICtrlSetState($toujoursAfficher[0], $GUI_CHECKED)
WinSetOnTop($gui, "", 1)
Else
GUICtrlSetState($toujoursAfficher[0], $GUI_UNCHECKED)
WinSetOnTop($gui, "", 0)
EndIf
EndFunc
Func AjouterTexte($play)
$numPart = UBound($partition, 1)-1
$ajoutTexte = ""
$partition[$numPart][0] = $touches[$i][0]
$partition[$numPart][2] = $play
If($temps <> -1) Then
$partition[$numPart-1][1] = Round(TimerDiff($temps))
If($afficherTemps[1]) Then
$ajoutTexte &= "[" & $partition[$numPart-1][1] & "]"
EndIf
EndIf
$temps = TimerInit()
If($partition[$numPart][2]) Then
$ajoutTexte &= $partition[$numPart][0]
ElseIf($afficherRelachesTouches[1]) Then
$ajoutTexte &= "{" & $partition[$numPart][0] & "}"
EndIf
_GUICtrlEdit_AppendText(GUICtrlGetHandle($edit[0]), $ajoutTexte)
ReDim $partition[UBound($partition, 1)+1][UBound($partition, 2)]
EndFunc
Func Reload()
Local $texte = GetPartition($afficherTemps[1], $afficherRelachesTouches[1])
_GUICtrlEdit_SetText(GUICtrlGetHandle($edit[0]), $texte)
EndFunc
Func GetPartition($temps, $relachesTouches)
Local $texte = ""
For $i = 0 To UBound($partition, 1)-2
If($i > 0 And $temps) Then
$texte &= "[" & $partition[$i-1][1] & "]"
EndIf
If($partition[$i][2]) Then
$texte &= $partition[$i][0]
ElseIf($relachesTouches) Then
$texte &= "{" & $partition[$i][0] & "}"
EndIf
Next
Return $texte
EndFunc
Func WM_COMMAND($hWnd, $iMsg, $lParam, $wParam)
$canPlay = False
Switch($hWnd)
Case $gui
Switch($wParam)
Case GUICtrlGetHandle($edit[0])
If(BitShift($lParam, 16) = 0x0100) Then
GUICtrlSetState($edit[1], $GUI_FOCUS)
EndIf
ContinueCase
Case GUICtrlGetHandle($edit[1])
$canPlay = True
Case GUICtrlGetHandle($input[1])
Local $vit = GUICtrlRead($input[1])
Local $final = ""
Local $err = False
For $i = 1 To StringLen($vit)
Local $mid = StringMid($vit, $i, 1)
If(Asc($mid) >= Asc("0") And Asc($mid) <= Asc("9") Or Asc($mid) = Asc(".")) Then
$final &= $mid
Else
$err = True
EndIf
Next
If($err) Then
GUICtrlSetData($input[1], $final)
EndIf
EndSwitch
EndSwitch
EndFunc
Func Play($note, $ajoutGamme = 0)
$note = "0x" & Hex($note)
Local $base = "0x" & Hex(0x00400990)
Local $gammePlayed = $gamme+$ajoutGamme
Local $ajoutGame = "0x" & Hex($gammePlayed*0x0C00)
$volume[0] = GUICtrlRead($slider)
If($volume[0] <> $volume[1]) Then
$volume[1] = $volume[0]
SetVolume($volume[0])
EndIf
$instrument[0] = _InstrumentToNumber(GUICtrlRead($combo))
If($instrument[0] <> $instrument[1]) Then
$instrument[1] = $instrument[0]
_MidiOutSetInstrument($midi, $instrument[1])
EndIf
Local $msg = "0x" & Hex(Number($base) + Number($note) + Number($ajoutGame))
_MidiOutShortMsg($midi, $msg)
EndFunc
Func SetVolume($volume)
Local $vol = TransformIntToVol($volume)
_MidiOutSetVolume($vol)
EndFunc
Func TransformIntToVol($volume)
Local $vol[2]
$vol[0] = "0x" & Hex(BitShift($volume, -8), 4)
$vol[1] = "0x" & Hex(BitShift($volume, -24), 8)
Local $newVol = "0x" & Hex(BitOR($vol[0], $vol[1]), 8)
Return $newVol
EndFunc
Func Stop($note, $ajoutGamme = 0)
$note = "0x" & Hex($note)
Local $base = "0x" & Hex(0x00000990)
Local $gammePlayed = $gamme+$ajoutGamme
Local $ajoutGame = "0x" & Hex($gammePlayed*0x0C00)
Local $msg = "0x" & Hex(Number($base) + Number($note) + Number($ajoutGame))
_MidiOutShortMsg($midi, $msg)
EndFunc
Func ActivEdit()
ReDim $partition[1][UBound($partition, 2)]
For $i = 0 To UBound($partition, 2)-1
$partition[0][$i] = ""
Next
$temps = -1
GUICtrlSetData($edit[0], "")
GUICtrlSetState($edit[1], $GUI_FOCUS)
EndFunc
Func GetCodeTouche($touche)
Local $code = -1
For $i = 0 To UBound($touches, 1)-1
If($touches[$i][0] = $touche) Then
$code = $i
ExitLoop
EndIf
Next
Return $code
EndFunc
Func _IsChecked($ctrl)
Return BitAND(GUICtrlRead($ctrl), $GUI_CHECKED) = $GUI_CHECKED
EndFunc
Func quit()
Exit
EndFunc
Func _InstrumentToNumber($instr_sel)
Local $instr = -1
For $i = 0 To UBound($instrumentList, 1)-1
If($instrumentList[$i] = $instr_sel) Then
$instr = $i
ExitLoop
EndIf
Next
Return $instr
EndFunc
Func GetInstruments()
Local $retour = ""
For $i = 0 To UBound($instrumentList, 1)-1
$retour &= $instrumentList[$i] & "|"
Next
$retour = StringTrimRight($retour, 1)
Return $retour
EndFunc
Code : Tout sélectionner
erti zer tyu^ yuiop erti op^ ttp otp otp ot^ poi
Code : Tout sélectionner
e :az a:; ;ae za: :az ea;; z ry tre ae za: :az ea;;
- Prise en compte des changements de theAvenger
- Correction du bug concernant le manque de son suite à une mise à jour AutoIt (un piano sans son c'est dommage)
- Suppression de _ArrayCreate()
MAJ : 1.1.0
- Sauvegarder des morceaux
- Chargement des morceaux
- Visualisation des temps d'appui
- Visualisation des relâchements de touches
- Jouer un morceau
Edit : Suite à un bug, je ne peux pas mettre la coloration syntaxique sous peine d'avoir un message vide. Si un modo / admin passe par là et veux s'y essayer : Welcome !
- Midiudf.au3
- (32.08 Kio) Téléchargé 359 fois