functionnable midi proto
This commit is contained in:
parent
98d5e494b7
commit
931626c47d
4 changed files with 208 additions and 16 deletions
75
node_2d.tscn
75
node_2d.tscn
|
|
@ -9,6 +9,12 @@ script/source = "extends Node2D
|
|||
# https://docs.godotengine.org/en/stable/classes/class_inputeventmidi.html
|
||||
# https://docs.godotengine.org/en/stable/classes/class_%40globalscope.html#enum-globalscope-midimessage
|
||||
|
||||
var midi_beat: bool = false
|
||||
var midi_jog: bool = false
|
||||
var midi_turnleft: bool = false
|
||||
var midi_turnright: bool = false
|
||||
|
||||
var debug := false
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
|
|
@ -16,25 +22,66 @@ func _ready():
|
|||
print(OS.get_connected_midi_inputs())
|
||||
|
||||
|
||||
func _unhandled_input(event):
|
||||
if event is InputEventKey:
|
||||
if event.keycode == KEY_ESCAPE:
|
||||
func _unhandled_input(input_event):
|
||||
if input_event is InputEventKey:
|
||||
if input_event.keycode == KEY_ESCAPE:
|
||||
get_tree().quit()
|
||||
if input_event is InputEventMIDI:
|
||||
if debug:
|
||||
_print_midi_info(input_event)
|
||||
if input_event.channel == 2 and input_event.message == 9:
|
||||
pass
|
||||
|
||||
|
||||
func _input(input_event):
|
||||
if input_event is InputEventMIDI:
|
||||
if input_event.channel == 2 and (input_event.message == 9 or input_event.message == 11):
|
||||
midi_beat = true
|
||||
if input_event.channel == 1 and (input_event.message == 9 or input_event.message == 11):
|
||||
midi_jog = true
|
||||
if input_event.channel == 1 and input_event.controller_value == 127:
|
||||
midi_turnleft = true
|
||||
if input_event.channel == 1 and input_event.controller_value == 1:
|
||||
midi_turnright = true
|
||||
|
||||
func _print_midi_info(midi_event: InputEventMIDI):
|
||||
print(midi_event)
|
||||
print(\"Channel \" + str(midi_event.channel))
|
||||
print(\"Message \" + str(midi_event.message))
|
||||
print(\"Pitch \" + str(midi_event.pitch))
|
||||
print(\"Velocity \" + str(midi_event.velocity))
|
||||
print(\"Instrument \" + str(midi_event.instrument))
|
||||
print(\"Pressure \" + str(midi_event.pressure))
|
||||
print(\"Controller number: \" + str(midi_event.controller_number))
|
||||
print(\"Controller value: \" + str(midi_event.controller_value))
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(_delta):
|
||||
|
||||
# process inputs
|
||||
if Input.is_action_pressed(\"quit\"):
|
||||
# exit the software
|
||||
get_tree().quit()
|
||||
if Input.is_action_pressed(\"left\") or MIDIMessage.MIDI_MESSAGE_CONTROL_CHANGE == 1:
|
||||
# trigger the left controller
|
||||
print(\"left\")
|
||||
if Input.is_action_pressed(\"right\") or MIDIMessage.MIDI_MESSAGE_CONTROL_CHANGE == 1:
|
||||
# trigger the right controller
|
||||
print(\"right\")
|
||||
|
||||
if !debug:
|
||||
# process inputs
|
||||
if Input.is_action_pressed(\"quit\"):
|
||||
# exit the software
|
||||
get_tree().quit()
|
||||
if Input.is_action_pressed(\"left\") or midi_beat:
|
||||
# trigger the left controller
|
||||
print(\"left\")
|
||||
if Input.is_action_pressed(\"right\") or midi_jog:
|
||||
# trigger the right controller
|
||||
print(\"right\")
|
||||
if midi_turnleft:
|
||||
# trigger the left controller
|
||||
print(\"turn left\")
|
||||
if midi_turnright:
|
||||
# trigger the right controller
|
||||
print(\"turn right\")
|
||||
|
||||
# reset inputs
|
||||
midi_beat = false
|
||||
midi_jog = false
|
||||
midi_turnleft= false
|
||||
midi_turnright = false
|
||||
"
|
||||
|
||||
[node name="Node2D" type="Node2D"]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue