nein.
wie sie u.a. in Danilos PureMIDI verwendet werden, zu begreifen.
um mit möglichst wenig befehlscode der Soundkarte MIDI-Sounds zu entlocken.
vornehmlich für soundeffekte, und nicht um Musik auszugeben.
in PureMIDI ist schon ziemlich viel drin.
In der MIDI-Include von ts wahrscheinlich auch, muss ich halt mal rein schaun.
Code: Alles auswählen
;:------------------------:;
; ;
; PureBasic include file ;
; for using WinAPI MIDI ;
; ;
; by Danilo, 26.12.2002 ;
; ;
;:------------------------:;
; Thanks: ;
; Paul, for his small ;
; MIDI examples ;
;:------------------------:;
;
;- 16 MIDI Channels
; ----------------
#Channel1 = 0 : #Channel2 = 1 : #Channel3 = 2 : #Channel4 = 3
#Channel5 = 4 : #Channel6 = 5 : #Channel7 = 6 : #Channel8 = 7
#Channel9 = 8 : #Channel10 = 9 : #Channel11 = 10 : #Channel12 = 11
#Channel13 = 12 : #Channel14 = 13 : #Channel15 = 14 : #Channel16 = 15
;
;- Instruments
; -----------
; Piano : Chromatic Percussion : Organ
; -------------------------------------------------------------------------------------------
#Acoustic_grand_piano = 0 : #Celesta = 8 : #Hammond_organ = 16
#Bright_acoustic_piano = 1 : #Glockenspiel = 9 : #Percussive_organ = 17
#Electric_grand_piano = 2 : #Music_box = 10 : #Rock_organ = 18
#Honky_tonk_piano = 3 : #Vibraphone = 11 : #Church_organ = 19
#Rhodes_piano = 4 : #Marimba = 12 : #Reed_organ = 20
#Chorused_piano = 5 : #Xylophone = 13 : #Accordion = 21
#Harpsichord = 6 : #Tubular_bells = 14 : #Harmonica = 22
#Clavinet = 7 : #Dulcimer = 15 : #Tango_accordion = 23
; : :
; Guitar : Bass : Strings
; -------------------------------------------------------------------------------------------
#Acoustic_guitar_nylon = 24 : #Acoustic_bass = 32 : #Violin = 40
#Acoustic_guitar_steel = 25 : #Electric_bass_finger = 33 : #Viola = 41
#Electric_guitar_jazz = 26 : #Electric_bass_pick = 34 : #Cello = 42
#Electric_guitar_clean = 27 : #Fretless_bass = 35 : #Contrabass = 43
#Electric_guitar_muted = 28 : #Slap_bass_1 = 36 : #Tremolo_strings = 44
#Overdriven_guitar = 29 : #Slap_bass_2 = 37 : #Pizzicato_strings = 45
#Distortion_guitar = 30 : #Synth_bass_1 = 38 : #Orchestral_harp = 46
#Guitar_harmonics = 31 : #Synth_bass_2 = 39 : #Timpani = 47
; : :
; Ensemble : Brass : Reed
; -------------------------------------------------------------------------------------------
#String_ensemble_1 = 48 : #Trumpet = 56 : #Soprano_sax = 64
#String_ensemble_2 = 49 : #Trombone = 57 : #Alto_sax = 65
#Synth_strings_1 = 50 : #Tuba = 58 : #Tenor_sax = 66
#Synth_strings_2 = 51 : #Muted_trumpet = 59 : #Baritone_sax = 67
#Choir_Aahs = 52 : #French_horn = 60 : #Oboe = 68
#Voice_Oohs = 53 : #Brass_section = 61 : #English_horn = 69
#Synth_voice = 54 : #Synth_brass_1 = 62 : #Bassoon = 70
#Orchestra_hit = 55 : #Synth_brass_2 = 63 : #Clarinet = 71
; : :
; Pipe : Synth Lead : Synth Pad
; -------------------------------------------------------------------------------------------
#Piccolo = 72 : #Lead_1_square = 80 : #Pad_1_new_age = 88
#Flute = 73 : #Lead_2_sawtooth = 81 : #Pad_2_warm = 89
#Recorder = 74 : #Lead_3_calliope_lead = 82 : #Pad_3_polysynth = 90
#Pan_flute = 75 : #Lead_4_chiff_lead = 83 : #Pad_4_choir = 91
#Bottle_blow = 76 : #Lead_5_charang = 84 : #Pad_5_bowed = 92
#Shakuhachi = 77 : #Lead_6_voice = 85 : #Pad_6_metallic = 93
#Whistle = 78 : #Lead_7_fifths = 86 : #Pad_7_halo = 94
#Ocarina = 79 : #Lead_8_brass_lead = 87 : #Pad_8_sweep = 95
; : :
; SYNTH EFFECTS : ETHNIC : PERCUSSIVE
; -------------------------------------------------------------------------------------------
#FX_1_rain = 96 : #Sitar = 104 : #Tinkle_Bell = 112
#FX_2_soundtrack = 97 : #Banjo = 105 : #Agogo = 113
#FX_3_crystal = 98 : #Shamisen = 106 : #Steel_Drums = 114
#FX_4_atmosphere = 99 : #Koto = 107 : #Woodblock = 115
#FX_5_brightness = 100 : #Kalimba = 108 : #Taiko_Drum = 116
#FX_6_goblins = 101 : #Bagpipe = 109 : #Melodic_Tom = 117
#FX_7_echoes = 102 : #Fiddle = 110 : #Synth_Drum = 118
#FX_8_sci_fi = 103 : #Shanai = 111 : #Reverse_Cymbal = 119
; : :
; Sound Effects
; -------------------------------------------------------------------------------------------
#Guitar_fret_noise = 120
#Breath_noise = 121
#Seashore = 122
#Bird_tweet = 123
#Telephone_ring = 124
#Helicopter = 125
#Applause = 126
#Gunshot = 127
; missing constants
#MOD_WAVETABLE = 6
#MOD_SWSYNTH = 7
#MAXPNAMELEN = 32
Structure MIDIOUTCAPS2
wMid.w
wPid.w
vDriverVersion.l
szPname.b[#MAXPNAMELEN]
wTechnology.w
wVoices.w
wNotes.w
wChannelMask.w
dwSupport.l
EndStructure
NewList DeviceInfo.MIDIOUTCAPS2()
Global handle_MidiOut
Procedure MidiOutMessage(hMidi,iCommand,iChannel,iData1,iData2)
ProcedureReturn midiOutShortMsg_(hMidi, iCommand | iChannel | (iData1 << 8) | (iData2 << 16) )
EndProcedure
Procedure SetInstrument(channel,instrument)
;MidiOutMessage(handle_MidiOut, $C0, channel, instrument, 0)
midiOutShortMsg_(handle_MidiOut,$C0|channel|(instrument<<8))
EndProcedure
Procedure PlayNote(channel,Note)
;MidiOutMessage(handle_MidiOut, $90, channel, Note , 127)
midiOutShortMsg_(handle_MidiOut,$90|channel|(Note<<8)|(127<<16))
EndProcedure
Procedure StopNote(channel,Note)
;MidiOutMessage(handle_andle_MidiOut, $90, channel, Note , 0)
midiOutShortMsg_(handle_MidiOut,$90|channel|(Note<<8))
EndProcedure
;Procedure ChangeMIDIdevice(number)
; If handle_MidiOut
; midiOutClose_(handle_MidiOut)
; EndIf
; If midiOutOpen_(@handle_MidiOut,number,0,0,0) = #MMSYSERR_NOERROR
; Result = handle_MidiOut
; Else
; MessageRequester("ERROR","Cant open MIDI device",#MB_ICONERROR)
; Result = 0
; EndIf
; ProcedureReturn Result
;EndProcedure
Procedure Add2DeviceList(DeviceNr)
AddElement(DeviceInfo())
midiOutGetDevCaps_(DeviceNr,@DeviceInfo(),SizeOf(MIDIOUTCAPS2))
DeviceInfo()\wMid = DeviceNr
;MessageRequester("INFO","FOUND Device "+Str(DeviceInfo()\wMid)+": "+PeekS(@DeviceInfo()\szPname[0],#MAXPNAMELEN-1),0)
EndProcedure
Procedure CheckDevices()
; Check for MIDIMAPPER
If midiOutOpen_(@handle_MidiOut,#MIDIMAPPER,0,0,0) = #MMSYSERR_NOERROR
Add2DeviceList(#MIDIMAPPER)
midiOutClose_(handle_MidiOut)
EndIf
; Check other Devices
count = midiOutGetNumDevs_()
If count
For a = 0 To count-1
If midiOutOpen_(@handle_MidiOut,a,0,0,0) = #MMSYSERR_NOERROR
Add2DeviceList(a)
midiOutClose_(handle_MidiOut)
EndIf
Next a
EndIf
ProcedureReturn CountList(DeviceInfo())
EndProcedure
Procedure ShowNewDeviceInfo()
SetGadgetText(10,"device number: " +Str (DeviceInfo()\wMid))
SetGadgetText(11,"driver version: " +StrU((DeviceInfo()\vDriverVersion & $FF00)>>8,2)+"."+StrU((DeviceInfo()\vDriverVersion & $FF)>>8,2))
Select DeviceInfo()\wTechnology
Case 1 : Tech$ = "a MIDI hardware port" ; #MOD_MIDIPORT
Case 2 : Tech$ = "a synthesizer" ; #MOD_SYNTH
Case 3 : Tech$ = "a square wave synthesizer" ; #MOD_SQSYNTH
Case 4 : Tech$ = "an FM synthesizer" ; #MOD_FMSYNTH
Case 5 : Tech$ = "the Microsoft MIDI mapper" ; #MOD_MAPPER
Case 6 : Tech$ = "a hardware wavetable synthesizer" ; #MOD_WAVETABLE
Case 7 : Tech$ = "a software synthesizer" ; #MOD_SWSYNTH
Default : Tech$ = "a -[ ERROR, no info available ]-"
EndSelect
SetGadgetText(12,"the device is "+Tech$)
SetGadgetText(13,"number of voices: "+Str(DeviceInfo()\wVoices)+" (not meaningful for hardware ports)")
SetGadgetText(14,"max notes: "+Str(DeviceInfo()\wNotes)+" (not meaningful for hardware ports)")
channels = DeviceInfo()\wChannelMask & $FFFF
For a = 15 To 0 Step -1
x = channels & 1
If x
ChanSupport$ = "X"
Else
ChanSupport$ = "--"
EndIf
SetGadgetText(20+a,ChanSupport$)
channels >> 1
Next a
EndProcedure
Procedure TestMIDIPlay()
If midiOutOpen_(@handle_MidiOut,DeviceInfo()\wMid,0,0,0) = #MMSYSERR_NOERROR
DisableGadget(1,1):DisableGadget(2,1):DisableGadget(3,1):DisableGadget(51,1)
While WindowEvent() : Wend
SetInstrument(#Channel1,0)
For a = $2C To $4C Step 2
PlayNote(#Channel1,a) : Delay(100) : StopNote(#Channel1,a)
SetGadgetState(50,a-$2C): While WindowEvent() : Wend
Next a
For a = $4C To $2C Step -2
PlayNote(#Channel1,a) : Delay(100) : StopNote(#Channel1,a)
SetGadgetState(50,a-$2C): While WindowEvent() : Wend
Next a
midiOutClose_(handle_MidiOut)
DisableGadget(1,0):DisableGadget(2,0):DisableGadget(3,0):DisableGadget(51,0)
While WindowEvent() : Wend
Else
MessageRequester("ERROR","Cant open MIDI device",#MB_ICONERROR)
EndIf
EndProcedure
Procedure InitializeMidiSystem()
If midiOutOpen_(@handle_MidiOut,DeviceInfo()\wMid,0,0,0) = #MMSYSERR_NOERROR
Result = 1
Else
MessageRequester("ERROR","Cant open MIDI device",#MB_ICONERROR)
Result = 0
EndIf
ProcedureReturn Result
EndProcedure
Procedure CloseMidi()
If handle_MidiOut
midiOutClose_(handle_MidiOut)
EndIf
EndProcedure
Procedure ChooseDevice()
OpenWindow(0,0,0,300,295,#PB_Window_TitleBar|#PB_Window_ScreenCentered,"Please select MIDI device")
CreateGadgetList(WindowID())
ListViewGadget(1,10,10,280,60)
ResetList(DeviceInfo())
While NextElement(DeviceInfo())
AddGadgetItem(1,-1,PeekS(@DeviceInfo()\szPname[0],#MAXPNAMELEN-1))
Wend
Frame3DGadget(0, 9,264,202,22,"",2)
ButtonGadget( 2, 10,265,200,20,"OK, let's start!"): DisableGadget(2,1)
Frame3DGadget(0,219,264, 72,22,"",2)
ButtonGadget( 3,220,265, 70,20,"Quit")
TextGadget(10,10,120,280,15,"device number: "+"--")
TextGadget(11,10,105,280,15,"driver version: "+"--")
TextGadget(12,10, 90,280,15,"the device is "+"a --")
TextGadget(13,10,135,280,15,"number of voices: "+"--")
TextGadget(14,10,150,280,15,"max notes: "+"--")
For a = 0 To 15
TextGadget(20+a,8+a*18,190,15,15,Hex(a),#PB_Text_Center)
TextGadget(20+a,8+a*18,205,15,15,"--",#PB_Text_Center)
Next a
ProgressBarGadget(50, 10,235,200,15,0,32,#PB_ProgressBar_Smooth)
Frame3DGadget(0,219,231,72,23,"",2)
ButtonGadget(51,220,232,70,21,"Test") : DisableGadget(51,1)
Frame3DGadget(0, 5, 75,290,95,"driver info",0)
Frame3DGadget(0, 5,175,290,50,"supported channels",0)
Repeat
Select WaitWindowEvent()
Case #PB_EventCloseWindow : End
Case #PB_EventGadget
Select EventGadgetID()
Case 1
x = GetGadgetState(1)
If x > -1
DisableGadget(2,0) : DisableGadget(51,0)
SelectElement(DeviceInfo(),x)
ShowNewDeviceInfo()
EndIf
Case 2
If InitializeMidiSystem()
Quit = 1
EndIf
Case 3
End
Case 51
TestMIDIPlay()
EndSelect
EndSelect
Until Quit = 1
CloseWindow(0)
EndProcedure