soby 0.1.0 → 0.1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/soby/presentation.rb +83 -81
  3. metadata +14 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5d65c06b2a1b4f7fb9baa781273823ee83a98dbf
4
- data.tar.gz: 4be8a4d47977a8c4e635010bf8929b73118b2f8c
3
+ metadata.gz: 40ca6eed485167e4e748ae296923bcfb926caf41
4
+ data.tar.gz: 7e75b024e1246f547bf608e1c5d8c93145f09d11
5
5
  SHA512:
6
- metadata.gz: 7021ff045f8a62b4c998d65494578987bbdae8e9bda04a5f3d9f9f51f91864e6c93a4331d9b34610453d7206059695a23ee150a1675763c75574809ed353d919
7
- data.tar.gz: e79848a3b0e5fea1a683c59d1688f98b1624a8701730fd8e57878eda451921c73a36a65ab86111f6e17137af48a9f159ed75616fed856e81d69c714eb00fb9db
6
+ metadata.gz: db03a0890923583db6da54e5efad62774c7e72a7542f92d8041233c5a59952ca218d639841fb21e54e7b6c0053b83f5d197ff43c6040bb3806c552a0ceab6c82
7
+ data.tar.gz: a1be61b2207d228fa3634e7524b3bb97ba09cde88ced8767ff82ced3b6307c1dad7b5d1b8525c7676f295e33c071cf57369cc778e66332111dee9787d7405d3c
@@ -1,12 +1,12 @@
1
1
  require 'ostruct'
2
2
  require 'base64'
3
3
 
4
- class Presentation
4
+ class Presentation
5
5
 
6
6
  include_package 'processing.core'
7
7
 
8
- include Soby
9
-
8
+ include Soby
9
+
10
10
  attr_accessor :geometry, :slides, :pshape, :svg, :transform
11
11
  attr_accessor :width, :height, :matrix, :videos
12
12
  attr_reader :nb_slides, :debug, :program, :url
@@ -28,7 +28,7 @@ class Presentation
28
28
  @pshape = PShapeSVG.new(xml)
29
29
  @svg = Nokogiri::XML(open(@url)).children[1];
30
30
  end
31
-
31
+
32
32
  def reset
33
33
  load_files
34
34
  build_internal
@@ -38,15 +38,15 @@ class Presentation
38
38
  def height ; @pshape.getHeight; end
39
39
 
40
40
 
41
- def build_internal
41
+ def build_internal
42
42
 
43
- # Create the frames..
43
+ # Create the frames..
44
44
  @slides = {}
45
45
  @nb_slides = 0
46
46
  @playing_videos = []
47
47
 
48
48
  puts "Svg null, look for the error... !" if @svg == nil
49
- return if @svg == nil
49
+ return if @svg == nil
50
50
 
51
51
  load_frames
52
52
  load_videos
@@ -62,25 +62,25 @@ class Presentation
62
62
  def load_frames
63
63
 
64
64
  puts "Loading the frames..."
65
- @svg.children.each do |child|
66
-
65
+ @svg.children.each do |child|
66
+
67
67
  next unless child.name =~ /frame/
68
68
 
69
- ## ignore if it references nothing.
69
+ ## ignore if it references nothing.
70
70
  attr = child.attributes
71
71
  next if attr["refid"] == nil
72
72
 
73
- slide = Slide.new(child)
74
-
73
+ slide = Slide.new(child)
74
+
75
75
  # get the element associated with each slide...
76
76
  @svg.search("[id=" + slide.refid + "]").each do |elem|
77
77
 
78
- case elem.name
78
+ case elem.name
79
79
  when "rect", "image"
80
80
  add_rect_or_image_frame(elem, slide)
81
- when "g"
81
+ when "g"
82
82
  add_group(elem, slide)
83
- else
83
+ else
84
84
  puts "Slide type not supported ! " + elem.name
85
85
  end # end case
86
86
  end # search
@@ -100,15 +100,15 @@ class Presentation
100
100
  id = slide.title
101
101
  refid = slide.refid
102
102
 
103
- add_slide(slide)
103
+ add_slide(slide)
104
104
 
105
105
  # set the geometry & transformation
106
106
  transform = get_global_transform element
107
- @slides[id].set_geometry(element, transform[0])
107
+ @slides[id].set_geometry(element, transform[0])
108
108
  pshape_element = @pshape.getChild(refid)
109
109
 
110
110
  # hide the element
111
- if pshape_element == nil
111
+ if pshape_element == nil
112
112
  puts "Error: rect or Image ID: #{refid} not found. CHECK THE PROCESSING VERSION."
113
113
  else
114
114
  pshape_element.setVisible(!@slides[id].hide) if element.name == "rect"
@@ -117,60 +117,60 @@ class Presentation
117
117
  puts "Slide #{id} created from a rect : #{refid}" if element.name == "rect"
118
118
  puts "Slide #{id} created from an image: #{refid}" if element.name == "image"
119
119
  end
