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, t2 = 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,t2=Tone.new)
  @tones = Fader.new(t1,t2,0)
  @max_frames = m
  self.frames = m
  @tone_count = 1
  @tone_single = t1
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.



59
60
61
62
63
64
65
66
67
# File 'lib/tone_part.rb', line 59

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

#frames=(val) ⇒ Object



31
32
33
34
# File 'lib/tone_part.rb', line 31

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

#freqObject

get main freq



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

def freq
  tone.freq.start
end

#freq=(val) ⇒ Object

set freq of start and final to val



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

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

#noteObject

get main note



41
42
43
# File 'lib/tone_part.rb', line 41

def note
  tone.note
end

#note=(val) ⇒ Object

set freq of start and final to Note.freq

val

the note to call freq on



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

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



72
73
74
75
76
77
78
79
80
81
82
83
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
# File 'lib/tone_part.rb', line 72

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