Class: InevitableCacophony::OctaveStructure

Inherits:
Object
  • Object
show all
Defined in:
lib/inevitable_cacophony/octave_structure.rb

Defined Under Namespace

Classes: Chord, NoteSequence, Scale

Constant Summary collapse

OCTAVE_RATIO =

Frequency scaling for a difference of one whole octave

2
OCTAVE_STRUCTURE_SENTENCE =

Regular expressions used in parsing

/Scales are constructed/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scale_text) ⇒ OctaveStructure

TODO: Allow contructing these without parsing text

Parameters:

  • scale_text (String)

    Dwarf Fortress musical form description including scale information.



65
66
67
68
69
70
71
72
# File 'lib/inevitable_cacophony/octave_structure.rb', line 65

def initialize(scale_text)
        description = Parser::SectionedText.new(scale_text)
        octave_description = description.find_paragraph(OCTAVE_STRUCTURE_SENTENCE)
        @octave_divisions = parse_octave_structure(octave_description)
        
        @chords = parse_chords(description)
        @scales = parse_scales(description, chords)
end

Instance Attribute Details

#chordsObject (readonly)

Returns the value of attribute chords.



74
75
76
# File 'lib/inevitable_cacophony/octave_structure.rb', line 74

def chords
  @chords
end

#scalesObject (readonly)

Returns the value of attribute scales.



74
75
76
# File 'lib/inevitable_cacophony/octave_structure.rb', line 74

def scales
  @scales
end

Instance Method Details

#chromatic_scaleScale

Returns A scale including all available notes in the octave. (As the chromatic scale does for well-tempered Western instruments).

Returns:

  • (Scale)

    A scale including all available notes in the octave. (As the chromatic scale does for well-tempered Western instruments)



78
79
80
# File 'lib/inevitable_cacophony/octave_structure.rb', line 78

def chromatic_scale
        Scale.new([], @octave_divisions + [2])
end