Class: Stretto::MusicElements::Tempo

Inherits:
MusicElement show all
Defined in:
lib/stretto/music_elements/tempo.rb

Overview

Tempo represents the bpm of the song.

It is indicated by a T followed by the value of the tempo. There are some predefined variables that define the most common tempos (see Variables::TEMPO_VARIABLES), and the default is allegro, that is, a tempo of T120 bpm

Instance Attribute Summary

Attributes inherited from MusicElement

#original_string, #pattern

Attributes included from Node

#next, #prev

Instance Method Summary (collapse)

Methods inherited from MusicElement

#build_music_string, #duration, #end_of_tie?, #start_of_tie?, #to_s

Constructor Details

- (Tempo) initialize(string_or_options, pattern = nil)

Returns a new instance of Tempo



14
15
16
17
18
19
20
21
# File 'lib/stretto/music_elements/tempo.rb', line 14

def initialize(string_or_options, pattern = nil)
  token = case string_or_options
    when String then Stretto::Parser.parse_tempo!(string_or_options)
    else string_or_options
  end
  super(token[:text_value], pattern)
  @original_value = token[:value]
end

Instance Method Details

- (Object) bpm



27
28
29
# File 'lib/stretto/music_elements/tempo.rb', line 27

def bpm
  value
end

- (Object) substitute_variables!



35
36
37
# File 'lib/stretto/music_elements/tempo.rb', line 35

def substitute_variables!
  self.value = value
end

- (Object) value



31
32
33
# File 'lib/stretto/music_elements/tempo.rb', line 31

def value
  @value || @original_value.to_i(@pattern)
end

- (Object) value=(value)



23
24
25
# File 'lib/stretto/music_elements/tempo.rb', line 23

def value=(value)
   @value = value
end