InputEventMIDI

package
v0.0.0-...-fa94a0d Latest Latest
Warning

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

Go to latest
Published: Sep 18, 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

func (Instance) ControllerNumber

func (self Instance) ControllerNumber() int

func (Instance) ControllerValue

func (self Instance) ControllerValue() int

func (Instance) ID

func (self Instance) ID() ID

func (Instance) Instrument

func (self Instance) Instrument() int

func (Instance) Message

func (self Instance) Message() Message

func (Instance) Pitch

func (self Instance) Pitch() int

func (Instance) Pressure

func (self Instance) Pressure() int

func (Instance) SetChannel

func (self Instance) SetChannel(value int)

func (Instance) SetControllerNumber

func (self Instance) SetControllerNumber(value int)

func (Instance) SetControllerValue

func (self Instance) SetControllerValue(value int)

func (Instance) SetInstrument

func (self Instance) SetInstrument(value int)

func (Instance) SetMessage

func (self Instance) SetMessage(value Message)

func (*Instance) SetObject

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

func (Instance) SetPitch

func (self Instance) SetPitch(value int)

func (Instance) SetPressure

func (self Instance) SetPressure(value int)

func (Instance) SetVelocity

func (self Instance) SetVelocity(value int)

func (Instance) Velocity

func (self Instance) Velocity() int

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