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.



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

def line
  @line
end

#musical_symbolsObject (readonly)

Returns the value of attribute musical_symbols.



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

def musical_symbols
  @musical_symbols
end

#pitchObject (readonly)

Returns the value of attribute pitch.



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

def pitch
  @pitch
end

Class Method Details

.get(name) ⇒ Object



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

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

Instance Method Details

#==(other) ⇒ Object



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

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

#clef_typeObject



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

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

#modern?Boolean

Returns:

  • (Boolean)


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

def modern?
  @modern
end

#musical_symbolObject



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

def musical_symbol
  musical_symbols.first
end

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



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

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



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

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



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

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