music-utils 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore CHANGED
@@ -4,8 +4,13 @@
4
4
  # build directory
5
5
  pkg/
6
6
 
7
- # Gems
8
- Gemfile.lock
9
-
10
7
  # vim swap files
11
8
  *.swp
9
+
10
+ # bundler config
11
+ .bundle/
12
+
13
+ # jedit files
14
+ *.*~
15
+ *.*#
16
+
@@ -1,9 +1,17 @@
1
+ ## 1.2.1 (Jun 28, 2011)
2
+
3
+ Features:
4
+
5
+ - Added support to major pentatonic scale and virtually any other scale
6
+
7
+
1
8
  ## 1.2.0 (May 25, 2011)
2
9
 
3
10
  Features:
4
11
 
5
12
  - Added functionality to calculate the highest note of an interval
6
13
 
14
+
7
15
  ## 1.1.2 (May 21, 2011)
8
16
 
9
17
  Features:
@@ -0,0 +1,27 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ music-utils (1.2.1)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.1.2)
10
+ rake (0.9.2)
11
+ rspec (2.6.0)
12
+ rspec-core (~> 2.6.0)
13
+ rspec-expectations (~> 2.6.0)
14
+ rspec-mocks (~> 2.6.0)
15
+ rspec-core (2.6.4)
16
+ rspec-expectations (2.6.0)
17
+ diff-lcs (~> 1.1.2)
18
+ rspec-mocks (2.6.0)
19
+
20
+ PLATFORMS
21
+ ruby
22
+
23
+ DEPENDENCIES
24
+ bundler
25
+ music-utils!
26
+ rake (>= 0.8)
27
+ rspec
data/README.md CHANGED
@@ -60,14 +60,14 @@ Testing
60
60
 
61
61
  To run the tests:
62
62
 
63
- $ rake
63
+ $ bin/rake
64
64
 
65
65
 
66
66
  To Do
67
67
  -----
68
68
 
69
69
  * Add validations (notes, alterations, etc)
70
- * Add support to pentatonic scale and others
70
+ * Add other scales structures and its tests
71
71
 
72
72
 
73
73
  Copyright
@@ -0,0 +1,3 @@
1
+ #!/bin/bash
2
+
3
+ bundle exec rake $1
@@ -1,40 +1,40 @@
1
- require 'music-utils/interval/interval'
2
- require 'music-utils/scales/scales'
3
-
4
- # Music utils
5
- module MusicUtils
6
- include Scales
7
-
8
- # Returns the number of the interval
9
- def MusicUtils.number(note1, note2, step = 0)
10
- Interval.new(note1, note2, step).number
11
- end
12
-
13
- # Returns semitones of interval
14
- def MusicUtils.semitones(note1, note2, step = 0)
15
- Interval.new(note1, note2, step).semitones
16
- end
17
-
18
- # Returns the quality of interval
19
- def MusicUtils.quality(note1, note2, step = 0)
20
- Interval.new(note1, note2, step).quality
21
- end
22
-
23
- # Returns short notation
24
- def MusicUtils.short(note1, note2, step = 0)
25
- Interval.new(note1, note2, step).short
26
- end
27
-
1
+ require 'music-utils/interval/interval'
2
+ require 'music-utils/scales/scales'
3
+
4
+ # Music utils
5
+ module MusicUtils
6
+ include Scales
7
+
8
+ # Returns the number of the interval
9
+ def MusicUtils.number(note1, note2, step = 0)
10
+ Interval.new(note1, note2, step).number
11
+ end
12
+
13
+ # Returns semitones of interval
14
+ def MusicUtils.semitones(note1, note2, step = 0)
15
+ Interval.new(note1, note2, step).semitones
16
+ end
17
+
18
+ # Returns the quality of interval
19
+ def MusicUtils.quality(note1, note2, step = 0)
20
+ Interval.new(note1, note2, step).quality
21
+ end
22
+
23
+ # Returns short notation
24
+ def MusicUtils.short(note1, note2, step = 0)
25
+ Interval.new(note1, note2, step).short
26
+ end
27
+
28
28
  # Returns the second note of an interval
29
29
  # calculates from its first note and number
30
30
  # and quality in short notation
