jazz_model 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +21 -0
  3. data/README.md +187 -0
  4. data/db/schema.rb +83 -0
  5. data/lib/jazz_model/base.rb +13 -6
  6. data/lib/jazz_model/chord.rb +50 -70
  7. data/lib/jazz_model/chord_collection.rb +21 -45
  8. data/lib/jazz_model/chord_quality.rb +5 -6
  9. data/lib/jazz_model/chord_scale.rb +13 -13
  10. data/lib/jazz_model/chord_symbol.rb +14 -12
  11. data/lib/jazz_model/chord_symbol_collection.rb +3 -10
  12. data/lib/jazz_model/chord_tone.rb +20 -21
  13. data/lib/jazz_model/definition.rb +18 -18
  14. data/lib/jazz_model/definitions/default.rb +316 -321
  15. data/lib/jazz_model/definitions/keys.rb +36 -36
  16. data/lib/jazz_model/definitions.rb +3 -0
  17. data/lib/jazz_model/key.rb +22 -25
  18. data/lib/jazz_model/key_context.rb +31 -22
  19. data/lib/jazz_model/mode.rb +30 -35
  20. data/lib/jazz_model/mode_context.rb +22 -26
  21. data/lib/jazz_model/mode_sequence.rb +13 -12
  22. data/lib/jazz_model/notes_collection.rb +64 -71
  23. data/lib/jazz_model/scale.rb +63 -85
  24. data/lib/jazz_model/scale_tone.rb +14 -15
  25. data/lib/jazz_model/tone.rb +47 -48
  26. data/lib/jazz_model/tone_sequence.rb +56 -58
  27. data/lib/jazz_model/version.rb +2 -2
  28. data/lib/jazz_model/voicing.rb +6 -7
  29. data/lib/jazz_model/voicing_tone.rb +5 -6
  30. data/lib/jazz_model.rb +7 -10
  31. metadata +104 -141
  32. data/CHANGELOG.rdoc +0 -14
  33. data/Gemfile +0 -4
  34. data/README.rdoc +0 -186
  35. data/Rakefile +0 -14
  36. data/lib/jazz_model/note_sequence.rb +0 -15
  37. data/spec/chord_collection_spec.rb +0 -21
  38. data/spec/chord_quality_spec.rb +0 -27
  39. data/spec/chord_scale_spec.rb +0 -7
  40. data/spec/chord_spec.rb +0 -29
  41. data/spec/chord_symbol_spec.rb +0 -6
  42. data/spec/chord_tone_spec.rb +0 -6
  43. data/spec/definition_spec.rb +0 -35
  44. data/spec/key_context_spec.rb +0 -27
  45. data/spec/key_spec.rb +0 -15
  46. data/spec/mode_spec.rb +0 -9
  47. data/spec/notes_collection_spec.rb +0 -25
  48. data/spec/scale_spec.rb +0 -42
  49. data/spec/scale_tone_spec.rb +0 -6
  50. data/spec/spec_helper.rb +0 -12
  51. data/spec/tone_sequence_spec.rb +0 -17
  52. data/spec/tone_spec.rb +0 -4
  53. data/spec/voicing_spec.rb +0 -6
  54. data/spec/voicing_tone_spec.rb +0 -6
@@ -1,27 +1,29 @@
1
1
  module JazzModel
2
2
  # A standard chord symbol (if there is such a thing...).
3
3
  # Several chord symbols can be associated with a given chord,
4
- # and each chord can be designated +case_sensitive+ or not, to handle
5
- # cases such as M representing Major and m representing minor.
6
- # Act as a list to facilitate preference ordering. May abandong this
4
+ # and each chord can be designated +case_sensitive+ or not, to handle
5
+ # cases such as M representing Major and m representing minor.
6
+ # Act as a list to facilitate preference ordering. May abandong this
7
7
  # in the future to prefer a simple +primary+ designation.
8
- #
8
+ #
9
9
  # == Associations
10
- #
10
+ #
11
11
  # * +chord+ - Chord associated with the chord symbol.
12
- #
12
+ #
13
13
  class ChordSymbol < JazzModel::Base
14
14
  belongs_to :chord
15
-
15
+
16
16
  class << self
17
17
  # Finds a chord symbol
18
18
  def resolve(symbol)
19
- self.all.detect do |cs|
20
- cs.case_sensitive? ? (cs.name == symbol) : (cs.name.downcase == symbol.downcase)
21
- end
19
+ all.detect { |cs| cs.matches?(symbol) }
22
20
  end
23
21
  alias_method :[], :resolve
24
22
  end
25
-
23
+
24
+ # Tests whether +symbol+ matches this chord symbol, respecting case sensitivity.
25
+ def matches?(symbol)
26
+ case_sensitive? ? name == symbol : name.casecmp?(symbol)
27
+ end
26
28
  end
27
- end
29
+ end
@@ -1,17 +1,10 @@
1
1
  module JazzModel
2
2
  # Module mixin for Chord symbols
3
3
  module ChordSymbolCollection
