mirror of
https://github.com/S4mpsa/InfOS.git
synced 2025-09-08 06:38:57 -04:00
Improving play-tune
Improving readability and possibly performance Using the notes api
This commit is contained in:
parent
e194231476
commit
c9fc3a1456
@ -1,56 +1,13 @@
|
||||
-- Import section
|
||||
Computer = require("computer")
|
||||
local note = require("note")
|
||||
--
|
||||
|
||||
local notes = {
|
||||
["G#3"] = 207.6523,
|
||||
["A3"] = 220.0000,
|
||||
["A#3"] = 233.0819,
|
||||
["B3"] = 246.9417,
|
||||
["C4"] = 261.6256,
|
||||
["C#4"] = 277.1826,
|
||||
["D4"] = 293.6648,
|
||||
["D#4"] = 311.1270,
|
||||
["E4"] = 329.6276,
|
||||
["F4"] = 349.2282,
|
||||
["F#4"] = 369.9944,
|
||||
["G4"] = 391.9954,
|
||||
["G#4"] = 415.3047,
|
||||
["A4"] = 440.0000,
|
||||
["A#4"] = 466.1638,
|
||||
["B4"] = 493.8833,
|
||||
["C5"] = 523.2511,
|
||||
["C#5"] = 554.3653,
|
||||
["D5"] = 587.3295,
|
||||
["D#5"] = 622.2540,
|
||||
["E5"] = 659.2551,
|
||||
["F5"] = 698.4565,
|
||||
["F#5"] = 739.9888,
|
||||
["G5"] = 783.9909,
|
||||
["G#5"] = 830.6094,
|
||||
["A5"] = 880.000,
|
||||
["A#5"] = 932.3275,
|
||||
["B5"] = 987.7666,
|
||||
["C6"] = 1046.502,
|
||||
["C#6"] = 1108.731,
|
||||
["D6"] = 1174.659,
|
||||
["D#6"] = 1244.508,
|
||||
["E6"] = 1318.510,
|
||||
["F6"] = 1396.913,
|
||||
["F#6"] = 1479.978,
|
||||
["G6"] = 1567.982,
|
||||
["E5"] = 659.2551,
|
||||
["G#6"] = 1661.219,
|
||||
["A6"] = 1760.000,
|
||||
["A#6"] = 1864.655,
|
||||
["B6"] = 1975.533
|
||||
}
|
||||
|
||||
local function playTune(tune)
|
||||
return function()
|
||||
for i, note in ipairs(tune) do
|
||||
Computer.beep(notes[note.pitch or note], note.duration or 0.1)
|
||||
os.sleep(note.wait or 0.01)
|
||||
for i, tone in ipairs(tune) do
|
||||
note.play(tone.pitch or tone, tone.duration or 0.1)
|
||||
os.sleep(tone.wait or 0.01)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user