key_change 1.0.2 → 2.0.0
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.
- checksums.yaml +4 -4
- data/lib/key_change.rb +11 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 769ca9ac9405e435ddf348e8e530458efbe02787
|
4
|
+
data.tar.gz: 1a8f3f9b61495c601f2549eb75f08b3070043ad4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9015c4bb4b48effe4c705f4864a534695a77b9aa6b7a73e3955c03094a4b8d5d8ea61cdf80b22bbec328daf98be5946d4646d06a372a76ee087f5da77181b7a9
|
7
|
+
data.tar.gz: ea6668f80851904eb7fc25618c35fdbe7971643199f8f0540fbbab98fb67b0a2c661601301d64d5ad69dd5d8791a3696bc73a6bcc5c466d33cdf15a786141094
|
data/lib/key_change.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
NOTES_SHARP = ["C", "C♯", "D", "D♯", "E", "F", "F♯", "G", "G♯", "A", "A♯", "B"]
|
3
3
|
NOTES_FLAT = ["C", "D♭", "D", "E♭", "E", "F", "G♭", "G", "A♭", "A", "B♭", "B"]
|
4
4
|
|
5
|
-
#
|
5
|
+
# 便利なメソッドの定義
|
6
6
|
def sharp? (note)
|
7
7
|
note.match(/♯/) || note.match(/#/)
|
8
8
|
end
|
@@ -22,7 +22,7 @@ end
|
|
22
22
|
|
23
23
|
# noteの位置を調べて返します
|
24
24
|
# C と C♯ の差で (position = 1 - 0) にならないように「1」を足します
|
25
|
-
def
|
25
|
+
def position_of(note)
|
26
26
|
if flat?(note)
|
27
27
|
NOTES_FLAT.index(note) + 1
|
28
28
|
else
|
@@ -41,8 +41,8 @@ def change (original_chords, old_key, new_key, option)
|
|
41
41
|
replace(chord)
|
42
42
|
end
|
43
43
|
|
44
|
-
old_key_position =
|
45
|
-
new_key_position =
|
44
|
+
old_key_position = position_of(old_key)
|
45
|
+
new_key_position = position_of(new_key)
|
46
46
|
|
47
47
|
# キーの差を計算する
|
48
48
|
if new_key_position == old_key_position
|
@@ -57,6 +57,11 @@ def change (original_chords, old_key, new_key, option)
|
|
57
57
|
|
58
58
|
chords.map do |chord|
|
59
59
|
|
60
|
+
if chord.match(/\//) # D/F♯みたいなコードの場合はコードを分解してから再起で新しいコードを取得して、その二つの文字列を連結する
|
61
|
+
split_chords = chord.split("/")
|
62
|
+
new_split_chords = change(split_chords, old_key, new_key, option)
|
63
|
+
chord = new_split_chords[0] + "/" + new_split_chords[1]
|
64
|
+
else
|
60
65
|
addition = ""
|
61
66
|
case chord
|
62
67
|
when /dim7/ then
|
@@ -94,7 +99,7 @@ def change (original_chords, old_key, new_key, option)
|
|
94
99
|
chord.gsub!(addition, "")
|
95
100
|
end
|
96
101
|
|
97
|
-
original_position =
|
102
|
+
original_position = position_of(chord)
|
98
103
|
if key_up == true
|
99
104
|
new_position = original_position + difference
|
100
105
|
if new_position > 12
|
@@ -130,7 +135,7 @@ def change (original_chords, old_key, new_key, option)
|
|
130
135
|
when :all_flat then
|
131
136
|
NOTES_FLAT[new_position] + addition
|
132
137
|
end
|
133
|
-
|
138
|
+
end # 配列か一つの要素だけを認識するif・else文の終わり
|
134
139
|
end #chords.mapの終わり
|
135
140
|
|
136
141
|
end
|