diff --git a/GdpdExample/Main.tscn b/GdpdExample/Main.tscn index 3889266..f22ef64 100644 --- a/GdpdExample/Main.tscn +++ b/GdpdExample/Main.tscn @@ -15,53 +15,6 @@ collision_mask = 0 physics_material_override = SubResource( 3 ) gravity_scale = 0.0 script = ExtResource( 1 ) -patch = "#N canvas 574 271 456 518 12; -#X obj 361 21 loadbang; -#X msg 361 51 \\; pd dsp 1; -#X floatatom 21 198 5 0 0 0 - - - 0; -#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 189 230 line~; -#X msg 189 206 \\$1 100; -#X obj 189 127 unpack f f; -#X floatatom 189 177 5 0 0 0 - - - 0; -#X obj 21 256 noise~; -#X obj 21 286 bp~ 500 1000; -#X obj 21 70 route freq gain panvol; -#X obj 21 316 *~; -#X msg 296 338 \\$1 100; -#X floatatom 296 159 5 0 0 0 - - - 0; -#X obj 199 437 earplug~ 0 0; -#X obj 296 362 line; -#X obj 122 158 != 0; -#X obj 122 206 switch~; -#X obj 122 182 tgl 19 0 empty empty empty 0 -10 0 12 #fcfcfc #000000 #000000 0 1; -#X connect 2 0 12 1; -#X connect 3 0 4 0; -#X connect 4 0 13 0; -#X connect 6 0 17 0; -#X connect 7 0 6 1; -#X connect 8 0 7 0; -#X connect 9 0 10 0; -#X connect 9 1 16 0; -#X connect 10 0 8 0; -#X connect 10 0 19 0; -#X connect 11 0 12 0; -#X connect 12 0 14 0; -#X connect 13 0 2 0; -#X connect 13 1 14 1; -#X connect 13 2 9 0; -#X connect 14 0 6 0; -#X connect 15 0 18 0; -#X connect 16 0 15 0; -#X connect 17 0 5 0; -#X connect 17 1 5 1; -#X connect 18 0 17 1; -#X connect 19 0 21 0; -#X connect 21 0 20 0; -" [node name="CollisionShape" type="CollisionShape" parent="."] shape = SubResource( 1 ) diff --git a/GdpdExample/main-earplug.pd b/GdpdExample/main-earplug.pd new file mode 100644 index 0000000..df864f6 --- /dev/null +++ b/GdpdExample/main-earplug.pd @@ -0,0 +1,55 @@ +#N canvas 108 222 456 518 12; +#X obj 361 21 loadbang; +#X msg 361 51 \; pd dsp 1; +#X floatatom 21 198 5 0 0 0 - - - 0; +#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 189 264 line~; +#X msg 189 240 \$1 100; +#X obj 189 127 unpack f f; +#X floatatom 189 177 5 0 0 0 - - - 0; +#X obj 21 256 noise~; +#X obj 21 286 bp~ 500 1000; +#X obj 21 70 route freq gain panvol; +#X obj 21 316 *~; +#X msg 296 338 \$1 100; +#X floatatom 296 159 5 0 0 0 - - - 0; +#X obj 199 437 earplug~ 0 0; +#X obj 296 362 line; +#X obj 132 310 switch~; +#X obj 132 286 tgl 19 0 empty empty empty 0 -10 0 12 #fcfcfc #000000 #000000 0 1; +#X obj 132 262 change; +#X text 89 155 switch on/off before 0 to stop startup pops, f 12; +#X obj 189 216 max 0; +#X obj 132 238 > -0.3; +#X obj 296 248 expr 360-$f1; +#X obj 296 182 expr $f1*180/3.141592; +#X connect 2 0 12 1; +#X connect 3 0 4 0; +#X connect 4 0 13 0; +#X connect 6 0 17 0; +#X connect 7 0 6 1; +#X connect 8 0 7 0; +#X connect 9 0 10 0; +#X connect 9 1 16 0; +#X connect 10 0 23 0; +#X connect 10 0 24 0; +#X connect 11 0 12 0; +#X connect 12 0 14 0; +#X connect 13 0 2 0; +#X connect 13 1 14 1; +#X connect 13 2 9 0; +#X connect 14 0 6 0; +#X connect 15 0 18 0; +#X connect 16 0 26 0; +#X connect 17 0 5 0; +#X connect 17 1 5 1; +#X connect 18 0 17 1; +#X connect 20 0 19 0; +#X connect 21 0 20 0; +#X connect 23 0 8 0; +#X connect 24 0 21 0; +#X connect 25 0 15 0; +#X connect 26 0 25 0; diff --git a/GdpdExample/main.gd b/GdpdExample/main.gd index 4a61b26..e687d16 100644 --- a/GdpdExample/main.gd +++ b/GdpdExample/main.gd @@ -1,10 +1,13 @@ extends RigidBody -export (String, MULTILINE) var patch = "" export (float, 0, 100) var audible_range_max = 10.0 +export (float, 1, 12) var preset = 1 + +export (bool) var use_embeded_patch = false +export (String, MULTILINE) var patch = "" -var _use_earplug = false var _my_patch = "res://main.pd" +#var _my_patch = "res://main-earplug.pd" var _my_id = 0 func set_size(size): @@ -24,13 +27,30 @@ func set_gain(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) -# _save_patch() + 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)) @@ -38,6 +58,9 @@ func _ready(): # listen 'player_transform_updated' event Events.connect("player_transform_updated", self, "_on_Events_player_transform_updated") + # send 'preset' + set_preset(preset) + func _on_Events_player_transform_updated(playerpos, playerheading): var mypos = get_global_translation() var mypos2d = Vector2(mypos.x, mypos.z) @@ -46,16 +69,11 @@ func _on_Events_player_transform_updated(playerpos, playerheading): 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 - # radians to degrees -# if angle < 0: -# angle = angle + PI*2 - angle = rad2deg(angle) + if angle > PI: + angle = angle - PI*2 # (check) # print(str(_my_id) +" : ("+ str(distance) +","+ str(angle) +")") # calculate gain -# var gain = max(1 - distance/audible_range_max, 0) var gain = 1 - distance/audible_range_max # send to the patch Global._gdpd.start_message(3) diff --git a/GdpdExample/main.pd b/GdpdExample/main.pd index ccbb2eb..9d95dfc 100644 --- a/GdpdExample/main.pd +++ b/GdpdExample/main.pd @@ -1,4 +1,4 @@ -#N canvas 574 271 456 518 12; +#N canvas 126 281 456 518 12; #X obj 361 21 loadbang; #X msg 361 51 \; pd dsp 1; #X floatatom 21 198 5 0 0 0 - - - 0; @@ -14,40 +14,67 @@ #X obj 21 286 bp~ 500 1000; #X obj 21 70 route freq gain panvol; #X obj 21 316 *~; -#X msg 296 338 \$1 100; -#X floatatom 296 159 5 0 0 0 - - - 0; -#X obj 199 437 earplug~ 0 0; -#X obj 296 362 line; #X obj 132 310 switch~; #X obj 132 286 tgl 19 0 empty empty empty 0 -10 0 12 #fcfcfc #000000 #000000 0 1; #X obj 132 262 change; #X text 89 155 switch on/off before 0 to stop startup pops, f 12; #X obj 189 216 max 0; #X obj 132 238 > -0.3; -#X obj 296 248 expr 360-$f1; +#X obj 303 253 hsl 100 20 -1 1 0 0 empty empty empty -2 -10 0 12 #fcfcfc #000000 #000000 0 1; +#X obj 300 349 line~; +#X msg 300 325 \$1 100; +#X obj 300 278 expr ($f1 + 1)/8; +#X floatatom 300 302 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 296 159 5 0 0 0 - - - 0; +#X obj 296 182 sin; +#X floatatom 296 206 5 0 0 0 - - - 0; #X connect 2 0 12 1; #X connect 3 0 4 0; #X connect 4 0 13 0; -#X connect 6 0 17 0; +#X connect 6 0 26 0; #X connect 7 0 6 1; #X connect 8 0 7 0; #X connect 9 0 10 0; -#X connect 9 1 16 0; -#X connect 10 0 23 0; -#X connect 10 0 24 0; +#X connect 9 1 27 0; +#X connect 10 0 19 0; +#X connect 10 0 20 0; #X connect 11 0 12 0; #X connect 12 0 14 0; #X connect 13 0 2 0; #X connect 13 1 14 1; #X connect 13 2 9 0; #X connect 14 0 6 0; -#X connect 15 0 18 0; -#X connect 16 0 25 0; -#X connect 17 0 5 0; -#X connect 17 1 5 1; -#X connect 18 0 17 1; -#X connect 20 0 19 0; -#X connect 21 0 20 0; -#X connect 23 0 8 0; -#X connect 24 0 21 0; -#X connect 25 0 15 0; +#X connect 16 0 15 0; +#X connect 17 0 16 0; +#X connect 19 0 8 0; +#X connect 20 0 17 0; +#X connect 21 0 24 0; +#X connect 22 0 26 1; +#X connect 23 0 22 0; +#X connect 24 0 25 0; +#X connect 25 0 23 0; +#X connect 26 0 5 0; +#X connect 26 1 5 1; +#X connect 27 0 28 0; +#X connect 28 0 29 0; +#X connect 29 0 21 0; diff --git a/GdpdExample/osc-earplug.pd b/GdpdExample/osc-earplug.pd new file mode 100644 index 0000000..9cfb577 --- /dev/null +++ b/GdpdExample/osc-earplug.pd @@ -0,0 +1,53 @@ +#N canvas 650 226 456 518 12; +#X obj 361 21 loadbang; +#X msg 361 51 \; pd dsp 1; +#X obj 50 277 osc~ 440; +#X floatatom 21 198 5 0 0 0 - - - 0; +#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 189 127 unpack f f; +#X obj 21 70 route freq gain panvol; +#X obj 50 301 *~; +#X msg 296 338 \$1 100; +#X floatatom 296 159 5 0 0 0 - - - 0; +#X obj 199 437 earplug~ 0 0; +#X obj 296 362 line; +#X obj 189 264 line~; +#X msg 189 240 \$1 100; +#X floatatom 189 177 5 0 0 0 - - - 0; +#X obj 132 310 switch~; +#X obj 132 286 tgl 19 0 empty empty empty 0 -10 0 12 #fcfcfc #000000 #000000 0 1; +#X obj 132 262 change; +#X text 89 155 switch on/off before 0 to stop startup pops, f 12; +#X obj 189 216 max 0; +#X obj 132 238 > -0.3; +#X obj 296 248 expr 360-$f1; +#X obj 296 182 expr $f1*180/3.141592; +#X connect 2 0 10 0; +#X connect 3 0 2 0; +#X connect 4 0 5 0; +#X connect 5 0 9 0; +#X connect 7 0 13 0; +#X connect 8 0 17 0; +#X connect 8 1 12 0; +#X connect 9 0 3 0; +#X connect 9 1 10 1; +#X connect 9 2 8 0; +#X connect 10 0 7 0; +#X connect 11 0 14 0; +#X connect 12 0 25 0; +#X connect 13 0 6 0; +#X connect 13 1 6 1; +#X connect 14 0 13 1; +#X connect 15 0 7 1; +#X connect 16 0 15 0; +#X connect 17 0 22 0; +#X connect 17 0 23 0; +#X connect 19 0 18 0; +#X connect 20 0 19 0; +#X connect 22 0 16 0; +#X connect 23 0 20 0; +#X connect 24 0 11 0; +#X connect 25 0 24 0; diff --git a/GdpdExample/osc.gd b/GdpdExample/osc.gd index df084d1..ca0b6f9 100644 --- a/GdpdExample/osc.gd +++ b/GdpdExample/osc.gd @@ -1,10 +1,13 @@ extends RigidBody -export (String, MULTILINE) var patch = "" export (float, 0, 100) var audible_range_max = 10.0 export (float, 1, 12) var preset = 1 +export (bool) var use_embeded_patch = false +export (String, MULTILINE) var patch = "" + var _my_patch = "res://osc.pd" +#var _my_patch = "res://osc-earplug.pd" var _my_id = 0 func set_size(size): @@ -44,7 +47,10 @@ func set_color(color): func _ready(): # save patch (for export) -# _save_patch() + 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)) @@ -63,16 +69,11 @@ func _on_Events_player_transform_updated(playerpos, playerheading): 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 - # radians to degrees -# if angle < 0: -# angle = angle + PI*2 - angle = rad2deg(angle) + if angle > PI: + angle = angle - PI*2 # (check) # print(str(_my_id) +" : ("+ str(distance) +","+ str(angle) +")") # calculate gain -# var gain = max(1 - distance/audible_range_max, 0) var gain = 1 - distance/audible_range_max # send to the patch Global._gdpd.start_message(3) @@ -84,7 +85,6 @@ func _on_Events_player_transform_updated(playerpos, playerheading): func _exit_tree(): Global.close_patch(_my_id) - pass func _save_patch(): # save patch diff --git a/GdpdExample/osc.pd b/GdpdExample/osc.pd index 19b0592..922e97f 100644 --- a/GdpdExample/osc.pd +++ b/GdpdExample/osc.pd @@ -1,4 +1,4 @@ -#N canvas 540 203 456 518 12; +#N canvas 659 277 456 518 12; #X obj 361 21 loadbang; #X msg 361 51 \; pd dsp 1; #X obj 50 277 osc~ 440; @@ -10,10 +10,6 @@ #X obj 189 127 unpack f f; #X obj 21 70 route freq gain panvol; #X obj 50 301 *~; -#X msg 296 338 \$1 100; -#X floatatom 296 159 5 0 0 0 - - - 0; -#X obj 199 437 earplug~ 0 0; -#X obj 296 362 line; #X obj 189 264 line~; #X msg 189 240 \$1 100; #X floatatom 189 177 5 0 0 0 - - - 0; @@ -23,29 +19,60 @@ #X text 89 155 switch on/off before 0 to stop startup pops, f 12; #X obj 189 216 max 0; #X obj 132 238 > -0.3; -#X obj 296 248 expr 360-$f1; +#X obj 303 253 hsl 100 20 -1 1 0 0 empty empty empty -2 -10 0 12 #fcfcfc #000000 #000000 0 1; +#X obj 300 349 line~; +#X msg 300 325 \$1 100; +#X obj 300 278 expr ($f1 + 1)/8; +#X floatatom 300 302 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 296 159 5 0 0 0 - - - 0; +#X obj 296 182 sin; +#X floatatom 296 206 5 0 0 0 - - - 0; #X connect 2 0 10 0; #X connect 3 0 2 0; #X connect 4 0 5 0; #X connect 5 0 9 0; -#X connect 7 0 13 0; -#X connect 8 0 17 0; -#X connect 8 1 12 0; +#X connect 7 0 25 0; +#X connect 8 0 13 0; +#X connect 8 1 26 0; #X connect 9 0 3 0; #X connect 9 1 10 1; #X connect 9 2 8 0; #X connect 10 0 7 0; -#X connect 11 0 14 0; -#X connect 12 0 24 0; -#X connect 13 0 6 0; -#X connect 13 1 6 1; -#X connect 14 0 13 1; -#X connect 15 0 7 1; +#X connect 11 0 7 1; +#X connect 12 0 11 0; +#X connect 13 0 18 0; +#X connect 13 0 19 0; +#X connect 15 0 14 0; #X connect 16 0 15 0; -#X connect 17 0 22 0; -#X connect 17 0 23 0; -#X connect 19 0 18 0; -#X connect 20 0 19 0; -#X connect 22 0 16 0; -#X connect 23 0 20 0; -#X connect 24 0 11 0; +#X connect 18 0 12 0; +#X connect 19 0 16 0; +#X connect 20 0 23 0; +#X connect 21 0 25 1; +#X connect 22 0 21 0; +#X connect 23 0 24 0; +#X connect 24 0 22 0; +#X connect 25 0 6 0; +#X connect 25 1 6 1; +#X connect 26 0 27 0; +#X connect 27 0 28 0; +#X connect 28 0 20 0; diff --git a/GdpdExample/osc.tscn b/GdpdExample/osc.tscn index 91e0835..45c2780 100644 --- a/GdpdExample/osc.tscn +++ b/GdpdExample/osc.tscn @@ -15,51 +15,6 @@ collision_mask = 0 physics_material_override = SubResource( 3 ) gravity_scale = 0.0 script = ExtResource( 1 ) -patch = "#N canvas 540 203 456 518 12; -#X obj 361 21 loadbang; -#X msg 361 51 \\; pd dsp 1; -#X obj 80 277 osc~ 440; -#X floatatom 21 198 5 0 0 0 - - - 0; -#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 189 230 line~; -#X msg 189 206 \\$1 100; -#X obj 189 127 unpack f f; -#X floatatom 189 177 5 0 0 0 - - - 0; -#X obj 21 70 route freq gain panvol; -#X obj 80 301 *~; -#X msg 296 338 \\$1 100; -#X floatatom 296 159 5 0 0 0 - - - 0; -#X obj 199 437 earplug~ 0 0; -#X obj 296 362 line; -#X obj 122 158 != 0; -#X obj 122 206 switch~; -#X obj 122 182 tgl 19 0 empty empty empty 0 -10 0 12 #fcfcfc #000000 #000000 0 1; -#X connect 2 0 13 0; -#X connect 3 0 2 0; -#X connect 4 0 5 0; -#X connect 5 0 12 0; -#X connect 7 0 16 0; -#X connect 8 0 7 1; -#X connect 9 0 8 0; -#X connect 10 0 11 0; -#X connect 10 1 15 0; -#X connect 11 0 9 0; -#X connect 11 0 18 0; -#X connect 12 0 3 0; -#X connect 12 1 13 1; -#X connect 12 2 10 0; -#X connect 13 0 7 0; -#X connect 14 0 17 0; -#X connect 15 0 14 0; -#X connect 16 0 6 0; -#X connect 16 1 6 1; -#X connect 17 0 16 1; -#X connect 18 0 20 0; -#X connect 20 0 19 0; -" [node name="CollisionShape" type="CollisionShape" parent="."] shape = SubResource( 1 )