lib/head_music/clef.rb in head_music-0.23.2 vs lib/head_music/clef.rb in head_music-0.23.3
- old
+ new
@@ -3,38 +3,92 @@
# A clef assigns pitches to the lines and spaces of a staff.
class HeadMusic::Clef
include HeadMusic::NamedRudiment
CLEFS = [
- { pitch: 'G4', line: 2, names: %w[treble G-clef], modern: true },
- { pitch: 'G4', line: 1, names: ['French', 'French violin'] },
- { pitch: 'G3', line: 2, names: ['choral tenor', 'tenor', 'tenor G-clef'], modern: true },
-
- { pitch: 'F3', line: 3, names: ['baritone'] },
- { pitch: 'F3', line: 4, names: %w[bass F-clef], modern: true },
- { pitch: 'F3', line: 5, names: ['sub-bass'] },
-
- { pitch: 'C4', line: 1, names: ['soprano'] },
- { pitch: 'C4', line: 2, names: ['mezzo-soprano'] },
- { pitch: 'C4', line: 3, names: %w[alto viola counter-tenor countertenor C-clef], modern: true },
- { pitch: 'C4', line: 4, names: ['tenor', 'tenor C-clef'], modern: true },
- { pitch: 'C4', line: 5, names: ['baritone', 'baritone C-clef'] },
-
- { pitch: nil, line: 3, names: %w[neutral percussion] },
+ {
+ pitch: 'G4', line: 2,
+ names: %w[treble G-clef],
+ modern: true,
+ unicode: '𝄞', html_entity: '𝄞',
+ },
+ {
+ pitch: 'G4', line: 1,
+ names: ['French', 'French violin'],
+ unicode: '𝄞', html_entity: '𝄞',
+ },
+ {
+ pitch: 'G3', line: 2,
+ names: ['choral tenor', 'tenor', 'tenor G-clef'],
+ modern: true,
+ unicode: '𝄠', html_entity: '𝄠',
+ },
+ {
+ pitch: 'F3', line: 3,
+ names: ['baritone'],
+ unicode: '𝄢', html_entity: '𝄢',
+ },
+ {
+ pitch: 'F3', line: 4,
+ names: %w[bass F-clef],
+ modern: true,
+ unicode: '𝄢', html_entity: '𝄢',
+ },
+ {
+ pitch: 'F3', line: 5,
+ names: ['sub-bass'],
+ unicode: '𝄢', html_entity: '𝄢',
+ },
+ {
+ pitch: 'C4', line: 1,
+ names: ['soprano'],
+ unicode: '𝄡', html_entity: '𝄡',
+ },
+ {
+ pitch: 'C4', line: 2,
+ names: ['mezzo-soprano'],
+ unicode: '𝄡', html_entity: '𝄡',
+ },
+ {
+ pitch: 'C4', line: 3,
+ names: %w[alto viola counter-tenor countertenor C-clef],
+ modern: true,
+ unicode: '𝄡', html_entity: '𝄡',
+ },
+ {
+ pitch: 'C4', line: 4,
+ names: ['tenor', 'tenor C-clef'],
+ modern: true,
+ unicode: '𝄡', html_entity: '𝄡',
+ },
+ {
+ pitch: 'C4', line: 5,
+ names: ['baritone', 'baritone C-clef'],
+ unicode: '𝄡', html_entity: '𝄡',
+ },
+ {
+ pitch: nil, line: 3,
+ names: %w[neutral percussion],
+ modern: true,
+ unicode: '𝄥', html_entity: '𝄥',
+ },
].freeze
def self.get(name)
get_by_name(name)
end
- attr_reader :pitch, :line
+ attr_reader :pitch, :line, :musical_symbol
+ delegate :ascii, :html_entity, :unicode, to: :musical_symbol
+
def initialize(name)
@name = name.to_s
clef_data = CLEFS.detect { |clef| clef[:names].map(&:downcase).include?(name.downcase) }
@pitch = HeadMusic::Pitch.get(clef_data[:pitch])
@line = clef_data[:line]
@modern = clef_data[:modern]
+ @musical_symbol = HeadMusic::MusicalSymbol.new(clef_data.slice(:ascii, :html_entity, :unicode))
end
def clef_type
"#{pitch.letter_name}-clef"
end