music-utils 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## 1.0.2 (May 12, 2011)
2
+
3
+ Features:
4
+
5
+ - Fixed do-sol bug
6
+
7
+
1
8
  ## 1.0.1 (May 6, 2011)
2
9
 
3
10
  Features:
data/Rakefile CHANGED
@@ -12,6 +12,13 @@ RSpec::Core::RakeTask.new(:spec) do |spec|
12
12
  spec.fail_on_error = false
13
13
  end
14
14
 
15
+ desc "Run benchmarks"
16
+ task :bench do
17
+ Dir["benchmark/**/*_bm.rb"].each do |f|
18
+ eval(File.read(f))
19
+ end
20
+ end
21
+
15
22
  # Gems tasks
16
23
  require "bundler"
17
24
  Bundler::GemHelper.install_tasks
@@ -5,15 +5,26 @@ require 'music-utils/scales/scales'
5
5
  require 'benchmark'
6
6
 
7
7
  n = 100_000
8
+ label_width = 60
8
9
 
9
- Benchmark.bmbm(15) do |b|
10
- b.report('with strings:') do
10
+ Benchmark.bm(label_width) do |b|
11
+ b.report('Classifying do-mi interval with strings (number):') do
12
+ n.times { MusicUtils.number('do', 'mi') }
13
+ end
14
+ b.report('Classifying do-mi interval with strings (quality):') do
15
+ n.times { MusicUtils.quality('do', 'mi') }
16
+ end
17
+ b.report('Classifying do-mi interval with strings (short notation):') do
11
18
  n.times { MusicUtils.short('do', 'mi') }
12
19
  end
13
- b.report('with symbols:') do
14
- n.times { MusicUtils.short(:do, :mi) }
20
+
21
+ b.report('Classifying do-mi interval with scales (number):') do
22
+ n.times { MusicUtils.number(Scales::DO, Scales::MI) }
23
+ end
24
+ b.report('Classifying do-mi interval with scales (quality):') do
25
+ n.times { MusicUtils.quality(Scales::DO, Scales::MI) }
15
26
  end
16
- b.report('with scales:') do
27
+ b.report('Classifying do-mi interval with scales (short notation):') do
17
28
  n.times { MusicUtils.short(Scales::DO, Scales::MI) }
18
29
  end
19
30
  end
@@ -7,10 +7,21 @@ module MusicUtils
7
7
  include Scales
8
8
 
9
9
  def initialize(note1, note2, step)
10
- @note1 = note1[0..1].to_sym
11
- @note1_alt = note1[2..3]
12
- @note2 = note2[0..1].to_sym
13
- @note2_alt = note2[2..3]
10
+
11
+ # SOL is the only note of length = 3
12
+ n = 0
13
+ n += 1 if note1[0..2].to_sym == SOL
14
+
15
+ @note1 = note1[0..1 + n].to_sym
16
+ @note1_alt = note1[2 + n..3 + n]
17
+
18
+ # SOL is the only note of length = 3
19
+ n = 0
20
+ n += 1 if note2[0..2].to_sym == SOL
21
+
22
+ @note2 = note2[0..1 + n].to_sym
23
+ @note2_alt = note2[2 + n..3 + n]
24
+
14
25
  @step = step
15
26
  end
16
27
 
@@ -2,21 +2,57 @@
2
2
  module Scales
3
3
 
4
4
  # Notes
5
- DO = :do
6
- RE = :re
7
- MI = :mi
8
- FA = :fa
5
+ DO = :do
6
+ RE = :re
7
+ MI = :mi
8
+ FA = :fa
9
9
  SOL = :sol
10
- LA = :la
11
- SI = :si
10
+ LA = :la
11
+ SI = :si
12
12
 
13
13
  DIATONIC_SCALE = [DO, RE, MI, FA, SOL, LA, SI]
14
14
 
15
15
  # Alterations:
16
- FLAT = 'b'
17
- DFLAT = FLAT + FLAT
18
- SHARP = '#'
19
- DSHARP = SHARP + SHARP
16
+ FLAT = 'b'
17
+ DFLAT = FLAT + FLAT
18
+ SHARP = '#'
19
+ DSHARP = SHARP + SHARP
20
+
21
+ # Altered notes
22
+ DOF = DO.to_s + FLAT
23
+ DOFF = DO.to_s + DFLAT
24
+ DOS = DO.to_s + SHARP
25
+ DOSS = DO.to_s + DSHARP
26
+
27
+ REF = RE.to_s + FLAT
28
+ REFF = RE.to_s + DFLAT
29
+ RES = RE.to_s + SHARP
30
+ RESS = RE.to_s + DSHARP
31
+
32
+ MIF = MI.to_s + FLAT
33
+ MIFF = MI.to_s + DFLAT
34
+ MIS = MI.to_s + SHARP
35
+ MISS = MI.to_s + DSHARP
36
+
37
+ FAF = FA.to_s + FLAT
38
+ FAFF = FA.to_s + DFLAT
39
+ FAS = FA.to_s + SHARP
40
+ FASS = FA.to_s + DSHARP
41
+
42
+ SOLF = SOL.to_s + FLAT
43
+ SOLFF = SOL.to_s + DFLAT
44
+ SOLS = SOL.to_s + SHARP
45
+ SOLSS = SOL.to_s + DSHARP
46
+
47
+ LAF = LA.to_s + FLAT
48
+ LAFF = LA.to_s + DFLAT
49
+ LAS = LA.to_s + SHARP
50
+ LASS = LA.to_s + DSHARP
51
+
52
+ SIF = SI.to_s + FLAT
53
+ SIFF = SI.to_s + DFLAT
54
+ SIS = SI.to_s + SHARP
55
+ SISS = SI.to_s + DSHARP
20
56
 
