music-utils 1.0.0 → 1.0.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/CHANGELOG.md +8 -0
- data/benchmark/music-utils_bm.rb +19 -0
- data/lib/music-utils.rb +2 -0
- data/lib/music-utils/interval/interval.rb +17 -19
- data/lib/music-utils/scales/scales.rb +36 -8
- data/lib/music-utils/version.rb +1 -1
- metadata +9 -8
data/CHANGELOG.md
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
$:.push File.expand_path("../../lib", __FILE__)
|
2
|
+
|
3
|
+
require 'music-utils'
|
4
|
+
require 'music-utils/scales/scales'
|
5
|
+
require 'benchmark'
|
6
|
+
|
7
|
+
n = 100_000
|
8
|
+
|
9
|
+
Benchmark.bmbm(15) do |b|
|
10
|
+
b.report('with strings:') do
|
11
|
+
n.times { MusicUtils.short('do', 'mi') }
|
12
|
+
end
|
13
|
+
b.report('with symbols:') do
|
14
|
+
n.times { MusicUtils.short(:do, :mi) }
|
15
|
+
end
|
16
|
+
b.report('with scales:') do
|
17
|
+
n.times { MusicUtils.short(Scales::DO, Scales::MI) }
|
18
|
+
end
|
19
|
+
end
|
data/lib/music-utils.rb
CHANGED
@@ -7,8 +7,10 @@ module MusicUtils
|
|
7
7
|
include Scales
|
8
8
|
|
9
9
|
def initialize(note1, note2, step)
|
10
|
-
@note1 = note1
|
11
|
-
@
|
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]
|
12
14
|
@step = step
|
13
15
|
end
|
14
16
|
|
@@ -36,9 +38,9 @@ module MusicUtils
|
|
36
38
|
count, i = no_unison(count, i)
|
37
39
|
|
38
40
|
# counting semi-tones
|
39
|
-
until_find_note2(i) do |
|
41
|
+
until_find_note2(i) do |ii|
|
40
42
|
# from 'mi' to 'fa' and 'si' to 'do' there 1 semi-tone
|
41
|
-
if DIATONIC_SCALE[
|
43
|
+
if DIATONIC_SCALE[ii] == Scales::FA or DIATONIC_SCALE[ii] == Scales::DO
|
42
44
|
count += 1
|
43
45
|
else
|
44
46
|
count += 2
|
@@ -48,19 +50,15 @@ module MusicUtils
|
|
48
50
|
count = count + (12 * @step) if @step > 0
|
49
51
|
|
50
52
|
# counting notes alterations
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
count -= 1 if c == '#'
|
56
|
-
end
|
53
|
+
count += 1 if @note1_alt == Scales::FLAT
|
54
|
+
coutn += 2 if @note1_alt == Scales::DFLAT
|
55
|
+
count -= 1 if @note1_alt == Scales::SHARP
|
56
|
+
count -= 1 if @note1_alt == Scales::DSHARP
|
57
57
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
count += 1 if c == '#'
|
63
|
-
end
|
58
|
+
count -= 1 if @note2_alt == Scales::FLAT
|
59
|
+
count -= 2 if @note2_alt == Scales::DFLAT
|
60
|
+
count += 1 if @note2_alt == Scales::SHARP
|
61
|
+
count -= 2 if @note2_alt == Scales::DSHARP
|
64
62
|
|
65
63
|
count
|
66
64
|
end
|
@@ -82,7 +80,7 @@ module MusicUtils
|
|
82
80
|
# Common loop to search note 2
|
83
81
|
def until_find_note2(i)
|
84
82
|
# search note2
|
85
|
-
while DIATONIC_SCALE[i] != @note2
|
83
|
+
while DIATONIC_SCALE[i] != @note2
|
86
84
|
i += 1
|
87
85
|
if i > DIATONIC_SCALE.length
|
88
86
|
i = 0; next
|
@@ -93,7 +91,7 @@ module MusicUtils
|
|
93
91
|
|
94
92
|
# Jumps to the next note if note 1 and note 2 are the same
|
95
93
|
def no_unison(count, i)
|
96
|
-
if @note1
|
94
|
+
if @note1 == @note2
|
97
95
|
count += 1; i += 1
|
98
96
|
end
|
99
97
|
[count, i]
|
@@ -101,7 +99,7 @@ module MusicUtils
|
|
101
99
|
|
102
100
|
# Returns index of note 1
|
103
101
|
def note1_index
|
104
|
-
DIATONIC_SCALE.index(@note1
|
102
|
+
DIATONIC_SCALE.index(@note1)
|
105
103
|
end
|
106
104
|
|
107
105
|
end
|
@@ -1,13 +1,41 @@
|
|
1
1
|
# Scales module
|
2
2
|
module Scales
|
3
|
-
|
3
|
+
|
4
|
+
# Notes
|
5
|
+
DO = :do
|
6
|
+
RE = :re
|
7
|
+
MI = :mi
|
8
|
+
FA = :fa
|
9
|
+
SOL = :sol
|
10
|
+
LA = :la
|
11
|
+
SI = :si
|
12
|
+
|
13
|
+
DIATONIC_SCALE = [DO, RE, MI, FA, SOL, LA, SI]
|
14
|
+
|
15
|
+
# Alterations:
|
16
|
+
FLAT = 'b'
|
17
|
+
DFLAT = FLAT + FLAT
|
18
|
+
SHARP = '#'
|
19
|
+
DSHARP = SHARP + SHARP
|
20
|
+
|
21
|
+
# Qualities
|
22
|
+
PERF = 'P'
|
23
|
+
MAJ = 'M'
|
24
|
+
MIN = 'm'
|
25
|
+
AUG = 'A'
|
26
|
+
AUGP = AUG + AUG
|
27
|
+
DIM = 'd'
|
28
|
+
DIMP = DIM + DIM
|
29
|
+
|
30
|
+
# Qualities hash
|
4
31
|
QUALITIES = {
|
5
|
-
2 => {0 =>
|
6
|
-
3 => {1 =>
|
7
|
-
4 => {3 =>
|
8
|
-
5 => {5 =>
|
9
|
-
6 => {6 =>
|
10
|
-
7 => {8 =>
|
11
|
-
8 => {10 =>
|
32
|
+
2 => {0 => DIM, 1 => MIN, 2 => MAJ, 3 => AUG, 4 => AUGP},
|
33
|
+
3 => {1 => DIMP, 2 => DIM, 3 => MIN, 4 => MAJ, 5 => AUG, 6 => AUGP},
|
34
|
+
4 => {3 => DIMP, 4 => DIM, 5 => PERF, 6 => AUG, 7 => AUGP},
|
35
|
+
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},
|
37
|
+
7 => {8 => DIMP, 9 => DIM, 10 => MIN, 11 => MAJ, 12 => AUG, 13 => AUGP},
|
38
|
+
8 => {10 => DIMP, 11 => DIM, 12 => PERF, 13 => AUG, 14 => AUGP}
|
12
39
|
}
|
40
|
+
|
13
41
|
end
|
data/lib/music-utils/version.rb
CHANGED
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.
|
4
|
+
version: 1.0.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-
|
12
|
+
date: 2011-05-08 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement: &
|
16
|
+
requirement: &83068570 !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: *
|
24
|
+
version_requirements: *83068570
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: bundler
|
27
|
-
requirement: &
|
27
|
+
requirement: &83068380 !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: *
|
35
|
+
version_requirements: *83068380
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &83109790 !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: *
|
46
|
+
version_requirements: *83109790
|
47
47
|
description: Utils for music. At the moment only to classify intervals.
|
48
48
|
email:
|
49
49
|
- jorgeluis700@gmail.com
|
@@ -57,6 +57,7 @@ files:
|
|
57
57
|
- LICENSE
|
58
58
|
- README.md
|
59
59
|
- Rakefile
|
60
|
+
- benchmark/music-utils_bm.rb
|
60
61
|
- lib/music-utils.rb
|
61
62
|
- lib/music-utils/interval/interval.rb
|
62
63
|
- lib/music-utils/scales/scales.rb
|