From 4aeba8ea69a9f401139f472fee5d220b5f0a59b2 Mon Sep 17 00:00:00 2001 From: Christopher Arndt Date: Sat, 4 Nov 2023 23:45:43 +0100 Subject: [PATCH] Android export and various tweaks Signed-off-by: Christopher Arndt --- UI.tscn | 6 +- export_presets.cfg | 202 +++++++++++++++++++++++++++++++++++++++++++++ osc_receiver.gd | 6 +- osc_sender.gd | 17 ++-- project.godot | 13 ++- slider.gd | 8 +- testosc.sh | 6 +- toggle_button.gd | 8 +- ui.gd | 43 +++++++--- 9 files changed, 270 insertions(+), 39 deletions(-) diff --git a/UI.tscn b/UI.tscn index ab42bf3..3066733 100644 --- a/UI.tscn +++ b/UI.tscn @@ -24,6 +24,8 @@ anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 script = ExtResource("1_28t32") +osc_dest_port = 9001 +debug = true [node name="MarginContainer" type="MarginContainer" parent="."] layout_mode = 1 @@ -39,8 +41,8 @@ theme_override_constants/margin_bottom = 20 [node name="GridContainer" type="GridContainer" parent="MarginContainer"] layout_mode = 2 -theme_override_constants/h_separation = 10 -theme_override_constants/v_separation = 10 +theme_override_constants/h_separation = 15 +theme_override_constants/v_separation = 25 columns = 4 [node name="VSlider1" type="VSlider" parent="MarginContainer/GridContainer"] diff --git a/export_presets.cfg b/export_presets.cfg index 1a2dc01..efb7152 100644 --- a/export_presets.cfg +++ b/export_presets.cfg @@ -37,3 +37,205 @@ unzip -o -q \"{temp_dir}/{archive_name}\" -d \"{temp_dir}\" ssh_remote_deploy/cleanup_script="#!/usr/bin/env bash kill $(pgrep -x -f \"{temp_dir}/{exe_name} {cmd_args}\") rm -rf \"{temp_dir}\"" + +[preset.1] + +name="Android" +platform="Android" +runnable=true +dedicated_server=false +custom_features="" +export_filter="all_resources" +include_filter="" +exclude_filter="" +export_path="export/de.chrisarndt.osc_demo.apk" +encryption_include_filters="" +encryption_exclude_filters="" +encrypt_pck=false +encrypt_directory=false + +[preset.1.options] + +custom_template/debug="" +custom_template/release="" +gradle_build/use_gradle_build=false +gradle_build/export_format=0 +gradle_build/min_sdk="" +gradle_build/target_sdk="" +architectures/armeabi-v7a=false +architectures/arm64-v8a=true +architectures/x86=false +architectures/x86_64=false +version/code=1 +version/name="1.0" +package/unique_name="de.chrisarndt.osc_demo" +package/name="OSC Demo" +package/signed=true +package/app_category=0 +package/retain_data_on_uninstall=false +package/exclude_from_recents=false +launcher_icons/main_192x192="" +launcher_icons/adaptive_foreground_432x432="" +launcher_icons/adaptive_background_432x432="" +graphics/opengl_debug=false +xr_features/xr_mode=0 +xr_features/hand_tracking=0 +xr_features/hand_tracking_frequency=0 +xr_features/passthrough=0 +screen/immersive_mode=true +screen/support_small=true +screen/support_normal=true +screen/support_large=true +screen/support_xlarge=true +user_data_backup/allow=false +command_line/extra_args="" +apk_expansion/enable=false +apk_expansion/SALT="" +apk_expansion/public_key="" +permissions/custom_permissions=PackedStringArray() +permissions/access_checkin_properties=false +permissions/access_coarse_location=false +permissions/access_fine_location=false +permissions/access_location_extra_commands=false +permissions/access_mock_location=false +permissions/access_network_state=true +permissions/access_surface_flinger=false +permissions/access_wifi_state=false +permissions/account_manager=false +permissions/add_voicemail=false +permissions/authenticate_accounts=false +permissions/battery_stats=false +permissions/bind_accessibility_service=false +permissions/bind_appwidget=false +permissions/bind_device_admin=false +permissions/bind_input_method=false +permissions/bind_nfc_service=false +permissions/bind_notification_listener_service=false +permissions/bind_print_service=false +permissions/bind_remoteviews=false +permissions/bind_text_service=false +permissions/bind_vpn_service=false +permissions/bind_wallpaper=false +permissions/bluetooth=false +permissions/bluetooth_admin=false +permissions/bluetooth_privileged=false +permissions/brick=false +permissions/broadcast_package_removed=false +permissions/broadcast_sms=false +permissions/broadcast_sticky=false +permissions/broadcast_wap_push=false +permissions/call_phone=false +permissions/call_privileged=false +permissions/camera=false +permissions/capture_audio_output=false +permissions/capture_secure_video_output=false +permissions/capture_video_output=false +permissions/change_component_enabled_state=false +permissions/change_configuration=false +permissions/change_network_state=false +permissions/change_wifi_multicast_state=false +permissions/change_wifi_state=false +permissions/clear_app_cache=false +permissions/clear_app_user_data=false +permissions/control_location_updates=false +permissions/delete_cache_files=false +permissions/delete_packages=false +permissions/device_power=false +permissions/diagnostic=false +permissions/disable_keyguard=false +permissions/dump=false +permissions/expand_status_bar=false +permissions/factory_test=false +permissions/flashlight=false +permissions/force_back=false +permissions/get_accounts=false +permissions/get_package_size=false +permissions/get_tasks=false +permissions/get_top_activity_info=false +permissions/global_search=false +permissions/hardware_test=false +permissions/inject_events=false +permissions/install_location_provider=false +permissions/install_packages=false +permissions/install_shortcut=false +permissions/internal_system_window=false +permissions/internet=true +permissions/kill_background_processes=false +permissions/location_hardware=false +permissions/manage_accounts=false +permissions/manage_app_tokens=false +permissions/manage_documents=false +permissions/manage_external_storage=false +permissions/master_clear=false +permissions/media_content_control=false +permissions/modify_audio_settings=false +permissions/modify_phone_state=false +permissions/mount_format_filesystems=false +permissions/mount_unmount_filesystems=false +permissions/nfc=false +permissions/persistent_activity=false +permissions/process_outgoing_calls=false +permissions/read_calendar=false +permissions/read_call_log=false +permissions/read_contacts=false +permissions/read_external_storage=false +permissions/read_frame_buffer=false +permissions/read_history_bookmarks=false +permissions/read_input_state=false +permissions/read_logs=false +permissions/read_phone_state=false +permissions/read_profile=false +permissions/read_sms=false +permissions/read_social_stream=false +permissions/read_sync_settings=false +permissions/read_sync_stats=false +permissions/read_user_dictionary=false +permissions/reboot=false +permissions/receive_boot_completed=false +permissions/receive_mms=false +permissions/receive_sms=false +permissions/receive_wap_push=false +permissions/record_audio=false +permissions/reorder_tasks=false +permissions/restart_packages=false +permissions/send_respond_via_message=false +permissions/send_sms=false +permissions/set_activity_watcher=false +permissions/set_alarm=false +permissions/set_always_finish=false +permissions/set_animation_scale=false +permissions/set_debug_app=false +permissions/set_orientation=false +permissions/set_pointer_speed=false +permissions/set_preferred_applications=false +permissions/set_process_limit=false +permissions/set_time=false +permissions/set_time_zone=false +permissions/set_wallpaper=false +permissions/set_wallpaper_hints=false +permissions/signal_persistent_processes=false +permissions/status_bar=false +permissions/subscribed_feeds_read=false +permissions/subscribed_feeds_write=false +permissions/system_alert_window=false +permissions/transmit_ir=false +permissions/uninstall_shortcut=false +permissions/update_device_stats=false +permissions/use_credentials=false +permissions/use_sip=false +permissions/vibrate=false +permissions/wake_lock=false +permissions/write_apn_settings=false +permissions/write_calendar=false +permissions/write_call_log=false +permissions/write_contacts=false +permissions/write_external_storage=false +permissions/write_gservices=false +permissions/write_history_bookmarks=false +permissions/write_profile=false +permissions/write_secure_settings=false +permissions/write_settings=false +permissions/write_sms=false +permissions/write_social_stream=false +permissions/write_sync_settings=false +permissions/write_user_dictionary=false diff --git a/osc_receiver.gd b/osc_receiver.gd index 566f318..9feaf32 100644 --- a/osc_receiver.gd +++ b/osc_receiver.gd @@ -3,7 +3,7 @@ extends Node class_name OSCReceiver -@export var default_address:String = "0.0.0.0" +@export var default_address:String = "*" @export var default_port: int = 9001 @export var poll_interval: float = 0.05 @export var debug: bool = false @@ -33,10 +33,10 @@ func register_callback(oscaddress, argtypes, callback): _observers[[oscaddress, argtypes]].append(callback) -func start_server(address:String = default_address, port:int = default_port): +func start_server(port:int = default_port, bind_address:String = default_address): _server = UDPServer.new() - if _server.listen(port, address) != OK: + if _server.listen(port, bind_address) != OK: _debug("OSCReceiver could not bind to port: %s" % port) else: _debug("OSCReceiver listening on port: %s" % port) diff --git a/osc_sender.gd b/osc_sender.gd index 9dcb009..b907569 100644 --- a/osc_sender.gd +++ b/osc_sender.gd @@ -3,17 +3,18 @@ extends Node class_name OSCSender -@export var default_address:String = "0.0.0.0" -@export var default_port: int = 9001 +@export var default_address:String = "127.0.0.1" +@export var default_port: int = 9000 @export var debug: bool = false var _address: String var _port: int -var socket = PacketPeerUDP.new() +var _socket = PacketPeerUDP.new() func _init(): _address = default_address _port = default_port + _socket.set_dest_address(_address, _port) func _debug(msg): @@ -23,18 +24,18 @@ func _debug(msg): func set_destination(dest): if dest is int: - socket.set_dest_address(_address, dest) + _socket.set_dest_address(_address, dest) _port = dest elif dest is String: - socket.set_dest_address(dest, _port) + _socket.set_dest_address(dest, _port) _address = dest elif dest is Array: - socket.set_dest_address(dest[0], dest[1]) + _socket.set_dest_address(dest[0], dest[1]) _address = dest[0] _port = dest[1] -func send_osc(dest, oscaddress: String, argtypes: String, values: Array): +func send_osc(oscaddress: String, argtypes: String, values: Array, dest = null): assert(oscaddress.begins_with("/")) var buf = StreamPeerBuffer.new() buf.set_big_endian(true) @@ -79,7 +80,7 @@ func send_osc(dest, oscaddress: String, argtypes: String, values: Array): if dest != null: set_destination(dest) - socket.put_packet(buf.get_data_array()) + _socket.put_packet(buf.get_data_array()) return OK diff --git a/project.godot b/project.godot index 7e1dae7..bc89283 100644 --- a/project.godot +++ b/project.godot @@ -13,6 +13,7 @@ config_version=5 config/name="OSC Demo" run/main_scene="res://UI.tscn" config/features=PackedStringArray("4.1") +boot_splash/bg_color=Color(0.141176, 0.141176, 0.141176, 1) [debug] @@ -20,9 +21,17 @@ settings/fps/force_fps=30 [display] -window/size/viewport_width=300 -window/size/viewport_height=400 +window/size/viewport_width=362 +window/size/viewport_height=800 +window/stretch/mode="canvas_items" +window/handheld/orientation=1 + +[input_devices] + +pointing/emulate_touch_from_mouse=true [rendering] +renderer/rendering_method="mobile" +textures/vram_compression/import_etc2_astc=true environment/default_environment="res://default_env.tres" diff --git a/slider.gd b/slider.gd index 8f78e9a..94de797 100644 --- a/slider.gd +++ b/slider.gd @@ -2,8 +2,8 @@ extends VSlider func recv_osc(msg_info, values): - print("Sender IP: %s" % msg_info["ip"]) - print("Sender Port: %d" % msg_info["port"]) - print("Address: %s" % msg_info["address"]) - print("Types: %s" % msg_info["types"]) + #print("Sender IP: %s" % msg_info["ip"]) + #print("Sender Port: %d" % msg_info["port"]) + #print("Address: %s" % msg_info["address"]) + #print("Types: %s" % msg_info["types"]) set_value_no_signal(clampf(values[0], 0.0, 1.0)) diff --git a/testosc.sh b/testosc.sh index 6dcaba4..23ec665 100755 --- a/testosc.sh +++ b/testosc.sh @@ -3,11 +3,11 @@ PORT=9001 for ctrl in 0 1 2 3; do for value in `LC_ALL=C seq 0.1 0.1 1.0`; do - oscsend $HOST $PORT /slider/$ctrl/set f $value + oscsend $HOST $PORT /slider/$ctrl f $value sleep 0.1 done - oscsend $HOST $PORT /button/$ctrl/set i 1 + oscsend $HOST $PORT /button/$ctrl i 1 sleep 1 - oscsend $HOST $PORT /button/$ctrl/set i 0 + oscsend $HOST $PORT /button/$ctrl i 0 done diff --git a/toggle_button.gd b/toggle_button.gd index 6b39dab..eb90c5a 100644 --- a/toggle_button.gd +++ b/toggle_button.gd @@ -2,8 +2,8 @@ extends Button func recv_osc(msg_info, values): - print("Sender IP: %s" % msg_info["ip"]) - print("Sender Port: %d" % msg_info["port"]) - print("Address: %s" % msg_info["address"]) - print("Types: %s" % msg_info["types"]) + #print("Sender IP: %s" % msg_info["ip"]) + #print("Sender Port: %d" % msg_info["port"]) + #print("Address: %s" % msg_info["address"]) + #print("Types: %s" % msg_info["types"]) set_pressed_no_signal(bool(values[0])) diff --git a/ui.gd b/ui.gd index 99aa293..e06b204 100644 --- a/ui.gd +++ b/ui.gd @@ -1,49 +1,66 @@ extends Control + const OSCReceiver = preload("res://osc_receiver.gd") var osc_server: OSCReceiver const OSCSender = preload("res://osc_sender.gd") var osc_client: OSCSender +@export var osc_server_address:String = "*" +@export var osc_server_port: int = 9001 +@export var osc_dest_address:String = "127.0.0.1" +@export var osc_dest_port: int = 9000 +@export var debug: bool = false + + func _ready(): osc_client = OSCSender.new() + osc_client.debug = debug + osc_client.set_destination([osc_dest_address, osc_dest_port]) osc_server = OSCReceiver.new() + osc_server.debug = debug add_child(osc_server) + var button_callback = Callable(self, "_button_pressed") var slider_callback = Callable(self, "_slider_moved") # configure all sensors for i in range(4): var nodename = "VSlider%d" % (i + 1) - var osc_addr = "/slider/%d/set" % i + var osc_addr = "/slider/%d" % i var slider_node = find_child(nodename) osc_server.register_callback(osc_addr, "f", slider_node.recv_osc) slider_node.value_changed.connect(slider_callback.bind(i)) - + for i in range(4): var nodename = "Button%d" % (i + 1) - var osc_addr = "/button/%d/set" % i + var osc_addr = "/button/%d" % i var button_node = find_child(nodename) osc_server.register_callback(osc_addr, "i", button_node.recv_osc) button_node.pressed.connect(button_callback.bind(button_node, i)) # start listening for osc messages - osc_server.start_server() + osc_server.start_server(osc_server_port, osc_server_address) func _button_pressed(btn: Button, idx: int): - print("Button %s pressed: state = %s" % [idx, btn.button_pressed]) - osc_client.send_osc(9000, "/button/%d" % idx, "i", [1 if btn.button_pressed else 0]) + _debug("Button %s pressed: state = %s" % [idx, btn.button_pressed]) + osc_client.send_osc("/button/%d" % idx, "i", [1 if btn.button_pressed else 0]) func _slider_moved(value: float, idx: int): - print("Slider %d moved: value = %f" % [idx, value]) - osc_client.send_osc(9000, "/slider/%d" % idx, "f", [value]) + _debug("Slider %d moved: value = %f" % [idx, value]) + osc_client.send_osc("/slider/%d" % idx, "f", [value]) func recv_osc(msg_info, values): - print("Sender IP: %s" % msg_info["ip"]) - print("Sender Port: %d" % msg_info["port"]) - print("Address: %s" % msg_info["address"]) - print("Types: %s" % msg_info["types"]) - print("Values:", values) + _debug("Sender IP: %s" % msg_info["ip"]) + _debug("Sender Port: %d" % msg_info["port"]) + _debug("Address: %s" % msg_info["address"]) + _debug("Types: %s" % msg_info["types"]) + _debug("Values: %s" % values) + + +func _debug(msg): + if debug: + print(msg)