diff --git a/scenes/main.gd b/scenes/main.gd index d71bb6b..aa5a678 100644 --- a/scenes/main.gd +++ b/scenes/main.gd @@ -32,16 +32,18 @@ func _ready(): playback = $Player.get_stream_playback() fill_buffer() + if OS.get_name() != "Web": + OS.open_midi_inputs() + print(OS.get_connected_midi_inputs()) + else: + %MidiButton.visible = true + if multiplayer_enabled: %MultiplayerButton.visible = true if Utils.get_external_freq_param(): print("Direct connect to external freq: ", Utils.get_external_freq_param()) _on_multiplayer_button_pressed() - - # FIXME: make this dependent on button - OS.open_midi_inputs() - print(OS.get_connected_midi_inputs()) func set_morse_state(state: bool): MorseState.set_state(state) @@ -163,3 +165,8 @@ func _on_reset_button_pressed() -> void: func _on_multiplayer_button_pressed() -> void: get_tree().change_scene_to_file("res://scenes/MultiplayerConnect.tscn") + + +func _on_midi_button_pressed() -> void: + OS.open_midi_inputs() + print(OS.get_connected_midi_inputs()) diff --git a/scenes/main.tscn b/scenes/main.tscn index 94699ae..128742c 100644 --- a/scenes/main.tscn +++ b/scenes/main.tscn @@ -64,6 +64,14 @@ text = "Save Wav" layout_mode = 2 size_flags_vertical = 3 +[node name="MidiButton" type="Button" parent="VBoxContainer/HBoxContainer"] +unique_name_in_owner = true +visible = false +layout_mode = 2 +size_flags_stretch_ratio = 0.25 +text = "Open +Midi" + [node name="ResetButton" type="Button" parent="VBoxContainer/HBoxContainer"] layout_mode = 2 size_flags_horizontal = 3 @@ -89,5 +97,6 @@ script = ExtResource("3_sugp2") [connection signal="button_down" from="VBoxContainer/MorseButton" to="." method="_on_morse_button_down"] [connection signal="button_up" from="VBoxContainer/MorseButton" to="." method="_on_morse_button_up"] [connection signal="pressed" from="VBoxContainer/WavButton" to="." method="_on_wav_button_pressed"] +[connection signal="pressed" from="VBoxContainer/HBoxContainer/MidiButton" to="." method="_on_midi_button_pressed"] [connection signal="pressed" from="VBoxContainer/HBoxContainer/ResetButton" to="." method="_on_reset_button_pressed"] [connection signal="pressed" from="VBoxContainer/HBoxContainer/MultiplayerButton" to="." method="_on_multiplayer_button_pressed"] diff --git a/scenes/multiplayer_connect.gd b/scenes/multiplayer_connect.gd index 13a5229..fab6f27 100644 --- a/scenes/multiplayer_connect.gd +++ b/scenes/multiplayer_connect.gd @@ -225,6 +225,20 @@ func _on_morse_button_button_up() -> void: return set_morse_state(false) +func _input(input_event): + if input_event is InputEventMIDI: + _process_midi_event(input_event) + +func _process_midi_event(midi_event): + if not mmb_self: + return + + if midi_event.channel in [0, 9]: + if midi_event.message == MIDI_MESSAGE_NOTE_ON: + set_morse_state(true) + elif midi_event.message == MIDI_MESSAGE_NOTE_OFF: + set_morse_state(false) + func _on_leave_button_pressed() -> void: send_data({"cmd": "leave"})