class Coltrane::Renderers::TextRenderer::RepresentationPianoNoteSetDrawer

Constants

PIANO_TEMPLATE

Public Instance Methods

render() click to toggle source
# File lib/coltrane/renderers/text_renderer/representation_piano_note_set_drawer.rb, line 18
def render
  PIANO_TEMPLATE.each_line.map.each_with_index do |l, ln|
    case ln
    when 2, 3 then replace_x(l, Representation::Piano.black_notes, 1, ln - 2)
    when 6    then replace_x(l, Representation::Piano.white_notes, 2)
    else l
    end
  end.join
end

Private Instance Methods

replace_x(line, notes, size, index = 0) click to toggle source
# File lib/coltrane/renderers/text_renderer/representation_piano_note_set_drawer.rb, line 30
def replace_x(line, notes, size, index = 0)
  line.gsub('X' * size).with_index do |_match, i|
    note = notes[i % notes.size]
    next ' ' * size unless note_set.include?(note)
    Paint[replacer(note)[size == 2 ? 0..2 : index], 'red']
  end
end
replacer(note) click to toggle source
# File lib/coltrane/renderers/text_renderer/representation_piano_note_set_drawer.rb, line 38
def replacer(note)
  case flavor
  when :intervals then (note_set.root - note).name
  when :marks then '◼ '
  when :degrees then note_set.notes.degree(note).to_s.rjust(2, '0')
  when :notes then note.pretty_name.to_s.ljust(2, " ")
  end
end