Class: JazzModel::NotesCollection

Inherits:
Object
  • Object
show all
Includes:
Enumerable, KeyContext
Defined in:
lib/jazz_model/notes_collection.rb

Overview

NotesCollection represents a collection of notes. Using this collection, you can determine chord and scale/mode matches in specific or all keys. This class is currently under heavily development and will eventually be home to heavy logic involved in associating an arbitrary collection of notes with chords, given that some scales tone may be “omitable”, etc.

Creating a NotesCollection object

Creating the collection of notes should be done by indexing the Notes class directly with a comma-separated string of notes.

Current Limitations

Will only do exact 100% match of notes given and notes in chords. No fuzzyness such as the ability to omit the root and other non-important tones. Does not yet find supersets or subsets.

Examples

Finding All Associated Chords

NotesCollection['C, E, G, A'].chords.symbols
# => "Amin7, Cmaj6"

Finding Associated Chords in Given Key

NotesCollection['C, E, G, A'].in_key_of('A').chords.symbols
# => "Amin7"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from KeyContext

included

Constructor Details

#initialize(value = []) ⇒ NotesCollection

Returns a new instance of NotesCollection.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/jazz_model/notes_collection.rb', line 40

def initialize(value = [])
	@value_as_given = value
	@keys = []
	@invalid_keys = []
		
	value = value.split(/,| /).map(&:strip) if value.instance_of?(String)
	value.each do |key_name|
		key_object = Key[key_name]

		if key_object.nil?
			@invalid_keys << key_name
		else
			@keys << key_object
		end
	end
end

Instance Attribute Details

#invalid_keysObject

Returns the value of attribute invalid_keys.



38
39
40
# File 'lib/jazz_model/notes_collection.rb', line 38

def invalid_keys
  @invalid_keys
end

#keysObject

Returns the value of attribute keys.



37
38
39
# File 'lib/jazz_model/notes_collection.rb', line 37

def keys
  @keys
end

Instance Method Details

#chordsObject

Chords associated with this collection of notes



64
65
66
67
68
69
70
71
72
# File 'lib/jazz_model/notes_collection.rb', line 64

def chords
	if key
		chords_in_key(key)
	else
		Key.primaries.map do |in_key|
			chords_in_key(in_key)
		end.flatten
	end.extend(ChordCollection)
end

#to_xmlObject

XML Representation



75
76
77
# File 'lib/jazz_model/notes_collection.rb', line 75

def to_xml
	'<NotesCollection name="' + @value_as_given.to_s + '"></NotesCollection>'
end