diff --git a/src/main/resources/assets/opencomputers/lua/component/internet/bin/wget.lua b/src/main/resources/assets/opencomputers/lua/component/internet/bin/wget.lua index 36122de81..257d49916 100644 --- a/src/main/resources/assets/opencomputers/lua/component/internet/bin/wget.lua +++ b/src/main/resources/assets/opencomputers/lua/component/internet/bin/wget.lua @@ -14,7 +14,7 @@ local args, options = shell.parse(...) if #args < 1 then io.write("Usage: wget [-fq] url \n") io.write(" -f: Force overwriting existing files.\n") - io.write(" -q: Quit mode - no status messages.") + io.write(" -q: Quiet mode - no status messages.") return end @@ -74,4 +74,4 @@ else f:close() fs.remove(filename) io.stderr:write("HTTP request failed: " .. response .. "\n") -end \ No newline at end of file +end diff --git a/src/main/resources/assets/opencomputers/lua/rom/bin/label.lua b/src/main/resources/assets/opencomputers/lua/rom/bin/label.lua index f9a231529..be0eaace4 100644 --- a/src/main/resources/assets/opencomputers/lua/rom/bin/label.lua +++ b/src/main/resources/assets/opencomputers/lua/rom/bin/label.lua @@ -12,7 +12,7 @@ local proxy, reason if options.a then proxy, reason = fs.proxy(args[1]) else - proxy, reaons = fs.get(args[1]) + proxy, reason = fs.get(args[1]) end if not proxy then io.stderr:write(reason) @@ -26,4 +26,4 @@ else if not result then io.stderr:write(reason or "could not set label") end -end \ No newline at end of file +end diff --git a/src/main/resources/assets/opencomputers/lua/rom/lib/note.lua b/src/main/resources/assets/opencomputers/lua/rom/lib/note.lua new file mode 100644 index 000000000..67b7c8704 --- /dev/null +++ b/src/main/resources/assets/opencomputers/lua/rom/lib/note.lua @@ -0,0 +1,126 @@ +--Provides all music notes in range of computer.beep in MIDI and frequency form +--Author: Vexatos +local computer = require("computer") + +local note = {} +--The table that maps note names to their respective MIDI codes +local notes = {} +--The reversed table "notes" +local reverseNotes = {} + +do + --All the base notes + local tempNotes = { + "c", + "c#", + "d", + "d#", + "e", + "f", + "f#", + "g", + "g#", + "a", + "a#", + "b" + } + --The table containing all the standard notes and # semitones in correct order, temporarily + local sNotes = {} + --The table containing all the b semitones + local bNotes = {} + + --Registers all possible notes in order + do + table.insert(sNotes,"a0") + table.insert(sNotes,"a#0") + table.insert(bNotes,"bb0") + table.insert(sNotes,"b0") + for i = 1,6 do + for _,v in ipairs(tempNotes) do + table.insert(sNotes,v..tostring(i)) + if #v == 1 and v ~= "c" and v ~= "f" then + table.insert(bNotes,v.."b"..tostring(i)) + end + end + end + end + for i=21,95 do + notes[sNotes[i-20]]=tostring(i) + end + + --Reversing the whole table in reverseNotes, used for note.get + do + for k,v in pairs(notes) do + reverseNotes[tonumber(v)]=k + end + end + + --This is registered after reverseNotes to avoid conflicts + for k,v in ipairs(bNotes) do + notes[v]=tostring(notes[string.gsub(v,"(.)b(.)","%1%2")]-1) + end +end + +--Converts string or frequency into MIDI code +function note.midi(n) + if type(n) == "string" then + n = string.lower(n) + if tonumber(notes[n])~=nil then + return tonumber(notes[n]) + else + error("Wrong input "..tostring(n).." given to note.midi, needs to be [semitone sign], e.g. A#0 or Gb4") + end + elseif type(n) == "number" then + return math.floor((12*math.log(n/440,2))+69) + else + error("Wrong input "..tostring(n).." given to note.midi, needs to be a number or a string") + end +end + +--Converts String or MIDI code into frequency +function note.freq(n) + if type(n) == "string" then + n = string.lower(n) + if tonumber(notes[n])~=nil then + return math.pow(2,(tonumber(notes[n])-69)/12)*440 + else + error("Wrong input "..tostring(n).." given to note.freq, needs to be [semitone sign], e.g. A#0 or Gb4",2) + end + elseif type(n) == "number" then + return math.pow(2,(n-69)/12)*440 + else + error("Wrong input "..tostring(n).." given to note.freq, needs to be a number or a string",2) + end +end + +--Converts a MIDI value back into a string +function note.name(n) + n = tonumber(n) + if reverseNotes[n] then + return string.upper(string.match(reverseNotes[n],"^(.)"))..string.gsub(reverseNotes[n],"^.(.*)","%1") + else + error("Attempt to get a note for a non-exsisting MIDI code",2) + end +end + +--Converts Note block ticks (0-24) to MIDI code (34-58) and vice-versa +function note.ticks(n) + if type(n) == "number" then + if n>=0 and n<=24 then + return n+34 + elseif n>=34 and n<=58 then + return n-34 + else + error("Wrong input "..tostring(n).." given to note.ticks, needs to be a number [0-24 or 34-58]",2) + end + else + error("Wrong input "..tostring(n).." given to note.ticks, needs to be a number",2) + end +end + +--Plays a tone, input is either the note as a string or the MIDI code as well as the duration of the tone +function note.play(tone,duration) + computer.beep(note.freq(tone),duration) +end + +return note