Class: OutroRails::VoicingStubGenerator
- Inherits:
-
Object
- Object
- OutroRails::VoicingStubGenerator
- Includes:
- VoicingSeedWriter
- Defined in:
- lib/outro_rails/generators/voicing_stub_generator.rb
Overview
Builds stub voicing seed files for a chord entry (a hash loaded from db/seeds/chords/*.yml).
Constant Summary collapse
- INSTRUMENTS =
The instruments stubs can be generated for, as symbols - the rake task iterates this list and branches on
instrument == :guitar. OutroRails::Instruments::ENUM_VALUES.keys
- LOWEST_C_MIDI =
Piano stubs place the first note in the octave above this pitch.
Theory::Pitch.parse("C3").midi
Instance Attribute Summary
Attributes included from VoicingSeedWriter
Instance Method Summary collapse
-
#filename(instrument) ⇒ Object
Seed filename for one instrument, e.g.
-
#initialize(chord) ⇒ VoicingStubGenerator
constructor
Takes the chord seed entry to generate stubs for.
-
#note_names ⇒ Object
Normalized chord tones, e.g.
-
#relative_path(instrument) ⇒ Object
That filename under the root's directory, e.g.
-
#stub_yaml(instrument) ⇒ Object
Piano: one entry per inversion Guitar: a single root-position stub to fill in manually.
Methods included from VoicingSeedWriter
Constructor Details
#initialize(chord) ⇒ VoicingStubGenerator
Takes the chord seed entry to generate stubs for
22 23 24 |
# File 'lib/outro_rails/generators/voicing_stub_generator.rb', line 22 def initialize(chord) @chord = chord end |
Instance Method Details
#filename(instrument) ⇒ Object
Seed filename for one instrument, e.g. "c-major-7-piano.yml"
27 28 29 |
# File 'lib/outro_rails/generators/voicing_stub_generator.rb', line 27 def filename(instrument) "#{chord.fetch('slug')}-#{instrument}.yml" end |
#note_names ⇒ Object
Normalized chord tones, e.g. E7#9 => [E, G#, B, D, F##->G]
37 38 39 |
# File 'lib/outro_rails/generators/voicing_stub_generator.rb', line 37 def note_names chord.fetch("intervals").map { |interval| root.at_interval(interval) } end |
#relative_path(instrument) ⇒ Object
That filename under the root's directory, e.g. "c/c-major-7-piano.yml"
32 33 34 |
# File 'lib/outro_rails/generators/voicing_stub_generator.rb', line 32 def relative_path(instrument) File.join(root.path_slug, filename(instrument)) end |
#stub_yaml(instrument) ⇒ Object
Piano: one entry per inversion Guitar: a single root-position stub to fill in manually
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/outro_rails/generators/voicing_stub_generator.rb', line 43 def stub_yaml(instrument) instrument = instrument.to_sym unless INSTRUMENTS.include?(instrument) raise ArgumentError, "unknown instrument #{instrument.inspect} " \ "(expected #{INSTRUMENTS.join(' or ')})" end case instrument when :piano chord_tones.each_index.map do |position| entry_yaml(instrument, chord_tones.rotate(position), position + 1) end.join("\n") when :guitar entry_yaml(instrument, chord_tones) end end |