31
- def MusicUtils.high_note(from, short)
32
- Interval.high_note(from, short)
33
- end
34
-
35
- # Returns a scale
36
- def MusicUtils.scale(from, scale)
37
- Scales.scale(from, scale)
38
- end
39
-
31
+ def MusicUtils.high_note(from, short)
32
+ Interval.high_note(from, short)
33
+ end
34
+
35
+ # Returns a scale
36
+ def MusicUtils.scale(from, scale)
37
+ Scales.scale(from, scale)
38
+ end
39
+
40
40
  end
@@ -0,0 +1,6 @@
1
+ module MusicUtils
2
+ # Tag module for errors
3
+ module Errors
4
+ end
5
+ end
6
+
@@ -0,0 +1,15 @@
1
+ module MusicUtils
2
+
3
+ # This exception its raised when
4
+ # a given interval is invalid
5
+ class InvalidInterval < StdError
6
+ attr_reader :interval
7
+
8
+ def initialize(msg, original=$!, interval)
9
+ super(msg, original)
10
+ @interval = interval
11
+ end
12
+ end
13
+
14
+ end
15
+
@@ -0,0 +1,15 @@
1
+ module MusicUtils
2
+
3
+ # This exception its raised when
4
+ # a given note is invalid
5
+ class InvalidNote < StdError
6
+ attr_reader :note
7
+
8
+ def initialize(msg, original=$!, note)
9
+ super(msg, original)
10
+ @note = note
11
+ end
12
+ end
13
+
14
+ end
15
+
@@ -0,0 +1,16 @@
1
+ module MusicUtils
2
+
3
+ # Prevents the user of the library
4
+ # from rescuing the global `StandardError`.
5
+ class StdError < StandardError
6
+ extend Error
7
+ attr_reader :original
8
+
9
+ # Create the error with a message and an original that defaults to
10
+ # the exception that is currently active, in this thread, if one exists
11
+ def initialize(msg, original=$!)
12
+ super(msg)
13
+ @original = original;
14
+ end
15
+ end
16
+ end
@@ -14,6 +14,7 @@ module Scales
14
14
  SI = :si
15
15
 
16
16
  DIATONIC_SCALE = [DO, RE, MI, FA, SOL, LA, SI]
17
+ DIATONIC_SCALE_AUX = [DO, DO, RE, RE, MI, FA, FA, SOL, SOL, LA, LA, SI]
17
18
 
18
19
  # Alterations:
19
20
  FLAT = 'f'
@@ -72,6 +73,7 @@ module Scales
72
73
  MAJ_SCALE = [2, 2, 1, 2, 2, 2, 1]
73
74
  NATURAL_MIN_SCALE = [2, 1, 2, 2, 1, 2, 2]
74
75
  MELODIC_MIN_SCALE = [2, 1, 2, 2, 1, 2, 1]
76
+ PENTATONIC_MAJ = [2, 2, 3, 2, 3]
75
77
 
76
78
  # Qualities
77
79
  PERF = 'P'
@@ -104,7 +106,8 @@ module Scales
104
106
 
105
107
  from_note, from_alter = MusicUtils::Note.parse(from)
106
108
 
107
- diatonic_scale = diatonic_scale_from(from_note)
109
+ #diatonic_scale = diatonic_scale_from(from_note)
110
+ diatonic_scale = scale_from(from_note, scale_struct)
108
111
  diatonic_scale.delete(from_note)
109
112
 
110
113
  length = CROMATIC_SCALE.length
@@ -129,22 +132,10 @@ module Scales
129
132
 
130
133
  scale
131
134
  end
132
-
133
- # Create a diatonic scale starting with the "from" note
135
+
136
+ # Create a diatonic scale starting with the "from" note
134
137
  def Scales.diatonic_scale_from(from)
135
- diatonic_scale = []
136
- length = DIATONIC_SCALE.length
137
- i = DIATONIC_SCALE.index(from)
138
- c = 0
139
- while c < length
140
- diatonic_scale << DIATONIC_SCALE[i]
141
- i += 1
142
- c += 1
143
- if i > length - 1
144
- i = 0
145
- end
146
- end
147
- diatonic_scale
138
+ diatonic_aux_scale_from(from).uniq
148
139
  end
