musician 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/files/chord.rb +29 -34
- data/lib/files/note.rb +12 -11
- data/lib/files/song.rb +18 -5
- data/lib/musician.rb +1 -1
- 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: 9aa91808647c10fa546b0ec0fc1994afa5585578
|
4
|
+
data.tar.gz: 78a4be48e645e66c76103c3ba63da2b46fda4301
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b09a4cd13a9b2185057f26ff8c2391ca43be1022714de3ff50686a278e096209141359b9ecefb3f3125f18c676f669db66a2976deafab8d9d8aec47eaa373747
|
7
|
+
data.tar.gz: 246c1ba61b6f4421e3e127f726343b3b886b63d5ebb0c2b5fa585c1277aba8227a5cee1ffb026dc1d5ea1a743d3a3b35489a13c64e1711f9330e70fcf66bcbca
|
data/lib/files/chord.rb
CHANGED
@@ -2,59 +2,54 @@ class Chord < Note
|
|
2
2
|
|
3
3
|
attr_accessor :name, :raw_name, :addition
|
4
4
|
|
5
|
-
def initialize(
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
|
11
|
-
|
12
|
-
#
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
@
|
17
|
-
@addition = raw_elements[1]
|
18
|
-
@name = name
|
19
|
-
@name = change_symbol
|
5
|
+
def initialize(initial_name)
|
6
|
+
# Chord.name と Note.name はそもそも違うものなのでOOPにおいては良くないかもしれない
|
7
|
+
# こう: 「Note.name #=> "G"」 「Chord.name #=> "Gm7"」
|
8
|
+
# でも、Note.nameとChord.nameは分かりやすいので、これで行きます。
|
9
|
+
# そのために、Noteのインスタンス変数をadditionなしで作ってから、name, raw_nameとadditionを定義しています。
|
10
|
+
|
11
|
+
raw_elements = sanitize(initial_name)
|
12
|
+
super(raw_elements[:raw_name]) # Noteのインスタンス変数を作る
|
13
|
+
|
14
|
+
@name = change_symbol(initial_name)
|
15
|
+
@raw_name = change_symbol(raw_elements[:raw_name])
|
16
|
+
@addition = raw_elements[:addition]
|
20
17
|
end
|
21
18
|
|
22
|
-
# note.rbだけで置くようにしたいけど、raw_nameが。。。
|
23
19
|
def position
|
24
20
|
if sharp?
|
25
|
-
SHARP_CHORDS.index(raw_name)
|
21
|
+
SHARP_CHORDS.index(@raw_name)
|
26
22
|
else
|
27
|
-
FLAT_CHORDS.index(raw_name)
|
23
|
+
FLAT_CHORDS.index(@raw_name)
|
28
24
|
end
|
29
25
|
end
|
30
26
|
|
31
27
|
private
|
32
|
-
def
|
28
|
+
def sanitize(initial_name)
|
33
29
|
|
34
|
-
|
35
|
-
|
30
|
+
raw_elements = {
|
31
|
+
raw_name: String.new,
|
32
|
+
addition: String.new
|
33
|
+
}
|
36
34
|
|
37
|
-
# addition
|
35
|
+
# intial_nameにはadditionがあるかどうか確認する
|
38
36
|
finished_search = false
|
39
|
-
until !addition.empty? || finished_search == true
|
40
|
-
ADDITIONS.each do |
|
41
|
-
regexp = Regexp.new(
|
42
|
-
|
43
|
-
|
44
|
-
addition =
|
45
|
-
raw << name.gsub(add, "")
|
46
|
-
raw << add
|
37
|
+
until !(raw_elements[:addition].empty?) || finished_search == true
|
38
|
+
ADDITIONS.each do |addition|
|
39
|
+
regexp = Regexp.new(addition)
|
40
|
+
if initial_name.match(regexp)
|
41
|
+
raw_elements[:raw_name] = initial_name.gsub(addition, "")
|
42
|
+
raw_elements[:addition] = addition
|
47
43
|
break
|
48
44
|
end
|
49
45
|
end
|
50
46
|
# もしadditionがなければ、nameをそのまま返して、additionが空の配列のまま返す
|
51
|
-
if addition.empty?
|
52
|
-
|
53
|
-
raw << addition
|
47
|
+
if raw_elements[:addition].empty?
|
48
|
+
raw_elements[:raw_name] = initial_name
|
54
49
|
end
|
55
50
|
finished_search = true
|
56
51
|
end
|
57
|
-
|
52
|
+
raw_elements
|
58
53
|
end
|
59
54
|
|
60
55
|
end
|
data/lib/files/note.rb
CHANGED
@@ -3,29 +3,30 @@ class Note
|
|
3
3
|
attr_accessor :name
|
4
4
|
|
5
5
|
def initialize(name)
|
6
|
-
@name = name
|
7
|
-
@name = change_symbol
|
6
|
+
@name = change_symbol(name)
|
8
7
|
end
|
9
8
|
|
10
|
-
|
11
|
-
@name = @name.tr("#b", "#{Sharp}#{Flat}") # gsub()の変わりに「tr」を使ってる(・ω・)
|
12
|
-
end
|
13
|
-
|
14
|
-
# Noteを初期化する時に#は♯に変換されるから両方が要るかな。。。
|
9
|
+
# 「#」と「b」要らんと思う
|
15
10
|
def sharp?
|
16
|
-
|
11
|
+
!!@name.match(/#/) || !!@name.match(/♯/) # 真偽を返して欲しかった「!!」を入れました
|
17
12
|
end
|
18
13
|
|
19
14
|
def flat?
|
20
|
-
|
15
|
+
!!@name.match(/b/) || !!@name.match(/♭/)
|
21
16
|
end
|
22
17
|
|
23
18
|
def position
|
24
19
|
if sharp?
|
25
|
-
SHARP_CHORDS.index(name)
|
20
|
+
SHARP_CHORDS.index(@name)
|
26
21
|
else
|
27
|
-
FLAT_CHORDS.index(name)
|
22
|
+
FLAT_CHORDS.index(@name)
|
28
23
|
end
|
29
24
|
end
|
30
25
|
|
26
|
+
private
|
27
|
+
|
28
|
+
def change_symbol(note)
|
29
|
+
note = note.tr("#b", "#{Sharp}#{Flat}") # gsub()の変わりに「tr」を使ってる(・ω・)
|
30
|
+
end
|
31
|
+
|
31
32
|
end
|
data/lib/files/song.rb
CHANGED
@@ -2,12 +2,23 @@ class Song
|
|
2
2
|
|
3
3
|
attr_accessor :key, :chords, :title, :tempo
|
4
4
|
|
5
|
-
|
5
|
+
|
6
6
|
def initialize(key, chords)
|
7
|
-
|
7
|
+
# 文字列かChordのインスタンス変数、両方で定義できるように
|
8
|
+
unless key.instance_of? Chord
|
9
|
+
@key = Chord.new(key)
|
10
|
+
else
|
11
|
+
@key = key
|
12
|
+
end
|
13
|
+
|
8
14
|
@chords = chords.map do |chord|
|
9
|
-
Chord
|
15
|
+
unless chord.instance_of? Chord
|
16
|
+
Chord.new(chord)
|
17
|
+
else
|
18
|
+
chord
|
19
|
+
end
|
10
20
|
end
|
21
|
+
|
11
22
|
# 作る時に定義しなくていいけど、一応自分で定義できる
|
12
23
|
@title = ""
|
13
24
|
@tempo = ""
|
@@ -20,8 +31,10 @@ class Song
|
|
20
31
|
end
|
21
32
|
|
22
33
|
def key_change(new_key, option=:sharp)
|
23
|
-
|
24
|
-
new_key
|
34
|
+
|
35
|
+
unless new_key.instance_of? Chord
|
36
|
+
new_key = Chord.new(new_key)
|
37
|
+
end
|
25
38
|
|
26
39
|
if key.position < new_key.position
|
27
40
|
key_up = true
|
data/lib/musician.rb
CHANGED
@@ -2,7 +2,7 @@ Sharp = "♯"
|
|
2
2
|
Flat = "♭"
|
3
3
|
SHARP_CHORDS = ["C", "C♯", "D", "D♯", "E", "F", "F♯", "G", "G♯", "A", "A♯", "B"]
|
4
4
|
FLAT_CHORDS = ["C", "D♭", "D", "E♭", "E", "F", "G♭", "G", "A♭", "A", "B♭", "B"]
|
5
|
-
ADDITIONS = ["
|
5
|
+
ADDITIONS = ["add2", "add9", "dim7", "dim", "sus4", "sus", "maj7", "maj", "m7", "m", "aug", "2", "6", "7", "9", "11"]
|
6
6
|
|
7
7
|
require 'files/note'
|
8
8
|
require 'files/chord'
|