head_music 6.0.0 → 6.0.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: ee7c3b6377d30fa88d3f9e7f5b5450bf0664c65b4559ba6fccaf79d19ef3cfcf
4
- data.tar.gz: 56ec218fb604b9c1c2fe3a6c2935a1157340afc0a23f3cb882ad9dd9980f1bcd
3
+ metadata.gz: 64230af5264efb58e93a127cc3ad7528f9fd33f663b98ba117bb49d746e500ce
4
+ data.tar.gz: c6c72eb473869b2aa01dc80f37d54787dda8816f0ac46404d365ee30431f6eab
5
5
  SHA512:
6
- metadata.gz: 6c8b2afd59aae59bcd88a8d67aa1662e79d6086166da1588bdf502a720fb471b2c55b3b6ada13eb7f09e998cd8b8c8408ec4888303d0edd9cdf09accc64c92ed
7
- data.tar.gz: 4076e9b2b22c369f6f7e08bd202cf333d54c410df206bcc0d06417a68142be232ef58fe174aae627922e5a5ef993a9f247e706d23c17cce0f927b49198f3b987
6
+ metadata.gz: c049302d49e156b572c3dc0aeb8b9cf59db93ec77ca0e0636c4a64375e4c5648a886ec21ec3e63077981c938317841989df0825c153848aef45b16b13117df2a
7
+ data.tar.gz: 4dddb70eeb88d7ae04f4184365c791d650731524c2d35c6a300b22227bc24fba921c9efa3d6fa9a0212a7a4f43e2680a0c0cdfbbcc580b11ea17bc9e39ebc4be
data/.rubocop.yml CHANGED
@@ -26,4 +26,4 @@ RSpec/ContextWording:
26
26
  - by
27
27
 
28
28
  RSpec/NestedGroups:
29
- Max: 4
29
+ Max: 5
@@ -105,7 +105,9 @@ class HeadMusic::Content::Voice
105
105
  end
106
106
 
107
107
  def to_s
108
- "#{role}: #{pitches.first(10).map(&:to_s)}"
108
+ return pitches_string if role.to_s.strip == ""
109
+
110
+ [role, pitches_string].join(": ")
109
111
  end
110
112
 
111
113
  private
@@ -114,4 +116,8 @@ class HeadMusic::Content::Voice
114
116
  @placements << placement
115
117
  @placements = @placements.sort
116
118
  end
119
+
120
+ def pitches_string
121
+ pitches.first(10).map(&:to_s).join(" ")
122
+ end
117
123
  end
@@ -21,7 +21,7 @@ class HeadMusic::Instrument::Staff
21
21
  end
22
22
 
23
23
  def name_key
24
- attributes["name_key"]
24
+ attributes["name_key"] || ""
25
25
  end
26
26
 
27
27
  def name
@@ -0,0 +1,30 @@
1
+ # Key signatures are enharmonic when all pitch classes in one are respellings of the pitch classes in the other.
2
+ class HeadMusic::KeySignature::EnharmonicEquivalence
3
+ attr_reader :key_signature
4
+
5
+ def self.get(key_signature)
6
+ key_signature = HeadMusic::KeySignature.get(key_signature)
7
+ @enharmonic_equivalences ||= {}
8
+ @enharmonic_equivalences[key_signature.to_s] ||= new(key_signature)
9
+ end
10
+
11
+ def initialize(key_signature)
12
+ @key_signature = HeadMusic::KeySignature.get(key_signature)
13
+ end
14
+
15
+ def enharmonic_equivalent?(other)
16
+ other = HeadMusic::KeySignature.get(other)
17
+
18
+ p key_signature.pitch_classes.map(&:to_i).sort
19
+ p other.pitch_classes.map(&:to_i).sort
20
+ p key_signature.alterations.map(&:to_s).sort
21
+ p other.alterations.map(&:to_s).sort
22
+ key_signature.pitch_classes.map(&:to_i).sort == other.pitch_classes.map(&:to_i).sort &&
23
+ key_signature.alterations.map(&:to_s).sort != other.alterations.map(&:to_s).sort
24
+ end
25
+
26
+ # alias_method :enharmonic?, :enharmonic_equivalent?
27
+ # alias_method :equivalent?, :enharmonic_equivalent?
28
+
29
+ private_class_method :new
30
+ end
@@ -21,7 +21,7 @@ class HeadMusic::KeySignature
21
21
 
22
22
  delegate :pitch_class, to: :tonic_spelling, prefix: :tonic
23
23
  delegate :to_s, to: :name
24
- delegate :pitches, to: :scale
24
+ delegate :pitches, :pitch_classes, to: :scale
25
25
 
26
26
  def initialize(tonic_spelling, scale_type = nil)
27
27
  @tonic_spelling = HeadMusic::Spelling.get(tonic_spelling)
@@ -67,19 +67,23 @@ class HeadMusic::KeySignature
67
67
  flats.length + double_flats.length * 2
68
68
  end
69
69
 
70
- def signs
71
- flats.any? ? flats : sharps
70
+ def num_alterations
71
+ num_sharps + num_flats
72
72
  end
73
73
 
