class Metronome::OddBar
Attributes
beat_array[RW]
tempo[RW]
Public Class Methods
new(tempo, in_beat)
click to toggle source
# File lib/metronome-odd.rb, line 123 def initialize(tempo, in_beat) 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 @in_beat = in_beat @tempo = tempo upbeat_b = true time = 1 prev_beat = 1 in_beat.each do |t| if upbeat_b beat = Beat.new(tempo/t, @upbeat_sound_file) upbeat_b = false else beat = Beat.new(tempo/t, @downbeat_sound_file) end @beat_array.push(beat) end end
Public Instance Methods
print_sign()
click to toggle source
# File lib/metronome-odd.rb, line 148 def print_sign # In order to print an odd bar, firstly we find the beat sound times # in in_sum, starting from 1. # Then we add the silences in the beats in in_clone # Finally we print the bar, with numbers in the beats and # semicolons in the silences that occur in a beat # width may be used to change size width = 8 max_beat = @in_beat.sum in_sum = [1.0] acum = 1.0 @in_beat.each do |e| acum=acum+e;in_sum.push(acum) end in_clone = in_sum.clone (1...max_beat.floor).each do |d| if not(in_clone.include?(d)) in_clone.push(Float(d)) end end in_clone = in_clone.sort print "|" in_clone[0...-1].each_with_index do |d, i| if in_sum.include?(d) if d == Integer(d) print(':') end print(d.floor) else print(':') end if d<in_clone.last t = Integer((in_clone[i+1]-in_clone[i])*width-1) t.times do print " " end end end print "|" end