class HeadMusic::Clef
A clef assigns pitches to the lines and spaces of a staff.
Constants
- RECORDS
Attributes
line[R]
musical_symbols[R]
pitch[R]
Public Class Methods
get(name)
click to toggle source
# File lib/head_music/clef.rb, line 11 def self.get(name) get_by_name(name) end
new(name)
click to toggle source
# File lib/head_music/clef.rb, line 59 def initialize(name) record = record_for_name(name) initialize_data_from_record(record) end
Public Instance Methods
==(other)
click to toggle source
# File lib/head_music/clef.rb, line 47 def ==(other) HeadMusic::Utilities::HashKey.for(self) == HeadMusic::Utilities::HashKey.for(other) end
clef_type()
click to toggle source
# File lib/head_music/clef.rb, line 23 def clef_type "#{pitch.letter_name}-clef" end
modern?()
click to toggle source
# File lib/head_music/clef.rb, line 43 def modern? @modern end
musical_symbol()
click to toggle source
# File lib/head_music/clef.rb, line 19 def musical_symbol musical_symbols.first end
name(locale_code: Locale::DEFAULT_CODE)
click to toggle source
# File lib/head_music/clef.rb, line 51 def name(locale_code: Locale::DEFAULT_CODE) I18n.translate(name_key, scope: :clefs, locale: locale_code) end
pitch_for_line(line_number)
click to toggle source
# 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)
click to toggle source
# 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
Private Instance Methods
initialize_data_from_record(record)
click to toggle source
# File lib/head_music/clef.rb, line 85 def initialize_data_from_record(record) initialize_keys_from_record(record) @pitch = HeadMusic::Pitch.get(record[:pitch]) @line = record[:line] @modern = record[:modern] initialize_musical_symbols(record[:symbols]) end
initialize_keys_from_record(record)
click to toggle source
# File lib/head_music/clef.rb, line 93 def initialize_keys_from_record(record) @name_key = record[:name_key] @alias_name_keys = [record[:alias_name_keys]].flatten.compact end
initialize_musical_symbols(list)
click to toggle source
# File lib/head_music/clef.rb, line 98 def initialize_musical_symbols(list) @musical_symbols = (list || []).map do |symbol_data| HeadMusic::MusicalSymbol.new(symbol_data.slice(:ascii, :html_entity, :unicode)) end end
name_key_translations(name_keys)
click to toggle source
# File lib/head_music/clef.rb, line 77 def name_key_translations(name_keys) name_keys.map do |name_key| I18n.config.available_locales.map do |locale_code| I18n.translate(name_key, scope: :clefs, locale: locale_code) end.flatten.uniq.compact end.flatten.uniq.compact end
name_keys_from_record(record)
click to toggle source
# File lib/head_music/clef.rb, line 73 def name_keys_from_record(record) ([record[:name_key]] + [record[:alias_name_keys]]).flatten.compact.uniq.map(&:to_sym) end
record_for_name(name)
click to toggle source
# File lib/head_music/clef.rb, line 64 def record_for_name(name) name = name.to_s.strip key = HeadMusic::Utilities::HashKey.for(name) RECORDS.detect do |record| name_keys = name_keys_from_record(record) name_keys.include?(key) || name_key_translations(name_keys).include?(name) end end