-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocessador.lua
More file actions
282 lines (207 loc) · 7.4 KB
/
processador.lua
File metadata and controls
282 lines (207 loc) · 7.4 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
package.path = './lib/?.lua;' .. package.path
require "xml.xml"
require "xml.handler"
require "xml.tableToXML"
-- Print contents of `tbl`, with indentation.
-- `indent` sets the initial level of indentation.
function tprint(tbl, indent)
if not indent then indent = 0 end
for k, v in pairs(tbl) do
formatting = string.rep(" ", indent) .. k .. ": "
if type(v) == "table" then
print(formatting)
tprint(v, indent+1)
else
print(formatting .. v)
end
end
end
function deepcopy(orig)
local orig_type = type(orig)
local copy
if orig_type == 'table' then
copy = {}
for orig_key, orig_value in next, orig, nil do
copy[deepcopy(orig_key)] = deepcopy(orig_value)
end
setmetatable(copy, deepcopy(getmetatable(orig)))
else -- number, string, boolean, etc
copy = orig
end
return copy
end
function table.removekey(table, key)
local element = table[key]
table[key] = nil
return element
end
local function contains(table, val)
for i=1,#table do
if table[i] == val then
return true
end
end
return false
end
function splitFilename(strFilename)
-- Returns the Path, Filename, and Extension as 3 values
sep = package.config:sub(1,1)
print(sep)
return string.match(strFilename, "(.-)([^"..sep..sep.."]-([^"..sep..sep.."%.]+))$")
end
function getTags(table)
local tags = {}
if table.area then
for i=1, #table.area do
if table.area[i]._attr["tag"] then
tags[i] = table.area[i]._attr["tag"]
end
end
return tags
end
end
local function has_value (tab, val)
for index, value in pairs(tab) do
if value == val then
return true
end
end
return false
end
path,file,extension = splitFilename(arg[1])
print(path,file,extension)
if (extension ~= "ncl") then
error("Voce deve passar um arquivo com a extensao .ncl")
end
filename_in = arg[1]
f, e = io.open(filename_in, "r")
if f then
xmltextNCL = f:read("*a")
else
error(e)
end
--Instantiate the object the states the XML file as a Lua table
xmlhandlerNCL = simpleTreeHandler()
--Instantiate the object that parses the XML to a Lua table
xmlparserNCL = xmlParser(xmlhandlerNCL)
xmlparserNCL:parse(xmltextNCL)
res = showTable(xmlhandlerNCL.root)
--print(res)
effect_id_list = {}
-- loop para buscar os atributos de mídia de efeitos sensoriais
for key, value in pairs(xmlhandlerNCL.root.ncl.body.media) do
has_sensory_effects = "no"
player_increment = 1
if(value._attr.setype) then
has_sensory_effects = "yes"
end
print("media:'".. value._attr.id .."'has sensory effects?:".. has_sensory_effects)
if(has_sensory_effects == "yes") then
effect_id_list[#effect_id_list+1] = value._attr.id
-- Criar uma nova area para essa mídia
value.area = {}
value.area._attr = {}
value.area._attr.id = {}
value.area._attr["id"] = "effectInterface"
-- adicionar um novo arquivo lua que vai representar o efeito sensorial
-- será um novo arquivo para cada mídia de efeito sensorial
-- esse arquivo deverá ter os valores de atributos
player_instance_name = ""..effect_id_list[#effect_id_list].."_"..value._attr.setype.."Player.lua" -- string.format("%04d",player_increment)
value._attr.src = player_instance_name
-- Remover o SEtype do NCL
effect_type = value._attr.setype
value._attr.setype = nil
effect_properties = {}
-- Salvar as propriedades de mídia numa tabela
for _,property in pairs(value.property) do
if(property._attr.name) then
effect_properties[property._attr.name] = property._attr.value
end
end
-- transformar a localização de NCL para string
if(effect_properties["azimuthal"] and effect_properties["polar"]) then
effect_location = "{"..effect_properties["azimuthal"]..","..effect_properties["polar"]..""
effect_properties["azimuthal"],effect_properties["polar"] = nil
else
if(effect_properties["wcs"]) then
effect_location = "{"..effect_properties["wcs"]..""
effect_properties["wcs"] = nil
else
error("Nao identificados parametros de localização do efeito. Você deve usar (azimulhal,polar) ou (WCS) ")
end
end
if(effect_properties["width"] and effect_properties["height"]) then
effect_location = effect_location .. "," .. effect_properties["width"] .. "," .. effect_properties["height"] .. "}"
effect_properties["width"],effect_properties["height"] = nil
else
effect_location = effect_location .. "}"
end
player_instance = [[
--- automatically created palyer instance
function main()
require('event')
package.path = './lib/?.lua;' .. package.path
local SEplayer = require('lib.SEplayer.SEplayer')
local effect = {}]].."\n"
player_instance = player_instance .. "effect.type = '"..effect_type.."'\n"
player_instance = player_instance .. "effect.location = "..effect_location.."\n"
-- adicionando o restante das propriedades
for k,v in pairs(effect_properties) do
player_instance = player_instance .. "effect."..k.. " = '" .. v .. "'\n"
end
player_instance = player_instance .. "print('"..player_instance_name.." iniciado')"
player_instance = player_instance .. [[
local player = SEplayer:new(effect)
function handler(evt)
if (evt.class ~= 'ncl') then return end
if (evt.type == 'presentation') and (evt.label == 'effectInterface') then
player:presentation(evt)
elseif (evt.type == 'attribution') then
effect[evt.name] = evt.value
end
end
function post_evt(action)
evt = {}
evt.class = 'ncl'
evt.type = 'presentation'
evt.label = 'effectInterface'
evt.action = action
event.post(evt)
end
event.register(handler)
player:register(post_evt)
end
local ok, res = pcall(main)
if not ok then
print("\n\nError: "..res, "\n\n")
return -1
end
]]
local file = io.open(""..path..""..player_instance_name, "w")
file:write(player_instance)
file:close()
end
end
-- alterar restante do documento para ficar consistente com o novo .lua
-- passo necessário para podermos inserir novas portas com table.insert
if(xmlhandlerNCL.root.ncl.body.port._attr)then
temp_table = deepcopy(xmlhandlerNCL.root.ncl.body.port)
xmlhandlerNCL.root.ncl.body.port = {}
xmlhandlerNCL.root.ncl.body.port[1] = temp_table
end
for _,effect_id in pairs(effect_id_list) do
-- Criar uma porta para essa mídia ( p/ forçar a inicialização do .lua)
temp_table = {_attr={}}
temp_table._attr["id"] = "p"..effect_id
temp_table._attr["component"] = effect_id
table.insert(xmlhandlerNCL.root.ncl.body.port,temp_table)
-- já que estamos aqui, vamos buscar links (~=set) e inserir a interface neles
for link_key, link_value in pairs(xmlhandlerNCL.root.ncl.body.link) do
for _,bind_v in pairs(link_value.bind) do
if(bind_v._attr.role ~= "set" and bind_v._attr.component == effect_id) then
bind_v._attr["interface"] = "effectInterface"
end
end
end
end
writeToXml(xmlhandlerNCL.root,""..arg[1].."_ready.ncl")