bah.portmidi: Constants Types Modinfo Source  

PortMidi

Portable Real-Time MIDI Library.

BaH.Portmidi is a BlitzMax implementation of Portmidi, a platform independent library for MIDI.

Using Portmidi

The Portmidi module is built around the use of callbacks.
The main type, TPortMidi is initialized with two of them. An error callback, and a read callback. You need to implement these functions to allow Portmidi to inform you when something happens.

The read function is called when MIDI Input data becomes available for a particular stream.

The error function is called when Portmidi determines that something has gone wrong.

A minimal example might look like :

Function err(errorNumber:Int, errorString:String)
	Print "Oops - " + errorString
	End
End Function

Function read(stream:TPortMidiStream, length:Int, messages:TMidiMessage[])
	Print length + " messages available"
End Function

Local midi:TPortMidi = TPortMidi.Create(err, read)

If midi Then

	midi.openInput(0)
	
	While Not KeyDown(key_escape)
		WaitEvent
	Wend

End If

A TMidiMessage represents a MIDI event sent by a MIDI device - for example, a keyboard key press.
The fields... status, data1 and data2, provide the message details.

A single read() event can have multiple message parts. You can use length to determine how many messages are available to process.
Do not use the length of the messages array as this may be larger than the number of actual available messages. (The array is static and grows when required, but isn't reset in an effort to keep it efficient).

SysEx

You can send and receive a SysEx message via the sendReceiveSysEx() method of TPortMidi. This method takes another callback function as a parameter, which will be called once the SysEx reply from the device is received. The receive part of this runs on the same background timer as the rest of the module, and so you can continue with your app while data is received from the device.

Local data:String = Chr($F0) + Chr($7E) + Chr($00) + Chr($06) + Chr($01) + Chr($F7)

midi.sendReceiveSysEx(1, 3, data, Null, sysexCallback)

' hang around and wait for the end...
While Not KeyDown(key_escape)
	WaitEvent
Wend

End

Function sysexCallback(recMessage:String, userData:Object)
	' .....
End Function

Constants

Const PM_FILT_ACTIVE:Int
Descriptionfilter active sensing messages ($FE)

Const PM_FILT_AFTERTOUCH:Int
Descriptionfilter both channel And poly aftertouch.

Const PM_FILT_CHANNEL_AFTERTOUCH:Int
Descriptionfilter channel aftertouch (most midi controllers use this) ($D0-$DF)*/

Const PM_FILT_CLOCK:Int
Descriptionfilter clock messages (CLOCK $F8, START $FA, STOP $FC, And Continue $FB)

Const PM_FILT_CONTROL:Int
DescriptionControl Changes (CC's) ($B0-$BF)*/

Const PM_FILT_FD:Int
Descriptionfilter undefined FD messages.

Const PM_FILT_MTC:Int
DescriptionMIDI Time Code ($F1)*/

Const PM_FILT_NOTE:Int
Descriptionfilter note-on And note-off ($90-$9F And $80-$8F.

Const PM_FILT_PITCHBEND:Int
DescriptionPitch Bender ($E0-$EF*/

Const PM_FILT_PLAY:Int
Descriptionfilter play messages (start $FA, stop $FC, Continue $FB)

Const PM_FILT_POLY_AFTERTOUCH:Int
Descriptionper-note aftertouch ($A0-$AF)

Const PM_FILT_PROGRAM:Int
DescriptionProgram changes ($C0-$CF)

Const PM_FILT_REALTIME:Int
Descriptionfilter all real-time messages.

Const PM_FILT_RESET:Int
Descriptionfilter reset messages ($FF)

Const PM_FILT_SONG_POSITION:Int
DescriptionSong Position ($F2)

Const PM_FILT_SONG_SELECT:Int
DescriptionSong Select ($F3)*/

Const PM_FILT_SYSEX:Int

Const PM_FILT_SYSTEMCOMMON:Int
DescriptionAll System Common messages (mtc, song position, song Select, tune request)

Const PM_FILT_TICK:Int
Descriptionfilter tick messages ($F9)

Const PM_FILT_TUNE:Int
DescriptionTuning request ($F6)*/

Const PM_FILT_UNDEFINED:Int
Descriptionfilter undefined real-time messages.

Const pmNoDevice:Int
DescriptionThe device Id value the represents "No Device".

Types

Type TMidiMessage
DescriptionA midi event message part.
Field data1:Int
DescriptionMessage data 1.
Field data2:Int
DescriptionMessage data 2.
Field raw:Int
DescriptionThe raw message data.
Informationstatus, data1 and data2 derive from this value.
Field status:Int
DescriptionMessage status.
Field timestamp:Int
DescriptionTimestamp.

Type TPortMidi
DescriptionPortMidi main Type.
Method close(deviceId:Int)
DescriptionCloses the specified midi stream.
Method device:TPortMidiStream(deviceId:Int)
DescriptionReturns the TPortMidiStream device for the specified deviceId.
Method deviceCount:Int()
DescriptionReturns the number of midi devices (input and output)
Method deviceName:String(deviceIndex:Int)
DescriptionThe name of the specified device.
Method getDefaultInputDeviceId:Int()
DescriptionReturns the default input device ID or pmNoDevice if there are no devices.
Method getDefaultOutputDeviceId:Int()
DescriptionReturns the default output device ID or pmNoDevice if there are no devices.
Method inputDeviceCount:Int()
DescriptionThe number of input devices.
Method inputDeviceName:String(inputIndex:Int)
DescriptionThe name of the input device, by inputIndex.
Method interface:String(deviceIndex:Int)
DescriptionThe underlying API name.
Method openInput:Int(deviceId:Int, userData:Object = Null, useDefaultCallback:Int = True, setTimer:Int = True)
DescriptionOpens the specified input device for reading.
InformationdeviceId value is the index of the input device.
Method openOutput:Int(deviceId:Int)
DescriptionOpens an output stream for the specified deviceId.
Method outputDeviceCount:Int()
DescriptionThe number of output devices.
Method outputDeviceName:String(outputIndex:Int)
DescriptionThe name of the output device, by outputIndex.
Method sendReceiveSysEx:Int(inputId:Int, outputId:Int, sendData:String, userData:Object, ..
DescriptionPerforms a SysEx send/recieve on the specified output and input devices.
InformationsendData is the data you wish to send to the device.
userData is an optional object that will be passed to the callback.
callback is a function that is called on completion of the recieved data.
Method setFilter:Int(deviceId:Int, filter:Int)
DescriptionSets filters on an open input stream to drop selected input types.
InformationBy default, only active sensing messages are filtered. To prohibit, say, active sensing and sysex messages, call with PM_FILT_ACTIVE | PM_FILT_SYSEX.

Available filters are : PM_FILT_ACTIVE, PM_FILT_SYSEX, PM_FILT_CLOCK, PM_FILT_PLAY, PM_FILT_TICK, PM_FILT_FD, PM_FILT_UNDEFINED, PM_FILT_RESET, PM_FILT_REALTIME, PM_FILT_NOTE, PM_FILT_CHANNEL_AFTERTOUCH, PM_FILT_POLY_AFTERTOUCH, PM_FILT_AFTERTOUCH, PM_FILT_PROGRAM, PM_FILT_CONTROL, PM_FILT_PITCHBEND, PM_FILT_MTC, PM_FILT_SONG_POSITION, PM_FILT_SONG_SELECT, PM_FILT_TUNE and PM_FILT_SYSTEMCOMMON.

Function Create:TPortMidi(errCallback( errorNumber:Int, errorString:String), ..
DescriptionCreates a new PortMidi instance.
InformationInitializes PortMidi, and gets details of available devices.

Type TPortMidiStream
DescriptionA PortMidi stream/device.
Field isInput:Int = False
DescriptionTrue if this is an input stream.
Method close()
DescriptionCloses an open stream.
Method interface:String()
DescriptionReturns the underlying midi API name.
Method isOpen:Int()
DescriptionReturns True if the stream is open.
Method name:String()
DescriptionReturns the device name.
Method setFilter:Int(filter:Int)
DescriptionSets filters on the open input stream to drop selected input types.

Module Information

Version1.03
AuthorRoss Bencina, Phil Burk, Roger B. Dannenberg
CopyrightPhil Burk, Ross Bencina, Roger B. Dannenberg
CreditsWrapper - Initial implementation : Nigel Brown
CreditsWrapper - 1.00+ Type based/Hook/Callback : Bruce A Henderson
LicenseFree
ModserverBRL
History1.03
HistoryDocumentation improvements.
History1.02
HistoryUpdate to 17-Jan-07 portmidi release.
HistoryNew filters for setFilter().
HistoryAdded sendReceiveSysEx and openOutput methods, and new sysex handler.
History1.01
HistoryAdded TMidiMessage type.
HistoryRewrite of the event buffer handling to use the new type.
HistoryMore functionality. Improved documentation.
History1.00 Release
HistoryFirst release using portmidi sdk
CC_OPTS-DUSE_DLL_FOR_CLEANUP
CC_OPTS-DNEWBUFFER