Looking for MIDI-Library
-
- Enthusiast
- Posts: 113
- Joined: Sun Jul 29, 2012 2:51 pm
Re: Looking for MIDI-Library
I got it to work in 32 bit. It does not work in 64 bit i'm afraid.
Here is the error I get when compiling and running:
POLINK: fatal error: corrupt library: '.\Lib_midi4.lib.
Any ideas?
Mike
Here is the error I get when compiling and running:
POLINK: fatal error: corrupt library: '.\Lib_midi4.lib.
Any ideas?
Mike
Re: Looking for MIDI-Library
A 64-Bit application can only load 64-Bit DLLs, or use 64-Bit libs.
The same for 32-Bit application.
I haven't download this, but is there no 64-Bit version you can't use it for 64-Bit
The same for 32-Bit application.
I haven't download this, but is there no 64-Bit version you can't use it for 64-Bit

PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Re: Looking for MIDI-Library
click on button [Install Midi lib]
the installer asks if purebasic is found at the specified location?
if so, just click on the Folder proposed
or indicate where is Purebasic
click [ok]
the installer displays a small window that says
the documentation is on Help Folder
the installer asks if purebasic is found at the specified location?
if so, just click on the Folder proposed
or indicate where is Purebasic
click [ok]
the installer displays a small window that says
---> "the installation is complete""l'installation est terminée"

