pianorollpicture2openmptclipboard.sdlbas 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. #! /usr/bin/sdlbrt
  2. finp$="test.png"
  3. if argc>2 then:finp$=argv(2):end if
  4. fout$=finp$+"_openmptclipboard.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 8:qtxou$+=qtxoub$:next
  15. qtxouf$=qtxou$
  16. dim chn[50]
  17. function nttnte$(noteb)
  18. e$= "C-1C#1D-1D#1E-1F-1F#1G-1G#1A-1A#1B-1"
  19. e$=e$+"C-2C#2D-2D#2E-2F-2F#2G-2G#2A-2A#2B-2"
  20. e$=e$+"C-3C#3D-3D#3E-3F-3F#3G-3G#3A-3A#3B-3"
  21. e$=e$+"C-4C#4D-4D#4E-4F-4F#4G-4G#4A-4A#4B-4"
  22. e$=e$+"C-5C#5D-5D#5E-5F-5F#5G-5G#5A-5A#5B-5"
  23. e$=e$+"C-6C#6D-6D#6E-6F-6F#6G-6G#6A-6A#6B-6"
  24. e$=e$+"C-7C#7D-7D#7E-7F-7F#7G-7G#7A-7A#7B-7"
  25. e$=e$+"C-8C#8D-8D#8E-8F-8F#8G-8G#8A-8A#8B-8..."
  26. tmq=noteb
  27. if tmq<1 then:tmq=1:end if
  28. if tmq>97 then:tmq=97:end if
  29. return mid$(e$,(tmq*3)-2,3)
  30. end function
  31. function hfromrgbhex(hexvl)
  32. tcvl=hexvl
  33. rv=bitwiseand(tcvl,255):tcvl=int(tcvl/256)
  34. gv=bitwiseand(tcvl,255):tcvl=int(tcvl/256)
  35. bv=bitwiseand(tcvl,255)
  36. minv=255
  37. if rv<minv then:minv=rv:end if
  38. if gv<minv then:minv=gv:end if
  39. if bv<minv then:minv=bv:end if
  40. maxv=0
  41. if rv>maxv then:maxv=rv:end if
  42. if gv>maxv then:maxv=gv:end if
  43. if bv>maxv then:maxv=bv:end if
  44. deltav=maxv-minv
  45. if deltav<.1 then:deltav=.1:end if
  46. if maxv=0 then:hv=0:end if
  47. if gv=maxv then:hv=2+((bv-rv)/deltav):end if
  48. if bv=maxv then:hv=4+((rv-gv)/deltav):end if
  49. if rv=maxv then:hv=((gv-bv)/deltav):end if
  50. hv=((int(hv*60))+36000)mod 360
  51. return hv
  52. end function
  53. function sfromrgbhex(hexvl)
  54. tcvl=hexvl
  55. rv=bitwiseand(tcvl,255):tcvl=int(tcvl/256)
  56. gv=bitwiseand(tcvl,255):tcvl=int(tcvl/256)
  57. bv=bitwiseand(tcvl,255)
  58. minv=255
  59. if rv<minv then:minv=rv:end if
  60. if gv<minv then:minv=gv:end if
  61. if bv<minv then:minv=bv:end if
  62. maxv=0
  63. if rv>maxv then:maxv=rv:end if
  64. if gv>maxv then:maxv=gv:end if
  65. if bv>maxv then:maxv=bv:end if
  66. deltav=maxv-minv
  67. if deltav<.1 then:deltav=.1:end if
  68. if maxv<>0 then:sv=deltav/maxv:end if
  69. if maxv=0 then:sv=0:end if
  70. sv=int(sv*255)
  71. return sv
  72. end function
  73. function vfromrgbhex(hexvl)
  74. tcvl=hexvl
  75. rv=bitwiseand(tcvl,255):tcvl=int(tcvl/256)
  76. gv=bitwiseand(tcvl,255):tcvl=int(tcvl/256)
  77. bv=bitwiseand(tcvl,255)
  78. maxv=0
  79. if rv>maxv then:maxv=rv:end if
  80. if gv>maxv then:maxv=gv:end if
  81. if bv>maxv then:maxv=bv:end if
  82. vv=maxv
  83. return vv
  84. end function
  85. setdisplay(512,128,32,1)
  86. if picw<>0 then:setdisplay(picw,128,32,1):end if
  87. paper(8^8-1):ink(0):pen(0):cls
  88. loadimage(finp$,1):pasteicon(0,0,1)
  89. for x=0 to 7
  90. u=point(x,0)
  91. qh=hfromrgbhex(u)
  92. qs=sfromrgbhex(u)
  93. if qs>50 then
  94. chn[int(qh/10)]=x
  95. end if
  96. next
  97. open fout$ for output as #2
  98. print #2,"[Module]"
  99. print #2,"Format:mod"
  100. print #2,"Title:"
  101. print #2," "
  102. print #2,"[MoreInfo]"
  103. print #2,"SongLenght:"+str$(int(picw/64))
  104. print #2,"VersionFlag1:0x00"
  105. txou9$="PlayOrder:0"
  106. for x=64 to picw-1 step 64
  107. txou9$+=","+str$(int(x/64))
  108. next
  109. print #2,txou9$
  110. print #2,"VersionFlag2:8CHN"
  111. print #2," "
  112. print #2,"[SampleInfo0]"
  113. print #2,"Name:SquareWave"
  114. print #2,"Lenght:0x0020"
  115. print #2,"Finetune:0"
  116. print #2,"Volume:0x40"
  117. print #2,"RepeatPoint:0x0000"
  118. print #2,"RepeatLenght:0x0020"
  119. print #2," "
  120. print #2,"[Sample0]"
  121. print #2,"7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F80808080808080808080808080808080"
  122. lml=1
  123. for x=0 to picw-1
  124. if x mod 64=0 then:print #2," ":print #2,"[Pattern"+str$(int(x/64))+"]":print #2,"ModPlug Tracker MOD":end if
  125. qtxou$=qtxouf$
  126. if x>32 then:lml=0:end if
  127. for y=95 to lml step -1
  128. u=point(x,y)
  129. qs=sfromrgbhex(u)
  130. qh=hfromrgbhex(u)
  131. vs=vfromrgbhex(u)
  132. if qs>10 then
  133. qtxou$=replace$(chn[int(qh/10)]*12+1,qtxou$,nttnte$(y))
  134. qtxou$=replace$(chn[int(qh/10)]*12+4,qtxou$,"00")
  135. qtxou$=replace$(chn[int(qh/10)]*12+9,qtxou$,"C"+ucase$(right$("00"+hex$( (int(qs/16))*4 ),2)) )
  136. end if
  137. next
  138. 'qtxou$=replace$(4,qtxou$,ucase$(right$("00"+hex$(x mod 64),2)))
  139. print #2,qtxou$
  140. if x mod 64=63 then:print:end if
  141. next
  142. print #2," "
  143. close #2
  144. 'waitkey