Advertisement
Press0K

midi

Oct 14th, 2019
599
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.00 KB | None | 0 0
  1. mon = peripheral.wrap("top")
  2. spk = peripheral.wrap("right")
  3. songname = "Untitled.mid"
  4. pats = {
  5. snare = {},
  6. hat = {},
  7. basedrum = {},
  8. bass = {},
  9. harp = {},
  10. flute = {},
  11. bell = {},
  12. chime = {},
  13. guitar = {},
  14. }
  15. instNames = {
  16. "snare",
  17. "hat",
  18. "basedrum",
  19. "bass",
  20. "harp",
  21. "flute",
  22. "bell",
  23. "chime",
  24. "guitar",
  25. }
  26. songLength = 32
  27.  
  28.  
  29. function Main()
  30. while true do
  31. DrawHome()
  32. end
  33. end
  34.  
  35. function DrawHome()
  36. mon.clear()
  37. mon.setCursorPos(1,1)
  38. mon.setTextColor(colors.white)
  39. mon.setBackgroundColor(colors.blue)
  40. mon.write(" " .. songname .. " ")
  41. mon.setCursorPos(19,1)
  42. mon.setTextColor(colors.black)
  43. mon.setBackgroundColor(colors.green)
  44. mon.write(" PLAY ")
  45. mon.setCursorPos(25,1)
  46. mon.setTextColor(colors.black)
  47. mon.setBackgroundColor(colors.red)
  48. mon.write(" STOP ")
  49. mon.setCursorPos(33,1)
  50. mon.setTextColor(colors.black)
  51. mon.setBackgroundColor(colors.orange)
  52. mon.write(" SAVE ")
  53. mon.setCursorPos(39,1)
  54. mon.setTextColor(colors.red)
  55. mon.setBackgroundColor(colors.black)
  56. mon.write("X")
  57.  
  58. local c = 0
  59. mon.setBackgroundColor(colors.black)
  60. for k, v in pairs(pats) do
  61. mon.setCursorPos(4,3+i)
  62. if #v > 0 then
  63. mon.setTextColor(colors.green)
  64. else
  65. mon.setTextColor(colors.gray)
  66. end
  67. mon.write(k)
  68. c = c + 1
  69. end
  70.  
  71. local x, y = GetClick()
  72. if y == 1 then
  73. if x >= 19 and x <= 24 then
  74. -- PLAY
  75. elseif x >= 25 and x <= 30 then
  76. -- STOP
  77. elseif x >= 33 and x <= 38 then
  78. -- SAVE
  79. elseif x == 39 then
  80. -- QUIT
  81. end
  82. elseif y >= 3 and y <= 11 then
  83. local instIndex = y - 2
  84. if x >= 4 and x <= instNames[instIndex]:len() - 1 then
  85. DrawPat(instNames[instIndex])
  86. end
  87. end
  88. end
  89.  
  90. function DrawPat(inst)
  91. local viewSection = 1
  92.  
  93. while true do
  94. mon.clear()
  95. mon.setCursorPos(1,1)
  96. mon.setTextColor(colors.black)
  97. mon.setBackgroundColor(colors.orange)
  98. mon.write(" " .. inst .. " ")
  99. mon.setCursorPos(19,1)
  100. mon.setTextColor(colors.black)
  101. mon.setBackgroundColor(colors.green)
  102. mon.write(" PLAY ")
  103. mon.setCursorPos(25,1)
  104. mon.setTextColor(colors.black)
  105. mon.setBackgroundColor(colors.red)
  106. mon.write(" STOP ")
  107. mon.setCursorPos(34,1)
  108. mon.setTextColor(colors.black)
  109. mon.setBackgroundColor(colors.orange)
  110. mon.write(" BACK ")
  111.  
  112. for i = 1, 9 do
  113. for j = 1, 32 do
  114. mon.setCursorPos(3,2+j)
  115. if pats[inst][j] == i then
  116. mon.setBackgroundColor(colors.blue)
  117. else
  118. mon.setBackgroundColor(colors.black)
  119. end
  120. mon.write(" ")
  121. end
  122. end
  123.  
  124. local x, y = GetClick()
  125. if y == 1 then
  126. if x >= 19 and x <= 24 then
  127. -- PLAY
  128. elseif x >= 25 and x <= 30 then
  129. -- STOP
  130. elseif x >= 34 and x <= 39 then
  131. -- BACK
  132. end
  133. -- elseif y >= 3 and y <= 11 then
  134. -- local instIndex = y - 2
  135. -- if x >= 4 and x <= instNames[instIndex]:len() - 1 then
  136. -- DrawPat(instNames[instIndex])
  137. -- end
  138. end
  139. end
  140. end
  141.  
  142. function GetClick()
  143. while true do
  144. local event, p1, p2, p3 = os.pullEvent()
  145. if event == "monitor_touch" or event == "mouse_click" then
  146. return p2, p3
  147. end
  148. end
  149. end
  150.  
  151. args = {...}
  152. if #args > 0 then
  153. -- load a saved file
  154. else
  155. for k, v in pats do
  156. for i = 1, songLength do
  157. table.insert(v, 0)
  158. end
  159. end
  160. end
  161. Main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement