Skip to content

Commit 336f59d

Browse files
author
Liam Sherwin
committed
Art-Net Output From Desk
1 parent c7c2866 commit 336f59d

File tree

8 files changed

+198
-77
lines changed

8 files changed

+198
-77
lines changed

Main.tscn

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ layout_mode = 2
589589
size_flags_horizontal = 2
590590
text = "Ip Address"
591591

592-
[node name="Art Net Port" type="LineEdit" parent="TabContainer/Patch Bay/VBoxContainer/HSplitContainer/PanelContainer2/VSplitContainer/PanelContainer/VBoxContainer/GridContainer/PanelContainer2/VBoxContainer/IO Controls/Art-Net/HBoxContainer"]
592+
[node name="Art Net IP" type="LineEdit" parent="TabContainer/Patch Bay/VBoxContainer/HSplitContainer/PanelContainer2/VSplitContainer/PanelContainer/VBoxContainer/GridContainer/PanelContainer2/VBoxContainer/IO Controls/Art-Net/HBoxContainer"]
593593
custom_minimum_size = Vector2(145.25, 0)
594594
layout_mode = 2
595595
size_flags_horizontal = 10
@@ -683,6 +683,7 @@ text = "Universe "
683683
custom_minimum_size = Vector2(200, 0)
684684
layout_mode = 2
685685
item_count = 1
686+
allow_reselect = true
686687
popup/item_0/text = " "
687688
popup/item_0/id = 0
688689

@@ -943,7 +944,7 @@ script = ExtResource("25_w0caf")
943944
[connection signal="pressed" from="TabContainer/Patch Bay/VBoxContainer/HSplitContainer/PanelContainer2/VSplitContainer/PanelContainer/VBoxContainer/PanelContainer/Universe Controls/New Output" to="TabContainer/Patch Bay" method="_on_new_output_pressed"]
944945
[connection signal="pressed" from="TabContainer/Patch Bay/VBoxContainer/HSplitContainer/PanelContainer2/VSplitContainer/PanelContainer/VBoxContainer/PanelContainer/Universe Controls/New Channel Overide" to="TabContainer/Patch Bay" method="_on_new_channel_overide_pressed"]
945946
[connection signal="item_selected" from="TabContainer/Patch Bay/VBoxContainer/HSplitContainer/PanelContainer2/VSplitContainer/PanelContainer/VBoxContainer/GridContainer/PanelContainer2/VBoxContainer/IO Type" to="TabContainer/Patch Bay" method="_on_io_type_item_selected"]
946-
[connection signal="text_submitted" from="TabContainer/Patch Bay/VBoxContainer/HSplitContainer/PanelContainer2/VSplitContainer/PanelContainer/VBoxContainer/GridContainer/PanelContainer2/VBoxContainer/IO Controls/Art-Net/HBoxContainer/Art Net Port" to="TabContainer/Patch Bay" method="_on_art_net_port_text_submitted"]
947+
[connection signal="text_submitted" from="TabContainer/Patch Bay/VBoxContainer/HSplitContainer/PanelContainer2/VSplitContainer/PanelContainer/VBoxContainer/GridContainer/PanelContainer2/VBoxContainer/IO Controls/Art-Net/HBoxContainer/Art Net IP" to="TabContainer/Patch Bay" method="_on_art_net_ip_text_submitted"]
947948
[connection signal="value_changed" from="TabContainer/Patch Bay/VBoxContainer/HSplitContainer/PanelContainer2/VSplitContainer/PanelContainer/VBoxContainer/GridContainer/PanelContainer2/VBoxContainer/IO Controls/Art-Net/HBoxContainer2/Art Net Port" to="TabContainer/Patch Bay" method="_on_art_net_port_value_changed"]
948949
[connection signal="value_changed" from="TabContainer/Patch Bay/VBoxContainer/HSplitContainer/PanelContainer2/VSplitContainer/PanelContainer/VBoxContainer/GridContainer/PanelContainer2/VBoxContainer/IO Controls/Art-Net/HBoxContainer3/Art Net Universe" to="TabContainer/Patch Bay" method="_on_art_net_universe_value_changed"]
949950
[connection signal="item_selected" from="TabContainer/Desk/VSplitContainer/PanelContainer/VBoxContainer/PanelContainer/HBoxContainer/Desk Universe Option" to="TabContainer/Desk" method="_on_desk_universe_option_item_selected"]

Scripts/Classes/Art_net.gd

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,30 @@ extends Node
22
class_name ArtNet
33

44
var _udp_peer = PacketPeerUDP.new()
5-
var target_ip = "172.0.0.1"
6-
var target_port = 6454
75

8-
var _formatted_dmx_data = []
9-
var _packet_id = 0
6+
var art_net = {
7+
"ip":"172.0.0.1",
8+
"port":6454,
9+
"universe":0,
10+
"name":"Art-Net Output",
11+
"type":"Art-Net"
12+
}
1013

1114
func connect_to_host():
1215
_udp_peer.close()
13-
_udp_peer.connect_to_host(target_ip, target_port)
14-
15-
#func receive(data, _slot):
16-
#if typeof(data) != 27:
17-
#return
18-
#_formatted_dmx_data = []
19-
#for channel in range(1, 513):
20-
#_formatted_dmx_data.append(data.dmx_channels.get(channel, 0))
21-
#send_artnet_packet(data.universe-1)
22-
#print(_formatted_dmx_data)
23-
24-
func send_packet(universe,dmx_data):
25-
print(universe)
16+
print(_udp_peer.connect_to_host(art_net.ip, art_net.port))
17+
18+
func _get_name():
19+
return art_net.name
20+
21+
func _set_name(name):
22+
art_net.name = name
23+
24+
func get_type():
25+
return art_net.type
26+
27+
28+
func send_packet(dmx_data):
2629
print(dmx_data)
2730
# Construct Art-Net packet
2831
var packet = PackedByteArray()
@@ -44,20 +47,20 @@ func send_packet(universe,dmx_data):
4447
packet.append(0)
4548

4649
# Universe (16-bit)
47-
packet.append(universe)
48-
packet.append(0)
50+
packet.append(art_net.universe % 256) # Lower 8 bits
51+
packet.append(art_net.universe / 256) # Upper 8 bits
4952

5053
# Length (16-bit)
5154
# packet.append_array([512 % 256, int(512 / 255)])
5255
packet.append(02)
5356
packet.append(00)
5457

5558
# DMX Channels
56-
for value in dmx_data:
57-
packet.append(value)
59+
for channel in range(1, 513):
60+
packet.append(dmx_data.get(channel, 0))
61+
print(dmx_data.get(channel, 0))
5862

5963
# Send the packet
6064
# _udp_peer.set_dest_address(ip, port)
61-
print(packet)
62-
print(_udp_peer.put_packet(packet))
65+
_udp_peer.put_packet(packet)
6366

Scripts/Classes/Empty.gd

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
extends Node
2+
class_name Empty
3+
4+
func _get_name():
5+
return "Empty"
6+
7+
func get_type():
8+
return "Empty"

Scripts/Classes/Universe.gd

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
extends Node
22
class_name Universe
33

