Class: Dist
Overview
a consecutave sequence of morphable tones (TonePart) of varying lengths, and rate of morphs, played without gaps.
Instance Attribute Summary collapse
-
#dist ⇒ Object
Returns the value of attribute dist.
Instance Method Summary collapse
-
#[](i) ⇒ Object
get a Dist child.
-
#branches ⇒ Object
count children (Dists only).
-
#clear_hits ⇒ Object
delete all hits.
-
#clear_snd ⇒ Object
delete all Snd attached to this Dist.
-
#del(todel) ⇒ Object
delete another Dist.
-
#dubstep_percussion ⇒ Object
make children with the hits you need for a bar of dubstep percussion.
-
#first_born ⇒ Object
get first child.
-
#hits ⇒ Object
getter for HitSq.
-
#initialize ⇒ Dist
constructor
will have a defult hit at 0 if it has a sound and no hits have been made.
-
#last_born ⇒ Object
get last child.
-
#length ⇒ Object
get the total length in frames.
-
#length=(set) ⇒ Object
set the total length in frames.
-
#make(num = 1, i = 0) ⇒ Object
add num TonePart to Snd at i’s ToneSeq, with my #length as max.
-
#Mapper ⇒ Object
shortcut to create a Mapper, with Mapper#map_to= me.
-
#persist_hits(is_def = false) ⇒ Object
(internal use only) copy our hits down to the underlining object.
-
#set_child_len(val) ⇒ Object
sets the length of all children Dist to val.
-
#snd(i = 0) ⇒ Object
getter for Snd.
-
#snd_each ⇒ Object
run on all sounds.
-
#sounds ⇒ Object
count sounds.
-
#space_children_across ⇒ Object
evenly disperse each child across len by modifying the length and hits.
Methods inherited from Api
Constructor Details
Instance Attribute Details
#dist ⇒ Object
Returns the value of attribute dist.
4 5 6 |
# File 'lib/api/dist.rb', line 4 def dist @dist end |
Instance Method Details
#[](i) ⇒ Object
get a Dist child
87 88 89 90 91 92 93 94 95 |
# File 'lib/api/dist.rb', line 87 def [] i child=@dist.get_children[i] raise "This Dist has no child at index #{i}. " + "It has #{branches} children." if child.nil? d=Dist.new d.dist=child d.make_hits d end |
#branches ⇒ Object
count children (Dists only)
113 114 115 |
# File 'lib/api/dist.rb', line 113 def branches @dist.get_children.count end |
#clear_hits ⇒ Object
delete all hits
81 82 83 84 85 |
# File 'lib/api/dist.rb', line 81 def clear_hits @hits.hits = [] persist_hits self end |
#clear_snd ⇒ Object
delete all Snd attached to this Dist
139 140 141 142 |
# File 'lib/api/dist.rb', line 139 def clear_snd @dist.tss = [] self end |
#del(todel) ⇒ Object
delete another Dist
66 67 68 69 |
# File 'lib/api/dist.rb', line 66 def del todel @dist.snd.delete todel.dist self end |
#dubstep_percussion ⇒ Object
make children with the hits you need for a bar of dubstep percussion. set their #length to mine this dist has 5 children, in order: bass drum, secondary bass drum, snare, hi hat, second hi hat
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/api/dist.rb', line 17 def dubstep_percussion self << Dist.new # bass drum self.last_born.clear_hits self.last_born << [0.0] self << Dist.new # 2nd bass drum self.last_born.clear_hits self.last_born << [0.75, 0.875] #two last drum hits self << Dist.new # snare self.last_born.clear_hits self.last_born << [0.5] # third beat self << Dist.new # hi hat self.last_born.clear_hits self.last_born << [0.375,0.625] # off beats self << Dist.new # 2nd hi hat self.last_born.clear_hits self.last_born << [0.125,0.875] # off beats set_child_len length self end |
#first_born ⇒ Object
get first child
105 106 107 108 109 110 111 |
# File 'lib/api/dist.rb', line 105 def first_born child=@dist.get_children.first d=Dist.new d.dist=child d.make_hits d end |
#hits ⇒ Object
getter for HitSq. Will persist any changes you make to it.
117 118 119 |
# File 'lib/api/dist.rb', line 117 def hits @hits end |
#last_born ⇒ Object
get last child
97 98 99 100 101 102 103 |
# File 'lib/api/dist.rb', line 97 def last_born child=@dist.get_children.last d=Dist.new d.dist=child d.make_hits d end |
#length ⇒ Object
get the total length in frames
77 78 79 |
# File 'lib/api/dist.rb', line 77 def length @dist.len end |
#length=(set) ⇒ Object
set the total length in frames
71 72 73 74 75 |
# File 'lib/api/dist.rb', line 71 def length= set @dist.len = set @dist.tss.each {|tss| tss.len = set } self end |
#make(num = 1, i = 0) ⇒ Object
add num TonePart to Snd at i’s ToneSeq, with my #length as max.
57 58 59 |
# File 'lib/api/dist.rb', line 57 def make(num=1, i=0) snd(i).toneseq.make(num) end |
#Mapper ⇒ Object
shortcut to create a Mapper, with Mapper#map_to= me
62 63 64 |
# File 'lib/api/dist.rb', line 62 def Mapper Mapper.new(self) end |
#persist_hits(is_def = false) ⇒ Object
(internal use only) copy our hits down to the underlining object
155 156 157 158 159 |
# File 'lib/api/dist.rb', line 155 def persist_hits(is_def = false) @dist.hits = hits.hits @dist.hits = [0.0] if is_def && hits.hits.count == 0 self end |
#set_child_len(val) ⇒ Object
sets the length of all children Dist to val
50 51 52 53 54 |
# File 'lib/api/dist.rb', line 50 def set_child_len val branches.times do |i| self[i].length = val end end |
#snd(i = 0) ⇒ Object
getter for Snd. Will persist any changes you make to it.
121 122 123 124 125 126 127 128 |
# File 'lib/api/dist.rb', line 121 def snd i=0 snd=Snd.new snd.add_parent self new=@dist.tss[i] raise "Dist has no sound at index #{i}. It has #{sounds} sounds." if new.nil? snd<< new snd end |
#snd_each ⇒ Object
run on all sounds
144 145 146 147 148 149 |
# File 'lib/api/dist.rb', line 144 def snd_each sounds.times {|i| yield(snd i) } self end |
#sounds ⇒ Object
count sounds
151 152 153 |
# File 'lib/api/dist.rb', line 151 def sounds @dist.tss.count end |
#space_children_across ⇒ Object
evenly disperse each child across len by modifying the length and hits. uses #length
39 40 41 42 43 44 45 46 47 |
# File 'lib/api/dist.rb', line 39 def space_children_across len = self.length branches.times do |i| hit = i.to_f / branches self[i].length = len #(1/branches)* len + hit * len self[i].clear_hits self[i] << hit end end |