149
140
 
150
141
  # Returns index of the note in the cromatic scale
@@ -165,5 +156,43 @@ module Scales
165
156
  i
166
157
  end
167
158
 
159
+ # Create a diatonic scale starting with the "from" note
160
+ # with notes dups
161
+ def Scales.diatonic_aux_scale_from(from)
162
+ diatonic_scale = []
163
+ length = DIATONIC_SCALE_AUX.length
164
+ i = DIATONIC_SCALE_AUX.index(from)
165
+ c = 0
166
+ while c < length
167
+ diatonic_scale << DIATONIC_SCALE_AUX[i]
168
+ i += 1
169
+ c += 1
170
+ if i > length - 1
171
+ i = 0
172
+ end
173
+ end
174
+ diatonic_scale
175
+ end
176
+
177
+ def Scales.scale_from(from_note, scale_struct)
178
+ i = 0
179
+ c = 0
180
+ scale = []
181
+ scale << from_note
182
+
183
+ ds = diatonic_aux_scale_from(from_note)
184
+
185
+ while c < scale_struct.size
186
+ i += scale_struct[c]
187
+ if scale.last != ds[i]
188
+ scale << ds[i]
189
+ else
190
+ scale << ds[i + 1]
191
+ end
192
+ c += 1
193
+ end
194
+ scale
195
+ end
196
+
168
197
  end
169
198
  end
@@ -1,3 +1,3 @@
1
1
  module MusicUtils
2
- VERSION = '1.2.0'
2
+ VERSION = '1.2.1'
3
3
  end
@@ -309,25 +309,25 @@ describe MusicUtils do
309
309
  context "Scales" do
310
310
  context "Major scale" do
311
311
  context "Natural notes" do
312
- it "the major scale of DO should be [DO, RE, MI, FA, SOL, LA, SI, DO]" do
312
+ it "the major scale of DO should be [DO, RE, MI, FA, SOL, LA, SI]" do
313
313
  MusicUtils.scale(DO, MAJ_SCALE).should == [DO, RE, MI, FA, SOL, LA, SI]
314
314
  end
315
- it "the major scale of RE should be [RE, MI, FAS, SOL, LA, SI, DOS, RE]" do
315
+ it "the major scale of RE should be [RE, MI, FAS, SOL, LA, SI, DOS]" do
316
316
  MusicUtils.scale(RE, MAJ_SCALE).should == [RE, MI, FAS, SOL, LA, SI, DOS]
317
317
  end
318
- it "the major scale of MI should be [MI, FAS, SOLS, LA, SI, DOS, RES, MI]" do
318
+ it "the major scale of MI should be [MI, FAS, SOLS, LA, SI, DOS, RES]" do
319
319
  MusicUtils.scale(MI, MAJ_SCALE).should == [MI, FAS, SOLS, LA, SI, DOS, RES]
320
320
  end
321
- it "the major scale of FA should be [FA, SOL, LA, SIF, DO, RE, MI, FA]" do
321
+ it "the major scale of FA should be [FA, SOL, LA, SIF, DO, RE, MI]" do
322
322
  MusicUtils.scale(FA, MAJ_SCALE).should == [FA, SOL, LA, SIF, DO, RE, MI]
323
323
  end
324
- it "the major scale of SOL should be [SOL, LA, SI, DO, RE, MI, FAS, SOL]" do
324
+ it "the major scale of SOL should be [SOL, LA, SI, DO, RE, MI, FAS]" do
325
325
  MusicUtils.scale(SOL, MAJ_SCALE).should == [SOL, LA, SI, DO, RE, MI, FAS]
326
326
  end
327
- it "the major scale of LA should be [LA, SI, DOS, RE, MI, FAS, SOLS, LA]" do
327
+ it "the major scale of LA should be [LA, SI, DOS, RE, MI, FAS, SOLS]" do
328
328
  MusicUtils.scale(LA, MAJ_SCALE).should == [LA, SI, DOS, RE, MI, FAS, SOLS]
329
329
  end
