InputEventMIDI

package
v0.0.0-...-357ca8a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 20, 2025 License: MIT Imports: 25 Imported by: 0

Documentation

Overview

InputEventMIDI stores information about messages from MIDI (Musical Instrument Digital Interface) devices. These may include musical keyboards, synthesizers, and drum machines.

MIDI messages can be received over a 5-pin MIDI connector or over USB. If your device supports both be sure to check the settings in the device to see which output it is using.

By default, Godot does not detect MIDI devices. You need to call OS.OpenMidiInputs, first. You can check which devices are detected with OS.GetConnectedMidiInputs, and close the connection with OS.CloseMidiInputs.

package main

import (
	"fmt"

	"graphics.gd/classdb/InputEvent"
	"graphics.gd/classdb/InputEventMIDI"
	"graphics.gd/classdb/Node"
	"graphics.gd/classdb/OS"
	"graphics.gd/variant/Object"
)

type MyMIDI struct {
	Node.Extension[MyMIDI]
}

func (n MyMIDI) Ready() {
	OS.OpenMidiInputs()
	fmt.Println(OS.GetConnectedMidiInputs())
}

func (n MyMIDI) Input(event InputEvent.Instance) {
	if event, ok := Object.As[InputEventMIDI.Instance](event); ok {
		fmt.Println(event)
		fmt.Println("Channel ", event.Channel())
		fmt.Println("Message ", event.Message())
		fmt.Println("Pitch ", event.Pitch())
		fmt.Println("Velocity ", event.Velocity())
		fmt.Println("Instrument ", event.Instrument())
		fmt.Println("Pressure ", event.Pressure())
		fmt.Println("Controller number: ", event.ControllerNumber())
		fmt.Println("Controller value: ", event.ControllerValue())
	}
}

Note: Godot does not support MIDI output, so there is no way to emit MIDI messages from Godot. Only MIDI input is supported.

Note: On the Web platform, using MIDI input requires a browser permission to be granted first. This permission request is performed when calling OS.OpenMidiInputs. MIDI input will not work until the user accepts the permission request.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Advanced

type Advanced = class

Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.

type Any

type Any interface {
	gd.IsClass
	AsInputEventMIDI() Instance
}

type Extension

type Extension[T gdclass.Interface] struct{ gdclass.Extension[T, Instance] }

Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this Extension

func (*Extension[T]) AsInputEvent

func (self *Extension[T]) AsInputEvent() InputEvent.Instance

func (*Extension[T]) AsInputEventMIDI

func (self *Extension[T]) AsInputEventMIDI() Instance

func (*Extension[T]) AsObject

func (self *Extension[T]) AsObject() [1]gd.Object

func (*Extension[T]) AsRefCounted

func (self *Extension[T]) AsRefCounted() [1]gd.RefCounted

func (*Extension[T]) AsResource

func (self *Extension[T]) AsResource() Resource.Instance

type ID

type ID Object.ID

ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.

func (ID) Instance

func (id ID) Instance() (Instance, bool)

type Instance

type Instance [1]gdclass.InputEventMIDI

Instance of the class with convieniently typed arguments and results.

var Nil Instance

Nil is a nil/null instance of the class. Equivalent to the zero value.

func New

func New() Instance

func (Instance) AsInputEvent

func (self Instance) AsInputEvent() InputEvent.Instance

func (Instance) AsInputEventMIDI

func (self Instance) AsInputEventMIDI() Instance

func (Instance) AsObject

func (self Instance) AsObject() [1]gd.Object

func (Instance) AsRefCounted

func (self Instance) AsRefCounted() [1]gd.RefCounted

func (Instance) AsResource

func (self Instance) AsResource() Resource.Instance

func (Instance) Channel

func (self Instance) Channel() int

The MIDI channel of this message, ranging from 0 to 15. MIDI channel 9 is reserved for percussion instruments.

func (Instance) ControllerNumber

func (self Instance) ControllerNumber() int

The unique number of the controller, if Message is MidiMessageControlChange, otherwise this is 0. This value can be used to identify sliders for volume, balance, and panning, as well as switches and pedals on the MIDI device. See the General MIDI specification for a small list.

func (Instance) ControllerValue

func (self Instance) ControllerValue() int

The value applied to the controller. If Message is MidiMessageControlChange, this value ranges from 0 to 127, otherwise it is 0. See also ControllerValue.

func (Instance) ID

func (self Instance) ID() ID

func (Instance) Instrument

func (self Instance) Instrument() int

The instrument (also called program or preset) used on this MIDI message. This value ranges from 0 to 127.

To see what each value means, refer to the General MIDI's instrument list. Keep in mind that the list is off by 1 because it does not begin from 0. A value of 0 corresponds to the acoustic grand piano.

func (Instance) Message

func (self Instance) Message() Message

Represents the type of MIDI message (see the [MIDIMessage] enum).

For more information, see the MIDI message status byte list chart.

func (Instance) Pitch

func (self Instance) Pitch() int

The pitch index number of this MIDI message. This value ranges from 0 to 127.

On a piano, the middle C is 60, followed by a C-sharp (61), then a D (62), and so on. Each octave is split in offsets of 12. See the "MIDI note number" column of the piano key frequency chart a full list.

func (Instance) Pressure

func (self Instance) Pressure() int

The strength of the key being pressed. This value ranges from 0 to 127.

Note: For many devices, this value is always 0. Other devices such as musical keyboards may simulate pressure by changing the Velocity, instead.

func (Instance) SetChannel

func (self Instance) SetChannel(value int)

SetChannel sets the property returned by [GetChannel].

func (Instance) SetControllerNumber

