Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - local sm_file
 - local note_lookup_table = {
 - ['1000'] = '4', ['0100'] = '2',
 - ['0010'] = '8', ['0001'] = '6',
 - ['1100'] = '1', ['1010'] = '7',
 - ['1001'] = 'B', ['0110'] = 'A',
 - ['0101'] = '3', ['0011'] = '9',
 - ['1110'] = '<81>', ['0111'] = '<83>',
 - ['1101'] = '<61>', ['1011'] = '<8B>',
 - ['1111'] = '<19>', ['0000'] = '0',
 - }
 - function string:getField(field)
 - local _, idx = self:find('#' .. field:upper() .. ':')
 - local str = self:match('%b:;', idx)
 - return str:sub(2, #str - 1)
 - end
 - local function processMeasure(measure)
 - local beat_notes = {''}
 - local note_count = 0
 - for note in measure:gmatch('%d%d%d%d') do
 - beat_notes[#beat_notes+1] = note_lookup_table[note]
 - beat_notes[#beat_notes+1] = ''
 - note_count = note_count + 1
 - end
 - if note_count == 4 then
 - for i=3, 9, 2 do beat_notes[i] = '0' end
 - elseif note_count == 8 then
 - elseif note_count == 12 then
 - for i=3, 25, 2 do beat_notes[i] = '0' end
 - beat_notes[1], beat_notes[#beat_notes+1] = '[', ']'
 - elseif note_count == 16 then
 - beat_notes[1], beat_notes[#beat_notes+1] = '(', ')'
 - elseif note_count == 24 then
 - beat_notes[1], beat_notes[#beat_notes+1] = '[', ']'
 - elseif note_count == 32 then
 - for i=3, 65, 2 do beat_notes[i] = '0' end
 - beat_notes[1], beat_notes[#beat_notes+1] = '{', '}'
 - elseif note_count == 48 then
 - for i=3, 97, 2 do beat_notes[i] = '000' end
 - beat_notes[1], beat_notes[#beat_notes+1] = '`', '\''
 - elseif note_count == 64 then
 - beat_notes[1], beat_notes[#beat_notes+1] = '{', '}'
 - elseif note_count == 96 then
 - for i=3, 193, 2 do beat_notes[i] = '0' end
 - beat_notes[1], beat_notes[#beat_notes+1] = '`', '\''
 - elseif note_count == 192 then
 - beat_notes[1], beat_notes[#beat_notes+1] = '`', '\''
 - else
 - return nil
 - end
 - return table.concat(beat_notes) .. '\n'
 - end
 - local sm_filename = 'test'
 - local tmp = io.open(sm_filename .. '.sm')
 - sm_file = tmp:read('*a')
 - tmp:close()
 - local title = sm_file:getField('TITLE')
 - local artist = sm_file:getField('ARTIST')
 - local file = sm_file:getField('MUSIC')
 - local gap = tonumber(sm_file:getField('OFFSET')) * -1000
 - local sample_start = sm_file:getField('SAMPLESTART')
 - local sample_length = sm_file:getField('SAMPLELENGTH')
 - local changebpm = sm_file:getField('BPMS')
 - local note_data, idx = sm_file:getField('NOTES')
 - local start_bpm = changebpm:match('%d*%.?%d*%s*=%s*(%d+%.?%d+)')
 - if start_bpm == nil then end
 - local _, idx = changebpm:find('%d*%.?%d*%s*=%s*%d+%.?%d+%s*,')
 - if idx then
 - changebpm = changebpm:sub(idx + 1)
 - else
 - changebpm = '' end
 - local changebpm_str = {}
 - if changebpm ~= '' then
 - for beat, bpm, comma in changebpm:gmatch('(%d*%.?%d*)%s*(=%s*%d+%.?%d*)(,?)') do
 - changebpm_str[#changebpm_str+1] = string.format("%.3f", tonumber(beat) * 4)..bpm
 - if comma ~= '' then changebpm_str[#changebpm_str+1] = ',' end
 - end
 - end
 - local file_contents = {}
 - file_contents[#file_contents+1] = '#TITLE:' .. sm_file:getField('TITLE') .. ';\n'
 - file_contents[#file_contents+1] = '#ARTIST:' .. sm_file:getField('ARTIST') .. ';\n'
 - file_contents[#file_contents+1] = '#FILE:' .. sm_file:getField('MUSIC') .. ';\n'
 - file_contents[#file_contents+1] = '#BPM:' .. start_bpm .. ';\n'
 - file_contents[#file_contents+1] = '#GAP:' .. tonumber(sm_file:getField('OFFSET')) * -1000 .. ';\n'
 - file_contents[#file_contents+1] = '#SAMPLESTART:' .. sm_file:getField('SAMPLESTART') .. ';\n'
 - file_contents[#file_contents+1] = '#SAMPLELENGTH:' .. sm_file:getField('SAMPLELENGTH') .. ';\n\n'
 - if changebpm ~= '' then
 - file_contents[#file_contents+1] = '#CHANGEBPM:' .. table.concat(changebpm_str) .. ';\n'
 - end
 - file_contents[#file_contents+1] = '#SINGLE:MANIAC:1:\n'
 - local _, idx = sm_file:find('%d+%.%d+%s*%:', idx)
 - sm_file = sm_file:sub(idx + 1)
 - for measure in sm_file:gmatch('.-[,;]') do
 - file_contents[#file_contents+1] = processMeasure(measure)
 - end
 - local dwi_file = io.open(sm_filename .. '.dwi', 'w')
 - dwi_file:write(table.concat(file_contents)..'\n')
 - dwi_file:close()
 
Advertisement
 
                    Add Comment                
                
                        Please, Sign In to add comment