Class: ToneSeq
Overview
a sequence of TonePart that will play sequentially. These are highest level sounds without timing.
Instance Attribute Summary collapse
-
#toneparts ⇒ Object
Array of TonePart.
Instance Method Summary collapse
-
#amp_reduce(val) ⇒ Object
reduce amp of all tones by this val.
- #fade ⇒ Object
-
#frames ⇒ Object
return the total frames of all toneparts combined.
-
#frames=(val) ⇒ Object
set the frames of each tonepart to val.
-
#initialize ⇒ ToneSeq
constructor
A new instance of ToneSeq.
-
#join ⇒ Object
when joined, a tone sequence makes the end of each tone the same as the start of the next one.
-
#len=(set) ⇒ Object
set length of all toneparts to equally add to set when combined.
-
#make(num) ⇒ Object
add num TonePart to self, with it’s max allowable frames as #frames.
-
#random(extra_detail = 5, even = false, delay = 0, start_amp = 0.5, max_f = 2000, min_f = 120, max_sat = 0.2, min_detail = 50) ⇒ Object
random everything.
-
#render(parent_hit_index = nil) ⇒ Object
compile all data on all #toneparts, then write it to file(s).
- #tonepart(i = 0) ⇒ Object
Constructor Details
Instance Attribute Details
#toneparts ⇒ Object
Array of TonePart
4 5 6 |
# File 'lib/tone_seq.rb', line 4 def toneparts @toneparts end |
Instance Method Details
#amp_reduce(val) ⇒ Object
reduce amp of all tones by this val
108 109 110 |
# File 'lib/tone_seq.rb', line 108 def amp_reduce val toneparts.each { |tp| tp.amp_mult(1.0/val) } end |
#fade ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/tone_seq.rb', line 75 def fade @toneparts.each {|tp| tp.tones.start.fade tp.tones.final.fade } self end |
#frames ⇒ Object
return the total frames of all toneparts combined.
63 64 65 66 67 |
# File 'lib/tone_seq.rb', line 63 def frames total=0 toneparts.each {|tp| total+=tp.tone.frames} total end |
#frames=(val) ⇒ Object
set the frames of each tonepart to val.
72 73 74 |
# File 'lib/tone_seq.rb', line 72 def frames= val @toneparts.each {|tp| tp.frames = val} end |
#join ⇒ Object
when joined, a tone sequence makes the end of each tone the same as the start of the next one. this creates a smooth sound. todo
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/tone_seq.rb', line 9 def join toneparts.count.times do |i| # if more after me, do it if i+1 < toneparts.count me = toneparts[i].tone(0) nxt = toneparts[i+1].tone(0) me.detail.final = nxt.detail.start me.saturations.final = nxt.saturations.start me.set_freq_final( nxt.freq.start, false) me.set_amp_final( nxt.amp.start, false) me = toneparts[i].tone(1) nxt = toneparts[i+1].tone(1) me.detail.final = nxt.detail.start me.saturations.final = nxt.saturations.start me.set_freq_final( nxt.freq.start, false) me.set_amp_final( nxt.amp.start, false) end end end |
#len=(set) ⇒ Object
set length of all toneparts to equally add to set when combined.
83 84 85 86 87 88 |
# File 'lib/tone_seq.rb', line 83 def len= set @toneparts.each {|tp| tp.max_frames = set / toneparts.count tp.frames = set / toneparts.count } end |
#make(num) ⇒ Object
add num TonePart to self, with it’s max allowable frames as #frames.
90 91 92 93 94 |
# File 'lib/tone_seq.rb', line 90 def make(num) # puts "ToneSeq: making #{num} parts in tone" num.times { self.toneparts.push TonePart.new } self.len= (frames.to_f).round end |
#random(extra_detail = 5, even = false, delay = 0, start_amp = 0.5, max_f = 2000, min_f = 120, max_sat = 0.2, min_detail = 50) ⇒ Object
random everything
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/tone_seq.rb', line 36 def random extra_detail = 5, even = false, delay=0, start_amp = 0.5, max_f = 2000, min_f = 120, max_sat=0.2, min_detail=50 make(extra_detail) # sets the lens evenly. frames_left = self.frames - self.frames.to_f*delay #- extra_detail+1 #minus a little so it must have 1 frame toneparts.count.times do |i| # sets the lens randomly. portion = frames_left * rand # puts "portion #{portion}" if i == toneparts.count portion = frames_left end frames_left -= 1+portion toneparts[i].tone.frames = 1+portion if !even # toneparts[i].tone.rand_sat_both 3, max_sat toneparts[i].tone.rand_freq_both(min_f, max_f) toneparts[i].tone.rand_detail_both min_detail max_amp = start_amp if i>0 # it can't be higher than the last amp max_amp = toneparts[i-1].tone.amp.start end toneparts[i].tone.rand_amp_both max_amp, max_amp * 0.75 # not much lower end join end |
#render(parent_hit_index = nil) ⇒ Object
compile all data on all #toneparts, then write it to file(s)
97 98 99 100 101 102 103 104 105 |
# File 'lib/tone_seq.rb', line 97 def render(parent_hit_index=nil) data = WaveData.new toneparts.each do |tp| data + tp.out(parent_hit_index).out end files= FileList.new files.write data files end |
#tonepart(i = 0) ⇒ Object
68 69 70 |
# File 'lib/tone_seq.rb', line 68 def tonepart i=0 @toneparts[i] end |