PortMidi.SendMessage
--------------------

Sends a midi message.

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

MBS( "PortMidi.SendMessage"; StreamRef; Status; Data1; Data2 { ; TimeStamp } ) 

**MBS**( **"PortMidi.SendMessage";** /\* Sends a midi message. \*/  
**$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 \*/   
**$Status**; /\* The Midi status code.e.g. 144 \*/   
**$Data1**; /\* The first data byte.e.g. 4\*12+0 \*/   
**$Data2**; /\* The second data bytes.e.g. 127 \*/   
**$TimeStamp**) /\* Optional; The timestamp. If zero or not provided, note is sent immediately. e.g. 0 \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| 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 |  |
| Status | The Midi status code. | 144 |  |
| Data1 | The first data byte. | 4\*12+0 |  |
| Data2 | The second data bytes. | 127 |  |
| TimeStamp | The timestamp. If zero or not provided, note is sent immediately. | 0 | Optional |

### Result

Returns OK or error.

### Description

Sends a midi message.  
The Status is the command code. 144 is note on and 128 is note off. For those note commands Data1 is the number of the note. 48 (4\*12) is C2 and then you can count over all notes till you get to next octave with C3 (5\*12).  
### Examples

Press down a C note:

 MBS ( "PortMidi.SendMessage"; $StreamRef ; 144; 4\*12+0; 127 )  
Release a C note:

 MBS ( "PortMidi.SendMessage"; $StreamRef ; 128; 4\*12+0; 127 )  
### See also

- [PortMidi.Close](PortMidiClose.md)
- [PortMidi.OpenInput](PortMidiOpenInput.md)
- [PortMidi.OpenOutput](PortMidiOpenOutput.md)
- [PortMidi.ReadMessage](PortMidiReadMessage.md)
- [PortMidi.SendMessageRaw](PortMidiSendMessageRaw.md)
- [Socket.SendMessage](SocketSendMessage.md)

### Example Databases

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

This function checks for a license.

Created 18th August 2014 , last changed 3th April 2021

  
[PortMidi.Rescan](PortMidiRescan.md) - [PortMidi.SendMessageRaw](PortMidiSendMessageRaw.md)

[HTML Version](PortMidiSendMessage.shtml)