Class: SndDist
Overview
the distribution of a ToneSeq, or multiple other SndDists
Instance Attribute Summary collapse
-
#hits ⇒ Object
Array of floats containing the delays for each time a bar played.
-
#len ⇒ Object
Returns the value of attribute len.
-
#snd ⇒ Object
Array of SndDist.
-
#tss ⇒ Object
Array of ToneSeq.
Instance Method Summary collapse
- #add(sn) ⇒ Object
-
#disperse_hits(possible_hits = 4, chance = 1, ignore_first = 0, ignore_last = 0) ⇒ Object
Adds into #hits.
-
#end_node ⇒ Object
get pointer to the first end node.
- #get_children ⇒ Object
-
#initialize ⇒ SndDist
constructor
A new instance of SndDist.
-
#populate(depth = 0) ⇒ Object
recursivly create children with 4 hits, or a toneseq with 1 tonepart.
-
#render(parent_hit_index = 0) ⇒ Object
write children.
-
#tally_frames(old = 0) ⇒ Object
me and all children.
Constructor Details
#initialize ⇒ SndDist
Returns a new instance of SndDist.
11 12 13 14 15 16 |
# File 'lib/snd_dist.rb', line 11 def initialize @hits = [] @snd = [] @tss = [] @len = 0 end |
Instance Attribute Details
#hits ⇒ Object
Array of floats containing the delays for each time a bar played. 0 to 1.
4 5 6 |
# File 'lib/snd_dist.rb', line 4 def hits @hits end |
#len ⇒ Object
Returns the value of attribute len.
9 10 11 |
# File 'lib/snd_dist.rb', line 9 def len @len end |
Instance Method Details
#add(sn) ⇒ Object
46 47 48 |
# File 'lib/snd_dist.rb', line 46 def add sn self.snd<<sn end |
#disperse_hits(possible_hits = 4, chance = 1, ignore_first = 0, ignore_last = 0) ⇒ Object
Adds into #hits.
- possible_hits
-
number of hits that can occur. Must be int
- chance
-
chance a hit will be included. range: 0 to 1
- ignore_first
-
skip the first n possible hits
- ignore_first
-
skip the last n possible hits
e.g. disperse_hits(16,1,4,4) makes this pattern [-|-|-|-|+|+|+|+|+|+|+|+|-|-|-|-|]
101 102 103 104 105 106 107 108 |
# File 'lib/snd_dist.rb', line 101 def disperse_hits(possible_hits = 4, chance = 1, ignore_first=0, ignore_last=0) possible_hits.times do |i| if ignore_first <= i && possible_hits - ignore_last > i delay = i/possible_hits.to_f hits.push delay if (rand + chance >= 1) end end end |
#end_node ⇒ Object
get pointer to the first end node.
23 24 25 26 27 28 29 |
# File 'lib/snd_dist.rb', line 23 def end_node if !tss.empty? return self else return snd.first.end_node end end |
#get_children ⇒ Object
18 19 20 |
# File 'lib/snd_dist.rb', line 18 def get_children @snd end |
#populate(depth = 0) ⇒ Object
recursivly create children with 4 hits, or a toneseq with 1 tonepart
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/snd_dist.rb', line 51 def populate(depth=0) raise "Error, you ran Dist.populate before seting hits and length first." if hits.count.to_f < 1 || len < 1 puts "==|Dep: #{depth}| populating distributed sounds " max_child_len=(len/hits.count.to_f).round if depth==0 t=ToneSeq.new self.tss<<t t.make(1,max_child_len) else#not 0 yet, recurse sn=SndDist.new add sn sn.len = max_child_len sn.disperse_hits(4) sn.populate depth-1 end end |
#render(parent_hit_index = 0) ⇒ Object
write children
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 |
# File 'lib/snd_dist.rb', line 69 def render(parent_hit_index=0) # parent_into = (parent_hit_index+1) / hits.count.to_f #DEP # puts "==#{parent_hit_index} rendering sound #{hits.count} times. (#{App.time_since} secs)" files=FileList.new raise "forgot to put a length of this sound dist" if len.nil? log "Warning: one of your sound distributions have no hits. on purpose? ", 3 if hits.empty? hits.each_with_index do |delay, i| delay_in_frames = (delay *len).round into=(i+1).to_f/hits.count snd.each do |sn| # puts "another snd dist " files.addlist sn.render(into), delay_in_frames end tss.each do |sn| files.addlist sn.render(into), delay_in_frames end # puts "#{ App.done} #{App.total}" if !tss.empty? App.done += 1 App.logger.(App.done, App.total, nil, 0, 50) end end files.child_len = (len) files end |
#tally_frames(old = 0) ⇒ Object
me and all children. not frames, hits
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/snd_dist.rb', line 32 def tally_frames(old=0) if !tss.empty? # puts "returning hits count #{hits.count}" return hits.count else result=0 snd.each do |sn| result += hits.count*sn.tally_frames(old) end # puts "all in result #{result}" return result end end |