Class: TonePart

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

Overview

one or two Tone that can be morphed between eachother

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(m = 0, t1 = Tone.new) ⇒ TonePart

Returns a new instance of TonePart.



8
9
10
11
12
13
14
# File 'lib/tone_part.rb', line 8

def initialize(m=0,t1=Tone.new)
  @tone_count = 1
  @tone_single = t1
  @tones = Fader.new(t1,nil,0)
  @max_frames = m
  self.frames = m
end

Instance Attribute Details

#max_framesObject

Returns the value of attribute max_frames.



5
6
7
# File 'lib/tone_part.rb', line 5

def max_frames
  @max_frames
end

#tone_countObject

Returns the value of attribute tone_count.



7
8
9
# File 'lib/tone_part.rb', line 7

def tone_count
  @tone_count
end

#tone_singleObject

Returns the value of attribute tone_single.



6
7
8
# File 'lib/tone_part.rb', line 6

def tone_single
  @tone_single
end

#tonesObject

Fader of Tone



4
5
6
# File 'lib/tone_part.rb', line 4

def tones
  @tones
end

Instance Method Details

#amp_mult(factor) ⇒ Object

multiply all amplitudes (Tone.amp) by factor.



65
66
67
68
69
70
71
72
73
# File 'lib/tone_part.rb', line 65

def amp_mult(factor)
  tone(0).amp.start *= factor
  #puts "amp: #{tone.tones.start.amp.start}"
  tone(0).amp.final *= factor
  if tone_count > 1
    tone(1).amp.start *= factor
    tone(1).amp.final *= factor
  end
end

#do_all {|(tone(0))| ... } ⇒ Object

perform the block on all tones

Yields:



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

def do_all
  yield (tone(0))
  yield (tone(1))
end

#frames=(val) ⇒ Object



37
38
39
40
# File 'lib/tone_part.rb', line 37

def frames= val
  tone(0).frames = val
  tone(1).frames = val
end

#freqObject

get main freq



43
44
45
# File 'lib/tone_part.rb', line 43

def freq
  tone.freq.start
end

#freq=(val) ⇒ Object

set freq of start and final to val



52
53
54
55
# File 'lib/tone_part.rb', line 52

def freq= val
  tone(0).freq.start = val
  tone(1).freq.start = val
end

#noteObject

get main note



47
48
49
# File 'lib/tone_part.rb', line 47

def note
  tone.note
end

#note=(val) ⇒ Object

set freq of start and final to Note.freq

val

the note to call freq on



59
60
61
62
# File 'lib/tone_part.rb', line 59

def note= val
  tone(0).freq.start = val.freq
  tone(1).freq.start = val.freq
end

#out(into) ⇒ Object

return tone with mixed settings of tones#start with tones#final.

into

how much of the final tone is mixed in. 0 is none. Range: 0 to 1



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/tone_part.rb', line 84

def out(into)  
  return tone_single if tone_count == 1
  
  out = tones.start.deep_copy

  #wave
  range = tones.final.wave.detail.start - tones.start.wave.detail.start
  out.wave.detail.start += range*into
  range = tones.final.wave.detail.final - tones.start.wave.detail.final
  out.wave.detail.final += range*into
  range = tones.final.wave.saturations.start - tones.start.wave.saturations.start
  out.wave.saturations.start += range*into
  range = tones.final.wave.saturations.final - tones.start.wave.saturations.final
  out.wave.saturations.final += range*into
  
  #frames
  range = tones.final.frames - tones.start.frames 
  out.frames += range*into
  # puts "frames range #{out.frames}"

  #freq
  range = tones.final.freq.start - tones.start.freq.start
  out.freq.start += range*into
  range = tones.final.freq.final - tones.start.freq.final
  out.freq.final += range*into
  range = tones.final.freq.exp_no_nil - tones.start.freq.exp_no_nil
  out.freq.exp = out.freq.exp_no_nil + range*into

  #amp
  range = tones.final.amp.start - tones.start.amp.start
  out.amp.start += range*into
  range = tones.final.amp.final - tones.start.amp.final
  out.amp.final += range*into
  range = tones.final.amp.exp_no_nil - tones.start.amp.exp_no_nil
  out.amp.exp = out.amp.exp_no_nil + range*into

  out
end

#tone(i = 0) ⇒ Object



16
17
18
19
# File 'lib/tone_part.rb', line 16

def tone i=0
  return tone_single if tone_count == 1
  i==1 ? @tones.final : @tones.start
end

#two_tonesObject



21
22
23
24
25
# File 'lib/tone_part.rb', line 21

def two_tones
  self.tone_count = 2
  tones.start = tone_single
  tones.final = tone_single.deep_copy
end