120
-
121
-
122
- def add_group(group, slide)
123
-
120
+
121
+
122
+ def add_group(group, slide)
123
+
124
124
  id = slide.title
125
125
  refid = slide.refid
126
- add_slide(slide)
126
+ add_slide(slide)
127
127
 
128
128
  # TODO: Find the bounding box of any group..
129
129
  # TODO: Hide the whole group ?
130
130
  surf_max = 0
131
131
  biggest_rect = nil
132
-
132
+
133
133
  ## biggest_rect surface..
134
134
  group.css("rect").each do |rect|
135
135
  # (group.css("rect") + group.css("image")).each do |rect|
136
-
137
- if biggest_rect == nil
136
+
137
+ if biggest_rect == nil
138
138
  biggest_rect = rect
139
139
  end
140
-
140
+
141
141
  surf_rect = rect.attributes["width"].value.to_i \
142
142
  * rect.attributes["height"].value.to_i
143
143
 
144
- if(surf_rect > surf_max)
145
- biggest_rect = rect
144
+ if(surf_rect > surf_max)
145
+ biggest_rect = rect
146
146
  surf_max = surf_rect
147
147
  end
148
- end # rect.each
149
-
148
+ end # rect.each
149
+
150
150
  rect_id = biggest_rect.attributes["id"].value
151
151
  transform = get_global_transform biggest_rect
152
- @slides[id].set_geometry(biggest_rect, transform[0])
152
+ @slides[id].set_geometry(biggest_rect, transform[0])
153
153
 
154
- # The description (code to excute) might be in the group and not in the rect.
154
+ # The description (code to excute) might be in the group and not in the rect.
155
155
  ## TODO: check if it should really be the first ?
156
156
  desc = group.css("desc").first
157
157
  title = group.css("title").first
158
158
 
159
- if desc != nil
159
+ if desc != nil
160
160
  if title == nil || (title.text.match(/animation/) == nil and title.text.match(/video/) == nil)
161
- puts "Group Description read #{desc.text}"
162
-
161
+ puts "Group Description read #{desc.text}"
162
+
163
163
  @slides[id].description = desc.text
164
164
  end
165
165
  end
166
-
166
+
167
167
  e = @pshape.getChild(rect_id)
168
168
  # hide the rect
169
- if e == nil
169
+ if e == nil
170
170
  puts "Error: rect ID: #{rect_id} not found "
171
171
  else
172
172
  @pshape.getChild(rect_id).setVisible(!@slides[id].hide)
173
- end
173
+ end
174
174
 
175
175
  puts "Slide #{id} created from a group, and the rectangle: #{rect_id}"
176
176
 
@@ -186,14 +186,14 @@ class Presentation
186
186
  @svg.css("rect").each do |rect|
187
187
 
188
188
  return if rect.attributes["id"] == nil
189
- id = rect.attributes["id"].value #get the id
189
+ id = rect.attributes["id"].value #get the id
190
190
 
191
191
  title = rect.css("title")
192
- next if title == nil
192
+ next if title == nil
193
193
 
194
- is_video = title.text.match(/video/) != nil
194
+ is_video = title.text.match(/video/) != nil
195
195
  next unless is_video
196
-
196
+
197
197
  t = rect.css("desc").text.split("\n")
198
198
  slide_id = t[0]
199
199
  path = t[1]
@@ -201,13 +201,13 @@ class Presentation
201
201
  puts ("Loading the video : " + path)
202
202
 
203
203
  # Get the transformation
204
- tr = get_global_transform rect
204
+ tr = get_global_transform rect
205
205
 
206
- video = MyVideo.new(path, @slides[slide_id], tr[0], tr[1], tr[2])
206
+ video = MyVideo.new(path, @slides[slide_id], tr[0], tr[1], tr[2])
207
207
 
208
- if @slides[slide_id] == nil
209
- puts "Error -> The video #{id} is linked to the slide #{slide_id} which is not found !"
210
- else
208
+ if @slides[slide_id] == nil
209
+ puts "Error -> The video #{id} is linked to the slide #{slide_id} which is not found !"
210
+ else
211
211
 
212
212
  @slides[slide_id].add_video(video)
213
213
  puts "Video #{id} loaded with #{slide_id}"
@@ -235,11 +235,11 @@ class Presentation
235
235
 
236
236
  id = elem.attributes["id"].value
237
237
 
238
- # Get the animation information
238
+ # Get the animation information
239
239
  t = elem.css("desc").text.split("\n")
240
240
 
241
241
  # 1. which slide
242
- # 2. when
242
+ # 2. when
243
243
  slide_id = t[0]
244
244
  anim_id = t[1].to_i
245
245
 
@@ -248,12 +248,12 @@ class Presentation
248
248
 
249
249
  puts "Animation found on slide #{slide_id} with element #{animation.pshape_elem}"
250
250
 
