Module: JazzModel::ToneSequence
- Defined in:
- lib/jazz_model/tone_sequence.rb
Overview
This module is mixed in wherever a collection of tones is being returned and handles some of the fundamental logic involved in key and mode calculations and note values.
Instance Method Summary collapse
-
#all ⇒ Object
TODO: Have to use this until we figure out how to override find/default collection result.
-
#in_key_context! ⇒ Object
Shifts indexes to simulate a key change.
-
#in_key_of(in_key = nil) ⇒ Object
Manually specifies the key context for this tone sequence only.
-
#in_mode(mode) ⇒ Object
Manually specifies the mode context for this tone sequence only.
-
#in_mode_context! ⇒ Object
Shifts mode positions to place tone sequence in mode context.
-
#key ⇒ Object
Takes manually specified key context for this collection or delegates to th association owner.
-
#mode ⇒ Object
Takes manually specified mode context for this collection or delegates to the association owner.
-
#notes ⇒ Object
Does the magic in determining the actual note from the tones with tone and letter indexes.
Instance Method Details
#all ⇒ Object
TODO: Have to use this until we figure out how to override find/default collection result
47 48 49 50 51 |
# File 'lib/jazz_model/tone_sequence.rb', line 47 def all in_key_context! if key in_mode_context! if mode self.sort_by(&:position) end |
#in_key_context! ⇒ Object
Shifts indexes to simulate a key change
20 21 22 23 24 25 26 |
# File 'lib/jazz_model/tone_sequence.rb', line 20 def in_key_context! self.each do |tone| tone.tone = (tone.tone + key.index) % 12 tone.letter_index = (tone.letter_index + key.letter_index) % 7 end true end |
#in_key_of(in_key = nil) ⇒ Object
Manually specifies the key context for this tone sequence only.
14 15 16 17 |
# File 'lib/jazz_model/tone_sequence.rb', line 14 def in_key_of(in_key = nil) @key = in_key.instance_of?(String) ? Key[in_key] : in_key self end |
#in_mode(mode) ⇒ Object
Manually specifies the mode context for this tone sequence only.
35 36 37 38 |
# File 'lib/jazz_model/tone_sequence.rb', line 35 def in_mode(mode) @mode = mode self end |
#in_mode_context! ⇒ Object
Shifts mode positions to place tone sequence in mode context
41 42 43 44 |
# File 'lib/jazz_model/tone_sequence.rb', line 41 def in_mode_context! self.each {|tone| tone.position = (tone.position - mode) % self.count + 1} true end |
#key ⇒ Object
Takes manually specified key context for this collection or delegates to th association owner.
9 10 11 |
# File 'lib/jazz_model/tone_sequence.rb', line 9 def key @key || (proxy_owner.key if proxy_owner.respond_to?(:key)) end |
#mode ⇒ Object
Takes manually specified mode context for this collection or delegates to the association owner.
30 31 32 |
# File 'lib/jazz_model/tone_sequence.rb', line 30 def mode @mode || (proxy_owner.mode if proxy_owner.respond_to?(:mode)) end |
#notes ⇒ Object
Does the magic in determining the actual note from the tones with tone and letter indexes.
55 56 57 58 59 |
# File 'lib/jazz_model/tone_sequence.rb', line 55 def notes all.map do |tone| Key.from_index(tone.tone, tone.letter_index).name end.extend(NoteSequence) end |