Guest User

Paulo Silva

a guest
Mar 7th, 2008
818
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. '--- mod to txt converter - Paulo Silva - march '08 - GPL
  2. '--- started april '04 (wxBasic version) - .mod tune document converter to a .txt document
  3. '--- (tune trakers should be able to import and export .txt documents, just like VortexTracker does!)
  4. finp$="sometune.mod": fout$=finp$+".txt"
  5. '-------------------------------------------------------------
  6. '--- define variables and arrays
  7. songname$="":mkflag$="":npatt=0:nflag=0
  8. dim samplename$[32],samplelngth[32],sampleftune[32],samplevolum[32],samplereppt[32],samplerepln[32],pattseq[128]
  9. '----------------------------------------------- functions ------
  10. function decadj$(a,b)
  11.   tmpr$=right$(string$(b,asc("0"))+str$(a),b):decadj$=tmpr$:end function
  12. function hxfx$(a,b)
  13.   tmpr$=ucase$(right$(string$(b,asc("0"))+hex$(a),b)):hxfx$=tmpr$:end function
  14. function nttfrq$(b)
  15.   a$=   "3424,3232,3050,2880,2714,2562,2418,2282,2154,2034,1922,1814,"
  16.   a$=a$+"1712,1616,1525,1440,1357,1281,1209,1141,1077,1017, 961, 907,"
  17.   a$=a$+" 856, 808, 762, 720, 678, 640, 604, 570, 538, 508, 480, 453,"
  18.   a$=a$+" 428, 404, 381, 360, 339, 320, 302, 285, 269, 254, 240, 226,"
  19.   a$=a$+" 214, 202, 190, 180, 170, 160, 151, 143, 135, 127, 120, 113,"
  20.   a$=a$+" 107, 101,  95,  90,  85,  80,  75,  71,  67,  63,  60,  56,"
  21.   a$=a$+"  53,  50,  47,  45,  42,  40,  37,  35,  33,  31,  30,  28,"
  22.   a$=a$+"  26,  25,  23,  22,  21,  20,  18,  17,  16,  15,  15,  14,"
  23.   fl=0:tmpr=0
  24.   for c=1 to 96
  25.     d=val(mid$(a$,((c-1)*5)+1,4))
  26.     if ((b<(d+(d/35)))and(b>(d-(d/35)))and(fl=0)) then:fl=1:tmpr=c:end if:next
  27.   if b=0 then:tmpr=0:end if
  28.   '- correct notation?
  29.   e$="...C-2C#2D-2D#2E-2F-2F#2G-2G#2A-2A#2B-2"
  30.   e$=e$+"C-3C#3D-3D#3E-3F-3F#3G-3G#3A-3A#3B-3"
  31.   e$=e$+"C-4C#4D-4D#4E-4F-4F#4G-4G#4A-4A#4B-4"
  32.   e$=e$+"C-5C#5D-5D#5E-5F-5F#5G-5G#5A-5A#5B-5"
  33.   e$=e$+"C-6C#6D-6D#6E-6F-6F#6G-6G#6A-6A#6B-6"
  34.   e$=e$+"C-7C#7D-7D#7E-7F-7F#7G-7G#7A-7A#7B-7"
  35.   e$=e$+"C-8C#8D-8D#8E-8F-8F#8G-8G#8A-8A#8B-8"
  36.   tmpz$=mid$(e$,(tmpr*3)+1,3):nttfrq$=tmpz$:end function
  37. '--- open document
  38. open finp$ for input as #1
  39. '------------------------------- document reading -----
  40. '--- song name
  41.   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
  42.   songname$=tmpr$
  43. '--- each sample info
  44.   for i=1 to 31:tmpr$=""
  45.     for j=0 to 21:a=readbyte(1)
  46.       if (a<32 or a>127) then: a=0x2E: end if
  47.       tmpr$=tmpr$+chr$(a):next
  48.     samplename$[i]=tmpr$
  49.     '- get more info here
  50.     v0=readbyte(1):v1=readbyte(1):v=(v1+(v0*256))*2:samplelngth[i]=v
  51.     v=readbyte(1):sampleftune[i]=v:v=readbyte(1):samplevolum[i]=v
  52.     v0=readbyte(1):v1=readbyte(1):v=(v1+(v0*256))*2:samplereppt[i]=v
  53.     v0=readbyte(1):v1=readbyte(1):v=(v1+(v0*256))*2:samplerepln[i]=v:next
  54.   '--- tune pattern ammount
  55.   v=readbyte(1):npatt=v
  56.   '--- noisetracker flag
  57.   v=readbyte(1):nflag=v
  58.   '--- pattern sequence
  59.   for i=0 to 127:v=readbyte(1):pattseq[i]=v:next
  60.   '--- M.K. flag
  61.   tmpr$=""
  62.   for j=0 to 3:a=readbyte(1)
  63.     if (a<32 or a>127) then:a=0x2E:end if
  64.     tmpr$=tmpr$+chr$(a):next
  65.   mkflag$=tmpr$:chanamt=val(left$(mkflag$,2))
  66.   '--- defines hgpat
  67.   hgpat=0:for i=0 to 127:if pattseq[i]>hgpat then: hgpat=pattseq[i]:end if:next
  68.   '--- l� patfreq[],effectvl[],samplenumvl[]
  69.   dim patfreq[hgpat,64,64],effectvl[hgpat,64,64],samplenumvl[hgpat,64,64]
  70.   for l1=0 to hgpat  
  71.     for l2=0 to 63
  72.       for l3=0 to chanamt-1
  73.         v0=readbyte(1):v1=readbyte(1):v2=readbyte(1):v3=readbyte(1)
  74.         vf=v1+((bitwiseand(v0,0x0F))*256):patfreq[l1,l2,l3]=vf
  75.         vf=v3+((bitwiseand(v2,0x0F))*256):effectvl[l1,l2,l3]=vf
  76.         vf=(bitwiseand(v0,0xF0))+((bitwiseand(v2,0xF0))/16):samplenumvl[l1,l2,l3]=vf
  77.         next:next:next
  78.   '- doesn't closes #1, for samples conversion as hexdump
  79.   '-------------------------------------- saving the document -------
  80.   open fout$ for output as #2
  81.   print #2,"#Songname:"+songname$
  82.   for i=1 to 31
  83.     ofst$="  #Sample"+decadj$(i,2)
  84.     ofst$=ofst$+":L"+str$(samplelngth[i])
  85.     ofst$=ofst$+":T"+str$(sampleftune[i])
  86.     ofst$=ofst$+":V"+str$(samplevolum[i])
  87.     ofst$=ofst$+":RP"+str$(samplereppt[i])
  88.     ofst$=ofst$+":RL"+str$(samplerepln[i])
  89.     ofst$=ofst$+":"+str$(samplename$[i])
  90.     print #2,ofst$:next
  91.   print #2,"#NrPatterns:"+str$(npatt)
  92.   print #2,"#Flags:"+str$(nflag)+":"+mkflag$
  93.   for i=0 to 127 step 16:ofst$="  #Pattseq"
  94.     for j=0 to 15:ofst$=ofst$+":"+hxfx$(pattseq[i+j],2):next
  95.     print #2,ofst$:ofst$="":next
  96.   print #2," "
  97.   '- (l3:flags) - important - mkflag$
  98.   for l1=0 to hgpat:print #2,"## Pattern "+hxfx$(l1,2)
  99.     for l2=0 to 63:ofst$=""
  100.       for l3=0 to chanamt-1
  101.         ofst$=ofst$+nttfrq$(patfreq[l1,l2,l3])+" ("
  102.         ofst$=ofst$+hxfx$(effectvl[l1,l2,l3],3)+":"
  103.         ofst$=ofst$+decadj$(samplenumvl[l1,l2,l3],2)+") ":next
  104.       print #2,ofst$:next:next
  105.   '- conversion of samples into hexdump
  106.   for i=1 to 31
  107.     print #2," ":print #2,"## Sample "+decadj$(i,2):tmpr$=""
  108.     for j=1 to samplelngth[i]
  109.       a1=readbyte(1):tmpr$=tmpr$+hxfx$(a1,2)
  110.       if (j-1 mod 32)=31 then:print #2,tmpr$:tmpr$="":end if:next
  111.     if len(tmpr$)>0 then:print #2,tmpr$:tmpr$="":end if:next
  112.   close #2:close #1
  113.  
  114.  
  115.  
Advertisement
Add Comment
Please, Sign In to add comment