key_change 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/key_change.rb +175 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e9bfc6b47c91ccf65c17feba58b638104b3f190a
|
4
|
+
data.tar.gz: 321c735ca9c0cd2c8fb453abc6e42010448fb9e1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4c8fdaf73f7e931cc8c187e6b4593f7333b21a503050ae760f1d760c8e2d87ac1acf82e61aaf89f0ce9d7f44a469e49d5cc01a72a2f741ebdc5b7af4bac3a021
|
7
|
+
data.tar.gz: e6f10d45200e330f2246499b5ba92d38c5efa95c76bf9947acd37016add6b0a4b1fde207d5bb74aeefeeb4eecd44cfc8653485ceb3af1e216aa4c87040eaa539
|
data/lib/key_change.rb
ADDED
@@ -0,0 +1,175 @@
|
|
1
|
+
# 便利なファンクションの定義
|
2
|
+
def Sharp? (note)
|
3
|
+
if note.match(/♯/) || note.match(/\#/)
|
4
|
+
return true
|
5
|
+
else
|
6
|
+
return false
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def Flat? (note)
|
11
|
+
if note.match(/♭/) || note.match(/b/)
|
12
|
+
return true
|
13
|
+
else
|
14
|
+
return false
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
|
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 = []
|
26
|
+
|
27
|
+
# b か # であったら変換してくれる
|
28
|
+
if Sharp?(old_key)
|
29
|
+
old_key.gsub!(/\#/, "♯")
|
30
|
+
elsif Flat?(old_key)
|
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
|
+
end
|
39
|
+
|
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
|
54
|
+
|
55
|
+
# キーの差を計算する
|
56
|
+
if new_key_position == old_key_position
|
57
|
+
return chords
|
58
|
+
elsif new_key_position < old_key_position
|
59
|
+
difference = old_key_position - new_key_position
|
60
|
+
key_up = false
|
61
|
+
else
|
62
|
+
difference = new_key_position - old_key_position
|
63
|
+
key_up = true
|
64
|
+
end
|
65
|
+
|
66
|
+
chords.each do |chord|
|
67
|
+
|
68
|
+
# メソッドが終わってもオリジナルのコードが影響を受けてgsub!されるので注意してください
|
69
|
+
if Sharp?(chord)
|
70
|
+
chord.gsub!(/\#/, "♯")
|
71
|
+
elsif Flat?(chord)
|
72
|
+
chord.gsub!(/b/, "♭")
|
73
|
+
end
|
74
|
+
|
75
|
+
addition = ""
|
76
|
+
case chord
|
77
|
+
when /dim7/ then
|
78
|
+
addition = "dim7"
|
79
|
+
when /dim/ then
|
80
|
+
addition = "dim"
|
81
|
+
when /2/ then
|
82
|
+
addition = "2"
|
83
|
+
when /sus4/ then
|
84
|
+
addition = "sus4"
|
85
|
+
when /sus/ then
|
86
|
+
addition = "sus"
|
87
|
+
when /maj7/ then
|
88
|
+
addition = "maj7"
|
89
|
+
when /maj/ then
|
90
|
+
addition = "maj"
|
91
|
+
when /m7/ then
|
92
|
+
addition = "m7"
|
93
|
+
when /m/ then
|
94
|
+
addition = "m"
|
95
|
+
when /7/ then
|
96
|
+
addition = "7"
|
97
|
+
when /6/ then
|
98
|
+
addition = "6"
|
99
|
+
when /9/ then
|
100
|
+
addition = "9"
|
101
|
+
when /aug/ then
|
102
|
+
addition = "aug"
|
103
|
+
when /11/ then
|
104
|
+
addition = "11"
|
105
|
+
|
106
|
+
end
|
107
|
+
# chord を上手く計算するために、addition を chord から取り除く
|
108
|
+
if addition != ""
|
109
|
+
chord.gsub!(addition, "")
|
110
|
+
end
|
111
|
+
|
112
|
+
|
113
|
+
|
114
|
+
if key_up == true
|
115
|
+
if Flat?(chord)
|
116
|
+
original_position = notes_flat.index(chord) + 1
|
117
|
+
new_position = original_position + difference
|
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
|
129
|
+
end
|
130
|
+
else # key_up == false
|
131
|
+
if Flat?(chord)
|
132
|
+
original_position = notes_flat.index(chord) + 1
|
133
|
+
new_position = original_position - difference
|
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
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
if option == :default
|
149
|
+
option = :sharp
|
150
|
+
end
|
151
|
+
|
152
|
+
case option
|
153
|
+
when :sharp then
|
154
|
+
if Flat?(chord)
|
155
|
+
new_chords << notes_flat[new_position] + addition
|
156
|
+
else
|
157
|
+
new_chords << notes_sharp[new_position] + addition
|
158
|
+
end
|
159
|
+
when :flat then
|
160
|
+
if Sharp?(chord)
|
161
|
+
new_chords << notes_sharp[new_position] + addition
|
162
|
+
else
|
163
|
+
new_chords << notes_flat[new_position] + addition
|
164
|
+
end
|
165
|
+
when :all_sharp then
|
166
|
+
new_chords << notes_sharp[new_position] + addition
|
167
|
+
when :all_flat then
|
168
|
+
new_chords << notes_flat[new_position] + addition
|
169
|
+
end
|
170
|
+
|
171
|
+
end #chords.eachの終わり
|
172
|
+
|
173
|
+
return new_chords
|
174
|
+
|
175
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: key_change
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gabriel Arcangel Zayas
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-07-17 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: |-
|
14
|
+
Change the chords of an array of any length by providing the array, the original key and the new key in the arguments of the function
|
15
|
+
Please visit the following link for documentation: https://github.com/gazayas/key_change
|
16
|
+
音楽のchordの配列を楽に転調する。詳細はこちら:https://github.com/gazayas/key_change
|
17
|
+
email: g-zayas@hotmail.com
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- lib/key_change.rb
|
23
|
+
homepage: http://www.sanbika.jp
|
24
|
+
licenses: []
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 2.5.1
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: Do a key change in music
|
46
|
+
test_files: []
|