Here's a fully functional piano I created while testing things with playSoundFile() It's built with the Geyser framework.
![Exclamation :!:](./images/smilies/icon_exclaim.gif)
It works on Mudlet 2.1
Simply click a key to play it's note. The package includes the .wav files for each sound. You can change these if you want your piano to sound different.
Here's the script without the .wav files for your dissecting tendencies (this won't work if you simply copy/paste the script. You need those .wav files in the package!)
piano = {}
piano.container = Geyser.Container:new({
name = "piano.container",
x = 0, y = 0,
width = 350,
height = 200,
})
piano.white_keys = Geyser.HBox:new({
name = "piano.white_keys",
x = 0, y = 0, width = "100%", height = "100%",
},piano.container)
local keys = {"G#","A#","C","C#","D#","F","G"}
for k,v in pairs(keys) do
piano[v] = Geyser.Label:new({
name = "piano."..v,
},piano.white_keys)
piano[v]:setStyleSheet([[
background-color: white;
border-color: black;
border-width: 2px;
border-style: solid;
qproperty-alignment: AlignBottom;
]])
piano[v]:echo([[<center><span style="color:black"><span style="font-size: 16pt">]]..v)
piano[v]:setClickCallback( "piano.press_key", v )
end
local w = piano.container:get_width()
local x = w/7
local width = -x + w
piano.black_keys = Geyser.HBox:new({
name = "piano.black_keys",
x = "5%", y = 0, width = width , height = "70%",
},piano.container)
local keys = {"A","B","blank","D","E","F#"}
for k,v in pairs(keys) do
piano[v] = Geyser.Label:new({
name = "piano."..v,
},piano.black_keys)
piano[v]:setStyleSheet([[
background-color: black;
border-color: grey;
border-width: 2px;
border-style: solid;
qproperty-alignment: AlignBottom;
margin: 0px 5px 0px 5px;
]])
piano[v]:echo([[<center><span style="color:black"><span style="font-size: 16pt">]]..v)
piano[v]:setClickCallback( "piano.press_key", v )
if v == "blank" then
piano[v]:setStyleSheet([[
background-color: transparent;
]])
piano[v]:echo("")
end
end
function piano.press_key( note )
playSoundFile( getMudletHomeDir():gsub("\\","/") .. "/".. note .. ".wav")
end
- Piano.zip
- Install using the Package Manager!
- (2.82 MiB) Downloaded 856 times