pepeknamornik

Sound api

Jul 4th, 2020 (edited)
1,147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.99 KB | None | 0 0
  1. verze = "20.1223.R3"
  2. local speaker = nil
  3. local tArgs = { ... }
  4. local n = {}
  5. local s = {}
  6. local nastroj = {}
  7. local ton = 0
  8.  
  9. nastroje = {
  10.   [1] = "harp",
  11.   [2] = "bass",
  12.   [3] = "basedrum",
  13.   [4] = "bell",
  14.   [5] = "chime",
  15.   [6] = "flute",
  16.   [7] = "hat",
  17.   [8] = "snare",
  18.   [9] = "xylophone",
  19. }
  20.  
  21. local function load(name)
  22.     local file = fs.open(name,"r")
  23.     local data = file.readAll()
  24.     file.close()
  25.     return textutils.unserialize(data)
  26. end
  27.  
  28. if fs.exists("/C/system/RAM/devices/speaker.tmp") then
  29.     speakers = {}
  30.     speakers = load("/C/system/RAM/devices/speaker.tmp")
  31.     speaker = peripheral.wrap(tostring(speakers[0]))
  32.     if speaker == nil then speaker = peripheral.wrap(tostring(speakers[1])) end
  33. else
  34.     speaker = peripheral.find("speaker")
  35. end
  36.  
  37.     function p(note,s,nas,tonina)
  38.     if  tonina > 0 then nas = tonina end
  39.     if (nas == nil) then nas = 1 end
  40.    
  41.        
  42.         speaker.playNote(nastroje[nas],1,note)
  43.         sleep(0.15*s)
  44.     end
  45.  
  46.     function sound(type)
  47.  
  48.         if type == "startup" then n = {2,21,2,9,2,16,14,21,4,16} s = {0.5,1.2,1,1,0.5,1,1,2,0.5,1} nastroj ={2,1,2,1,2,1,1,1,2,1}
  49.         elseif type == "shutdown" then n = {14,9,2,4,4} s = {1,1,1,0.5,2}  nastroj ={1,1,1,2,1}
  50.         elseif type == "logout" then n = {16, 9, 9} s = {1,0.5,2} nastroj ={1,2,1}
  51.         elseif type == "login" then n = {9, 9,16} s = {1,0.5,2} nastroj ={1,2,1}
  52.         elseif type == "error" then n = {14,9,21} s = {0,0,0}
  53.         elseif type == "stop" then n = {1,6,13} s = {0,0,2} ton = 2
  54.         elseif type == "info" then n = {14,14,9,21} s = {0.3,0.1,0.1,0.1} ton = 6
  55.         elseif type == "hwout" then n = {16, 9} s = {1,0.3} ton = 2
  56.         elseif type == "hwin" then n = {9, 16} s = {1,0.3} ton = 2
  57.         elseif type == "trash" then n = {21,1,4} s = {1,0.5,1} ton = 8
  58.         elseif type == "folder" then n = {21} s = {1} ton = 8
  59.         elseif type == "print" then n = {9,4,16} s = {1,1,1} ton = 6
  60.         else n = {} s = {}
  61.         end
  62.  
  63.         for i=1, #n do
  64.         p(n[i],s[i], nastroj[i], ton)
  65.         end
  66.        
  67.         ton = 0
  68.         nastroj ={}
  69.        
  70.     end
  71.  
  72. if #tArgs > 0 then
  73.     sound(tArgs[1])
  74. end
Add Comment
Please, Sign In to add comment