Class: Music::Transcription::Tempo

Inherits:
Object
  • Object
show all
Includes:
Parseable
Defined in:
lib/music-transcription/model/tempo.rb,
lib/music-transcription/conversion/tempo_conversion.rb,
lib/music-transcription/parsing/convenience_methods.rb

Direct Known Subclasses

BPM, NPM, NPS, QNPM

Defined Under Namespace

Classes: BPM, NPM, NPS, QNPM

Constant Summary collapse

PARSER =
Parsing::TempoParser.new
CONVERSION_METHOD =
:to_tempo

Constants included from Parseable

Parseable::DEFAULT_SPLIT_PATTERN

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Parseable

included

Constructor Details

#initialize(value) ⇒ Tempo

Returns a new instance of Tempo.

Raises:



6
7
8
9
# File 'lib/music-transcription/model/tempo.rb', line 6

def initialize value
  raise NonPositiveError, "Given tempo value #{value} is not positive" if value <= 0
  @value = value
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



5
6
7
# File 'lib/music-transcription/model/tempo.rb', line 5

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object



11
12
13
# File 'lib/music-transcription/model/tempo.rb', line 11

def ==(other)
  self.class == other.class && self.value == other.value
end

#cloneObject



15
16
17
# File 'lib/music-transcription/model/tempo.rb', line 15

def clone
  self.class.new(@value)
end

#convert(tgt_class, bdur = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/music-transcription/conversion/tempo_conversion.rb', line 5

def convert tgt_class, bdur = nil
  args = (is_a?(BPM) || tgt_class == BPM) ? [bdur] : []
  
  return case tgt_class.new(1)
  when self.class then self.clone
  when Tempo::QNPM then to_qnpm(*args)
  when Tempo::NPM then to_npm(*args)
  when Tempo::NPS then to_nps(*args)
  when Tempo::BPM then to_bpm(*args)
  else
    raise TypeError, "Unexpected target tempo class #{tgt_class}"
  end
end