pianorollpicture2famitracker.sdlbas 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. #! /usr/bin/sdlbrt
  2. finp$="test.png"
  3. if argc>2 then:finp$=argv(2):end if
  4. fout$=finp$+"_famitracker.txt"
  5. shell("identify -format \'%w\n\' "+finp$+" > _width_.txt")
  6. open "_width_.txt" for input as #1
  7. file input #1,picwst$
  8. picw=val(picwst$)
  9. print picw
  10. close #1
  11. shell("rm _width_.txt")
  12. qtxoub$=": ... .. . ... "
  13. qtxou$=""
  14. for i=1 to 13:qtxou$+=qtxoub$:next
  15. qtxou$="ROW xx "+qtxou$
  16. qtxouf$=qtxou$
  17. dim chn[50]
  18. 'convert image -format "%wx%h" info:
  19. 'identify -format "%wx%h" image
  20. 'convert image -format "%b" info:
  21. 'identify -format "%b" image
  22. function nttnte$(noteb)
  23. e$= "C-1C#1D-1D#1E-1F-1F#1G-1G#1A-1A#1B-1"
  24. e$=e$+"C-2C#2D-2D#2E-2F-2F#2G-2G#2A-2A#2B-2"
  25. e$=e$+"C-3C#3D-3D#3E-3F-3F#3G-3G#3A-3A#3B-3"
  26. e$=e$+"C-4C#4D-4D#4E-4F-4F#4G-4G#4A-4A#4B-4"
  27. e$=e$+"C-5C#5D-5D#5E-5F-5F#5G-5G#5A-5A#5B-5"
  28. e$=e$+"C-6C#6D-6D#6E-6F-6F#6G-6G#6A-6A#6B-6"
  29. e$=e$+"C-7C#7D-7D#7E-7F-7F#7G-7G#7A-7A#7B-7"
  30. e$=e$+"C-8C#8D-8D#8E-8F-8F#8G-8G#8A-8A#8B-8..."
  31. tmq=noteb
  32. if tmq<1 then:tmq=1:end if
  33. if tmq>97 then:tmq=97:end if
  34. return mid$(e$,(tmq*3)-2,3)
  35. end function
  36. function hfromrgbhex(hexvl)
  37. tcvl=hexvl
  38. rv=bitwiseand(tcvl,255):tcvl=int(tcvl/256)
  39. gv=bitwiseand(tcvl,255):tcvl=int(tcvl/256)
  40. bv=bitwiseand(tcvl,255)
  41. minv=255
  42. if rv<minv then:minv=rv:end if
  43. if gv<minv then:minv=gv:end if
  44. if bv<minv then:minv=bv:end if
  45. maxv=0
  46. if rv>maxv then:maxv=rv:end if
  47. if gv>maxv then:maxv=gv:end if
  48. if bv>maxv then:maxv=bv:end if
  49. deltav=maxv-minv
  50. if deltav<.1 then:deltav=.1:end if
  51. if maxv=0 then:hv=0:end if
  52. if gv=maxv then:hv=2+((bv-rv)/deltav):end if
  53. if bv=maxv then:hv=4+((rv-gv)/deltav):end if
  54. if rv=maxv then:hv=((gv-bv)/deltav):end if
  55. hv=((int(hv*60))+36000)mod 360
  56. return hv
  57. end function
  58. function sfromrgbhex(hexvl)
  59. tcvl=hexvl
  60. rv=bitwiseand(tcvl,255):tcvl=int(tcvl/256)
  61. gv=bitwiseand(tcvl,255):tcvl=int(tcvl/256)
  62. bv=bitwiseand(tcvl,255)
  63. minv=255
  64. if rv<minv then:minv=rv:end if
  65. if gv<minv then:minv=gv:end if
  66. if bv<minv then:minv=bv:end if
  67. maxv=0
  68. if rv>maxv then:maxv=rv:end if
  69. if gv>maxv then:maxv=gv:end if
  70. if bv>maxv then:maxv=bv:end if
  71. deltav=maxv-minv
  72. if deltav<.1 then:deltav=.1:end if
  73. if maxv<>0 then:sv=deltav/maxv:end if
  74. if maxv=0 then:sv=0:end if
  75. sv=int(sv*255)
  76. return sv
  77. end function
  78. function vfromrgbhex(hexvl)
  79. tcvl=hexvl
  80. rv=bitwiseand(tcvl,255):tcvl=int(tcvl/256)
  81. gv=bitwiseand(tcvl,255):tcvl=int(tcvl/256)
  82. bv=bitwiseand(tcvl,255)
  83. maxv=0
  84. if rv>maxv then:maxv=rv:end if
  85. if gv>maxv then:maxv=gv:end if
  86. if bv>maxv then:maxv=bv:end if
  87. vv=maxv
  88. return vv
  89. end function
  90. setdisplay(512,128,32,1)
  91. if picw<>0 then:setdisplay(picw,128,32,1):end if
  92. paper(8^8-1):ink(0):pen(0):cls
  93. loadimage(finp$,1):pasteicon(0,0,1)
  94. for x=0 to 31
  95. u=point(x,0)
  96. qh=hfromrgbhex(u)
  97. qs=sfromrgbhex(u)
  98. if qs>50 then
  99. chn[int(qh/10)]=x
  100. end if
  101. next
  102. open fout$ for output as #2
  103. print #2,"# FamiTracker text format"
  104. print #2,"# Module information"
  105. print #2,"TITLE \"\""
  106. print #2,"AUTHOR \"\""
  107. print #2,"COPYRIGHT \"\""
  108. print #2,"# Module comment"
  109. print #2,"COMMENT \"\""
  110. print #2,"# Global settings"
  111. print #2,"MACHINE 0"
  112. print #2,"FRAMERATE 0"
  113. print #2,"EXPANSION 16"
  114. print #2,"VIBRATO 1"
  115. print #2,"SPLIT 32"
  116. print #2,"# Namco 163 global settings"
  117. print #2,"N163CHANNELS 5"
  118. print #2,"# Macros"
  119. print #2,"# DPCM samples"
  120. print #2,"# Detune settings"
  121. print #2,"# Grooves"
  122. print #2,"# Tracks using default groove"
  123. print #2,"# Instruments"
  124. print #2,"INST2A03 0 -1 -1 -1 -1 -1 \"instrument00\""
  125. print #2,"INSTN163 1 -1 -1 -1 -1 -1 32 0 1 \"instrument01\""
  126. print #2,"# Tracks"
  127. print #2,"TRACK 64 6 128 \"test\""
  128. print #2,"COLUMNS : 1 1 1 1 1 1 1 1 1 1 1 1 1"
  129. print #2,"N163WAVE 1 0 : 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0"
  130. lml=1
  131. for x=0 to picw-1
  132. if x mod 64=0 then:print #2," ":print #2,"Pattern "+ucase$(right$("00"+hex$(int(x/64)),2)):end if
  133. qtxou$=qtxouf$
  134. if x>32 then:lml=0:end if
  135. for y=95 to lml step -1
  136. u=point(x,y)
  137. qs=sfromrgbhex(u)
  138. qh=hfromrgbhex(u)
  139. vs=vfromrgbhex(u)
  140. if qs>10 then
  141. qtxou$=replace$(chn[int(qh/10)]*15+9,qtxou$,nttnte$(y))
  142. if chn[int(qh/10)]<5 then
  143. qtxou$=replace$(chn[int(qh/10)]*15+13,qtxou$,"00")
  144. else
  145. qtxou$=replace$(chn[int(qh/10)]*15+13,qtxou$,"01")
  146. end if
  147. qtxou$=replace$(chn[int(qh/10)]*15+16,qtxou$, ucase$(right$("0"+hex$( int(qs/16) ),1)) )
  148. 'qtxou$=replace$(chn[int(qh/10)]*15+18,qtxou$, str$(qh) )
  149. end if
  150. next
  151. qtxou$=replace$(4,qtxou$,ucase$(right$("00"+hex$(x mod 64),2)))
  152. print #2,qtxou$
  153. if x mod 64=63 then:print:end if
  154. next
  155. print #2," "
  156. for x=0 to picw-1 step 64
  157. txou8$=ucase$(right$("00"+hex$(int(x/64)),2))
  158. txou9$="ORDER "+txou8$+" : "
  159. for z=1 to 13:txou9$+=txou8$:txou9$+=" ":next
  160. print #2,txou9$
  161. next
  162. print #2," "
  163. print #2,"# End of export"
  164. close #2
  165. 'waitkey