111 lines
2.9 KiB
Text
111 lines
2.9 KiB
Text
[gd_scene load_steps=2 format=2]
|
|
|
|
[sub_resource type="GDScript" id=1]
|
|
script/source = "extends Control
|
|
|
|
var _gdpd
|
|
var _patches = []
|
|
|
|
func _load_patch(pd_patch) :
|
|
#separate file name from directory
|
|
var patch_name = pd_patch.split(\"/\")[-1]
|
|
var patch_dir = pd_patch.trim_suffix(patch_name)
|
|
|
|
#load patch
|
|
var id = _gdpd.openPatch(patch_name, patch_dir)
|
|
_patches.append(id)
|
|
# print(\"loading:\" + str(id))
|
|
|
|
func _ready() :
|
|
_gdpd = load(\"res://addons/gdpd/bin/gdpd.gdns\").new()
|
|
|
|
func _process(delta) :
|
|
while _gdpd.has_message() :
|
|
var msg = _gdpd.get_next()
|
|
print(msg)
|
|
if msg[0] == \"random\" :
|
|
# print(\"r\")
|
|
pass
|
|
|
|
func _on_Start_pressed() :
|
|
var inps = _gdpd.get_available_input_devices()
|
|
var outs = _gdpd.get_available_output_devices()
|
|
# _gdpd.init(0, 2, 48000, 64)
|
|
_gdpd.init_devices(inps[0], outs[0])
|
|
|
|
#the patch path should be the absolute one
|
|
_load_patch(ProjectSettings.globalize_path(\"res://patch.pd\"))
|
|
_load_patch(ProjectSettings.globalize_path(\"res://patch.pd\"))
|
|
_load_patch(ProjectSettings.globalize_path(\"res://patch.pd\"))
|
|
_load_patch(ProjectSettings.globalize_path(\"res://patch.pd\"))
|
|
_load_patch(ProjectSettings.globalize_path(\"res://patch.pd\"))
|
|
_load_patch(ProjectSettings.globalize_path(\"res://patch.pd\"))
|
|
_load_patch(ProjectSettings.globalize_path(\"res://patch.pd\"))
|
|
_load_patch(ProjectSettings.globalize_path(\"res://patch.pd\"))
|
|
_load_patch(ProjectSettings.globalize_path(\"res://patch.pd\"))
|
|
_load_patch(ProjectSettings.globalize_path(\"res://patch.pd\"))
|
|
|
|
_gdpd.subscribe(\"toGodot\")
|
|
|
|
func _on_Stop_pressed() :
|
|
print(_patches)
|
|
for id in _patches:
|
|
# print(\"closing:\" + str(id))
|
|
_gdpd.closePatch(id)
|
|
# _patches.erase(id) # <= BAD!
|
|
# Do not erase entries while iterating over the array !!
|
|
_patches.clear()
|
|
_gdpd.stop()
|
|
|
|
func _on_Send_pressed() :
|
|
_gdpd.start_message(1)
|
|
_gdpd.add_float(300)
|
|
_gdpd.finish_list(\"fromGodot\")
|
|
|
|
"
|
|
|
|
[node name="Control" type="Control"]
|
|
anchor_right = 1.0
|
|
anchor_bottom = 1.0
|
|
script = SubResource( 1 )
|
|
__meta__ = {
|
|
"_edit_use_anchors_": false
|
|
}
|
|
|
|
[node name="Stop" type="Button" parent="."]
|
|
anchor_left = 0.5
|
|
anchor_top = 0.5
|
|
anchor_right = 0.5
|
|
anchor_bottom = 0.5
|
|
margin_left = -50.0
|
|
margin_top = 75.0
|
|
margin_right = 50.0
|
|
margin_bottom = 125.0
|
|
text = "Stop"
|
|
|
|
[node name="Start" type="Button" parent="."]
|
|
anchor_left = 0.5
|
|
anchor_top = 0.5
|
|
anchor_right = 0.5
|
|
anchor_bottom = 0.5
|
|
margin_left = -50.0
|
|
margin_top = -125.0
|
|
margin_right = 50.0
|
|
margin_bottom = -75.0
|
|
text = "Start"
|
|
|
|
[node name="Send" type="Button" parent="."]
|
|
anchor_left = 0.5
|
|
anchor_top = 0.5
|
|
anchor_right = 0.5
|
|
anchor_bottom = 0.5
|
|
margin_left = -50.0
|
|
margin_top = -25.0
|
|
margin_right = 50.0
|
|
margin_bottom = 25.0
|
|
text = "send"
|
|
|
|
[connection signal="pressed" from="Stop" to="." method="_on_Stop_pressed"]
|
|
[connection signal="pressed" from="Start" to="." method="_on_Start_pressed"]
|
|
[connection signal="pressed" from="Send" to="." method="_on_Send_pressed"]
|