Class: Metronome::Practice

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

Instance Method Summary collapse

Constructor Details

#initializePractice

Returns a new instance of Practice.



192
193
194
# File 'lib/metronome-odd.rb', line 192

def initialize
  @next_bar_hash = Hash.new(nil)
end

Instance Method Details

#force_tempo(tempo) ⇒ Object



233
234
235
236
237
238
239
# File 'lib/metronome-odd.rb', line 233

def force_tempo(tempo)
  self.each do |bar|
    unless bar.class == Silence
      bar.set_tempo(tempo)
    end
  end
end

#loop_stop?Boolean

Returns:

  • (Boolean)


228
229
230
231
# File 'lib/metronome-odd.rb', line 228

def loop_stop?
  sound(:loop)
  @@stop
end

#playObject



224
225
226
# File 'lib/metronome-odd.rb', line 224

def play
  sound(:play)
end


249
250
251
252
253
254
255
256
257
258
259
# File 'lib/metronome-odd.rb', line 249

def print_practice
  bar_counter = 0 # 0 accounts for the intial silence
  self.each do |b| 
    unless b.class == Silence
      print "\n#{bar_counter}:\t"
      b.print_sign
    end
    bar_counter += 1
  end
  puts
end

#push(b) ⇒ Object



241
242
243
244
245
246
247
# File 'lib/metronome-odd.rb', line 241

def push(b)
  super(b)
  if @prev_bar
    @next_bar_hash[@prev_bar] = b
  end
  @prev_bar = b
end

#sound(type) ⇒ Object



196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# File 'lib/metronome-odd.rb', line 196

def sound(type)
  @@stop = false
  bar_counter = 0 # 0 accounts for the intial silence

  self.each do |b| 
    unless b.class == Silence
      print "\n#{bar_counter}:\t"
      b.print_sign
      if @next_bar_hash[b]
        print " -> "
        @next_bar_hash[b].print_sign
        print "\t"
      else
        case type
        when :play
          print " - last bar! "
        when :loop
          print " - repeat! "
        end
      end
    end
    b.play
    bar_counter += 1
    if @@stop then break end
  end
  puts
end