head_music 0.23.1 → 0.24.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5df85a8374d61221a2217a55bc0766bbfde35a5040768353f8d006f53755acff
4
- data.tar.gz: 9d749a3a8def07c981019ba936a2718a2c3a89e661ab945437223e902df830f2
3
+ metadata.gz: 0abe4bcc9d5eda30350352723a69a500c1a072d08e39de64d9266a25953771fa
4
+ data.tar.gz: 25a2b86a64a5c4f31cb75c5de988c59cad7e0a271a78adcde5e3cc2f040b88ef
5
5
  SHA512:
6
- metadata.gz: 6e58ad0dd9dcb2358195aa47a59801eaae763a5c27926088318308b37c7b86ec0edc3cb0b14ffb314661209a4d7c652c5f8826c663c1f80f781e1933b3ac452a
7
- data.tar.gz: a9deabf2b150cb062a617c9439094d4328a8c5fb0b390d915b73205fe226b82f3b96fe57c4eb542f29c23c62484e2513e0a68366840ac677660b38991975dabc
6
+ metadata.gz: 670ca78b363ae669a73e4159b46e5465439824f1e051f15f8846acce3a6790352ac64b33cd41e82d6a602e3ef3582a6e224b9fd4da0fb5fbc85263c82d3e26c7
7
+ data.tar.gz: 1407f5414eb3842a61745c9943f50f14d866c1318d1a93d9c21ed296d57d5a61ba850f3c6b562c94ca20a9b23ada2098dc445af44184baed3969bfe3c29ab2bb
@@ -1,6 +1,9 @@
1
1
  Layout/DotPosition:
2
2
  EnforcedStyle: trailing
3
3
 
4
+ Layout/LineLength:
5
+ Max: 120
6
+
4
7
  Metrics/BlockLength:
5
8
  Exclude:
6
9
  - 'Gemfile'
@@ -10,15 +13,21 @@ Metrics/BlockLength:
10
13
  Metrics/ClassLength:
11
14
  Max: 155
12
15
 
13
- Metrics/LineLength:
14
- Max: 120
16
+ Style/ClassAndModuleChildren:
17
+ EnforcedStyle: compact
18
+
19
+ Style/HashEachMethods:
20
+ Enabled: false
21
+
22
+ Style/HashTransformKeys:
23
+ Enabled: false
24
+
25
+ Style/HashTransformValues:
26
+ Enabled: false
15
27
 
16
28
  Style/SymbolArray:
17
29
  Enabled: true
18
30
 
19
- Style/ClassAndModuleChildren:
20
- EnforcedStyle: compact
21
-
22
31
  Style/TrailingCommaInArrayLiteral:
23
32
  EnforcedStyleForMultiline: consistent_comma
24
33
 
@@ -26,7 +35,7 @@ Style/TrailingCommaInHashLiteral:
26
35
  EnforcedStyleForMultiline: consistent_comma
27
36
 
28
37
  AllCops:
29
- TargetRubyVersion: 2.6
38
+ TargetRubyVersion: 2.4
30
39
 
31
40
  Layout/EmptyLineAfterGuardClause:
32
41
  Enabled: false
data/Gemfile CHANGED
@@ -9,7 +9,7 @@ gemspec
9
9
 
10
10
  group :test do
11
11
  gem 'codeclimate-test-reporter', '~> 1.0.0'
12
- gem 'rubocop', '>= 0.56.0', require: false
12
+ gem 'rubocop', '>= 0.80.0', require: false
13
13
  gem 'rubocop-rspec', require: false
14
14
  gem 'simplecov'
15
15
  end
data/Rakefile CHANGED
@@ -9,5 +9,5 @@ task default: :spec
9
9
 
10
10
  desc 'Open an irb session preloaded with this library'
11
11
  task :console do
12
- sh 'irb -rubygems -I lib -r head_music.rb'
12
+ sh 'irb -I lib -r head_music.rb'
13
13
  end
@@ -24,11 +24,12 @@ Gem::Specification.new do |spec|
24
24
 
25
25
  spec.required_ruby_version = '>= 2.4.0'
