music-utils 0.3.20 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
- ## 0.0.1 (April 23, 2011)
1
+ ## 0.0.1 (March 23, 2011)
2
2
 
3
3
  Features:
4
4
 
5
- - Added support to full diatonic scale in quality method
5
+ - First commit
6
+
7
+ ## 0.3.20 (April 26, 2011)
8
+
9
+ Features:
10
+
11
+ - Added support to full diatonic scale in quality method
12
+
13
+ ## 0.4.0 (April 26, 2011)
14
+
15
+ Features:
16
+
17
+ - Added support for notes alterations
data/README.md CHANGED
@@ -10,6 +10,7 @@ Simple intervals:
10
10
  * Interval.new('do', 'mi', 0).number #=> 3 (3th)
11
11
  * Interval.new('do', 'mi', 0).semitone #=> 4 (semi-tones)
12
12
  * Interval.new('do', 'mi', 0).quality #=> M (major)
13
+ * Interval.new('do#', 'mi', 0).quality #=> m (major)
13
14
 
14
15
  Compound intervals:
15
16
 
@@ -19,7 +20,7 @@ Compound intervals:
19
20
 
20
21
  To Do
21
22
  -----
22
- * Add support to note alterations
23
+ * Add more rspec examples
23
24
 
24
25
  Copyright
25
26
  ---------
data/lib/interval.rb CHANGED
@@ -2,12 +2,12 @@
2
2
  module Scales
3
3
  DIATONIC_SCALE = ['do', 're', 'mi', 'fa', 'sol', 'la', 'si']
4
4
  QUALITIES = {
5
- 2 => {0 => 'd', 1 => 'm', 2 => 'M', 3 => 'A'},
6
- 3 => {2 => 'd', 3 => 'm', 4 => 'M', 5 => 'A'},
5
+ 2 => {0 => 'd', 1 => 'm', 2 => 'M', 3 => 'A', 4 => 'AA'},
6
+ 3 => {1 => 'dd', 2 => 'd', 3 => 'm', 4 => 'M', 5 => 'A', 6 => 'AA'},
7
7
  4 => {3 => 'dd', 4 => 'd', 5 => 'P', 6 => 'A', 7 => 'AA'},
8
8
  5 => {5 => 'dd', 6 => 'd', 7 => 'P', 8 => 'A', 9 => 'AA'},
9
- 6 => {7 => 'd', 8 => 'm', 9 => 'M', 10 => 'A'},
10
- 7 => {9 => 'd', 10 => 'm', 11 => 'M', 12 => 'A'},
9
+ 6 => {6 => 'dd', 7 => 'd', 8 => 'm', 9 => 'M', 10 => 'A', 11 => 'AA'},
10
+ 7 => {8 => 'dd', 9 => 'd', 10 => 'm', 11 => 'M', 12 => 'A', 13 => 'AA'},
11
11
  8 => {10 => 'dd', 11 => 'd', 12 => 'P', 13 => 'A', 14 => 'AA'}
12
12
  }
13
13
  end
@@ -25,16 +25,16 @@ class Interval
25
25
  # It classifies the diatonic interval
26
26
  def number
27
27
  # initialize counter and index of scale
28
- i = DIATONIC_SCALE.index(@note1)
28
+ i = DIATONIC_SCALE.index(@note1[0..1])
29
29
  count = 1
30
30
 
31
31
  # No unison
32
- if @note1 == @note2
32
+ if @note1[0..1] == @note2[0..1]
33
33
  count += 1; i += 1
34
34
  end
35
35
 
36
36
  # Counting notes
37
- while DIATONIC_SCALE[i] != @note2
37
+ while DIATONIC_SCALE[i] != @note2[0..1]
38
38
  i += 1
39
39
  if i > DIATONIC_SCALE.length
40
40
  i = 0; next
@@ -48,16 +48,16 @@ class Interval
48
48
  # Returns the number of semitones
49
49
  def semitone
50
50
  # initialize counter and index of scale
51
- i = DIATONIC_SCALE.index(@note1)
51
+ i = DIATONIC_SCALE.index(@note1[0..1])
52
52
  count = 0
53
53
 
54
54
  # No unison
55
- if @note1 == @note2
55
+ if @note1[0..1] == @note2[0..1]
56
56
  count += 1; i += 1
57
57
  end
58
58
 
59
59
  # Counting semi-tones
60
- while DIATONIC_SCALE[i] != @note2
60
+ while DIATONIC_SCALE[i] != @note2[0..1]
61
61
  i += 1
62
62
  if i > DIATONIC_SCALE.length
63
63
  i = 0; next
@@ -72,6 +72,22 @@ class Interval
72
72
  end
73
73
 
74
74
  count = count + (12 * @step) if @step > 0
75
+
76
+ # Counting notes alterations
77
+ alter = @note1[2..3]
78
+
79
+ alter.each_char do |c|
80
+ count += 1 if c == 'b'
81
+ count -= 1 if c == '#'
82
+ end
83
+
84
+ alter = @note2[2..3]
85
+
86
+ alter.each_char do |c|
87
+ count -= 1 if c == 'b'
88
+ count += 1 if c == '#'
89
+ end
90
+
75
91
  count
76
92
  end
77
93
 
data/music-utils.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
  Gem::Specification.new do |s|
3
3
  # Basic Info
4
4
  s.name = 'music-utils'
5
- s.version = '0.3.20'
5
+ s.version = '0.4.0'
6
6
  s.summary = 'music-utils'
7
7
  s.description = 'Utils for music'
8
8
  s.platform = Gem::Platform::RUBY
@@ -24,7 +24,12 @@ describe Interval do
24
24
  i = Interval.new('do', 'mi', 0)
25
25
  i.semitone.should == 4
26
26
  end
27
-
27
+
28
+ it "simple interval dob-mi# should be 6 semitones" do
29
+ i = Interval.new('dob', 'mi#', 0)
30
+ i.semitone.should == 6
31
+ end
32
+
28
33
  it "simple interval do-do should be 12 semitones" do
29
34
  i = Interval.new('do', 'do', 0)
30
35
  i.semitone.should == 12
@@ -46,7 +51,17 @@ describe Interval do
46
51
  i = Interval.new('do', 'mi', 0)
47
52
  i.quality.should == 'M'
48
53
  end
49
-
54
+
55
+ it "quality of interval do#-mi should be m" do
56
+ i = Interval.new('do#', 'mi', 0)
57
+ i.quality.should == 'm'
58
+ end
59
+
60
+ it "quality of interval dob-mi# should be AA" do
61
+ i = Interval.new('dob', 'mi#', 0)
62
+ i.quality.should == 'AA'
63
+ end
64
+
50
65
  it "quality of interval do-do should be P" do
51
66
  i = Interval.new('do', 'do', 0)
52
67
  i.quality.should == 'P'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: music-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.20
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-04-26 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &24133836 !ruby/object:Gem::Requirement
16
+ requirement: &77436860 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *24133836
24
+ version_requirements: *77436860
25
25
  description: Utils for music
26
26
  email:
27
27
  - jorgeluis700@gmail.com
@@ -54,7 +54,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
54
54
  version: '0'
55
55
  segments:
56
56
  - 0
57
- hash: -731370575
57
+ hash: -975623391
58
58
  required_rubygems_version: !ruby/object:Gem::Requirement
59
59
  none: false
60
60
  requirements: