CsoundUnity 4.0.0-alpha.3
Loading...
Searching...
No Matches
Csound.Unity.CsoundUnityMidiInput Class Reference

Platform-agnostic MIDI input component for CsoundUnity. Add this component to the same GameObject as CsoundUnity (or assign the CsoundUnity reference in the inspector). Make sure the CSD has <CsOptions> -M0 </CsOptions> to activate Csound's MIDI subsystem. More...

Inheritance diagram for Csound.Unity.CsoundUnityMidiInput:

Public Member Functions

void RestartMidiInput ()
 Restarts MIDI input, applying any filter changes made at runtime. Equivalent to disabling and re-enabling the component.

Public Attributes

CsoundUnity csoundUnity
 The instance that receives the MIDI messages. When left empty, the CsoundUnity on this GameObject is used.

Properties

string[] IncludeOnlySourcesContaining [get, set]
 (macOS / iOS / visionOS / Windows) If non-empty, ONLY MIDI sources whose name contains at least one of these substrings (case-insensitive) will be connected. Takes priority over ExcludeSourcesContaining. Call before the component is enabled, or restart MIDI input after changing. Example: set to new[]{"Port 1"} to use only the first port of a keyboard that exposes multiple ports (e.g. Novation SL MkII).
string[] ExcludeSourcesContaining [get, set]
 (macOS / iOS / visionOS / Windows) MIDI sources whose name contains any of these substrings (case-insensitive) will be ignored. Ignored when IncludeOnlySourcesContaining is non-empty. Call before the component is enabled, or restart MIDI input after changing.

Events

Action< int, int, int > NoteOn
 Fired on a MIDI Note On. Args: channel (1-16), note (0-127), velocity (1-127).
Action< int, int, int > NoteOff
 Fired on a MIDI Note Off (or Note On with velocity 0). Args: channel (1-16), note (0-127), velocity (0-127).
Action< int, int, int > ControlChange
 Fired on a MIDI Control Change. Args: channel (1-16), controller (0-127), value (0-127).
Action< int, int > ProgramChange
 Fired on a MIDI Program Change. Args: channel (1-16), program (0-127).

Detailed Description

Platform-agnostic MIDI input component for CsoundUnity. Add this component to the same GameObject as CsoundUnity (or assign the CsoundUnity reference in the inspector). Make sure the CSD has <CsOptions> -M0 </CsOptions> to activate Csound's MIDI subsystem.

Platform support: macOS / iOS / visionOS — CoreMIDI (USB, BLE, Network MIDI); Android — android.media.midi (USB + BLE, API 23+); Windows — WinMM (short MIDI messages; SysEx not supported); WebGL — Web MIDI API (Chrome/Edge, HTTPS).

On Android and WebGL the backend delivers messages with UnitySendMessage, which addresses a GameObject by name: with two of them named the same, every message goes to the first one Unity finds and the other receives nothing. Give each GameObject carrying this component a distinct name. CoreMIDI and WinMM address the receiver directly.

In addition to forwarding messages to Csound, this component fires C# events (NoteOn, NoteOff, ControlChange, ProgramChange) that any other script can subscribe to for non-Csound purposes.

Member Function Documentation

◆ RestartMidiInput()

void Csound.Unity.CsoundUnityMidiInput.RestartMidiInput ( )
inline

Restarts MIDI input, applying any filter changes made at runtime. Equivalent to disabling and re-enabling the component.

Member Data Documentation

◆ csoundUnity

CsoundUnity Csound.Unity.CsoundUnityMidiInput.csoundUnity

The instance that receives the MIDI messages. When left empty, the CsoundUnity on this GameObject is used.

Property Documentation

◆ ExcludeSourcesContaining

string [] Csound.Unity.CsoundUnityMidiInput.ExcludeSourcesContaining
getset

(macOS / iOS / visionOS / Windows) MIDI sources whose name contains any of these substrings (case-insensitive) will be ignored. Ignored when IncludeOnlySourcesContaining is non-empty. Call before the component is enabled, or restart MIDI input after changing.

◆ IncludeOnlySourcesContaining

string [] Csound.Unity.CsoundUnityMidiInput.IncludeOnlySourcesContaining
getset

(macOS / iOS / visionOS / Windows) If non-empty, ONLY MIDI sources whose name contains at least one of these substrings (case-insensitive) will be connected. Takes priority over ExcludeSourcesContaining. Call before the component is enabled, or restart MIDI input after changing. Example: set to new[]{"Port 1"} to use only the first port of a keyboard that exposes multiple ports (e.g. Novation SL MkII).

Event Documentation

◆ ControlChange

Action<int, int, int> Csound.Unity.CsoundUnityMidiInput.ControlChange

Fired on a MIDI Control Change. Args: channel (1-16), controller (0-127), value (0-127).

◆ NoteOff

Action<int, int, int> Csound.Unity.CsoundUnityMidiInput.NoteOff

Fired on a MIDI Note Off (or Note On with velocity 0). Args: channel (1-16), note (0-127), velocity (0-127).

◆ NoteOn

Action<int, int, int> Csound.Unity.CsoundUnityMidiInput.NoteOn

Fired on a MIDI Note On. Args: channel (1-16), note (0-127), velocity (1-127).

◆ ProgramChange

Action<int, int> Csound.Unity.CsoundUnityMidiInput.ProgramChange

Fired on a MIDI Program Change. Args: channel (1-16), program (0-127).


The documentation for this class was generated from the following file: