Sha256: 2c0628031d0185ae95054de077d9d30bbcc84d4dd82caee763b9ea6600ac89f7

Contents?: true

Size: 768 Bytes

Versions: 23

Compression:

Stored size: 768 Bytes

Contents

module Music
module Transcription

# Represent the musical tempo, with beats ber minute and beat duration.
class Tempo
  include Comparable
  attr_reader :beats_per_minute, :beat_duration
  
  def initialize beats_per_minute, beat_duration = Rational(1,4)
    @beats_per_minute = beats_per_minute
    @beat_duration = beat_duration
  end
  
  def ==(other)
    (other.beats_per_minute == @beats_per_minute) &&
    (other.beat_duration == @beat_duration)
  end
  
  def notes_per_second
    (@beats_per_minute * @beat_duration) / 60.0
  end
  
  def between? a, b
    notes_per_second.between? a, b
  end
  
  def <=>(other)
    if other.is_a? Tempo
      notes_per_second <=> other.notes_per_second
    else
      notes_per_second <=> other
    end
  end
end

end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
music-transcription-0.17.1 lib/music-transcription/model/tempo.rb
music-transcription-0.17.0 lib/music-transcription/model/tempo.rb
music-transcription-0.16.0 lib/music-transcription/model/tempo.rb
music-transcription-0.15.0 lib/music-transcription/model/tempo.rb
music-transcription-0.14.0 lib/music-transcription/model/tempo.rb
music-transcription-0.13.0 lib/music-transcription/model/tempo.rb
music-transcription-0.11.0 lib/music-transcription/model/tempo.rb
music-transcription-0.10.0 lib/music-transcription/tempo.rb
music-transcription-0.9.2 lib/music-transcription/tempo.rb
music-transcription-0.9.1 lib/music-transcription/tempo.rb
music-transcription-0.9.0 lib/music-transcription/tempo.rb
music-transcription-0.8.1 lib/music-transcription/tempo.rb
music-transcription-0.8.0 lib/music-transcription/tempo.rb
music-transcription-0.7.3 lib/music-transcription/tempo.rb
music-transcription-0.7.2 lib/music-transcription/tempo.rb
music-transcription-0.7.1 lib/music-transcription/tempo.rb
music-transcription-0.7.0 lib/music-transcription/tempo.rb
music-transcription-0.6.3 lib/music-transcription/tempo.rb
music-transcription-0.6.2 lib/music-transcription/tempo.rb
music-transcription-0.6.1 lib/music-transcription/tempo.rb