musician 0.0.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 17f0c98a088bdcda6656d0cd23d8b04ca135914d
4
- data.tar.gz: 82cb2aaa56e67a79f149b7f327ee28e49dafdb51
3
+ metadata.gz: d5a0602cfef96b5fb12983bfb55be1cd1e994276
4
+ data.tar.gz: 96507362f14c35912bb1d968dc3f5193463e022e
5
5
  SHA512:
6
- metadata.gz: 99a256418060cd47e9ab83ceb97ab3fbf0f26f85c909fffe91fdc3061292a9f7794fcc73b0331ebdf21cc409f487b8851e722f0a3116bf5083cd4f5f32ead8f3
7
- data.tar.gz: faa93b524d746c122d14998dab993e3de043d6a835a471d8156d414abdbe9b8065d2057a9b0d2c83d07640aa180693ee84bfd68d9d185e48884dd045e199cc8a
6
+ metadata.gz: 69bf88c781e38ce655df9d4fbd39a3b49848d661852e0c6a7cec168dff09430be6c87c90950ab23a3e9179430d409c1d9f75679b760a72b4c7927e289bc36ef9
7
+ data.tar.gz: 134b786f32e78043edbd4e1357b0a481b493fcaccbdd40682d5ad3dc7a0cbd13c33b8290302ad64663785f06480db7057b18a3989f3ead89adcdc1dba082eefd
data/lib/files/chord.rb CHANGED
@@ -1,86 +1,60 @@
1
- class Chord
1
+ class Chord < Note
2
2
 
3
- Sharp = "♯"
4
- Flat = "♭"
5
-
6
- attr_accessor :name, :sanitized_name, :addition
7
- attr_reader :Sharp_chords, :Flat_chords
3
+ attr_accessor :name, :raw_name, :addition
8
4
 
9
5
  def initialize(name)
10
- name = name.tr("#b", "#{Sharp}#{Flat}") # gsub()の変わりに「tr」を使ってる(・ω・)
6
+ # ちょっとややこしいし良くないかもしれないけど、
7
+ # 一応 @name が chord の name になってて、@raw_name が addition (maj7, dim とか)なしの name
8
+ # こう: @name #=> "G♭m" @raw_name #=> "G♭"
9
+ # でも、Note.name は普通は maj7 や dim とかはないから、OOP においては Chord.name はおかしいかもしれない
10
+ # Note.name は Chord.name と違うので、OOPの考え方においては良くないかもしれない。
11
+ # でも、Note.name と Chord.name はバリ分かりやすいと思うのでそのようにしたい。
12
+ # とりあえす、Chord.name は Note.name とは違うという風に書いています。
11
13
  @name = name
