head_music 0.5.1 → 0.5.2

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
  SHA1:
3
- metadata.gz: 27bbe45d50118d4f5f4bcf02e3192da3ddd2ec70
4
- data.tar.gz: 1900eb67572a4bfb79e0b91c05673bfadd1f7c2c
3
+ metadata.gz: 208eb249d8215ed60a1047fa2ce44d615da37cf3
4
+ data.tar.gz: 9e02bbfcd8df9e1ca07dc737b594063831caf7f3
5
5
  SHA512:
6
- metadata.gz: 30f5b988d501ca3286bc41da70c3ca3672d9d30438d81a5740c1c8db4bd1d4e3e9af594302aa928afea446c2d6197f1b3aa0d69280c1e94fc986e03359712872
7
- data.tar.gz: d5534e5c7dadf6b7339d29b4db89256cf2d853b5415add44032c15eb24f1e10a83bb0d185d4437ef319a29f7c003f0b90228e3cce19bcfe22d5d73646255f561
6
+ metadata.gz: a76df5d52cfc41df45d538da2fb0b4443d64bd65f4713e412e611082853906495881c26631799bad5c1fd160eea7355baa6c3c8911ad4151f8c719f61866900a
7
+ data.tar.gz: 3153be5ac2b260d3ef0c9035d2e2772ba35d0871f831878eba88313365a843a08e24a4bb6ce59d1bc2fc661c388e317efdb7a2fc3ff92c76eed6db45b5165a3b
@@ -0,0 +1,20 @@
1
+ class HeadMusic::Consonance
2
+ LEVELS = %w[perfect imperfect dissonant]
3
+
4
+ def self.get(name)
5
+ @consonances ||= {}
6
+ @consonances[name.to_sym] ||= new(name) if LEVELS.include?(name.to_s)
7
+ end
8
+
9
+ attr_reader :name
10
+
11
+ delegate :to_s, to: :name
12
+
13
+ def initialize(name)
14
+ @name = name.to_s.to_sym
15
+ end
16
+
17
+ LEVELS.each do |method_name|
18
+ define_method(:"#{method_name}?") { to_s == method_name }
19
+ end
20
+ end
@@ -26,6 +26,7 @@ class HeadMusic::FunctionalInterval
26
26
 
27
27
  delegate :to_s, to: :name
28
28
  delegate :==, to: :to_s
29
+ delegate :perfect?, :major?, :minor?, :diminished?, :augmented?, :doubly_diminished?, :doubly_augmented?, to: :quality
29
30
 
30
31
  def self.get(name)
31
32
  words = name.to_s.split(/[_ ]+/)
@@ -136,4 +137,34 @@ class HeadMusic::FunctionalInterval
136
137
  end
137
138
  HeadMusic::FunctionalInterval.new(higher_pitch, inverted_low_pitch)
138
139
  end
140
+
141
+ def consonance
142
+ if quality.perfect?
143
+ if [number, simple_number].include?(4)
144
+ HeadMusic::Consonance.get(:dissonant)
145
+ else
146
+ HeadMusic::Consonance.get(:perfect)
147
+ end
148
+ elsif quality.major? || quality.minor?
149
+ if [number, simple_number] & [3, 6].empty?
150
+ HeadMusic::Consonance.get(:dissonant)
151
+ else
152
+ HeadMusic::Consonance.get(:imperfect)
153
+ end
154
+ else
155
+ HeadMusic::Consonance.get(:dissonant)
156
+ end
157
+ end
158
+
159
+ def skip?
160
+ number > 2
161
+ end
162
+
163
+ def step?
164
+ number <= 2
165
+ end
166
+
167
+ NUMBER_NAMES.each do |method_name|
168
+ define_method(:"#{method_name}?") { number_name == method_name }
169
+ end
139
170
  end
@@ -59,5 +59,9 @@ class HeadMusic::Quality
59
59
  %w[a e i o u h].include?(name.to_s.first) ? 'an' : 'a'
60
60
  end
61
61
 
62
+ NAMES.each do |method_name|
63
+ define_method(:"#{method_name}?") { name == method_name }
64
+ end
65
+
62
66
  private_class_method :new
63
67
  end
@@ -42,8 +42,8 @@ class HeadMusic::Scale
42
42
  end
43
43
  end
44
44
 
45
- def spellings
46
- pitches.map(&:spelling).map(&:to_s)
45
+ def spellings(direction: :ascending, octaves: 1)
46
+ pitches(direction: direction, octaves: octaves).map(&:spelling).map(&:to_s)
47
47
  end
48
48
 
49
49
  def pitch_names(direction: :ascending, octaves: 1)
@@ -1,3 +1,3 @@
1
1
  module HeadMusic
2
- VERSION = "0.5.1"
2
+ VERSION = "0.5.2"
3
3
  end
data/lib/head_music.rb CHANGED
@@ -6,6 +6,7 @@ require "humanize"
6
6
 
7
7
  require "head_music/accidental"
8
8
  require "head_music/circle"
9
+ require "head_music/consonance"
9
10
  require "head_music/functional_interval"
10
11
  require "head_music/interval"
11
12
  require "head_music/key_signature"
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.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob Head
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-02-21 00:00:00.000000000 Z
11
+ date: 2017-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -116,6 +116,7 @@ files:
116
116
  - lib/head_music.rb
117
117
  - lib/head_music/accidental.rb
118
118
  - lib/head_music/circle.rb
119
+ - lib/head_music/consonance.rb
119
120
  - lib/head_music/functional_interval.rb
120
121
  - lib/head_music/interval.rb
121
122
  - lib/head_music/key_signature.rb