4+
const Art_Net = preload("res://Scripts/Classes/Art_net.gd")
5+
const Empty = preload("res://Scripts/Classes/Empty.gd")
6+
7+
48
var universe = {
59
"name": "New Universe",
610
"uuid":Globals.new_uuid(),
@@ -9,6 +13,13 @@ var universe = {
913
"inputs": {
1014
},
1115
"outputs": {
16+
17+
},
18+
"dmx_data":{
19+
20+
},
21+
"desk_data":{
22+
1223
}
1324
}
1425

@@ -21,10 +32,34 @@ func _get_name():
2132
func get_uuid():
2233
return universe.uuid
2334

24-
func new_input(type):
35+
func get_all_outputs():
36+
return universe.outputs
37+
38+
func get_output(uuid=""):
39+
if uuid:
40+
return universe.outputs[uuid]
41+
return
42+
43+
func new_output(type=""):
2544
var uuid = Globals.new_uuid()
45+
universe.outputs[uuid] = {}
46+
return change_output_type(uuid, type)
47+
48+
func change_output_type(uuid, type):
49+
if not type: type == "Empty"
2650
match type:
2751
"Empty":
28-
universe.inputs[uuid] = {}
52+
universe.outputs[uuid] = Empty.new()
2953
"Art-Net":
30-
universe.inputs[uuid] = {}
54+
universe.outputs[uuid] = Art_Net.new()
55+
universe.outputs[uuid].connect_to_host()
56+
return universe.outputs[uuid]
57+
58+
func set_desk_data(dmx_data):
59+
universe.desk_data.merge(dmx_data, true)
60+
_compile_and_send()
61+
62+
func _compile_and_send():
63+
var compiled_dmx_data = universe.desk_data
64+
for output in universe.outputs:
65+
universe.outputs[output].send_packet(compiled_dmx_data)

Scripts/Desk.gd

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
extends Control
22

3-
var dmx_data = []
3+
var dmx_data = {}
44
var universe = 1
5+
6+
var current_universe
7+
58
# Called when the node enters the scene tree for the first time.
69
func _ready():
7-
dmx_data.resize(512)
8-
dmx_data.fill(0)
910

1011
for i in range(1, 513):
1112
var node_to_add = Globals.components.channel_slider.instantiate()
@@ -18,11 +19,15 @@ func reload_universes():
1819
Globals.nodes.desk_universe_option.clear()
1920
for universe in Globals.universes:
2021
Globals.nodes.desk_universe_option.add_item(Globals.universes[universe].name)
21-
22+
23+
Globals.nodes.desk_universe_option.select(0)
24+
2225
func slider_changed(value, channel):
23-
dmx_data[channel-1] = value
24-
Globals.set_desk_data(universe, dmx_data)
26+
dmx_data[channel] = value
27+
current_universe.set_desk_data(dmx_data)
28+
#Globals.set_desk_data(universe, dmx_data)
2529

2630

2731
func _on_desk_universe_option_item_selected(index):
28-
universe = index
32+
print()
33+
current_universe = Globals.universes[Globals.universes.keys()[index]]

Scripts/Global.gd

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,7 @@ func reload_universe_io_connections(io={}):
200200
print(universes)
201201

202202
func _ready():
203-
art_net_sender.target_ip = "192.168.1.53"
204-
art_net_sender.connect_to_host()
205-
var dmx = []
206-
dmx.resize(512)
207-
dmx.fill(255)
208-
art_net_sender.send_packet(0, dmx)
203+
pass
209204

210205
func new_universe():
211206
var new_universe = Universe.new()

Scripts/Patch_bay.gd

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ extends Control
33
var current_universe_uuid
44
var current_io_uuid
55
var current_io_type
6+
var current_io
67

78
var input_options = [
89
"Empty",
@@ -39,6 +40,7 @@ func delete_request(node):
3940
universes[current_universe_uuid].outputs.erase(node.get_meta("output_uuid"))
4041
current_io_uuid = ""
4142
current_io_type = ""
43+
current_io = ""
4244
reload_io()
4345

4446
).bind(node))
@@ -48,14 +50,15 @@ func edit_request(node):
4850
match node.get_meta("type"):
4951
"universe":
5052
current_universe_uuid = node.get_meta("universe_uuid")
51-
Globals.nodes.universe_name.text = universes[current_universe_uuid].name
53+
Globals.nodes.universe_name.text = universes[current_universe_uuid].get_name()
5254

5355
set_universe_controls_enabled(true)
5456
reload_io()
5557
"output":
5658
current_io_uuid = node.get_meta("output_uuid")
5759
current_io_type = "output"
58-
set_io_controls_enabled(true, universes[current_universe_uuid].outputs[current_io_uuid].type)
60+
current_io = universes[current_universe_uuid].get_output(current_io_uuid)
61+
set_io_controls_enabled(true, universes[current_universe_uuid].get_output(current_io_uuid).get_type())
5962
reload_io()
6063

6164
func on_edit_mode_changed(edit_mode):
@@ -110,45 +113,50 @@ func new_input():
110113
Globals.nodes.universe_inputs.add_child(node_to_add)
111114

