Class: ToneSeq

Inherits:
Object show all
Defined in:
lib/tone_seq.rb

Overview

a sequence of TonePart that will play sequentially. These are highest level sounds without timing.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeToneSeq

Returns a new instance of ToneSeq.



30
31
32
33
# File 'lib/tone_seq.rb', line 30

def initialize()
  @toneparts = []
  make(1)
end

Instance Attribute Details

#tonepartsObject

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



122
123
124
# File 'lib/tone_seq.rb', line 122

def amp_reduce val
  toneparts.each { |tp| tp.amp_mult(1.0/val) }
end

#do_allObject



35
36
37
38
39
# File 'lib/tone_seq.rb', line 35

def do_all
  toneparts.each do |tp|
    yield tp
  end
end

#fadeObject



89
90
91
92
93
94
95
# File 'lib/tone_seq.rb', line 89

def fade
  @toneparts.each {|tp| 
    tp.tone(0).fade
    tp.tone(1).fade
    }
  self
end

#framesObject

return the total frames of all toneparts combined.



76
77
78
79
80
# File 'lib/tone_seq.rb', line 76

def frames
  total=0
  toneparts.each {|tp| total+=tp.tone.frames}
  total
end

#frames=(val) ⇒ Object

set the frames of each tonepart to val.



85
86
87
# File 'lib/tone_seq.rb', line 85

def frames= val
  @toneparts.each {|tp| tp.frames = val}
end

#joinObject

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.



97
98
99
100
101
102
# File 'lib/tone_seq.rb', line 97

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.



104
105
106
107
108
# File 'lib/tone_seq.rb', line 104

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.8, min_detail = 20) ⇒ Object

random everything



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/tone_seq.rb', line 42

def random extra_detail = 5, even = false, delay=0, start_amp = 0.5, 
           max_f = 2000, min_f = 120, max_sat=0.8, min_detail=20
  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
    
    tp = toneparts[i]
    tp.two_tones
    tp.tone(1).rand_sat_both 3, max_sat
    tp.tone(1).rand_freq_both(min_f, max_f)
    tp.tone(1).rand_detail_both min_detail
    
  end
  join
end

#render(parent_hit_index = nil) ⇒ Object

compile all data on all #toneparts, then write it to file(s)



111
112
113
114
115
116
117
118
119
# File 'lib/tone_seq.rb', line 111

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



81
82
83
# File 'lib/tone_seq.rb', line 81

def tonepart i=0
  @toneparts[i]
end