Class: Metronome::Bar

Inherits:
Object
  • Object
show all
Defined in:
lib/metronome-odd.rb

Direct Known Subclasses

OddBar

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tempo, n, d) ⇒ Bar

Returns a new instance of Bar.



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/metronome-odd.rb', line 79

def initialize(tempo, n, d)
  data_dir = Gem.datadir("metronome-odd")
  data_dir = data_dir ? data_dir : ""
  @upbeat_sound_file = data_dir + "/beat_upbeat.aiff"
  @downbeat_sound_file = data_dir + "/beat_downbeat.aiff"

  @beat_array = Array.new
  @beat_array.push(Beat.new(tempo*d/4.0, @upbeat_sound_file))

  @n = n
  @d = d

  @tempo = tempo

  (2..n).each do 
    @beat_array.push(Beat.new(tempo*d/4.0, @downbeat_sound_file))
  end
  self
end

Instance Attribute Details

#beat_arrayObject

Returns the value of attribute beat_array.



77
78
79
# File 'lib/metronome-odd.rb', line 77

def beat_array
  @beat_array
end

#dObject (readonly)

Returns the value of attribute d.



75
76
77
# File 'lib/metronome-odd.rb', line 75

def d
  @d
end

#downbeat_sound_file=(value) ⇒ Object (writeonly)

Sets the attribute downbeat_sound_file

Parameters:

  • value

    the value to set the attribute downbeat_sound_file to.



73
74
75
# File 'lib/metronome-odd.rb', line 73

def downbeat_sound_file=(value)
  @downbeat_sound_file = value
end

#nObject (readonly)

Returns the value of attribute n.



74
75
76
# File 'lib/metronome-odd.rb', line 74

def n
  @n
end

#tempoObject

Returns the value of attribute tempo.



76
77
78
# File 'lib/metronome-odd.rb', line 76

def tempo
  @tempo
end

#upbeat_sound_file=(value) ⇒ Object (writeonly)

Sets the attribute upbeat_sound_file

Parameters:

  • value

    the value to set the attribute upbeat_sound_file to.



72
73
74
# File 'lib/metronome-odd.rb', line 72

def upbeat_sound_file=(value)
  @upbeat_sound_file = value
end

Instance Method Details

#playObject



99
100
101
# File 'lib/metronome-odd.rb', line 99

def play
  @beat_array.each {|b| b.play}
end


103
104
105
# File 'lib/metronome-odd.rb', line 103

def print_sign
  print "|#{@n}x#{@d}|"
end

#set_tempo(tempo) ⇒ Object



107
108
109
110
111
112
113
114
115
# File 'lib/metronome-odd.rb', line 107

def set_tempo(tempo)
  old_tempo = Float(@tempo)

  @beat_array.each do |beat|
    beat.silence.duration *= old_tempo/tempo
  end

  @tempo = tempo
end