All pastes #917027 Raw Edit

Something

public ruby v1 · immutable
#917027 ·published 2008-02-25 02:35 UTC
rendered paste body
# Note span (whole, quarter, eighth, sixteenth, thirty-secondspans = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]# Note tonenotes = Array.new(20)# Tones for each line in the inputtones = ['B', 'A', 'G', 'F','E','D','C','B','A','G','F','E']# Counter for tones arrayt=0IO.foreach('../input.txt') {  |line|    # Counter for notes array  i=0    begin    # Grab the chars for the note and flag columns    n = line[i*4+1]    m = line[i*4]        # If flag, there may be more, add 7    spans[i] += 7 if n == ?\\    # If bar, add 1 if flag (to make 8) or if we didn't already see a flag    spans[i] += 1 if m == ?| && (n == ?\\ || spans[i] < 8)        # Add 1 if whole or quarter note and set the tone for the note    if m == ?o      spans[i] += 1 if spans[i] < 4      notes[i] = tones[t]    end        i += 1  end until i >= line.size    t += 1}str = ''n=0spans.each {  |i|    # If 0, no more notes  break if i == 0    # 32'nd note only has 3 flags, fix here  i += 8 if i == 24    # Build note string  str << notes[n]  str << '\\' << i.to_s if i > 1  str << ' '  n += 1}puts str.rstrip