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,1134 @@
1
+
2
+ #require 'rubygems'
3
+
4
+
5
+ #require 'midiator'
6
+ #require './Level_two'
7
+
8
+ include Level_two
9
+ #~ require './lib/midiator/interface.rb'
10
+ class Array
11
+ def alterindx(hash)
12
+
13
+ self.each{|t|
14
+ # puts "ho #{hash[t.val]}"
15
+ t.val=hash[t.val]||0+t.val}
16
+ end
17
+ end
18
+
19
+
20
+ class Bouncer
21
+ attr_accessor :done
22
+ attr_accessor :val
23
+ attr_accessor :running
24
+ attr_accessor :turned_on
25
+ attr_accessor :inc
26
+ attr_accessor :leng
27
+ attr_accessor :del
28
+ attr_accessor :sender
29
+ attr_accessor :chn
30
+
31
+ def initialize(packet=nil,chn=0,leg=4)
32
+ @running=true
33
+ @inc=0
34
+ @turned_on=false
35
+ @val=packet
36
+ @chn=chn
37
+ leg=4 if leg.nil?
38
+ @leng=leg
39
+ #~ puts @leng
40
+ end
41
+
42
+ def uf
43
+ Marshal::load(Marshal.dump(self))
44
+ end
45
+
46
+ end
47
+
48
+
49
+ class GotimeObject
50
+ attr_accessor :val
51
+ attr_accessor :internalgranularity
52
+ attr_accessor :offset
53
+ attr_accessor :gotimary
54
+ attr_accessor :curraryval
55
+
56
+ def initialize(v)
57
+ if v.class==Fixnum
58
+ @val=v
59
+ @internalgranularity=v
60
+ @curraryval=0
61
+ else
62
+ @gotimary=v
63
+ @curraryval=0
64
+ end
65
+ end
66
+
67
+ def granularity
68
+ @internalgranularity#+rand(2)
69
+ end
70
+
71
+ def status
72
+ if @gotimary.nil?
73
+ if Midistack.ticker==0
74
+ #~ puts 'zero'
75
+ return true
76
+ else
77
+ #~ puts 'slipped'
78
+ x=Midistack.ticker%@internalgranularity==0
79
+ #~ if x then puts 'yeh' end
80
+ return x
81
+ end
82
+ else
83
+ #~ puts "mt:#{Midistack.ticker} os:#{@offset} cv#{@curraryval} cvv#{@gotimary[@curraryval]} t/f: #{Midistack.ticker-@offset==@gotimary[@curraryval]-1}"
84
+ #~ $fyl.puts " #{@offset}, #{@curraryval}, len:#{@gotimary.length} #{@gotimary[@curraryval]}"
85
+ #~ return Midistack.ticker-@offset==@gotimary[@curraryval]-1
86
+ end
87
+ end
88
+
89
+ end
90
+
91
+ class Midistack
92
+ @stack=[]
93
+ @echostack=[]
94
+ @done=false
95
+ @internaldone=false
96
+ @ticker=0
97
+ class<<self
98
+ attr_reader :stack
99
+ attr_reader :echostack
100
+ attr_reader :done
101
+ attr_reader :ticker
102
+ end
103
+
104
+ def self.feed(bouncer)
105
+ @stack.push bouncer unless bouncer.val.nil?
106
+
107
+ end
108
+
109
+ def self.done=(val)
110
+ @done=val
111
+
112
+ end
113
+
114
+ def self.harvestechostack
115
+ @echostack.each{|i|
116
+ #~ puts " cycling through #{i.val}"
117
+ if i.inc==3
118
+ #~ puts " pushing to @stack #{i.val}"
119
+ i.inc=0
120
+ i.running=false
121
+ @stack.push i unless i.val.nil?
122
+ else
123
+ i.inc+=1
124
+ end}
125
+ end
126
+
127
+ def self.play
128
+ #~ harvestechostack
129
+ unless @internaldone
130
+ @stack.each {|d|
131
+ d.inc+=1
132
+
133
+ if d.turned_on==false
134
+ d.turned_on=true
135
+ #~ puts d.chn
136
+
137
+ gaga=(d.chn==9) ? 120 : 60
138
+ #~ puts gaga
139
+ $midi.note_on(d.val,d.chn,gaga)
140
+ if d.chn==0
141
+ e=d.uf
142
+ e.inc=0
143
+ e.turned_on=false
144
+ @echostack.push e if e.running
145
+ #~ puts "pushing to echostack #{e.val}"
146
+ end
147
+ #~ $fyl.puts "#{d.val} #{d.chn} #{@ticker}"
148
+ #~ puts "#{d.val} #{d.chn} #{@ticker}"
149
+ #~ $fyl2.puts "#{d.val} #{d.chn} #{@ticker}"
150
+ #~ puts "#{d.val} #{d.chn} #{@ticker}"
151
+ elsif d.inc>d.leng
152
+ $midi.note_off(d.val,d.chn,100)
153
+ d.del=true
154
+ end
155
+ }
156
+ @stack.delete_if {|d| d.del}
157
+
158
+ if @done
159
+ @internaldone=true
160
+ #~ sleep($g)
161
+ @stack.each {|d| $midi.note_off(d.val,d.chn,100)}
162
+ end
163
+ @ticker+=1
164
+ #~ puts "ticker:#{@ticker}"
165
+ else
166
+ @internaldone=false
167
+ end
168
+ #~ $fyl.puts " "
169
+ #~ puts " "
170
+ end
171
+
172
+ end
173
+
174
+ class FlagObject
175
+
176
+ attr_accessor :currentchildren
177
+ attr_accessor :childrenaelist
178
+ attr_accessor :childrenaeattriblist
179
+ attr_accessor :versions
180
+
181
+
182
+ def initialize(vrsns)
183
+ @currentchildren=1
184
+ @versions=vrsns
185
+ end
186
+
187
+
188
+ end
189
+
190
+ class ParamObjs
191
+ end
192
+
193
+ class Alter_Pitch_Paramobj<ParamObjs
194
+
195
+ attr_accessor :x
196
+ attr_accessor :y
197
+
198
+ def initialize(amt)
199
+ @x=amt
200
+ @y=amt
201
+ end
202
+ def rslt
203
+ puts "rrs #{@x}"
204
+ rtrn=@x
205
+ @x+=@y
206
+ puts "rrt #{@x}"
207
+ return rtrn
208
+ end
209
+ end
210
+
211
+
212
+
213
+
214
+ class MelodyObject
215
+
216
+ attr_accessor :val
217
+ attr_accessor :children
218
+ attr_accessor :name
219
+ attr_accessor :nayme
220
+ attr_accessor :currentchild
221
+ attr_accessor :parent
222
+ attr_accessor :status
223
+ attr_accessor :situation
224
+ attr_accessor :seeder
225
+ attr_accessor :type
226
+ attr_accessor :gotimeobject
227
+ attr_accessor :chn
228
+ attr_accessor :leng
229
+ attr_accessor :space
230
+ attr_accessor :place
231
+ attr_accessor :started
232
+ attr_accessor :offset
233
+ attr_accessor :flag
234
+ attr_accessor :childrenlist
235
+
236
+
237
+ #def versionize(versions)
238
+ #@flag=FlagObject.new(versions)
239
+ #@flag.childrenaelist=[]
240
+ #@flag.childrenaeattriblist=[]
241
+ #@flag.childrenaelist[0]=@children
242
+ #1.upto(versions) do |v|
243
+ # tmpchildren=anewchildren
244
+ # @flag.childrenaelist[v]=tmpchildren
245
+ # @flag.childrenaeattriblist[v]=Hash.new
246
+ #end
247
+ #@children=@flag.childrenaelist[1]
248
+ #end
249
+
250
+ def versionize(versions)
251
+ s=Section.new
252
+
253
+ end
254
+
255
+
256
+
257
+
258
+
259
+
260
+
261
+
262
+ def alter_versions_all(alter_pitch,alter_pitch_paramobj,amt)
263
+ b=Object.const_get(alter_pitch_paramobj)
264
+ x=b.new(amt)
265
+ @flag.childrenaelist.each do |currentchildren|
266
+ unless currentchildren==@children
267
+ qq=x.rslt
268
+ puts qq
269
+ currentchildren.each do |currentchildrencurrentchild|
270
+ puts 'starting'
271
+
272
+ currentchildrencurrentchild.send(alter_pitch,qq)
273
+ puts 'ending'
274
+ end
275
+ end
276
+ end
277
+ end
278
+
279
+ def alter_pitch(rsltamt)
280
+ if self.class==Ender
281
+ @val+=rsltamt
282
+ puts @val
283
+ else
284
+ unless @children==nil or @children.empty?
285
+ @children.each do |cd|
286
+ cd.alter_pitch(rsltamt)
287
+ end
288
+ end
289
+ end
290
+ end
291
+
292
+ def anewchildren
293
+ rslt=Section.new
294
+ @children.each_with_index do |kid,i|
295
+ # p "b4 #{kid.val} val #{kid.status}"
296
+ if kid.class==Ender then
297
+ rslt.addon kid.clone
298
+ else
299
+ rslt.addon kid.uf
300
+ end
301
+ kid.parent=self
302
+ # p kid.parent.name
303
+ # kid.name=i.to_s
304
+ # p "ftr #{rslt[i].val} val #{rslt[i].status}"
305
+
306
+ end
307
+ return rslt
308
+ end
309
+
310
+
311
+
312
+
313
+ =begin
314
+ def anewchildren
315
+ rslt=[]
316
+ @children.each_with_index do |kid,i|
317
+ # p "b4 #{kid.val} val #{kid.status}"
318
+ if kid.class==Ender then
319
+ rslt.push kid.clone
320
+ else
321
+ rslt.push kid.uf
322
+ end
323
+ kid.parent=self
324
+ p kid.parent.name
325
+ kid.name=i.to_s
326
+ # p "ftr #{rslt[i].val} val #{rslt[i].status}"
327
+
328
+ end
329
+ return rslt
330
+ end
331
+ =end
332
+
333
+
334
+
335
+
336
+ def klean
337
+ unless @children==nil
338
+ if @children.length==1 and @children[0].class!=Ender and @parent!=nil
339
+ #tmp=@children[0]
340
+ @children[0].parent=@parent
341
+ @parent.children[parent.children.index(self)]=@children[0] #children.each {|chile| chile.parent=self}
342
+ end
343
+ @children.each {|chyle| chyle.klean}
344
+
345
+ end
346
+ end
347
+
348
+ def threadout(*arr)
349
+ arr.push self.uf
350
+
351
+ newsec=t(*arr)
352
+ if self.parent==nil
353
+ s=Section.new
354
+ s.addon(newsec)
355
+ return s
356
+ else
357
+ self.parent.children[parent.children.index(self)]=newsec
358
+ newsec.parent=self.parent
359
+ # p "a "+newsec.name
360
+ # p "a "+newsec.parent.name
361
+ return newsec
362
+ end
363
+ end
364
+
365
+
366
+ def repl(replacer)
367
+ self.parent.children[parent.children.index(self)]=replacer # unless self.parent==nil
368
+ replacer.parent=self.parent # unless self.parent==nil
369
+ return replacer
370
+ end
371
+
372
+
373
+ def fynd!(addy)
374
+
375
+ innerfynd!(addy)
376
+ return $ss
377
+ end
378
+
379
+
380
+
381
+ def innerfynd!(addy)
382
+ #puts "#{self.class.to_s} #{@name}" if @name.to_s.length<6 and self.class!=Ender
383
+ unless @children.empty?
384
+ @children.each do |d|
385
+ if d.name==addy
386
+
387
+ $ss=d.uf
388
+ $ss.parent=nil
389
+ else
390
+ d.innerfynd!(addy)
391
+ end
392
+ end
393
+ else
394
+ # p 'j'
395
+ end
396
+
397
+ end
398
+
399
+ def fynd(addy)
400
+
401
+ innerfynd(addy)
402
+ return $ss
403
+ end
404
+
405
+
406
+
407
+ def innerfynd(addy)
408
+ unless @children.empty?
409
+ @children.each do |d|
410
+ if d.name==addy
411
+
412
+ $ss=d
413
+ else
414
+ d.innerfynd(addy)
415
+ end
416
+ end
417
+ else
418
+ # p 'j'
419
+ end
420
+
421
+ end
422
+
423
+
424
+
425
+
426
+
427
+
428
+
429
+ def nayme(naymelevel="1")
430
+ @name=naymelevel
431
+ unless @children.empty?
432
+ unless @children[0].class==Ender
433
+ lastnum=naymelevel[naymelevel.length-1].to_i
434
+
435
+ inc=1
436
+ @children.each do |kd|
437
+
438
+ d=naymelevel+'.'+inc.to_s #after 9 levels, breaks...
439
+
440
+ kd.nayme(d)
441
+
442
+ inc+=1
443
+ end
444
+ end
445
+ end
446
+ end
447
+
448
+ def bottomlevel
449
+ # p 'bottomlevel'
450
+ bl=[]
451
+ self.innerbottomlevel(bl)
452
+ # puts 'now bl'
453
+ return bl
454
+ end
455
+
456
+ def innerbottomlevel(bl)
457
+ # p 'innerbottomlevel'
458
+ unless @children.empty?
459
+ @children.each do |d|
460
+ if d.class==Ender
461
+ bl.push(d.val) unless 0==d.val
462
+ else
463
+ d.innerbottomlevel(bl)
464
+ end
465
+ end
466
+ else
467
+ if self.class==Ender then bl.push(@val) end
468
+ end
469
+ end
470
+
471
+
472
+
473
+
474
+ def bottomlevel!
475
+ # p 'bottomlevel!'
476
+ bl=[]
477
+ self.innerbottomlevel!(bl)
478
+ return bl
479
+ end
480
+
481
+ def innerbottomlevel!(bl)
482
+ # p 'innerbottomlevel!'
483
+ unless @children.empty?
484
+ @children.each do |d|
485
+ if d.class==Ender
486
+ bl.push(d)
487
+ else
488
+ d.innerbottomlevel!(bl)
489
+ end
490
+ end
491
+ else
492
+ if self.class==Ender then bl.push(self) end
493
+ end
494
+
495
+
496
+
497
+ end
498
+
499
+
500
+
501
+
502
+
503
+ def alteri
504
+ p 'alteri'
505
+ #something that alters based on note.
506
+ #first, collect all notes.. then assign an amount to alter each, and apply throughout.
507
+
508
+ a=self.bottomlevel
509
+
510
+ a.each{|d| puts d}
511
+ maphash={}
512
+ a.each{|b| maphash[b]=rand(8)+b}
513
+ p maphash
514
+ self.bottomlevel!.alterindx(maphash)
515
+ return self
516
+ end
517
+
518
+
519
+ def halved
520
+ if @children.length==2 then
521
+ @children.delete_at(1)
522
+ else
523
+ @children.each do |d|
524
+ d.halved
525
+ end
526
+ end
527
+ end
528
+
529
+
530
+ =begin
531
+ def strt
532
+ $midi = MIDIator::Interface.new
533
+ $midi.autodetect_driver
534
+ end
535
+ =end
536
+
537
+
538
+ # def strt
539
+ # $midi = Midi_interface.new
540
+
541
+ # end
542
+
543
+ # def prg_chg(track,program)
544
+
545
+ def runn
546
+
547
+ g=@beat
548
+ #webster=Array.new(6) { (rand(122-97) + 97).chr }.join
549
+
550
+ $midi = Midi_interface.new
551
+ stop=false
552
+
553
+ trap('INT') {stop=true}
554
+
555
+ until Midistack.done or stop==true
556
+
557
+ x=Time.now.to_f
558
+
559
+ go_down
560
+
561
+ h=x+g #-0.001
562
+ GC.start
563
+ while Time.now.to_f<h
564
+ sleep 0.0001
565
+ end
566
+ Midistack.play
567
+ #~ x+=1
568
+ end
569
+ Midistack.stack.each do |d|
570
+ $midi.note_off(d.val,d.chn,100)
571
+ d.del=true
572
+ end
573
+ GC.start
574
+ end
575
+
576
+
577
+ def initialize(seder=0)
578
+ @children=[]
579
+ @childrenlist=[]
580
+ @name=self.class.to_s
581
+ @currentchild=0
582
+ @situation=:free
583
+ @status=:notdone
584
+ @started=false
585
+ @space=1
586
+ @offset=0
587
+ localinit(seder)
588
+ end
589
+
590
+ def localinit(x)
591
+ end
592
+
593
+ def gotime
594
+ @gotimeobject.status
595
+ end
596
+
597
+ def statussituation(child)
598
+ {child.status=>child.situation}
599
+ end
600
+
601
+ def statusempties
602
+ {self.class=>if @children.empty? then :childrenempty else :childrennotempty end}
603
+ end
604
+
605
+ def go_down
606
+ # $namarr.push @name if children[0]==nil or children[0].class==Ender #@name.length==$watchlevel ##
607
+ #~ $fyl.puts " in go_down, #{self.name}'s status is #{statusempties}"
608
+ #if first time going down, set the gotime objects start position
609
+
610
+ case statusempties
611
+
612
+ when {Section=> :childrennotempty}
613
+ @children[@currentchild].go_down
614
+
615
+ when {Section=> :childrenempty}
616
+
617
+ @status=:done
618
+ backout
619
+
620
+ when {Threadset=>:childrenempty}
621
+
622
+ @status=:wait
623
+
624
+ when {Threadset=>:childrennotempty}
625
+ # puts 'uo'
626
+ @children.each {|i| i.go_down}
627
+
628
+ end
629
+ end
630
+
631
+ def backout
632
+
633
+ if parent.nil?
634
+
635
+ return
636
+
637
+ else
638
+
639
+ if self==@parent.children[parent.children.length-1]
640
+ @status=:done
641
+ @parent.status=:done
642
+ @parent.backout
643
+ else
644
+ @status=:done
645
+ @parent.currentchild+=1
646
+ @parent.go_down
647
+ end
648
+
649
+ end
650
+ end
651
+
652
+ def checkwhere
653
+ # puts "checking where, self is #{self.class} val is #{self.val} status is #{self.status}"
654
+ if self.class==Threadset then
655
+ @place=:both
656
+ elsif self.class==Section then
657
+ @place=:both
658
+ else
659
+ starting=starting?
660
+ ending=ending?
661
+ #~ puts "starting:#{starting} ending:#{ending}"
662
+ case
663
+ when (starting==true and ending==false)
664
+ #~ puts 'y1'
665
+ @place=:starting
666
+ when (starting==true and ending==true)
667
+ #~ puts 'y2'
668
+ @place=:both
669
+ when (starting==false and ending==true)
670
+ #~ puts 'y3'
671
+ @place=:ending
672
+ when (starting==false and ending==false)
673
+ #~ puts 'y4'
674
+ @place=:middle
675
+ end
676
+ end
677
+ end
678
+
679
+ def starting?
680
+ if @started
681
+ if Midistack.ticker==@offset
682
+ true
683
+ else
684
+ false
685
+ end
686
+ else
687
+ @offset=Midistack.ticker
688
+ @started=true
689
+ true
690
+ end
691
+ end
692
+
693
+ def ending?
694
+ #~ puts "class:#{self.class} kid ofst:#{@children[@currentchild].offset} kid spc:#{@children[@currentchild].space} ticker:#{Midistack.ticker}"
695
+ #~ puts "HIII #{@offset} #{@space-1}"
696
+ if Midistack.ticker==@offset+@space-1 then
697
+ true
698
+ else
699
+ false
700
+ end
701
+ end
702
+
703
+
704
+
705
+
706
+
707
+
708
+
709
+ #~ def starting?
710
+ #~ if @currentchild==0 and not @children[@currentchild].started then
711
+ #~ @children[@currentchild].started=true
712
+ #~ @children[@currentchild].offset=Midistack.ticker
713
+ #~ puts 'starting- first'
714
+ #~ return true
715
+ #~ end
716
+ #~ if @children[@currentchild].started then
717
+ #~ if @children[@currentchild].offset==Midistack.ticker
718
+ #~ puts 'starting'
719
+ #~ return true
720
+ #~ else
721
+ #~ return false
722
+ #~ end
723
+ #~ else
724
+ #~ @children[@currentchild].started=true
725
+ #~ puts 'starting'
726
+ #~ @children[@currentchild].offset=Midistack.ticker
727
+ #~ true
728
+ #~ end
729
+ #~ end
730
+
731
+
732
+
733
+
734
+
735
+ def go_up(data)
736
+ #~ $fyl.puts " in checkchildstatus, #{self.name}'s status is #{@status} and his childtypestatus is #{childtypestatus}"
737
+ #~ puts data.val
738
+ #~ puts "at top" if @parent.nil?
739
+ cc.checkwhere
740
+ #####################
741
+ # puts "#{childtypestatus} #{@children[@currentchild].val}" if @children[@currentchild].class==Ender and @children[@currentchild].val!=0
742
+ # if @children[@currentchild].val!=0 then
743
+ # case
744
+ # when @children[@currentchild].val!=nil then
745
+ # @children.each{|k| puts "lower #{k.val} #{k.status}" unless k.val==0}
746
+ # puts "currchildren #{@flag.currentchildren}" unless @flag==nil
747
+ # when @children[@currentchild].children[0].val!=nil then
748
+ # @children[@currentchild].children.each{|k| puts "hier #{k.val} #{k.status}" unless k.val==0}
749
+ # end
750
+ #end
751
+
752
+
753
+ unless @parent.nil?
754
+ if @parent.name=='1'
755
+ # puts "#{@name} #{childtypestatus}"
756
+ else
757
+ # puts @parent.name
758
+ end
759
+ end
760
+ case childtypestatus
761
+ when {:lastchild=>:done}
762
+
763
+
764
+ #~ $fyl.puts " in checkchildstatus, #{self.name}'s status changing to :done"
765
+ case cc.place
766
+ when :starting
767
+ @status=:notdone
768
+ when :both
769
+ @status=:done
770
+ @currentchild=0
771
+ # p "WOW"
772
+ @children.each {|c|
773
+ c.status=:notdone
774
+ c.started=false
775
+ }
776
+ # if @flag==nil then puts 'nil' else puts (@flag.currentchildren+1) end
777
+ # if @flag==nil then puts 'nil' else puts (@flag.versions+1) end
778
+
779
+ # if @flag==nil then puts 'nil' else puts "HI #{(@flag.currentchildren+1) % (@flag.versions+1)}" end
780
+ @flag.currentchildren=(@flag.currentchildren+1) % (@flag.versions+1) unless @flag==nil #0 unless @flag==nil#
781
+ @children=@flag.childrenaelist[@flag.currentchildren] unless @flag==nil #0] unless @flag==nil #
782
+
783
+ @children.each {|c|
784
+ c.status=:notdone
785
+ c.started=false
786
+ }
787
+
788
+
789
+
790
+
791
+ # @children.each {|i|
792
+ # puts "both #{i.val} #{i.status}"} unless @flag==nil
793
+ # puts "currchildren #{@flag.currentchildren}" unless @flag==nil
794
+ # puts " YOOOOOOOO #{@flag.currentchildren}" unless @flag==nil
795
+ # unless @flag==nil
796
+ # @flag.childrenaelist[@flag.currentchildren].each {|s| puts s.status; puts s.val}
797
+ # end
798
+
799
+ when :ending
800
+ @status=:done
801
+ @currentchild=0
802
+ # p "WOW"
803
+ #maybe i just need to add a clause here which says: change @children (if there's a flag on this object)
804
+ #could it be that fucking easy?
805
+
806
+ #and then on the front end, create
807
+ #@childrenlist full of versions of @children
808
+ #and @flag which will contain the index of what children is current
809
+ #
810
+ #
811
+ #
812
+ @children.each {|c|
813
+ c.status=:notdone
814
+ c.started=false
815
+ }
816
+
817
+
818
+ data=Bouncer.new
819
+ # if @flag==nil then puts 'nil' else puts (@flag.currentchildren+1) end
820
+ # if @flag==nil then puts 'nil' else puts (@flag.versions+1) end
821
+
822
+ # if @flag==nil then puts 'nil' else puts "HI #{(@flag.currentchildren+1) % (@flag.versions+1)}" end
823
+ @flag.currentchildren=(@flag.currentchildren+1) % (@flag.versions+1) unless @flag==nil # unless @flag==nil# =
824
+ # puts " YOOOOOOOO #{@flag.currentchildren}" unless @flag==nil
825
+ @children=@flag.childrenaelist[@flag.currentchildren] unless @flag==nil #0] unless @flag==nil #
826
+
827
+ @children.each {|c|
828
+ c.status=:notdone
829
+ c.started=false
830
+ }
831
+
832
+
833
+ # @children.each {|i|
834
+ # puts "ending #{i.val} #{i.status}"} unless @flag==nil
835
+ # puts "currchildren #{@flag.currentchildren}" unless @flag==nil
836
+ # unless @flag==nil
837
+ # @flag.childrenaelist[@flag.currentchildren].each {|s| puts s.status; puts s.val}
838
+ # end
839
+
840
+
841
+ when :middle
842
+ @status=:wait
843
+ end
844
+
845
+ pass(data)
846
+
847
+ when {:lastchild=>:notdone}
848
+ #~ nochange
849
+ #puts " in checkchildstatus, #{self.name}'s status changing to :notdone"
850
+ case cc.place
851
+ when :starting
852
+ @status=:notdone
853
+ when :both
854
+ @status=:notdone
855
+ when :ending
856
+ @status=:notdone
857
+ data=Bouncer.new
858
+ when :middle
859
+ @status=:wait
860
+ end
861
+
862
+ pass(data)
863
+
864
+ when {:notlastchild=>:done} #youre moving on to the next child though you wait
865
+ #~ nochange
866
+
867
+ #~ $fyl.puts " in checkchildstatus, it says it's gotime, so #{self.name}'s status changing to :notdone"
868
+ #~ puts 'nlc-d'
869
+ case cc.place
870
+ when :starting
871
+ @status=:notdone
872
+ when :both
873
+ @currentchild+=1
874
+ @status=:notdone
875
+ when :ending
876
+ @currentchild+=1
877
+ @status=:notdone
878
+ data=Bouncer.new
879
+ when :middle
880
+ @status=:wait
881
+ end
882
+ pass(data)
883
+ when {:notlastchild=>:notdone}
884
+
885
+
886
+ case cc.place
887
+ when :starting
888
+ @status=:notdone
889
+ when :both
890
+ @status=:notdone
891
+ when :ending
892
+ @status=:notdone
893
+ data=Bouncer.new
894
+ when :middle
895
+ @status=:wait
896
+ end
897
+
898
+ pass(data)
899
+
900
+ when {:notlastchild=>:wait},{:lastchild=>:wait}
901
+ #nochange
902
+ #nochange
903
+ #~ $fyl.puts " in checkchildstatus, #{self.name}'s status changing to :wait"
904
+ @status=:wait
905
+ pass(data)
906
+ when :notallchildrencollected
907
+ @childhash[@children[@currentchild]]=data #this assumes no sub-threads. if there are any then they blow it up
908
+ @currentchild+=1
909
+ #nochange
910
+ #stopdata
911
+
912
+ when :allchildrencollected
913
+ @childhash[@children[@currentchild]]=data
914
+
915
+ @children.each {|i| setsituations(i)}
916
+ @currentchild=0
917
+ passchildrensdata
918
+
919
+ end
920
+ end
921
+
922
+
923
+
924
+ def setsituations(child)
925
+ if child.status==:done
926
+ if children.length==1
927
+ child.situation=:master
928
+ else
929
+ if child.situation==:free
930
+
931
+ someone_else_is_a_slave=false
932
+
933
+ @children.each {|d|
934
+ unless d==child
935
+ if d.situation==:slave
936
+ someone_else_is_a_slave=true #someone else is a slave! you're either a slave or
937
+ #a master!
938
+ end
939
+ end
940
+ }
941
+
942
+ if not someone_else_is_a_slave #no one else is a slave- you're a slave!
943
+ child.situation=:slave
944
+ else
945
+ #someone else is a slave- are you a slave or maybe the master? youre the master if
946
+ #everyone else is a slave
947
+ everyone_else_a_slave=true #assume everyone is until someone says theyre not
948
+ @children.each {|d|
949
+ unless d==child
950
+ if d.situation!=:slave
951
+ everyone_else_a_slave=false #not everyone else is a slave, so youre a slave
952
+ end
953
+ end
954
+ }
955
+
956
+ if everyone_else_a_slave
957
+ child.situation=:master
958
+ else
959
+ child.situation=:slave
960
+ end
961
+
962
+ end
963
+
964
+ end
965
+ end
966
+
967
+ end
968
+ end
969
+
970
+
971
+
972
+ def passchildrensdata
973
+ #~ $fyl.puts " so how many children does #{self.name} think it has?: #{@children.length}"
974
+ data=Bouncer.new
975
+ data.val=Hash.new
976
+ @children.each do |i|
977
+ #~ $fyl.puts " in passchildrensdata, (child) #{i.name}'s status is #{statussituation(i)}"
978
+ case statussituation(i)
979
+
980
+ when {:wait=>:master},{:wait=>:slave},{:wait=>:free}
981
+ #nochange
982
+ #nochange
983
+ #stopdata
984
+
985
+ when {:notdone=>:free},{:notdone=>:slave},{:notdone=>:master}
986
+ #nochange
987
+ #nochange
988
+
989
+ data.val[i]=@childhash[i]
990
+ when {:done=>:master}
991
+ #~ puts "#{i.name} is done bitch"
992
+ #nochange
993
+
994
+ @status=:done
995
+ data.val[i]=@childhash[i]
996
+ #~ @tripped=false
997
+ #~ @gotimeobject.curraryval=0
998
+ when {:done=>:slave}
999
+ i.currentchild=0
1000
+ i.status=:notdone
1001
+ #nochange to self
1002
+ data.val[i]=@childhash[i]
1003
+
1004
+ end
1005
+
1006
+ end
1007
+
1008
+ pass(data) #unless data.val.empty?
1009
+
1010
+ end
1011
+
1012
+ def pass(data)
1013
+ #~ puts "#{@name} sez #{@status}, #{gotime}"
1014
+ if @parent.nil?
1015
+ #~ puts "at top, val=#{if data.val.class==Hash then data.val.each_value {|d| d} else data.val end}"
1016
+ unless @status==:wait
1017
+ #~ puts "sez not waiting, val= #{val}"
1018
+ midifeed(data)
1019
+ Midistack.done=true if @status==:done
1020
+ end
1021
+ else
1022
+ #~ puts "#{@name} sez going to parent"
1023
+ @parent.go_up(data)
1024
+ end
1025
+ end
1026
+
1027
+
1028
+ def midifeed(bouncer)
1029
+ if bouncer.val.class==Hash
1030
+ bouncer.val.each_value {|e|
1031
+ midifeed(e)}
1032
+
1033
+ else
1034
+ #~ $fyl.puts " so feeding a bouncer w #{bouncer.val}"
1035
+ Midistack.feed(bouncer)
1036
+ end
1037
+
1038
+
1039
+ end
1040
+
1041
+
1042
+ def lastchild
1043
+ @currentchild==@children.length-1
1044
+ end
1045
+
1046
+ def cc
1047
+ @children[@currentchild]
1048
+
1049
+ end
1050
+
1051
+ end
1052
+
1053
+
1054
+ class Sections< MelodyObject
1055
+
1056
+ def localinit(gotimobj) #- when initializing from a structure, first create any gotimobj and deliver
1057
+ if gotimobj.class==Fixnum
1058
+ gotimobj=1 if gotimobj==0
1059
+ @gotimeobject=GotimeObject.new(gotimobj)
1060
+ else
1061
+ @gotimeobject=gotimobj
1062
+ end
1063
+
1064
+ locallocal
1065
+ end
1066
+
1067
+ def locallocal
1068
+ end
1069
+
1070
+ def childtypestatus
1071
+ childtype=if @currentchild==@children.length-1 then :lastchild else :notlastchild end
1072
+ {childtype=>@children[@currentchild].status}
1073
+ end
1074
+
1075
+ end
1076
+
1077
+ class Threadset < Sections
1078
+
1079
+ def locallocal
1080
+ @childhash=Hash.new
1081
+ end
1082
+
1083
+ def childtypestatus
1084
+ if @currentchild==@children.length-1
1085
+ :allchildrencollected
1086
+ else
1087
+ :notallchildrencollected
1088
+ end
1089
+ end
1090
+
1091
+
1092
+ end
1093
+
1094
+ class Section < Sections
1095
+
1096
+ attr_accessor :beat
1097
+
1098
+ def heysection
1099
+ end
1100
+
1101
+
1102
+ end
1103
+
1104
+ class Ender<MelodyObject
1105
+
1106
+ def detrip
1107
+ end
1108
+
1109
+ def initialize(seder,len=4)
1110
+ @val=seder
1111
+ @chn=0
1112
+ @space=len
1113
+ @leng=len
1114
+ @offset=0
1115
+ @name=seder
1116
+ @children=[]
1117
+ @started=false
1118
+ #~ puts " #{@leng}"
1119
+ end
1120
+
1121
+ def go_down
1122
+
1123
+ # puts " in go_down, #{self.name}'s value is #{@val}"
1124
+ # puts "#{@parent.flag.currentchildren} is currchildren" unless @parent.flag==nil
1125
+ @status=:done
1126
+ envelope=Bouncer.new(@val,@chn,@leng)
1127
+ # puts "enderval: #{@val} #{@status}"
1128
+ @parent.go_up(envelope)
1129
+ end
1130
+
1131
+ end
1132
+ print{"foo"}
1133
+
1134
+