diff --git a/templates/wavescene/Player.gd b/templates/wavescene/Player.gd new file mode 100644 index 0000000..3a5c148 --- /dev/null +++ b/templates/wavescene/Player.gd @@ -0,0 +1,78 @@ +extends KinematicBody + +var camera_angle = 0 +var mouse_sensitivity = 0.3 +var camera_change = Vector2() + +var velocity = Vector3() +var direction = Vector3() + +#fly variables +const FLY_SPEED = 20 +const FLY_ACCEL = 4 + +var mouse_captured = true + +func _ready(): + Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) + +func _physics_process(delta): + + if mouse_captured: + aim() + fly(delta) + # emit signal - playerinfo_updated + var tf = $Head/Camera.get_global_transform_interpolated() + if tf != Events.player_tf_old: + Events.emit_signal("player_transform_updated", $Head/Camera.get_global_translation(), $Head.global_rotation.y) + Events.player_tf_old = tf + + if Input.is_action_just_pressed('toggle_mouse'): + if mouse_captured: + mouse_captured = false + Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) + else: + mouse_captured = true + Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) + +func _input(event): + if event is InputEventMouseMotion: + camera_change = event.relative + +func fly(delta): + # reset the direction of the player + direction = Vector3() + + # get the rotation of the camera + var aim = $Head/Camera.get_global_transform().basis + + # check input and change direction + if Input.is_action_pressed("move_forward"): + direction -= aim.z + if Input.is_action_pressed("move_backward"): + direction += aim.z + if Input.is_action_pressed("move_left"): + direction -= aim.x + if Input.is_action_pressed("move_right"): + direction += aim.x + + direction = direction.normalized() + + # where would the player go at max speed + var target = direction * FLY_SPEED + + # calculate a portion of the distance to go + velocity = velocity.linear_interpolate(target, FLY_ACCEL * delta) + + # move + move_and_slide(velocity) + +func aim(): + if camera_change.length() > 0: + $Head.rotate_y(deg2rad(-camera_change.x * mouse_sensitivity)) + + var change = -camera_change.y * mouse_sensitivity + if change + camera_angle < 90 and change + camera_angle > -90: + $Head/Camera.rotate_x(deg2rad(change)) + camera_angle += change + camera_change = Vector2() diff --git a/templates/wavescene/Player.tscn b/templates/wavescene/Player.tscn new file mode 100644 index 0000000..3900a7b --- /dev/null +++ b/templates/wavescene/Player.tscn @@ -0,0 +1,21 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://Player.gd" type="Script" id=1] + +[sub_resource type="CapsuleShape" id=1] +radius = 0.6 +height = 2.0 + +[node name="Player" type="KinematicBody"] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 3.52113, 0.98772 ) +script = ExtResource( 1 ) + +[node name="Capsule" type="CollisionShape" parent="."] +transform = Transform( 1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0 ) +shape = SubResource( 1 ) + +[node name="Head" type="Spatial" parent="."] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.5, 0 ) + +[node name="Camera" type="Camera" parent="Head"] +far = 10000.0 diff --git a/templates/wavescene/Scene.gd b/templates/wavescene/Scene.gd new file mode 100644 index 0000000..2190d1a --- /dev/null +++ b/templates/wavescene/Scene.gd @@ -0,0 +1,14 @@ +extends Node + +var wave = load("res://wave.tscn") + +func _ready(): + for i in range(11): + var w = wave.instance() + w.set_size(rand_range(0.2, 1.2)) + w.set_color(Color.darkgoldenrod) + w.set_preset(randf()*800 + 200) + var d = polar2cartesian(rand_range(10, 20), rand_range(0, 2*PI)) + w.translate(Vector3(d.x, rand_range(2, 8), d.y)) + w.set_preset(i) + add_child(w) diff --git a/templates/wavescene/Scene.tscn b/templates/wavescene/Scene.tscn new file mode 100644 index 0000000..d3f2979 --- /dev/null +++ b/templates/wavescene/Scene.tscn @@ -0,0 +1,37 @@ +[gd_scene load_steps=6 format=2] + +[ext_resource path="res://Player.tscn" type="PackedScene" id=2] +[ext_resource path="res://Scene.gd" type="Script" id=3] + +[sub_resource type="BoxShape" id=1] +extents = Vector3( 300, 1, 300 ) + +[sub_resource type="CubeMesh" id=2] +size = Vector3( 600, 2, 600 ) + +[sub_resource type="Environment" id=3] +fog_enabled = true + +[node name="Scene" type="Node"] +script = ExtResource( 3 ) + +[node name="StaticBody" type="StaticBody" parent="."] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1, 0 ) +__meta__ = { +"_edit_group_": true +} + +[node name="CollisionShape" type="CollisionShape" parent="StaticBody"] +shape = SubResource( 1 ) + +[node name="MeshInstance" type="MeshInstance" parent="StaticBody"] +mesh = SubResource( 2 ) + +[node name="DirectionalLight" type="DirectionalLight" parent="."] +transform = Transform( 1, 0, 0, 0, 0.158589, 0.987345, 0, -0.987345, 0.158589, 0, 57.3999, 0 ) +shadow_enabled = true + +[node name="Player" parent="." instance=ExtResource( 2 )] + +[node name="WorldEnvironment" type="WorldEnvironment" parent="."] +environment = SubResource( 3 ) diff --git a/templates/wavescene/addons/gdpd/bin/gdpd.gdns b/templates/wavescene/addons/gdpd/bin/gdpd.gdns new file mode 100644 index 0000000..869b3c3 --- /dev/null +++ b/templates/wavescene/addons/gdpd/bin/gdpd.gdns @@ -0,0 +1,8 @@ +[gd_resource type="NativeScript" load_steps=2 format=2] + +[ext_resource path="res://addons/gdpd/bin/libgdpd.gdnlib" type="GDNativeLibrary" id=1] + +[resource] +resource_name = "gdpd" +class_name = "Gdpd" +library = ExtResource( 1 ) diff --git a/templates/wavescene/addons/gdpd/bin/libgdpd.gdnlib b/templates/wavescene/addons/gdpd/bin/libgdpd.gdnlib new file mode 100644 index 0000000..048e4af --- /dev/null +++ b/templates/wavescene/addons/gdpd/bin/libgdpd.gdnlib @@ -0,0 +1,18 @@ +[general] + +singleton=false +load_once=false +symbol_prefix="godot_" +reloadable=true + +[entry] + +X11.64="res://addons/gdpd/bin/x11/libgdpd.so" +Windows.64="res://addons/gdpd/bin/win/libgdpd.dll" +OSX.64="res://addons/gdpd/bin/osx/libgdpd.dylib" + +[dependencies] + +X11.64=[ ] +Windows.64=[ ] +OSX.64=[ ] diff --git a/templates/wavescene/addons/gdpd/bin/osx/libgdpd.dylib b/templates/wavescene/addons/gdpd/bin/osx/libgdpd.dylib new file mode 100755 index 0000000..a8021de Binary files /dev/null and b/templates/wavescene/addons/gdpd/bin/osx/libgdpd.dylib differ diff --git a/templates/wavescene/autoload/Events.gd b/templates/wavescene/autoload/Events.gd new file mode 100644 index 0000000..c50a795 --- /dev/null +++ b/templates/wavescene/autoload/Events.gd @@ -0,0 +1,6 @@ +extends Node + +var player_tf_old = Transform() +signal player_transform_updated(position, heading) +# position : Vector3 +# heading : Vector2 (projected x-z plane, and normalized) diff --git a/templates/wavescene/autoload/Events.tscn b/templates/wavescene/autoload/Events.tscn new file mode 100644 index 0000000..00dabc1 --- /dev/null +++ b/templates/wavescene/autoload/Events.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://autoload/Events.gd" type="Script" id=1] + +[node name="Events" type="Node"] +script = ExtResource( 1 ) diff --git a/templates/wavescene/autoload/Global.gd b/templates/wavescene/autoload/Global.gd new file mode 100644 index 0000000..89497f7 --- /dev/null +++ b/templates/wavescene/autoload/Global.gd @@ -0,0 +1,118 @@ +extends Node + + +#gdpd (pd interface with godot) +var _gdpd +var _patches = [] + +export (bool) var _enable_gui = false +export (String) var _gui_path = "/Applications/Pd-0.53-1.app/Contents/Resources" +export (bool) var _verbose = false +export (float) var _sample_rate = 48000 +export (int) var _blocksize = 256 + +func _ready(): + _gdpd = load("res://addons/gdpd/bin/gdpd.gdns").new() + if _enable_gui: + # set gui path to activate gui window (otherwise, nogui) + _gdpd.set_gui_path(_gui_path) + _gdpd.set_volume(1) # by default, volume(gain) == 0 + _gdpd.set_verbose(_verbose) # by default, suppress 'print' + _gdpd.init(0, 2, _sample_rate, _blocksize) + _gdpd.computeAudio(true) # [; pd dsp 1 ( + _gdpd.subscribe("toGodot") + # delayed 'stream start' to prevent start-up 'pop' noise. + yield(get_tree().create_timer(0.3), "timeout") + _gdpd.streamstart() + +func _exit_tree(): + if _patches.size() != 0: + print() + print("! ======== * purging leftover opened patches ... * ======== !") + print() + for id in _patches: + _gdpd.closePatch(id) + _patches.clear() + _gdpd.stop() + +func load_patch(pd_patch) -> int: + #the patch path should be the absolute one + #separate file name from directory + var patch_name = pd_patch.split("/")[-1] + var patch_dir = pd_patch.trim_suffix(patch_name) + var id = _gdpd.openPatch(patch_name, patch_dir) + _patches.append(id) + return id + +func close_patch(id): + if id in _patches: + _gdpd.closePatch(id) + _patches.erase(id) + +func _process(_delta) : + while _gdpd.has_message(): + var msg = _gdpd.get_next() + print(msg) +# if msg[0] == "random": +# print("r") + + +## save some files to user directory +## + *.wav +#func _extract_res_to_user_recursive(src, dst): +# var dotfolders = RegEx.new() +# dotfolders.compile("^\\.\\w*") +# var wavfiles = RegEx.new() +# wavfiles.compile("\\w+\\.wav$") +# var dir = Directory.new() +# if dir.open(src) == OK: +# dir.list_dir_begin() +# var file_name = dir.get_next() +# while file_name != "": +# if dir.current_is_dir(): +# print("Found directory: " + file_name) +# if not dotfolders.search(file_name): +# dir.make_dir(dst + "/" + file_name) +# _extract_res_to_user_recursive(dir.get_current_dir() + "/" + file_name, dst + "/" + file_name) +# else: +# if wavfiles.search(file_name): +# print("Found wav file: " + file_name) +# dir.copy(src + "/" + file_name, dst + "/" + file_name) +# +# file_name = dir.get_next() +# else: +# print("An error occurred when trying to access the path. : " + src) + + + +# ==== archived. ==== + + + # duplicate "res://" into 'user://' ==> we need godot 4 for this approach.. +# _copydirectory_recursive("res://", "user://") + + +## copy directory recursively ==> we need godot 4 for this approach.. +#func _copydirectory_recursive(src, dst): +# var dotfolders = RegEx.new() +# dotfolders.compile("^\\.\\w*") +# var pdfiles = RegEx.new() +# pdfiles.compile("\\w+\\.pd$") +# var dir = Directory.new() +# if dir.open(src) == OK: +# dir.list_dir_begin() +# var file_name = dir.get_next() +# while file_name != "": +# if dir.current_is_dir(): +# print("Found directory: " + file_name) +# if not dotfolders.search(file_name): +# dir.make_dir(dst + "/" + file_name) +# _copydirectory_recursive(dir.get_current_dir() + "/" + file_name, dst + "/" + file_name) +# else: +# if pdfiles.search(file_name): +# print("Found puredata file: " + file_name) +# dir.copy(src + "/" + file_name, dst + "/" + file_name) +# +# file_name = dir.get_next() +# else: +# print("An error occurred when trying to access the path. : " + src) diff --git a/templates/wavescene/autoload/Global.tscn b/templates/wavescene/autoload/Global.tscn new file mode 100644 index 0000000..a00373d --- /dev/null +++ b/templates/wavescene/autoload/Global.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://autoload/Global.gd" type="Script" id=1] + +[node name="Global" type="Node"] +script = ExtResource( 1 ) diff --git a/templates/wavescene/default_env.tres b/templates/wavescene/default_env.tres new file mode 100644 index 0000000..20207a4 --- /dev/null +++ b/templates/wavescene/default_env.tres @@ -0,0 +1,7 @@ +[gd_resource type="Environment" load_steps=2 format=2] + +[sub_resource type="ProceduralSky" id=1] + +[resource] +background_mode = 2 +background_sky = SubResource( 1 ) diff --git a/templates/wavescene/export_presets.cfg b/templates/wavescene/export_presets.cfg new file mode 100644 index 0000000..2d3b85b --- /dev/null +++ b/templates/wavescene/export_presets.cfg @@ -0,0 +1,73 @@ +[preset.0] + +name="Mac OSX" +platform="Mac OSX" +runnable=true +custom_features="" +export_filter="all_resources" +include_filter="" +exclude_filter="" +export_path="./Sands and Waves (worldscene1).dmg" +script_export_mode=1 +script_encryption_key="" + +[preset.0.options] + +custom_template/debug="" +custom_template/release="" +application/name="" +application/info="Made with Godot Engine" +application/icon="" +application/identifier="in.dianaband.worldscene1" +application/signature="" +application/app_category="Games" +application/short_version="1.0" +application/version="1.0" +application/copyright="" +display/high_res=false +privacy/microphone_usage_description="" +privacy/camera_usage_description="" +privacy/location_usage_description="" +privacy/address_book_usage_description="" +privacy/calendar_usage_description="" +privacy/photos_library_usage_description="" +privacy/desktop_folder_usage_description="" +privacy/documents_folder_usage_description="" +privacy/downloads_folder_usage_description="" +privacy/network_volumes_usage_description="" +privacy/removable_volumes_usage_description="" +codesign/enable=true +codesign/identity="" +codesign/timestamp=false +codesign/hardened_runtime=false +codesign/replace_existing_signature=true +codesign/entitlements/custom_file="" +codesign/entitlements/allow_jit_code_execution=false +codesign/entitlements/allow_unsigned_executable_memory=false +codesign/entitlements/allow_dyld_environment_variables=false +codesign/entitlements/disable_library_validation=true +codesign/entitlements/audio_input=false +codesign/entitlements/camera=false +codesign/entitlements/location=false +codesign/entitlements/address_book=false +codesign/entitlements/calendars=false +codesign/entitlements/photos_library=false +codesign/entitlements/apple_events=false +codesign/entitlements/debugging=false +codesign/entitlements/app_sandbox/enabled=false +codesign/entitlements/app_sandbox/network_server=false +codesign/entitlements/app_sandbox/network_client=false +codesign/entitlements/app_sandbox/device_usb=false +codesign/entitlements/app_sandbox/device_bluetooth=false +codesign/entitlements/app_sandbox/files_downloads=0 +codesign/entitlements/app_sandbox/files_pictures=0 +codesign/entitlements/app_sandbox/files_music=0 +codesign/entitlements/app_sandbox/files_movies=0 +codesign/custom_options=PoolStringArray( ) +notarization/enable=false +notarization/apple_id_name="" +notarization/apple_id_password="" +notarization/apple_team_id="" +texture_format/s3tc=true +texture_format/etc=false +texture_format/etc2=false diff --git a/templates/wavescene/icon.png b/templates/wavescene/icon.png new file mode 100644 index 0000000..c98fbb6 Binary files /dev/null and b/templates/wavescene/icon.png differ diff --git a/templates/wavescene/project.godot b/templates/wavescene/project.godot new file mode 100644 index 0000000..a23d57c --- /dev/null +++ b/templates/wavescene/project.godot @@ -0,0 +1,66 @@ +; Engine configuration file. +; It's best edited using the editor UI and not directly, +; since the parameters that go here are not all obvious. +; +; Format: +; [section] ; section goes between [] +; param=value ; assign values to parameters + +config_version=4 + +[application] + +config/name="Sands and Waves (worldscene1)" +run/main_scene="res://Scene.tscn" +config/icon="res://icon.png" + +[autoload] + +Global="*res://autoload/Global.tscn" +Events="*res://autoload/Events.tscn" + +[gui] + +common/drop_mouse_on_gui_input_disabled=true + +[input] + +move_right={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":68,"physical_scancode":0,"unicode":0,"echo":false,"script":null) + ] +} +move_left={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":65,"physical_scancode":0,"unicode":0,"echo":false,"script":null) + ] +} +move_forward={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":87,"physical_scancode":0,"unicode":0,"echo":false,"script":null) + ] +} +move_backward={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":83,"physical_scancode":0,"unicode":0,"echo":false,"script":null) + ] +} +toggle_mouse={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777217,"physical_scancode":0,"unicode":0,"echo":false,"script":null) + ] +} + +[layer_names] + +3d_physics/layer_1="world" +3d_physics/layer_2="player" +3d_physics/layer_3="sounder" + +[physics] + +common/enable_pause_aware_picking=true + +[rendering] + +environment/default_environment="res://default_env.tres" diff --git a/templates/wavescene/sound/01.wav b/templates/wavescene/sound/01.wav new file mode 100644 index 0000000..6b66e08 Binary files /dev/null and b/templates/wavescene/sound/01.wav differ diff --git a/templates/wavescene/sound/02.wav b/templates/wavescene/sound/02.wav new file mode 100644 index 0000000..8bfc0db Binary files /dev/null and b/templates/wavescene/sound/02.wav differ diff --git a/templates/wavescene/sound/03.wav b/templates/wavescene/sound/03.wav new file mode 100644 index 0000000..ade2ab9 Binary files /dev/null and b/templates/wavescene/sound/03.wav differ diff --git a/templates/wavescene/sound/04.wav b/templates/wavescene/sound/04.wav new file mode 100644 index 0000000..b86db55 Binary files /dev/null and b/templates/wavescene/sound/04.wav differ diff --git a/templates/wavescene/sound/05.wav b/templates/wavescene/sound/05.wav new file mode 100644 index 0000000..10746b0 Binary files /dev/null and b/templates/wavescene/sound/05.wav differ diff --git a/templates/wavescene/sound/06.wav b/templates/wavescene/sound/06.wav new file mode 100644 index 0000000..6668bcf Binary files /dev/null and b/templates/wavescene/sound/06.wav differ diff --git a/templates/wavescene/sound/07.wav b/templates/wavescene/sound/07.wav new file mode 100644 index 0000000..7e3ce7d Binary files /dev/null and b/templates/wavescene/sound/07.wav differ diff --git a/templates/wavescene/sound/08.wav b/templates/wavescene/sound/08.wav new file mode 100644 index 0000000..ed6af36 Binary files /dev/null and b/templates/wavescene/sound/08.wav differ diff --git a/templates/wavescene/sound/09.wav b/templates/wavescene/sound/09.wav new file mode 100644 index 0000000..9bfb2c9 Binary files /dev/null and b/templates/wavescene/sound/09.wav differ diff --git a/templates/wavescene/sound/10.wav b/templates/wavescene/sound/10.wav new file mode 100644 index 0000000..9709d80 Binary files /dev/null and b/templates/wavescene/sound/10.wav differ diff --git a/templates/wavescene/sound/11.wav b/templates/wavescene/sound/11.wav new file mode 100644 index 0000000..99e7451 Binary files /dev/null and b/templates/wavescene/sound/11.wav differ diff --git a/templates/wavescene/wave.gd b/templates/wavescene/wave.gd new file mode 100644 index 0000000..1ccd607 --- /dev/null +++ b/templates/wavescene/wave.gd @@ -0,0 +1,100 @@ +extends RigidBody + +export (float, 0, 100) var audible_range_max = 10.0 +export (float, 0, 10) var preset = 0 + +export (bool) var use_embeded_patch = false +export (String, MULTILINE) var patch = "" + +var _my_patch = "res://wave.pd" +var _my_id = 0 + +func set_size(size): + $CollisionShape.shape.radius = size + $MeshInstance.mesh.radius = size + $MeshInstance.mesh.height = size * 2 + +func set_freq(freq): + Global._gdpd.start_message(2) + Global._gdpd.add_symbol('freq') + Global._gdpd.add_float(freq) + Global._gdpd.finish_list("fromGodot" + String(_my_id)) + +func set_gain(gain): + Global._gdpd.start_message(2) + Global._gdpd.add_symbol('gain') + Global._gdpd.add_float(gain) + Global._gdpd.finish_list("fromGodot" + String(_my_id)) + +func set_param(param): + Global._gdpd.start_message(param.size()+1) + Global._gdpd.add_symbol("param") + for i in range(param.size()): + Global._gdpd.add_float(param[i]) + Global._gdpd.finish_list("fromGodot" + String(_my_id)) + +func set_preset(prs): + preset = prs + Global._gdpd.start_message(2) + Global._gdpd.add_symbol("preset") + Global._gdpd.add_float(prs) + Global._gdpd.finish_list("fromGodot" + String(_my_id)) + +func set_color(color): + $MeshInstance.material_override = SpatialMaterial.new() + $MeshInstance.material_override.albedo_color = color + +func _ready(): + # save patch (for export) + if use_embeded_patch: + assert(_my_patch.substr(0, 7) == "user://", "use userpath with embeded_patch enabled !") + assert(patch != "", "patch is empty?") + _save_patch() + + # load patch + _my_id = Global.load_patch(ProjectSettings.globalize_path(_my_patch)) + + # listen 'player_transform_updated' event + Events.connect("player_transform_updated", self, "_on_Events_player_transform_updated") + + # send 'preset' + set_preset(preset) + set_gain(1) + +func _on_Events_player_transform_updated(playerpos, playerheading): + var mypos = get_global_translation() + var mypos2d = Vector2(mypos.x, mypos.z) + var playerpos2d = Vector2(playerpos.x, playerpos.z) + # calculate distance + var distance = mypos.distance_to(playerpos) + # calculate angle + var angle = fmod(fmod(playerpos2d.angle_to_point(mypos2d) + playerheading - PI/2, PI*2) + PI*2, PI*2) + if angle > PI: + angle = angle - PI*2 + # (check) +# print(str(_my_id) +" : ("+ str(distance) +","+ str(angle) +")") + # calculate gain + var gain = 1 - distance/audible_range_max + # send to the patch + Global._gdpd.start_message(3) + Global._gdpd.add_symbol("panvol") + Global._gdpd.add_float(gain) + Global._gdpd.add_float(angle) + Global._gdpd.finish_list("fromGodot" + String(_my_id)) + + +func _exit_tree(): + Global.close_patch(_my_id) + +func _save_patch(): + # save patch + # prepare directory + var patch_name = _my_patch.split("/")[-1] + var patch_dir = _my_patch.trim_suffix(patch_name) + var dir = Directory.new() + dir.make_dir_recursive(patch_dir) + # save to file + var file = File.new() + file.open(_my_patch, File.WRITE) + file.store_string(patch) + file.close() diff --git a/templates/wavescene/wave.pd b/templates/wavescene/wave.pd new file mode 100644 index 0000000..ad35b9d --- /dev/null +++ b/templates/wavescene/wave.pd @@ -0,0 +1,266 @@ +#N canvas 91 156 456 518 12; +#X obj 361 21 loadbang; +#X msg 361 51 \; pd dsp 1; +#X obj 21 22 r fromGodot\$0; +#X obj 21 46 list trim; +#X obj 199 467 dac~ 1 2; +#X obj 199 407 *~; +#X obj 217 120 unpack f f; +#X obj 58 301 *~; +#X obj 217 257 line~; +#X msg 217 233 \$1 100; +#X floatatom 217 170 5 0 0 0 - - - 0; +#X obj 160 303 switch~; +#X obj 160 279 tgl 19 0 empty empty empty 0 -10 0 12 #fcfcfc #000000 #000000 0 1; +#X obj 160 255 change; +#X text 117 148 switch on/off before 0 to stop startup pops, f 12; +#X obj 217 209 max 0; +#X obj 160 231 > -0.3; +#X obj 331 246 hsl 100 20 -1 1 0 0 empty empty empty -2 -10 0 12 #fcfcfc #000000 #000000 0 1; +#X obj 328 342 line~; +#X msg 328 318 \$1 100; +#X obj 328 271 expr ($f1 + 1)/8; +#X floatatom 328 295 5 0 0 0 - - - 0; +#N canvas 68 97 450 300 pan2~ 0; +#X obj 51 98 cos~; +#X obj 111 98 cos~; +#X obj 33 128 *~; +#X obj 93 128 *~; +#X obj 33 158 outlet~; +#X obj 93 158 outlet~; +#X obj 33 24 inlet~; +#X obj 111 24 inlet~; +#X obj 111 74 +~ 0.75; +#X connect 0 0 2 1; +#X connect 1 0 3 1; +#X connect 2 0 4 0; +#X connect 3 0 5 0; +#X connect 6 0 2 0; +#X connect 6 0 3 0; +#X connect 7 0 8 0; +#X connect 7 0 0 0; +#X connect 8 0 1 0; +#X restore 199 437 pd pan2~; +#X floatatom 328 152 5 0 0 0 - - - 0; +#X obj 328 175 sin; +#X floatatom 328 199 5 0 0 0 - - - 0; +#X obj 21 70 route preset gain panvol; +#N canvas 613 355 561 460 wave 0; +#X obj 24 16 inlet; +#X obj 24 340 outlet~; +#N canvas 68 97 766 684 wav2 0; +#X obj 265 300 table \$0-sound 8820; +#X obj 29 402 soundfiler; +#X obj 152 182 f \$0; +#X obj 152 160 bng 15 250 50 0 empty empty empty 17 7 0 10 #fcfcfc #000000 #000000; +#X obj 29 182 list append; +#X msg 29 160 read -resize; +#X msg 29 270 read -resize sound/01.wav; +#X obj 29 204 list prepend set; +#X obj 29 226 list trim; +#X obj 29 138 t b a; +#X obj 29 292 list append; +#X msg 29 380 read -resize sound/01.wav 1003-sound; +#X obj 29 314 list prepend set; +#X obj 29 336 list trim; +#X obj 29 248 t b a; +#X obj 29 358 t b a; +#X obj 152 138 loadbang; +#X text 624 625 dianaband; +#X obj 42 52 inlet; +#X msg 152 204 \$1-sound; +#X text 27 24 (1) filename; +#X obj 29 424 sel 0; +#X obj 29 106 t a a; +#X obj 278 626 print [wav~]; +#X msg 52 496 error: cannot load the file!; +#X obj 358 472 samplerate~; +#X obj 339 494 /; +#X msg 339 516 length: \$1 seconds; +#X msg 321 538 samples: \$1 ea; +#X text 267 270 sound loads to ...; +#X text 315 601 messages to post ...; +#X obj 470 102 inlet; +#X obj 422 182 sel 0; +#X msg 180 74 error: file should be loaded first!!; +#X text 559 401 [1] audio; +#X text 624 645 2016; +#X msg 96 106 error: file name should be a string!!; +#X obj 42 74 route float bang; +#X obj 238 196 list prepend; +#X msg 319 174 loading:; +#X obj 319 152 loadbang; +#X obj 238 218 list trim; +#X obj 75 518 f \$0; +#X msg 75 540 \; \$1-sound resize 1 \; \$1-sound 0 0 \;; +#X obj 565 474 loadbang; +#X msg 565 496 0; +#X msg 29 608 0; +#X msg 61 608 1; +#X obj 61 446 t b a; +#X obj 29 474 t b b b; +#X text 568 448 loaded? check.; +#X floatatom 114 421 5 0 0 1 s:0-samples - \$0-samples 0; +#X obj 565 518 v \$0-is-loaded; +#X obj 502 146 v \$0-is-loaded; +#X obj 29 636 v \$0-is-loaded; +#X floatatom 502 168 5 0 0 0 - - - 0; +#X obj 560 308 phasor~; +#X obj 560 330 *~; +#X floatatom 560 287 5 0 0 0 - - - 0; +#X obj 592 248 v \$0-playspeed_x1; +#X obj 560 265 *; +#X obj 560 226 t a b; +#X text 328 354 info. msg. / playback speed; +#X obj 321 383 t a a b b a; +#X obj 376 406 samplerate~; +#X obj 376 428 /; +#X obj 560 374 outlet~; +#X floatatom 630 316 5 0 0 2 r:0-samples \$0-samples - 0; +#X obj 376 450 v \$0-playspeed_x1; +#X obj 565 544 loadbang; +#X msg 565 566 0; +#X obj 565 588 v \$0-playspeed_x1; +#X text 469 74 (2) play speed : 1 for x1; +#X obj 470 124 t a b; +#X obj 470 207 spigot; +#X obj 509 187 tgl 15 0 empty empty empty 17 7 0 10 #fcfcfc #000000 #000000 0 1; +#X obj 560 352 tabread~ \$0-sound; +#X text 637 123 (3) rewind!; +#X obj 640 148 inlet; +#X msg 640 190 0; +#X obj 640 170 bng 15 250 50 0 empty empty empty 17 7 0 10 #fcfcfc #000000 #000000; +#X text 306 14 NOTE!! filename will be searched relative to THIS patch's location. so copy and keep it nearby to the main patch. e.g. the very same folder or ./lib/ and use ../data/*.wav etc.; +#X connect 1 0 21 0; +#X connect 1 0 51 0; +#X connect 2 0 19 0; +#X connect 3 0 2 0; +#X connect 4 0 7 0; +#X connect 5 0 4 0; +#X connect 6 0 10 0; +#X connect 7 0 8 0; +#X connect 8 0 14 0; +#X connect 9 0 5 0; +#X connect 9 1 4 1; +#X connect 10 0 12 0; +#X connect 11 0 1 0; +#X connect 12 0 13 0; +#X connect 13 0 15 0; +#X connect 14 0 6 0; +#X connect 14 1 6 0; +#X connect 15 0 11 0; +#X connect 15 1 11 0; +#X connect 16 0 3 0; +#X connect 18 0 37 0; +#X connect 19 0 10 1; +#X connect 21 0 49 0; +#X connect 21 1 48 0; +#X connect 22 0 9 0; +#X connect 22 1 38 0; +#X connect 24 0 23 0; +#X connect 25 0 26 1; +#X connect 26 0 27 0; +#X connect 27 0 23 0; +#X connect 28 0 23 0; +#X connect 31 0 73 0; +#X connect 32 0 33 0; +#X connect 33 0 23 0; +#X connect 36 0 23 0; +#X connect 37 0 36 0; +#X connect 37 1 36 0; +#X connect 37 2 22 0; +#X connect 38 0 41 0; +#X connect 39 0 38 1; +#X connect 40 0 39 0; +#X connect 41 0 23 0; +#X connect 42 0 43 0; +#X connect 44 0 45 0; +#X connect 45 0 52 0; +#X connect 46 0 54 0; +#X connect 47 0 54 0; +#X connect 48 0 47 0; +#X connect 48 1 63 0; +#X connect 49 0 46 0; +#X connect 49 1 24 0; +#X connect 49 2 42 0; +#X connect 53 0 55 0; +#X connect 55 0 32 0; +#X connect 55 0 75 0; +#X connect 56 0 57 0; +#X connect 57 0 76 0; +#X connect 58 0 56 0; +#X connect 59 0 60 1; +#X connect 60 0 58 0; +#X connect 61 0 60 0; +#X connect 61 1 59 0; +#X connect 63 0 28 0; +#X connect 63 1 26 0; +#X connect 63 2 25 0; +#X connect 63 3 64 0; +#X connect 63 4 65 1; +#X connect 64 0 65 0; +#X connect 65 0 68 0; +#X connect 67 0 57 1; +#X connect 69 0 70 0; +#X connect 70 0 71 0; +#X connect 73 0 74 0; +#X connect 73 1 53 0; +#X connect 74 0 61 0; +#X connect 75 0 74 1; +#X connect 76 0 66 0; +#X connect 78 0 80 0; +#X connect 79 0 56 1; +#X connect 80 0 79 0; +#X restore 24 300 pd wav2; +#X obj 203 76 text define -k wavefiles\$0; +#A set sound/01.wav \; sound/02.wav \; sound/03.wav \; sound/04.wav \; sound/05.wav \; sound/06.wav \; sound/07.wav \; sound/08.wav \; sound/09.wav \; sound/10.wav \; sound/11.wav \;; +#X obj 24 100 text get wavefiles\$0; +#X floatatom 24 71 5 0 0 0 - - - 0; +#X text 87 280 (1) filename; +#X text 87 300 (2) play speed : 1 for x1; +#X text 87 320 (3) rewind!; +#X text 234 49 list of filenames; +#X text 357 237 or generate filenames; +#X obj 24 140 t b b a; +#X msg 47 166 1; +#X text 395 35 sound/01.wav \; sound/02.wav \; sound/03.wav \; sound/04.wav \; sound/05.wav \; sound/06.wav \; sound/07.wav \; sound/08.wav \; sound/09.wav \; sound/10.wav \; sound/11.wav \;; +#X obj 349 265 makefilename sound/%2d.wav; +#X connect 0 0 5 0; +#X connect 2 0 1 0; +#X connect 4 0 11 0; +#X connect 5 0 4 0; +#X connect 11 0 2 2; +#X connect 11 1 12 0; +#X connect 11 2 2 0; +#X connect 12 0 2 1; +#X restore 21 230 pd wave; +#X floatatom 76 100 5 0 0 0 - - - 0; +#X connect 2 0 3 0; +#X connect 3 0 26 0; +#X connect 5 0 22 0; +#X connect 6 0 10 0; +#X connect 6 1 23 0; +#X connect 7 0 5 0; +#X connect 8 0 5 1; +#X connect 9 0 8 0; +#X connect 10 0 15 0; +#X connect 10 0 16 0; +#X connect 12 0 11 0; +#X connect 13 0 12 0; +#X connect 15 0 9 0; +#X connect 16 0 13 0; +#X connect 17 0 20 0; +#X connect 18 0 22 1; +#X connect 19 0 18 0; +#X connect 20 0 21 0; +#X connect 21 0 19 0; +#X connect 22 0 4 0; +#X connect 22 1 4 1; +#X connect 23 0 24 0; +#X connect 24 0 25 0; +#X connect 25 0 17 0; +#X connect 26 0 27 0; +#X connect 26 1 28 0; +#X connect 26 2 6 0; +#X connect 27 0 7 0; +#X connect 28 0 7 1; diff --git a/templates/wavescene/wave.tscn b/templates/wavescene/wave.tscn new file mode 100644 index 0000000..ce8f27d --- /dev/null +++ b/templates/wavescene/wave.tscn @@ -0,0 +1,23 @@ +[gd_scene load_steps=5 format=2] + +[ext_resource path="res://wave.gd" type="Script" id=1] + +[sub_resource type="PhysicsMaterial" id=3] + +[sub_resource type="SphereShape" id=1] + +[sub_resource type="SphereMesh" id=2] +resource_local_to_scene = true + +[node name="wave" type="RigidBody" groups=["sounders"]] +collision_layer = 4 +collision_mask = 0 +physics_material_override = SubResource( 3 ) +gravity_scale = 0.0 +script = ExtResource( 1 ) + +[node name="CollisionShape" type="CollisionShape" parent="."] +shape = SubResource( 1 ) + +[node name="MeshInstance" type="MeshInstance" parent="."] +mesh = SubResource( 2 )