Alyssa

Keyboard

Aug 19th, 2013
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.80 KB | None | 0 0
  1. line = 1
  2. song = {...}
  3. run = true
  4. instr = 0
  5. notenum = 0
  6. notes = {}
  7. instrs = {}
  8. run = true
  9. waits = {}
  10. if song[1] == nil then
  11.  print("Please specify file to save to")
  12.  run = false
  13. end
  14. if run == true then
  15.  fileto = song[1]
  16.  print("Saving File at: " .. song[1] .. " ok? y or yes ")
  17.  ok = read()
  18.  if ok == "y" or ok == "yes" then
  19.   run = true
  20.  else
  21.   print("Chose to not save file at " .. song[1] .. "")
  22.   run = false
  23.  end
  24. end
  25. side = "bottom"
  26. inb = peripheral.wrap(side)
  27.  
  28. function savefile()
  29.  i = 0
  30.  file = fs.open(fileto, "w")
  31.  for i = 1, notenum do
  32.   if notes[i] then
  33.   sleep(0.05)
  34.   file.write(instrs[i] .. "\n" )
  35.   file.write(notes[i] .. "\n" )
  36.   file.write(waits[i] .. "\n" )
  37.   end
  38.  end
  39.  file.close()
  40.  print("saved song!")
  41. end
  42.  
  43. function noteup()
  44.  if instr ~= 4 then
  45.   instr = instr +1
  46.  else
  47.   instr = 0
  48.  end
  49. end
  50.  
  51. function notedown()
  52.  if instr ~= 0 then
  53.   instr = instr -1
  54.  else
  55.   instr = 4
  56.  end
  57. end
  58. while run == true do
  59.  term.clear()
  60.  term.setCursorPos(1,1)
  61.  print("Instrument: " .. instr .. " ")
  62.  if notes[notenumm] then
  63.   print("Last note: " .. notes[notenumm] .. " ")
  64.  end
  65.  time1 = os.clock()
  66.  event, num = os.pullEvent("key")
  67.  if num == 200 or num == 17 then
  68.   noteup()
  69.  end
  70.  if num == 208 or num == 31 then
  71.   notedown()
  72.  end
  73.  if num == 2 or num == 3 or num == 4 or num == 5 or num == 6 or num == 7 or num == 8 or num == 9 or num == 10 or num == 11 then
  74.   time2 = os.clock()
  75.   time = time2 - time1
  76.   note = num -1
  77.   note = note *2
  78.   note = note +4
  79.   notes[notenum] = note
  80.   notenumm = notenum
  81.   instrs[notenum] = instr
  82.   waits[notenum] = time
  83.   inb.playNote(instr,note)
  84.   notenum = notenum +1
  85.   line = line +3
  86.  elseif num ~= 208 and num ~= 31 and num ~= 200 and num ~=17 then
  87.   run = false
  88.   quit = true
  89.  end
  90. end
  91. if quit == true then
  92.  savefile()
  93. end
Advertisement
Add Comment
Please, Sign In to add comment