Class: Music::Transcription::Tempo

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_durationObject (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_minuteObject (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

Returns:

  • (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_secondObject



19
20
21
# File 'lib/music-transcription/tempo.rb', line 19

def notes_per_second
  (@beats_per_minute * @beat_duration) / 60.0
end