ThinkInvisible

CTracker

Aug 19th, 2013
680
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 23.52 KB | None | 0 0
  1. ------------------------------------
  2. ---ThinkInvisible's-----------------
  3. ------------------------------------
  4. --                                --
  5. -- /----                          --
  6. -- |                              --
  7. -- |   -+- +-\  ^  /-- |/ /-- +-\ --
  8. -- |    |  |-/ /-\ |   +  +-- |-/ --
  9. -- |    |  | \ | | \-- |\ \-- | \ --
  10. -- |                              --
  11. -- \----                          --
  12. --      Minecraft Music Maker     --
  13. --                                --
  14. ------------------------------------
  15. ------------------------------------
  16. --     V1.0.1.1 FOR CC 1.56,      --
  17. --  REQUIRES IMMIBIS PERIPHERALS  --
  18. ------------------------------------
  19.  
  20.  
  21. ---------
  22. --SETUP--
  23. ---------
  24. term.clear()
  25. term.setCursorPos(1, 1)
  26.  
  27. if (not term.isColor()) then
  28.     print("You need to use an Advanced (Golden) Computer with this program! To craft one, use the normal Computer recipe and replace all Stone with Gold Ingots.")
  29.     error("Can't run - improper computer setup", 0)
  30. end
  31.  
  32. local function getDev(d, skip) --snippet from forums - find any side device 'd' is located on
  33.   for _, side in pairs(rs.getSides()) do
  34.     if (peripheral.isPresent(side)) then
  35.       if (peripheral.getType(side) == string.lower(d)) then
  36.         if(skip == 0) then
  37.             return side
  38.         else
  39.             skip = skip - 1
  40.         end
  41.       end
  42.     end
  43.   end
  44.   return nil
  45. end
  46.  
  47. local function tContains(t, find) --naive table contains function - assumes everything is a table
  48.     for _, i in pairs(t) do
  49.         if(i == find) then return true end
  50.     end
  51.     return false
  52. end
  53.  
  54. local monExists = false
  55. local mon = getDev("monitor", 0) --for the vuemeter, optional - advanced monitor (nyi, just ignore this)
  56. if(not mon) then
  57.     print("You can attatch at least two advanced monitors (horizontally) to your computer for a visualizer.")
  58.     print("Press enter to continue.")
  59.     read()
  60.     term.clear()
  61.     term.setCursorPos(1, 1)
  62. else
  63.     mon = peripheral.wrap(mon)
  64.     mon.getSize()
  65.     mszx, mszy = mon.getSize()
  66.     if mszx >= 18 and mszy >= 5 and mon.isColor() then
  67.         monExists = true
  68.     else
  69.         print("You must have at least two Advanced Monitors placed horizontally (widescreen) for a visualizer.")
  70.         print("Press enter to continue.")
  71.         read()
  72.         term.clear()
  73.         term.setCursorPos(1, 1)
  74.     end
  75. end
  76. local spka = getDev("speaker", 0) --for sound, required - immibis peripherals speaker
  77. local spkb = getDev("speaker", 1) --for sound, required - immibis peripherals speaker
  78. local validpairs = {"frontback", "leftright"}
  79. if ((not spka) or (not spkb)) then
  80.     print("You need two speakers from the Immibis' Peripherals mod to use this program! They must be on opposite sides of the computer, not top or bottom!")
  81.     error("Can't run - improper computer setup", 0)
  82. end
  83. local spkchain = spka .. spkb
  84. if (not tContains(validpairs, spkchain)) then --we want stereo to work at least a little right, so make sure there are two speakers on opposite sides
  85.     print("Your speakers must be on the LEFT AND RIGHT or FRONT AND BACK sides of the computer!")
  86.     error("Can't run - improper computer setup", 0)
  87. end
  88.  
  89. --volume variables
  90. local globVol = 15 --parent volume
  91. local partVol = 1 --amount of parent volume set by volume commands
  92. local panning = 0.5 --0 = left, 1 = right
  93.  
  94. --key variables
  95. local ctrlFlag = false --is the ctrl key down
  96.  
  97. --buffers, buffer flags
  98. local copyBuffer={} --copied data
  99. local copyStartX = 0 --copied data location flags
  100. local copyStartY = 0
  101. local copyEndX = 0
  102. local copyEndY = 0
  103. local extModulesNote={} --all modules
  104. local loadedModuleNote={} --current module
  105. local loadedModuleIndex = 1 --current module number
  106. local modStart = 1 --start of play loop
  107. local modEnd = 1 --end of play loop
  108. local modIndex = 1  --playing module
  109. local modLetterIndex = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"} --just a useful reference for number-to-letter stuff
  110.  
  111. --selection variables
  112. local colPlay = 1 --selected column (for play)
  113. local setCol = 1 --selected column (for edit)
  114. local setRow = 1 --selected row (for edit)
  115. local selStartX = 1 --flags for selection (for batch edit)
  116. local selStartY = 1
  117. local selEndX = 1
  118. local selEndY = 1
  119.  
  120. --display variables
  121. local displayHelp = true --show the help?
  122. local scrollAmt = 0 --horizontal scroll in notes
  123. local szx, szy = term.getSize() --used to determine how much of the screen to draw a bar
  124. local visNotes = {}
  125.  
  126. local mszx = 0
  127. local mszy = 0
  128. if mon then
  129.     local mszx, mszy = mon.getSize() --peripheral.call(mon, "getSize") --used to center the vuemeter
  130. end
  131. local visVals = {0, 0, 0, 0, 0, 0, 0, 0} --0 to 3 - 'time' value for each channel
  132. for i = 1, 8 do
  133.     visNotes[i] = {}
  134.     for j = 1, mszy do
  135.         visNotes[i][j] = 0
  136.     end
  137. end
  138. local visColIndex = {colors.black, colors.gray, colors.green, colors.lime}
  139.  
  140. --song and sound variables
  141. local tempo = 32 --rate of play - quarter notes per second
  142. local setOct = 3 --lowermost octave to 'type in' - the qwerty row
  143. local noteLetterIndex = {"C ", "C#", "D ", "D#", "E ", "F ", "F#", "G ", "G#", "A " , "A#", "B "} --used for text
  144. local freqLetterIndex = {16.35, 17.32, 18.35, 19.45, 20.60, 21.83, 23.12, 24.50, 25.96, 27.50, 29.14, 30.87} --used for calculation - frequencies of notes starting from C
  145. local playSong = false --auto increment song?
  146. local detcode = "9gkKQgoJwcKbeYthmSvlbn9UAUmPdz1a" --randomly generated code pasted into each file to identify it
  147.  
  148. for i = 1, 16 do --set up the arrays
  149.     extModulesNote[i] = {}
  150.     for j = 1, 8 do
  151.         extModulesNote[i][j] = {}
  152.         for k = 1, 64 do
  153.             extModulesNote[i][j][k] = -1
  154.         end
  155.     end
  156. end
  157. for j = 1, 8 do
  158.     loadedModuleNote[j] = {}
  159.     for k = 1, 64 do
  160.         loadedModuleNote[j][k] = -1
  161.     end
  162. end
  163.  
  164.  
  165. ----------------
  166. --MAIN PROGRAM--
  167. ----------------
  168.  
  169. function pushVuemeter(index)
  170.     for i = 1, 8 do
  171.         if loadedModuleNote[i][index] == -1 then
  172.             visVals[i] = visVals[i] > 0 and visVals[i] - 1 or 0
  173.             visNotes[i][1] = 0
  174.         elseif loadedModuleNote[i][index] == -2 then
  175.             visVals[i] = 0
  176.             visNotes[i][1] = 0
  177.         else
  178.             visVals[i] = 3
  179.             visNotes[i][1] = 1
  180.         end
  181.         for j = mszy, 2, -1 do
  182.             visNotes[i][j] = visNotes[i][j-1]
  183.         end
  184.     end
  185. end
  186.  
  187. function drawVuemeter()
  188.     mszx, mszy = mon.getSize()
  189.     mon.clear()
  190.     mon.setBackgroundColor(colors.white)
  191.     mon.setTextColor(colors.black)
  192.     for i = 1, mszy do
  193.         mon.setCursorPos(mszx / 2 + 1, i)
  194.         mon.write(" ")
  195.     end
  196.     for i = 1, 8 do
  197.         for j = 1, mszy do
  198.             mon.setBackgroundColor(visColIndex[visVals[i] + 1])
  199.             if visNotes[i][j] == 1 then
  200.                 if (j - colPlay) % 5 == 1 then
  201.                     mon.setBackgroundColor(colors.purple)
  202.                 elseif (j - colPlay) % 5 == 2 then
  203.                     mon.setBackgroundColor(colors.magenta)
  204.                 elseif (j - colPlay) % 5 == 3 then
  205.                     mon.setBackgroundColor(colors.lightBlue)
  206.                 elseif (j - colPlay) % 5 == 4 then
  207.                     mon.setBackgroundColor(colors.cyan)
  208.                 else
  209.                     mon.setBackgroundColor(colors.blue)
  210.                 end
  211.             end
  212.             mon.setCursorPos(mszx/2 + 1 - i, j)
  213.             mon.write(" ")
  214.             mon.setCursorPos(mszx/2 + 1 + i, j)
  215.             mon.write(" ")
  216.         end
  217.     end
  218. end
  219.  
  220. function playCol(index) --play a column to the speaker
  221.     if monExists then
  222.         pushVuemeter(index)
  223.         drawVuemeter()
  224.     end
  225.     peripheral.call(spka, "setAttenuation" , globVol * partVol * panning)
  226.     peripheral.call(spkb, "setAttenuation" , globVol * partVol * (1 - panning))
  227.     for i = 1, 8 do                                                
  228.         if(loadedModuleNote[i][index] >= 0) then peripheral.call(spka, "start", i-1, freqLetterIndex[loadedModuleNote[i][index]-math.floor(loadedModuleNote[i][index]/12)*12+1]*math.pow(2, math.floor(loadedModuleNote[i][index]/12))) end
  229.         if(loadedModuleNote[i][index] == -2) then peripheral.call(spka, "stop", i-1) end
  230.         if(loadedModuleNote[i][index] >= 0) then peripheral.call(spkb, "start", i-1, freqLetterIndex[loadedModuleNote[i][index]-math.floor(loadedModuleNote[i][index]/12)*12+1]*math.pow(2, math.floor(loadedModuleNote[i][index]/12))) end
  231.         if(loadedModuleNote[i][index] == -2) then peripheral.call(spkb, "stop", i-1) end
  232.     end
  233. end
  234.  
  235. function stopCol() --stop all sound
  236.     for i = 1, 8 do
  237.         peripheral.call(spka, "stop", i-1)
  238.         peripheral.call(spkb, "stop", i-1)
  239.     end
  240. end
  241.  
  242. function saveSong(fname) --save song to a file - will be replaced with a dialog
  243.     f = fs.open(fname, "w")
  244.     f.writeLine(detcode)
  245.     f.writeLine("ThinkInvisible - CTracker song file")
  246.     f.writeLine("You probably shouldn't change this manually")
  247.     f.writeLine(modStart)
  248.     f.writeLine(modEnd)
  249.     for i = modStart, modEnd do
  250.         for j = 1, 8 do
  251.             for k = 1, 64 do
  252.                 f.writeLine(extModulesNote[i][j][k])
  253.             end
  254.         end
  255.     end
  256.     f.writeLine(tempo)
  257.     f.close()
  258. end
  259.  
  260. function loadSong(fname) --load a song from a file - will be replaced with a dialog
  261.     f = fs.open(fname, "r")
  262.     if (not (f.readLine() == detcode)) then
  263.         f.close()
  264.         term.write("That isn't a valid CTracker song.")
  265.         read()
  266.         return false
  267.     end
  268.     f.readLine()
  269.     f.readLine()
  270.     modStart = tonumber(f.readLine())
  271.     modEnd = tonumber(f.readLine())
  272.     for i = modStart, modEnd do
  273.         for j = 1, 8 do
  274.             for k = 1, 64 do
  275.                 extModulesNote[i][j][k] = tonumber(f.readLine())
  276.             end
  277.         end
  278.     end
  279.     tempo = tonumber(f.readLine())
  280.     f.close()
  281.     loadModule(modStart)
  282. end
  283.  
  284. function loadModule(index) --load a module to the editing buffer
  285.     term.clear()
  286.     for i = 1, 8 do
  287.         for j = 1, 64 do
  288.             loadedModuleNote[i][j] = extModulesNote[index][i][j]
  289.         end
  290.     end
  291.     loadedModuleIndex = index
  292. end
  293.  
  294. function saveModule(index) --save the editing buffer to a module
  295.     term.clear()
  296.     for i = 1, 8 do
  297.         for j = 1, 64 do
  298.             extModulesNote[index][i][j] = loadedModuleNote[i][j]
  299.         end
  300.     end
  301. end
  302.  
  303. function setNote(channel, note, key) --set a note, obviously - just a safeguard
  304.     if(key == nil) then key = -1 end
  305.     loadedModuleNote[channel][note] = key
  306. end
  307.  
  308. while true do --main program loop
  309.     term.setBackgroundColor(colors.gray)
  310.     for j = 1, 4 do --draw the top menu bar
  311.         term.setCursorPos(1, j)
  312.         for i = 1, szx do
  313.             term.write(" ")
  314.         end
  315.     end
  316.     term.setCursorPos(1, 1) --write the button text
  317.     if(displayHelp == true) then term.setBackgroundColor(colors.white) term.setTextColor(colors.black) end
  318.     term.write("Help")
  319.     term.setBackgroundColor(colors.gray)
  320.     term.setTextColor(colors.white)
  321.     term.write("   ML " .. modLetterIndex[modStart] .. " " .. modLetterIndex[modEnd] .. " (12, 34 modify)")
  322.     term.setCursorPos(1, 2)
  323.     term.write("SAVE LOAD  OCTS " .. setOct .. " (56 modify)")
  324.     term.setCursorPos(1, 3)
  325.     if(playSong == true) then term.setTextColor(colors.red) else term.setTextColor(colors.white) end
  326.     term.write("Play")
  327.     term.setCursorPos(1, 4)
  328.     term.write("Tempo " .. tempo .. " (78 modify)")
  329.     term.setCursorPos(1, 5)
  330.     term.setBackgroundColor(colors.white)
  331.     term.setTextColor(colors.gray)
  332.     for i = 1, szx do --draw the divider
  333.         term.write(" ")
  334.     end
  335.     term.setCursorPos(1, 5) --write status bar stuff
  336.     term.write("MOD   ABCDEFGHIJKLMNOP  " .. setCol .. " " .. setRow)
  337.     term.setTextColor(colors.gray)
  338.     term.setCursorPos(5, 5)
  339.     term.write(tostring(loadedModuleIndex))
  340.     term.setCursorPos(7, 5)
  341.     term.write("A")
  342.     term.setCursorPos(6 + loadedModuleIndex, 5)
  343.     term.setBackgroundColor(colors.black)
  344.     term.setTextColor(colors.white)
  345.     term.write(" ")
  346.     for i = 1, 64 do --draw a the notes!
  347.         for j = 1, 8 do
  348.             term.setCursorPos(i*3 - scrollAmt * 3 - 2 , j+5)
  349.             term.setBackgroundColor(colors.black) --default notes to a black background with white text
  350.             term.setTextColor(colors.white)
  351.             if(i == setCol or setRow == j) then term.setBackgroundColor(colors.blue) elseif(i % 4 == 1) then term.setBackgroundColor(colors.gray) end
  352.              --if the column or row is the selected one set the background to blue. if the column is a first beat (4/4 time) set the background to grey.
  353.             if(playSong == true) then
  354.                 if(i == colPlay) then term.setBackgroundColor(colors.lime) term.setTextColor(colors.black) end
  355.             else
  356.                 if(i == colPlay) then term.setBackgroundColor(colors.yellow) term.setTextColor(colors.black) end
  357.             end
  358.              --if the playing position is at this column set it to yellow (paused) or lime.
  359.             if(i == setCol and setRow == j) then term.setBackgroundColor(colors.green) term.setTextColor(colors.black) end
  360.             if((i >= selStartX) and (i <= selEndX) and (j >= selStartY) and (j <= selEndY)) then
  361.                 term.setTextColor(colors.blue)
  362.                 term.setBackgroundColor(colors.orange)
  363.             end
  364.             if(loadedModuleNote[j][i] == -1) then term.write("--") elseif(loadedModuleNote[j][i] == -2) then term.write("==") else
  365.                 term.write(noteLetterIndex[1 + loadedModuleNote[j][i] - math.floor(loadedModuleNote[j][i]/12)*12]) end
  366.             term.write(tostring(math.floor(loadedModuleNote[j][i]/12)))
  367.         end
  368.     end
  369.     if(displayHelp == true) then
  370.         term.setBackgroundColor(colors.blue)
  371.         term.setTextColor(colors.red)
  372.         term.setCursorPos(1, 6)
  373.         print("L-click select cell (---); 9/0 set selection at selected cell; shift/enter transpose; Ctrl-x/ctrl-c/ctrl-v work; Letter key set note; - continue note; = stop note; Left-click module letter (MOD) - load, right-click save; Arrow keys scroll and move.")
  374.         term.setCursorPos(1, 1)
  375.     end
  376.    
  377.     term.setBackgroundColor(colors.black)
  378.     term.setTextColor(colors.white)
  379.     evt, aa, ab, ac = os.pullEvent()
  380.     if (playSong == true and evt == "timer" and aa == lastPlay) then
  381.         scrollAmt = colPlay
  382.         if (scrollAmt > 47) then scrollAmt = 47 end
  383.         selCol = colPlay
  384.         playCol(colPlay)
  385.         colPlay = colPlay + 1
  386.         if(colPlay == 65) then
  387.             modIndex = modIndex + 1
  388.             if(modIndex > modEnd) then modIndex = modStart end
  389.             loadModule(modIndex)
  390.             colPlay = 1
  391.         end
  392.         lastPlay = os.startTimer(4/tempo)
  393.     end
  394.     if(evt == "key" and aa == 41) then
  395.         peripheral.call(spka, "shutdown")
  396.         peripheral.call(spkb, "shutdown")
  397.         term.clear()
  398.         term.setCursorPos(1, 1)
  399.         term.setBackgroundColor(colors.black)
  400.         term.setTextColor(colors.white)
  401.         return
  402.     end
  403.     if (evt == "key" and displayHelp == false) then
  404.         if (aa == 29) then
  405.             ctrlFlag = not ctrlFlag
  406.         end
  407.         if ctrlFlag == true then
  408.             if(selStartX > 0 and selStartY > 0 and selEndX > 0 and selEndY > 0) then
  409.                 if (aa == 46) then --copy
  410.                     copyStartX = selStartX
  411.                     copyEndX = selEndX
  412.                     copyStartY = selStartY
  413.                     copyEndY = selEndY
  414.                     for i = copyStartY, copyEndY do
  415.                         copyBuffer[i] = {}
  416.                         for j = copyStartX, copyEndX do
  417.                             copyBuffer[i][j] = loadedModuleNote[i][j]
  418.                         end
  419.                     end
  420.                 elseif (aa == 45) then --cut
  421.                     copyStartX = selStartX
  422.                     copyEndX = selEndX
  423.                     copyStartY = selStartY
  424.                     copyEndY = selEndY
  425.                     for i = copyStartY, copyEndY do
  426.                         copyBuffer[i] = {}
  427.                         for j = copyStartX, copyEndX do
  428.                             copyBuffer[i][j] = loadedModuleNote[i][j]
  429.                             loadedModuleNote[i][j] = -1
  430.                         end
  431.                     end
  432.                 elseif (aa == 47) then --paste
  433.                     for i = copyStartY, copyEndY do
  434.                         for j = copyStartX, copyEndX do
  435.                             loadedModuleNote[i+setRow-1][j+setCol-1] = copyBuffer[i][j]
  436.                         end
  437.                     end
  438.                 end
  439.             end
  440.             if (aa == keys.a) then
  441.                 selStartX = 1
  442.                 selStartY = 1
  443.                 selEndX = 64
  444.                 selEndY = 8
  445.             elseif (aa == keys.b) then
  446.                 selStartX = 0
  447.                 selStartY = 0
  448.                 selEndX = 0
  449.                 selEndY = 0
  450.             end
  451.             if not (aa == 29) then
  452.                 ctrlFlag = false
  453.             end
  454.         else
  455.         if (aa == 211) then
  456.             for i = selStartX, selEndX do
  457.                 for j = selStartY, selEndY do
  458.                     loadedModuleNote[j][i] = -1
  459.                 end
  460.             end
  461.         elseif (aa == 8) then
  462.             tempo = tempo - 1
  463.             if(tempo < 1) then tempo = 1 end
  464.         elseif (aa == 9) then
  465.             tempo = tempo + 1
  466.             if(tempo > 400) then tempo = 400 end
  467.         elseif (aa == 54) then
  468.             for i = selStartX, selEndX do
  469.                 for j = selStartY, selEndY do
  470.                     if loadedModuleNote[j][i] > 0 then
  471.                         loadedModuleNote[j][i] = loadedModuleNote[j][i] - 1
  472.                     end
  473.                 end
  474.             end
  475.         elseif (aa == 28) then
  476.             for i = selStartX, selEndX do
  477.                 for j = selStartY, selEndY do
  478.                     if loadedModuleNote[j][i] > 0 and loadedModuleNote[j][i] < 144 then
  479.                         loadedModuleNote[j][i] = loadedModuleNote[j][i] + 1
  480.                     end
  481.                 end
  482.             end
  483.         elseif(aa == 10) then
  484.             selStartX = setCol;
  485.             selStartY = setRow;
  486.             if selStartX > selEndX then selStartX = selEndX end
  487.             if selStartY > selEndY then selStartY = selEndY end
  488.         elseif(aa == 11) then
  489.             selEndX = setCol;
  490.             selEndY = setRow;
  491.             if selEndX < selStartX then setEndX = selStartX end
  492.             if selEndY < selStartY then selEndY = selStartY end
  493.         elseif (aa == 2) then
  494.             modStart = modStart - 1
  495.             if(modStart < 1) then modStart = 1 end
  496.             modIndex = modStart
  497.         elseif (aa == 3) then
  498.             modStart = modStart + 1
  499.             if(modStart > modEnd) then modStart = modEnd end
  500.             modIndex = modStart
  501.         elseif (aa == 4) then
  502.             modEnd = modEnd - 1
  503.             if(modEnd < modStart) then modEnd = modStart end
  504.         elseif (aa == 5) then
  505.             modEnd = modEnd + 1
  506.             if(modEnd > 16) then modEnd = 16 end
  507.         elseif(aa == 205) then
  508.                 scrollAmt = scrollAmt + 1
  509.                 setCol = setCol + 1;
  510.                 if (setCol > 64) then setCol = 64 end
  511.                 if (scrollAmt > 47) then scrollAmt = 47 end
  512.                 term.clear()
  513.         elseif(aa == 203) then
  514.                 scrollAmt = scrollAmt - 1
  515.                 setCol = setCol - 1;
  516.                 if(setCol < 1) then setCol = 1 end
  517.                 if scrollAmt < 0 then scrollAmt = 0 end
  518.                 term.clear()
  519.         elseif(aa == 200) then
  520.             setRow = setRow - 1;
  521.             if(setRow < 1) then setRow = 1 end
  522.         elseif(aa == 208) then
  523.             setRow = setRow + 1;
  524.             if(setRow > 8) then setRow = 8 end
  525.         elseif aa == keys.q then
  526.             setNote(setRow, setCol, 0 + 12 * setOct)
  527.             playCol(setCol)
  528.         elseif aa == keys.w then
  529.             setNote(setRow, setCol, 1 + 12 * setOct)
  530.             playCol(setCol)
  531.         elseif aa == keys.e then
  532.             setNote(setRow, setCol, 2 + 12 * setOct)
  533.             playCol(setCol)
  534.         elseif aa == keys.r then   
  535.             setNote(setRow, setCol, 3 + 12 * setOct)
  536.             playCol(setCol)
  537.         elseif aa == keys.t then
  538.             setNote(setRow, setCol, 4 + 12 * setOct)
  539.             playCol(setCol)
  540.         elseif aa == keys.y then
  541.             setNote(setRow, setCol, 5 + 12 * setOct)
  542.             playCol(setCol)
  543.         elseif aa == keys.u then
  544.             setNote(setRow, setCol, 6 + 12 * setOct)
  545.             playCol(setCol)
  546.         elseif aa == keys.i then
  547.             setNote(setRow, setCol, 7 + 12 * setOct)
  548.             playCol(setCol)
  549.         elseif aa == keys.o then
  550.             setNote(setRow, setCol, 8 + 12 * setOct)
  551.             playCol(setCol)
  552.         elseif aa == keys.p then
  553.             setNote(setRow, setCol, 9 + 12 * setOct)
  554.             playCol(setCol)
  555.         elseif aa == 26 then
  556.             setNote(setRow, setCol, 10 + 12 * setOct)
  557.             playCol(setCol)
  558.         elseif aa == 27 then
  559.             setNote(setRow, setCol, 11 + 12 * setOct)
  560.             playCol(setCol)
  561.         elseif aa == keys.a then
  562.             setNote(setRow, setCol, 12 + 12 * setOct)
  563.             playCol(setCol)
  564.         elseif aa == keys.s then
  565.             setNote(setRow, setCol, 13 + 12 * setOct)
  566.             playCol(setCol)
  567.         elseif aa == keys.d then
  568.             setNote(setRow, setCol, 14 + 12 * setOct)
  569.             playCol(setCol)
  570.         elseif aa == keys.f then   
  571.             setNote(setRow, setCol, 15 + 12 * setOct)
  572.             playCol(setCol)
  573.         elseif aa == keys.g then
  574.             setNote(setRow, setCol, 16 + 12 * setOct)
  575.             playCol(setCol)
  576.         elseif aa == keys.h then
  577.             setNote(setRow, setCol, 17 + 12 * setOct)
  578.             playCol(setCol)
  579.         elseif aa == keys.j then
  580.             setNote(setRow, setCol, 18 + 12 * setOct)
  581.             playCol(setCol)
  582.         elseif aa == keys.k then
  583.             setNote(setRow, setCol, 19 + 12 * setOct)
  584.             playCol(setCol)
  585.         elseif aa == keys.l then
  586.             setNote(setRow, setCol, 20 + 12 * setOct)
  587.             playCol(setCol)
  588.         elseif aa == keys.semiColon then
  589.             setNote(setRow, setCol, 21 + 12 * setOct)
  590.             playCol(setCol)
  591.         elseif aa == keys.apostrophe then
  592.             setNote(setRow, setCol, 22 + 12 * setOct)
  593.             playCol(setCol)
  594.         elseif aa == 43 then
  595.             setNote(setRow, setCol, 23 + 12 * setOct)
  596.             playCol(setCol)
  597.         elseif aa == 44 then
  598.             setNote(setRow, setCol, 24 + 12 * setOct)
  599.             playCol(setCol)
  600.         elseif aa == 45 then
  601.             setNote(setRow, setCol, 25 + 12 * setOct)
  602.             playCol(setCol)
  603.         elseif aa == 46 then
  604.             setNote(setRow, setCol, 26 + 12 * setOct)
  605.             playCol(setCol)
  606.         elseif aa == 47 then
  607.             setNote(setRow, setCol, 27 + 12 * setOct)
  608.             playCol(setCol)
  609.         elseif aa == 48 then
  610.             setNote(setRow, setCol, 28 + 12 * setOct)
  611.             playCol(setCol)
  612.         elseif aa == 49 then
  613.             setNote(setRow, setCol, 29 + 12 * setOct)
  614.             playCol(setCol)
  615.         elseif aa == 50 then
  616.             setNote(setRow, setCol, 30 + 12 * setOct)
  617.             playCol(setCol)
  618.         elseif aa == 51 then
  619.             setNote(setRow, setCol, 31 + 12 * setOct)
  620.             playCol(setCol)
  621.         elseif aa == 52 then
  622.             setNote(setRow, setCol, 32 + 12 * setOct)
  623.             playCol(setCol)
  624.         elseif aa == 53 then
  625.             setNote(setRow, setCol, 33 + 12 * setOct)
  626.             playCol(setCol)
  627.         elseif aa == 12 then
  628.             setNote(setRow, setCol, -1)
  629.             playCol(setCol)
  630.         elseif aa == 13 then
  631.             setNote(setRow, setCol, -2)
  632.             playCol(setCol)
  633.         elseif aa == 6 then
  634.             setOct = setOct - 1
  635.             if(setOct < 1) then setOct = 1 end
  636.         elseif aa == 7 then
  637.             setOct = setOct + 1
  638.             if(setOct > 5) then setOct = 5 end
  639.         end
  640.         end
  641.     end
  642.     if(evt == "mouse_click") then
  643.         if(aa == 1) then
  644.             if(ac == 5 and ab > 39 and ab < 44) then
  645.                 term.clear()
  646.                 term.setCursorPos(1, 1)
  647.                 term.setBackgroundColor(colors.black)
  648.                 term.setTextColor(colors.white)
  649.                 return
  650.             end
  651.             if(ac == 3) then
  652.                 if(ab < 5) then
  653.                     loadModule(modIndex)
  654.                     playSong = not playSong
  655.                     stopCol()
  656.                     colPlay = 1
  657.                     lastPlay = os.startTimer(4/tempo)
  658.                 end
  659.             end
  660.             if(ac == 1 and ab < 5) then
  661.                 displayHelp = not displayHelp
  662.                 term.clear()
  663.             end
  664.             if(ac == 2) then
  665.                 if(ab > 0 and ab < 4) then
  666.                     stopCol()
  667.                     term.clear()
  668.                     term.setCursorPos(1, 1)
  669.                     term.setBackgroundColor(colors.black)
  670.                     term.setTextColor(colors.white)
  671.                     print("Enter a file name to save.")
  672.                     n = read()
  673.                     saveSong(n)
  674.                     term.clear()
  675.                 end
  676.                 if(ab > 4 and ab < 9) then
  677.                     stopCol()
  678.                     term.clear()
  679.                     term.setCursorPos(1, 1)
  680.                     term.setBackgroundColor(colors.black)
  681.                     term.setTextColor(colors.white)
  682.                     print("Enter a file name to load.")
  683.                     n = read()
  684.                     loadSong(n)
  685.                     term.clear()
  686.                 end
  687.             end
  688.             if(displayHelp == false) then
  689.                 if(ac == 6) then
  690.                     setRow = 1
  691.                     setCol = math.ceil(ab / 3) + scrollAmt
  692.                 elseif(ac == 7) then
  693.                     setRow = 2
  694.                     setCol = math.ceil(ab / 3) + scrollAmt
  695.                 elseif(ac == 8) then
  696.                     setRow = 3
  697.                     setCol = math.ceil(ab / 3) + scrollAmt
  698.                 elseif(ac == 9) then
  699.                     setRow = 4
  700.                     setCol = math.ceil(ab / 3) + scrollAmt
  701.                 elseif(ac == 10) then
  702.                     setRow = 5
  703.                     setCol = math.ceil(ab / 3) + scrollAmt
  704.                 elseif(ac == 11) then
  705.                     setRow = 6
  706.                     setCol = math.ceil(ab / 3) + scrollAmt
  707.                 elseif(ac == 12) then
  708.                     setRow = 7
  709.                     setCol = math.ceil(ab / 3) + scrollAmt
  710.                 elseif(ac == 13) then
  711.                     setRow = 8
  712.                     setCol = math.ceil(ab / 3) + scrollAmt
  713.                 end
  714.                 if(setCol > 64) then setCol = 64 end
  715.                 if(ac == 5 and ab > 6 and ab < 23) then
  716.                     loadModule(ab - 6)
  717.                 end
  718.             end
  719.         end
  720.         if(aa == 2) then
  721.             if(displayHelp == false) then
  722.                 if(ac == 6) then
  723.                     setRow = 1
  724.                     setCol = math.ceil(ab / 3) + scrollAmt
  725.                 elseif(ac == 7) then
  726.                     setRow = 2
  727.                     setCol = math.ceil(ab / 3) + scrollAmt
  728.                 elseif(ac == 8) then
  729.                     setRow = 3
  730.                     setCol = math.ceil(ab / 3) + scrollAmt
  731.                 elseif(ac == 9) then
  732.                     setRow = 4
  733.                     setCol = math.ceil(ab / 3) + scrollAmt
  734.                 elseif(ac == 10) then
  735.                     setRow = 5
  736.                     setCol = math.ceil(ab / 3) + scrollAmt
  737.                 elseif(ac == 11) then
  738.                     setRow = 6
  739.                     setCol = math.ceil(ab / 3) + scrollAmt
  740.                 elseif(ac == 12) then
  741.                     setRow = 7
  742.                     setCol = math.ceil(ab / 3) + scrollAmt
  743.                 elseif(ac == 13) then
  744.                     setRow = 8
  745.                     setCol = math.ceil(ab / 3) + scrollAmt
  746.                 end
  747.                 if(ac > 5 and ac < 14) then
  748.                     if(setCol > 64) then setCol = 64 end
  749.                     setNote(setRow, setCol, -1, 0)
  750.                     playCol(setCol)
  751.                 end
  752.                 if(ac == 5 and ab > 6 and ab < 23) then
  753.                     saveModule(ab - 6)
  754.                 end
  755.             end
  756.         end
  757.     end
  758. end
  759.  
  760. term.clear()
  761. term.setCursorPos(1, 1)
  762. term.setBackgroundColor(colors.black)
  763. term.setTextColor(colors.white)
Advertisement
Add Comment
Please, Sign In to add comment