330
- it "the major scale of SI should be [SI, DOS, RES, MI, FAS, SOLS, LAS, SI]" do
330
+ it "the major scale of SI should be [SI, DOS, RES, MI, FAS, SOLS, LAS]" do
331
331
  MusicUtils.scale(SI, MAJ_SCALE).should == [SI, DOS, RES, MI, FAS, SOLS, LAS]
332
332
  end
333
333
  end
@@ -451,8 +451,78 @@ describe MusicUtils do
451
451
  end
452
452
  end
453
453
  end
454
-
454
+ context "Pentatonic major" do
455
+ context "Natural notes" do
456
+ it "the pentatonic major scale of DO should be [DO, RE, MI, SOL, LA]" do
457
+ MusicUtils.scale(DO, PENTATONIC_MAJ).should == [DO, RE, MI, SOL, LA]
458
+ end
459
+ it "the pentatonic major scale of RE should be [RE, MI, FAS, LA, SI]" do
460
+ MusicUtils.scale(RE, PENTATONIC_MAJ).should == [RE, MI, FAS, LA, SI]
461
+ end
462
+ it "the pentatonic major scale of MI should be [MI, FAS, SOLS, SI, DOS]" do
463
+ MusicUtils.scale(MI, PENTATONIC_MAJ).should == [MI, FAS, SOLS, SI, DOS]
464
+ end
465
+ it "the pentatonic major scale of FA should be [FA, SOL, LA, DO, RE]" do
466
+ MusicUtils.scale(FA, PENTATONIC_MAJ).should == [FA, SOL, LA, DO, RE]
467
+ end
468
+ it "the pentatonic major scale of SOL should be [SOL, LA, SI, RE, MI]" do
469
+ MusicUtils.scale(SOL, PENTATONIC_MAJ).should == [SOL, LA, SI, RE, MI]
470
+ end
471
+ it "the pentatonic major scale of LA should be [LA, SI, DOS, MI, FAS]" do
472
+ MusicUtils.scale(LA, PENTATONIC_MAJ).should == [LA, SI, DOS, MI, FAS]
473
+ end
474
+ it "the pentatonic major scale of SI should be [SI, DOS, RES, FAS, SOLS]" do
475
+ MusicUtils.scale(SI, PENTATONIC_MAJ).should == [SI, DOS, RES, FAS, SOLS]
476
+ end
477
+ end
478
+ context "Sharped notes" do
479
+ it "the major pentatonic of DO# should be [DOS, RES, MIS, SOLS, LAS]" do
480
+ MusicUtils.scale(DOS, PENTATONIC_MAJ).should == [DOS, RES, MIS, SOLS, LAS]
481
+ end
482
+ it "the major pentatonic of RE# should be [RES, MIS, FASS, LAS, SIS]" do
483
+ MusicUtils.scale(RES, PENTATONIC_MAJ).should == [RES, MIS, FASS, LAS, SIS]
484
+ end
485
+ it "the major pentatonic of MI# should be [MIS, FASS, SOLSS, SIS, DOSS]" do
486
+ MusicUtils.scale(MIS, PENTATONIC_MAJ).should == [MIS, FASS, SOLSS, SIS, DOSS]
487
+ end
488
+ it "the major pentatonic of FA# should be [FAS, SOLS, LAS, DOS, RES]" do
489
+ MusicUtils.scale(FAS, PENTATONIC_MAJ).should == [FAS, SOLS, LAS, DOS, RES]
490
+ end
491
+ it "the major pentatonic of SOL# should be [SOLS, LAS, SIS, RES, MIS]" do
492
+ MusicUtils.scale(SOLS, PENTATONIC_MAJ).should == [SOLS, LAS, SIS, RES, MIS]
493
+ end
494
+ it "the major pentatonic of LA# should be [LAS, SIS, DOSS, MIS, FASS]" do
495
+ MusicUtils.scale(LAS, PENTATONIC_MAJ).should == [LAS, SIS, DOSS, MIS, FASS]
496
+ end
497
+ it "the major pentatonic of SI# should be [SIS, DOSS, RESS, FASS, SOLSS]" do
498
+ MusicUtils.scale(SIS, PENTATONIC_MAJ).should == [SIS, DOSS, RESS, FASS, SOLSS]
499
+ end
500
+ end
501
+ context "Flated notes" do
502
+ it "the major pentatonic of DOb should be [DOF, REF, MIF, SOLF, LAF]" do
503
+ MusicUtils.scale(DOF, PENTATONIC_MAJ).should == [DOF, REF, MIF, SOLF, LAF]
504
+ end
505
+ it "the major pentatonic of REb should be [REF, MIF, FA, LAF, SIF]" do
506
+ MusicUtils.scale(REF, PENTATONIC_MAJ).should == [REF, MIF, FA, LAF, SIF]
507
+ end
508
+ it "the major pentatonic of MIb should be [MIF, FA, SOL, SIF, DO]" do
509
+ MusicUtils.scale(MIF, PENTATONIC_MAJ).should == [MIF, FA, SOL, SIF, DO]
510
+ end
511
+ it "the major pentatonic of FAb should be [FAF, SOLF, LAF, DOF, REF]" do
512
+ MusicUtils.scale(FAF, PENTATONIC_MAJ).should == [FAF, SOLF, LAF, DOF, REF]
513
+ end
514
+ it "the major pentatonic of SOLb should be [SOLF, LAF, SIF, REF, MIF]" do
515
+ MusicUtils.scale(SOLF, PENTATONIC_MAJ).should == [SOLF, LAF, SIF, REF, MIF]
516
+ end
517
+ it "the major pentatonic of LAb should be [LAF, SIF, DO, MIF, FA]" do
518
+ MusicUtils.scale(LAF, PENTATONIC_MAJ).should == [LAF, SIF, DO, MIF, FA]
519
+ end
520
+ it "the major pentatonic of SIb should be [SIF, DO, RE, FA, SOL]" do
521
+ MusicUtils.scale(SIF, PENTATONIC_MAJ).should == [SIF, DO, RE, FA, SOL]
522
+ end
523
+ end
524
+ end
455
525
  end