74
- alias_method :sharps_and_flats, :signs
75
- alias_method :accidentals, :signs
74
+ def alterations
75
+ flats.any? ? (double_flats + flats) : (double_sharps + sharps)
76
+ end
77
+
78
+ alias_method :sharps_and_flats, :alterations
79
+ alias_method :accidentals, :alterations
76
80
 
77
81
  def name
78
82
  [tonic_spelling, scale_type].join(" ")
79
83
  end
80
84
 
81
85
  def ==(other)
82
- signs == self.class.get(other).signs
86
+ alterations == self.class.get(other).alterations
83
87
  end
84
88
 
85
89
  def to_s
@@ -93,38 +97,12 @@ class HeadMusic::KeySignature
93
97
  end
94
98
 
95
99
  def enharmonic_equivalent?(other)
96
- other = KeySignature.get(other)
97
- enharmonic_equivalence.equivalent?(other)
100
+ enharmonic_equivalence.enharmonic_equivalent?(other)
98
101
  end
99
102
 
100
103
  private
101
104
 
102
105
  def enharmonic_equivalence
103
- @enharmonic_equivalence ||= EnharmonicEquivalence.get(self)
104
- end
105
-
106
- # Key signatures are enharmonic when all pitch classes in one are respellings of the pitch classes in the other.
107
- class EnharmonicEquivalence
108
- def self.get(key_signature)
109
- key_signature = HeadMusic::KeySignature.get(key_signature)
110
- @enharmonic_equivalences ||= {}
111
- @enharmonic_equivalences[key_signature.to_s] ||= new(key_signature)
112
- end
113
-
114
- attr_reader :key_signature
115
-
116
- def initialize(key_signature)
117
- @key_signature = HeadMusic::KeySignature.get(key_signature)
118
- end
119
-
120
- def enharmonic_equivalent?(other)
121
- other = HeadMusic::KeySignature.get(other)
122
- (key_signature.signs | other.signs).map(&:to_s).uniq.length == 12
123
- end
124
-
125
- alias_method :enharmonic?, :enharmonic_equivalent?
126
- alias_method :equivalent?, :enharmonic_equivalent?
127
-
128
- private_class_method :new
106
+ @enharmonic_equivalence ||= HeadMusic::KeySignature::EnharmonicEquivalence.get(self)
129
107
  end
130
108
  end
@@ -48,7 +48,9 @@ class HeadMusic::Motion
48
48
  end
49
49
 
50
50
  def to_s
51
- "#{contrapuntal_motion} motion from #{first_harmonic_interval} to #{second_harmonic_interval}"
51
+ return "repetition of a #{second_harmonic_interval}" unless contrapuntal_motion != :repetition
52
+
53
+ "#{contrapuntal_motion} motion from a #{first_harmonic_interval} to a #{second_harmonic_interval}"
52
54
  end
53
55
 
54
56
  private
@@ -10,13 +10,10 @@ class HeadMusic::PitchClassSet
10
10
  @pitch_classes = identifiers.map { |identifier| HeadMusic::PitchClass.get(identifier) }.uniq.sort
11
11
  end
12
12
 
13
- def inspect
14
- pitch_classes.map(&:to_s).join(" ")
15
- end
16
-
17
13
  def to_s
18
- pitch_classes.map(&:to_s).join(" ")
14
+ pitch_classes.map(&:to_i).inspect
19
15
  end
16
+ alias_method :inspect, :to_s
20
17
 
21
18
  def ==(other)
22
19
  pitch_classes == other.pitch_classes
@@ -28,6 +28,10 @@ class HeadMusic::Scale
28
28
  @pitches[direction][octaves] ||= determine_scale_pitches(direction, octaves)
29
29
  end
30
30
 
31
+ def pitch_classes
32
+ pitches.map(&:pitch_class).uniq
33
+ end
34
+
31
35
  def spellings(direction: :ascending, octaves: 1)
32
36
  pitches(direction: direction, octaves: octaves).map(&:spelling).map(&:to_s)
33
37
  end
@@ -1,3 +1,3 @@
1
1
  module HeadMusic
2
- VERSION = "6.0.0"
2
+ VERSION = "6.0.1"
3
3
  end
data/lib/head_music.rb CHANGED
@@ -46,6 +46,7 @@ require "head_music/instrument/staff_scheme"
46
46
  require "head_music/instrument/staff"
47
47
  require "head_music/interval_cycle"
48
48
  require "head_music/key_signature"
49
+ require "head_music/key_signature/enharmonic_equivalence"
49
50
  require "head_music/letter_name"
50
51
  require "head_music/melodic_interval"
51
52
  require "head_music/meter"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: head_music
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.0
4
+ version: 6.0.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: 2023-12-29 00:00:00.000000000 Z
11
+ date: 2023-12-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -144,6 +144,7 @@ files:
144
144
  - lib/head_music/instrument_family.rb
145
145
  - lib/head_music/interval_cycle.rb
146
146
  - lib/head_music/key_signature.rb
147
+ - lib/head_music/key_signature/enharmonic_equivalence.rb
147
148
  - lib/head_music/letter_name.rb
148
149
  - lib/head_music/locales/de.yml
149
150
  - lib/head_music/locales/en.yml