head_music 0.24.0 → 0.24.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,57 @@
1
+ fr:
2
+ rudiments:
3
+ clef: clé
4
+ clefs:
5
+ alto_clef: clé alto
6
+ baritone_c_clef: clé de baryton
7
+ baritone_clef: clé de baryton
8
+ baritone_f_clef: clé de fa 3e
9
+ bass_clef: clé de basse
10
+ c_clef: clé d'ut
11
+ choral_tenor_clef: choral tenor clef
12
+ contrabass_clef: clé de contrebasse
13
+ countertenor_clef: clé de contre-ténor
14
+ double_treble_clef: double clé de sol
15
+ drum_clef: clé de tambour
16
+ f_clef: clé de fa
17
+ fifth_line_c_clef: clé d'ut 5e
18
+ fifth_line_f_clef: clé de fa 5e
19
+ first_line_c_clef: clé d'ut 1re
20
+ first_line_g_clef: clé de sol 1re
21
+ fourth_line_c_clef: clé d'ut 4e
22
+ fourth_line_f_clef: clé de fa 4e
23
+ french_clef: clé de sol 1re
24
+ french_violin_clef: clé de sol 1re
25
+ g_clef: clé de sol
26
+ indefinite_pitch_clef: clé à pas indéfini
27
+ mezzo_soprano_clef: clé de mezzo-soprano
28
+ neutral_clef: clé neutre
29
+ percussion_clef: clé de percussion
30
+ second_line_c_clef: clé d'ut 2e
31
+ second_line_g_clef: clé de sol 2e
32
+ soprano_clef: clé de soprano
33
+ sub_bass_clef: clé de fa 5e
34
+ tenor_c_clef: clé d'ut 4e
35
+ tenor_clef: clé de ténor
36
+ tenor_g_clef: clé de sol 2e
37
+ third_line_c_clef: clé d'ut 3e
38
+ third_line_f_clef: clé de fa 3e
39
+ treble_clef: clé de sol
40
+ viola_clef: clé d'ut
41
+ violin_clef: clé de sol
42
+ instruments:
43
+ accordian: accordéon
44
+ alto_flute: flûte alto
45
+ alto_voice: alto
46
+ bagpipe: cornemuse
47
+ baritone_voice: baryton
48
+ bass_clarinet: clarinette basse
49
+ bass_voice: basse
50
+ piano: piano
51
+ viola: alto
52
+ violin: violon
53
+ instrument_voices:
54
+ alto: alto
55
+ baritone: baryton
56
+ bass: basse
57
+ guitar: guitare
@@ -0,0 +1,58 @@
1
+ it:
2
+ rudiments:
3
+ clef: chiave
4
+ consonance: consonanza
5
+ clefs:
6
+ alto_clef: chiave di contralto
7
+ baritone_c_clef: chiave di baritono
8
+ baritone_clef: chiave di baritono
9
+ baritone_f_clef: chiave di baritono
10
+ bass_clef: chiave di basso
11
+ c_clef: chiave di do
12
+ choral_tenor_clef: chiave di sol in ottava
13
+ contrabass_clef: chiave di contrabbasso
14
+ countertenor_clef: chiave di controtenore
15
+ double_treble_clef: chiave di sol in ottava
16
+ drum_clef: chiave di percussione
17
+ f_clef: chiave di fa
18
+ fifth_line_c_clef: chiave di do sulla 5ª linea
19
+ fifth_line_f_clef: chiave di fa sulla 5ª linea
20
+ first_line_c_clef: chiave di do sulla 1ª linea
21
+ first_line_g_clef: chiave di sol sulla 1ª linea
22
+ fourth_line_c_clef: chiave di do sulla 4ª linea
23
+ fourth_line_f_clef: chiave di fa sulla 4ª linea
24
+ french_clef: chiave di violino francese
25
+ french_violin_clef: chiave di violino francese
26
+ g_clef: chiave di sol
27
+ indefinite_pitch_clef: chiave neutra
28
+ mezzo_soprano_clef: chiave di mezzosoprano
29
+ neutral_clef: chiave neutra
30
+ percussion_clef: chiave di percussione
31
+ second_line_c_clef: chiave di do sulla 2ª linea
32
+ second_line_g_clef: chiave di sol sulla 2ª linea
33
+ soprano_clef: chiave di soprano
34
+ sub_bass_clef: chiave di subbasso
35
+ tenor_c_clef: chiave di tenore
36
+ tenor_clef: chiave di tenore
37
+ tenor_g_clef: chiave di sol in ottava
38
+ third_line_c_clef: chiave di do sulla 3ª linea
39
+ third_line_f_clef: chiave di fa sulla 3ª linea
40
+ treble_clef: chiave di violino
41
+ viola_clef: chiave di viola
42
+ violin_clef: chiave di violino
43
+ instruments:
44
+ accordian: fisarmonica
45
+ alto_flute: flauto contralto
46
+ alto_voice: contralto
47
+ bagpipe: cornamusa
48
+ baritone_voice: baritono
49
+ bass_voice: basso
50
+ guitar: chitarra
51
+ piccolo: ottavino
52
+ piano: piano
53
+ viola: viola
54
+ violin: violino
55
+ instrument_voices:
56
+ alto: contralto
57
+ baritone: baritono
58
+ bass: basso
@@ -2,44 +2,111 @@
2
2
 
