98 lines
2.8 KiB
GDScript
98 lines
2.8 KiB
GDScript
extends Node
|
|
|
|
export (bool) var use_embeded_patch = false
|
|
export (String, MULTILINE) var patch1 = ""
|
|
export (String, MULTILINE) var patch2 = ""
|
|
|
|
var _my_patch1 = "user://autoload/outL.pd"
|
|
var _my_patch2 = "user://autoload/outR.pd"
|
|
var _my_id1 = 0
|
|
var _my_id2 = 0
|
|
|
|
var _reverb = false
|
|
var _lowpass = false
|
|
|
|
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_id1))
|
|
Global._gdpd.start_message(2)
|
|
Global._gdpd.add_symbol('gain')
|
|
Global._gdpd.add_float(gain)
|
|
Global._gdpd.finish_list("fromGodot" + String(_my_id2))
|
|
|
|
func set_reverb(reverb):
|
|
Global._gdpd.start_message(2)
|
|
Global._gdpd.add_symbol('reverb')
|
|
Global._gdpd.add_float(reverb)
|
|
Global._gdpd.finish_list("fromGodot" + String(_my_id1))
|
|
Global._gdpd.start_message(2)
|
|
Global._gdpd.add_symbol('reverb')
|
|
Global._gdpd.add_float(reverb)
|
|
Global._gdpd.finish_list("fromGodot" + String(_my_id2))
|
|
|
|
func set_lowpass(lowpass):
|
|
Global._gdpd.start_message(2)
|
|
Global._gdpd.add_symbol('lowpass')
|
|
Global._gdpd.add_float(lowpass)
|
|
Global._gdpd.finish_list("fromGodot" + String(_my_id1))
|
|
Global._gdpd.start_message(2)
|
|
Global._gdpd.add_symbol('lowpass')
|
|
Global._gdpd.add_float(lowpass)
|
|
Global._gdpd.finish_list("fromGodot" + String(_my_id2))
|
|
|
|
func _ready():
|
|
# save patch (for export)
|
|
if use_embeded_patch:
|
|
assert(_my_patch1.substr(0, 7) == "user://", "use userpath with embeded_patch enabled !")
|
|
assert(_my_patch2.substr(0, 7) == "user://", "use userpath with embeded_patch enabled !")
|
|
assert(patch1 != "", "patch is empty?")
|
|
assert(patch2 != "", "patch is empty?")
|
|
_save_patch()
|
|
|
|
# load patch
|
|
_my_id1 = Global.load_patch(ProjectSettings.globalize_path(_my_patch1))
|
|
_my_id2 = Global.load_patch(ProjectSettings.globalize_path(_my_patch2))
|
|
|
|
# set start-up defaults
|
|
set_gain(1)
|
|
set_reverb(0)
|
|
set_lowpass(0)
|
|
|
|
func _exit_tree():
|
|
Global.close_patch(_my_id1)
|
|
Global.close_patch(_my_id2)
|
|
|
|
func _process(delta):
|
|
if Input.is_action_just_pressed("reverb"):
|
|
_reverb = not _reverb
|
|
set_reverb(float(_reverb))
|
|
|
|
if Input.is_action_just_pressed("lowpass"):
|
|
_lowpass = not _lowpass
|
|
set_lowpass(float(_lowpass))
|
|
|
|
func _save_patch():
|
|
# save patch
|
|
# prepare directory
|
|
var patch_name1 = _my_patch1.split("/")[-1]
|
|
var patch_dir1 = _my_patch1.trim_suffix(patch_name1)
|
|
var dir1 = Directory.new()
|
|
dir1.make_dir_recursive(patch_dir1)
|
|
# save to file
|
|
var file1 = File.new()
|
|
file1.open(_my_patch1, File.WRITE)
|
|
file1.store_string(patch1)
|
|
file1.close()
|
|
####
|
|
var patch_name2 = _my_patch2.split("/")[-1]
|
|
var patch_dir2 = _my_patch2.trim_suffix(patch_name2)
|
|
var dir2 = Directory.new()
|
|
dir2.make_dir_recursive(patch_dir2)
|
|
# save to file
|
|
var file2 = File.new()
|
|
file2.open(_my_patch2, File.WRITE)
|
|
file2.store_string(patch2)
|
|
file2.close()
|