the documentation is on Help Folder
Re: Looking for MIDI-Library
another Example :
midi sound to Windows events
midi sound to Windows events
; cette exemple montre comment employer la Midi librairie
; pour sonoriser l'ouverture ou la fermeture d'une fenetre
; le midi pourrai etre employer pour sonoriser tout evenements Windows !!
; ***********************************************
;This example shows how to use the Midi library
; For sound to the opening or closing a window
; Lunch could be used for any sound to Windows events !!
; ******** initialisation obligatoire ***********
Declare son_ouverture()
Declare son_fermeture()
Enumeration 35
#Acoustic_Bass_Drum
#Bass_Drum_1
#Side_Stick
#Acoustic_Snare
#Hand_Clap
#Electric_Snare
#Low_Floor_Tom
#Closed_Hi_Hat
#High_Floor_Tom
#Pedal_Hi_Hat
#Low_Tom
#Open_Hi_Hat
#Low_Mid_Tom
#Hi_Mid_Tom
#Crash_Cymbal_1
#High_Tom
#Ride_Cymbal_1
#Chinese_Cymbal
#Ride_Bell
#Tambourine
#Splash_Cymbal
#Cowbell
#Crash_Cymbal_2
#Vibraslap
#Ride_Cymbal_2
#Hi_Bongo
#Low_Bongo
#Mute_Hi_Conga
#Open_Hi_Conga
#Low_Conga
#High_Timbale
#Low_Timbale
#High_Agogo
#Low_Agogo
#Cabasa
#Maracas
#Short_Whistle
#Long_Whistle
#Short_Guiro
#Long_Guiro
#Claves
#Hi_Wood_Block
#Low_Wood_Block
#Mute_Cuica
#Open_Cuica
#Mute_Triangle
#Open_Triangle
EndEnumeration
MIDIOpen() ; ouvre le midi
; *****************************************
son_ouverture()
If openwindow (0, 100, 200, 320, 200, "PureBasic Window" , #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget )
Repeat
Event = waitwindowevent ()
If Event = #PB_Event_CloseWindow ; If the user has pressed on the close button
Quit = 1
EndIf
Until Quit = 1
EndIf
son_fermeture()
End ; All the opened windows are closed automatically by PureBasic
Procedure son_ouverture()
vitesse=250
For i=1 To 2 ; utilisation d'une boucle
Midi_batterie( #Side_Stick , "double_croche" ,127,127,vitesse)
Midi_batterie( #Closed_Hi_Hat , "double_croche" ,127,127,vitesse)
Next i
Midi_batterie( #Crash_Cymbal_1 , "noire" ,127,127,vitesse)
EndProcedure
Procedure son_fermeture()
vitesse=250
For i=1 To 2 ; utilisation d'une boucle
Midi_batterie( #Closed_Hi_Hat , "double_croche" ,127,127,vitesse)
Midi_batterie( #Acoustic_Snare , "double_croche" ,127,127,vitesse)
Next i
Midi_batterie( #Long_Whistle , "blanche" ,127,127,vitesse)
EndProcedure
; EPB
-
- Enthusiast
- Posts: 113
- Joined: Sun Jul 29, 2012 2:51 pm
Re: Looking for MIDI-Library
Thank you.
For 32 bit, I got it working.
Is there a way to do this in 64 bit? Mac?
Mike
For 32 bit, I got it working.
Is there a way to do this in 64 bit? Mac?
Mike
Re: Looking for MIDI-Library
never !!karmacomposer wrote: Mac?
Mike

-
- Enthusiast
- Posts: 113
- Joined: Sun Jul 29, 2012 2:51 pm
Re: Looking for MIDI-Library
DoBro,
Does the MIDI Player example play a MIDI file at all? All I see is the debug window with a bunch of '0' and no sound! How do I actually play a MIDI file?
Although I have been able to find out how to list and choose a MIDI device from another Pure Basic project, how would I assign playing the MIDI file to that device (MIDI Out)? I assume this library can play MIDI files with multiple tracks and instruments within it - or can it only play a single MIDI track? Can Karaoke .MID files be played with this library?
Likewise, say I wanted to intercept MIDI notes coming from a keyboard. How would I choose the correct MIDI input device?
Does your library cover this? Is there any documentation on your library?
Mike
Does the MIDI Player example play a MIDI file at all? All I see is the debug window with a bunch of '0' and no sound! How do I actually play a MIDI file?
Although I have been able to find out how to list and choose a MIDI device from another Pure Basic project, how would I assign playing the MIDI file to that device (MIDI Out)? I assume this library can play MIDI files with multiple tracks and instruments within it - or can it only play a single MIDI track? Can Karaoke .MID files be played with this library?
Likewise, say I wanted to intercept MIDI notes coming from a keyboard. How would I choose the correct MIDI input device?
Does your library cover this? Is there any documentation on your library?
Mike
Re: Looking for MIDI-Library
say I wanted to intercept MIDI notes coming from a keyboard. How would I choose the correct MIDI input device?
Code: Select all
;simple Midi In/Out
; by einander
; PB 5.00 beta 5
; Windows Only, with a Midi Keyboard attached.
EnableExplicit
;
Structure MIDI
MIDIIn.L
MIDIOut.L
Stat.A
Dat1.A
Dat2.A
EndStructure
;
Define Ev
Global _Midi.Midi,_TG,_Quit
;
Procedure MIDIInProc(hMidiIn, Msg, Instance, Dat1, Dat2) ; get MIDINotes
;callback function for handling incoming MIDI messages.
;Here only show NoteOn, NoteOff and Velocity ; dat2 is unused for Midi in/ Out
;see http://msdn.microsoft.com/en-us/library/windows/desktop/dd798460%28v=vs.85%29.aspx
With _MIDI
Select Msg
Case #MM_MIM_DATA
Select Dat1 & $FF
Case 144
\Stat=Dat1 >> 8 ;Note
\Dat1=Dat1 >> 16 ;Velocity
If \Dat1 : SetGadgetText(_TG,"Note On "+Str(\Stat)+" Vel "+Str(\Dat1))
Else : SetGadgetText(_TG,"Note Off "+Str(\Stat))
EndIf
Case 128
\Stat=Dat1 >> 8 ;Note
\Dat1=Dat1 >> 16 ;Velocity
SetGadgetText(_TG,"Note Off "+Str(\Stat)+" Vel "+Str(\Dat1))
EndSelect
EndSelect
EndWith
EndProcedure
;
Procedure MIDIinit(Instrument=0)
With _Midi
If midiInGetNumDevs_()
If midiInOpen_(@\MidiIN, 0, @MIDIInProc(), 0, #CALLBACK_FUNCTION) = #MMSYSERR_NOERROR
If midiInStart_(\MidiIN) <> #MMSYSERR_NOERROR
MessageRequester("Error","Can't start MIDI IN",0)
End
EndIf
Else : MessageRequester("Error","Can't open MIDI IN",0)
End
EndIf
midiOutOpen_(@\MidiOUT, 0, 0, 0, 0)
midiOutShortMsg_(\MidiOUT, 192 | Instrument<<8 ) ; set instrument
If \MidiIN And \MidiOUT
If Not midiConnect_(\MidiIN, \MidiOUT, 0)
SetGadgetText(_TG, "MIDI setting ready! Play MIDI Keyboard")
Else : MessageRequester("Error","Can't connect MIDI",0)
End
EndIf
EndIf
Else
MessageRequester("Error","No Midi devices found",0)
End
EndIf
EndWith
EndProcedure
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
OpenWindow(0,0,0,400,100,"MIDI Play",#PB_Window_SystemMenu|1)
Define Wi=WindowWidth(0)
Define He=WindowHeight(0)
_TG=TextGadget(-1,10,10,Wi,30,"")
Define TBVol=TrackBarGadget(-1,10,50,300,24,0,$Ffff)
SetGadgetState(Tbvol,$FFFF)
MIDIinit()
With _Midi
midiOutSetVolume_(\MidiOUT,$FFFF)
Repeat
If GetAsyncKeyState_(27)&$8000 :_Quit=#True : EndIf
Ev=WaitWindowEvent()
If Ev=#PB_Event_Gadget
Select EventGadget()
Case TBVol : midiOutSetVolume_(\MidiOUT,GetGadgetState(Tbvol))
EndSelect
EndIf
Until Ev=#PB_Event_CloseWindow Or _Quit
midiDisconnect_(\MidiIN, \MidiOUT, 0)
While midiInClose_(\MidiIN) = #MIDIERR_STILLPLAYING : Wend
While midiOutClose_(\MidiOUT) = #MIDIERR_STILLPLAYING : Wend
midiOutClose_(\MidiOUT)
EndWith
-
- Enthusiast
- Posts: 113
- Joined: Sun Jul 29, 2012 2:51 pm
Re: Looking for MIDI-Library
Thanks for this - very interesting. I read the article on MSDN and this really shows me how to adapt c++ to PureBasic. I have so much to learn. The Syntax is very different from what I am used to, but I can learn it.einander wrote:say I wanted to intercept MIDI notes coming from a keyboard. How would I choose the correct MIDI input device?Code: Select all
;simple Midi In/Out ; by einander ; PB 5.00 beta 5 ; Windows Only, with a Midi Keyboard attached. EnableExplicit ; Structure MIDI MIDIIn.L MIDIOut.L Stat.A Dat1.A Dat2.A EndStructure ; Define Ev Global _Midi.Midi,_TG,_Quit ; Procedure MIDIInProc(hMidiIn, Msg, Instance, Dat1, Dat2) ; get MIDINotes ;callback function for handling incoming MIDI messages. ;Here only show NoteOn, NoteOff and Velocity ; dat2 is unused for Midi in/ Out ;see http://msdn.microsoft.com/en-us/library/windows/desktop/dd798460%28v=vs.85%29.aspx With _MIDI Select Msg Case #MM_MIM_DATA Select Dat1 & $FF Case 144 \Stat=Dat1 >> 8 ;Note \Dat1=Dat1 >> 16 ;Velocity If \Dat1 : SetGadgetText(_TG,"Note On "+Str(\Stat)+" Vel "+Str(\Dat1)) Else : SetGadgetText(_TG,"Note Off "+Str(\Stat)) EndIf Case 128 \Stat=Dat1 >> 8 ;Note \Dat1=Dat1 >> 16 ;Velocity SetGadgetText(_TG,"Note Off "+Str(\Stat)+" Vel "+Str(\Dat1)) EndSelect EndSelect EndWith EndProcedure ; Procedure MIDIinit(Instrument=0) With _Midi If midiInGetNumDevs_() If midiInOpen_(@\MidiIN, 0, @MIDIInProc(), 0, #CALLBACK_FUNCTION) = #MMSYSERR_NOERROR If midiInStart_(\MidiIN) <> #MMSYSERR_NOERROR MessageRequester("Error","Can't start MIDI IN",0) End EndIf Else : MessageRequester("Error","Can't open MIDI IN",0) End EndIf midiOutOpen_(@\MidiOUT, 0, 0, 0, 0) midiOutShortMsg_(\MidiOUT, 192 | Instrument<<8 ) ; set instrument If \MidiIN And \MidiOUT If Not midiConnect_(\MidiIN, \MidiOUT, 0) SetGadgetText(_TG, "MIDI setting ready! Play MIDI Keyboard") Else : MessageRequester("Error","Can't connect MIDI",0) End EndIf EndIf Else MessageRequester("Error","No Midi devices found",0) End EndIf EndWith EndProcedure ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< OpenWindow(0,0,0,400,100,"MIDI Play",#PB_Window_SystemMenu|1) Define Wi=WindowWidth(0) Define He=WindowHeight(0) _TG=TextGadget(-1,10,10,Wi,30,"") Define TBVol=TrackBarGadget(-1,10,50,300,24,0,$Ffff) SetGadgetState(Tbvol,$FFFF) MIDIinit() With _Midi midiOutSetVolume_(\MidiOUT,$FFFF) Repeat If GetAsyncKeyState_(27)&$8000 :_Quit=#True : EndIf Ev=WaitWindowEvent() If Ev=#PB_Event_Gadget Select EventGadget() Case TBVol : midiOutSetVolume_(\MidiOUT,GetGadgetState(Tbvol)) EndSelect EndIf Until Ev=#PB_Event_CloseWindow Or _Quit midiDisconnect_(\MidiIN, \MidiOUT, 0) While midiInClose_(\MidiIN) = #MIDIERR_STILLPLAYING : Wend While midiOutClose_(\MidiOUT) = #MIDIERR_STILLPLAYING : Wend midiOutClose_(\MidiOUT) EndWith
This code plays a piano sound (in the left side only - weird panning), and I figured out how to change the instrument type. I am going to add a selector so I can choose
which GM instrument to play. One thing I cannot seem to figure out is how to change the MIDI device that this plays out of.
I have 3 MIDI keyboards. One is attached to a true MIDI interface (that's the one that plays) and the other two are USB MIDI devices. How can I choose one of the USB MIDI devices? Is there a command or parameter to do this?
Mike
Re: Looking for MIDI-Library
Hi Mike: The example is only a simple starting point to show how to play a sound with a midi keyboard.
I have only one USB midiKeyboard, and the program reads input from it.
To do more advanced Midi programming, you must explore the Windows Multimedia Midi Functions.
See here:
http://msdn.microsoft.com/en-us/library ... 85%29.aspx
and here the midiOutProc Callback
http://msdn.microsoft.com/en-us/library ... 85%29.aspx
I have only one USB midiKeyboard, and the program reads input from it.
To do more advanced Midi programming, you must explore the Windows Multimedia Midi Functions.
See here:
http://msdn.microsoft.com/en-us/library ... 85%29.aspx
and here the midiOutProc Callback
http://msdn.microsoft.com/en-us/library ... 85%29.aspx
-
- Enthusiast
- Posts: 113
- Joined: Sun Jul 29, 2012 2:51 pm
Re: Looking for MIDI-Library
This seems to be the command, but I have no idea how to code this in Purebasic. The MIDI_ command seems to have other commands (via code completion), but the following is not one of them:
Does PureBasic have MIDI commands built in? I did not see any includes or library files in your code, unlike the previous poster's MIDI lib file. Yours seems to call Windows native commands. Am I wrong?
And yes, I am slowly going chapter-by-chapter through the PureBasic book and I have already read the help docs that come with PureBasic. I learn better by studying existing code.
Mike
Code: Select all
The midiConnect function connects a MIDI input device to a MIDI thru or output device, or connects a MIDI thru device to a MIDI output device.
Syntax
C++
MMRESULT midiConnect(
HMIDI hMidi,
HMIDIOUT hmo,
LPVOID pReserved
);
Parameters
hMidi
Handle to a MIDI input device or a MIDI thru device. (For thru devices, this handle must have been returned by a call to the midiOutOpen function.)
hmo
Handle to the MIDI output or thru device.
pReserved
Reserved; must be NULL
And yes, I am slowly going chapter-by-chapter through the PureBasic book and I have already read the help docs that come with PureBasic. I learn better by studying existing code.
Mike
Re: Looking for MIDI-Library
PB don't have yet native midi commands; you must use winAPI to do midi tasks.
Look also on the German and French PB forums; you can found there good midi examples.
Look also on the German and French PB forums; you can found there good midi examples.
-
- Enthusiast
- Posts: 113
- Joined: Sun Jul 29, 2012 2:51 pm
Re: Looking for MIDI-Library
I will. Google translate is my friend.einander wrote:PB don't have yet native midi commands; you must use winAPI to do midi tasks.
Look also on the German and French PB forums; you can found there good midi examples.
Mike
-
- User
- Posts: 40
- Joined: Wed Oct 06, 2010 9:37 pm
Re: Looking for MIDI-Library
KharmaComposer asked for "how to choose between different MIDI-interfaces"?
Being a newbie I still managed to use Einander's code and chose my external USB-interface instead of my internal device. Just let OutDev be 1 instead of zero.
Procedure MIDIinit(*MIDIInProc=-1,Instrument=0) ;MIDIinproc default solo muestra Note on, Note off
Protected OutDev=1 , InDev
I am using Win10, 64 bits.
Being a newbie I still managed to use Einander's code and chose my external USB-interface instead of my internal device. Just let OutDev be 1 instead of zero.
Procedure MIDIinit(*MIDIInProc=-1,Instrument=0) ;MIDIinproc default solo muestra Note on, Note off
Protected OutDev=1 , InDev
I am using Win10, 64 bits.
Newbie