3
3
  # NameRudiment is a module to be included in classes whose instances may be identified by name.
4
4
  module HeadMusic::Named
5
- attr_reader :name
6
5
  delegate :to_s, to: :name
7
6
 
8
- def initialize(name)
9
- @name = name.to_s
10
- end
7
+ # Locale encapsulates a language and optional region or country.
8
+ class Locale
9
+ DEFAULT_CODE = :en_US
11
10
 
12
- def hash_key
13
- HeadMusic::Utilities::HashKey.for(name)
11
+ attr_reader :language, :region
12
+
13
+ def self.default_locale
14
+ get(DEFAULT_CODE)
15
+ end
16
+
17
+ def self.get(code)
18
+ @locales ||= {}
19
+ parts = code.to_s.split(/[_\-]/)
20
+ language = parts[0].downcase
21
+ region = parts[1]&.upcase
22
+ key = [language, region].compact.join('_').to_sym
23
+ @locales[key] ||= new(language: language, region: region)
24
+ end
25
+
26
+ def initialize(language:, region: nil)
27
+ @language = language
28
+ @region = region
29
+ end
30
+
31
+ def code
32
+ @code ||= [@language, @region].compact.join('_')
33
+ end
34
+
35
+ private_class_method :new
14
36
  end
15
37
 
16
- def self.included(base)
17
- base.extend(ClassMethods)
38
+ # A LocalizedName is the name of a rudiment in a locale.
39
+ class LocalizedName
40
+ attr_reader :locale, :name, :abbreviation
41
+
42
+ delegate :code, to: :locale, prefix: true
43
+ delegate :language, :region, to: :locale
44
+
45
+ def initialize(name:, locale_code: Locale::DEFAULT_CODE, abbreviation: nil)
46
+ @name = name
47
+ @locale = Locale.get(locale_code)
48
+ @abbreviation = abbreviation
49
+ end
18
50
  end
19
51
 
20
52
  # Adds .get_by_name to the including class.
21
53
  module ClassMethods
22
54
  def get_by_name(name)
23
55
  name = name.to_s
24
- @instances_by_name ||= {}
56
+ @instances ||= {}
25
57
  key = HeadMusic::Utilities::HashKey.for(name)
26
- @instances_by_name[key] ||= new(name)
58
+ @instances[key] ||= new(name)
27
59
  end
60
+ end
28
61
 
29
- def aliases
30
- {}
31
- end
62
+ def self.included(base)
63
+ base.extend(ClassMethods)
32
64
  end
33
65
 
34
- # An Alias encapsulates an alternative name for a rudiment.
35
- class Alias
36
- attr_reader :key, :name, :abbreviation, :locale
66
+ attr_reader :name_key, :alias_name_keys
37
67
 
38
- def initialize(key:, name:, abbreviation: nil, locale: nil)
39
- @key = key
40
- @name = name
41
- @abbreviation = abbreviation
42
- @locale = locale
43
- end
68
+ def name=(name)
69
+ ensure_localized_name(name: name)
70
+ end
71
+
72
+ def name(locale_code: Locale::DEFAULT_CODE)
73
+ localized_name(locale_code: locale_code)&.name
74
+ end
75
+
76
+ def localized_name(locale_code: Locale::DEFAULT_CODE)
77
+ locale = Locale.get(locale_code || Locale::DEFAULT_CODE)
78
+ localized_name_in_matching_locale(locale) ||
79
+ localized_name_in_locale_matching_language(locale) ||
80
+ localized_name_in_default_locale ||
81
+ localized_names.first
82
+ end
83
+
84
+ def ensure_localized_name(name:, locale_code: Locale::DEFAULT_CODE, abbreviation: nil)
85
+ @localized_names ||= []
86
+ @localized_names << LocalizedName.new(name: name, locale_code: locale_code, abbreviation: abbreviation)
87
+ @localized_names.uniq!
88
+ end
89
+
90
+ # Returns an array of LocalizedName instances that are synonymous with the name.
91
+ def localized_names
92
+ @localized_names ||= []
93
+ end
94
+
95
+ private
96
+
97
+ def localized_name_in_matching_locale(locale)
98
+ localized_names.detect { |candidate| candidate.locale_code == locale.code }
99
+ end
100
+
101
+ def localized_name_in_locale_matching_language(locale)
102
+ localized_names.detect { |candidate| candidate.language == locale.language }
103
+ end
104
+
105
+ def localized_name_in_default_locale
106
+ localized_names.detect { |name| name.locale_code == Locale::DEFAULT_CODE }
107
+ end
108
+
109
+ def hash_key
110
+ HeadMusic::Utilities::HashKey.for(name)
44
111
  end
