key_change 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/key_change.rb +52 -91
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a54f17413b6a34e150c7004034f67f7bbf00703
|
4
|
+
data.tar.gz: a8651b1b3c5c44f355630d661c0dd66e442a17f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ec0e319e3247508228a12416b1dc9a1c795e764e4a71f6a123e1f24b5b1ead7b9229fae355c12f15b33a5db0e49ccaefb778b5fa488c529752280b8fe36e12e
|
7
|
+
data.tar.gz: 88ccc06a6c2b087474c44f81406fa982057c4267ea57e76b030c3be6d5c86aabb6c01b8e846768c829a77cab475c7d29901983d1b66fa88600d83959da6aad71
|
data/lib/key_change.rb
CHANGED
@@ -1,56 +1,48 @@
|
|
1
|
+
# 必要な変数の定義
|
2
|
+
NOTES_SHARP = ["C", "C♯", "D", "D♯", "E", "F", "F♯", "G", "G♯", "A", "A♯", "B"]
|
3
|
+
NOTES_FLAT = ["C", "D♭", "D", "E♭", "E", "F", "G♭", "G", "A♭", "A", "B♭", "B"]
|
4
|
+
|
1
5
|
# 便利なファンクションの定義
|
2
|
-
def
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
6
|
+
def sharp? (note)
|
7
|
+
note.match(/♯/) || note.match(/#/)
|
8
|
+
end
|
9
|
+
|
10
|
+
def flat? (note)
|
11
|
+
note.match(/♭/) || note.match(/b/)
|
12
|
+
end
|
13
|
+
|
14
|
+
# 「b」か「#」であったら変換されます
|
15
|
+
def replace(note)
|
16
|
+
if sharp?(note)
|
17
|
+
note.gsub!(/#/, "♯")
|
18
|
+
elsif flat?(note)
|
19
|
+
note.gsub!(/b/, "♭")
|
7
20
|
end
|
8
21
|
end
|
9
22
|
|
10
|
-
|
11
|
-
|
12
|
-
|
23
|
+
# noteの位置を調べて返します
|
24
|
+
# C と C♯ の差で (position = 1 - 0) にならないように「1」を足します
|
25
|
+
def note_position(note)
|
26
|
+
if flat?(note)
|
27
|
+
NOTES_FLAT.index(note) + 1
|
13
28
|
else
|
14
|
-
|
29
|
+
NOTES_SHARP.index(note) + 1
|
15
30
|
end
|
16
31
|
end
|
17
32
|
|
33
|
+
# 主要のメソッド
|
34
|
+
def change (original_chords, old_key, new_key, option)
|
18
35
|
|
19
|
-
|
20
|
-
def Change (chords, old_key, new_key, option)
|
21
|
-
|
22
|
-
# 必要な変数の定義
|
23
|
-
notes_sharp = ["C", "C♯", "D", "D♯", "E", "F", "F♯", "G", "G♯", "A", "A♯", "B"]
|
24
|
-
notes_flat = ["C", "D♭", "D", "E♭", "E", "F", "G♭", "G", "A♭", "A", "B♭", "B"]
|
25
|
-
new_chords = []
|
36
|
+
chords = Marshal.load(Marshal.dump(original_chords))
|
26
37
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
old_key.gsub!(/\b/, "♭")
|
32
|
-
end
|
33
|
-
|
34
|
-
if Sharp?(new_key)
|
35
|
-
new_key.gsub!(/\#/, "♯")
|
36
|
-
elsif Flat?(new_key)
|
37
|
-
new_key.gsub!(/b/, "♭")
|
38
|
+
replace(old_key)
|
39
|
+
replace(new_key)
|
40
|
+
chords.each do |chord|
|
41
|
+
replace(chord)
|
38
42
|
end
|
39
43
|
|
40
|
-
|
41
|
-
|
42
|
-
if Flat? (old_key)
|
43
|
-
old_key_position = notes_flat.index(old_key) + 1
|
44
|
-
else
|
45
|
-
old_key_position = notes_sharp.index(old_key) + 1
|
46
|
-
end
|
47
|
-
|
48
|
-
# 新しい方も
|
49
|
-
if Flat? (new_key)
|
50
|
-
new_key_position = notes_flat.index(new_key) + 1
|
51
|
-
else
|
52
|
-
new_key_position = notes_sharp.index(new_key) + 1
|
53
|
-
end
|
44
|
+
old_key_position = note_position(old_key)
|
45
|
+
new_key_position = note_position(new_key)
|
54
46
|
|
55
47
|
# キーの差を計算する
|
56
48
|
if new_key_position == old_key_position
|
@@ -63,14 +55,7 @@ def Change (chords, old_key, new_key, option)
|
|
63
55
|
key_up = true
|
64
56
|
end
|
65
57
|
|
66
|
-
chords.
|
67
|
-
|
68
|
-
# メソッドが終わってもオリジナルのコードが影響を受けてgsub!されるので注意してください
|
69
|
-
if Sharp?(chord)
|
70
|
-
chord.gsub!(/\#/, "♯")
|
71
|
-
elsif Flat?(chord)
|
72
|
-
chord.gsub!(/b/, "♭")
|
73
|
-
end
|
58
|
+
chords.map do |chord|
|
74
59
|
|
75
60
|
addition = ""
|
76
61
|
case chord
|
@@ -102,48 +87,26 @@ def Change (chords, old_key, new_key, option)
|
|
102
87
|
addition = "aug"
|
103
88
|
when /11/ then
|
104
89
|
addition = "11"
|
105
|
-
|
106
90
|
end
|
91
|
+
|
107
92
|
# chord を上手く計算するために、addition を chord から取り除く
|
108
93
|
if addition != ""
|
109
94
|
chord.gsub!(addition, "")
|
110
95
|
end
|
111
96
|
|
112
|
-
|
113
|
-
|
97
|
+
original_position = note_position(chord)
|
114
98
|
if key_up == true
|
115
|
-
|
116
|
-
|
117
|
-
new_position
|
118
|
-
if new_position > 12
|
119
|
-
new_position -= 12
|
120
|
-
end
|
121
|
-
new_position -= 1
|
122
|
-
else
|
123
|
-
original_position = notes_sharp.index(chord) + 1
|
124
|
-
new_position = original_position + difference
|
125
|
-
if new_position > 12
|
126
|
-
new_position -= 12
|
127
|
-
end
|
128
|
-
new_position -= 1
|
99
|
+
new_position = original_position + difference
|
100
|
+
if new_position > 12
|
101
|
+
new_position -= 12
|
129
102
|
end
|
130
103
|
else # key_up == false
|
131
|
-
|
132
|
-
|
133
|
-
new_position
|
134
|
-
if new_position < 1
|
135
|
-
new_position += 12
|
136
|
-
end
|
137
|
-
new_position -= 1
|
138
|
-
else
|
139
|
-
original_position = notes_sharp.index(chord) + 1
|
140
|
-
new_position = original_position - difference
|
141
|
-
if new_position < 1
|
142
|
-
new_position += 12
|
143
|
-
end
|
144
|
-
new_position -= 1
|
104
|
+
new_position = original_position - difference
|
105
|
+
if new_position < 1
|
106
|
+
new_position += 12
|
145
107
|
end
|
146
108
|
end
|
109
|
+
new_position -= 1
|
147
110
|
|
148
111
|
if option == :default
|
149
112
|
option = :sharp
|
@@ -151,25 +114,23 @@ def Change (chords, old_key, new_key, option)
|
|
151
114
|
|
152
115
|
case option
|
153
116
|
when :sharp then
|
154
|
-
if
|
155
|
-
|
117
|
+
if flat?(chord)
|
118
|
+
NOTES_FLAT[new_position] + addition
|
156
119
|
else
|
157
|
-
|
120
|
+
NOTES_SHARP[new_position] + addition
|
158
121
|
end
|
159
122
|
when :flat then
|
160
|
-
if
|
161
|
-
|
123
|
+
if sharp?(chord)
|
124
|
+
NOTES_SHARP[new_position] + addition
|
162
125
|
else
|
163
|
-
|
126
|
+
NOTES_FLAT[new_position] + addition
|
164
127
|
end
|
165
128
|
when :all_sharp then
|
166
|
-
|
129
|
+
NOTES_SHARP[new_position] + addition
|
167
130
|
when :all_flat then
|
168
|
-
|
131
|
+
NOTES_FLAT[new_position] + addition
|
169
132
|
end
|
170
133
|
|
171
|
-
end #chords.
|
172
|
-
|
173
|
-
return new_chords
|
134
|
+
end #chords.mapの終わり
|
174
135
|
|
175
136
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: key_change
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabriel Arcangel Zayas
|
@@ -11,9 +11,8 @@ cert_chain: []
|
|
11
11
|
date: 2016-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |-
|
14
|
-
|
15
|
-
|
16
|
-
音楽のchordの配列を楽に転調する。詳細はこちら:https://github.com/gazayas/key_change
|
14
|
+
Music key change. Please visit the following link for documentation: https://github.com/gazayas/key_change
|
15
|
+
Rubyで転調を行う。詳細はこちら:https://github.com/gazayas/key_change
|
17
16
|
email: g-zayas@hotmail.com
|
18
17
|
executables: []
|
19
18
|
extensions: []
|