Class: HeadMusic::Clef

Inherits:
Object
  • Object
show all
Includes:
Named
Defined in:
lib/head_music/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("data/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.



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

def line
  @line
end

#musical_symbolsObject (readonly)

Returns the value of attribute musical_symbols.



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

def musical_symbols
  @musical_symbols
end

#pitchObject (readonly)

Returns the value of attribute pitch.



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

def pitch
  @pitch
end

Class Method Details

.get(name) ⇒ Object



9
10
11
# File 'lib/head_music/clef.rb', line 9

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

Instance Method Details

#==(other) ⇒ Object



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

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

#clef_typeObject



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

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

#modern?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/head_music/clef.rb', line 41

def modern?
  @modern
end

#musical_symbolObject



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

def musical_symbol
  musical_symbols.first
end

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



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

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



25
26
27
28
29
30
31
# File 'lib/head_music/clef.rb', line 25

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



33
34
35
36
37
38
39
# File 'lib/head_music/clef.rb', line 33

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