Class: HeadMusic::Rudiment::Mode
- Inherits:
-
DiatonicContext
- Object
- Base
- TonalContext
- DiatonicContext
- HeadMusic::Rudiment::Mode
- Includes:
- Named
- Defined in:
- lib/head_music/rudiment/mode.rb
Overview
Represents a musical mode (church modes)
Constant Summary collapse
- MODES =
i[ionian dorian phrygian lydian mixolydian aeolian locrian].freeze
Instance Attribute Summary collapse
-
#alias_name_keys ⇒ Object
included
from Named
readonly
Returns the value of attribute alias_name_keys.
-
#mode_name ⇒ Object
readonly
Returns the value of attribute mode_name.
-
#name_key ⇒ Object
included
from Named
readonly
Returns the value of attribute name_key.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #ensure_localized_name(name:, locale_code: Locale::DEFAULT_CODE, abbreviation: nil) ⇒ Object included from Named
-
#initialize(tonic_spelling, mode_name = :ionian) ⇒ Mode
constructor
A new instance of Mode.
- #localized_name(locale_code: Locale::DEFAULT_CODE) ⇒ Object included from Named
- #localized_name_in_default_locale ⇒ Object included from Named private
- #localized_name_in_locale_matching_language(locale) ⇒ Object included from Named private
- #localized_name_in_matching_locale(locale) ⇒ Object included from Named private
-
#localized_names ⇒ Object
included
from Named
Returns an array of LocalizedName instances that are synonymous with the name.
- #name ⇒ Object
- #name=(name) ⇒ Object included from Named
- #parallel ⇒ Object
- #relative ⇒ Object
- #relative_major ⇒ Object
- #scale_type ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(tonic_spelling, mode_name = :ionian) ⇒ Mode
Returns a new instance of Mode.
29 30 31 32 33 |
# File 'lib/head_music/rudiment/mode.rb', line 29 def initialize(tonic_spelling, mode_name = :ionian) super(tonic_spelling) @mode_name = mode_name.to_s.downcase.to_sym raise ArgumentError, "Mode must be one of: #{MODES.join(", ")}" unless MODES.include?(@mode_name) end |
Instance Attribute Details
#alias_name_keys ⇒ Object (readonly) Originally defined in module Named
Returns the value of attribute alias_name_keys.
#mode_name ⇒ Object (readonly)
Returns the value of attribute mode_name.
10 11 12 |
# File 'lib/head_music/rudiment/mode.rb', line 10 def mode_name @mode_name end |
#name_key ⇒ Object (readonly) Originally defined in module Named
Returns the value of attribute name_key.
Class Method Details
.get(identifier) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/head_music/rudiment/mode.rb', line 12 def self.get(identifier) return identifier if identifier.is_a?(HeadMusic::Rudiment::Mode) @modes ||= {} tonic_spelling, mode_name = parse_identifier(identifier) hash_key = HeadMusic::Utilities::HashKey.for(identifier) @modes[hash_key] ||= new(tonic_spelling, mode_name) end |
.parse_identifier(identifier) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/head_music/rudiment/mode.rb', line 21 def self.parse_identifier(identifier) identifier = identifier.to_s.strip parts = identifier.split(/\s+/) tonic_spelling = parts[0] mode_name = parts[1] || "ionian" [tonic_spelling, mode_name] end |
Instance Method Details
#==(other) ⇒ Object
88 89 90 91 |
# File 'lib/head_music/rudiment/mode.rb', line 88 def ==(other) other = self.class.get(other) tonic_spelling == other.tonic_spelling && mode_name == other.mode_name end |
#ensure_localized_name(name:, locale_code: Locale::DEFAULT_CODE, abbreviation: nil) ⇒ Object Originally defined in module Named
#localized_name(locale_code: Locale::DEFAULT_CODE) ⇒ Object Originally defined in module Named
#localized_name_in_default_locale ⇒ Object (private) Originally defined in module Named
#localized_name_in_locale_matching_language(locale) ⇒ Object (private) Originally defined in module Named
#localized_name_in_matching_locale(locale) ⇒ Object (private) Originally defined in module Named
#localized_names ⇒ Object Originally defined in module Named
Returns an array of LocalizedName instances that are synonymous with the name.
#name ⇒ Object
80 81 82 |
# File 'lib/head_music/rudiment/mode.rb', line 80 def name "#{tonic_spelling} #{mode_name}" end |
#name=(name) ⇒ Object Originally defined in module Named
#parallel ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/head_music/rudiment/mode.rb', line 64 def parallel # Return the parallel major or minor key case mode_name when :ionian HeadMusic::Rudiment::Key.get("#{tonic_spelling} major") when :aeolian HeadMusic::Rudiment::Key.get("#{tonic_spelling} minor") when :dorian, :phrygian HeadMusic::Rudiment::Key.get("#{tonic_spelling} minor") when :lydian, :mixolydian HeadMusic::Rudiment::Key.get("#{tonic_spelling} major") when :locrian HeadMusic::Rudiment::Key.get("#{tonic_spelling} minor") end end |
#relative ⇒ Object
60 61 62 |
# File 'lib/head_music/rudiment/mode.rb', line 60 def relative relative_major end |
#relative_major ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/head_music/rudiment/mode.rb', line 39 def relative_major case mode_name when :ionian return HeadMusic::Rudiment::Key.get("#{tonic_spelling} major") when :dorian relative_pitch = tonic_pitch + -2 when :phrygian relative_pitch = tonic_pitch + -4 when :lydian relative_pitch = tonic_pitch + -5 when :mixolydian relative_pitch = tonic_pitch + -7 when :aeolian relative_pitch = tonic_pitch + -9 when :locrian relative_pitch = tonic_pitch + -11 end HeadMusic::Rudiment::Key.get("#{relative_pitch.spelling} major") end |
#scale_type ⇒ Object
35 36 37 |
# File 'lib/head_music/rudiment/mode.rb', line 35 def scale_type @scale_type ||= HeadMusic::Rudiment::ScaleType.get(mode_name) end |
#to_s ⇒ Object
84 85 86 |
# File 'lib/head_music/rudiment/mode.rb', line 84 def to_s name end |