Class: Music::Transcription::Tempo
- Inherits:
-
Object
- Object
- Music::Transcription::Tempo
- Includes:
- Comparable
- Defined in:
- lib/music-transcription/tempo.rb
Overview
Represent the musical tempo, with beats ber minute and beat duration.
Instance Attribute Summary collapse
-
#beat_duration ⇒ Object
readonly
Returns the value of attribute beat_duration.
-
#beats_per_minute ⇒ Object
readonly
Returns the value of attribute beats_per_minute.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
- #between?(a, b) ⇒ Boolean
-
#initialize(beats_per_minute, beat_duration = Rational(1,4)) ⇒ Tempo
constructor
A new instance of Tempo.
- #notes_per_second ⇒ Object
Constructor Details
#initialize(beats_per_minute, beat_duration = Rational(1,4)) ⇒ Tempo
Returns a new instance of Tempo.
9 10 11 12 |
# File 'lib/music-transcription/tempo.rb', line 9 def initialize beats_per_minute, beat_duration = Rational(1,4) @beats_per_minute = beats_per_minute @beat_duration = beat_duration end |
Instance Attribute Details
#beat_duration ⇒ Object (readonly)
Returns the value of attribute beat_duration.
7 8 9 |
# File 'lib/music-transcription/tempo.rb', line 7 def beat_duration @beat_duration end |
#beats_per_minute ⇒ Object (readonly)
Returns the value of attribute beats_per_minute.
7 8 9 |
# File 'lib/music-transcription/tempo.rb', line 7 def beats_per_minute @beats_per_minute end |
Instance Method Details
#<=>(other) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/music-transcription/tempo.rb', line 27 def <=>(other) if other.is_a? Tempo notes_per_second <=> other.notes_per_second else notes_per_second <=> other end end |
#==(other) ⇒ Object
14 15 16 17 |
# File 'lib/music-transcription/tempo.rb', line 14 def ==(other) (other.beats_per_minute == @beats_per_minute) && (other.beat_duration == @beat_duration) end |
#between?(a, b) ⇒ Boolean
23 24 25 |
# File 'lib/music-transcription/tempo.rb', line 23 def between? a, b notes_per_second.between? a, b end |
#notes_per_second ⇒ Object
19 20 21 |
# File 'lib/music-transcription/tempo.rb', line 19 def notes_per_second (@beats_per_minute * @beat_duration) / 60.0 end |