Laine_prikol

Opencomputers Note Sequencer 0.3

Mar 7th, 2017
143
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local term = require("term")
  2. local computer = require("computer")
  3. local keyboard = require("keyboard")
  4. currentNote = 0
  5. note = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
  6. notesec = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
  7. i = 0
  8. i2 = 0
  9. term.clear()
  10. function redrawMenu()
  11. term.clear()
  12. print("+-Note Sequencer-----------------+")
  13. print("+ 1-2-3-4-5-6-7-8-9 Играть ноты  +")
  14. print("+ F1-F10 - Настройка нот         +")
  15. print("+ Ctrl - Играть  Shift - Random  +")
  16. print("+ X - Выход                      +")
  17. print("+--------------------------------+")
  18. print("Сечас играет нота: "..currentNote)
  19. end
  20.  
  21. function setNote(numNote,key)
  22.     if keyboard.isKeyDown(key) then
  23.         os.sleep(0.1)
  24.         print("Настройка ноты " .. numNote)
  25.         -- Чтение частоты
  26.         io.write("Частота: ")
  27.         note[numNote] = io.read("*number")
  28.         -- Чтение длительностей
  29.         io.write("Длительность (в секундах): ")
  30.         notesec[numNote] = io.read("*number")
  31.         redrawMenu()
  32.     end
  33. end
  34. function playNote(numNote,key)
  35.     if keyboard.isKeyDown(key) then
  36.         os.sleep(0.1)
  37.         computer.beep(note[numNote], notesec[numNote])
  38.     end
  39. end
  40.  
  41. redrawMenu()
  42. while true do
  43.     os.sleep(0.1)
  44.     setNote(1,0x3B)
  45.     setNote(2,0x3C)
  46.     setNote(3,0x3D)
  47.     setNote(4,0x3E)
  48.     setNote(5,0x3F)
  49.     setNote(6,0x40)
  50.     setNote(7,0x41)
  51.     setNote(8,0x42)
  52.     setNote(9,0x43)
  53.     setNote(10,0x44)
  54.     playNote(1,0x02)
  55.     playNote(2,0x03)
  56.     playNote(3,0x04)
  57.     playNote(4,0x05)
  58.     playNote(5,0x06)
  59.     playNote(6,0x07)
  60.     playNote(7,0x08)
  61.     playNote(8,0x09)
  62.     playNote(9,0x0A)
  63.     playNote(10,0x0B)
  64.     if keyboard.isKeyDown(0x2D) == true then -- Выход
  65.     os.sleep(0.1)
  66.     os.exit()
  67.     end
  68.     if keyboard.isShiftDown() == true then -- Рандом
  69.     computer.beep(1500, 0.5)
  70.     note = {math.random(100,2000), math.random(100,2000), math.random(100,2000), math.random(100,2000), math.random(100,2000), math.random(100,2000), math.random(100,2000), math.random(100,2000), math.random(100,2000), math.random(100,2000)}
  71.     notesec = {0.1, 0.2, 0.3, 0.1, 0, 0.4, 0.1, 0.2, 0.1, 0.3}
  72.     end
  73.     if keyboard.isControlDown() == true then -- Играть
  74.     io.write("Сколько раз повторять: ")
  75.     i2 = io.read("*number")
  76.     os.sleep(0.1)
  77.            for i = 1, i2 do
  78.             os.sleep(0)
  79.             computer.beep(note[1],notesec[1])
  80.             currentNote = currentNote + 1
  81.             redrawMenu()
  82.             computer.beep(note[2],notesec[2])
  83.             currentNote = currentNote + 1
  84.             redrawMenu()
  85.             computer.beep(note[3],notesec[3])
  86.             currentNote = currentNote + 1
  87.             redrawMenu()
  88.             computer.beep(note[4],notesec[4])
  89.             currentNote = currentNote + 1
  90.             redrawMenu()
  91.             computer.beep(note[5],notesec[5])
  92.             currentNote = currentNote + 1
  93.             redrawMenu()
  94.             computer.beep(note[6],notesec[6])
  95.             currentNote = currentNote + 1
  96.             redrawMenu()
  97.             computer.beep(note[7],notesec[7])
  98.             currentNote = currentNote + 1
  99.             redrawMenu()
  100.             computer.beep(note[8],notesec[8])
  101.             currentNote = currentNote + 1
  102.             redrawMenu()
  103.             computer.beep(note[9],notesec[9])
  104.             currentNote = currentNote + 1
  105.             redrawMenu()
  106.             computer.beep(note[10],notesec[10])
  107.             currentNote = currentNote + 1
  108.             currentNote = 0
  109.             redrawMenu()
  110. end
  111. end
  112. end
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×