26
26
 
27
- spec.add_runtime_dependency 'activesupport', '~> 5.0'
27
+ spec.add_runtime_dependency 'activesupport', '> 5.0'
28
28
  spec.add_runtime_dependency 'humanize', '~> 1.3'
29
+ spec.add_runtime_dependency 'i18n', '~> 1.8'
29
30
 
30
31
  spec.add_development_dependency 'bundler', '~> 1.13'
31
- spec.add_development_dependency 'rake', '~> 10.0'
32
+ spec.add_development_dependency 'rake', '>= 12.3.3'
32
33
  spec.add_development_dependency 'rspec', '~> 3.0'
33
34
  spec.add_development_dependency 'rspec-its', '~> 1.2'
34
35
  end
@@ -12,12 +12,25 @@ require 'head_music/version'
12
12
  require 'active_support/core_ext/module/delegation'
13
13
  require 'active_support/core_ext/string/access'
14
14
  require 'humanize'
15
+ require 'i18n'
16
+ require 'i18n/backend/fallbacks'
17
+
18
+ I18n::Backend::Simple.include I18n::Backend::Fallbacks
19
+ I18n.load_path << Dir[File.join(File.dirname(__dir__), 'lib', 'head_music', 'locales', '*.yml')]
20
+ I18n.config.available_locales = %i[en de fr it es en_US en_GB]
21
+ I18n.default_locale = :en
22
+ I18n.fallbacks[:de] = %i[de en_GB en]
23
+ I18n.fallbacks[:en_US] = %i[en_US en en_GB]
24
+ I18n.fallbacks[:en_GB] = %i[en_GB en en_US]
25
+ I18n.fallbacks[:es] = %i[es en]
26
+ I18n.fallbacks[:fr] = %i[fr en_GB en]
27
+ I18n.fallbacks[:it] = %i[it en_GB en]
15
28
 
16
29
  # utilities
17
30
  require 'head_music/utilities/hash_key'
18
31
 
19
32
  # modules
20
- require 'head_music/named_rudiment'
33
+ require 'head_music/named'
21
34
 
22
35
  # rudiments
23
36
  require 'head_music/chromatic_interval'
@@ -28,11 +41,13 @@ require 'head_music/diatonic_interval'
28
41
  require 'head_music/grand_staff'
29
42
  require 'head_music/harmonic_interval'
30
43
  require 'head_music/instrument'
44
+ require 'head_music/interval_cycle'
31
45
  require 'head_music/key_signature'
32
46
  require 'head_music/letter_name'
33
47
  require 'head_music/melodic_interval'
34
48
  require 'head_music/meter'
35
49
  require 'head_music/motion'
50
+ require 'head_music/musical_symbol'
36
51
  require 'head_music/octave'
37
52
  require 'head_music/pitch'
38
53
  require 'head_music/pitch/enharmonic_equivalence'
@@ -48,6 +63,7 @@ require 'head_music/scale'
48
63
  require 'head_music/scale_degree'
49
64
  require 'head_music/scale_type'
50
65
  require 'head_music/sign'
66
+ require 'head_music/solmization'
51
67
  require 'head_music/sonority'
52
68
  require 'head_music/spelling'
53
69
  require 'head_music/staff'
@@ -1,11 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # An interval is the distance between two pitches.
3
+ # A chromatic interval is the distance between two pitches measured in half-steps.
4
4
  class HeadMusic::ChromaticInterval
5
5
  include Comparable
6
6
 
7
7
  private_class_method :new
8
8
 
