Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '--- mod to txt converter - Paulo Silva - march '08 - GPL
- '--- started april '04 (wxBasic version) - .mod tune document converter to a .txt document
- '--- (tune trakers should be able to import and export .txt documents, just like VortexTracker does!)
- finp$="sometune.mod": fout$=finp$+".txt"
- '-------------------------------------------------------------
- '--- define variables and arrays
- songname$="":mkflag$="":npatt=0:nflag=0
- dim samplename$[32],samplelngth[32],sampleftune[32],samplevolum[32],samplereppt[32],samplerepln[32],pattseq[128]
- '----------------------------------------------- functions ------
- function decadj$(a,b)
- tmpr$=right$(string$(b,asc("0"))+str$(a),b):decadj$=tmpr$:end function
- function hxfx$(a,b)
- tmpr$=ucase$(right$(string$(b,asc("0"))+hex$(a),b)):hxfx$=tmpr$:end function
- function nttfrq$(b)
- a$= "3424,3232,3050,2880,2714,2562,2418,2282,2154,2034,1922,1814,"
- a$=a$+"1712,1616,1525,1440,1357,1281,1209,1141,1077,1017, 961, 907,"
- a$=a$+" 856, 808, 762, 720, 678, 640, 604, 570, 538, 508, 480, 453,"
- a$=a$+" 428, 404, 381, 360, 339, 320, 302, 285, 269, 254, 240, 226,"
- a$=a$+" 214, 202, 190, 180, 170, 160, 151, 143, 135, 127, 120, 113,"
- a$=a$+" 107, 101, 95, 90, 85, 80, 75, 71, 67, 63, 60, 56,"
- a$=a$+" 53, 50, 47, 45, 42, 40, 37, 35, 33, 31, 30, 28,"
- a$=a$+" 26, 25, 23, 22, 21, 20, 18, 17, 16, 15, 15, 14,"
- fl=0:tmpr=0
- for c=1 to 96
- d=val(mid$(a$,((c-1)*5)+1,4))
- if ((b<(d+(d/35)))and(b>(d-(d/35)))and(fl=0)) then:fl=1:tmpr=c:end if:next
- if b=0 then:tmpr=0:end if
- '- correct notation?
- e$="...C-2C#2D-2D#2E-2F-2F#2G-2G#2A-2A#2B-2"
- e$=e$+"C-3C#3D-3D#3E-3F-3F#3G-3G#3A-3A#3B-3"
- e$=e$+"C-4C#4D-4D#4E-4F-4F#4G-4G#4A-4A#4B-4"
- e$=e$+"C-5C#5D-5D#5E-5F-5F#5G-5G#5A-5A#5B-5"
- e$=e$+"C-6C#6D-6D#6E-6F-6F#6G-6G#6A-6A#6B-6"
- e$=e$+"C-7C#7D-7D#7E-7F-7F#7G-7G#7A-7A#7B-7"
- e$=e$+"C-8C#8D-8D#8E-8F-8F#8G-8G#8A-8A#8B-8"
- tmpz$=mid$(e$,(tmpr*3)+1,3):nttfrq$=tmpz$:end function
- '--- open document
- open finp$ for input as #1
- '------------------------------- document reading -----
- '--- song name
- tmpr$="":for j=0 to 19:a=readbyte(1):if (a<32 or a>127) then: a=0x2E:end if:tmpr$=tmpr$+chr$(a):next
- songname$=tmpr$
- '--- each sample info
- for i=1 to 31:tmpr$=""
- for j=0 to 21:a=readbyte(1)
- if (a<32 or a>127) then: a=0x2E: end if
- tmpr$=tmpr$+chr$(a):next
- samplename$[i]=tmpr$
- '- get more info here
- v0=readbyte(1):v1=readbyte(1):v=(v1+(v0*256))*2:samplelngth[i]=v
- v=readbyte(1):sampleftune[i]=v:v=readbyte(1):samplevolum[i]=v
- v0=readbyte(1):v1=readbyte(1):v=(v1+(v0*256))*2:samplereppt[i]=v
- v0=readbyte(1):v1=readbyte(1):v=(v1+(v0*256))*2:samplerepln[i]=v:next
- '--- tune pattern ammount
- v=readbyte(1):npatt=v
- '--- noisetracker flag
- v=readbyte(1):nflag=v
- '--- pattern sequence
- for i=0 to 127:v=readbyte(1):pattseq[i]=v:next
- '--- M.K. flag
- tmpr$=""
- for j=0 to 3:a=readbyte(1)
- if (a<32 or a>127) then:a=0x2E:end if
- tmpr$=tmpr$+chr$(a):next
- mkflag$=tmpr$:chanamt=val(left$(mkflag$,2))
- '--- defines hgpat
- hgpat=0:for i=0 to 127:if pattseq[i]>hgpat then: hgpat=pattseq[i]:end if:next
- '--- l� patfreq[],effectvl[],samplenumvl[]
- dim patfreq[hgpat,64,64],effectvl[hgpat,64,64],samplenumvl[hgpat,64,64]
- for l1=0 to hgpat
- for l2=0 to 63
- for l3=0 to chanamt-1
- v0=readbyte(1):v1=readbyte(1):v2=readbyte(1):v3=readbyte(1)
- vf=v1+((bitwiseand(v0,0x0F))*256):patfreq[l1,l2,l3]=vf
- vf=v3+((bitwiseand(v2,0x0F))*256):effectvl[l1,l2,l3]=vf
- vf=(bitwiseand(v0,0xF0))+((bitwiseand(v2,0xF0))/16):samplenumvl[l1,l2,l3]=vf
- next:next:next
- '- doesn't closes #1, for samples conversion as hexdump
- '-------------------------------------- saving the document -------
- open fout$ for output as #2
- print #2,"#Songname:"+songname$
- for i=1 to 31
- ofst$=" #Sample"+decadj$(i,2)
- ofst$=ofst$+":L"+str$(samplelngth[i])
- ofst$=ofst$+":T"+str$(sampleftune[i])
- ofst$=ofst$+":V"+str$(samplevolum[i])
- ofst$=ofst$+":RP"+str$(samplereppt[i])
- ofst$=ofst$+":RL"+str$(samplerepln[i])
- ofst$=ofst$+":"+str$(samplename$[i])
- print #2,ofst$:next
- print #2,"#NrPatterns:"+str$(npatt)
- print #2,"#Flags:"+str$(nflag)+":"+mkflag$
- for i=0 to 127 step 16:ofst$=" #Pattseq"
- for j=0 to 15:ofst$=ofst$+":"+hxfx$(pattseq[i+j],2):next
- print #2,ofst$:ofst$="":next
- print #2," "
- '- (l3:flags) - important - mkflag$
- for l1=0 to hgpat:print #2,"## Pattern "+hxfx$(l1,2)
- for l2=0 to 63:ofst$=""
- for l3=0 to chanamt-1
- ofst$=ofst$+nttfrq$(patfreq[l1,l2,l3])+" ("
- ofst$=ofst$+hxfx$(effectvl[l1,l2,l3],3)+":"
- ofst$=ofst$+decadj$(samplenumvl[l1,l2,l3],2)+") ":next
- print #2,ofst$:next:next
- '- conversion of samples into hexdump
- for i=1 to 31
- print #2," ":print #2,"## Sample "+decadj$(i,2):tmpr$=""
- for j=1 to samplelngth[i]
- a1=readbyte(1):tmpr$=tmpr$+hxfx$(a1,2)
- if (j-1 mod 32)=31 then:print #2,tmpr$:tmpr$="":end if:next
- if len(tmpr$)>0 then:print #2,tmpr$:tmpr$="":end if:next
- close #2:close #1
Advertisement
Add Comment
Please, Sign In to add comment