head_music 0.24.0 → 0.24.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/head_music.gemspec +2 -1
- data/lib/head_music.rb +14 -0
- data/lib/head_music/chromatic_interval.rb +1 -0
- data/lib/head_music/clef.rb +60 -77
- data/lib/head_music/data/clefs.yml +126 -0
- data/lib/head_music/data/instruments.yml +36 -0
- data/lib/head_music/diatonic_interval.rb +1 -0
- data/lib/head_music/grand_staff.rb +11 -6
- data/lib/head_music/instrument.rb +38 -25
- data/lib/head_music/locales/de.yml +63 -0
- data/lib/head_music/locales/en.yml +198 -0
- data/lib/head_music/locales/en_GB.yml +3 -0
- data/lib/head_music/locales/es.yml +53 -0
- data/lib/head_music/locales/fr.yml +57 -0
- data/lib/head_music/locales/it.yml +58 -0
- data/lib/head_music/named.rb +89 -22
- data/lib/head_music/reference_pitch.rb +104 -49
- data/lib/head_music/rhythmic_unit.rb +1 -1
- data/lib/head_music/scale_type.rb +1 -1
- data/lib/head_music/sign.rb +39 -14
- data/lib/head_music/solmization.rb +52 -0
- data/lib/head_music/solmizations.yml +20 -0
- data/lib/head_music/utilities/hash_key.rb +1 -1
- data/lib/head_music/version.rb +1 -1
- metadata +28 -4
@@ -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
|
-
{
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
{
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
{
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
{
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
{
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
{
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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 =
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
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
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
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
|
data/lib/head_music/sign.rb
CHANGED
@@ -6,22 +6,37 @@ require 'head_music/musical_symbol'
|
|
6
6
|
class HeadMusic::Sign
|
7
7
|
include Comparable
|
8
8
|
|
9
|
-
attr_reader :identifier, :cents, :
|
9
|
+
attr_reader :identifier, :cents, :musical_symbols
|
10
10
|
|
11
11
|
delegate :ascii, :unicode, :html_entity, to: :musical_symbol
|
12
12
|
|
13
|
-
|
14
|
-
{
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
{
|
13
|
+
SIGN_RECORDS = [
|
14
|
+
{
|
15
|
+
identifier: :sharp, cents: 100,
|
16
|
+
symbols: [{ ascii: '#', unicode: '♯', html_entity: '♯' }],
|
17
|
+
},
|
18
|
+
{
|
19
|
+
identifier: :flat, cents: -100,
|
20
|
+
symbols: [{ ascii: 'b', unicode: '♭', html_entity: '♭' }],
|
21
|
+
},
|
22
|
+
{
|
23
|
+
identifier: :natural, cents: 0,
|
24
|
+
symbols: [{ ascii: '', unicode: '♮', html_entity: '♮' }],
|
25
|
+
},
|
26
|
+
{
|
27
|
+
identifier: :double_sharp, cents: 200,
|
28
|
+
symbols: [{ ascii: 'x', unicode: '𝄪', html_entity: '𝄪' }],
|
29
|
+
},
|
30
|
+
{
|
31
|
+
identifier: :double_flat, cents: -200,
|
32
|
+
symbols: [{ ascii: 'bb', unicode: '𝄫', html_entity: '𝄫' }],
|
33
|
+
},
|
19
34
|
].freeze
|
20
35
|
|
21
|
-
SIGN_IDENTIFIERS =
|
36
|
+
SIGN_IDENTIFIERS = SIGN_RECORDS.map { |attributes| attributes[:identifier] }.freeze
|
22
37
|
|
23
38
|
def self.all
|
24
|
-
|
39
|
+
SIGN_RECORDS.map { |attributes| new(attributes) }
|
25
40
|
end
|
26
41
|
|
27
42
|
def self.symbols
|
@@ -76,16 +91,26 @@ class HeadMusic::Sign
|
|
76
91
|
cents <=> other.cents
|
77
92
|
end
|
78
93
|
|
94
|
+
def musical_symbol
|
95
|
+
musical_symbols.first
|
96
|
+
end
|
97
|
+
|
79
98
|
private
|
80
99
|
|
81
100
|
def initialize(attributes)
|
82
101
|
@identifier = attributes[:identifier]
|
83
102
|
@cents = attributes[:cents]
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
)
|
103
|
+
initialize_musical_symbols(attributes[:symbols])
|
104
|
+
end
|
105
|
+
|
106
|
+
def initialize_musical_symbols(list)
|
107
|
+
@musical_symbols = (list || []).map do |record|
|
108
|
+
HeadMusic::MusicalSymbol.new(
|
109
|
+
unicode: record[:unicode],
|
110
|
+
ascii: record[:ascii],
|
111
|
+
html_entity: record[:html_entity]
|
112
|
+
)
|
113
|
+
end
|
89
114
|
end
|
90
115
|
|
91
116
|
private_class_method :new
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# A scale degree is a number indicating the ordinality of the spelling in the key signature.
|
4
|
+
# TODO: Rewrite to accept a tonal_center and a scale type.
|
5
|
+
class HeadMusic::Solmization
|
6
|
+
include HeadMusic::Named
|
7
|
+
|
8
|
+
DEFAULT_SOLMIZATION = 'solfège'
|
9
|
+
|
10
|
+
RECORDS = YAML.load_file(File.expand_path('solmizations.yml', __dir__)).freeze
|
11
|
+
|
12
|
+
attr_reader :syllables
|
13
|
+
|
14
|
+
def self.get(identifier = nil)
|
15
|
+
get_by_name(identifier)
|
16
|
+
end
|
17
|
+
|
18
|
+
private_class_method :new
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def initialize(name = nil)
|
23
|
+
name = nil if name.empty?
|
24
|
+
name ||= DEFAULT_SOLMIZATION
|
25
|
+
record = record_for_name(name)
|
26
|
+
if record
|
27
|
+
initialize_data_from_record(record)
|
28
|
+
else
|
29
|
+
self.name = name
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def record_for_name(name)
|
34
|
+
key = HeadMusic::Utilities::HashKey.for(name)
|
35
|
+
RECORDS.detect do |record|
|
36
|
+
name_strings = record[:localized_names].map { |localized_name| localized_name[:name] }
|
37
|
+
name_keys = name_strings.map { |name_string| HeadMusic::Utilities::HashKey.for(name_string) }
|
38
|
+
name_keys.include?(key)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def initialize_data_from_record(record)
|
43
|
+
@syllables = record[:syllables]
|
44
|
+
initialize_localized_names(record[:localized_names])
|
45
|
+
end
|
46
|
+
|
47
|
+
def initialize_localized_names(list)
|
48
|
+
@localized_names = (list || []).map do |name_attributes|
|
49
|
+
HeadMusic::Named::LocalizedName.new(name_attributes.slice(:name, :locale_code, :abbreviation))
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
---
|
2
|
+
- :syllables:
|
3
|
+
- do
|
4
|
+
- re
|
5
|
+
- mi
|
6
|
+
- fa
|
7
|
+
- sol
|
8
|
+
- la
|
9
|
+
- ti
|
10
|
+
:localized_names:
|
11
|
+
- :name: solfège
|
12
|
+
- :name: solfège
|
13
|
+
:locale_code: en
|
14
|
+
- :name: solfège
|
15
|
+
:locale_code: fr
|
16
|
+
- :name: solfeggio
|
17
|
+
:locale_code: it
|
18
|
+
- :name: sol-fa
|
19
|
+
- :name: solfa
|
20
|
+
- :name: solfeo
|
@@ -6,6 +6,6 @@ module HeadMusic::Utilities; end
|
|
6
6
|
# Util for converting an object to a consistent hash key
|
7
7
|
module HeadMusic::Utilities::HashKey
|
8
8
|
def self.for(identifier)
|
9
|
-
identifier.to_s.downcase.gsub(/\W+/, '_').to_sym
|
9
|
+
I18n.transliterate(identifier.to_s).downcase.gsub(/\W+/, '_').to_sym
|
10
10
|
end
|
11
11
|
end
|
data/lib/head_music/version.rb
CHANGED
metadata
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: head_music
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.24.
|
4
|
+
version: 0.24.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob Head
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '5.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '5.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: i18n
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.8'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.8'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: bundler
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -131,6 +145,8 @@ files:
|
|
131
145
|
- lib/head_music/content/position.rb
|
132
146
|
- lib/head_music/content/rhythmic_value.rb
|
133
147
|
- lib/head_music/content/voice.rb
|
148
|
+
- lib/head_music/data/clefs.yml
|
149
|
+
- lib/head_music/data/instruments.yml
|
134
150
|
- lib/head_music/diatonic_interval.rb
|
135
151
|
- lib/head_music/grand_staff.rb
|
136
152
|
- lib/head_music/harmonic_interval.rb
|
@@ -138,6 +154,12 @@ files:
|
|
138
154
|
- lib/head_music/interval_cycle.rb
|
139
155
|
- lib/head_music/key_signature.rb
|
140
156
|
- lib/head_music/letter_name.rb
|
157
|
+
- lib/head_music/locales/de.yml
|
158
|
+
- lib/head_music/locales/en.yml
|
159
|
+
- lib/head_music/locales/en_GB.yml
|
160
|
+
- lib/head_music/locales/es.yml
|
161
|
+
- lib/head_music/locales/fr.yml
|
162
|
+
- lib/head_music/locales/it.yml
|
141
163
|
- lib/head_music/melodic_interval.rb
|
142
164
|
- lib/head_music/meter.rb
|
143
165
|
- lib/head_music/motion.rb
|
@@ -158,6 +180,8 @@ files:
|
|
158
180
|
- lib/head_music/scale_degree.rb
|
159
181
|
- lib/head_music/scale_type.rb
|
160
182
|
- lib/head_music/sign.rb
|
183
|
+
- lib/head_music/solmization.rb
|
184
|
+
- lib/head_music/solmizations.yml
|
161
185
|
- lib/head_music/sonority.rb
|
162
186
|
- lib/head_music/spelling.rb
|
163
187
|
- lib/head_music/staff.rb
|