45
112
  end
@@ -31,6 +31,7 @@ class HeadMusic::Octave
31
31
  end
32
32
 
33
33
  attr_reader :number
34
+
34
35
  delegate :to_i, :to_s, to: :number
35
36
 
36
37
  def initialize(number)
@@ -44,6 +44,7 @@ class HeadMusic::Quality
44
44
  end
45
45
 
46
46
  attr_reader :name
47
+
47
48
  delegate :to_s, to: :name
48
49
 
49
50
  def initialize(name)
@@ -7,60 +7,85 @@ class HeadMusic::ReferencePitch
7
7
 
8
8
  DEFAULT_PITCH_NAME = 'A4'
9
9
  DEFAULT_FREQUENCY = 440.0
10
+ DEFAULT_REFERENCE_PITCH_NAME = 'A440'
10
11
 
11
12
  NAMED_REFERENCE_PITCHES = [
12
- { name: 'Baroque', pitch: 'A4', frequency: 415.0 },
13
- { name: 'Classical', pitch: 'A4', frequency: 430.0 },
14
- { name: 'Scientific', pitch: 'C4', frequency: 256.0 },
15
- { name: 'Verdi', pitch: 'A4', frequency: 432.0 }, # Pythagorean tuning
16
- { name: 'French', pitch: 'A4', frequency: 435.0 },
17
- { name: 'New Philharmonic', pitch: 'A4', frequency: 439.0 },
18
- { name: 'A440', pitch: 'A4', frequency: 440.0 },
19
- { name: 'Sydney Symphony Orchestra', pitch: 'A4', frequency: 441.0 },
20
- { name: 'New York Philharmonic', pitch: 'A4', frequency: 442.0 },
21
- { name: 'Berlin Philharmonic', pitch: 'A4', frequency: 443.0 },
22
- { name: 'Boston Symphony Orchestra', pitch: 'A4', frequency: 444.0 },
23
- { name: 'Old Philharmonic', pitch: 'A4', frequency: 452.4 },
24
- { name: 'Chorton', pitch: 'A4', frequency: 466.0 },
25
- ].freeze
26
-
27
- ALIAS_DATA = [
28
- { key: :baroque, name: 'Kammerton' },
29
- { key: :classical, name: 'Haydn' },
30
- { key: :classical, name: 'Mozart' },
31
- { key: :scientific, name: 'philosophical' },
32
- { key: :scientific, name: 'Sauveur' },
33
- { key: :scientific, name: 'Schiller' },
34
- { key: :french, name: 'continental' },
35
- { key: :french, name: 'international' },
36
- { key: :new_philharmonic, name: 'low' },
37
- { key: :old_philharmonic, name: 'high' },
38
- { key: :a440, name: 'concert' },
39
- { key: :a440, name: 'Stuttgart' },
40
- { key: :a440, name: 'Scheibler' },
41
- { key: :a440, name: 'ISO 16' },
42
- { key: :chorton, name: 'choir' },
13
+ {
14
+ frequency: 415.0,
15
+ key: :baroque,
16
+ alias_keys: %i[chamber_tone],
17
+ },
18
+ {
19
+ frequency: 430.0,
20
+ key: :classical,
21
+ alias_keys: %i[haydn mozart],
22
+ },
23
+ {
24
+ pitch: 'C4',
25
+ frequency: 256.0,
26
+ key: :scientific,
27
+ alias_keys: %i[philosophical sauveur],
28
+ },
29
+ {
30
+ frequency: 432.0,
31
+ tuning: 'Pythagorean',
32
+ key: :verdi,
33
+ },
34
+ {
35
+ frequency: 435.0,
36
+ key: :french,
37
+ alias_keys: %i[continental international],
38
+ },
39
+ {
40
+ frequency: 439.0,
41
+ key: :new_philharmonic,
42
+ alias_keys: %i[low],
43
+ },
44
+ {
45
+ frequency: 440.0,
46
+ key: :a440,
47
+ alias_keys: %i[concert stuttgart scheibler iso_16],
48
+ },
49
+ {
50
+ frequency: 441.0,
51
+ key: :sydney_symphony_orchestra,
52
+ },
53
+ {
54
+ frequency: 442.0,
55
+ key: :new_york_philharmonic,
56
+ },
57
+ {
58
+ frequency: 443.0,
59
+ key: :berlin_philharmonic,
60
+ },
61
+ {
62
+ frequency: 444.0,
63
+ key: :boston_symphony_orchestra,
64
+ },
65
+ {
66
+ frequency: 452.4,
67
+ key: :old_philharmonic,
68
+ alias_keys: %i[high],
69
+ },
70
+ {
71
+ frequency: 466.0,
72
+ key: :chorton,
73
+ alias_keys: %i[choir],
74
+ },
43
75
  ].freeze
