music-utils 0.5.1 → 0.5.2
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/lib/interval.rb +38 -27
- data/music-utils.gemspec +1 -1
- metadata +5 -5
data/lib/interval.rb
CHANGED
@@ -25,22 +25,14 @@ class Interval
|
|
25
25
|
# It classifies the diatonic interval
|
26
26
|
def number
|
27
27
|
# initialize counter and index of scale
|
28
|
-
i =
|
28
|
+
i = note1_index
|
29
29
|
count = 1
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
count += 1; i += 1
|
34
|
-
end
|
35
|
-
|
31
|
+
count, i = no_unison(count, i)
|
32
|
+
|
36
33
|
# Counting notes
|
37
|
-
|
38
|
-
|
39
|
-
if i > DIATONIC_SCALE.length
|
40
|
-
i = 0; next
|
41
|
-
end
|
42
|
-
count += 1
|
43
|
-
end
|
34
|
+
until_find_note2(i) { count += 1 }
|
35
|
+
|
44
36
|
count = count + (8 * @step) - 1 if @step > 0
|
45
37
|
count
|
46
38
|
end
|
@@ -48,21 +40,13 @@ class Interval
|
|
48
40
|
# Returns the number of semitones
|
49
41
|
def semitone
|
50
42
|
# initialize counter and index of scale
|
51
|
-
i =
|
43
|
+
i = note1_index
|
52
44
|
count = 0
|
53
45
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
# Counting semi-tones
|
60
|
-
while DIATONIC_SCALE[i] != @note2[0..1]
|
61
|
-
i += 1
|
62
|
-
if i > DIATONIC_SCALE.length
|
63
|
-
i = 0; next
|
64
|
-
end
|
65
|
-
|
46
|
+
count, i = no_unison(count, i)
|
47
|
+
|
48
|
+
# counting semi-tones
|
49
|
+
until_find_note2(i) do |i|
|
66
50
|
# from 'mi' to 'fa' and 'si' to 'do' there 1 semi-tone
|
67
51
|
if DIATONIC_SCALE[i] == 'fa' or DIATONIC_SCALE[i] == 'do'
|
68
52
|
count += 1
|
@@ -73,7 +57,7 @@ class Interval
|
|
73
57
|
|
74
58
|
count = count + (12 * @step) if @step > 0
|
75
59
|
|
76
|
-
#
|
60
|
+
# counting notes alterations
|
77
61
|
alter = @note1[2..3]
|
78
62
|
|
79
63
|
alter.each_char do |c|
|
@@ -102,5 +86,32 @@ class Interval
|
|
102
86
|
def short
|
103
87
|
quality + number.to_s
|
104
88
|
end
|
89
|
+
|
90
|
+
private
|
91
|
+
|
92
|
+
# Common loop to search note 2
|
93
|
+
def until_find_note2(i)
|
94
|
+
# search note2
|
95
|
+
while DIATONIC_SCALE[i] != @note2[0..1]
|
96
|
+
i += 1
|
97
|
+
if i > DIATONIC_SCALE.length
|
98
|
+
i = 0; next
|
99
|
+
end
|
100
|
+
yield i
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
# Jumps to the next note if note 1 and note 2 are the same
|
105
|
+
def no_unison(count, i)
|
106
|
+
if @note1[0..1] == @note2[0..1]
|
107
|
+
count += 1; i += 1
|
108
|
+
end
|
109
|
+
[count, i]
|
110
|
+
end
|
111
|
+
|
112
|
+
# Returns index of note 1
|
113
|
+
def note1_index
|
114
|
+
DIATONIC_SCALE.index(@note1[0..1])
|
115
|
+
end
|
105
116
|
|
106
117
|
end
|
data/music-utils.gemspec
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: 0.5.
|
4
|
+
version: 0.5.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-04-
|
12
|
+
date: 2011-04-29 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &24028992 !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: *
|
24
|
+
version_requirements: *24028992
|
25
25
|
description: Utils for music. At the moment only one class to classify intervals.
|
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:
|
57
|
+
hash: 934369633
|
58
58
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
59
|
none: false
|
60
60
|
requirements:
|