4
-
5
- # WARNING: This is basically duplicated from ChordSymbol
6
- # Find way to make this DRY!
7
- #
8
- # Finds a chord symbol
4
+ # Finds a chord symbol within the collection
9
5
  def resolve(symbol)
10
- self.detect do |cs|
11
- cs.case_sensitive? ? (cs.name == symbol) : (cs.name.downcase == symbol.downcase)
12
- end
6
+ detect { |cs| cs.matches?(symbol) }
13
7
  end
14
8
  alias_method :[], :resolve
15
-
16
9
  end
17
- end
10
+ end
@@ -1,32 +1,31 @@
1
1
  module JazzModel
2
- # Represents one non-octval tone in a chord. Chord tones are not ordered
3
- # and arrays of chord tones should be compared using +to_set+.
4
- #
2
+ # Represents one non-octval tone in a chord. Chord tones are not ordered
3
+ # and arrays of chord tones should be compared using +to_set+.
4
+ #
5
5
  # == Attributes
6
- #
7
- # * +tone+ - A tone index from 0-11 representing the relative position of the
6
+ #
7
+ # * +tone+ - A tone index from 0-11 representing the relative position of the
8
8
  # tone within the chromatic scale.
9
- #
10
- # * +letter_index+ - A 0-6 value representing the relative letter position, which
9
+ #
10
+ # * +letter_index+ - A 0-6 value representing the relative letter position, which
11
11
  # helps to disambiguate theoretic values such as Eb and D#. See +Key+.
12
- #
13
- # * +strength+ - A strength metric representing the tonal strength of the tone
14
- # within the context of the chord. Lower numbers are stronger. Zero always
12
+ #
13
+ # * +strength+ - A strength metric representing the tonal strength of the tone
14
+ # within the context of the chord. Lower numbers are stronger. Zero always
15
15
  # represents the root of the chord and any guide tones should be defined as one.
16
- #
17
- # * +omitable+ - Specifies whether the tone can commonly be ommitted in jazz voicings
16
+ #
17
+ # * +omitable+ - Specifies whether the tone can commonly be ommitted in jazz voicings
18
18
  # for this chord. For example, the root and the fifth are often not necessary.
19
- #
19
+ #
20
20
  # == Key Context
21
- #
21
+ #
22
22
  # +key+ is delgated to chord to access the chord's key context.
23
- #
23
+ #
24
24
  class ChordTone < Tone
25
25
  belongs_to :chord
26
-
27
- acts_as_list :scope => :chord
28
-
29
- delegate :key, :to => :chord
30
-
26
+
27
+ acts_as_list scope: :chord
28
+
29
+ delegate :key, to: :chord
31
30
  end
32
- end
31
+ end
@@ -2,11 +2,11 @@ module JazzModel
2
2
  class Definition
3
3
  cattr_accessor :definitions
4
4
  @@definitions = []
5
-
5
+
6
6
  attr_reader :name
7
7
  attr_reader :definition
8
8
  attr_reader :included_definitions
9
-
9
+
10
10
  def initialize(name = nil, &block)
11
11
  if name.is_a?(Hash)
12
12
  raise ArgumentError, "Only one hash key expected" if name.keys.size > 1
@@ -16,51 +16,51 @@ module JazzModel
16
16
  @name = name
17
17
  @included_definitions = []
18
18
  end
19
-
19
+
20
20
  @definition = block
21
21
  @loaded = false
22
-
22
+
23
23
  @@definitions << self
24
24
  end
25
-
25
+
26
26
  def loaded?
27
27
  !!@loaded
28
28
  end
29
-
29
+
30
30
  def self.[](name)
31
- definitions.find {|d| d.name.to_s == name.to_s }
31
+ definitions.find { |d| d.name.to_s == name.to_s }
32
32
  end
33
-
33
+
34
34
  def self.define(name, &block)
35
- definition = self.new(name, &block)
35
+ new(name, &block)
36
36
  end
37
-
37
+
38
38
  def self.load(name)
39
- if definition = self[name]
39
+ if (definition = self[name])
40
40
  definition.load
41
41
  else
42
42
  raise ArgumentError, "No definition known '#{name}'."
43
43
  end
44
44
  end
45
-
45
+
46
46
  def ensure_loaded
47
47
  load unless loaded?
48
48
  end
49
-
49
+
50
50
  def load
51
51
  (all_included_definitions.uniq - [self]).each do |d|
52
52
  self.class[d].ensure_loaded
53
53
  end
54
-
54
+
55
55
  instance_eval(&@definition)
56
-
56
+
57
57
  @loaded = true
58
58
  end
59
-
59
+
60
60
  def all_included_definitions
61
- (@included_definitions.map {|d| self.class[d].try(:all_included_definitions) } + @included_definitions).flatten.compact.uniq
61
+ (@included_definitions.map { |d| self.class[d].try(:all_included_definitions) } + @included_definitions).flatten.compact.uniq
62
62
  end
63
63
  end
64
64
  end
65
65
 
66
- Dir[File.join(File.dirname(__FILE__), "definitions", "*.rb")].each {|f| require f}
66
+ Dir[File.join(File.dirname(__FILE__), "definitions", "*.rb")].each { |f| require f }