je suis allée a la peche !!
j'ai trouvé de quoi satisfaire ton apetit du MiDI
voici recuperé sur codearchive une petite librairie complete de la gestion du midi
Code : Tout sélectionner
; German forum: http://robsite.de/php/pureboard/viewtopic.php?t=2786&highlight=
; Author: GPI
; Date: 09. November 2003
;info:Play Midis direct (with mci)
Procedure GetMidiLength(Nb)
a$=Space(#MAX_PATH)
i=mciSendString_("status mid"+Str(Nb)+" length",@a$,#MAX_PATH,0)
ProcedureReturn Val(a$)
EndProcedure
Procedure SetMidiTimeFormatToMS(Nb)
ProcedureReturn mciSendString_("set mid"+Str(Nb)+" time format milliseconds",0,0,0)
EndProcedure
Procedure SetMidiTimeFormatToTick(Nb)
ProcedureReturn mciSendString_("set mid"+Str(Nb)+" time format song pointer",0,0,0)
EndProcedure
Procedure LoadMidi(Nb,file.s)
;i=mciSendString_("open Sequencer!"+Chr(34)+file+Chr(34)+" alias mid"+Str(Nb),0,0,0)
i=mciSendString_("OPEN "+Chr(34)+file+Chr(34)+" Type SEQUENCER ALIAS mid"+Str(Nb),0,0,0)
If i=0
ProcedureReturn #True
Else
ProcedureReturn #False
EndIf
EndProcedure
Procedure PlayMidi(Nb)
i=mciSendString_("play mid"+Str(Nb)+" from "+Str(0),0,0,0)
ProcedureReturn i
EndProcedure
Procedure PlayMidiFrom(Nb,Start,endPos)
i=mciSendString_("play mid"+Str(Nb)+" from "+Str(Start)+" to "+Str(endPos),0,0,0)
ProcedureReturn i
EndProcedure
Procedure PauseMidi(Nb)
i=mciSendString_("pause mid"+Str(Nb),0,0,0)
ProcedureReturn i
EndProcedure
Procedure ResumeMidi(Nb)
i=mciSendString_("resume mid"+Str(Nb),0,0,0)
ProcedureReturn i
EndProcedure
Procedure StopMidi(Nb)
i=mciSendString_("stop mid"+Str(Nb),0,0,0)
ProcedureReturn i
EndProcedure
Procedure FreeMidi(Nb)
i=mciSendString_("close mid"+Str(Nb),0,0,0)
ProcedureReturn i
EndProcedure
Procedure SetMidiTempo(Nb,Tempo)
i=mciSendString_("set mid"+Str(Nb)+" tempo "+Str(Tempo),0,0,0)
ProcedureReturn i
EndProcedure
Procedure GetMidiPosition(Nb)
a$=Space(#MAX_PATH)
i=mciSendString_("status mid"+Str(Nb)+" position",@a$,#MAX_PATH,0)
ProcedureReturn Val(a$)
EndProcedure
Procedure GetMidiTempo(Nb)
a$=Space(#MAX_PATH)
i=mciSendString_("status mid"+Str(Nb)+" Tempo",@a$,#MAX_PATH,0)
ProcedureReturn Val(a$)
EndProcedure
Procedure IsMidiPlaying(Nb)
a$=Space(#MAX_PATH)
i=mciSendString_("status mid"+Str(Nb)+" mode",@a$,#MAX_PATH,0)
If a$="playing"
ProcedureReturn #True
Else
ProcedureReturn #False
EndIf
EndProcedure
Procedure IsMidiPaused(Nb)
a$=Space(#MAX_PATH)
i=mciSendString_("status mid"+Str(Nb)+" mode",@a$,#MAX_PATH,0)
If a$="paused"
ProcedureReturn #True
Else
ProcedureReturn #False
EndIf
EndProcedure
Procedure IsMidiReady(Nb)
a$=Space(#MAX_PATH)
i=mciSendString_("status mid"+Str(Nb)+" mode",@a$,#MAX_PATH,0)
Debug a$
If a$="not ready"
ProcedureReturn #False
Else
ProcedureReturn #True
EndIf
EndProcedure
;- Example
; OpenWindow(1,0,200,10,10,#PB_Window_SystemMenu,"Midi-Test")
;
; LoadMidi(1,"D:\download\vgmusic.com\music\dreamcast\sa_dc_06.mid")
; Debug GetMidiLength(1)
; SetMidiTimeFormatToMS(1)
; Debug GetMidiLength(1)
;
; PlayMidi(1)
;
; old=-1
; Repeat
; If IsMidiPlaying(1)
; event=WindowEvent()
; x=GetMidiPosition(1)/100
; If old<>x
; Debug "+"+Str(x)
; old=x
; EndIf
; Else
; event=WaitWindowEvent()
; EndIf
; Until event=#PB_Event_CloseWindow
; StopMidi(1)
; FreeMidi(1)
;
; ExecutableFormat=Windows
; EOF
puis il y a ça aussi !
Code : Tout sélectionner
; English forum: http://purebasic.myforums.net/viewtopic.php?t=8107&highlight=
; Author: Cor
; Date: 29. October 2003
Global hMidiOut
#Acoustic_Steel_Guitar = 25
#Channel1 = 1
#Channel2 = 2
#Channel3 = 3
#Channel4 = 4
#Channel5 = 5
#Channel6 = 6
Procedure MidiOutMessage(hMidi,iStatus,iChannel,iData1,iData2)
dwMessage = iStatus | iChannel | (iData1 << 8 ) | (iData2 << 16)
ProcedureReturn midiOutShortMsg_(hMidi, dwMessage) ;
EndProcedure
Procedure SetInstrument(channel,instrument)
MidiOutMessage(hMidiOut, $C0, channel, instrument, 0)
EndProcedure
Procedure PlayNote(channel,Note,velocity)
MidiOutMessage(hMidiOut, $90, channel, Note , velocity)
EndProcedure
Procedure StopNote(channel,Note)
MidiOutMessage(hMidiOut, $90, channel, Note , 0)
EndProcedure
midi.MIDIOUTCAPS
devices = midiOutGetNumDevs_()
For devnum=-1 To devices-1
If midiOutGetDevCaps_(devnum,@midi,SizeOf(MIDIOUTCAPS))=0
If midi\wVoices >0
midiport=devnum
EndIf
EndIf
Next
*hMidiOut.l
If midiOutOpen_(@hMidiOut,midiport,0,0,0) = #MMSYSERR_NOERROR
; set acoustic steel guitar as instrument
SetInstrument(#Channel1,#Acoustic_Steel_Guitar)
SetInstrument(#Channel2,#Acoustic_Steel_Guitar)
SetInstrument(#Channel3,#Acoustic_Steel_Guitar)
SetInstrument(#Channel4,#Acoustic_Steel_Guitar)
For cnt = 1 To 5
; normal sound
PlayNote(#Channel1,$2D,63)
PlayNote(#Channel2,$39,63)
PlayNote(#Channel3,$3C,63)
PlayNote(#Channel4,$40,63)
Delay (2000)
StopNote(#Channel1,$2D)
StopNote(#Channel2,$39)
StopNote(#Channel3,$3C)
StopNote(#Channel3,$40)
; this must be a staccato sound
PlayNote(#Channel1,$39,100)
PlayNote(#Channel2,$3C,100)
PlayNote(#Channel3,$40,100)
Delay (300)
StopNote(#Channel1,$39)
StopNote(#Channel2,$3C)
StopNote(#Channel3,$40)
Delay (200)
; this must be a muted sound
PlayNote(#Channel1,$2D,80)
PlayNote(#Channel2,$30,80)
PlayNote(#Channel3,$34,80)
Delay (300)
StopNote(#Channel1,$2D)
StopNote(#Channel2,$30)
StopNote(#Channel3,$34 )
Delay (285)
Next
; end: reset instruments to 0 (default)
SetInstrument(#Channel1,0)
SetInstrument(#Channel2,0)
SetInstrument(#Channel3,0)
SetInstrument(#Channel4,0)
; end: close MIDI output
midiOutClose_(hMidiOut)
EndIf
End
; ExecutableFormat=Windows
; EOF