Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local note_lookup_table={
- ['1000']='4', ['0100']='2',
- ['0010']='8', ['0001']='6',
- ['1100']='1', ['1010']='7',
- ['1001']='A', ['0110']='B',
- ['0101']='3', ['0011']='9',
- ['1110']='<A4>', ['0111']='<A6>',
- ['1101']='<B2>', ['1011']='<B8>',
- ['1111']='<AB>', ['0000']='0',
- }
- local function processMeasure(measure)
- local measure_notes={}
- local note_count=0
- for note in measure:gmatch('%d%d%d%d') do
- measure_notes[#measure_notes+1]=note_lookup_table[note]
- note_count=note_count + 1
- end
- if note_count==12 then
- measure_notes[0]='['
- measure_notes[25]=']'
- elseif note_count==16 then
- measure_notes[0]='('
- measure_notes[17]=')'
- elseif note_count==24 then
- measure_notes[0]='['
- measure_notes[25]=']'
- elseif note_count==32 then
- measure_notes[0]='{'
- measure_notes[65]='}'
- elseif note_count==48 then
- measure_notes[0]='`'
- measure_notes[49]='\''
- elseif note_count==64 then
- measure_notes[0]='{'
- measure_notes[65]='}'
- elseif note_count==96 then
- measure_notes[0]='`'
- measure_notes[96]='\''
- elseif note_count==192 then
- measure_notes[0]='`'
- measure_notes[193]='\''
- end
- return table.concat(measure_notes)
- end
- local sm_file
- do
- local tmp=io.open(sm_filename)
- sm_file=tmp:read('*a')
- tmp:close()
- end
- local title=sm_file:getField('TITLE')
- local artist=sm_file:getField('ARTIST')
- local file=sm_file:getField('FILE')
- local bpm=sm_file:getField('BPM')
- local gap=sm_file:getField('GAP')
- local sample_start=sm_file:getField('SAMPLESTART')
- local sample_length=sm_file:getField('SAMPLELENGTH')
- local note_data, idx=sm_file:getField('NOTES')
- local measure
- do
- local _, idx=sm_file:find('%s*%d+%s*%.%s*%d+%s*%:', idx)
- measure=sm_file:match('%b:,', idx)
- _, idx=sm_file:find(',', idx)
- sm_file:sub(idx)
- end
- processMeasure(measure)
- for measure in sm_file:gmatch('.*%,') do
- processMeasure(measure)
- end
- local file_contents={}
- file_contents[#file_contents+1]='#TITLE:' .. title .. ';\n'
- file_contents[#file_contents+1]='#ARTIST:' .. artist .. ';\n'
- file_contents[#file_contents+1]='#FILE:' .. file .. ';\n'
- file_contents[#file_contents+1]='#BPM:' .. bpm .. ';\n'
- file_contents[#file_contents+1]='#GAP:' .. gap .. ';\n'
- file_contents[#file_contents+1]='#SAMPLESTART:' .. sample_start .. ';\n'
- file_contents[#file_contents+1]='#SAMPLELENGTH:' .. sample_length .. ';\n'
- file_contents[#file_contents+1]='#SINGLE:ANOTHER:1:\n'
- file_contents[#file_contents+1]=';'
- do
- local dwi_file=io.open(sm_filename .. '.dwi', 'w')
- dwi_file:write(table.concat(file_contents))
- dwi_file:close()
- end
- function string.getField(file_string, field)
- local _, idx=file_string:find('#' .. field:upper() .. ':')
- return file_string:match('%b:;', idx), idx
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement