Browse files

Re-implemented definitions system, passing existing specs.

  • Loading branch information...
1 parent da0b12c commit ba40ca4fc52ca02228d288f21e10505db297a265 @rubiety committed Oct 21, 2010
View
3 Gemfile
@@ -1,5 +1,4 @@
source 'http://rubygems.org'
gem "activemodel", "~> 3.0.0"
-gem "activesupport", "~> 3.0.0"
-gem "supermodel"
+gem "activesupport", "~> 3.0.0"
View
97 db/migrate/001_create_initial_schema.rb
@@ -1,97 +0,0 @@
-class CreateInitialSchema < ActiveRecord::Migration
- def self.up
- create_table :keys do |t|
- t.string :name
- t.string :long_name
- t.boolean :primary, :default => true
- t.integer :index
- t.integer :letter_index
- t.integer :cycle_index
- end
-
- create_table :chord_qualities do |t|
- t.string :name
- t.string :code
- end
-
- create_table :chords do |t|
- t.belongs_to :chord_quality
- t.integer :parent_id
- t.string :name
- t.text :synonyms
- t.text :information
- end
-
- create_table :chord_symbols do |t|
- t.belongs_to :chord
- t.string :name
- t.boolean :case_sensitive, :default => false
- t.integer :strength
- t.boolean :primary, :default => false
- end
-
- create_table :chord_tones do |t|
- t.belongs_to :chord
- t.integer :position
- t.integer :tone
- t.integer :letter_index
- t.integer :strength
- t.boolean :omitable, :default => false
- t.text :information
- end
-
- create_table :scales do |t|
- t.string :name
- t.string :information
- t.integer :symmetry_index
- end
-
- create_table :scale_tones do |t|
- t.belongs_to :scale
- t.integer :position
- t.integer :tone
- t.integer :letter_index
- end
-
- create_table :modes do |t|
- t.belongs_to :scale
- t.integer :mode
- t.string :name
- t.text :synonyms
- t.integer :dissonance
- end
-
- create_table :chord_scales do |t|
- t.belongs_to :chord
- t.belongs_to :mode
- t.integer :strength
- t.text :information
- end
-
- create_table :voicings do |t|
- t.belongs_to :chord
- t.string :name
- t.text :information
- end
-
- create_table :voicing_tones do |t|
- t.belongs_to :voicings
- t.integer :position
- t.integer :tone
- t.integer :tone_reference_offset, :default => 0
- t.text :information
- end
- end
-
- def self.down
- drop_table :chord_qualities
- drop_table :chords
- drop_table :chord_symbols
- drop_table :chord_tones
- drop_table :scales
- drop_table :scale_tones
- drop_table :modes
- drop_table :chord_scales
- drop_table :voicings
- end
-end
View
4 jazz_model.gemspec
@@ -17,7 +17,9 @@ Gem::Specification.new do |s|
s.rubyforge_project = s.name
s.required_rubygems_version = ">= 1.3.4"
- s.add_dependency("activemodel", [">= 3.0.0"])
+ s.add_dependency("activerecord", [">= 3.0.0"])
s.add_dependency("activesupport", [">= 3.0.0"])
+ s.add_dependency("acts_as_list", [">= 0.1.2"])
+ s.add_dependency("acts_as_tree", [">= 0.1.1"])
s.add_development_dependency("rspec", ["~> 2.0"])
end
View
9 lib/jazz_model.rb
@@ -1,10 +1,13 @@
module JazzModel
+ require "rubygems"
require "active_support"
- require "active_model"
- require "supermodel"
+ require "active_record"
+ require "acts_as_tree"
+ require "acts_as_list"
extend ActiveSupport::Autoload
+ autoload :Base
autoload :Chord
autoload :ChordCollection
autoload :ChordQuality
@@ -25,4 +28,6 @@ module JazzModel
autoload :ToneSequence
autoload :Voicing
autoload :VoicingTone
+
+ autoload :Definition
end
View
8 lib/jazz_model/base.rb
@@ -1,9 +1,9 @@
module JazzModel
class Base < ActiveRecord::Base
- def self.setup
- establish_connection :adapter => "sqlite3", :database => ":memory"
- load File.join(File.dirname(__FILE__), "../../db/schema.rb")
- end
+ self.abstract_class = true
+
+ establish_connection :adapter => "sqlite3", :database => ":memory:"
+ load File.join(File.dirname(__FILE__), "../../db/schema.rb")
def self.load_definitions(definition = :default)
definition = JazzModel::Definitions.const_get(definition.to_s.camelize) unless definition.is_a?(Class)
View
6 lib/jazz_model/chord.rb
@@ -78,11 +78,11 @@ module JazzModel
# Chord['Amin7'].modes.names
# # => ['A Dorian']
#
- class Chord < ActiveRecord::Base
+ class Chord < JazzModel::Base
include KeyContext
-
+
acts_as_tree
-
+
belongs_to :chord_quality
has_many :symbols, :class_name => 'ChordSymbol', :extend => ChordSymbolCollection
View
2 lib/jazz_model/chord_quality.rb
@@ -5,7 +5,7 @@ module JazzModel
# == Associations
# * +chords+ - A collection of chords associated with the chord quality.
#
- class ChordQuality < ActiveRecord::Base
+ class ChordQuality < JazzModel::Base
has_many :chords
class << self
View
8 lib/jazz_model/chord_scale.rb
@@ -13,12 +13,18 @@ module JazzModel
#
# Delegates +key+ to the associated chord to access key context through this relationship.
#
- class ChordScale < ActiveRecord::Base
+ class ChordScale < JazzModel::Base
belongs_to :chord
belongs_to :mode
delegate :scale, :to => :mode
delegate :key, :to => :chord
+ def self.specify(mode, strength = 1)
+ chord_scale = self.new
+ chord_scale.mode = mode
+ chord_scale.strength = strength
+ chord_scale
+ end
end
end
View
2 lib/jazz_model/chord_symbol.rb
@@ -10,7 +10,7 @@ module JazzModel
#
# * +chord+ - Chord associated with the chord symbol.
#
- class ChordSymbol < ActiveRecord::Base
+ class ChordSymbol < JazzModel::Base
belongs_to :chord
class << self
View
74 lib/jazz_model/definition.rb
@@ -0,0 +1,74 @@
+module JazzModel
+ class Definition
+ cattr_accessor :definitions
+ @@definitions = []
+
+ attr_reader :name
+ attr_reader :definition
+ attr_reader :included_definitions
+
+ class Context
+ include JazzModel
+ include JazzModel::Tone::Interval
+ include JazzModel::Tone::LetterInterval
+ include JazzModel::Tone::Offsets
+ end
+
+ def initialize(name = nil, &block)
+ if name.is_a?(Hash)
+ raise ArgumentError, "Only one hash key expected" if name.keys.size > 1
+ @name = name.keys[0]
+ @included_definitions = name.values[0].is_a?(Array) ? name.values[0].map(&:to_sym) : [name.values[0].to_sym]
+ else
+ @name = name
+ @included_definitions = []
+ end
+
+ @definition = block
+ @loaded = false
+
+ @@definitions << self
+ end
+
+ def loaded?
+ !!@loaded
+ end
+
+ def self.[](name)
+ definitions.find {|d| d.name.to_s == name.to_s }
+ end
+
+ def self.define(name, &block)
+ definition = self.new(name, &block)
+ end
+
+ def self.load(name)
+ if definition = self[name]
+ definition.load
+ else
+ raise ArgumentError, "No definition known '#{name}'."
+ end
+ end
+
+ def ensure_loaded
+ load unless loaded?
+ end
+
+ def load
+ (all_included_definitions.uniq - [self]).each do |d|
+ self.class[d].ensure_loaded
+ end
+
+ instance_eval(&@definition)
+
+ @loaded = true
+ end
+
+ def all_included_definitions
+ (@included_definitions.map {|d| self.class[d].try(:all_included_definitions) } + @included_definitions).flatten.compact.uniq
+ end
+ end
+end
+
+# Load Included Definitions:
+Dir[File.join(File.dirname(__FILE__), "definitions", "*.rb")].each {|f| require f}
View
17 lib/jazz_model/definitions/base.rb
@@ -1,17 +0,0 @@
-module JazzModel
- module Definitions
- class Base
- class_inheritable_array :included_definitions
-
- def define
- [included_definitions.uniq - self.class].each do |definition|
- definition.define
- end
- end
-
- def self.use(klass)
- self.included_definitions << klass
- end
- end
- end
-end
View
502 lib/jazz_model/definitions/default.rb
@@ -0,0 +1,502 @@
+JazzModel::Definition.define :default => [:keys] do
+ JazzModel::Scale.create!(:name => 'Major').tap do |s|
+ s.tones.create([
+ {:tone => 0, :letter_index => JazzModel::Tone::LetterInterval::FIRST},
+ {:tone => 2, :letter_index => JazzModel::Tone::LetterInterval::SECOND},
+ {:tone => 4, :letter_index => JazzModel::Tone::LetterInterval::THIRD},
+ {:tone => 5, :letter_index => JazzModel::Tone::LetterInterval::FOURTH},
+ {:tone => 7, :letter_index => JazzModel::Tone::LetterInterval::FIFTH},
+ {:tone => 9, :letter_index => JazzModel::Tone::LetterInterval::SIXTH},
+ {:tone => 11, :letter_index => JazzModel::Tone::LetterInterval::SEVENTH}
+ ])
+
+ s.modes.create!(:mode => 1, :name => 'Ionian')
+ s.modes.create!(:mode => 2, :name => 'Dorian')
+ s.modes.create!(:mode => 3, :name => 'Phrygian')
+ s.modes.create!(:mode => 4, :name => 'Lydian')
+ s.modes.create!(:mode => 5, :name => 'Mixolydian')
+ s.modes.create!(:name => 6, :name => 'Aeolian')
+ s.modes.create!(:name => 7, :name => 'Locrian')
+ end
+
+ JazzModel::Scale.create!(:name => 'Melodic Minor').tap do |s|
+ s.tones.create([
+ {:tone => 0, :letter_index => JazzModel::Tone::LetterInterval::FIRST},
+ {:tone => 2, :letter_index => JazzModel::Tone::LetterInterval::SECOND},
+ {:tone => 3, :letter_index => JazzModel::Tone::LetterInterval::THIRD},
+ {:tone => 5, :letter_index => JazzModel::Tone::LetterInterval::FOURTH},
+ {:tone => 7, :letter_index => JazzModel::Tone::LetterInterval::FIFTH},
+ {:tone => 9, :letter_index => JazzModel::Tone::LetterInterval::SIXTH},
+ {:tone => 11, :letter_index => JazzModel::Tone::LetterInterval::SEVENTH}
+ ])
+
+ s.modes.create!(:mode => 1, :name => 'Melodic Minor')
+ s.modes.create!(:mode => 2, :name => 'Phrygian #6', :synonyms => 'Dorian b2')
+ s.modes.create!(:mode => 3, :name => 'Lydian Augmented')
+ s.modes.create!(:mode => 4, :name => 'Lydian Dominant', :synonyms => 'Mixolydian #4')
+ s.modes.create!(:mode => 5, :name => 'Mixolydian b6')
+ s.modes.create!(:name => 6, :name => 'Locrian #2', :synonyms => 'Aeolian b5')
+ s.modes.create!(:name => 7, :name => 'Super Locrian', :synonyms => 'Diminished Whole Tone')
+ end
+
+ JazzModel::Scale.create!(:name => 'Whole Tone', :symmetry_index => 2).tap do |s|
+ s.tones.create([
+ {:tone => 0, :letter_index => JazzModel::Tone::LetterInterval::FIRST},
+ {:tone => 2, :letter_index => JazzModel::Tone::LetterInterval::SECOND},
+ {:tone => 4, :letter_index => JazzModel::Tone::LetterInterval::THIRD},
+ {:tone => 6, :letter_index => JazzModel::Tone::LetterInterval::FOURTH},
+ {:tone => 8, :letter_index => JazzModel::Tone::LetterInterval::FIFTH},
+ {:tone => 10, :letter_index => JazzModel::Tone::LetterInterval::SEVENTH}
+ ])
+
+ s.modes.create!(:mode => 1, :name => 'Whole Tone')
+ end
+
+ JazzModel::Scale.create!(:name => 'Pentatonic').tap do |s|
+ s.tones.create([
+ {:tone => 0, :letter_index => JazzModel::Tone::LetterInterval::FIRST},
+ {:tone => 2, :letter_index => JazzModel::Tone::LetterInterval::SECOND},
+ {:tone => 4, :letter_index => JazzModel::Tone::LetterInterval::THIRD},
+ {:tone => 7, :letter_index => JazzModel::Tone::LetterInterval::FIFTH},
+ {:tone => 9, :letter_index => JazzModel::Tone::LetterInterval::SIXTH}
+ ])
+
+ s.modes.create!(:mode => 1, :name => 'Pentatonic')
+ end
+
+ JazzModel::Scale.create!(:name => 'Blues').tap do |s|
+ s.tones.create([
+ {:tone => 0, :letter_index => JazzModel::Tone::LetterInterval::FIRST},
+ {:tone => 2, :letter_index => JazzModel::Tone::LetterInterval::SECOND},
+ {:tone => 3, :letter_index => JazzModel::Tone::LetterInterval::THIRD},
+ {:tone => 4, :letter_index => JazzModel::Tone::LetterInterval::THIRD},
+ {:tone => 7, :letter_index => JazzModel::Tone::LetterInterval::FIFTH},
+ {:tone => 9, :letter_index => JazzModel::Tone::LetterInterval::SIXTH}
+ ])
+
+ s.modes.create!(:mode => 1, :name => 'Major Blues')
+ s.modes.create!(:mode => 5, :name => 'Minor Blues')
+ end
+
+ JazzModel::Scale.create!(:name => 'Diminished', :symmetry_index => 3).tap do |s|
+ s.tones.create([
+ {:tone => 0, :letter_index => JazzModel::Tone::LetterInterval::FIRST},
+ {:tone => 1, :letter_index => JazzModel::Tone::LetterInterval::SECOND},
+ {:tone => 3, :letter_index => JazzModel::Tone::LetterInterval::THIRD},
+ {:tone => 4, :letter_index => JazzModel::Tone::LetterInterval::THIRD},
+ {:tone => 6, :letter_index => JazzModel::Tone::LetterInterval::FOURTH},
+ {:tone => 7, :letter_index => JazzModel::Tone::LetterInterval::FIFTH},
+ {:tone => 9, :letter_index => JazzModel::Tone::LetterInterval::SIXTH},
+ {:tone => 10, :letter_index => JazzModel::Tone::LetterInterval::SEVENTH}
+ ])
+
+ s.modes.create!(:mode => 1, :name => 'Half-Whole')
+ s.modes.create!(:mode => 2, :name => 'Whole-Half')
+ end
+
+ JazzModel::Scale.create!(:name => 'Harmonic Minor').tap do |s|
+ s.tones.create([
+ {:tone => 0, :letter_index => JazzModel::Tone::LetterInterval::FIRST},
+ {:tone => 2, :letter_index => JazzModel::Tone::LetterInterval::SECOND},
+ {:tone => 3, :letter_index => JazzModel::Tone::LetterInterval::THIRD},
+ {:tone => 5, :letter_index => JazzModel::Tone::LetterInterval::FOURTH},
+ {:tone => 7, :letter_index => JazzModel::Tone::LetterInterval::FIFTH},
+ {:tone => 8, :letter_index => JazzModel::Tone::LetterInterval::SIXTH},
+ {:tone => 11, :letter_index => JazzModel::Tone::LetterInterval::SEVENTH}
+ ])
+ end
+
+ JazzModel::Scale.create!(:name => 'Bebop').tap do |s|
+ s.tones.create([
+ {:tone => 0, :letter_index => JazzModel::Tone::LetterInterval::FIRST},
+ {:tone => 2, :letter_index => JazzModel::Tone::LetterInterval::SECOND},
+ {:tone => 4, :letter_index => JazzModel::Tone::LetterInterval::THIRD},
+ {:tone => 5, :letter_index => JazzModel::Tone::LetterInterval::FOURTH},
+ {:tone => 7, :letter_index => JazzModel::Tone::LetterInterval::FIFTH},
+ {:tone => 9, :letter_index => JazzModel::Tone::LetterInterval::SIXTH},
+ {:tone => 10, :letter_index => JazzModel::Tone::LetterInterval::SEVENTH},
+ {:tone => 11, :letter_index => JazzModel::Tone::LetterInterval::SEVENTH}
+ ])
+
+ s.modes.create!(:mode => 1, :name => 'Dominant Bebop')
+ s.modes.create!(:mode => 2, :name => 'Major Bebop')
+ end
+
+
+ ##### Initialize Chords #####
+
+ JazzModel::ChordQuality.create!(:name => 'Major', :code => 'MAJ').tap do |q|
+ q.chords.create!(:name => 'Major Triad').tap do |c|
+ c.symbols.create!(:name => 'maj', :primary => true)
+ c.symbols.create!(:name => 'M', :case_sensitive => true)
+ c.symbols.create!(:name => 'major')
+
+ c.tones.create([
+ {:tone => JazzModel::Tone::Interval::ROOT, :letter_index => JazzModel::Tone::LetterInterval::FIRST, :strength => 0},
+ {:tone => JazzModel::Tone::Interval::MAJOR_3RD, :letter_index => JazzModel::Tone::LetterInterval::THIRD, :strength => 2},
+ {:tone => JazzModel::Tone::Interval::PERFECT_5TH, :letter_index => JazzModel::Tone::LetterInterval::FIFTH, :strength => 1}
+ ])
+
+ c.chord_scales << JazzModel::ChordScale.specify(JazzModel::Scale['Major'][1])
+ end
+
+ q.chords.create!(:name => 'Major 7').tap do |c|
+ c.symbols.create!(:name => 'maj7', :primary => true)
+ c.symbols.create!(:name => 'M7', :case_sensitive => true)
+ c.symbols.create!(:name => 'major7')
+
+ c.tones.create([
+ {:tone => JazzModel::Tone::Interval::ROOT, :letter_index => JazzModel::Tone::LetterInterval::FIRST, :strength => 0, :omitable => true},
+ {:tone => JazzModel::Tone::Interval::MAJOR_3RD, :letter_index => JazzModel::Tone::LetterInterval::THIRD, :strength => 1},
+ {:tone => JazzModel::Tone::Interval::PERFECT_5TH, :letter_index => JazzModel::Tone::LetterInterval::FIFTH, :strength => 2, :omitable => true},
+ {:tone => JazzModel::Tone::Interval::MAJOR_7TH, :letter_index => JazzModel::Tone::LetterInterval::SEVENTH, :strength => 2}
+ ])
+
+ c.children.create!(:name => 'Major 7 #11').tap do |cc|
+ cc.symbols.create!(:name => 'maj7#11', :primary => true)
+ cc.symbols.create!(:name => 'M7#11')
+ cc.symbols.create!(:name => 'major7#11')
+ cc.symbols.create!(:name => 'lyd')
+ cc.symbols.create!(:name => 'lydian')
+
+ cc.tones.create([
+ {:tone => JazzModel::Tone::Interval::ROOT, :letter_index => JazzModel::Tone::LetterInterval::FIRST, :strength => 0, :omitable => true},
+ {:tone => JazzModel::Tone::Interval::MAJOR_3RD, :letter_index => JazzModel::Tone::LetterInterval::THIRD, :strength => 1},
+ {:tone => JazzModel::Tone::Interval::PERFECT_5TH, :letter_index => JazzModel::Tone::LetterInterval::FIFTH, :strength => 2, :omitable => true},
+ {:tone => JazzModel::Tone::Interval::MAJOR_7TH, :letter_index => JazzModel::Tone::LetterInterval::SEVENTH, :strength => 2},
+ {:tone => JazzModel::Tone::Interval::AUGMENTED_4TH, :letter_index => JazzModel::Tone::LetterInterval::FOURTH, :strength => 3}
+ ])
+
+ cc.chord_scales << JazzModel::ChordScale.specify(JazzModel::Scale['Major'][4])
+ end
+
+ c.children.create!(:name => 'Lydian Augmented').tap do |cc|
+ cc.symbols.create!(:name => 'maj7#4#5', :primary => true)
+ cc.symbols.create!(:name => 'lydaug')
+ cc.symbols.create!(:name => 'maj7#11#5')
+
+ cc.tones.create([
+ {:tone => JazzModel::Tone::Interval::ROOT, :letter_index => JazzModel::Tone::LetterInterval::FIRST, :strength => 0, :omitable => true},
+ {:tone => JazzModel::Tone::Interval::MAJOR_3RD, :letter_index => JazzModel::Tone::LetterInterval::THIRD, :strength => 1},
+ {:tone => JazzModel::Tone::Interval::AUGMENTED_5TH, :letter_index => JazzModel::Tone::LetterInterval::FIFTH, :strength => 2, :omitable => true},
+ {:tone => JazzModel::Tone::Interval::MAJOR_7TH, :letter_index => JazzModel::Tone::LetterInterval::SEVENTH, :strength => 2},
+ {:tone => JazzModel::Tone::Interval::AUGMENTED_4TH, :letter_index => JazzModel::Tone::LetterInterval::FOURTH, :strength => 3}
+ ])
+
+ cc.chord_scales << JazzModel::ChordScale.specify(JazzModel::Scale['Melodic Minor'][3])
+ end
+
+ c.chord_scales << JazzModel::ChordScale.specify(JazzModel::Scale['Major'][1])
+ end
+
+ q.chords.create!(:name => 'Major 6').tap do |c|
+ c.symbols.create!(:name => '6', :primary => true)
+ c.symbols.create!(:name => 'maj6')
+ c.symbols.create!(:name => 'M6', :case_sensitive => true)
+ c.symbols.create!(:name => 'major6')
+
+ c.tones.create([
+ {:tone => JazzModel::Tone::Interval::ROOT, :letter_index => JazzModel::Tone::LetterInterval::FIRST, :strength => 0},
+ {:tone => JazzModel::Tone::Interval::MAJOR_3RD, :letter_index => JazzModel::Tone::LetterInterval::THIRD, :strength => 1},
+ {:tone => JazzModel::Tone::Interval::PERFECT_5TH, :letter_index => JazzModel::Tone::LetterInterval::FIFTH, :strength => 2},
+ {:tone => JazzModel::Tone::Interval::MAJOR_6TH, :letter_index => JazzModel::Tone::LetterInterval::SIXTH, :strength => 3}
+ ])
+
+ c.chord_scales << JazzModel::ChordScale.specify(JazzModel::Scale['Pentatonic'][1])
+ c.chord_scales << JazzModel::ChordScale.specify(JazzModel::Scale['Major'][1], 2)
+ end
+ end
+
+
+ JazzModel::ChordQuality.create!(:name => 'Minor', :code => 'MIN').tap do |q|
+ q.chords.create!(:name => 'Minor Triad').tap do |c|
+ c.symbols.create!(:name => 'min', :primary => true)
+ c.symbols.create!(:name => 'm', :case_sensitive => true)
+ c.symbols.create!(:name => 'minor')
+
+ c.tones.create([
+ {:tone => JazzModel::Tone::Interval::ROOT, :letter_index => JazzModel::Tone::LetterInterval::FIRST, :strength => 0},
+ {:tone => JazzModel::Tone::Interval::MINOR_3RD, :letter_index => JazzModel::Tone::LetterInterval::THIRD, :strength => 1},
+ {:tone => JazzModel::Tone::Interval::PERFECT_5TH, :letter_index => JazzModel::Tone::LetterInterval::FIFTH, :strength => 2}
+ ])
+
+ c.chord_scales << JazzModel::ChordScale.specify(JazzModel::Scale['Major'][2])
+ c.chord_scales << JazzModel::ChordScale.specify(JazzModel::Scale['Major'][6], 2)
+ c.chord_scales << JazzModel::ChordScale.specify(JazzModel::Scale['Major'][3], 3)
+ end
+
+ q.chords.create!(:name => 'Minor 7').tap do |c|
+ c.symbols.create!(:name => 'min7', :primary => true)
+ c.symbols.create!(:name => 'm7', :case_sensitive => true)
+ c.symbols.create!(:name => 'minor7')
+
+ c.tones.create([
+ {:tone => JazzModel::Tone::Interval::ROOT, :letter_index => JazzModel::Tone::LetterInterval::FIRST, :strength => 0, :omitable => true},
+ {:tone => JazzModel::Tone::Interval::MINOR_3RD, :letter_index => JazzModel::Tone::LetterInterval::THIRD, :strength => 1},
+ {:tone => JazzModel::Tone::Interval::PERFECT_5TH, :letter_index => JazzModel::Tone::LetterInterval::FIFTH, :strength => 2, :omitable => true},
+ {:tone => JazzModel::Tone::Interval::MINOR_7TH, :letter_index => JazzModel::Tone::LetterInterval::SEVENTH, :strength => 1}
+ ])
+
+ c.chord_scales << JazzModel::ChordScale.specify(JazzModel::Scale['Major'][2])
+ c.chord_scales << JazzModel::ChordScale.specify(JazzModel::Scale['Major'][6], 2)
+ end
+
+ q.chords.create!(:name => 'Minor 6').tap do |c|
+ c.symbols.create!(:name => 'min6', :primary => true)
+ c.symbols.create!(:name => 'm6', :case_sensitive => true)
+ c.symbols.create!(:name => 'minor6')
+
+ c.tones.create([
+ {:tone => JazzModel::Tone::Interval::ROOT, :letter_index => JazzModel::Tone::LetterInterval::FIRST, :strength => 0, :omitable => true},
+ {:tone => JazzModel::Tone::Interval::MINOR_3RD, :letter_index => JazzModel::Tone::LetterInterval::THIRD, :strength => 1},
+ {:tone => JazzModel::Tone::Interval::PERFECT_5TH, :letter_index => JazzModel::Tone::LetterInterval::FIFTH, :strength => 2},
+ {:tone => JazzModel::Tone::Interval::MAJOR_6TH, :letter_index => JazzModel::Tone::LetterInterval::SIXTH, :strength => 1}
+ ])
+
+ c.chord_scales << JazzModel::ChordScale.specify(JazzModel::Scale['Major'][1])
+ end
+
+ q.chords.create!(:name => 'Phrygian').tap do |c|
+ c.symbols.create!(:name => 'phryg', :primary => true)
+ c.symbols.create!(:name => 'minb2')
+ c.symbols.create!(:name => 'mb2')
+ c.symbols.create!(:name => 'minorb2')
+ c.symbols.create!(:name => 'phrygian')
+ c.symbols.create!(:name => 'susb9')
+
+ c.tones.create([
+ {:tone => JazzModel::Tone::Interval::ROOT, :letter_index => JazzModel::Tone::LetterInterval::FIRST, :strength => 0, :omitable => true},
+ {:tone => JazzModel::Tone::Interval::MINOR_3RD, :letter_index => JazzModel::Tone::LetterInterval::THIRD, :strength => 1},
+ {:tone => JazzModel::Tone::Interval::PERFECT_5TH, :letter_index => JazzModel::Tone::LetterInterval::FIFTH, :strength => 2},
+ {:tone => JazzModel::Tone::Interval::MINOR_2ND, :letter_index => JazzModel::Tone::LetterInterval::SECOND, :strength => 1},
+ {:tone => JazzModel::Tone::Interval::MINOR_6TH, :letter_index => JazzModel::Tone::LetterInterval::SIXTH, :strength => 3}
+ ])
+
+ c.chord_scales << JazzModel::ChordScale.specify(JazzModel::Scale['Major'][3])
+ end
+
+ q.chords.create!(:name => 'Minor b6').tap do |c|
+ c.symbols.create!(:name => 'minb6', :primary => true)
+ c.symbols.create!(:name => 'mb6')
+ c.symbols.create!(:name => 'minorb6')
+ c.symbols.create!(:name => 'aeolian')
+
+ c.tones.create([
+ {:tone => JazzModel::Tone::Interval::ROOT, :letter_index => JazzModel::Tone::LetterInterval::FIRST, :strength => 0, :omitable => true},
+ {:tone => JazzModel::Tone::Interval::MINOR_3RD, :letter_index => JazzModel::Tone::LetterInterval::THIRD, :strength => 1},
+ {:tone => JazzModel::Tone::Interval::PERFECT_5TH, :letter_index => JazzModel::Tone::LetterInterval::FIFTH, :strength => 2},
+ {:tone => JazzModel::Tone::Interval::MINOR_6TH, :letter_index => JazzModel::Tone::LetterInterval::SIXTH, :strength => 3}
+ ])
+
+ c.chord_scales << JazzModel::ChordScale.specify(JazzModel::Scale['Major'][6])
+ end
+
+ q.chords.create!(:name => 'Major-Minor').tap do |c|
+ c.symbols.create!(:name => 'min#7', :primary => true)
+ c.symbols.create!(:name => 'majmin')
+ c.symbols.create!(:name => 'm#7', :case_sensitive => true)
+ c.symbols.create!(:name => 'minor#7')
+ c.symbols.create!(:name => 'major-minor')
+
+ c.tones.create([
+ {:tone => JazzModel::Tone::Interval::ROOT, :letter_index => JazzModel::Tone::LetterInterval::FIRST, :strength => 0, :omitable => true},
+ {:tone => JazzModel::Tone::Interval::MINOR_3RD, :letter_index => JazzModel::Tone::LetterInterval::THIRD, :strength => 1},
+ {:tone => JazzModel::Tone::Interval::PERFECT_5TH, :letter_index => JazzModel::Tone::LetterInterval::FIFTH, :strength => 2},
+ {:tone => JazzModel::Tone::Interval::MAJOR_7TH, :letter_index => JazzModel::Tone::LetterInterval::SEVENTH, :strength => 1}
+ ])
+
+ c.chord_scales << JazzModel::ChordScale.specify(JazzModel::Scale['Melodic Minor'][1])
+ end
+ end
+
+
+ JazzModel::ChordQuality.create!(:name => 'Dominant', :code => 'DOM').tap do |q|
+ q.chords.create!(:name => 'Dominant 7').tap do |c|
+ c.symbols.create!(:name => '7', :primary => true)
+ c.symbols.create!(:name => 'dom')
+
+ c.tones.create([
+ {:tone => JazzModel::Tone::Interval::ROOT, :letter_index => JazzModel::Tone::LetterInterval::FIRST, :strength => 0, :omitable => true},
+ {:tone => JazzModel::Tone::Interval::MAJOR_3RD, :letter_index => JazzModel::Tone::LetterInterval::THIRD, :strength => 1},
+ {:tone => JazzModel::Tone::Interval::PERFECT_5TH, :letter_index => JazzModel::Tone::LetterInterval::FIFTH, :strength => 3, :omitable => true},
+ {:tone => JazzModel::Tone::Interval::DOMINANT_7TH, :letter_index => JazzModel::Tone::LetterInterval::SEVENTH, :strength => 2}
+ ])
+
+ c.chord_scales << JazzModel::ChordScale.specify(JazzModel::Scale['Major']['Mixolydian'])
+
+ c.children.create!(:name => 'Dominant 9').tap do |cc|
+ cc.symbols.create!(:name => '9', :primary => true)
+ cc.symbols.create!(:name => 'dom9')
+
+ cc.tones.create([
+ {:tone => JazzModel::Tone::Interval::ROOT, :letter_index => JazzModel::Tone::LetterInterval::FIRST, :strength => 0, :omitable => true},
+ {:tone => JazzModel::Tone::Interval::MAJOR_3RD, :letter_index => JazzModel::Tone::LetterInterval::THIRD, :strength => 1},
+ {:tone => JazzModel::Tone::Interval::PERFECT_5TH, :letter_index => JazzModel::Tone::LetterInterval::FIFTH, :strength => 3, :omitable => true},
+ {:tone => JazzModel::Tone::Interval::DOMINANT_7TH, :letter_index => JazzModel::Tone::LetterInterval::SEVENTH, :strength => 2},
+ {:tone => JazzModel::Tone::Interval::MAJOR_2ND, :letter_index => JazzModel::Tone::LetterInterval::SECOND, :strength => 4}
+ ])
+
+ cc.chord_scales << JazzModel::ChordScale.specify(JazzModel::Scale['Major']['Mixolydian'])
+ end
+
+ c.children.create!(:name => 'Dominant 6/9').tap do |cc|
+ cc.symbols.create!(:name => '6/9', :primary => true)
+ cc.symbols.create!(:name => '69')
+
+ cc.tones.create([
+ {:tone => JazzModel::Tone::Interval::ROOT, :letter_index => JazzModel::Tone::LetterInterval::FIRST, :strength => 0, :omitable => true},
+ {:tone => JazzModel::Tone::Interval::MAJOR_3RD, :letter_index => JazzModel::Tone::LetterInterval::THIRD, :strength => 1},
+ {:tone => JazzModel::Tone::Interval::PERFECT_5TH, :letter_index => JazzModel::Tone::LetterInterval::FIFTH, :strength => 3, :omitable => true},
+ {:tone => JazzModel::Tone::Interval::DOMINANT_7TH, :letter_index => JazzModel::Tone::LetterInterval::SEVENTH, :strength => 2},
+ {:tone => JazzModel::Tone::Interval::MAJOR_2ND, :letter_index => JazzModel::Tone::LetterInterval::SECOND, :strength => 4},
+ {:tone => JazzModel::Tone::Interval::MAJOR_6TH, :letter_index => JazzModel::Tone::LetterInterval::SIXTH, :strength => 4}
+ ])
+
+ cc.chord_scales << JazzModel::ChordScale.specify(JazzModel::Scale['Major']['Mixolydian'])
+ cc.chord_scales << JazzModel::ChordScale.specify(JazzModel::Scale['Major']['Ionian'])
+ end
+
+ c.children.create!(:name => 'Dominant b9').tap do |cc|
+ cc.symbols.create!(:name => '7b9', :primary => true)
+
+ cc.tones.create([
+ {:tone => JazzModel::Tone::Interval::ROOT, :letter_index => JazzModel::Tone::LetterInterval::FIRST, :strength => 0, :omitable => true},
+ {:tone => JazzModel::Tone::Interval::MAJOR_3RD, :letter_index => JazzModel::Tone::LetterInterval::THIRD, :strength => 1},
+ {:tone => JazzModel::Tone::Interval::PERFECT_5TH, :letter_index => JazzModel::Tone::LetterInterval::FIFTH, :strength => 3, :omitable => true},
+ {:tone => JazzModel::Tone::Interval::DOMINANT_7TH, :letter_index => JazzModel::Tone::LetterInterval::SEVENTH, :strength => 2},
+ {:tone => JazzModel::Tone::Interval::MINOR_2ND, :letter_index => JazzModel::Tone::LetterInterval::SECOND, :strength => 4}
+ ])
+
+ cc.chord_scales << JazzModel::ChordScale.specify(JazzModel::Scale['Diminished'][1])
+ cc.chord_scales << JazzModel::ChordScale.specify(JazzModel::Scale['Major']['Mixolydian'], 2)
+ end
+
+ c.children.create!(:name => 'Dominant #9').tap do |cc|
+ cc.symbols.create!(:name => '7#9', :primary => true)
+
+ cc.tones.create([
+ {:tone => JazzModel::Tone::Interval::ROOT, :letter_index => JazzModel::Tone::LetterInterval::FIRST, :strength => 0, :omitable => true},
+ {:tone => JazzModel::Tone::Interval::MAJOR_3RD, :letter_index => JazzModel::Tone::LetterInterval::THIRD, :strength => 1},
+ {:tone => JazzModel::Tone::Interval::PERFECT_5TH, :letter_index => JazzModel::Tone::LetterInterval::FIFTH, :strength => 3, :omitable => true},
+ {:tone => JazzModel::Tone::Interval::DOMINANT_7TH, :letter_index => JazzModel::Tone::LetterInterval::SEVENTH, :strength => 2},
+ {:tone => JazzModel::Tone::Interval::AUGMENTED_2ND, :letter_index => JazzModel::Tone::LetterInterval::SECOND, :strength => 4}
+ ])
+
+ cc.chord_scales << JazzModel::ChordScale.specify(JazzModel::Scale['Melodic Minor'][7])
+ cc.chord_scales << JazzModel::ChordScale.specify(JazzModel::Scale['Diminished'][1], 2)
+ end
+
+ c.children.create!(:name => 'Dominant #11').tap do |cc|
+ cc.symbols.create!(:name => '7#11', :primary => true)
+ cc.symbols.create!(:name => 'lyd7')
+ cc.symbols.create!(:name => 'lydiandom')
+
+ cc.tones.create([
+ {:tone => JazzModel::Tone::Interval::ROOT, :letter_index => JazzModel::Tone::LetterInterval::FIRST, :strength => 0, :omitable => true},
+ {:tone => JazzModel::Tone::Interval::MAJOR_3RD, :letter_index => JazzModel::Tone::LetterInterval::THIRD, :strength => 1},
+ {:tone => JazzModel::Tone::Interval::PERFECT_5TH, :letter_index => JazzModel::Tone::LetterInterval::FIFTH, :strength => 3, :omitable => true},
+ {:tone => JazzModel::Tone::Interval::DOMINANT_7TH, :letter_index => JazzModel::Tone::LetterInterval::SEVENTH, :strength => 2},
+ {:tone => JazzModel::Tone::Interval::AUGMENTED_4TH, :letter_index => JazzModel::Tone::LetterInterval::FOURTH, :strength => 4}
+ ])
+
+ cc.chord_scales << JazzModel::ChordScale.specify(JazzModel::Scale['Melodic Minor'][4])
+ end
+
+ c.children.create!(:name => 'Mixoylidian b6').tap do |cc|
+ cc.symbols.create!(:name => '7b6', :primary => true)
+
+ cc.tones.create([
+ {:tone => JazzModel::Tone::Interval::ROOT, :letter_index => JazzModel::Tone::LetterInterval::FIRST, :strength => 0, :omitable => true},
+ {:tone => JazzModel::Tone::Interval::MAJOR_3RD, :letter_index => JazzModel::Tone::LetterInterval::THIRD, :strength => 1},
+ {:tone => JazzModel::Tone::Interval::PERFECT_5TH, :letter_index => JazzModel::Tone::LetterInterval::FIFTH, :strength => 3},
+ {:tone => JazzModel::Tone::Interval::DOMINANT_7TH, :letter_index => JazzModel::Tone::LetterInterval::SEVENTH, :strength => 2},
+ {:tone => JazzModel::Tone::Interval::MINOR_6TH, :letter_index => JazzModel::Tone::LetterInterval::SIXTH, :strength => 4}
+ ])
+
+ cc.chord_scales << JazzModel::ChordScale.specify(JazzModel::Scale['Melodic Minor'][5])
+ end
+
+ c.children.create!(:name => 'Altered').tap do |cc|
+ cc.symbols.create!(:name => 'alt', :primary => true)
+ cc.symbols.create!(:name => 'altered')
+ cc.symbols.create!(:name => '7#9#5')
+ cc.symbols.create!(:name => '7#5#9')
+ cc.symbols.create!(:name => '7b9#9')
+ cc.symbols.create!(:name => '7#9b9')
+ cc.symbols.create!(:name => '7#5')
+
+ cc.tones.create([
+ {:tone => JazzModel::Tone::Interval::ROOT, :letter_index => JazzModel::Tone::LetterInterval::FIRST, :strength => 0, :omitable => true},
+ {:tone => JazzModel::Tone::Interval::MAJOR_3RD, :letter_index => JazzModel::Tone::LetterInterval::THIRD, :strength => 1},
+ {:tone => JazzModel::Tone::Interval::DOMINANT_7TH, :letter_index => JazzModel::Tone::LetterInterval::SEVENTH, :strength => 2},
+ {:tone => JazzModel::Tone::Interval::MINOR_2ND, :letter_index => JazzModel::Tone::LetterInterval::SECOND, :strength => 4},
+ {:tone => JazzModel::Tone::Interval::AUGMENTED_2ND, :letter_index => JazzModel::Tone::LetterInterval::SECOND, :strength => 4},
+ {:tone => JazzModel::Tone::Interval::AUGMENTED_5TH, :letter_index => JazzModel::Tone::LetterInterval::FIFTH, :strength => 4}
+ ])
+
+ cc.chord_scales << JazzModel::ChordScale.specify(JazzModel::Scale['Melodic Minor'][7])
+ end
+
+ c.children.create!(:name => 'Dominant b5').tap do |cc|
+ cc.symbols.create!(:name => '7b5', :primary => true)
+
+ cc.tones.create([
+ {:tone => JazzModel::Tone::Interval::ROOT, :letter_index => JazzModel::Tone::LetterInterval::FIRST, :strength => 0, :omitable => true},
+ {:tone => JazzModel::Tone::Interval::MAJOR_3RD, :letter_index => JazzModel::Tone::LetterInterval::THIRD, :strength => 1},
+ {:tone => JazzModel::Tone::Interval::DIMINISHED_5TH, :letter_index => JazzModel::Tone::LetterInterval::FIFTH, :strength => 3},
+ {:tone => JazzModel::Tone::Interval::DOMINANT_7TH, :letter_index => JazzModel::Tone::LetterInterval::SEVENTH, :strength => 2}
+ ])
+
+ cc.chord_scales << JazzModel::ChordScale.specify(JazzModel::Scale['Melodic Minor'][4])
+ end
+
+ end
+ end
+
+
+ JazzModel::ChordQuality.create!(:name => 'Diminished', :code => 'DIM').tap do |q|
+ q.chords.create!(:name => 'Diminished Triad').tap do |c|
+ c.symbols.create!(:name => 'dim', :primary => true)
+ c.symbols.create!(:name => 'b5')
+
+ c.tones.create([
+ {:tone => JazzModel::Tone::Interval::ROOT, :letter_index => JazzModel::Tone::LetterInterval::FIRST, :strength => 0},
+ {:tone => JazzModel::Tone::Interval::MINOR_3RD, :letter_index => JazzModel::Tone::LetterInterval::THIRD, :strength => 1},
+ {:tone => JazzModel::Tone::Interval::DIMINISHED_5TH, :letter_index => JazzModel::Tone::LetterInterval::FIFTH, :strength => 1}
+ ])
+
+ c.chord_scales << JazzModel::ChordScale.specify(JazzModel::Scale['Diminished'][1])
+ c.chord_scales << JazzModel::ChordScale.specify(JazzModel::Scale['Diminished'][2])
+ end
+
+ q.chords.create!(:name => 'Half Diminished').tap do |c|
+ c.symbols.create!(:name => 'dim7', :primary => true)
+ c.symbols.create!(:name => '7b5')
+
+ c.tones.create([
+ {:tone => JazzModel::Tone::Interval::ROOT, :letter_index => JazzModel::Tone::LetterInterval::FIRST, :strength => 0},
+ {:tone => JazzModel::Tone::Interval::MINOR_3RD, :letter_index => JazzModel::Tone::LetterInterval::THIRD, :strength => 2},
+ {:tone => JazzModel::Tone::Interval::DIMINISHED_5TH, :letter_index => JazzModel::Tone::LetterInterval::FIFTH, :strength => 1},
+ {:tone => JazzModel::Tone::Interval::MINOR_7TH, :letter_index => JazzModel::Tone::LetterInterval::SEVENTH, :strength => 1}
+ ])
+
+ c.chord_scales << JazzModel::ChordScale.specify(JazzModel::Scale['Major'][7])
+ c.chord_scales << JazzModel::ChordScale.specify(JazzModel::Scale['Melodic Minor'][6])
+ end
+
+ q.chords.create!(:name => 'Full Diminished').tap do |c|
+ c.symbols.create!(:name => 'fulldim', :primary => true)
+ c.symbols.create!(:name => 'b5bb7')
+
+ c.tones.create([
+ {:tone => JazzModel::Tone::Interval::ROOT, :letter_index => JazzModel::Tone::LetterInterval::FIRST, :strength => 0},
+ {:tone => JazzModel::Tone::Interval::MINOR_3RD, :letter_index => JazzModel::Tone::LetterInterval::THIRD, :strength => 2},
+ {:tone => JazzModel::Tone::Interval::DIMINISHED_5TH, :letter_index => JazzModel::Tone::LetterInterval::FIFTH, :strength => 1},
+ {:tone => JazzModel::Tone::Interval::DIMINISHED_7TH, :letter_index => JazzModel::Tone::LetterInterval::SEVENTH, :strength => 1}
+ ])
+
+ c.chord_scales << JazzModel::ChordScale.specify(JazzModel::Scale['Diminished'][1])
+ c.chord_scales << JazzModel::ChordScale.specify(JazzModel::Scale['Diminished'][2])
+ end
+ end
+end
View
103 lib/jazz_model/definitions/keys.rb
@@ -1,57 +1,48 @@
-module JazzModel
- module Definitions
- class Keys < Base
- def define
- ##### Initialize Keys #####
- Key.create!(:name => 'C', :long_name => 'C', :index => 0, :letter_index => 0, :cycle_index => 0)
- Key.create!(:name => 'B#', :long_name => 'B Sharp', :index => 0, :letter_index => 6, :cycle_index => 0, :primary => false)
- Key.create!(:name => 'Dbb', :long_name => 'D Double-Flat', :index => 0, :letter_index => 1, :cycle_index => 0, :primary => false)
-
- Key.create!(:name => 'F', :long_name => 'F', :index => 5, :letter_index => 3, :cycle_index => 1)
- Key.create!(:name => 'E#', :long_name => 'E Sharp', :index => 5, :letter_index => 2, :cycle_index => 1, :primary => false)
- Key.create!(:name => 'Gbb', :long_name => 'G Double-Flat', :index => 5, :letter_index => 4, :cycle_index => 1, :primary => false)
-
- Key.create!(:name => 'Bb', :long_name => 'B Flat', :index => 10, :letter_index => 6, :cycle_index => 2)
- Key.create!(:name => 'A#', :long_name => 'A Sharp', :index => 10, :letter_index => 5, :cycle_index => 2, :primary => false)
- Key.create!(:name => 'Cbb', :long_name => 'C Double-Flat', :index => 10, :letter_index => 0, :cycle_index => 2, :primary => false)
-
- Key.create!(:name => 'Eb', :long_name => 'E Flat', :index => 3, :letter_index => 2, :cycle_index => 3)
- Key.create!(:name => 'D#', :long_name => 'D Sharp', :index => 3, :letter_index => 1, :cycle_index => 3, :primary => false)
- Key.create!(:name => 'Fbb', :long_name => 'F Double Flat', :index => 3, :letter_index => 3, :cycle_index => 3, :primary => false)
-
- Key.create!(:name => 'Ab', :long_name => 'A Flat', :index => 8, :letter_index => 5, :cycle_index => 4)
- Key.create!(:name => 'G#', :long_name => 'G Sharp', :index => 8, :letter_index => 4, :cycle_index => 4, :primary => false)
-
- Key.create!(:name => 'Db', :long_name => 'D Flat', :index => 1, :letter_index => 1, :cycle_index => 5)
- Key.create!(:name => 'C#', :long_name => 'C Sharp', :index => 1, :letter_index => 0, :cycle_index => 5, :primary => false)
- Key.create!(:name => 'B##', :long_name => 'B Double-Sharp', :index => 1, :letter_index => 6, :cycle_index => 5, :primary => false)
-
- Key.create!(:name => 'Gb', :long_name => 'G Flat', :index => 6, :letter_index => 4, :cycle_index => 6)
- Key.create!(:name => 'F#', :long_name => 'F Sharp', :index => 6, :letter_index => 3, :cycle_index => 6, :primary => false)
- Key.create!(:name => 'E##', :long_name => 'E Double-Sharp', :index => 6, :letter_index => 2, :cycle_index => 6, :primary => false)
-
- Key.create!(:name => 'B', :long_name => 'B', :index => 11, :letter_index => 6, :cycle_index => 7)
- Key.create!(:name => 'Cb', :long_name => 'C Flat', :index => 11, :letter_index => 0, :cycle_index => 7, :primary => false)
- Key.create!(:name => 'A##', :long_name => 'A Double-Sharp', :index => 11, :letter_index => 5, :cycle_index => 7, :primary => false)
-
- Key.create!(:name => 'E', :long_name => 'E', :index => 4, :letter_index => 2, :cycle_index => 8)
- Key.create!(:name => 'Fb', :long_name => 'F Flat', :index => 4, :letter_index => 3, :cycle_index => 8, :primary => false)
- Key.create!(:name => 'D##', :long_name => 'D Double-Sharp', :index => 4, :letter_index => 1, :cycle_index => 8, :primary => false)
-
- Key.create!(:name => 'A', :long_name => 'A', :index => 9, :letter_index => 5, :cycle_index => 9)
- Key.create!(:name => 'Bbb', :long_name => 'B Double-Flat', :index => 9, :letter_index => 6, :cycle_index => 9, :primary => false)
- Key.create!(:name => 'G##', :long_name => 'G Double-Sharp', :index => 9, :letter_index => 4, :cycle_index => 9, :primary => false)
-
- Key.create!(:name => 'D', :long_name => 'D', :index => 2, :letter_index => 1, :cycle_index => 10)
- Key.create!(:name => 'C##', :long_name => 'C Double-Sharp', :index => 2, :letter_index => 0, :cycle_index => 10, :primary => false)
- Key.create!(:name => 'Ebb', :long_name => 'E Double-Flat', :index => 2, :letter_index => 2, :cycle_index => 10, :primary => false)
-
- Key.create!(:name => 'G', :long_name => 'G', :index => 7, :letter_index => 4, :cycle_index => 11)
- Key.create!(:name => 'F##', :long_name => 'F Double-Sharp', :index => 7, :letter_index => 3, :cycle_index => 11, :primary => false)
- Key.create!(:name => 'Abb', :long_name => 'A Double-Flat', :index => 7, :letter_index => 5, :cycle_index => 11, :primary => false)
-
- super
- end
- end
- end
+JazzModel::Definition.define :keys do
+ JazzModel::Key.create!(:name => 'C', :long_name => 'C', :index => 0, :letter_index => 0, :cycle_index => 0)
+ JazzModel::Key.create!(:name => 'B#', :long_name => 'B Sharp', :index => 0, :letter_index => 6, :cycle_index => 0, :primary => false)
+ JazzModel::Key.create!(:name => 'Dbb', :long_name => 'D Double-Flat', :index => 0, :letter_index => 1, :cycle_index => 0, :primary => false)
+
+ JazzModel::Key.create!(:name => 'F', :long_name => 'F', :index => 5, :letter_index => 3, :cycle_index => 1)
+ JazzModel::Key.create!(:name => 'E#', :long_name => 'E Sharp', :index => 5, :letter_index => 2, :cycle_index => 1, :primary => false)
+ JazzModel::Key.create!(:name => 'Gbb', :long_name => 'G Double-Flat', :index => 5, :letter_index => 4, :cycle_index => 1, :primary => false)
+
+ JazzModel::Key.create!(:name => 'Bb', :long_name => 'B Flat', :index => 10, :letter_index => 6, :cycle_index => 2)
+ JazzModel::Key.create!(:name => 'A#', :long_name => 'A Sharp', :index => 10, :letter_index => 5, :cycle_index => 2, :primary => false)
+ JazzModel::Key.create!(:name => 'Cbb', :long_name => 'C Double-Flat', :index => 10, :letter_index => 0, :cycle_index => 2, :primary => false)
+
+ JazzModel::Key.create!(:name => 'Eb', :long_name => 'E Flat', :index => 3, :letter_index => 2, :cycle_index => 3)
+ JazzModel::Key.create!(:name => 'D#', :long_name => 'D Sharp', :index => 3, :letter_index => 1, :cycle_index => 3, :primary => false)
+ JazzModel::Key.create!(:name => 'Fbb', :long_name => 'F Double Flat', :index => 3, :letter_index => 3, :cycle_index => 3, :primary => false)
+
+ JazzModel::Key.create!(:name => 'Ab', :long_name => 'A Flat', :index => 8, :letter_index => 5, :cycle_index => 4)
+ JazzModel::Key.create!(:name => 'G#', :long_name => 'G Sharp', :index => 8, :letter_index => 4, :cycle_index => 4, :primary => false)
+
+ JazzModel::Key.create!(:name => 'Db', :long_name => 'D Flat', :index => 1, :letter_index => 1, :cycle_index => 5)
+ JazzModel::Key.create!(:name => 'C#', :long_name => 'C Sharp', :index => 1, :letter_index => 0, :cycle_index => 5, :primary => false)
+ JazzModel::Key.create!(:name => 'B##', :long_name => 'B Double-Sharp', :index => 1, :letter_index => 6, :cycle_index => 5, :primary => false)
+
+ JazzModel::Key.create!(:name => 'Gb', :long_name => 'G Flat', :index => 6, :letter_index => 4, :cycle_index => 6)
+ JazzModel::Key.create!(:name => 'F#', :long_name => 'F Sharp', :index => 6, :letter_index => 3, :cycle_index => 6, :primary => false)
+ JazzModel::Key.create!(:name => 'E##', :long_name => 'E Double-Sharp', :index => 6, :letter_index => 2, :cycle_index => 6, :primary => false)
+
+ JazzModel::Key.create!(:name => 'B', :long_name => 'B', :index => 11, :letter_index => 6, :cycle_index => 7)
+ JazzModel::Key.create!(:name => 'Cb', :long_name => 'C Flat', :index => 11, :letter_index => 0, :cycle_index => 7, :primary => false)
+ JazzModel::Key.create!(:name => 'A##', :long_name => 'A Double-Sharp', :index => 11, :letter_index => 5, :cycle_index => 7, :primary => false)
+
+ JazzModel::Key.create!(:name => 'E', :long_name => 'E', :index => 4, :letter_index => 2, :cycle_index => 8)
+ JazzModel::Key.create!(:name => 'Fb', :long_name => 'F Flat', :index => 4, :letter_index => 3, :cycle_index => 8, :primary => false)
+ JazzModel::Key.create!(:name => 'D##', :long_name => 'D Double-Sharp', :index => 4, :letter_index => 1, :cycle_index => 8, :primary => false)
+
+ JazzModel::Key.create!(:name => 'A', :long_name => 'A', :index => 9, :letter_index => 5, :cycle_index => 9)
+ JazzModel::Key.create!(:name => 'Bbb', :long_name => 'B Double-Flat', :index => 9, :letter_index => 6, :cycle_index => 9, :primary => false)
+ JazzModel::Key.create!(:name => 'G##', :long_name => 'G Double-Sharp', :index => 9, :letter_index => 4, :cycle_index => 9, :primary => false)
+
+ JazzModel::Key.create!(:name => 'D', :long_name => 'D', :index => 2, :letter_index => 1, :cycle_index => 10)
+ JazzModel::Key.create!(:name => 'C##', :long_name => 'C Double-Sharp', :index => 2, :letter_index => 0, :cycle_index => 10, :primary => false)
+ JazzModel::Key.create!(:name => 'Ebb', :long_name => 'E Double-Flat', :index => 2, :letter_index => 2, :cycle_index => 10, :primary => false)
+
+ JazzModel::Key.create!(:name => 'G', :long_name => 'G', :index => 7, :letter_index => 4, :cycle_index => 11)
+ JazzModel::Key.create!(:name => 'F##', :long_name => 'F Double-Sharp', :index => 7, :letter_index => 3, :cycle_index => 11, :primary => false)
+ JazzModel::Key.create!(:name => 'Abb', :long_name => 'A Double-Flat', :index => 7, :letter_index => 5, :cycle_index => 11, :primary => false)
end
View
517 lib/jazz_model/definitions/standard.rb
@@ -1,517 +0,0 @@
-module JazzModel
- module Definitions
- class Default < Base
- use(Keys)
-
- def define
- def ChordScale.specify(mode, strength = 1)
- chord_scale = self.new
- chord_scale.mode = mode
- chord_scale.strength = strength
- chord_scale
- end
-
- with Scale.create!(:name => 'Major') do |s|
- s.tones.create([
- {:tone => 0, :letter_index => FIRST},
- {:tone => 2, :letter_index => SECOND},
- {:tone => 4, :letter_index => THIRD},
- {:tone => 5, :letter_index => FOURTH},
- {:tone => 7, :letter_index => FIFTH},
- {:tone => 9, :letter_index => SIXTH},
- {:tone => 11, :letter_index => SEVENTH}
- ])
-
- s.modes.create!(:mode => 1, :name => 'Ionian')
- s.modes.create!(:mode => 2, :name => 'Dorian')
- s.modes.create!(:mode => 3, :name => 'Phrygian')
- s.modes.create!(:mode => 4, :name => 'Lydian')
- s.modes.create!(:mode => 5, :name => 'Mixolydian')
- s.modes.create!(:name => 6, :name => 'Aeolian')
- s.modes.create!(:name => 7, :name => 'Locrian')
- end
-
- with Scale.create!(:name => 'Melodic Minor') do |s|
- s.tones.create([
- {:tone => 0, :letter_index => FIRST},
- {:tone => 2, :letter_index => SECOND},
- {:tone => 3, :letter_index => THIRD},
- {:tone => 5, :letter_index => FOURTH},
- {:tone => 7, :letter_index => FIFTH},
- {:tone => 9, :letter_index => SIXTH},
- {:tone => 11, :letter_index => SEVENTH}
- ])
-
- s.modes.create!(:mode => 1, :name => 'Melodic Minor')
- s.modes.create!(:mode => 2, :name => 'Phrygian #6', :synonyms => 'Dorian b2')
- s.modes.create!(:mode => 3, :name => 'Lydian Augmented')
- s.modes.create!(:mode => 4, :name => 'Lydian Dominant', :synonyms => 'Mixolydian #4')
- s.modes.create!(:mode => 5, :name => 'Mixolydian b6')
- s.modes.create!(:name => 6, :name => 'Locrian #2', :synonyms => 'Aeolian b5')
- s.modes.create!(:name => 7, :name => 'Super Locrian', :synonyms => 'Diminished Whole Tone')
- end
-
- with Scale.create!(:name => 'Whole Tone', :symmetry_index => 2) do |s|
- s.tones.create([
- {:tone => 0, :letter_index => FIRST},
- {:tone => 2, :letter_index => SECOND},
- {:tone => 4, :letter_index => THIRD},
- {:tone => 6, :letter_index => FOURTH},
- {:tone => 8, :letter_index => FIFTH},
- {:tone => 10, :letter_index => SEVENTH}
- ])
-
- s.modes.create!(:mode => 1, :name => 'Whole Tone')
- end
-
- with Scale.create!(:name => 'Pentatonic') do |s|
- s.tones.create([
- {:tone => 0, :letter_index => FIRST},
- {:tone => 2, :letter_index => SECOND},
- {:tone => 4, :letter_index => THIRD},
- {:tone => 7, :letter_index => FIFTH},
- {:tone => 9, :letter_index => SIXTH}
- ])
-
- s.modes.create!(:mode => 1, :name => 'Pentatonic')
- end
-
- with Scale.create!(:name => 'Blues') do |s|
- s.tones.create([
- {:tone => 0, :letter_index => FIRST},
- {:tone => 2, :letter_index => SECOND},
- {:tone => 3, :letter_index => THIRD},
- {:tone => 4, :letter_index => THIRD},
- {:tone => 7, :letter_index => FIFTH},
- {:tone => 9, :letter_index => SIXTH}
- ])
-
- s.modes.create!(:mode => 1, :name => 'Major Blues')
- s.modes.create!(:mode => 5, :name => 'Minor Blues')
- end
-
- with Scale.create!(:name => 'Diminished', :symmetry_index => 3) do |s|
- s.tones.create([
- {:tone => 0, :letter_index => FIRST},
- {:tone => 1, :letter_index => SECOND},
- {:tone => 3, :letter_index => THIRD},
- {:tone => 4, :letter_index => THIRD},
- {:tone => 6, :letter_index => FOURTH},
- {:tone => 7, :letter_index => FIFTH},
- {:tone => 9, :letter_index => SIXTH},
- {:tone => 10, :letter_index => SEVENTH}
- ])
-
- s.modes.create!(:mode => 1, :name => 'Half-Whole')
- s.modes.create!(:mode => 2, :name => 'Whole-Half')
- end
-
- with Scale.create!(:name => 'Harmonic Minor') do |s|
- s.tones.create([
- {:tone => 0, :letter_index => FIRST},
- {:tone => 2, :letter_index => SECOND},
- {:tone => 3, :letter_index => THIRD},
- {:tone => 5, :letter_index => FOURTH},
- {:tone => 7, :letter_index => FIFTH},
- {:tone => 8, :letter_index => SIXTH},
- {:tone => 11, :letter_index => SEVENTH}
- ])
- end
-
- with Scale.create!(:name => 'Bebop') do |s|
- s.tones.create([
- {:tone => 0, :letter_index => FIRST},
- {:tone => 2, :letter_index => SECOND},
- {:tone => 4, :letter_index => THIRD},
- {:tone => 5, :letter_index => FOURTH},
- {:tone => 7, :letter_index => FIFTH},
- {:tone => 9, :letter_index => SIXTH},
- {:tone => 10, :letter_index => SEVENTH},
- {:tone => 11, :letter_index => SEVENTH}
- ])
-
- s.modes.create!(:mode => 1, :name => 'Dominant Bebop')
- s.modes.create!(:mode => 2, :name => 'Major Bebop')
- end
-
-
- ##### Initialize Chords #####
-
- with ChordQuality.create!(:name => 'Major', :code => 'MAJ') do |q|
- with q.chords.create!(:name => 'Major Triad') do |c|
- c.symbols.create!(:name => 'maj', :primary => true)
- c.symbols.create!(:name => 'M', :case_sensitive => true)
- c.symbols.create!(:name => 'major')
-
- c.tones.create([
- {:tone => ROOT, :letter_index => FIRST, :strength => 0},
- {:tone => MAJOR_3RD, :letter_index => THIRD, :strength => 2},
- {:tone => PERFECT_5TH, :letter_index => FIFTH, :strength => 1}
- ])
-
- c.chord_scales << ChordScale.specify(Scale['Major'][1])
- end
-
- with q.chords.create!(:name => 'Major 7') do |c|
- c.symbols.create!(:name => 'maj7', :primary => true)
- c.symbols.create!(:name => 'M7', :case_sensitive => true)
- c.symbols.create!(:name => 'major7')
-
- c.tones.create([
- {:tone => ROOT, :letter_index => FIRST, :strength => 0, :omitable => true},
- {:tone => MAJOR_3RD, :letter_index => THIRD, :strength => 1},
- {:tone => PERFECT_5TH, :letter_index => FIFTH, :strength => 2, :omitable => true},
- {:tone => MAJOR_7TH, :letter_index => SEVENTH, :strength => 2}
- ])
-
- with c.children.create!(:name => 'Major 7 #11') do |cc|
- cc.symbols.create!(:name => 'maj7#11', :primary => true)
- cc.symbols.create!(:name => 'M7#11')
- cc.symbols.create!(:name => 'major7#11')
- cc.symbols.create!(:name => 'lyd')
- cc.symbols.create!(:name => 'lydian')
-
- cc.tones.create([
- {:tone => ROOT, :letter_index => FIRST, :strength => 0, :omitable => true},
- {:tone => MAJOR_3RD, :letter_index => THIRD, :strength => 1},
- {:tone => PERFECT_5TH, :letter_index => FIFTH, :strength => 2, :omitable => true},
- {:tone => MAJOR_7TH, :letter_index => SEVENTH, :strength => 2},
- {:tone => AUGMENTED_4TH, :letter_index => FOURTH, :strength => 3}
- ])
-
- cc.chord_scales << ChordScale.specify(Scale['Major'][4])
- end
-
- with c.children.create!(:name => 'Lydian Augmented') do |cc|
- cc.symbols.create!(:name => 'maj7#4#5', :primary => true)
- cc.symbols.create!(:name => 'lydaug')
- cc.symbols.create!(:name => 'maj7#11#5')
-
- cc.tones.create([
- {:tone => ROOT, :letter_index => FIRST, :strength => 0, :omitable => true},
- {:tone => MAJOR_3RD, :letter_index => THIRD, :strength => 1},
- {:tone => AUGMENTED_5TH, :letter_index => FIFTH, :strength => 2, :omitable => true},
- {:tone => MAJOR_7TH, :letter_index => SEVENTH, :strength => 2},
- {:tone => AUGMENTED_4TH, :letter_index => FOURTH, :strength => 3}
- ])
-
- cc.chord_scales << ChordScale.specify(Scale['Melodic Minor'][3])
- end
-
- c.chord_scales << ChordScale.specify(Scale['Major'][1])
- end
-
- with q.chords.create!(:name => 'Major 6') do |c|
- c.symbols.create!(:name => '6', :primary => true)
- c.symbols.create!(:name => 'maj6')
- c.symbols.create!(:name => 'M6', :case_sensitive => true)
- c.symbols.create!(:name => 'major6')
-
- c.tones.create([
- {:tone => ROOT, :letter_index => FIRST, :strength => 0},
- {:tone => MAJOR_3RD, :letter_index => THIRD, :strength => 1},
- {:tone => PERFECT_5TH, :letter_index => FIFTH, :strength => 2},
- {:tone => MAJOR_6TH, :letter_index => SIXTH, :strength => 3}
- ])
-
- c.chord_scales << ChordScale.specify(Scale['Pentatonic'][1])
- c.chord_scales << ChordScale.specify(Scale['Major'][1], 2)
- end
- end
-
-
- with ChordQuality.create!(:name => 'Minor', :code => 'MIN') do |q|
- with q.chords.create!(:name => 'Minor Triad') do |c|
- c.symbols.create!(:name => 'min', :primary => true)
- c.symbols.create!(:name => 'm', :case_sensitive => true)
- c.symbols.create!(:name => 'minor')
-
- c.tones.create([
- {:tone => ROOT, :letter_index => FIRST, :strength => 0},
- {:tone => MINOR_3RD, :letter_index => THIRD, :strength => 1},
- {:tone => PERFECT_5TH, :letter_index => FIFTH, :strength => 2}
- ])
-
- c.chord_scales << ChordScale.specify(Scale['Major'][2])
- c.chord_scales << ChordScale.specify(Scale['Major'][6], 2)
- c.chord_scales << ChordScale.specify(Scale['Major'][3], 3)
- end
-
- with q.chords.create!(:name => 'Minor 7') do |c|
- c.symbols.create!(:name => 'min7', :primary => true)
- c.symbols.create!(:name => 'm7', :case_sensitive => true)
- c.symbols.create!(:name => 'minor7')
-
- c.tones.create([
- {:tone => ROOT, :letter_index => FIRST, :strength => 0, :omitable => true},
- {:tone => MINOR_3RD, :letter_index => THIRD, :strength => 1},
- {:tone => PERFECT_5TH, :letter_index => FIFTH, :strength => 2, :omitable => true},
- {:tone => MINOR_7TH, :letter_index => SEVENTH, :strength => 1}
- ])
-
- c.chord_scales << ChordScale.specify(Scale['Major'][2])
- c.chord_scales << ChordScale.specify(Scale['Major'][6], 2)
- end
-
- with q.chords.create!(:name => 'Minor 6') do |c|
- c.symbols.create!(:name => 'min6', :primary => true)
- c.symbols.create!(:name => 'm6', :case_sensitive => true)
- c.symbols.create!(:name => 'minor6')
-
- c.tones.create([
- {:tone => ROOT, :letter_index => FIRST, :strength => 0, :omitable => true},
- {:tone => MINOR_3RD, :letter_index => THIRD, :strength => 1},
- {:tone => PERFECT_5TH, :letter_index => FIFTH, :strength => 2},
- {:tone => MAJOR_6TH, :letter_index => SIXTH, :strength => 1}
- ])
-
- c.chord_scales << ChordScale.specify(Scale['Major'][1])
- end
-
- with q.chords.create!(:name => 'Phrygian') do |c|
- c.symbols.create!(:name => 'phryg', :primary => true)
- c.symbols.create!(:name => 'minb2')
- c.symbols.create!(:name => 'mb2')
- c.symbols.create!(:name => 'minorb2')
- c.symbols.create!(:name => 'phrygian')
- c.symbols.create!(:name => 'susb9')
-
- c.tones.create([
- {:tone => ROOT, :letter_index => FIRST, :strength => 0, :omitable => true},
- {:tone => MINOR_3RD, :letter_index => THIRD, :strength => 1},
- {:tone => PERFECT_5TH, :letter_index => FIFTH, :strength => 2},
- {:tone => MINOR_2ND, :letter_index => SECOND, :strength => 1},
- {:tone => MINOR_6TH, :letter_index => SIXTH, :strength => 3}
- ])
-
- c.chord_scales << ChordScale.specify(Scale['Major'][3])
- end
-
- with q.chords.create!(:name => 'Minor b6') do |c|
- c.symbols.create!(:name => 'minb6', :primary => true)
- c.symbols.create!(:name => 'mb6')
- c.symbols.create!(:name => 'minorb6')
- c.symbols.create!(:name => 'aeolian')
-
- c.tones.create([
- {:tone => ROOT, :letter_index => FIRST, :strength => 0, :omitable => true},
- {:tone => MINOR_3RD, :letter_index => THIRD, :strength => 1},
- {:tone => PERFECT_5TH, :letter_index => FIFTH, :strength => 2},
- {:tone => MINOR_6TH, :letter_index => SIXTH, :strength => 3}
- ])
-
- c.chord_scales << ChordScale.specify(Scale['Major'][6])
- end
-
- with q.chords.create!(:name => 'Major-Minor') do |c|
- c.symbols.create!(:name => 'min#7', :primary => true)
- c.symbols.create!(:name => 'majmin')
- c.symbols.create!(:name => 'm#7', :case_sensitive => true)
- c.symbols.create!(:name => 'minor#7')
- c.symbols.create!(:name => 'major-minor')
-
- c.tones.create([
- {:tone => ROOT, :letter_index => FIRST, :strength => 0, :omitable => true},
- {:tone => MINOR_3RD, :letter_index => THIRD, :strength => 1},
- {:tone => PERFECT_5TH, :letter_index => FIFTH, :strength => 2},
- {:tone => MAJOR_7TH, :letter_index => SEVENTH, :strength => 1}
- ])
-
- c.chord_scales << ChordScale.specify(Scale['Melodic Minor'][1])
- end
- end
-
-
- with ChordQuality.create!(:name => 'Dominant', :code => 'DOM') do |q|
- with q.chords.create!(:name => 'Dominant 7') do |c|
- c.symbols.create!(:name => '7', :primary => true)
- c.symbols.create!(:name => 'dom')
-
- c.tones.create([
- {:tone => ROOT, :letter_index => FIRST, :strength => 0, :omitable => true},
- {:tone => MAJOR_3RD, :letter_index => THIRD, :strength => 1},
- {:tone => PERFECT_5TH, :letter_index => FIFTH, :strength => 3, :omitable => true},
- {:tone => DOMINANT_7TH, :letter_index => SEVENTH, :strength => 2}
- ])
-
- c.chord_scales << ChordScale.specify(Scale['Major']['Mixolydian'])
-
- with c.children.create!(:name => 'Dominant 9') do |cc|
- cc.symbols.create!(:name => '9', :primary => true)
- cc.symbols.create!(:name => 'dom9')
-
- cc.tones.create([
- {:tone => ROOT, :letter_index => FIRST, :strength => 0, :omitable => true},
- {:tone => MAJOR_3RD, :letter_index => THIRD, :strength => 1},
- {:tone => PERFECT_5TH, :letter_index => FIFTH, :strength => 3, :omitable => true},
- {:tone => DOMINANT_7TH, :letter_index => SEVENTH, :strength => 2},
- {:tone => MAJOR_2ND, :letter_index => SECOND, :strength => 4}
- ])
-
- cc.chord_scales << ChordScale.specify(Scale['Major']['Mixolydian'])
- end
-
- with c.children.create!(:name => 'Dominant 6/9') do |cc|
- cc.symbols.create!(:name => '6/9', :primary => true)
- cc.symbols.create!(:name => '69')
-
- cc.tones.create([
- {:tone => ROOT, :letter_index => FIRST, :strength => 0, :omitable => true},
- {:tone => MAJOR_3RD, :letter_index => THIRD, :strength => 1},
- {:tone => PERFECT_5TH, :letter_index => FIFTH, :strength => 3, :omitable => true},
- {:tone => DOMINANT_7TH, :letter_index => SEVENTH, :strength => 2},
- {:tone => MAJOR_2ND, :letter_index => SECOND, :strength => 4},
- {:tone => MAJOR_6TH, :letter_index => SIXTH, :strength => 4}
- ])
-
- cc.chord_scales << ChordScale.specify(Scale['Major']['Mixolydian'])
- cc.chord_scales << ChordScale.specify(Scale['Major']['Ionian'])
- end
-
- with c.children.create!(:name => 'Dominant b9') do |cc|
- cc.symbols.create!(:name => '7b9', :primary => true)
-
- cc.tones.create([
- {:tone => ROOT, :letter_index => FIRST, :strength => 0, :omitable => true},
- {:tone => MAJOR_3RD, :letter_index => THIRD, :strength => 1},
- {:tone => PERFECT_5TH, :letter_index => FIFTH, :strength => 3, :omitable => true},
- {:tone => DOMINANT_7TH, :letter_index => SEVENTH, :strength => 2},
- {:tone => MINOR_2ND, :letter_index => SECOND, :strength => 4}
- ])
-
- cc.chord_scales << ChordScale.specify(Scale['Diminished'][1])
- cc.chord_scales << ChordScale.specify(Scale['Major']['Mixolydian'], 2)
- end
-
- with c.children.create!(:name => 'Dominant #9') do |cc|
- cc.symbols.create!(:name => '7#9', :primary => true)
-
- cc.tones.create([
- {:tone => ROOT, :letter_index => FIRST, :strength => 0, :omitable => true},
- {:tone => MAJOR_3RD, :letter_index => THIRD, :strength => 1},
- {:tone => PERFECT_5TH, :letter_index => FIFTH, :strength => 3, :omitable => true},
- {:tone => DOMINANT_7TH, :letter_index => SEVENTH, :strength => 2},
- {:tone => AUGMENTED_2ND, :letter_index => SECOND, :strength => 4}
- ])
-
- cc.chord_scales << ChordScale.specify(Scale['Melodic Minor'][7])
- cc.chord_scales << ChordScale.specify(Scale['Diminished'][1], 2)
- end
-
- with c.children.create!(:name => 'Dominant #11') do |cc|
- cc.symbols.create!(:name => '7#11', :primary => true)
- cc.symbols.create!(:name => 'lyd7')
- cc.symbols.create!(:name => 'lydiandom')
-
- cc.tones.create([
- {:tone => ROOT, :letter_index => FIRST, :strength => 0, :omitable => true},
- {:tone => MAJOR_3RD, :letter_index => THIRD, :strength => 1},
- {:tone => PERFECT_5TH, :letter_index => FIFTH, :strength => 3, :omitable => true},
- {:tone => DOMINANT_7TH, :letter_index => SEVENTH, :strength => 2},
- {:tone => AUGMENTED_4TH, :letter_index => FOURTH, :strength => 4}
- ])
-
- cc.chord_scales << ChordScale.specify(Scale['Melodic Minor'][4])
- end
-
- with c.children.create!(:name => 'Mixoylidian b6') do |cc|
- cc.symbols.create!(:name => '7b6', :primary => true)
-
- cc.tones.create([
- {:tone => ROOT, :letter_index => FIRST, :strength => 0, :omitable => true},
- {:tone => MAJOR_3RD, :letter_index => THIRD, :strength => 1},
- {:tone => PERFECT_5TH, :letter_index => FIFTH, :strength => 3},
- {:tone => DOMINANT_7TH, :letter_index => SEVENTH, :strength => 2},
- {:tone => MINOR_6TH, :letter_index => SIXTH, :strength => 4}
- ])
-
- cc.chord_scales << ChordScale.specify(Scale['Melodic Minor'][5])
- end
-
- with c.children.create!(:name => 'Altered') do |cc|
- cc.symbols.create!(:name => 'alt', :primary => true)
- cc.symbols.create!(:name => 'altered')
- cc.symbols.create!(:name => '7#9#5')
- cc.symbols.create!(:name => '7#5#9')
- cc.symbols.create!(:name => '7b9#9')
- cc.symbols.create!(:name => '7#9b9')
- cc.symbols.create!(:name => '7#5')
-
- cc.tones.create([
- {:tone => ROOT, :letter_index => FIRST, :strength => 0, :omitable => true},
- {:tone => MAJOR_3RD, :letter_index => THIRD, :strength => 1},
- {:tone => DOMINANT_7TH, :letter_index => SEVENTH, :strength => 2},
- {:tone => MINOR_2ND, :letter_index => SECOND, :strength => 4},
- {:tone => AUGMENTED_2ND, :letter_index => SECOND, :strength => 4},
- {:tone => AUGMENTED_5TH, :letter_index => FIFTH, :strength => 4}
- ])
-
- cc.chord_scales << ChordScale.specify(Scale['Melodic Minor'][7])
- end
-
- with c.children.create!(:name => 'Dominant b5') do |cc|
- cc.symbols.create!(:name => '7b5', :primary => true)
-
- cc.tones.create([
- {:tone => ROOT, :letter_index => FIRST, :strength => 0, :omitable => true},
- {:tone => MAJOR_3RD, :letter_index => THIRD, :strength => 1},
- {:tone => DIMINISHED_5TH, :letter_index => FIFTH, :strength => 3},
- {:tone => DOMINANT_7TH, :letter_index => SEVENTH, :strength => 2}
- ])
-
- cc.chord_scales << ChordScale.specify(Scale['Melodic Minor'][4])
- end
-
- end
- end
-
-
- with ChordQuality.create!(:name => 'Diminished', :code => 'DIM') do |q|
- with q.chords.create!(:name => 'Diminished Triad') do |c|
- c.symbols.create!(:name => 'dim', :primary => true)
- c.symbols.create!(:name => 'b5')
-
- c.tones.create([
- {:tone => ROOT, :letter_index => FIRST, :strength => 0},
- {:tone => MINOR_3RD, :letter_index => THIRD, :strength => 1},
- {:tone => DIMINISHED_5TH, :letter_index => FIFTH, :strength => 1}
- ])
-
- c.chord_scales << ChordScale.specify(Scale['Diminished'][1])
- c.chord_scales << ChordScale.specify(Scale['Diminished'][2])
- end
-
- with q.chords.create!(:name => 'Half Diminished') do |c|
- c.symbols.create!(:name => 'dim7', :primary => true)
- c.symbols.create!(:name => '7b5')
-
- c.tones.create([
- {:tone => ROOT, :letter_index => FIRST, :strength => 0},
- {:tone => MINOR_3RD, :letter_index => THIRD, :strength => 2},
- {:tone => DIMINISHED_5TH, :letter_index => FIFTH, :strength => 1},
- {:tone => MINOR_7TH, :letter_index => SEVENTH, :strength => 1}
- ])
-
- c.chord_scales << ChordScale.specify(Scale['Major'][7])
- c.chord_scales << ChordScale.specify(Scale['Melodic Minor'][6])
- end
-
- with q.chords.create!(:name => 'Full Diminished') do |c|
- c.symbols.create!(:name => 'fulldim', :primary => true)
- c.symbols.create!(:name => 'b5bb7')
-
- c.tones.create([
- {:tone => ROOT, :letter_index => FIRST, :strength => 0},
- {:tone => MINOR_3RD, :letter_index => THIRD, :strength => 2},
- {:tone => DIMINISHED_5TH, :letter_index => FIFTH, :strength => 1},
- {:tone => DIMINISHED_7TH, :letter_index => SEVENTH, :strength => 1}
- ])
-
- c.chord_scales << ChordScale.specify(Scale['Diminished'][1])
- c.chord_scales << ChordScale.specify(Scale['Diminished'][2])
- end
- end
- end
- end
- end
-end
View
66 lib/jazz_model/key.rb
@@ -11,37 +11,39 @@ module JazzModel
# interpretations which are rare but theoretically different from their enharmonic
# counterparts.
#
- class Key < ActiveRecord::Base
- Letters = ['C' => 0, 'D' => 1, 'E' => 2, 'F' => 3, 'G' => 4, 'A' => 5, 'B' => 6]
-
- # Finds a key given a tonal index 0-11 and a letter index (to disambiguate enharmonic keys)
- def self.from_index(value, preferred_letter = nil)
- self.all.find {|k| k.index == value && (preferred_letter.nil? || k.letter_index == preferred_letter)}
- end
-
- # Finds a key object given the name (such as Eb)
- def self.from_name(value)
- self.all.find {|k| k.name == value}
- end
-
- # Finds a key object based on the name:
- # +Key['Eb']+
- #
- def self.[](value)
- self.from_name(value) || self.from_index(value)
- end
-
- # Returns an array of the 12 primary keys (definitions around the cycle of fourths)
- def self.primaries
- self.find_all_by_primary(true)
- end
-
- DEFAULT = self['C']
-
- # Tests whether the current key is enharmonic with +another_key+.
- def enharmonic_with?(another_key)
- self.index == another_key.index
- end
-
+ class Key < JazzModel::Base
+ Letters = ['C' => 0, 'D' => 1, 'E' => 2, 'F' => 3, 'G' => 4, 'A' => 5, 'B' => 6]
+
+ # Finds a key given a tonal index 0-11 and a letter index (to disambiguate enharmonic keys)
+ def self.from_index(value, preferred_letter = nil)
+ self.all.find {|k| k.index == value && (preferred_letter.nil? || k.letter_index == preferred_letter)}
+ end
+
+ # Finds a key object given the name (such as Eb)
+ def self.from_name(value)
+ self.all.find {|k| k.name == value}
+ end
+
+ # Finds a key object based on the name:
+ # +Key['Eb']+
+ #
+ def self.[](value)
+ self.from_name(value) || self.from_index(value)
+ end
+
+ # Returns an array of the 12 primary keys (definitions around the cycle of fourths)
+ def self.primaries
+ self.find_all_by_primary(true)
+ end
+
+ def self.default
+ self['C']
+ end
+
+ # Tests whether the current key is enharmonic with +another_key+.
+ def enharmonic_with?(another_key)
+ self.index == another_key.index
+ end
+
end
end
View
2 lib/jazz_model/mode.rb
@@ -25,7 +25,7 @@ module JazzModel
# Since modes should be accessed within the context of scales, mode-related examples are
# actually in scale. See +Scale+.
#
- class Mode < ActiveRecord::Base
+ class Mode < JazzModel::Base
include KeyContext
belongs_to :scale
View
10 lib/jazz_model/scale.rb
@@ -72,14 +72,12 @@ module JazzModel
# Scale['Major']['Dorian'].chords.symbols
# # => ['min7', 'min6']
#
- class Scale < ActiveRecord::Base
+ class Scale < JazzModel::Base
include KeyContext
include ModeContext
-
- with_options :dependent => :destroy do |scale|
- scale.has_many :modes, :extend => ModeSequence
- scale.has_many :tones, :class_name => 'ScaleTone', :extend => ToneSequence
- end
+
+ has_many :modes, :extend => ModeSequence, :dependent => :destroy
+ has_many :tones, :class_name => 'ScaleTone', :extend => ToneSequence, :dependent => :destroy
delegate :notes, :to => :tones
delegate :chords, :to => :main_mode
View
2 lib/jazz_model/tone.rb
@@ -3,7 +3,7 @@ module JazzModel
# Eventually will be expanded with common functionality for
# all tone objects.
#
- class Tone < ActiveRecord::Base
+ class Tone < JazzModel::Base
self.abstract_class = true
# Defines constants representing intervals
View
2 lib/jazz_model/voicing.rb
@@ -2,7 +2,7 @@ module JazzModel
# Represents a specific piano voicing.
# Work in progress!
#
- class Voicing < ActiveRecord::Base
+ class Voicing < JazzModel::Base
belongs_to :chord
has_many :voicing_tones
View
8 spec/chord_quality_spec.rb
@@ -6,22 +6,22 @@
it { should be_valid }
context "of Major" do
- subject { ChordQuality.find_by_name('Major') }
+ subject { JazzModel::ChordQuality.find_by_name('Major') }
it { should be_valid }
end
context "of Minor" do
- subject { ChordQuality.find_by_name('Minor') }
+ subject { JazzModel::ChordQuality.find_by_name('Minor') }
it { should be_valid }
end
context "of Dominant" do
- subject { ChordQuality.find_by_name('Dominant') }
+ subject { JazzModel::ChordQuality.find_by_name('Dominant') }
it { should be_valid }
end
context "of Diminished" do
- subject { ChordQuality.find_by_name('Diminished') }
+ subject { JazzModel::ChordQuality.find_by_name('Diminished') }
it { should be_valid }
end
end
View
2 spec/key_spec.rb
@@ -2,7 +2,7 @@
describe JazzModel::Key do
it "should default to C" do
- JazzModel::Key::DEFAULT.name.should == "C"
+ JazzModel::Key.default.name.should == "C"
end
it "should expose 12 primary keys" do
View
4 spec/scale_spec.rb
@@ -1,6 +1,6 @@
require "spec_helper"
-describe Scale do
+describe JazzModel::Scale do
subject { JazzModel::Scale['Major'] }
it { should be_valid }
@@ -33,7 +33,7 @@
pairings.each do |scale, notes|
context "as #{scale}" do
it "should give correct notes" do
- scale = Scale[scale]
+ scale = JazzModel::Scale[scale]
scale.should_not be_nil
scale.notes.should == notes
end
View
3 spec/spec_helper.rb
@@ -7,3 +7,6 @@
RSpec.configure do |config|
end
+
+# TODO: Move to context in individual specs, or test in a separate namespace
+JazzModel::Definition.load :default
View
2 spec/tone_sequence_spec.rb
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/../spec_helper'
+require "spec_helper"
describe JazzModel::ToneSequence do
subject { JazzModel::Chord['Cmaj7'] }

0 comments on commit ba40ca4

Please sign in to comment.