Midi.Output.Message Class

 

About Midi.Output.Message Class

 

Midi.Output.Message class is mainly used for sending MIDI Messages to MIDI Output devices.

 

Midi.Output.Message Class Methods

 

Midi.Output.Message.Clear() clears the MIDI Message Buffer. This function removes all bytes previously stored in the MIDI Message Buffer.

 

Midi.Output.Message.Size() returns the amount of bytes stored in the MIDI Message Buffer.

 

Midi.Output.Message.Byte( byte Byte ) Adds one byte to the MIDI Message Buffer.

byte Byte: value from 0 to 255.

 

Midi.Output.Message.Send( uint DeviceIndex ) sends the MIDI Message Buffer previously created with Midi.Output.Message.* functions to the specified MIDI Output device.

uint DeviceIndex: zero-based index of the device.

 

Midi.Output.Message.SendShort( uint DeviceIndex, byte Byte1, byte Byte2, byte Byte3 ) sends a Short MIDI Message Buffer (up to 3 bytes) to the specified MIDI Output device. This function has lower latency. Most MIDI Messages require up to 3 bytes (except for System Exclusive MIDI Messages). If the MIDI Message requires only 2 bytes, set the Byte3 argument to 0.

uint DeviceIndex: zero-based index of the device.
byte Byte1: first byte.
byte Byte2: second byte.
byte Byte3: third byte.

 

Code Example

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Giavapps.MIDI;

public class CodeExample : MonoBehaviour
{

void Awake()
{
Midi.Output.Device.Open(0);//Opens the first MIDI Output Device ("Microsoft GS Wavetable Synth" by default on Windows)
}

void Update()
{

//Checks if space key is pressed
if
(Input.GetKeyDown(KeyCode.Space))
{
//NOTE C5 ON – CHANNEL 1 – VELOCITY 100
Midi.Output.Message.Clear();//Clears the MIDI Message buffer
Midi.Output.Message.Byte(144);//Adds one byte to the MIDI Message buffer
Midi.Output.Message.Byte(60);//Adds one byte to the MIDI Message buffer
Midi.Output.Message.Byte(100);//Adds one byte to the MIDI Message buffer
Midi.Output.Message.Send(0);//Sends the MIDI Message to the MIDI Output Device
}
//Checks if space key is released
else if
(Input.GetKeyUp(KeyCode.Space))
{
//NOTE C5 OFF – CHANNEL 1 – VELOCITY 0
Midi.Output.Message.Clear();//Clears the MIDI Message buffer
Midi.Output.Message.Byte(128);//Adds one byte to the MIDI Message buffer
Midi.Output.Message.Byte(60);//Adds one byte to the MIDI Message buffer
Midi.Output.Message.Byte(0);//Adds one byte to the MIDI Message buffer
Midi.Output.Message.Send(0);//Sends the MIDI Message to the MIDI Output Device
}

//Checks if return key is pressed
if
(Input.GetKeyDown(KeyCode.Return))
{
//NOTE C5 ON – CHANNEL 1 – VELOCITY 100
Midi.Output.Message.SendShort(0, 144, 60, 100);//Sends the Short MIDI Message to the MIDI Output Device
}
//Checks if return key is released
else if
(Input.GetKeyUp(KeyCode.Return))
{
//NOTE C5 OFF – CHANNEL 1 – VELOCITY 0
Midi.Output.Message.SendShort(0, 128, 60, 0);//Sends the Short MIDI Message to the MIDI Output Device
}

}

void OnApplicationQuit()
{
Midi.Deinitialize();//Deinitializes Midi
}

}

 

I am Luigi Piscopo, also known as DJ GiDeejay / Producer / Remixer in the music world. I am a Producer with a lot of experience in photo editing, video editing, audio editing, graphic design, web design, programming and promotion.

Comments are closed.