PortMidi.SetDataAvailableHandler
--------------------------------

Sets the data available handler for this midi port.

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

MBS( "PortMidi.SetDataAvailableHandler"; StreamRef; FileName; ScriptName ) 

**MBS**( **"PortMidi.SetDataAvailableHandler";** /\* Sets the data available handler for this midi port. \*/  
**$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 \*/   
**$FileName**; /\* The name of the FileMaker File that contains the scripte.g. "MyDatabase.fp7" \*/   
**$ScriptName**) /\* The name of the script to rune.g. "DataAvailable" \*/ 

### 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 |
| FileName | The name of the FileMaker File that contains the script | "MyDatabase.fp7" |
| ScriptName | The name of the script to run | "DataAvailable" |

### Result

Returns OK or error.

### Description

Sets the data available handler for this midi port.  
When new data arrives, this script is called, so you can call [PortMidi.ReadMessage](PortMidiReadMessage.md) function.  
Be aware that script may be called when just a few notes are in the read buffer.  
### Examples

Set script to be triggered if data is available:

 Set Variable \[$r ; Value:MBS ("PortMidi.SetDataAvailableHandler"; $$port ; Get(FileName); "ReadMessage")\]  
### See also

- [PortMidi.ClearDataAvailableHandler](PortMidiClearDataAvailableHandler.md)
- [PortMidi.Close](PortMidiClose.md)
- [PortMidi.OpenInput](PortMidiOpenInput.md)
- [PortMidi.OpenOutput](PortMidiOpenOutput.md)
- [PortMidi.ReadMessage](PortMidiReadMessage.md)
- [PortMidi.SetDataAvailableEvaluate](PortMidiSetDataAvailableEvaluate.md)
- [SerialPort.SetDataAvailableHandler](SerialPortSetDataAvailableHandler.md)
- [Socket.SetDataAvailableHandler](SocketSetDataAvailableHandler.md)

### Release notes

- **Version 8.5**
    - Added [PortMidi.ClearDataAvailableHandler](http://www.mbsplugins.eu/PortMidiClearDataAvailableHandler.shtml), [PortMidi.SetDataAvailableEvaluate](http://www.mbsplugins.eu/PortMidiSetDataAvailableEvaluate.shtml) and [PortMidi.SetDataAvailableHandler](http://www.mbsplugins.eu/PortMidiSetDataAvailableHandler.shtml).

### Blog Entries

- [MBS FileMaker Plugin, version 8.5pr9](https://www.mbsplugins.de/archive/2018-11-24/MBS_FileMaker_Plugin_version_8/monkeybreadsoftware_blog_filemaker)

This function checks for a license.

Created 24th November 2018 , last changed 26th November 2018

  
[PortMidi.SetDataAvailableEvaluate](PortMidiSetDataAvailableEvaluate.md) - [PortMidi.SetFilter](PortMidiSetFilter.md)

[HTML Version](PortMidiSetDataAvailableHandler.shtml)