melody_object 0.0.2

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.
@@ -0,0 +1,119 @@
1
+
2
+ def sproutenapply(ary)
3
+ b=[]
4
+ ary.each {|d|
5
+ f=Section.new
6
+ h=Hash.new
7
+ d.each_index do |e|
8
+ h.store(hasharr[e],d[e])
9
+ end
10
+ #~ h.each_pair do |d,e| puts "#{d} #{e}" end
11
+ f.sproute(h) {(rand(4)+1)*12}
12
+ b.push f.apply(*qanx)
13
+ #~ sbaby.to_json if d=a[0]
14
+ }
15
+
16
+ return b
17
+
18
+ end
19
+
20
+ def combyn(hsh)
21
+ combind=[]
22
+
23
+ #~ s=Section.new
24
+ hsh.each_key do |ltr|
25
+ fyl=''
26
+ fyl<<ltr.to_s+'animals'
27
+ hsh[ltr].each do |sec|
28
+ fyl<<sec.to_s
29
+ end
30
+ fyl<<'.yaml'
31
+ #~ puts File.dirname(__FILE__)
32
+ #~ puts fyl
33
+ tmp=YAML.load_file(fyl)
34
+ #~ puts "HI #{hsh[ltr]}"
35
+ hsh[ltr].each do |sec|
36
+ yoursec=tmp[sec-1]
37
+ combind.push yoursec
38
+ end
39
+ end
40
+
41
+ File.open( 'combined.yaml', 'w' ) do |out|
42
+
43
+ YAML.dump(combind, out )
44
+ end
45
+
46
+ end
47
+
48
+
49
+ def fanx
50
+
51
+ if $variable>$hilimit then
52
+ $direction=:down
53
+ $variable-=$secondvariable
54
+ elsif $variable<$lolimit then
55
+ $direction=:up
56
+ $variable+=$secondvariable
57
+ else
58
+ case $direction
59
+ when :up
60
+ $variable+=$secondvariable
61
+ when :down
62
+ $variable-=$secondvariable
63
+ end
64
+ end
65
+ #~ $fyl.puts "#{self} #{$variable}"
66
+ return $variable
67
+ end
68
+
69
+ class Fanxobj
70
+
71
+ attr_accessor :variable
72
+ attr_accessor :hilimit
73
+ attr_accessor :secondvariable
74
+ attr_accessor :lolimit
75
+ attr_accessor :direction
76
+
77
+
78
+ def initialize(hsh={})
79
+ @variable=hsh[:var]||=60
80
+ @hilimit=hsh[:hi]||=72
81
+ @lolimit=hsh[:lo]||=48
82
+ @secondvariable=hsh[:secvar]||=5
83
+ @direction=hsh[:dir]||=:up
84
+ end
85
+
86
+ def fanx
87
+ if @variable>@hilimit then
88
+ @direction=:down
89
+ @variable-=@secondvariable
90
+ elsif @variable<@lolimit then
91
+ @direction=:up
92
+ @variable+=@secondvariable
93
+ else
94
+ case @direction
95
+ when :up
96
+ @variable+=@secondvariable
97
+ when :down
98
+ @variable-=@secondvariable
99
+ end
100
+ end
101
+ #~ @fyl.puts "#{self} #{@variable}"
102
+ return @variable
103
+ end
104
+
105
+ end
106
+
107
+
108
+ def qanx
109
+ a=[]
110
+ (4).times do
111
+ t=[]
112
+ (3).times do
113
+ t.push (rand(4))
114
+ end
115
+ a.push t
116
+ end
117
+ return a
118
+ end
119
+
@@ -0,0 +1,470 @@
1
+
2
+ module Level_two
3
+ #require './Level_three'
4
+
5
+
6
+ #require 'yaml'
7
+
8
+ #~ class Hash
9
+ #~ # Replacing the to_yaml function so it'll serialize hashes sorted (by their keys)
10
+ #~ #
11
+ #~ # Original function is in /usr/lib/ruby/1.8/yaml/rubytypes.rb
12
+ #~ def to_yaml( opts = {} )
13
+ #~ YAML::quick_emit( object_id, opts ) do |out|
14
+ #~ out.map( taguri, to_yaml_style ) do |map|
15
+ #~ sort.each do |k, v| # <-- here's my addition (the 'sort')
16
+ #~ map.add( k, v )
17
+ #~ end
18
+ #~ end
19
+ #~ end
20
+ #~ end
21
+ #~ end
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+ #$fyl=File.open('oout.txt','w')
38
+ # $jfyl=File.open('..\treemo\public\fyl.json','w')
39
+ $lvl=1
40
+ attr_accessor :lvl
41
+
42
+
43
+ def apply(*array_of_arrays)
44
+ #return a new section which is made up of the array of sections passed this (apply them). Not bound to any object...
45
+ s=Section.new
46
+ array_of_arrays.each do |h|
47
+ s.addon indx(h)
48
+ end
49
+ return s
50
+ end
51
+
52
+
53
+ def t(*arr)
54
+ #this threads an array of sections together, and puts that threadset under a section. not sure if it needs to be under a section,
55
+ #except that, it's passed as the top-level, it needs to be encapsulated as a section. there should be logic that treats a section
56
+ #with only one threadset as its child as a threadset itself
57
+ don=Section.new
58
+ aadd=Threadset.new
59
+ arr.each{|s|
60
+ aadd.addon(s)}
61
+ don.addon(aadd)
62
+ return don
63
+ end
64
+
65
+ def s(*arr)
66
+ #sectionize an array of sections
67
+ don=Section.new
68
+ arr.each{|d| don.addon(d)}
69
+ return don
70
+ end
71
+
72
+ def indx(dims)
73
+ #pulls a copy of a descendant out of a section...based on an array, where first number is child, second: grandchild, and so on
74
+ case dims.length
75
+ when 1
76
+ obj=@children[dims[0]].uf
77
+ when 2
78
+ obj=@children[dims[0]].children[dims[1]].uf
79
+ when 3
80
+ obj=@children[dims[0]].children[dims[1]].children[dims[2]].uf
81
+ when 4
82
+ obj=@children[dims[0]].children[dims[1]].children[dims[2]].children[dims[3]].uf
83
+
84
+ end
85
+ obj.parent=nil
86
+ return obj
87
+
88
+ end
89
+
90
+ def indx_in_place(dims)
91
+ #same as indx, but doesn't pull a copy; instead points to the child itself
92
+ case dims.length
93
+ when 1
94
+ obj=@children[dims[0]]
95
+ when 2
96
+ obj=@children[dims[0]].children[dims[1]]
97
+ when 3
98
+ obj=@children[dims[0]].children[dims[1]].children[dims[2]]
99
+ when 4
100
+ obj=@children[dims[0]].children[dims[1]].children[dims[2]].children[dims[3]]
101
+
102
+ end
103
+ return obj
104
+
105
+ end
106
+
107
+
108
+ def dubl
109
+ #doubles the notes- makes two for one, each 1/2 the length
110
+ unless self.class==Ender
111
+ unless@children.empty?
112
+ @children.each do |i|
113
+ i.dubl
114
+ end
115
+ end
116
+ else
117
+ val=@val
118
+ chn=@chn
119
+ len=@leng
120
+ yndx=@parent.children.index(self)
121
+ @parent.children[yndx]=Section.new
122
+ @parent.children[yndx].parent=@parent
123
+ @parent.children[yndx].create_specific_notes([val,val],len/2)
124
+ @parent.children[yndx].makechannel(@chn)
125
+ puts "#{val}, #{val}, #{len/2}"
126
+
127
+ end
128
+ end
129
+
130
+ def ends
131
+ #prints out the enders' values and lengths
132
+ unless self.class==Ender
133
+ unless@children.empty?
134
+ @children.each do |i|
135
+ i.ends
136
+ end
137
+ end
138
+ else
139
+ puts "yo #{@val}, #{@leng}"
140
+ end
141
+
142
+ end
143
+
144
+ def hasharr
145
+ a=[]
146
+ a[0]=:var
147
+ a[1]=:dir
148
+ a[2]=:secvar
149
+ a[3]=:hi
150
+ a[4]=:lo
151
+ return a
152
+ end
153
+
154
+ def sproute(arghash={})
155
+ #this is passed a third-party container, which it gives its own object. (the 'fanx' object), along with an optional block (for timing)
156
+ # 4 levels of children are sprouted down...like branches- all being passed the same container and the fanx.
157
+ # at the bottom level, specific notes are created based on the fanx.
158
+ # the note given is fanx.fanx... and the length is either yielded from the block, or a hash argument, or default of 12
159
+ # the goal is to encapsulate the logic for the notes in the fanxobj. this only applies the fanxobj to a bunch of different sections
160
+ # presumably so that you could then manipulate the different sections later in section-specific ways.
161
+ # so there would be a fanx-based logic, and then a section-based logic. theoretically you could then build a separate treatment
162
+ # for the sections... globally affecting each one in whatever way
163
+ val=0
164
+ @lvl||=0
165
+
166
+ arghash[:fanx]=Fanxobj.new(arghash) if @lvl==0
167
+
168
+ #~ @lvl.times do str=str+" " end
169
+ #~ puts " oh yeah" if block_given?
170
+ #~ $fyl.puts str+self.to_s
171
+ x=Proc.new if block_given?
172
+ #~ puts 'uo'
173
+ 4.times do addon(Section.new) end
174
+ @children.each do |d| d.lvl=@lvl+1 end
175
+
176
+ if @lvl<3 then
177
+ @children.each do |kid| block_given? ? kid.sproute(arghash,&x) : kid.sproute(arghash) end
178
+ else
179
+ #~ puts block_given? ? "yes" : "none"
180
+ @children.each do |kid|
181
+ #~ puts val
182
+ kid.create_specific_notes([arghash[:fanx].fanx,arghash[:fanx].fanx],block_given? ? yield(val) : arghash[:flag]||=12)
183
+ val+=1
184
+ end
185
+
186
+ end
187
+ end
188
+
189
+ def spaceout(spacer=' ')
190
+ if self.class==Ender
191
+ nam=spacer+@name.to_s+" "+self.to_s+" val:"+@val.to_s+" #{@status}"+"]"
192
+ else
193
+ nam=spacer+"["+@name.to_s+" "+self.to_s+" status:"+@status.to_s.upcase+" situation:"+@situation.to_s+" children:"+@children.length.to_s
194
+ end
195
+ $fyl.print nam
196
+ unless @children.empty?
197
+ @children.each do |d|
198
+ d.spaceout(spacer)
199
+ end
200
+ end
201
+ end
202
+
203
+ def inspectout(spacer='')
204
+ nam=self.inspect
205
+ #~ $fyl.puts nam
206
+
207
+ end
208
+
209
+ def to_json
210
+
211
+ $jfyl.puts "{id:0,item:["
212
+ to_jsonn
213
+ $jfyl.puts " ]}"
214
+ end
215
+
216
+ def to_jsonn(lvl=0, spacer="",incchk=false)
217
+
218
+ nokids=@children.empty?
219
+ if nokids then
220
+
221
+ str=spacer+"{id:#{lvl},text:\""+"#{@name} #{self.class.to_s} #{childtypestatus unless self.class==Ender}"+"\"}"#str=spacer+"{id:#{lvl},text:\""+self.to_s.gsub(/[#<>]/,'')+" #{@status} #{@val}"+"\"}"
222
+ $jfyl.puts str
223
+ else
224
+ case lvl
225
+ when 0
226
+ str="{id:#{$lvl},text:\"#{@name} #{self.class.to_s}\","
227
+ else
228
+ str=spacer+"{id:#{lvl},text:\""+"#{@name} #{self.class.to_s} #{childtypestatus unless self.class==Ender}"+"\"," # str=spacer+"{id:#{$lvl},text:\""+self.to_s.gsub(/[#<>]/,'')+" #{@status} #{@situation} #{@place} child:#{@currentchild}"+"\","
229
+ end
230
+ $jfyl.puts str
231
+ spacer=spacer+' '
232
+ $jfyl.puts spacer+"item:["
233
+ spacer=spacer+' '
234
+ @children.each do |kid|
235
+ $lvl+=1
236
+ lastkid=true
237
+ lastkid=false unless kid==@children[@children.length-1]
238
+ kid.to_jsonn($lvl,spacer,lastkid)
239
+ $jfyl.puts spacer+"," unless lastkid
240
+ end
241
+ $jfyl.puts spacer+"]"
242
+ $jfyl.puts spacer+"}"
243
+ end
244
+ end
245
+
246
+
247
+
248
+
249
+ def addon(*args)
250
+ args.each do |obj|
251
+
252
+ obj.parent=self
253
+ @children.push obj
254
+ end
255
+ end
256
+
257
+ def uf
258
+ Marshal::load(Marshal.dump(self))
259
+ end
260
+
261
+ def a(num)
262
+ x=Section.new
263
+ num.times do
264
+ x.addon(self.uf)
265
+ end
266
+ return x
267
+ end
268
+
269
+ def create_notes(num,len=4,lentype=:even,type=:all)
270
+
271
+ num.times do
272
+ bluci=rand(7)*7 % 12 + rand(8)*12
273
+ while bluci<32
274
+ bluci+=12
275
+ end
276
+ while bluci>100
277
+ bluci-=12
278
+ end
279
+ if lentype==:rand then lenn=rand(len)+(1) else lenn=len end
280
+ addon(Ender.new(bluci,lenn))
281
+ end
282
+
283
+ case type
284
+ when :none
285
+ @children.each do |i|
286
+ i.val=nil
287
+ end
288
+ when :all
289
+ when :low
290
+ @children.each do |i|
291
+ while i.val>50
292
+ i.val-=12
293
+ end
294
+ end
295
+ when :high
296
+ @children.each do |i|
297
+ while i.val<85
298
+ i.val+=12
299
+ end
300
+ end
301
+
302
+ when :drum1
303
+ @children.each do |i|
304
+
305
+ while i.val>47
306
+ i.val-=10
307
+ end
308
+ while i.val<36
309
+ i.val+=10
310
+ end
311
+
312
+ end
313
+ end
314
+
315
+
316
+ end
317
+
318
+ def loop(arghash={})
319
+ a=Section.new
320
+ tmp=Section.new
321
+ tmp.create_specific_notes(60)
322
+ len=tmp.children[0].leng
323
+ #~ arghash.each do |f| puts f end
324
+ #~ puts "ho #{arghash[:note]}"
325
+ note=arghash[:note]
326
+ beat=arghash[:beat].to_s
327
+ #~ puts beat
328
+ #~ sleep 1
329
+
330
+ lenary=[]
331
+ place=0
332
+
333
+ begin
334
+ #~ puts beat[place]
335
+ if beat[place].to_i==1 then
336
+ interiorplace=0
337
+ begin
338
+ interiorplace+=1
339
+ place+=1
340
+ #~ puts "#{beat[place].to_i} #{place} #{beat.length}"
341
+ #~ sleep 0.5
342
+ end until beat[place].to_i==1 or place>beat.length-1
343
+ #~ puts "pushing #{interiorplace*len}"
344
+ lenary.push interiorplace*len
345
+ else
346
+ a.create_specific_notes(0,len)
347
+ place+=1
348
+ end
349
+ end until place>beat.length-1
350
+ #~ return lenary
351
+ lenary.each do |l|
352
+ a.create_specific_notes(note,l)
353
+ end
354
+ return a
355
+ end
356
+
357
+ def create_specific_notes(arr,len=12)
358
+ if arr.class==Fixnum
359
+ addon(Ender.new(arr,len))
360
+ else
361
+ p=0
362
+ arr.each do |i|
363
+ if len.class==Fixnum then
364
+ addon(Ender.new(i,len))
365
+ else
366
+ addon(Ender.new(i,len[p])) unless len[p]==0
367
+ p+=1
368
+ end
369
+ end
370
+ end
371
+ end
372
+
373
+ def altr(type=:t)
374
+ case type
375
+ when :t
376
+ x=bottomlevel!
377
+
378
+ end
379
+
380
+
381
+ end
382
+
383
+ def sectionize(hash)
384
+ s=Section.new
385
+ notez=[]
386
+ tymez=[]
387
+ hash.each do|key,val|
388
+ notez=key
389
+ tymez=val
390
+ end
391
+
392
+ tymez.each do |p|
393
+ stemp=Section.new
394
+
395
+ stemp.create_specific_notes(notez,p)
396
+ s.addon(stemp)
397
+ end
398
+ return s
399
+ end
400
+
401
+ def scayle(times,wich=:both)
402
+ ar=bottomlevel!
403
+ ar.each do |i|
404
+ case wich
405
+ when :both
406
+ i.space*=times
407
+ i.leng*=times
408
+ when :space
409
+ i.space*=times
410
+ when :length
411
+ i.leng*=times
412
+ end
413
+ end
414
+ end
415
+
416
+ def makechannel(chn)
417
+ if self.class==Ender
418
+ @chn=chn
419
+ else
420
+ unless @children.empty?
421
+ @children.each do |i|
422
+ i.makechannel(chn)
423
+ end
424
+ end
425
+ end
426
+
427
+ end
428
+
429
+
430
+ def altered(amount)
431
+ x=self.uf
432
+ x.alter(amount)
433
+ return x
434
+ end
435
+
436
+
437
+ def alter(amount)
438
+ unless @children.empty?
439
+ @children.each do |d|
440
+ if d.class==Ender
441
+ d.val=d.val+amount
442
+ else
443
+ d.alter(amount)
444
+ end
445
+ end
446
+ else
447
+ if self.class==Ender then @val=@val+amount end
448
+ end
449
+ end
450
+ def chggran(neu)
451
+
452
+ @seeder.internalgranularity=neu if @granleader
453
+ @children.each {|j| j.chggran(neu)} unless @children.empty?
454
+ end
455
+
456
+ def combine(*args)
457
+ y=self.uf
458
+ x=Section.new
459
+ x.addon(y)
460
+ args.each do |d|
461
+ x.addon(d)
462
+ end
463
+ return x
464
+ end
465
+
466
+ def copy
467
+ return self.uf
468
+ end
469
+
470
+ end