-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIOMenu.gd
80 lines (54 loc) · 1.98 KB
/
IOMenu.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
extends Panel
func _ready():
$OpenDialog.current_dir = ProjectSettings.globalize_path("res://") + "demo/bank0/"
print (OS.get_executable_path().get_base_dir())
func _on_OpenDialog_file_selected(path):
if !global.currentPatch:
print("PatchEdit: Can't load, patch doesn't exist")
return
var f = File.new()
var ferr = f.open(path, File.READ)
$"../Audio".StopAll() #Stop active notes before loading the string in to prevent null access.
var err = global.currentPatch.FromString(f.get_as_text())
f.close()
if ferr != OK:
print ("File error %s." % ferr)
elif err != 0:
print ("Load attempt returned error code %s from patch." % err)
else:
#Update the UI to reflect the new patch settings.
owner.get_node("GraphEdit").wire_up(global.currentPatch.wiring)
yield(get_tree(), "idle_frame")
owner.update_ui()
func _on_SaveDialog_file_selected(path):
if !global.currentPatch:
print("PatchEdit: Can't save, patch doesn't exist")
return
var f = File.new()
f.open(path, File.WRITE)
f.store_string(global.currentPatch.IOString())
f.close()
func _on_Dialog_about_to_show():
$OpenDialog.invalidate()
$SaveDialog.invalidate()
pass # Replace with function body.
func _on_Open_pressed():
$OpenDialog.popup_centered()
func _on_Save_pressed():
$SaveDialog.popup_centered()
func _on_Copy_pressed():
if !global.currentPatch: return
OS.clipboard = global.currentPatch.ToString()
func _on_Paste_pressed():
if !global.currentPatch:
print("PatchEdit: Can't paste, patch doesn't exist")
return
$"../Audio".StopAll() #Stop active notes before loading the string in to prevent null access.
var err = global.currentPatch.FromString(OS.clipboard, true) #Second argument specifies to ignore IO version.
if err != 0:
print ("Paste attempt returned error code %s from patch." % err)
else:
#Update the UI to reflect the new patch settings.
owner.get_node("GraphEdit").wire_up(global.currentPatch.wiring)
yield(get_tree(), "idle_frame")
owner.update_ui()