Module: Level_two
- Defined in:
- lib/melody_object/Level_two.rb
Instance Attribute Summary collapse
-
#lvl ⇒ Object
Returns the value of attribute lvl.
Instance Method Summary collapse
- #a(num) ⇒ Object
- #addon(*args) ⇒ Object
- #alter(amount) ⇒ Object
- #altered(amount) ⇒ Object
- #altr(type = :t) ⇒ Object
- #apply(*array_of_arrays) ⇒ Object
- #chggran(neu) ⇒ Object
- #combine(*args) ⇒ Object
- #copy ⇒ Object
- #create_notes(num, len = 4, lentype = :even, type = :all) ⇒ Object
- #create_specific_notes(arr, len = 12) ⇒ Object
- #dubl ⇒ Object
- #ends ⇒ Object
- #hasharr ⇒ Object
- #indx(dims) ⇒ Object
- #indx_in_place(dims) ⇒ Object
- #inspectout(spacer = '') ⇒ Object
- #loop(arghash = {}) ⇒ Object
- #makechannel(chn) ⇒ Object
- #s(*arr) ⇒ Object
- #scayle(times, wich = :both) ⇒ Object
- #sectionize(hash) ⇒ Object
- #spaceout(spacer = ' ') ⇒ Object
- #sproute(arghash = {}) ⇒ Object
- #t(*arr) ⇒ Object
- #to_json ⇒ Object
- #to_jsonn(lvl = 0, spacer = "", incchk = false) ⇒ Object
- #uf ⇒ Object
Instance Attribute Details
#lvl ⇒ Object
Returns the value of attribute lvl.
40 41 42 |
# File 'lib/melody_object/Level_two.rb', line 40 def lvl @lvl end |
Instance Method Details
#a(num) ⇒ Object
261 262 263 264 265 266 267 |
# File 'lib/melody_object/Level_two.rb', line 261 def a(num) x=Section.new num.times do x.addon(self.uf) end return x end |
#addon(*args) ⇒ Object
249 250 251 252 253 254 255 |
# File 'lib/melody_object/Level_two.rb', line 249 def addon(*args) args.each do |obj| obj.parent=self @children.push obj end end |
#alter(amount) ⇒ Object
437 438 439 440 441 442 443 444 445 446 447 448 449 |
# File 'lib/melody_object/Level_two.rb', line 437 def alter(amount) unless @children.empty? @children.each do |d| if d.class==Ender d.val=d.val+amount else d.alter(amount) end end else if self.class==Ender then @val=@val+amount end end end |
#altered(amount) ⇒ Object
430 431 432 433 434 |
# File 'lib/melody_object/Level_two.rb', line 430 def altered(amount) x=self.uf x.alter(amount) return x end |
#altr(type = :t) ⇒ Object
373 374 375 376 377 378 379 380 381 |
# File 'lib/melody_object/Level_two.rb', line 373 def altr(type=:t) case type when :t x=bottomlevel! end end |
#apply(*array_of_arrays) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/melody_object/Level_two.rb', line 43 def apply(*array_of_arrays) #return a new section which is made up of the array of sections passed this (apply them). Not bound to any object... s=Section.new array_of_arrays.each do |h| s.addon indx(h) end return s end |
#chggran(neu) ⇒ Object
450 451 452 453 454 |
# File 'lib/melody_object/Level_two.rb', line 450 def chggran(neu) @seeder.internalgranularity=neu if @granleader @children.each {|j| j.chggran(neu)} unless @children.empty? end |
#combine(*args) ⇒ Object
456 457 458 459 460 461 462 463 464 |
# File 'lib/melody_object/Level_two.rb', line 456 def combine(*args) y=self.uf x=Section.new x.addon(y) args.each do |d| x.addon(d) end return x end |
#copy ⇒ Object
466 467 468 |
# File 'lib/melody_object/Level_two.rb', line 466 def copy return self.uf end |
#create_notes(num, len = 4, lentype = :even, type = :all) ⇒ Object
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
# File 'lib/melody_object/Level_two.rb', line 269 def create_notes(num,len=4,lentype=:even,type=:all) num.times do bluci=rand(7)*7 % 12 + rand(8)*12 while bluci<32 bluci+=12 end while bluci>100 bluci-=12 end if lentype==:rand then lenn=rand(len)+(1) else lenn=len end addon(Ender.new(bluci,lenn)) end case type when :none @children.each do |i| i.val=nil end when :all when :low @children.each do |i| while i.val>50 i.val-=12 end end when :high @children.each do |i| while i.val<85 i.val+=12 end end when :drum1 @children.each do |i| while i.val>47 i.val-=10 end while i.val<36 i.val+=10 end end end end |
#create_specific_notes(arr, len = 12) ⇒ Object
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 |
# File 'lib/melody_object/Level_two.rb', line 357 def create_specific_notes(arr,len=12) if arr.class==Fixnum addon(Ender.new(arr,len)) else p=0 arr.each do |i| if len.class==Fixnum then addon(Ender.new(i,len)) else addon(Ender.new(i,len[p])) unless len[p]==0 p+=1 end end end end |
#dubl ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/melody_object/Level_two.rb', line 108 def dubl #doubles the notes- makes two for one, each 1/2 the length unless self.class==Ender unless@children.empty? @children.each do |i| i.dubl end end else val=@val chn=@chn len=@leng yndx=@parent.children.index(self) @parent.children[yndx]=Section.new @parent.children[yndx].parent=@parent @parent.children[yndx].create_specific_notes([val,val],len/2) @parent.children[yndx].makechannel(@chn) puts "#{val}, #{val}, #{len/2}" end end |
#ends ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/melody_object/Level_two.rb', line 130 def ends #prints out the enders' values and lengths unless self.class==Ender unless@children.empty? @children.each do |i| i.ends end end else puts "yo #{@val}, #{@leng}" end end |
#hasharr ⇒ Object
144 145 146 147 148 149 150 151 152 |
# File 'lib/melody_object/Level_two.rb', line 144 def hasharr a=[] a[0]=:var a[1]=:dir a[2]=:secvar a[3]=:hi a[4]=:lo return a end |
#indx(dims) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/melody_object/Level_two.rb', line 72 def indx(dims) #pulls a copy of a descendant out of a section...based on an array, where first number is child, second: grandchild, and so on case dims.length when 1 obj=@children[dims[0]].uf when 2 obj=@children[dims[0]].children[dims[1]].uf when 3 obj=@children[dims[0]].children[dims[1]].children[dims[2]].uf when 4 obj=@children[dims[0]].children[dims[1]].children[dims[2]].children[dims[3]].uf end obj.parent=nil return obj end |
#indx_in_place(dims) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/melody_object/Level_two.rb', line 90 def indx_in_place(dims) #same as indx, but doesn't pull a copy; instead points to the child itself case dims.length when 1 obj=@children[dims[0]] when 2 obj=@children[dims[0]].children[dims[1]] when 3 obj=@children[dims[0]].children[dims[1]].children[dims[2]] when 4 obj=@children[dims[0]].children[dims[1]].children[dims[2]].children[dims[3]] end return obj end |
#inspectout(spacer = '') ⇒ Object
203 204 205 206 207 |
# File 'lib/melody_object/Level_two.rb', line 203 def inspectout(spacer='') nam=self.inspect #~ $fyl.puts nam end |
#loop(arghash = {}) ⇒ Object
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 |
# File 'lib/melody_object/Level_two.rb', line 318 def loop(arghash={}) a=Section.new tmp=Section.new tmp.create_specific_notes(60) len=tmp.children[0].leng #~ arghash.each do |f| puts f end #~ puts "ho #{arghash[:note]}" note=arghash[:note] beat=arghash[:beat].to_s #~ puts beat #~ sleep 1 lenary=[] place=0 begin #~ puts beat[place] if beat[place].to_i==1 then interiorplace=0 begin interiorplace+=1 place+=1 #~ puts "#{beat[place].to_i} #{place} #{beat.length}" #~ sleep 0.5 end until beat[place].to_i==1 or place>beat.length-1 #~ puts "pushing #{interiorplace*len}" lenary.push interiorplace*len else a.create_specific_notes(0,len) place+=1 end end until place>beat.length-1 #~ return lenary lenary.each do |l| a.create_specific_notes(note,l) end return a end |
#makechannel(chn) ⇒ Object
416 417 418 419 420 421 422 423 424 425 426 427 |
# File 'lib/melody_object/Level_two.rb', line 416 def makechannel(chn) if self.class==Ender @chn=chn else unless @children.empty? @children.each do |i| i.makechannel(chn) end end end end |
#s(*arr) ⇒ Object
65 66 67 68 69 70 |
# File 'lib/melody_object/Level_two.rb', line 65 def s(*arr) #sectionize an array of sections don=Section.new arr.each{|d| don.addon(d)} return don end |
#scayle(times, wich = :both) ⇒ Object
401 402 403 404 405 406 407 408 409 410 411 412 413 414 |
# File 'lib/melody_object/Level_two.rb', line 401 def scayle(times,wich=:both) ar=bottomlevel! ar.each do |i| case wich when :both i.space*=times i.leng*=times when :space i.space*=times when :length i.leng*=times end end end |
#sectionize(hash) ⇒ Object
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 |
# File 'lib/melody_object/Level_two.rb', line 383 def sectionize(hash) s=Section.new notez=[] tymez=[] hash.each do|key,val| notez=key tymez=val end tymez.each do |p| stemp=Section.new stemp.create_specific_notes(notez,p) s.addon(stemp) end return s end |
#spaceout(spacer = ' ') ⇒ Object
189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/melody_object/Level_two.rb', line 189 def spaceout(spacer=' ') if self.class==Ender nam=spacer+@name.to_s+" "+self.to_s+" val:"+@val.to_s+" #{@status}"+"]" else nam=spacer+"["+@name.to_s+" "+self.to_s+" status:"+@status.to_s.upcase+" situation:"+@situation.to_s+" children:"+@children.length.to_s end $fyl.print nam unless @children.empty? @children.each do |d| d.spaceout(spacer) end end end |
#sproute(arghash = {}) ⇒ Object
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 |
# File 'lib/melody_object/Level_two.rb', line 154 def sproute(arghash={}) #this is passed a third-party container, which it gives its own object. (the 'fanx' object), along with an optional block (for timing) # 4 levels of children are sprouted down...like branches- all being passed the same container and the fanx. # at the bottom level, specific notes are created based on the fanx. # the note given is fanx.fanx... and the length is either yielded from the block, or a hash argument, or default of 12 # the goal is to encapsulate the logic for the notes in the fanxobj. this only applies the fanxobj to a bunch of different sections # presumably so that you could then manipulate the different sections later in section-specific ways. # so there would be a fanx-based logic, and then a section-based logic. theoretically you could then build a separate treatment # for the sections... globally affecting each one in whatever way val=0 @lvl||=0 arghash[:fanx]=Fanxobj.new(arghash) if @lvl==0 #~ @lvl.times do str=str+" " end #~ puts " oh yeah" if block_given? #~ $fyl.puts str+self.to_s x=Proc.new if block_given? #~ puts 'uo' 4.times do addon(Section.new) end @children.each do |d| d.lvl=@lvl+1 end if @lvl<3 then @children.each do |kid| block_given? ? kid.sproute(arghash,&x) : kid.sproute(arghash) end else #~ puts block_given? ? "yes" : "none" @children.each do |kid| #~ puts val kid.create_specific_notes([arghash[:fanx].fanx,arghash[:fanx].fanx],block_given? ? yield(val) : arghash[:flag]||=12) val+=1 end end end |
#t(*arr) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/melody_object/Level_two.rb', line 53 def t(*arr) #this threads an array of sections together, and puts that threadset under a section. not sure if it needs to be under a section, #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 #with only one threadset as its child as a threadset itself don=Section.new aadd=Threadset.new arr.each{|s| aadd.addon(s)} don.addon(aadd) return don end |
#to_json ⇒ Object
209 210 211 212 213 214 |
# File 'lib/melody_object/Level_two.rb', line 209 def to_json $jfyl.puts "{id:0,item:[" to_jsonn $jfyl.puts " ]}" end |
#to_jsonn(lvl = 0, spacer = "", incchk = false) ⇒ Object
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 |
# File 'lib/melody_object/Level_two.rb', line 216 def to_jsonn(lvl=0, spacer="",incchk=false) nokids=@children.empty? if nokids then 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}"+"\"}" $jfyl.puts str else case lvl when 0 str="{id:#{$lvl},text:\"#{@name} #{self.class.to_s}\"," else 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}"+"\"," end $jfyl.puts str spacer=spacer+' ' $jfyl.puts spacer+"item:[" spacer=spacer+' ' @children.each do |kid| $lvl+=1 lastkid=true lastkid=false unless kid==@children[@children.length-1] kid.to_jsonn($lvl,spacer,lastkid) $jfyl.puts spacer+"," unless lastkid end $jfyl.puts spacer+"]" $jfyl.puts spacer+"}" end end |
#uf ⇒ Object
257 258 259 |
# File 'lib/melody_object/Level_two.rb', line 257 def uf Marshal::load(Marshal.dump(self)) end |