44
76
 
45
77
  attr_reader :pitch, :frequency
46
78
 
47
- def self.aliases
48
- @aliases ||= ALIAS_DATA.map { |attributes| HeadMusic::Named::Alias.new(attributes) }
49
- end
50
-
51
79
  def self.get(name)
52
80
  return name if name.is_a?(self)
53
81
  get_by_name(name)
54
82
  end
55
83
 
56
- def initialize(name = 'A440')
57
- @name = name.to_s
58
- reference_pitch_data = NAMED_REFERENCE_PITCHES.detect do |candidate|
59
- candidate_name_key = HeadMusic::Utilities::HashKey.for(candidate[:name])
60
- [candidate_name_key, candidate_name_key.to_s.delete('_').to_sym].include?(normalized_key)
61
- end || {}
62
- @pitch = HeadMusic::Pitch.get(reference_pitch_data.fetch(:pitch, DEFAULT_PITCH_NAME))
63
- @frequency = reference_pitch_data.fetch(:frequency, DEFAULT_FREQUENCY)
84
+ def initialize(name = DEFAULT_REFERENCE_PITCH_NAME)
85
+ record = named_reference_pitch_record_for_name(name)
86
+ @pitch = HeadMusic::Pitch.get(record.fetch(:pitch, DEFAULT_PITCH_NAME))
87
+ @frequency = record.fetch(:frequency, DEFAULT_FREQUENCY)
88
+ initialize_keys_from_record(record)
64
89
  end
65
90
 
66
91
  def description
@@ -79,12 +104,42 @@ class HeadMusic::ReferencePitch
79
104
 
80
105
  private
81
106
 
82
- def normalized_key
83
- @normalized_key ||= begin
84
- key = HeadMusic::Utilities::HashKey.for(name.to_s.gsub(/\W?(pitch|tuning|tone)/, ''))
85
- HeadMusic::ReferencePitch.aliases.detect do |alias_data|
86
- HeadMusic::Utilities::HashKey.for(alias_data.name) == key
87
- end&.key || key
107
+ def named_reference_pitch_record_for_name(name)
108
+ key = HeadMusic::Utilities::HashKey.for(normalized_name_string(name))
109
+ NAMED_REFERENCE_PITCHES.detect do |record|
110
+ name_keys_from_record(record).include?(key)
111
+ end || named_reference_pitch_record_for_name(DEFAULT_REFERENCE_PITCH_NAME)
112
+ end
113
+
114
+ def name_keys_from_record(record)
115
+ names_from_record(record).map { |name| HeadMusic::Utilities::HashKey.for(name) }
116
+ end
117
+
118
+ def names_from_record(record)
119
+ name_keys = ([record[:key]] + [record[:alias_keys]]).flatten.compact.uniq
120
+ normalized_translations_for_keys(name_keys)
121
+ end
122
+
123
+ def normalized_name_string(name)
124
+ name.gsub(' pitch', '').gsub(' tone', '').gsub(' tuning', '')
125
+ end
126
+
127
+ def initialize_keys_from_record(record)
128
+ @key = record[:key]
129
+ @alias_keys = [record[:alias_keys]].flatten.compact
130
+ end
131
+
132
+ def normalized_translations_for_keys(name_keys)
133
+ name_and_alias_translations_for_keys(name_keys).map do |name|
134
+ normalized_name_string(name)
88
135
  end
89
136
  end
137
+
138
+ def name_and_alias_translations_for_keys(name_keys)
139
+ name_keys.map do |name_key|
140
+ I18n.config.available_locales.map do |locale_code|
141
+ I18n.translate(name_key, scope: :reference_pitches, locale: locale_code)
142
+ end.flatten.uniq.compact
143
+ end.flatten.uniq.compact
144
+ end
90
145
  end
@@ -27,7 +27,7 @@ class HeadMusic::RhythmicUnit
27
27
  end
28
28
 
29
29
  def initialize(canonical_name)
30
- @name = canonical_name
30
+ self.name = canonical_name
31
31
  @numerator = 2**numerator_exponent
32
32
  @denominator = 2**denominator_exponent
33
33
  end