21
57
  # Qualities
22
58
  PERF = 'P'
@@ -33,7 +69,7 @@ module Scales
33
69
  3 => {1 => DIMP, 2 => DIM, 3 => MIN, 4 => MAJ, 5 => AUG, 6 => AUGP},
34
70
  4 => {3 => DIMP, 4 => DIM, 5 => PERF, 6 => AUG, 7 => AUGP},
35
71
  5 => {5 => DIMP, 6 => DIM, 7 => PERF, 8 => AUG, 9 => AUGP},
36
- 6 => {6 => DIMP, 7 => DIM, 8 => MIN, 9 => MAJ, 10 => AUG, 11 => AUGP},
72
+ 6 => {7 => DIMP, 8 => DIM, 9 => MIN, 10 => MAJ, 11 => AUG, 12 => AUGP},
37
73
  7 => {8 => DIMP, 9 => DIM, 10 => MIN, 11 => MAJ, 12 => AUG, 13 => AUGP},
38
74
  8 => {10 => DIMP, 11 => DIM, 12 => PERF, 13 => AUG, 14 => AUGP}
39
75
  }
@@ -1,3 +1,3 @@
1
1
  module MusicUtils
2
- VERSION = '1.0.1'
2
+ VERSION = '1.0.2'
3
3
  end
@@ -101,6 +101,11 @@ describe MusicUtils::Interval do
101
101
  i.short.should == 'm10'
102
102
  end
103
103
 
104
+ it "the short notation of do-sol interval should be P5" do
105
+ i = Interval.new('do', 'sol', 0)
106
+ i.short.should == 'P5'
107
+ end
108
+
104
109
  end
105
110
  end
106
111
 
@@ -1,42 +1,43 @@
1
1
  require 'music-utils'
2
2
 
3
3
  describe MusicUtils do
4
-
4
+ include Scales
5
+
5
6
  context "Intervals" do
6
7
 
7
8
  context "By number" do
8
9
  it "the number of simple interval do-mi should be a 3rd" do
9
- MusicUtils.number('do', 'mi').should == 3
10
+ MusicUtils.number(DO, MI).should == 3
10
11
  end
11
12
  it "the number of do-mi compound interval should be a 10th" do
12
- MusicUtils.number('do', 'mi', 1).should == 10
13
+ MusicUtils.number(DO, MI, 1).should == 10
13
14
  end
14
15
  end
15
16
 
16
17
  context "By semitones" do
17
18
  it "simple interval do-mi should be 4 semitones" do
18
- MusicUtils.semitones('do', 'mi').should == 4
19
+ MusicUtils.semitones(DO, MI).should == 4
19
20
  end
20
21
  it "compound interval do-mi should be 16 semitones" do
21
- MusicUtils.semitones('do', 'mi', 1).should == 16
22
+ MusicUtils.semitones(DO, MI, 1).should == 16
22
23
  end
23
24
  end
24
25
 
25
26
  context "By quality" do
26
27
  it "quality of interval do-mi should be M" do
27
- MusicUtils.quality('do', 'mi').should == 'M'
28
+ MusicUtils.quality(DO, MI).should == 'M'
28
29
  end
29
30
  it "quality of compound interval do-mi should be M" do
30
- MusicUtils.quality('do', 'mi', 1).should == 'M'
31
+ MusicUtils.quality(DO, MI, 1).should == 'M'
31
32
  end
32
33
  end
33
34
 
34
35
  context "By short notation" do
35
36
  it "the short notation of do#-mi interval should be m3" do
36
- MusicUtils.short('do#', 'mi').should == 'm3'
37
+ MusicUtils.short(DOS, MI).should == 'm3'
37
38
  end
38
39
  it "the short notation of do#-mi compound interval should be m10" do
39
- MusicUtils.short('do#', 'mi', 1).should == 'm10'
40
+ MusicUtils.short(DOS, MI, 1).should == 'm10'
40
41
  end
41
42
  end
42
43
 
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.0.1
4
+ version: 1.0.2
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-08 00:00:00.000000000Z
12
+ date: 2011-05-12 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &83068570 !ruby/object:Gem::Requirement
16
+ requirement: &84854900 !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: *83068570
24
+ version_requirements: *84854900
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bundler
27
- requirement: &83068380 !ruby/object:Gem::Requirement
27
+ requirement: &84854710 !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: *83068380
35
+ version_requirements: *84854710
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &83109790 !ruby/object:Gem::Requirement
38
+ requirement: &84854480 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *83109790
46
+ version_requirements: *84854480
47
47
  description: Utils for music. At the moment only to classify intervals.
48
48
  email:
49
49
  - jorgeluis700@gmail.com