coltrane 1.0.11 → 1.0.20

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,9 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Coltrane
4
+ # It deals with chords in roman notation
2
5
  class RomanChord
3
6
  DIGITS = {
4
7
  'I' => 1,
5
- 'V' => 5,
6
- }
8
+ 'V' => 5
9
+ }.freeze
7
10
 
8
11
  def initialize(scale, roman_numeral)
9
12
  @scale = scale
@@ -26,11 +29,11 @@ module Coltrane
26
29
  end
27
30
 
28
31
  def quality
29
- ChordQuality.new(name: is_major? ? 'M' : 'm')
32
+ ChordQuality.new(name: major? ? 'M' : 'm')
30
33
  end
31
34
 
32
- def is_major?
35
+ def major?
33
36
  @roman_numeral[0] =~ /[[:upper]]/
34
37
  end
35
38
  end
36
- end
39
+ end
@@ -1,18 +1,22 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Coltrane
4
+ # Musical scale creation and manipulation
2
5
  class Scale
3
6
  extend ClassicScales
4
7
  attr_reader :interval_sequence, :tone
5
8
 
6
9
  def initialize(*distances, tone: 'C', mode: 1, name: nil, notes: nil)
7
- @name = name
10
+ @name = name
8
11
  if !distances.nil? && !tone.nil?
9
12
  @tone = Note[tone]
10
- distances = distances.rotate(mode-1)
13
+ distances = distances.rotate(mode - 1)
11
14
  @interval_sequence = IntervalSequence.new(distances: distances)
12
15
  elsif !notes.nil?
13
16
  ds = NoteSet[*notes].interval_sequence.distances
14
- self.new(*ds, tone: notes.first)
15
- else raise WrongKeywords.new('[*distances, (tone: "C", mode: 1)] || [notes:]')
17
+ new(*ds, tone: notes.first)
18
+ else
19
+ raise WrongKeywordsError, '[*distances, tone: "C", mode: 1] || [notes:]'
16
20
  end
17
21
  end
18
22
 
@@ -22,7 +26,7 @@ module Coltrane
22
26
 
23
27
  def name
24
28
  @name = begin
25
- is = self.interval_sequence.distances
29
+ is = interval_sequence.distances
26
30
  (0...is.size).each do |i|
27
31
  if (scale_name = Coltrane::ClassicScales::SCALES.key(is.rotate(i)))
28
32
  return scale_name
@@ -36,26 +40,22 @@ module Coltrane
36
40
  "#{tone.name} #{name}"
37
41
  end
38
42
 
39
- alias_method :full_name, :pretty_name
43
+ alias full_name pretty_name
40
44
 
41
45
  def degree(d)
42
- if d < 1 || d > size
43
- raise WrongDegree.new(d)
44
- end
45
-
46
+ raise WrongDegreeError, d if d < 1 || d > size
46
47
  tone + interval_sequence[d - 1].semitones
47
48
  end
48
49
 
49
- alias_method :[], :degree
50
+ alias [] degree
50
51
 
51
52
  def degrees
52
53
  (1..size)
53
54
  end
54
55
 
55
56
  def degree_of_chord(chord)
56
- if chords(chord.size).map(&:name).include?(chord.name)
57
- degree_of_note(chord.root_note)
58
- end
57
+ return if chords(chord.size).map(&:name).include?(chord.name)
58
+ degree_of_note(chord.root_note)
59
59
  end
60
60
 
61
61
  def degree_of_note(note)
@@ -63,9 +63,9 @@ module Coltrane
63
63
  return note + 1 unless note.nil?
64
64
  end
65
65
 
66
- def &(something)
67
- raise HasNoNotes unless something.respond_to?(:notes)
68
- notes & something
66
+ def &(other)
67
+ raise HasNoNotesError unless other.respond_to?(:notes)
68
+ notes & other
69
69
  end
70
70
 
71
71
  def include_notes?(arg)
@@ -73,27 +73,25 @@ module Coltrane
73
73
  (self & noteset).size == noteset.size
74
74
  end
75
75
 
76
- alias_method :include?, :include_notes?
76
+ alias include? include_notes?
77
77
 
78
78
  def notes
79
- Coltrane::Cache.find_or_record(cache_key("notes")) do
79
+ Coltrane::Cache.find_or_record(cache_key('notes')) do
80
80
  NoteSet[*degrees.map { |d| degree(d) }]
81
81
  end
82
82
  end
83
83
 
84
84
  def interval(i)
85
- interval_sequence[(i-1) % size]
85
+ interval_sequence[(i - 1) % size]
86
86
  end
87
87
 
88
88
  def size
89
89
  interval_sequence.size
90
90
  end
91
91
 
92
- def tertians(n=3)
92
+ def tertians(n = 3)
93
93
  degrees.size.times.reduce([]) do |memo, d|
94
- ns = NoteSet[
95
- *n.times.map { |i| notes[(d + (i*2)) % (size)]}
96
- ]
94
+ ns = NoteSet[ *Array.new(n) { |i| notes[(d + (i * 2)) % size] } ]
97
95
  chord = Chord.new(notes: ns)
98
96
  chord.named? ? memo + [chord] : memo
99
97
  end
@@ -116,17 +114,11 @@ module Coltrane
116
114
  end
117
115
 
118
116
  def cache_key(extra)