456
526
  end
457
-
458
527
  end
528
+
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: 1.2.0
4
+ version: 1.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-05-25 00:00:00.000000000Z
12
+ date: 2011-06-28 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &85461120 !ruby/object:Gem::Requirement
16
+ requirement: &83229490 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0.8'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *85461120
24
+ version_requirements: *83229490
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bundler
27
- requirement: &85460930 !ruby/object:Gem::Requirement
27
+ requirement: &80893800 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *85460930
35
+ version_requirements: *80893800
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &85460700 !ruby/object:Gem::Requirement
38
+ requirement: &80897410 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,23 +43,30 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *85460700
46
+ version_requirements: *80897410
47
47
  description: Utils to classify music intervals, create scales and more. See README.md
48
48
  and CHANGELOG.md on homepage for more info.
49
49
  email:
50
50
  - jorgeluis700@gmail.com
51
- executables: []
51
+ executables:
52
+ - rake
52
53
  extensions: []
53
54
  extra_rdoc_files: []
54
55
  files:
55
56
  - .gitignore
56
57
  - CHANGELOG.md
57
58
  - Gemfile
59
+ - Gemfile.lock
58
60
  - LICENSE
59
61
  - README.md
60
62
  - Rakefile
61
63
  - benchmark/music-utils_bm.rb
64
+ - bin/rake
62
65
  - lib/music-utils.rb
66
+ - lib/music-utils/errors/error.rb
67
+ - lib/music-utils/errors/interval_errors.rb
68
+ - lib/music-utils/errors/note_errors.rb
69
+ - lib/music-utils/errors/std_error.rb
63
70
  - lib/music-utils/interval/interval.rb
64
71
  - lib/music-utils/note/note.rb
65
72
  - lib/music-utils/scales/scales.rb
@@ -80,6 +87,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
80
87
  - - ! '>='
81
88
  - !ruby/object:Gem::Version
82
89
  version: '0'
90
+ segments:
91
+ - 0
92
+ hash: 869210273
83
93
  required_rubygems_version: !ruby/object:Gem::Requirement
84
94
  none: false
85
95
  requirements:
@@ -88,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
98
  version: 1.3.6
89
99
  requirements: []
90
100
  rubyforge_project:
91
- rubygems_version: 1.7.2
101
+ rubygems_version: 1.8.5
92
102
  signing_key:
93
103
  specification_version: 3
94
104
  summary: Utils for common music tasks.