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.
@@ -4,6 +4,7 @@
4
4
  class HeadMusic::DiatonicInterval
5
5
  include Comparable
6
6
 
7
+ # TODO: include Named module
7
8
  NUMBER_NAMES = %w[
8
9
  unison second third fourth fifth sixth seventh octave
9
10
  ninth tenth eleventh twelfth thirteenth fourteenth fifteenth
@@ -6,16 +6,16 @@ class HeadMusic::GrandStaff
6
6
  piano: {
7
7
  instrument: :piano,
8
8
  staves: [
9
- { clef: :treble, instrument: :piano },
10
- { clef: :bass, instrument: :piano },
9
+ { clef: :treble_clef, for: :right_hand },
10
+ { clef: :bass_clef, for: :left_hand },
11
11
  ],
12
12
  },
13
13
  organ: {
14
14
  instrument: :organ,
15
15
  staves: [
16
- { clef: :treble, instrument: :organ },
17
- { clef: :bass, instrument: :organ },
18
- { clef: :bass, instrument: :pedals },
16
+ { clef: :treble_clef, for: :right_hand },
17
+ { clef: :bass_clef, for: :left_hand },
18
+ { clef: :bass_clef, for: :pedals },
19
19
  ],
20
20
  },
21
21
  }.freeze
@@ -41,7 +41,9 @@ class HeadMusic::GrandStaff
41
41
 
42
42
  def staves
43
43
  @staves ||=
44
- data[:staves].map { |staff| HeadMusic::Staff.new(staff[:clef], instrument: staff[:instrument] || instrument) }
44
+ data[:staves].map do |staff|
45
+ HeadMusic::Staff.new(staff[:clef], instrument: instrument)
46
+ end
45
47
  end
46
48
 
47
49
  def brace_staves_index_first
@@ -4,44 +4,76 @@
4
4
  class HeadMusic::Instrument
5
5
  include HeadMusic::Named
6
6
 
7
- INSTRUMENTS = {
8
- violin: {
9
- name: 'violin',
10
- family: :string,
11
- default_clef: :treble,
12
- },
13
- piano: {
14
- name: 'piano',
15
- family: :string,
16
- default_system: %i[treble bass],
17
- },
18
- }.freeze
7
+ INSTRUMENTS = YAML.load_file(File.expand_path('data/instruments.yml', __dir__)).freeze
19
8
 
20
9
  def self.get(name)
21
- get_by_name(name)
10
+ return get_by_name(name) if get_by_name(name)
11
+ return get_by_name(key_for_name(name)) if key_for_name(name)
12
+
13
+ new(name)
14
+ end
15
+
16
+ def self.all
17
+ INSTRUMENTS.map { |key, _data| get(key) }.sort_by(&:name)
18
+ end
19
+
20
+ attr_reader :name_key, :family, :default_clefs, :classifications, :voice
21
+
22
+ def ==(other)
23
+ to_s == other.to_s
22
24
  end
23
25
 
26
+ def translation(locale = :en)
27
+ return name unless name_key
28
+
29
+ I18n.translate(name_key, scope: [:instruments], locale: locale)
30
+ end
31
+
32
+ private_class_method :new
33
+
34
+ private
35
+
24
36
  def initialize(name)
25
- @name = name.to_s
37
+ record = record_for_name(name)
38
+ if record
39
+ initialize_data_from_record(record)
40
+ else
41
+ self.name = name.to_s
42
+ end
26
43
  end
27
44
 
28
- def data
29
- @data ||= INSTRUMENTS[hash_key]
45
+ def record_for_name(name)
46
+ record_for_key(HeadMusic::Utilities::HashKey.for(name)) ||
47
+ record_for_key(key_for_name(name))
30
48
  end
31
49
 
32
- def family
33
- data[:family]
50
+ def key_for_name(name)
51
+ INSTRUMENTS.each do |key, _data|
52
+ I18n.config.available_locales.each do |locale|
53
+ translation = I18n.t("instruments.#{key}", locale: locale)
54
+ return key if translation.downcase == name.downcase
55
+ end
56
+ end
57
+ nil
34
58
  end
35
59
 
36
- def default_system
37
- data[:default_system]
60
+ def record_for_key(key)
61
+ INSTRUMENTS.each do |name_key, data|
62
+ return data.merge!('name_key' => name_key) if name_key.to_s == key.to_s
63
+ end
64
+ nil
38
65
  end
39
66
 