119
- [
120
- @tone.name,
121
- @interval_sequence.intervals_semitones.join(),
122
- extra
123
- ].join('-')
117
+ [@tone.name, @interval_sequence.intervals_semitones.join, extra].join('-')
124
118
  end
125
119
 
126
120
  def all_chords
127
- (3..size).reduce([]) do |memo, s|
128
- memo + chords(s)
129
- end
121
+ (3..size).reduce([]) { |memo, s| memo + chords(s) }
130
122
  end
131
123
 
132
124
  def chords(size)
@@ -144,4 +136,4 @@ module Coltrane
144
136
  end
145
137
  end
146
138
  end
147
- end
139
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Coltrane
2
- VERSION = "1.0.11"
4
+ VERSION = '1.0.20'
3
5
  end
@@ -1,12 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Stolen from Active Support and changed a bit
4
+ # may in the future be substituted by facets version
1
5
  class String
2
- # Stolen from Active Support and changed a bit
3
6
  def underscore
4
7
  return self unless /[A-Z-]|::/.match?(self)
5
- word = self.to_s.gsub("::", "/")
8
+ word = to_s.gsub('::', '/')
6
9
  word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
7
10
  word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
8
- word.tr!("-", "_")
11
+ word.tr!('- ', '_')
9
12
  word.downcase!
10
13
  word
11
14
  end
12
- end
15
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coltrane
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.11
4
+ version: 1.0.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pedro Maciel
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-01-28 00:00:00.000000000 Z
11
+ date: 2018-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: facets
@@ -39,19 +39,19 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '2.0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: chroma
42
+ name: color
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.2.0
47
+ version: '1.8'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.2.0
54
+ version: '1.8'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: mercenary
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -105,6 +105,7 @@ files:
105
105
  - ".bundle/config"
106
106
  - ".gitignore"
107
107
  - ".rspec"
108
+ - ".rubocop.yml"
108
109
  - ".ruby-version"
109
110
  - CODE_OF_CONDUCT.md
110
111
  - Gemfile
@@ -146,7 +147,6 @@ files:
146
147
  - db/cache.sqlite3
147
148
  - db/cache_test.sqlite3
148
149
  - db/config.yml
149
- - db/schema.rb
150
150
  - exe/coltrane
151
151
  - img/coltrane-logo.png
152
152
  - img/screen-1.png
@@ -159,6 +159,7 @@ files:
159
159
  - img/screen-7.png
160
160
  - img/screen-8.png
161
161
  - img/screen-9.png
162
+ - lib/cli.rb
162
163
  - lib/cli/bass_guitar.rb
163
164
  - lib/cli/chord.rb
164
165
  - lib/cli/errors.rb
@@ -169,12 +170,10 @@ files:
169
170
  - lib/cli/scale.rb
170
171
  - lib/cli/text.rb
171
172
  - lib/cli/ukulele.rb
172
- - lib/coltrane-cli.rb
173
173
  - lib/coltrane.rb
174
174
  - lib/coltrane/cache.rb
175
175
  - lib/coltrane/cadence.rb
176
176
  - lib/coltrane/chord.rb
177
- - lib/coltrane/chord_cache.rb
178
177
  - lib/coltrane/chord_quality.rb
179
178
  - lib/coltrane/classic_progressions.rb
180
179
  - lib/coltrane/classic_scales.rb
@@ -191,10 +190,8 @@ files:
191
190
  - lib/coltrane/qualities.rb
192
191
  - lib/coltrane/roman_chord.rb
193
192
  - lib/coltrane/scale.rb
194
- - lib/coltrane/scale_chord.rb
195
193
  - lib/coltrane/version.rb
196
194
  - lib/core_ext.rb
197
- - pkg/coltrane-0.0.2.gem
198
195
  homepage: http://github.com/pedrozath/coltrane
199
196
  licenses:
200
197
  - MIT
@@ -1,30 +0,0 @@
1
- # This file is auto-generated from the current state of the database. Instead
2
- # of editing this file, please use the migrations feature of Active Record to
3
- # incrementally modify your database, and then regenerate this schema definition.
4
- #
5
- # Note that this schema.rb definition is the authoritative source for your
6
- # database schema. If you need to create the application database on another
7
- # system, you should be using db:schema:load, not running all the migrations
8
- # from scratch. The latter is a flawed and unsustainable approach (the more migrations
9
- # you'll amass, the slower it'll run and the greater likelihood for issues).
10
- #
11
- # It's strongly recommended that you check this file into your version control system.
12
-
13
- ActiveRecord::Schema.define(version: 20170508162849) do
14
-
15
- create_table "scale_caches", force: :cascade do |t|
16
- t.string "interval_sequence"
17
- t.string "tone"
18
- end
19
-
20
- create_table "chord_caches", force: :cascade do |t|
21
- t.string "name"
22
- t.integer "size"
23
- end
24
-
25
- create_table "scale_chords", force: :cascade do |t|
26
- t.integer "scale_cache_id"
27
- t.integer "chord_cache_id"
28
- end
29
-
30
- end
@@ -1,4 +0,0 @@
1
- class ChordCache < ActiveRecord::Base
2
- has_many :scale_chords
3
- has_many :scale_caches, through: :scale_chords
4
- end
@@ -1,4 +0,0 @@
1
- class ScaleChord < ActiveRecord::Base
2
- belongs_to :chord_cache
3
- belongs_to :scale_cache
4
- end