9
+ # TODO: include the Named module
9
10
  NAMES = %w[
10
11
  perfect_unison minor_second major_second minor_third major_third perfect_fourth tritone perfect_fifth
11
12
  minor_sixth major_sixth minor_seventh major_seventh perfect_octave
@@ -40,6 +41,10 @@ class HeadMusic::ChromaticInterval
40
41
  semitones
41
42
  end
42
43
 
44
+ def diatonic_name
45
+ NAMES[simple.semitones].gsub(/_/, ' ')
46
+ end
47
+
43
48
  # diatonic set theory
44
49
  alias specific_interval semitones
45
50
 
@@ -1,45 +1,54 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'head_music/interval_cycle'
4
+
3
5
  # A Circle of Fifths or Fourths shows relationships between pitch classes
4
- # TODO: Replace or empower with IntervalCycle (?)
5
- # https://en.wikipedia.org/wiki/Interval_cycle
6
- class HeadMusic::Circle
6
+ class HeadMusic::Circle < HeadMusic::IntervalCycle
7
7
  def self.of_fifths
8
- get(7)
8
+ get(:perfect_fifth)
9
9
  end
10
10
 
11
11
  def self.of_fourths
12
- get(5)
12
+ get(:perfect_fourth)
13
13
  end
14
14
 
15
- def self.get(interval = 7)
15
+ def self.get(interval = :perfect_fifth)
16
16
  @circles ||= {}
17
- @circles[interval.to_i] ||= new(interval)
17
+ diatonic_interval = HeadMusic::DiatonicInterval.get(interval)
18
+ @circles[interval] ||= new(interval: diatonic_interval, starting_pitch: 'C4')
18
19
  end
19
20
 
20
- attr_reader :interval, :pitch_classes
21
-
22
- def initialize(interval)
23
- @interval = interval.to_i
24
- @pitch_classes = pitch_classes_by_interval
21
+ def index(pitch_class)
22
+ pitch_classes.index(HeadMusic::Spelling.get(pitch_class).pitch_class)
25
23
  end
26
24
 
27
- def index(pitch_class)
28
- @pitch_classes.index(HeadMusic::Spelling.get(pitch_class).pitch_class)
25
+ alias spellings_up spellings
26
+
27
+ def key_signatures_up
28
+ spellings_up.map { |spelling| HeadMusic::KeySignature.new(spelling) }
29
29
  end
30
30
 
31
- private_class_method :new
31
+ def key_signatures_down
32
+ spellings_down.map { |spelling| HeadMusic::KeySignature.new(spelling) }
33
+ end
32
34
 
33
- private
35
+ def spellings_down
36
+ pitches_down.map(&:spelling)
37
+ end
34
38
 
35
- def pitch_classes_by_interval
36
- [HeadMusic::PitchClass.get(0)].tap do |list|
37
- loop do
38
- next_pitch_class = list.last + interval
39
- break if next_pitch_class == list.first
39
+ def pitches_down
40
+ @pitches_down ||= begin
41
+ [starting_pitch].tap do |list|
42
+ loop do
43
+ next_pitch = list.last - interval
44
+ next_pitch += octave while starting_pitch - next_pitch > 12
45
+ break if next_pitch.pitch_class == list.first.pitch_class
40
46
 
41
- list << next_pitch_class
47
+ list << next_pitch
48
+ end
42
49
  end
43
50
  end
44
51
  end
52
+
53
+ private_class_method :new
45
54
  end
@@ -1,39 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'yaml'
4
+
3
5
  # A clef assigns pitches to the lines and spaces of a staff.
4
6
  class HeadMusic::Clef
5
- include HeadMusic::NamedRudiment
6
-
7
- CLEFS = [
8
- { pitch: 'G4', line: 2, names: ['treble', 'G-clef'], modern: true },
9
- { pitch: 'G4', line: 1, names: ['French', 'French violin'] },
10
- { pitch: 'G3', line: 2, names: ['choral tenor', 'tenor', 'tenor G-clef'], modern: true },
11
-
12
- { pitch: 'F3', line: 3, names: ['baritone'] },
13
- { pitch: 'F3', line: 4, names: ['bass', 'F-clef'], modern: true },
14
- { pitch: 'F3', line: 5, names: ['sub-bass'] },
15
-
16
- { pitch: 'C4', line: 1, names: ['soprano'] },
17
- { pitch: 'C4', line: 2, names: ['mezzo-soprano'] },
18
- { pitch: 'C4', line: 3, names: ['alto', 'viola', 'counter-tenor', 'countertenor', 'C-clef'], modern: true },
19
- { pitch: 'C4', line: 4, names: ['tenor', 'tenor C-clef'], modern: true },
20
- { pitch: 'C4', line: 5, names: ['baritone', 'baritone C-clef'] },
7
+ include HeadMusic::Named
21
8
 
22
- { pitch: nil, line: 3, names: %w[neutral percussion] },
23
- ].freeze
9
+ RECORDS = YAML.load_file(File.expand_path('data/clefs.yml', __dir__)).freeze
24
10
 
25
11
  def self.get(name)
26
12
  get_by_name(name)
27
13
  end
28
14
 
29
- attr_reader :pitch, :line
15
+ attr_reader :pitch, :line, :musical_symbols
30
16
 
31
- def initialize(name)
32
- @name = name.to_s
33
- clef_data = CLEFS.detect { |clef| clef[:names].map(&:downcase).include?(name.downcase) }
34
- @pitch = HeadMusic::Pitch.get(clef_data[:pitch])
35
- @line = clef_data[:line]
36
- @modern = clef_data[:modern]
17
+ delegate :ascii, :html_entity, :unicode, to: :musical_symbol
18
+
19
+ def musical_symbol
20
+ musical_symbols.first
37
21
  end
38
22
 
39
23
  def clef_type
@@ -61,6 +45,59 @@ class HeadMusic::Clef
61
45
  end
62
46
 
63
47
  def ==(other)
64
- to_s == other.to_s
48
+ HeadMusic::Utilities::HashKey.for(self) == HeadMusic::Utilities::HashKey.for(other)
49
+ end
50
+
51
+ def name(locale_code: Locale::DEFAULT_CODE)
52
+ I18n.translate(name_key, scope: :clefs, locale: locale_code)
53
+ end
54
+
55
+ private_class_method :new
56
+
57
+ private
58
+
59
+ def initialize(name)
60
+ record = record_for_name(name)
61
+ initialize_data_from_record(record)
62
+ end
63
+
64
+ def record_for_name(name)
65
+ name = name.to_s.strip
66
+ key = HeadMusic::Utilities::HashKey.for(name)
67
+ RECORDS.detect do |record|
68
+ name_keys = name_keys_from_record(record)
69
+ name_keys.include?(key) || name_key_translations(name_keys).include?(name)
70
+ end
71
+ end
72
+
73
+ def name_keys_from_record(record)
74
+ ([record[:name_key]] + [record[:alias_name_keys]]).flatten.compact.uniq.map(&:to_sym)
75
+ end
76
+
77
+ def name_key_translations(name_keys)
78
+ name_keys.map do |name_key|
79
+ I18n.config.available_locales.map do |locale_code|
80
+ I18n.translate(name_key, scope: :clefs, locale: locale_code)
81
+ end.flatten.uniq.compact
82
+ end.flatten.uniq.compact
83
+ end
84
+
85
+ def initialize_data_from_record(record)
86
+ initialize_keys_from_record(record)
87
+ @pitch = HeadMusic::Pitch.get(record[:pitch])
88
+ @line = record[:line]
89
+ @modern = record[:modern]
90
+ initialize_musical_symbols(record[:symbols])
91
+ end
92
+
93
+ def initialize_keys_from_record(record)
94
+ @name_key = record[:name_key]
95
+ @alias_name_keys = [record[:alias_name_keys]].flatten.compact
96
+ end
97
+
98
+ def initialize_musical_symbols(list)
99
+ @musical_symbols = (list || []).map do |symbol_data|
100
+ HeadMusic::MusicalSymbol.new(symbol_data.slice(:ascii, :html_entity, :unicode))
101
+ end
65
102
  end
66
103
  end
@@ -0,0 +1,126 @@
1
+ ---
2
+ - :pitch: G4
3
+ :line: 2
4
+ :modern: true
5
+ :name_key: treble_clef
6
+ :alias_name_keys:
7
+ - g_clef
8
+ - second_line_g_clef
9
+ - violin_clef
10
+ :symbols:
11
+ - :unicode: "\U0001D11E"
12
+ :html_entity: "&#119070;"
13
+ - :pitch: G4
14
+ :line: 1
15
+ :name_key: french_violin_clef
16
+ :alias_name_keys:
17
+ - french_clef
18
+ - first_line_g_clef
19
+ :symbols:
20
+ - :unicode: "\U0001D11E"
21
+ :html_entity: "&#119070;"
22
+ - :pitch: G3
23
+ :line: 2
24
+ :modern: true
25
+ :name_key: choral_tenor_clef
26
+ :alias_name_keys:
27
+ - tenor_clef
28
+ - tenor_g_clef
29
+ :symbols:
30
+ - :unicode: "\U0001D120"
31
+ :html_entity: "&#119072;"
32
+ - :pitch: G3
33
+ :line: 2
34
+ :name_key: double_treble_clef
35
+ :symbols:
36
+ - :unicode: "\U0001D11E\U0001D11E"
37
+ :html_entity: "&#119070;&#119070;"
38
+ - :pitch: F3
39
+ :line: 3
40
+ :name_key: baritone_clef
41
+ :alias_name_keys:
42
+ - baritone_f_clef
43
+ - third_line_f_clef
44
+ :symbols:
45
+ - :unicode: "\U0001D122"
46
+ :html_entity: "&#119074;"
47
+ - :pitch: F3
48
+ :line: 4
49
+ :modern: true
50
+ :name_key: bass_clef
51
+ :alias_name_keys:
52
+ - f_clef
53
+ - fourth_line_f_clef
54
+ :symbols:
55
+ - :unicode: "\U0001D122"
56
+ :html_entity: "&#119074;"
57
+ - :pitch: F3
58
+ :line: 5
59
+ :name_key: sub_bass_clef
60
+ :alias_name_keys:
61
+ - contrabass_clef
62
+ - fifth_line_f_clef
63
+ :symbols:
64
+ - :unicode: "\U0001D122"
65
+ :html_entity: "&#119074;"
66
+ - :pitch: C4
67
+ :line: 1
68
+ :name_key: soprano_clef
69
+ :alias_name_keys:
70
+ - first_line_c_clef
71
+ :symbols:
72
+ - :unicode: "\U0001D121"
73
+ :html_entity: "&#119073;"
74
+ - :pitch: C4
75
+ :line: 2
76
+ :name_key: mezzo_soprano_clef
77
+ :alias_name_keys:
78
+ - second_line_c_clef
79
+ :symbols:
80
+ - :unicode: "\U0001D121"
81
+ :html_entity: "&#119073;"
82
+ - :pitch: C4
83
+ :line: 3
84
+ :modern: true
85
+ :name_key: alto_clef
86
+ :alias_name_keys:
87
+ - c_clef
88
+ - third_line_c_clef
89
+ - viola_clef
90
+ - countertenor_clef
91
+ :symbols:
92
+ - :unicode: "\U0001D121"
93
+ :html_entity: "&#119073;"
94
+ - :pitch: C4
95
+ :line: 4
96
+ :modern: true
97
+ :name_key: tenor_clef
98
+ :alias_name_keys:
99
+ - tenor_c_clef
100
+ - fourth_line_c_clef
101
+ :symbols:
102
+ - :unicode: "\U0001D121"
103
+ :html_entity: "&#119073;"
104
+ - :pitch: C4
105
+ :line: 5
106
+ :name_key: baritone_c_clef
107
+ :alias_name_keys:
108
+ - baritone_clef
109
+ - fifth_line_c_clef
110
+ :symbols:
111
+ - :unicode: "\U0001D121"
112
+ :html_entity: "&#119073;"
113
+ - :pitch:
114
+ :line: 3
115
+ :modern: true
116
+ :name_key: neutral_clef
117
+ :alias_name_keys:
118
+ - percussion_clef
119
+ - indefinite_pitch_clef
120
+ - rhythm_clef
121
+ - drum_clef
122
+ :symbols:
123
+ - :unicode: "\U0001D125"
124
+ :html_entity: "&#119077;"
125
+ - :unicode: "\U0001D126"
126
+ :html_entity: "&#119078;"