Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- args = ...
- filesystem = require("filesystem")
- sheet = "60E 50E 40E 42E 43H 00Q 60E 50E 40E 42E 43H 00Q 63E 53E 40E 42E 30Q 00E 30S 40S 60E 50E 40E 42E 43E 32E 43E 42E"
- --sheet = sheet .. "60E 50E 40E 42E 43H 00Q" .. "60E 50E 40E 42E 43H 00Q" .. "63E 53E 43E 30E 32H 00Q" .. "50H 00Q 32E 21E 23E 32E 23E 10E 11Q 23Q"
- --sheet = sheet .. "53E 23E 21E 23E 10Q 00E 23S 10S" .. "11E 11E 10E 23E 10E 30E 21Q" .."32E 30E 32E 21E 32Q 00E 32S 21S"
- if args and filesystem.exists(args) then
- local f = io.open(args,'r')
- sheet = f.read("*a")
- f.close()
- end
- tuning = {'E4','B3','G3','D3','A2','D2'}
- tempo = 71
- Note = {}
- song = {}
- duration = {}
- duration.W = (60/tempo)*4
- duration.H = (60/tempo)*2
- duration.Q = (60/tempo)*1
- duration.E = (60/tempo)*.5
- duration.S = (60/tempo)*.25
- freq = {}
- freq['C2'] = 65.41
- freq['C#2'] = 69.30
- freq['D2'] = 73.42
- freq['D#2'] = 77.78
- freq['E2'] = 82.41
- freq['F2'] = 87.31
- freq['F#2'] = 92.50
- freq['G2'] = 98.00
- freq['G#2'] = 103.83
- freq['A2'] = 110.00
- freq['A#2'] = 116.54
- freq['B2'] = 123.47
- freq['C3'] = 130.81
- freq['C#3'] = 138.59
- freq['D3'] = 146.83
- freq['D#3'] = 155.56
- freq['E3'] = 164.81
- freq['F3'] = 174.61
- freq['F#3'] = 185.00
- freq['G3'] = 196.00
- freq['G#3'] = 207.65
- freq['A3'] = 220.00
- freq['A#3'] = 233.08
- freq['B3'] = 246.94
- freq['C4'] = 261.63
- freq['C#4'] = 277.18
- freq['D4'] = 293.66
- freq['D#4'] = 311.13
- freq['E4'] = 329.63
- freq['F4'] = 349.23
- freq['F#4'] = 369.99
- freq['G4'] = 392.00
- freq['G#4'] = 415.30
- freq['A4'] = 440.00
- freq['A#4'] = 466.16
- freq['B4'] = 493.88
- freq['C5'] = 523.25
- freq['C#5'] = 554.37
- freq['D5'] = 587.33
- freq['D#5'] = 622.25
- freq['E5'] = 659.25
- freq['F5'] = 698.46
- freq['F#5'] = 739.99
- freq['G5'] = 783.99
- freq['G#5'] = 830.61
- freq['A5'] = 880.00
- freq['A#5'] = 932.33
- freq['B5'] = 987.77
- freq['C6'] = 1046.50
- freq['C#6'] = 1108.73
- freq['D6'] = 1174.66
- freq['D#6'] = 1244.51
- freq['E6'] = 1318.51
- freq['F6'] = 1396.91
- freq['F#6'] = 1479.98
- freq['G6'] = 1567.98
- freq['G#6'] = 1661.22
- freq['A6'] = 1760.00
- freq['A#6'] = 1864.66
- freq['B6'] = 1975.53
- freq['C7'] = 2093.00
- Note.alphabet = {'C','C#','D','D#','E','F','F#','G','G#','A','A#','B'}
- function Note:new(ithStr,ithFret,fracNote)
- o = {}
- o.ithStr = tonumber(ithStr)
- o.ithFret = tonumber(ithFret)
- o.fracNote = fracNote
- o.string = ithStr..ithFret..fracNote
- setmetatable(o,self)
- self.__index = self
- return o
- end
- function Note:getNote()
- --requires access to tuning table
- local strNote = tuning[self.ithStr]
- strNote = self:halfStep(strNote,self.ithFret)
- return strNote
- end
- function Note:getFreq()
- return freq[self:getNote()]
- end
- function Note:halfStep(strNote,numReps)
- if numReps == 0 then
- return strNote
- end
- local letter = strNote:sub(1,#strNote-1)
- local octave = strNote:sub(#strNote)
- local key = table.getKey(self.alphabet,letter)
- local index = key + numReps
- local octave = octave + math.floor(index/#self.alphabet)
- return self.alphabet[index%#self.alphabet]..octave
- end
- function table:getKey(value)
- for k,v in pairs(self) do
- if value == v then
- return k
- end
- end
- end
- function main()
- local measure = 0
- local signature = "4/4"
- for word in string.gmatch(sheet,'%g+') do
- --if (word == "|") and (4-measure~=0) then
- --table.insert(song,Note:new(0,4-measure,'E'))
- --measure = 0
- --else
- table.insert(song,Note:new(word:sub(1,1),word:sub(2,2),word:sub(3,3)))
- --if word:sub(3,3) == "W" then
- -- measure = measure + 4
- --elseif word:sub(3,3) == "H" then
- -- measure = measure + 2
- --elseif word:sub(3,3) == "Q" then
- -- measure = measure + 1
- --elseif word:sub(3,3) == "E" then
- -- measure = measure + 0.5
- --elseif word:sub(3,3) == "S" then
- -- measure = measure + 0.25
- --end
- --end
- end
- for _,note in ipairs(song) do
- if note.ithStr == 0 then
- os.sleep(duration[note.fracNote])
- else
- print(note.string.." "..note:getNote().." "..note:getFreq())
- computer.beep(note:getFreq(),duration[note.fracNote])
- end
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement