Voici un clavier midi tout simple. Merci à (je ne sais plus qui) qui avait posté des fonctions pour faire une boucle MIDI :
Code : Tout sélectionner
Global m_hMidiOut,m_MIDIOpen.b, channel
; ********************** Procedures ****************************************
Procedure SendMIDIMessage(nStatus.l,nCanal.l,nData1.l,nData2.l)
dwFlags.l = nStatus | nCanal | (nData1 << 8) | (nData2 << 16)
temp.l = midiOutShortMsg_(m_hMidiOut,dwFlags);
If temp<>0
MessageRequester("Problème", "Erreur dans l'envoi du message MIDI",0)
EndIf
EndProcedure
Procedure MIDIOpen()
If m_MIDIOpen = 0
If midiOutOpen_(@m_hMidiOut,MIDIMAPPER,0,0,0) <> 0
MessageRequester("Problème", "Impossible d'ouvrir le périphérique MIDI",0)
Else
SendMIDIMessage($C0,0,0,0)
m_MIDIOpen = 1
EndIf
EndIf
EndProcedure
Procedure PlayNoteMIDI(Canal.b,Note.b,VelociteDown.b,VelociteUp.b)
If m_MIDIOpen
low=(Note*256)+Canal+143
velocity=127
hi=velocity*256*256
dwFlags = low+hi
midiOutShortMsg_(m_hMidiOut,dwFlags);
;SendMIDIMessage($80 | Canal,channel,Note,VelociteDown)
;SendMIDIMessage($90 | Canal,channel,Note,VelociteUp)
EndIf
EndProcedure
Procedure StopNoteMIDI(Canal.b,Note.b)
If m_MIDIOpen
event=Canal+143
low=(Note*256)+event
hiZero=0
dwMsg=low+hiZero
midiOutShortMsg_(m_hMidiOut,dwMsg);
;SendMIDIMessage($80 | Canal,channel,Note,VelociteDown)
;SendMIDIMessage($90 | Canal,channel,Note,VelociteUp)
EndIf
EndProcedure
Procedure ChargeInstrument(Canal.b,Instrument.b)
If m_MIDIOpen
SendMIDIMessage($C0 | Canal,0,Instrument,0)
EndIf
EndProcedure
OpenWindow(0, 0, 0, 300, 20, "Keyboard")
ComboBoxGadget(0, 0, 0, 200, 20)
SpinGadget(1, 200, 0, 100, 20, 0, 6, #PB_Spin_Numeric|#PB_Spin_ReadOnly)
Dim keystate(256)
Dim key(256)
keystate(87) = 48 ;c
keystate(83) = 49 ;cs
keystate(88) = 50 ;d
keystate(68) = 51 ;ds
keystate(67) = 52 ;e
keystate(86) = 53 ;f
keystate(71) = 54 ;fs
keystate(66) = 55 ;g
keystate(72) = 56 ;gs
keystate(78) = 57 ;a
keystate(74) = 58 ;as
keystate(188) = 59 ;b
keystate(190) = 60 ;c
keystate(65) = 60 ;c
keystate(76) = 61 ;cs
keystate(50) = 61 ;cs
keystate(191) = 62 ;
keystate(90) = 62 ;
keystate(77) = 63 ;
keystate(51) = 63 ;
keystate(223) = 64 ;
keystate(69) = 64 ;
keystate(192) = 65 ;
keystate(82) = 65 ;
keystate(220) = 66 ;
keystate(53) = 66
keystate(84) = 67
keystate(54) = 68
keystate(89) = 69
keystate(55) = 70
keystate(85) = 71
keystate(73) = 72
keystate(57) = 73
keystate(79) = 74
keystate(48) = 75
keystate(80) = 76
keystate(221) = 77
keystate(187) = 78
keystate(186) = 79
For i = 0 To 127
Read.s instrument.s
AddGadgetItem(0, i, Str(i) + instrument)
Next
MIDIOpen()
ChargeInstrument(1,1)
channel = 1
Repeat
If WindowEvent() = #PB_Event_Gadget
If EventGadget() = 0
If GetGadgetState(0) < 127
ChargeInstrument(0,GetGadgetState(0)+1)
channel = 1
Else
ChargeInstrument(10,128)
channel = 10
EndIf
EndIf
EndIf
For i = 48 To 255
If GetAsyncKeyState_(i) And keystate(i)
If Not key(i)
PlayNoteMIDI(channel, keystate(i)+(Val(GetGadgetText(1))-3)*12, 127, 127)
key(i) = 1
EndIf
Else
If key(i)
key(i) = 0
StopNoteMIDI(channel, keystate(i)+(Val(GetGadgetText(1))-3)*12)
EndIf
EndIf
Next
Until 0
DataSection
Data.s "Grand Piano","Bright Grand","Honky Tonk"
Data.s "Rhodes","Chorus Piano","Harpsichord","Clavinet"
Data.s "Celesta","Glockenspiel","Music Box","Vibraphone"
Data.s "Marimba","Xylophone","Tubular Bells","Dulcimer"
Data.s "Hammond Organ","Percussion Organ","Rock Organ"
Data.s "Church Organ","Reed Organ","Accordian","Harmonica"
Data.s "Tango Accordian","Accoustic Nylon Guitar"
Data.s "Accoustic Steel Guitar","Electric Jazz Guitar"
Data.s "Electric Clean Guitar","Electric Mute Guitar"
Data.s "Overdrive Guitar","Distorted Guitar","Guitar Harmonic"
Data.s "Accoustic Bass","Electric Bass Finger","Electric Bass Pick"
Data.s "Fretless Bass","Slap Bass One","Slap Bass Two"
Data.s "Synth Bass One","Synth Bass Two","Violin","Viola","Cello"
Data.s "Contrabass","Tremolo Strings","Pizzicato Strings"
Data.s "Orchestra Harp","Timpani","String Ensemble One"
Data.s "String Ensemble Two","Synth Strings One","Synth Strings Two"
Data.s "Choir Ahhs","Voice Oohs","Synth Voice","Orchestra Hit"
Data.s "Trumpet","Trombone","Tuba","Mute Trumpet","French Horn"
Data.s "Brass Section","Synth Brass One","Synth Brass Two"
Data.s "Soprano Sax","Alto Sax","Tenor Sax","Bari Sax","Oboe"
Data.s "English Horn","Bassoon","Clarinet","Piccolo","Flute"
Data.s "Recorder","Pan Flute","Bottle Blow","Shakuhachi","Whistle"
Data.s "Ocarina","Square Wave","Sawtooth","Caliope","Chiff Lead"
Data.s "Charang","Solo Synth VX","Brite Saw","Brass and Lead"
Data.s "Fantasia Pad","Warm Pad","Poly Synth Pad","Space Vox Pad"
Data.s "Bowd Glas Pad","Metal Pad","Halo Pad","Sweep Pad"
Data.s "Ice Rain","Sound Track","Crystal","Atmosphere","Brightness"
Data.s "Goblin","Echo Drops","Star Theme","Sitar","Banjo","Shamisen"
Data.s "Koto","Kalimba","Bagpipe","Fiddle","Shanai"
Data.s "Tinkle Bell","Agogo","Steel Drums","Wood Block","Taiko Drum"
Data.s "Melodic Tom","Synth Drum","Rev Cymbal"
Data.s "Guitar Fret Noise","Breath Noise","Sea Shore","Bird Tweet"
Data.s "Phone Ring","Helicopter","Applause","Gunshot","Drum Kit"
EndDataSection
W = Do
X = Ré
C = Mi ...
V
B
N
,
; ou A = Do
: ou Z = Ré ...
! ou E
ù ou R
S = Do# ou Réb
D = Mib ou Ré#
G = Fa# ou Solb...
H
J
L = Do# ou Réb
M = Mib ou Ré#
* = Fa# ou Solb
AZERTYUIOP^$ = Do, Ré, Mi... Si, Do, Ré... Sol
é" = Do#, Mib
(-è = Fa#, Sol#Sib
çà= = Do#, Mib, Fa#
En gros, vous utilisez votre clavier d'ordinateur comme un piano. Le pavé numérique n'est pas utilisé.
Voilà !