251
- if @slides[slide_id] == nil
252
- puts "Error -> The animation #{id} is linked to the slide #{slide_id} which is not found !"
253
- else
251
+ if @slides[slide_id] == nil
252
+ puts "Error -> The animation #{id} is linked to the slide #{slide_id} which is not found !"
253
+ else
254
254
  # add the animation
255
255
  @slides[slide_id].add_animation(anim_id, animation)
256
-
256
+
257
257
  # hide the group !
258
258
  animation.pshape_elem.setVisible(false) unless animation.pshape_elem == nil
259
259
  puts "Animation #{id} loaded with #{slide_id}"
@@ -263,44 +263,45 @@ class Presentation
263
263
  end
264
264
 
265
265
  def display_videos
266
- if not @app.is_moving
266
+ if not @app.is_moving
267
267
 
268
268
  slide_no = @app.current_slide_no
269
269
 
270
270
  # # Display the videos
271
- if slide_no > 0 and @slides[slide_no].has_videos?
272
-
271
+ if slide_no > 0 and @slides[slide_no].has_videos?
272
+
273
273
 
274
274
  # draw the object
275
275
  @graphics.imageMode(Processing::App::CORNER)
276
-
277
- @slides[slide_no].videos.each do |my_video|
276
+
277
+ @slides[slide_no].videos.each do |my_video|
278
278
  @graphics.push_matrix
279
279
  @graphics.modelview.apply(my_video.matrix)
280
-
280
+
281
281
  # when the video is loaded it is saved... so that the memory can
282
282
  # hopefully be freed
283
- @playing_videos << my_video if my_video.play
283
+ @playing_videos << my_video if my_video.play
284
284
 
285
- # my_video.video.read if my_video.video.available?
285
+ ## force reading here..
286
+ my_video.video.read if my_video.video.available?
286
287
  # my_video.video.read
287
288
  @graphics.image(my_video.video, 0, 0, my_video.width, my_video.height)
288
289
 
289
-
290
+
290
291
  @graphics.pop_matrix
291
292
  end # videos.each
292
-
293
+
293
294
  else # has_videos
294
295
 
295
- ## no video, free some memory
296
+ ## no video, free some memory
296
297
  @playing_videos.each do |my_video|
297
298
  puts "Saving memory. "
298
299
  my_video.video.stop
299
- my_video.video = nil
300
- System.gc
300
+ my_video.video = nil
301
+ Java::JavaLang::System.gc
301
302
  end
302
303
  @playing_videos = []
303
- end
304
+ end
304
305
  end
305
306
  end
306
307
 
@@ -314,39 +315,40 @@ class Presentation
314
315
 
315
316
  attr_reader :matrix, :width, :height, :slide
316
317
  attr_accessor :video
317
-
318
- def initialize(path, slide, matrix, width, height)
318
+
319
+ def initialize(path, slide, matrix, width, height)
319
320
  @path = path
320
321
  @width = width
321
322
  @height = height
322
323
  @matrix = matrix
323
324
  @slide = slide
324
325
  end
325
-
326
- def play
327
- if @video == nil
326
+
327
+ def play
328
+ if @video == nil
328
329
 
329
330
  absolute_path = $app.sketchPath "" << @path
330
331
 
331
332
  puts ("loading the video : " + absolute_path)
332
333
  vid = Movie.new($app, absolute_path)
333
334
 
335
+ vid.play
334
336
  # vid = Movie.new($app, @path)
335
- puts "Loaded "
337
+ puts "Loaded "
336
338
  puts vid, vid.width, vid.height
337
- vid.play
339
+
338
340
  @video = vid
339
- true
340
- else
341
+ true
342
+ else
341
343
  false
342
344
  end
343
345
  end
344
-
346
+
345
347
  end
346
348
 
347
349
 
348
- def to_s
349
- "Slides #{@slides.size}"
350
+ def to_s
351
+ "Slides #{@slides.size}"
350
352
  end
351
353
 
352
- end
354
+ end
metadata CHANGED
@@ -1,18 +1,21 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Laviole
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-29 00:00:00.000000000 Z
11
+ date: 2015-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
15
15
  requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '1.6'
16
19
  - - ">="
17
20
  - !ruby/object:Gem::Version
18
21
  version: 1.6.3
@@ -21,12 +24,18 @@ dependencies:
21
24
  type: :runtime
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.6'
24
30
  - - ">="
25
31
  - !ruby/object:Gem::Version
26
32
  version: 1.6.3
27
33
  - !ruby/object:Gem::Dependency
28
34
  requirement: !ruby/object:Gem::Requirement
29
35
  requirements:
36
+ - - "~>"
37
+ - !ruby/object:Gem::Version
38
+ version: '0.8'
30
39
  - - ">="
31
40
  - !ruby/object:Gem::Version
32
41
  version: 0.8.0
@@ -35,6 +44,9 @@ dependencies:
35
44
  type: :runtime
36
45
  version_requirements: !ruby/object:Gem::Requirement
37
46
  requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '0.8'
38
50
  - - ">="
39
51
  - !ruby/object:Gem::Version
40
52
  version: 0.8.0