Class: HeadMusic::Rudiment::Clef

Inherits:
Object
  • Object
show all
Includes:
Named
Defined in:
lib/head_music/rudiment/clef.rb

Overview

A clef assigns pitches to the lines and spaces of a staff.

Constant Summary collapse

RECORDS =
YAML.load_file(File.expand_path("clefs.yml", __dir__)).freeze

Instance Attribute Summary collapse

Attributes included from Named

#alias_name_keys, #name_key

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Named

#ensure_localized_name, included, #localized_name, #localized_names, #name=

Instance Attribute Details

#lineObject (readonly)

Returns the value of attribute line.



16
17
18
# File 'lib/head_music/rudiment/clef.rb', line 16

def line
  @line
end

#musical_symbolsObject (readonly)

Returns the value of attribute musical_symbols.



16
17
18
# File 'lib/head_music/rudiment/clef.rb', line 16

def musical_symbols
  @musical_symbols
end

#pitchObject (readonly)

Returns the value of attribute pitch.



16
17
18
# File 'lib/head_music/rudiment/clef.rb', line 16

def pitch
  @pitch
end

Class Method Details

.get(name) ⇒ Object



12
13
14
# File 'lib/head_music/rudiment/clef.rb', line 12

def self.get(name)
  get_by_name(name)
end

Instance Method Details

#==(other) ⇒ Object



48
49
50
# File 'lib/head_music/rudiment/clef.rb', line 48

def ==(other)
  HeadMusic::Utilities::HashKey.for(self) == HeadMusic::Utilities::HashKey.for(other)
end

#clef_typeObject



24
25
26
# File 'lib/head_music/rudiment/clef.rb', line 24

def clef_type
  "#{pitch.letter_name}-clef"
end

#modern?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/head_music/rudiment/clef.rb', line 44

def modern?
  @modern
end

#musical_symbolObject



20
21
22
# File 'lib/head_music/rudiment/clef.rb', line 20

def musical_symbol
  musical_symbols.first
end

#name(locale_code: Locale::DEFAULT_CODE) ⇒ Object



52
53
54
# File 'lib/head_music/rudiment/clef.rb', line 52

def name(locale_code: Locale::DEFAULT_CODE)
  I18n.translate(name_key, scope: "head_music.clefs", locale: locale_code)
end

#pitch_for_line(line_number) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/head_music/rudiment/clef.rb', line 28

def pitch_for_line(line_number)
  @line_pitches ||= {}
  @line_pitches[line_number] ||= begin
    steps = (line_number - line) * 2
    pitch.natural_steps(steps)
  end
end

#pitch_for_space(space_number) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/head_music/rudiment/clef.rb', line 36

def pitch_for_space(space_number)
  @space_pitches ||= {}
  @space_pitches[space_number] ||= begin
    steps = (space_number - line) * 2 + 1
    pitch.natural_steps(steps)
  end
end