func (self Instance) SetControllerNumber(value int)

SetControllerNumber sets the property returned by [GetControllerNumber].

func (Instance) SetControllerValue

func (self Instance) SetControllerValue(value int)

SetControllerValue sets the property returned by [GetControllerValue].

func (Instance) SetInstrument

func (self Instance) SetInstrument(value int)

SetInstrument sets the property returned by [GetInstrument].

func (Instance) SetMessage

func (self Instance) SetMessage(value Message)

SetMessage sets the property returned by [GetMessage].

func (*Instance) SetObject

func (self *Instance) SetObject(obj [1]gd.Object) bool

func (Instance) SetPitch

func (self Instance) SetPitch(value int)

SetPitch sets the property returned by [GetPitch].

func (Instance) SetPressure

func (self Instance) SetPressure(value int)

SetPressure sets the property returned by [GetPressure].

func (Instance) SetVelocity

func (self Instance) SetVelocity(value int)

SetVelocity sets the property returned by [GetVelocity].

func (Instance) Velocity

func (self Instance) Velocity() int

The velocity of the MIDI message. This value ranges from 0 to 127. For a musical keyboard, this corresponds to how quickly the key was pressed, and is rarely above 110 in practice.

Note: Some MIDI devices may send a MidiMessageNoteOn message with 0 velocity and expect it to be treated the same as a MidiMessageNoteOff message. If necessary, this can be handled with a few lines of code:

func (Instance) Virtual

func (self Instance) Virtual(name string) reflect.Value

type Message

type Message int //gd:MIDIMessage
const (
	// Does not correspond to any MIDI message. This is the default value of [InputEventMIDI.Message].
	//
	// [InputEventMIDI.Message]: https://pkg.go.dev/graphics.gd/classdb/InputEventMIDI#Instance.Message
	MidiMessageNone Message = 0
	// MIDI message sent when a note is released.
	//
	// Note: Not all MIDI devices send this message; some may send [MidiMessageNoteOn] with [InputEventMIDI.Velocity] set to 0.
	//
	// [InputEventMIDI.Velocity]: https://pkg.go.dev/graphics.gd/classdb/InputEventMIDI#Instance.Velocity
	MidiMessageNoteOff Message = 8
	// MIDI message sent when a note is pressed.
	MidiMessageNoteOn Message = 9
	// MIDI message sent to indicate a change in pressure while a note is being pressed down, also called aftertouch.
	MidiMessageAftertouch Message = 10
	// MIDI message sent when a controller value changes. In a MIDI device, a controller is any input that doesn't play notes. These may include sliders for volume, balance, and panning, as well as switches and pedals. See the [General MIDI specification] for a small list.
	//
	// [General MIDI specification]: https://en.wikipedia.org/wiki/General_MIDI#Controller_events
	MidiMessageControlChange Message = 11
	// MIDI message sent when the MIDI device changes its current instrument (also called program or preset).
	MidiMessageProgramChange Message = 12
	// MIDI message sent to indicate a change in pressure for the whole channel. Some MIDI devices may send this instead of [MidiMessageAftertouch].
	MidiMessageChannelPressure Message = 13
	// MIDI message sent when the value of the pitch bender changes, usually a wheel on the MIDI device.
	MidiMessagePitchBend Message = 14
	// MIDI system exclusive (SysEx) message. This type of message is not standardized and it's highly dependent on the MIDI device sending it.
	//
	// Note: Getting this message's data from [InputEventMIDI] is not implemented.
	//
	// [InputEventMIDI]: https://pkg.go.dev/graphics.gd/classdb/InputEventMIDI
	MidiMessageSystemExclusive Message = 240
	// MIDI message sent every quarter frame to keep connected MIDI devices synchronized. Related to [MidiMessageTimingClock].
	//
	// Note: Getting this message's data from [InputEventMIDI] is not implemented.
	//
	// [InputEventMIDI]: https://pkg.go.dev/graphics.gd/classdb/InputEventMIDI
	MidiMessageQuarterFrame Message = 241
	// MIDI message sent to jump onto a new position in the current sequence or song.
	//
	// Note: Getting this message's data from [InputEventMIDI] is not implemented.
	//
	// [InputEventMIDI]: https://pkg.go.dev/graphics.gd/classdb/InputEventMIDI
	MidiMessageSongPositionPointer Message = 242
	// MIDI message sent to select a sequence or song to play.
	//
	// Note: Getting this message's data from [InputEventMIDI] is not implemented.
	//
	// [InputEventMIDI]: https://pkg.go.dev/graphics.gd/classdb/InputEventMIDI
	MidiMessageSongSelect Message = 243
	// MIDI message sent to request a tuning calibration. Used on analog synthesizers. Most modern MIDI devices do not need this message.
	MidiMessageTuneRequest Message = 246
	// MIDI message sent 24 times after [MidiMessageQuarterFrame], to keep connected MIDI devices synchronized.
	MidiMessageTimingClock Message = 248
	// MIDI message sent to start the current sequence or song from the beginning.
	MidiMessageStart Message = 250
	// MIDI message sent to resume from the point the current sequence or song was paused.
	MidiMessageContinue Message = 251
	// MIDI message sent to pause the current sequence or song.
	MidiMessageStop Message = 252
	// MIDI message sent repeatedly while the MIDI device is idle, to tell the receiver that the connection is alive. Most MIDI devices do not send this message.
	MidiMessageActiveSensing Message = 254
	// MIDI message sent to reset a MIDI device to its default state, as if it was just turned on. It should not be sent when the MIDI device is being turned on.
	MidiMessageSystemReset Message = 255
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL