Class: Metronome::Bar
- Inherits:
-
Object
- Object
- Metronome::Bar
- Defined in:
- lib/metronome-odd.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#beat_array ⇒ Object
Returns the value of attribute beat_array.
-
#d ⇒ Object
readonly
Returns the value of attribute d.
-
#downbeat_sound_file ⇒ Object
writeonly
Sets the attribute downbeat_sound_file.
-
#n ⇒ Object
readonly
Returns the value of attribute n.
-
#tempo ⇒ Object
Returns the value of attribute tempo.
-
#upbeat_sound_file ⇒ Object
writeonly
Sets the attribute upbeat_sound_file.
Instance Method Summary collapse
-
#initialize(tempo, n, d) ⇒ Bar
constructor
A new instance of Bar.
- #play ⇒ Object
- #print_sign ⇒ Object
- #set_tempo(tempo) ⇒ Object
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_array ⇒ Object
Returns the value of attribute beat_array.
77 78 79 |
# File 'lib/metronome-odd.rb', line 77 def beat_array @beat_array end |
#d ⇒ Object (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
73 74 75 |
# File 'lib/metronome-odd.rb', line 73 def downbeat_sound_file=(value) @downbeat_sound_file = value end |
#n ⇒ Object (readonly)
Returns the value of attribute n.
74 75 76 |
# File 'lib/metronome-odd.rb', line 74 def n @n end |
#tempo ⇒ Object
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
72 73 74 |
# File 'lib/metronome-odd.rb', line 72 def upbeat_sound_file=(value) @upbeat_sound_file = value end |
Instance Method Details
#play ⇒ Object
99 100 101 |
# File 'lib/metronome-odd.rb', line 99 def play @beat_array.each {|b| b.play} end |
#print_sign ⇒ Object
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 |