40
- def default_clef
41
- data[:default_clef]
67
+ def initialize_data_from_record(record)
68
+ @name_key = record['name_key'].to_sym
69
+ @family = record['family']
70
+ @default_clefs = record['default_clefs'] || []
71
+ @classifications = record['classifications'] || []
72
+ @voice = record['voice'].to_s
73
+ self.name = I18n.translate(name_key, scope: 'instruments', locale: 'en', default: inferred_name)
42
74
  end
43
75
 
44
- def ==(other)
45
- to_s == other.to_s
76
+ def inferred_name
77
+ name_key.to_s.gsub(/_/, ' ')
46
78
  end
47
79
  end
@@ -0,0 +1,63 @@
1
+ de:
2
+ rudiments:
3
+ clef: Notenschlüssel
4
+ consonance: Konsonanz
5
+ clefs:
6
+ alto_clef: Altschlüssel
7
+ baritone_c_clef: Baritonschlüssel
8
+ baritone_clef: Baritonschlüssel
9
+ baritone_f_clef: Baritonschlüssel
10
+ bass_clef: Bassschlüssel
11
+ c_clef: C-Schlüssel
12
+ choral_tenor_clef: oktavierten Violinschlüssel
13
+ contrabass_clef: contrabass clef
14
+ countertenor_clef: countertenor clef
15
+ double_treble_clef: double treble clef
16
+ drum_clef: Schlagzeugschlüssel
17
+ f_clef: F-Schlüssel
18
+ fifth_line_c_clef: fifth-line C-clef
19
+ fifth_line_f_clef: fifth-line F-clef
20
+ first_line_c_clef: Sopranschlüssel
21
+ first_line_g_clef: first-line G-clef
22
+ fourth_line_c_clef: fourth-line C-clef
23
+ fourth_line_f_clef: fourth-line F-clef
24
+ french_clef: French clef
25
+ french_violin_clef: French violin clef
26
+ g_clef: G-Schlüssel
27
+ indefinite_pitch_clef: indefinite pitch clef
28
+ mezzo_soprano_clef: Mezzosopranschlüssel
29
+ neutral_clef: Schlagzeugschlüssel
30
+ percussion_clef: Schlagzeugschlüssel
31
+ second_line_c_clef: second-line C-clef
32
+ second_line_g_clef: second-line G-clef
33
+ soprano_clef: Sopranschlüssel
34
+ sub_bass_clef: Subbassschlüssel
35
+ tenor_c_clef: Tenorschlüssel
36
+ tenor_clef: Tenorschlüssel
37
+ tenor_g_clef: tenor G-clef
38
+ third_line_c_clef: third-line C-clef
39
+ third_line_f_clef: third-line F-clef
40
+ treble_clef: Violinschlüssel
41
+ viola_clef: Bratschenschlüssel
42
+ violin_clef: Violinschlüssel
43
+ reference_pitches:
44
+ chamber_tone: Kammerton
45
+ choir_tone: Chorton
46
+ instruments:
47
+ accordian: Akkordeon
48
+ alto_flute: Altflöte
49
+ alto_voice: Alt
50
+ arpeggione: Arpeggione
51
+ bagpipe: Dudelsack
52
+ baritone_voice: Bariton
53
+ bass_voice: Bass
54
+ bass_clarinet: clarinette basse
55
+ fiddle: Geige
56
+ guitar: Gitarre
57
+ piano: Piano
58
+ viola: Bratsche
59
+ violin: Violine
60
+ instrument_voices:
61
+ alto: Alt
62
+ baritone: Bariton
63
+ bass: Bass
@@ -0,0 +1,198 @@
1
+ en:
2
+ rudiments:
3
+ chromatic_interval: chromatic interval
4
+ circle: circle
5
+ clef: clef
6
+ consonance: consonance
7
+ diatonic_interval: diatonic interval
8
+ grand_staff: grand staff
9
+ harmonic_interval: harmonic interval
10
+ instrument: instrument
11
+ interval_cycle: interval cycle
12
+ key_signature: key signature
13
+ letter_name: letter name
14
+ melodic_interval: melodic interval
15
+ meter: meter
16
+ motion: motion
17
+ musical_symbol: musical symbol
18
+ octave: octave
19
+ pitch: pitch
20
+ pitch_class: pitch class
21
+ pitch_class_set: pitch class set
22
+ pitch_set: pitch set
23
+ quality: quality
24
+ reference_pitch: reference pitch
25
+ rhythm: rhythm
26
+ rhythmic_unit: rhythmic unit
27
+ scale: scale
28
+ scale_degree: scale degree
29
+ scale_type: scale type
30
+ sign: sign
31
+ solmization: solmization
32
+ sonority: sonority
33
+ spelling: spelling
34
+ staff: staff
35
+ tuning: tuning
36
+ clefs:
37
+ alto_clef: alto clef
38
+ baritone_c_clef: baritone C-clef
39
+ baritone_clef: baritone clef
40
+ baritone_f_clef: baritone F-clef
41
+ bass_clef: bass clef
42
+ c_clef: C-clef
43
+ choral_tenor_clef: choral tenor clef
44
+ contrabass_clef: contrabass clef
45
+ countertenor_clef: countertenor clef
46
+ double_treble_clef: double treble clef
47
+ drum_clef: drum clef
48
+ f_clef: F-clef
49
+ fifth_line_c_clef: fifth-line C-clef
50
+ fifth_line_f_clef: fifth-line F-clef
51
+ first_line_c_clef: first-line C-clef
52
+ first_line_g_clef: first-line G-clef
53
+ fourth_line_c_clef: fourth-line C-clef
54
+ fourth_line_f_clef: fourth-line F-clef
55
+ french_clef: French clef
56
+ french_violin_clef: French violin clef
57
+ g_clef: G-clef
58
+ indefinite_pitch_clef: indefinite pitch clef
59
+ mezzo_soprano_clef: mezzo-soprano clef
60
+ neutral_clef: neutral clef
61
+ percussion_clef: percussion clef
62
+ second_line_c_clef: second-line C-clef
63
+ second_line_g_clef: second-line G-clef
64
+ soprano_clef: soprano clef
65
+ sub_bass_clef: sub-bass clef
66
+ tenor_c_clef: tenor C-clef
67
+ tenor_clef: tenor clef
68
+ tenor_g_clef: tenor G-clef
69
+ third_line_c_clef: third-line C-clef
70
+ third_line_f_clef: third-line F-clef
71
+ treble_clef: treble clef
72
+ viola_clef: viola clef
73
+ violin_clef: treble clef
74
+ reference_pitches:
75
+ a440: A440
76
+ baroque: Baroque pitch
77
+ berlin_philharmonic: Berlin Philharmonic
78
+ boston_symphony_orchestra: Boston Symphony Orchestra
79
+ chamber_tone: chamber tone
80
+ choir: choir tone
81
+ classical: classical pitch
82
+ concert: concert pitch
83
+ continental: continental pitch
84
+ french: French pitch
85
+ haydn: Haydn pitch
86
+ high: high pitch
87
+ international: international pitch
88
+ iso_16: ISO 16
89
+ low: low pitch
90
+ mozart: Mozart pitch
91
+ new_philharmonic: new philharmonic pitch
92
+ new_york_philharmonic: New York Philharmonic
93
+ old_philharmonic: old philharmonic pitch
94
+ philosophical: philosophical pitch
95
+ sauveur: Sauveur pitch
96
+ scheibler: Scheibler pitch
97
+ scientific: scientific pitch
98
+ stuttgart: Stuttgart pitch
99
+ sydney_symphony_orchestra: Sydney Symphony Orchestra
100
+ verdi: Verdi tuning
101
+ instruments:
102
+ accordian: accordian
103
+ alto_flute: alto flute
104
+ alto_voice: alto
105
+ arpeggione: arpeggione
106
+ bagpipe: bagpipe
107
+ baritone_voice: baritone
108
+ bass_clarinet: bass clarinet
109
+ bass_drum: bass drum
110
+ bass_guitar: bass guitar
111
+ bass_oboe: bass oboe
112
+ bass_trombone: bass trombone
113
+ bass_tuba: bass tuba
114
+ bass_voice: bass
115
+ bassoon: bassoon
116
+ castanets: castanets
117
+ cello: cello
118
+ chimes: chimes
119
+ clarinet: clarinet
120
+ clash_cymbals: clash cymbals
121
+ cornet: cornet
122
+ contrabassoon: contrabassoon
123
+ contra_bass_clarinet: contra bass clarinet
124
+ cor_anglais: cor anglais
125
+ cowbell: cowbell
126
+ cymbal: cymbal
127
+ crotales: crotales
128
+ double_bass: double bass
129
+ english_horn: English horn
130
+ euphonium: euphonium
131
+ flugel_horn: flugel horn
132
+ flute: flute
133
+ french_horn: French horn
134
+ glockenspiel: glockenspiel
135
+ guitar: guitar
136
+ harp: harp
137
+ harpsichord: harpsichord
138
+ mandolin: mandolin
139
+ maracas: maracas
140
+ marimba: marimba
141
+ metal_block: metal block
142
+ oboe: oboe
143
+ piano: piano
144
+ piccolo: piccolo
145
+ piccolo_trumpet: piccolo trumpet
146
+ side_drum: side drum
147
+ suspended_cymbal: suspended cymbal
148
+ synthesizer: synthesizer
149
+ tam_tam: tam-tam
150
+ tambourine: tambourine
151
+ temple_blocks: temple blocks
152
+ tenor_drum: tenor drum
153
+ tenor_trombone: tenor trombone
154
+ timpani: timpani
155
+ triangle: triangle
156
+ trumpet: trumpet
157
+ tuba: tuba
158
+ tubular_bells: tubular bells
159
+ vibraphone: vibraphone
160
+ viola: viola
161
+ violin: violin
162
+ woodblock: woodblock
163
+ xylophone: xylophone
164
+ instrument_abbreviations:
165
+ accordian:
166
+ - acc
167
+ alto_flute:
168
+ - afl
169
+ alto_voice:
170
+ - alt
171
+ bagpipe:
172
+ - bag
173
+ baritone_voice:
174
+ - bar
175
+ bass_voice:
176
+ - bass
177
+ bass_clarinet:
178
+ - bcl
179
+ instrument_classifications:
180
+ aerophone: aerophone
181
+ bowed: bowed
182
+ brass: brass
183
+ double_reed: double-reed
184
+ keyboard: keyboard
185
+ percussion: percussion
186
+ single_reed: single-reed
187
+ string: string
188
+ wind: wind
189
+ woodwind: woodwind
190
+ instrument_voices:
191
+ piccolo: piccolo
192
+ soprano: soprano
193
+ alto: alto
194
+ tenor: tenor
195
+ baritone: baritone
196
+ bass: bass
197
+ contrabass: contrabass
198
+ octobass: octobass
@@ -0,0 +1,3 @@
1
+ en_GB:
2
+ rudiments:
3
+ grand_staff: great staff
@@ -0,0 +1,53 @@
1
+ es:
2
+ rudiments:
3
+ clef: clave
4
+ consonance: consonancia
5
+ clefs:
6
+ alto_clef: clave contralto
7
+ baritone_c_clef: clave de barítono
8
+ baritone_clef: clave de barítono
9
+ baritone_f_clef: clave de fa en tercera
10
+ bass_clef: clave de bajo
11
+ c_clef: clave de do
12
+ choral_tenor_clef: choral tenor clef
13
+ contrabass_clef: clave de contrabajo
14
+ countertenor_clef: clave de contratenor
15
+ double_treble_clef: double clave de sol
16
+ drum_clef: clave para percusión
17
+ f_clef: clave de fa
18
+ fifth_line_c_clef: clave de do en quinta
19
+ fifth_line_f_clef: clave de fa en quinta
20
+ first_line_c_clef: clave de do en primera
21
+ first_line_g_clef: clave de sol en primera
22
+ fourth_line_c_clef: clave de do en cuarta
23
+ fourth_line_f_clef: clave de fa en cuarta
24
+ french_clef: clave de sol en primera
25
+ french_violin_clef: clave de sol en primera
26
+ g_clef: clave de sol
27
+ indefinite_pitch_clef: clave neutral
28
+ mezzo_soprano_clef: clave de mezzosoprano
29
+ neutral_clef: clave neutral
30
+ percussion_clef: clave para percusión
31
+ second_line_c_clef: clave de do en segunda
32
+ second_line_g_clef: clave de sol en segunda
33
+ soprano_clef: clave de soprano
34
+ sub_bass_clef: clave de fa en quinta
35
+ tenor_c_clef: clave de do en cuarta
36
+ tenor_clef: clave de tenor
37
+ tenor_g_clef: clave de sol en segunda
38
+ third_line_c_clef: clave de do en tercera
39
+ third_line_f_clef: clave de fa en tercera
40
+ treble_clef: clave de sol
41
+ viola_clef: clave de do
42
+ violin_clef: clave de sol
43
+ instruments:
44
+ accordian: acordeóon
45
+ alto_flute: flauta alto
46
+ alto_voice: contralto
47
+ bagpipe: gaita
48
+ baritone_voice: baritono
49
+ bass_voice: bajo
50
+ guitar: guitarra
51
+ piano: piano
52
+ viola: viola
53
+ violin: violín