working controls
This commit is contained in:
parent
931626c47d
commit
27b7780c86
1 changed files with 54 additions and 20 deletions
74
node_2d.tscn
74
node_2d.tscn
|
|
@ -9,15 +9,46 @@ 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
|
||||
|
||||
|
||||
# here, put the same values as in game config
|
||||
# for example here it's configured for:
|
||||
# spin 1: Ch 2 Note 10, so put 2 and 10
|
||||
# spin 2: Ch 2 Note 9, so put 2 and 9
|
||||
# jog: Ch 2 Note 8, so put 2 and 8
|
||||
# beat: Ch 3 Note 8, so put 3 and 8
|
||||
var spin_channel_1: int = 2
|
||||
var spin_note_1: int = 10
|
||||
|
||||
var spin_channel_2: int = 2
|
||||
var spin_note_2: int = 9
|
||||
|
||||
var jog_channel: int = 2
|
||||
var jog_note: int = 8
|
||||
|
||||
var beat_channel: int = 3
|
||||
var beat_note: int = 8
|
||||
# end of config
|
||||
|
||||
|
||||
# init values
|
||||
var midi_beat: bool = false
|
||||
var midi_jog: bool = false
|
||||
var midi_turnleft: bool = false
|
||||
var midi_turnright: bool = false
|
||||
|
||||
var debug := false
|
||||
# if >0: print midi event to the console (1 for minimal logs, 2 for more logs)
|
||||
# if =0: the program acts normally
|
||||
const debug := 0
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
|
||||
# fix midi values (the game adds one to the chanels)
|
||||
spin_channel_1 -= 1
|
||||
spin_channel_2 -= 1
|
||||
jog_channel -= 1
|
||||
beat_channel -= 1
|
||||
|
||||
OS.open_midi_inputs()
|
||||
print(OS.get_connected_midi_inputs())
|
||||
|
||||
|
|
@ -27,7 +58,7 @@ func _unhandled_input(input_event):
|
|||
if input_event.keycode == KEY_ESCAPE:
|
||||
get_tree().quit()
|
||||
if input_event is InputEventMIDI:
|
||||
if debug:
|
||||
if debug > 0:
|
||||
_print_midi_info(input_event)
|
||||
if input_event.channel == 2 and input_event.message == 9:
|
||||
pass
|
||||
|
|
@ -35,31 +66,37 @@ func _unhandled_input(input_event):
|
|||
|
||||
func _input(input_event):
|
||||
if input_event is InputEventMIDI:
|
||||
if input_event.channel == 2 and (input_event.message == 9 or input_event.message == 11):
|
||||
if input_event.channel == beat_channel and ((input_event.pitch == beat_note and input_event.velocity == 127) or input_event.controller_number == 10):
|
||||
midi_beat = true
|
||||
if input_event.channel == 1 and (input_event.message == 9 or input_event.message == 11):
|
||||
if input_event.channel == beat_channel and ((input_event.pitch == beat_note and input_event.velocity == 0) or input_event.controller_number == 9):
|
||||
midi_beat = false
|
||||
if input_event.channel == jog_channel and ((input_event.pitch == jog_note and input_event.velocity == 127) or input_event.controller_number == spin_note_1):
|
||||
midi_jog = true
|
||||
if input_event.channel == 1 and input_event.controller_value == 127:
|
||||
if input_event.channel == jog_channel and ((input_event.pitch == jog_note and input_event.velocity == 0) or input_event.controller_number == spin_note_2):
|
||||
midi_jog = false
|
||||
if (input_event.channel == spin_channel_1 or input_event.channel == spin_channel_2) and input_event.controller_value == 127:
|
||||
midi_turnleft = true
|
||||
if input_event.channel == 1 and input_event.controller_value == 1:
|
||||
if (input_event.channel == spin_channel_1 or input_event.channel == spin_channel_2) 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))
|
||||
if debug > 1:
|
||||
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):
|
||||
|
||||
if !debug:
|
||||
if debug == 0:
|
||||
# process inputs
|
||||
if Input.is_action_pressed(\"quit\"):
|
||||
# exit the software
|
||||
|
|
@ -76,11 +113,8 @@ func _process(_delta):
|
|||
if midi_turnright:
|
||||
# trigger the right controller
|
||||
print(\"turn right\")
|
||||
|
||||
# reset inputs
|
||||
midi_beat = false
|
||||
midi_jog = false
|
||||
midi_turnleft= false
|
||||
|
||||
midi_turnleft = false
|
||||
midi_turnright = false
|
||||
"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue