FeynmanTech

Audio Library

Sep 21st, 2013
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.30 KB | None | 0 0
  1. require'audio'
  2.  
  3. m = m or {}
  4.  
  5. m.delay = function(n)
  6.     local ct = os.clock()
  7.     while os.clock() <= ct + n do end
  8.     return true
  9. end
  10.  
  11. m.play = function()
  12.     io.write('\a-')
  13. end
  14.  
  15. m.metronome = function(s)
  16.     s = 60 / s
  17.     while true do
  18.         m.play()
  19.         m.delay(s)
  20.     end
  21. end
  22.  
  23. local w = function(...)
  24.     f:write(..., '\n')
  25. end
  26.  
  27. m.new = function(file, r, tempo)
  28.     r = tostring(r)
  29.     tempo = tempo or 60
  30.     file = file .. '.rtm'
  31.     local f = io.open(file, 'w')
  32.     f:write('require\'music\'\n')
  33.     f:write('local rstr = \'' .. r .. '\'\n')
  34.     f:write('local tempo = ' .. tempo .. '\n')
  35.     f:write([[local play = function()
  36.         for k = 1, #rstr do
  37.             if rstr.sub(rstr, k, k) == '1' then
  38.                 play(12, 60 / tempo)
  39.                 io.write('-')
  40.             else
  41.                 io.write('_')
  42.                 m.delay(60 / tempo)
  43.             end
  44.         end
  45.     end]])
  46.     f:write('\nplay()')
  47.     f:close()
  48. end
  49.  
  50. m.anew = function(file, r, tempo)
  51.     r = string.lower(tostring(r))
  52.     tempo = tempo or 60
  53.     file = file .. '.artm'
  54.     local f = io.open(file, 'w')
  55.     f:write('require\'music\'\n')
  56.     f:write('local rstr = \'' .. r .. '\'\n')
  57.     f:write('local tempo = ' .. tempo .. '\n')
  58.     f:write([[local play = function()
  59.         for k = 1, #rstr do
  60.             if rstr.sub(rstr, k, k) == 'r' then
  61.                 play(12, 60 / tempo)
  62.             else
  63.                 play(0, 60 / tempo)
  64.             end
  65.         end
  66.     end]])
  67.     f:write('\nplay()')
  68.     f:close()
  69. end
Advertisement
Add Comment
Please, Sign In to add comment