112115
func new_output():
113-
var output_uuid = Globals.new_uuid()
114-
115-
universes[current_universe_uuid].outputs[output_uuid] = {
116-
"type":"Empty",
117-
"name":"Empty Output",
118-
"settings":{
119-
120-
}
121-
}
116+
universes[current_universe_uuid].new_output("Empty")
117+
#var output_uuid = Globals.new_uuid()
118+
#
119+
#universes[current_universe_uuid].outputs[output_uuid] = {
120+
#"type":"Empty",
121+
#"name":"Empty Output",
122+
#"settings":{
123+
#
124+
#}
125+
#}
122126
reload_io()
123127

124128
func reload_io():
125129
if not current_universe_uuid:return
130+
126131
for node in Globals.nodes.universe_outputs.get_children():
127132
node.queue_free()
128-
for uuid in universes[current_universe_uuid].outputs:
129-
var output = universes[current_universe_uuid].outputs[uuid]
133+
134+
for uuid in universes[current_universe_uuid].get_all_outputs().keys():
135+
var output = universes[current_universe_uuid].get_output(uuid)
130136
var node_to_add = Globals.components.list_item.instantiate()
131-
node_to_add.set_item_name(output.name)
137+
print(output)
138+
node_to_add.set_item_name(output._get_name())
132139
node_to_add.control_node = self
133140
node_to_add.set_meta("output_uuid", uuid)
134141
node_to_add.set_meta("type", "output")
135142
node_to_add.name = uuid
136143
node_to_add.set_highlighted(false)
137144

138145
if current_io_uuid == uuid:
139-
if output.type:
140-
Globals.nodes.universe_io_type.selected = output_options.find(output.type)
141-
node_to_add.set_highlighted(true)
142-
if output.type != "Empty":
146+
if output.get_type():
147+
Globals.nodes.universe_io_type.selected = output_options.find(output.get_type())
148+
149+
if output.get_type() != "Empty":
143150
for node in Globals.nodes.universe_io_controls.get_children():
144-
if node.name == output.type:
151+
if node.name == output.get_type():
145152
node.visible = true
146153
else:
154+
147155
node.visible = false
156+
node_to_add.set_highlighted(true)
148157

149158
Globals.nodes.universe_outputs.add_child(node_to_add)
150159

151-
152160
func set_universe_controls_enabled(enabled):
153161
for node in Globals.nodes.universe_controls.get_children():
154162
if node is LineEdit:
@@ -167,7 +175,6 @@ func set_io_controls_enabled(enabled, type):
167175
node.visible = false
168176

169177

170-
171178
# Button Callbacks
172179

173180
func _on_io_type_item_selected(index):
@@ -177,27 +184,20 @@ func _on_io_type_item_selected(index):
177184
set_io_controls_enabled(true, input_options[index])
178185

179186
elif current_io_type == "output":
180-
universes[current_universe_uuid].outputs[current_io_uuid].type = output_options[index]
187+
current_io = universes[current_universe_uuid].change_output_type(current_io_uuid, output_options[index])
181188
set_io_controls_enabled(true, output_options[index])
182-
match output_options[index]:
183-
"Art-Net":
184-
universes[current_universe_uuid].outputs[current_io_uuid].settings = {
185-
"ip":"172.0.0.1",
186-
"port":6454,
187-
"universe":0
188-
}
189-
"Empty":
190-
universes[current_universe_uuid].outputs[current_io_uuid].settings = {}
191189
reload_io()
192190

193-
func _on_art_net_port_text_submitted(new_text):
194-
universes[current_universe_uuid].outputs[current_io_uuid].settings.ip = new_text
191+
func _on_art_net_ip_text_submitted(new_text):
192+
current_io.art_net.ip = new_text
193+
current_io.connect_to_host()
195194

196195
func _on_art_net_port_value_changed(value):
197-
universes[current_universe_uuid].outputs[current_io_uuid].settings.port = value
196+
current_io.art_net.port = value
197+
current_io.connect_to_host()
198198

199199
func _on_art_net_universe_value_changed(value):
200-
universes[current_universe_uuid].outputs[current_io_uuid].settings.universe = value
200+
current_io.art_net.universe = int(value)
201201

202202
func _on_new_universe_pressed():
203203
new_universe()

0 commit comments

Comments
 (0)