PortMidi.ReadMessage
--------------------

Reads one Midi message from the buffers.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [PortMidi](component_PortMidi.md) | [4.2](newinversion42.md) | ✅ Yes | ✅ Yes | ❌ No | ❌ No | ❌ No |

MBS( "PortMidi.ReadMessage"; StreamRef ) 

**MBS**( **"PortMidi.ReadMessage";** /\* Reads one Midi message from the buffers. \*/  
**$StreamRef**) /\* The reference to the midi stream. You create those with [PortMidi.OpenInput](PortMidiOpenInput.md) or [PortMidi.OpenOutput](PortMidiOpenOutput.md) and finally close them with [PortMidi.Close](PortMidiClose.md).e.g. $stream \*/ 

### Parameters

| Parameter | Description | Example |
|---|---|---|
| StreamRef | The reference to the midi stream. You create those with [PortMidi.OpenInput](PortMidiOpenInput.md) or [PortMidi.OpenOutput](PortMidiOpenOutput.md) and finally close them with [PortMidi.Close](PortMidiClose.md). | $stream |

### Result

Returns message, empty or error.

### Description

Reads one Midi message from the buffers.  
Format of result is a list containing: Status, Data1, Data2, Timestamp and raw message first as decimal number and then also as hex number. Hex notation makes reading easier for debugging.  
  
e.g. 144 is the status number for channel 1 note on followed by the Data1 as the note number and Data2 with the velocity. Status 128 is to turn the channel 1 note off.  
### Examples

Split MIDI Timestamp:

 # last five bits are frame counter   
Set Variable \[$Frame ; MBS ("[Math.BitwiseAND](MathBitwiseAND.md)"; TimeStamp; 31)\]  
\# Seconds are in 2nd byte, so take 6 bits after shifting 8 to right   
Set Variable \[$Second ; MBS ( "[Math.BitwiseAND](MathBitwiseAND.md)"; MBS ( "[Math.BitwiseShiftRight](MathBitwiseShiftRight.md)"; TimeStamp; 8 ); 63) \]  
\# Minutes are in 3rd byte, so take 6 bits after shifting 16 to right   
Set Variable \[$Minute ; MBS ( "[Math.BitwiseAND](MathBitwiseAND.md)"; MBS ( "[Math.BitwiseShiftRight](MathBitwiseShiftRight.md)"; TimeStamp; 16 ); 63) \]  
\# Hours are in 4th byte: take 5 bits after shifting 24 to right   
Set Variable \[$Hour ; MBS ( "[Math.BitwiseAND](MathBitwiseAND.md)"; MBS ( "[Math.BitwiseShiftRight](MathBitwiseShiftRight.md)"; TimeStamp; 24 ); 31)\]  
### See also

- [Math.BitwiseAND](MathBitwiseAND.md)
- [Math.BitwiseShiftRight](MathBitwiseShiftRight.md)
- [PortMidi.Close](PortMidiClose.md)
- [PortMidi.OpenInput](PortMidiOpenInput.md)
- [PortMidi.OpenOutput](PortMidiOpenOutput.md)
- [PortMidi.SendMessage](PortMidiSendMessage.md)
- [PortMidi.SendMessageRaw](PortMidiSendMessageRaw.md)
- [PortMidi.SetDataAvailableEvaluate](PortMidiSetDataAvailableEvaluate.md)
- [PortMidi.SetDataAvailableHandler](PortMidiSetDataAvailableHandler.md)

### Example Databases

- [Midi/Midi Receive](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Midi/Midi%20Receive.shtml#3ScriptAnchor_)

This function checks for a license.

Created 18th August 2014 , last changed 25th February 2026

  
[PortMidi.Poll](PortMidiPoll.md) - [PortMidi.Rescan](PortMidiRescan.md)

[HTML Version](PortMidiReadMessage.shtml)