musician 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3025626213997e715c4b42c5c21478dbd1895c0e
4
+ data.tar.gz: 00bb0168e1b86374ff0a20677ef51c5c7f8b5d5d
5
+ SHA512:
6
+ metadata.gz: 6a23414692035b15c0d96118b296f5bb700faa6c21d41cf78cd1aa6a39b978f111d805fd5503e02baf9957091b527da06cb2c85e8d942862b7cf66dc9fe187ed
7
+ data.tar.gz: b3c25b41bc11de1a4fefb3c604a85330ebb91a816e2418e427fb376cf584ceb0bcad6850547b9fdab805b18df8a746cf42ee70dc7821798e8ed3344cb3714ebb
@@ -0,0 +1,86 @@
1
+ class Chord
2
+
3
+ Sharp = "♯"
4
+ Flat = "♭"
5
+
6
+ attr_accessor :name, :sanitized_name, :addition
7
+ attr_reader :Sharp_chords, :Flat_chords
8
+
9
+ def initialize(name)
10
+ name = name.tr("#b", "#{Sharp}#{Flat}") # gsub()の変わりに「tr」を使ってる(・ω・)
11
+ @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(/♭/)
26
+ end
27
+
28
+ def position
29
+ # 1を足す理由は、key_changeの中で使うためです
30
+ # 1が足されないと計算がうまくできないから
31
+ # そして配列が正しく定義されるように、new_position -= 1 を def key_change ... end の中に行う
32
+ if sharp?
33
+ @Sharp_chords.index(sanitized_name)
34
+ else
35
+ @Flat_chords.index(sanitized_name)
36
+ end
37
+ end
38
+
39
+ private
40
+ def sanitize_method
41
+
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"
73
+ 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
+
84
+ end
85
+
86
+ end
@@ -0,0 +1,29 @@
1
+ class Music
2
+
3
+ def initialize
4
+ @quarter_note = "♩"
5
+ @half_note = ""
6
+ @whole_note = ""
7
+ @eight_note = "♪"
8
+ @sixteenth_note = ""
9
+ end
10
+
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
+ end
@@ -0,0 +1,71 @@
1
+ class Song
2
+
3
+ attr_accessor :key, :chords, :title, :tempo
4
+ attr_reader :Sharp_chords, :Flat_chords
5
+
6
+ # keyは文字列で、chordsは文字列の配列
7
+ def initialize(key, chords)
8
+ @key = Chord.new(key)
9
+ @chords = chords.map do |chord|
10
+ Chord.new(chord)
11
+ end
12
+ # 作る時に定義しなくていいけど、一応自分で定義できる
13
+ @title = ""
14
+ @tempo = ""
15
+ end
16
+
17
+ def key_change(new_key, option)
18
+ new_key = Chord.new(new_key)
19
+
20
+ if key.position < new_key.position
21
+ key_up = true
22
+ difference = new_key.position - key.position
23
+ elsif key.position > new_key.position
24
+ key_up = false
25
+ difference = key.position - new_key.position
26
+ else
27
+ # キーが変わってない場合
28
+ difference = 0
29
+ end
30
+
31
+ new_chord_array = []
32
+
33
+ new_chord_array = chords.map do |chord|
34
+ if key_up == true
35
+ new_position = (chord.position + 1) + difference
36
+ if new_position > 12
37
+ new_position -= 12
38
+ end
39
+ else
40
+ new_position = (chord.position + 1) - difference
41
+ if new_position < 1
42
+ new_position += 12
43
+ end
44
+ end
45
+ new_position -= 1
46
+
47
+ case option
48
+ when :default || :sharp then
49
+ if chord.flat?
50
+ chord.Flat_chords[new_position] + chord.addition
51
+ else
52
+ chord.Sharp_chords[new_position] + chord.addition
53
+ end
54
+ when :flat then
55
+ if chord.sharp?
56
+ chord.Sharp_chords[new_position] + chord.addition
57
+ else
58
+ chord.Flat_chords[new_position] + chord.addition
59
+ end
60
+ when :all_sharp
61
+ chord.Sharp_chords[new_position] + chord.addition
62
+ when :all_flat
63
+ chord.Flat_chords[new_position] + chord.addition
64
+ end
65
+ end
66
+
67
+ Song.new(new_key.name, new_chord_array)
68
+
69
+ end
70
+
71
+ end
@@ -0,0 +1,3 @@
1
+ require 'files/music'
2
+ require 'files/chord'
3
+ require 'files/song'
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: musician
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Gabriel Arcangel Zayas
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-09-10 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: http://www.github.com/gazayas/musician
14
+ email: g-zayas@hotmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/files/chord.rb
20
+ - lib/files/music.rb
21
+ - lib/files/song.rb
22
+ - lib/musician.rb
23
+ homepage: http://www.github.com/gazayas/musician
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: A gem for musicians. 音楽家のために役に立つgemです。
46
+ test_files: []