head_music 0.26.2 → 0.26.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/head_music.rb +1 -1
- data/lib/head_music/diatonic_interval.rb +1 -1
- data/lib/head_music/pitch.rb +14 -15
- data/lib/head_music/pitch/octave_equivalence.rb +1 -1
- data/lib/head_music/pitch_set.rb +1 -1
- data/lib/head_music/{octave.rb → register.rb} +12 -8
- data/lib/head_music/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3224075c2e9f76d778cdbd71942f5bf1496b25c52c56062169824fc3e916f947
|
4
|
+
data.tar.gz: e272fa27e163ca5ea97ceaed10f9098cb196f2ceb45008a89da7837452df6c6e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f007ea93b150e2a2f140fadb68d73c978e9ea1481dc0e7590c99f97b5b0fabb9be935adca85b92c86d48179b751aa745fcb81cfa194c7df3d2d0f4ae8282d60f
|
7
|
+
data.tar.gz: 3176231f3a293e9b482fcd7a6708159ca76ed73e8efbec6947fe5779d42fc97cb7850ec07be2d2ae5460bb0e8b88b7b70576e839c59d070707b2a7bbf7f491f0
|
data/lib/head_music.rb
CHANGED
@@ -49,7 +49,6 @@ require 'head_music/melodic_interval'
|
|
49
49
|
require 'head_music/meter'
|
50
50
|
require 'head_music/motion'
|
51
51
|
require 'head_music/musical_symbol'
|
52
|
-
require 'head_music/octave'
|
53
52
|
require 'head_music/pitch'
|
54
53
|
require 'head_music/pitch/enharmonic_equivalence'
|
55
54
|
require 'head_music/pitch/octave_equivalence'
|
@@ -58,6 +57,7 @@ require 'head_music/pitch_class_set'
|
|
58
57
|
require 'head_music/pitch_set'
|
59
58
|
require 'head_music/quality'
|
60
59
|
require 'head_music/reference_pitch'
|
60
|
+
require 'head_music/register'
|
61
61
|
require 'head_music/rhythm'
|
62
62
|
require 'head_music/rhythmic_unit'
|
63
63
|
require 'head_music/scale'
|
@@ -304,7 +304,7 @@ class HeadMusic::DiatonicInterval
|
|
304
304
|
def inversion
|
305
305
|
inverted_low_pitch = lower_pitch
|
306
306
|
while inverted_low_pitch < higher_pitch
|
307
|
-
inverted_low_pitch = HeadMusic::Pitch.fetch_or_create(lower_pitch.spelling, inverted_low_pitch.
|
307
|
+
inverted_low_pitch = HeadMusic::Pitch.fetch_or_create(lower_pitch.spelling, inverted_low_pitch.register + 1)
|
308
308
|
end
|
309
309
|
HeadMusic::DiatonicInterval.new(higher_pitch, inverted_low_pitch)
|
310
310
|
end
|
data/lib/head_music/pitch.rb
CHANGED
@@ -4,8 +4,7 @@
|
|
4
4
|
class HeadMusic::Pitch
|
5
5
|
include Comparable
|
6
6
|
|
7
|
-
attr_reader :spelling
|
8
|
-
attr_reader :octave
|
7
|
+
attr_reader :spelling, :register
|
9
8
|
|
10
9
|
delegate :letter_name, to: :spelling
|
11
10
|
delegate :series_ascending, :series_descending, to: :letter_name, prefix: true
|
@@ -51,7 +50,7 @@ class HeadMusic::Pitch
|
|
51
50
|
def self.from_name(name)
|
52
51
|
return nil unless name == name.to_s
|
53
52
|
|
54
|
-
fetch_or_create(HeadMusic::Spelling.get(name), HeadMusic::
|
53
|
+
fetch_or_create(HeadMusic::Spelling.get(name), HeadMusic::Register.get(name).to_i)
|
55
54
|
end
|
56
55
|
|
57
56
|
def self.from_number(number)
|
@@ -66,7 +65,7 @@ class HeadMusic::Pitch
|
|
66
65
|
sign_interval = natural_letter_pitch.smallest_interval_to(HeadMusic::PitchClass.get(number))
|
67
66
|
sign = HeadMusic::Sign.by(:semitones, sign_interval) if sign_interval != 0
|
68
67
|
spelling = HeadMusic::Spelling.fetch_or_create(letter_name, sign)
|
69
|
-
fetch_or_create(spelling, natural_letter_pitch.
|
68
|
+
fetch_or_create(spelling, natural_letter_pitch.register)
|
70
69
|
end
|
71
70
|
|
72
71
|
def self.natural_letter_pitch(number, letter_name)
|
@@ -76,26 +75,26 @@ class HeadMusic::Pitch
|
|
76
75
|
get(natural_letter_pitch)
|
77
76
|
end
|
78
77
|
|
79
|
-
def self.fetch_or_create(spelling,
|
80
|
-
|
81
|
-
return unless spelling && (-1..9).cover?(
|
78
|
+
def self.fetch_or_create(spelling, register = nil)
|
79
|
+
register ||= HeadMusic::Register::DEFAULT
|
80
|
+
return unless spelling && (-1..9).cover?(register)
|
82
81
|
|
83
82
|
@pitches ||= {}
|
84
|
-
hash_key = [spelling,
|
85
|
-
@pitches[hash_key] ||= new(spelling,
|
83
|
+
hash_key = [spelling, register].join
|
84
|
+
@pitches[hash_key] ||= new(spelling, register)
|
86
85
|
end
|
87
86
|
|
88
|
-
def initialize(spelling,
|
87
|
+
def initialize(spelling, register)
|
89
88
|
@spelling = HeadMusic::Spelling.get(spelling.to_s)
|
90
|
-
@
|
89
|
+
@register = register.to_i
|
91
90
|
end
|
92
91
|
|
93
92
|
def name
|
94
|
-
[spelling,
|
93
|
+
[spelling, register].join
|
95
94
|
end
|
96
95
|
|
97
96
|
def midi_note_number
|
98
|
-
(
|
97
|
+
(register + 1) * 12 + letter_name.pitch_class.to_i + sign_semitones.to_i
|
99
98
|
end
|
100
99
|
|
101
100
|
alias midi midi_note_number
|
@@ -150,7 +149,7 @@ class HeadMusic::Pitch
|
|
150
149
|
end
|
151
150
|
|
152
151
|
def natural_steps(num_steps)
|
153
|
-
HeadMusic::Pitch.get([target_letter_name(num_steps),
|
152
|
+
HeadMusic::Pitch.get([target_letter_name(num_steps), register + octaves_delta(num_steps)].join)
|
154
153
|
end
|
155
154
|
|
156
155
|
def frequency
|
@@ -167,7 +166,7 @@ class HeadMusic::Pitch
|
|
167
166
|
private
|
168
167
|
|
169
168
|
def octave_changes_to(other)
|
170
|
-
other.
|
169
|
+
other.register - register - octave_adjustment_to(other)
|
171
170
|
end
|
172
171
|
|
173
172
|
def octave_adjustment_to(other)
|
@@ -15,7 +15,7 @@ class HeadMusic::Pitch::OctaveEquivalence
|
|
15
15
|
|
16
16
|
def octave_equivalent?(other)
|
17
17
|
other = HeadMusic::Pitch.get(other)
|
18
|
-
pitch.spelling == other.spelling && pitch.
|
18
|
+
pitch.spelling == other.spelling && pitch.register != other.register
|
19
19
|
end
|
20
20
|
|
21
21
|
alias equivalent? octave_equivalent?
|
data/lib/head_music/pitch_set.rb
CHANGED
@@ -187,7 +187,7 @@ class HeadMusic::PitchSet
|
|
187
187
|
|
188
188
|
def reduction_pitches
|
189
189
|
pitches.map do |pitch|
|
190
|
-
pitch = HeadMusic::Pitch.fetch_or_create(pitch.spelling, pitch.
|
190
|
+
pitch = HeadMusic::Pitch.fetch_or_create(pitch.spelling, pitch.register - 1) while pitch > bass_pitch + 12
|
191
191
|
pitch
|
192
192
|
end.sort
|
193
193
|
end
|
@@ -1,7 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# The
|
4
|
-
|
3
|
+
# The register is a numeric octave identifier used in scientific pitch notation.
|
4
|
+
#
|
5
|
+
# A pitch is a spelling plus a register. For example, C4 is middle C and C5 is the C one octave higher.
|
6
|
+
# The number changes between the letter names B and C regardless of sharps and flats,
|
7
|
+
# so as an extreme example, Cb5 is actually a semitone below B#4.
|
8
|
+
class HeadMusic::Register
|
5
9
|
include Comparable
|
6
10
|
|
7
11
|
DEFAULT = 4
|
@@ -14,20 +18,20 @@ class HeadMusic::Octave
|
|
14
18
|
return nil unless identifier.to_s == identifier.to_i.to_s
|
15
19
|
return nil unless (-2..12).cover?(identifier.to_i)
|
16
20
|
|
17
|
-
@
|
18
|
-
@
|
21
|
+
@registers ||= {}
|
22
|
+
@registers[identifier.to_i] ||= new(identifier.to_i)
|
19
23
|
end
|
20
24
|
|
21
25
|
def self.from_name(string)
|
22
26
|
return unless string.to_s.match?(HeadMusic::Spelling::MATCHER)
|
23
27
|
|
24
|
-
_letter, _sign,
|
25
|
-
@
|
26
|
-
@
|
28
|
+
_letter, _sign, register_string = string.to_s.match(HeadMusic::Spelling::MATCHER).captures
|
29
|
+
@registers ||= {}
|
30
|
+
@registers[register_string.to_i] ||= new(register_string.to_i) if register_string
|
27
31
|
end
|
28
32
|
|
29
33
|
def self.default
|
30
|
-
@
|
34
|
+
@registers[DEFAULT] ||= new(DEFAULT)
|
31
35
|
end
|
32
36
|
|
33
37
|
attr_reader :number
|
data/lib/head_music/version.rb
CHANGED
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: 0.26.
|
4
|
+
version: 0.26.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob Head
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -166,7 +166,6 @@ files:
|
|
166
166
|
- lib/head_music/motion.rb
|
167
167
|
- lib/head_music/musical_symbol.rb
|
168
168
|
- lib/head_music/named.rb
|
169
|
-
- lib/head_music/octave.rb
|
170
169
|
- lib/head_music/pitch.rb
|
171
170
|
- lib/head_music/pitch/enharmonic_equivalence.rb
|
172
171
|
- lib/head_music/pitch/octave_equivalence.rb
|
@@ -175,6 +174,7 @@ files:
|
|
175
174
|
- lib/head_music/pitch_set.rb
|
176
175
|
- lib/head_music/quality.rb
|
177
176
|
- lib/head_music/reference_pitch.rb
|
177
|
+
- lib/head_music/register.rb
|
178
178
|
- lib/head_music/rhythm.rb
|
179
179
|
- lib/head_music/rhythmic_unit.rb
|
180
180
|
- lib/head_music/scale.rb
|