12
- sanitized_elements = sanitize_method
13
- @sanitized_name = sanitized_elements[0]
14
- @addition = sanitized_elements[1]
15
- @Sharp_chords = ["C", "C♯", "D", "D♯", "E", "F", "F♯", "G", "G♯", "A", "A♯", "B"]
16
- @Flat_chords = ["C", "D♭", "D", "E♭", "E", "F", "G♭", "G", "A♭", "A", "B♭", "B"]
17
- end
18
-
19
- # 真偽を返して欲しかったから次のように書きました
20
- def sharp?
21
- !!name.match(/#/) || !!name.match(/♯/)
22
- end
23
-
24
- def flat?
25
- !!name.match(/b/) || !!name.match(/♭/)
14
+ raw_elements = sanitize_method
15
+ super(raw_elements[0]) # 一応 raw_name で Note のインスタンス変数を作る
16
+ @raw_name = change_symbol
17
+ @addition = raw_elements[1]
18
+ @name = name
19
+ @name = change_symbol
26
20
  end
27
21
 
22
+ # note.rbだけで置くようにしたいけど、raw_nameが。。。
28
23
  def position
29
- # 1を足す理由は、key_changeの中で使うためです
30
- # 1が足されないと計算がうまくできないから
31
- # そして配列が正しく定義されるように、new_position -= 1 を def key_change ... end の中に行う
32
24
  if sharp?
33
- @Sharp_chords.index(sanitized_name)
25
+ SHARP_CHORDS.index(raw_name)
34
26
  else
35
- @Flat_chords.index(sanitized_name)
27
+ FLAT_CHORDS.index(raw_name)
36
28
  end
37
29
  end
38
30
 
39
31
  private
40
32
  def sanitize_method
41
33
 
42
- addition = ""
43
-
44
- case name
45
- when /dim7/ then
46
- addition = "dim7"
47
- when /dim/ then
48
- addition = "dim"
49
- when /2/ then
50
- addition = "2"
51
- when /sus4/ then
52
- addition = "sus4"
53
- when /sus/ then
54
- addition = "sus"
55
- when /maj7/ then
56
- addition = "maj7"
57
- when /maj/ then
58
- addition = "maj"
59
- when /m7/ then
60
- addition = "m7"
61
- when /m/ then
62
- addition = "m"
63
- when /7/ then
64
- addition = "7"
65
- when /6/ then
66
- addition = "6"
67
- when /9/ then
68
- addition = "9"
69
- when /aug/ then
70
- addition = "aug"
71
- when /11/ then
72
- addition = "11"
34
+ addition = String.new
35
+ raw = Array.new
36
+
37
+ # additionがあるか確認する
38
+ finished_search = false
39
+ until !addition.empty? || finished_search == true
40
+ ADDITIONS.each do |add|
41
+ regexp = Regexp.new(add)
42
+ raw = Array.new
43
+ if name.match(regexp)
44
+ addition = add
45
+ raw << name.gsub(add, "")
46
+ raw << add
47
+ break
48
+ end
49
+ end
50
+ # もしadditionがなければ、nameをそのまま返して、additionが空の配列のまま返す
51
+ if addition.empty?
52
+ raw << name
53
+ raw << addition
54
+ end
55
+ finished_search = true
73
56
  end
74
-
75
- sanitized_chord_array = []
76
- if addition != ""
77
- sanitized_chord_array << name.gsub(addition, "")
78
- sanitized_chord_array << addition
79
- else
80
- sanitized_chord_array << name
81
- sanitized_chord_array << ""
82
- end
83
-
57
+ raw
84
58
  end
85
59
 
86
60
  end
data/lib/files/music.rb CHANGED
@@ -1,29 +1,9 @@
1
1
  class Music
2
2
 
3
+ # whole restとか、half noteとかは見つけられないのでこのクラスを消すかな
3
4
  def initialize
4
5
  @quarter_note = "♩"
5
- @half_note = ""
6
- @whole_note = ""
7
- @eight_note = "♪"
8
- @sixteenth_note = ""
6
+ @eighth_note = ""
9
7
  end
10
8
 
11
- # この中にメソッドを作るかは分からないけど、
12
- # とにかく普通のキーボードで書けないシンボルを使えるようにする
13
-
14
- # Song.rbの方にはテンポがあるけど。。。
15
-
16
- def add_notes(note1, note2)
17
- # この中に、
18
- note1 = "♪"
19
- note2 = "♪"
20
- new_note = note1 + note2
21
- # をして、返すのは
22
- "♩"
23
- # みたいな感じのメソッドはどうかな
24
- # 今の段階ではそんなにいらないけど、一応役に立つと思う
25
-
26
- end
27
-
28
-
29
9
  end
data/lib/files/note.rb ADDED
@@ -0,0 +1,31 @@
1
+ class Note
2
+
3
+ attr_accessor :name
4
+
5
+ def initialize(name)
6
+ @name = name
7
+ @name = change_symbol
8
+ end
9
+
10
+ def change_symbol
11
+ @name = @name.tr("#b", "#{Sharp}#{Flat}") # gsub()の変わりに「tr」を使ってる(・ω・)
12
+ end
13
+
14
+ # Noteを初期化する時に#は♯に変換されるから両方が要るかな。。。
15
+ def sharp?
16
+ !!name.match(/#/) || !!name.match(/♯/) # 真偽を返して欲しかったから次のように書きました
17
+ end
18
+
19
+ def flat?
20
+ !!name.match(/b/) || !!name.match(/♭/)
21
+ end
22
+
23
+ def position
24
+ if sharp?
25
+ SHARP_CHORDS.index(name)
26
+ else
27
+ FLAT_CHORDS.index(name)
28
+ end
29
+ end
30
+
31
+ end
data/lib/files/song.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  class Song
2
2
 
3
3
  attr_accessor :key, :chords, :title, :tempo
4
- attr_reader :Sharp_chords, :Flat_chords
5
4
 
6
5
  # keyは文字列で、chordsは文字列の配列
7
6
  def initialize(key, chords)
@@ -14,8 +13,9 @@ class Song
14
13
  @tempo = ""
15
14
  end
16
15
 
17
- def key_change(new_key, option)
18
- new_key = Chord.new(new_key)
16
+ def key_change(new_key, option=:sharp)
17
+ # unless new_key.instance_of? Chord then new_key = Chord.new(new_key)
18
+ new_key = Chord.new(new_key) # もうすでにChordクラスであればこれを飛ばすようにする
19
19
 
20
20
  if key.position < new_key.position
21
21
  key_up = true
@@ -45,22 +45,22 @@ class Song
45
45
  new_position -= 1
46
46
 
47
47
  case option
48
- when :default || :sharp then
48
+ when :sharp then
49
49
  if chord.flat?
50
- chord.Flat_chords[new_position] + chord.addition
50
+ FLAT_CHORDS[new_position] + chord.addition
51
51
  else
52
- chord.Sharp_chords[new_position] + chord.addition
52
+ SHARP_CHORDS[new_position] + chord.addition
53
53
  end
54
54
  when :flat then
55
55
  if chord.sharp?
56
- chord.Sharp_chords[new_position] + chord.addition
56
+ SHARP_CHORDS[new_position] + chord.addition
57
57
  else
58
- chord.Flat_chords[new_position] + chord.addition
58
+ FLAT_CHORDS[new_position] + chord.addition
59
59
  end
60
60
  when :all_sharp
61
- chord.Sharp_chords[new_position] + chord.addition
61
+ SHARP_CHORDS[new_position] + chord.addition
62
62
  when :all_flat
63
- chord.Flat_chords[new_position] + chord.addition
63
+ FLAT_CHORDS[new_position] + chord.addition
64
64
  end
65
65
  end
66
66
 
data/lib/musician.rb CHANGED
@@ -1,3 +1,10 @@
1
- require 'files/music'
1
+ Sharp = "♯"
2
+ Flat = "♭"
3
+ SHARP_CHORDS = ["C", "C♯", "D", "D♯", "E", "F", "F♯", "G", "G♯", "A", "A♯", "B"]
4
+ FLAT_CHORDS = ["C", "D♭", "D", "E♭", "E", "F", "G♭", "G", "A♭", "A", "B♭", "B"]
5
+ ADDITIONS = ["dim7", "dim", "2", "sus4", "sus", "maj7", "maj", "m7", "m", "aug", "7", "6", "9", "11"]
6
+
7
+ require 'files/note'
2
8
  require 'files/chord'
3
9
  require 'files/song'
10
+ require 'files/music'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: musician
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriel Arcangel Zayas
@@ -18,6 +18,7 @@ extra_rdoc_files: []
18
18
  files:
19
19
  - lib/files/chord.rb
20
20
  - lib/files/music.rb
21
+ - lib/files/note.rb
21
22
  - lib/files/song.rb
22
23
  - lib/musician.rb
23
24
  homepage: http://www.github.com/gazayas/musician