Skip to content

Commit

Permalink
修piano小程序切换布局时没有停止所有声音
Browse files Browse the repository at this point in the history
调整快捷键功能,给alt和space键添加踏板功能
  • Loading branch information
MrZ626 committed Nov 21, 2024
1 parent e8f19d7 commit 6a3e2cf
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions assets/scene_app/piano.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ end

---@class Techmino.Piano.Object
---@field _type string
---@field _update fun(dt:number): any
---@field _update fun(self:Techmino.Piano.Object, dt:number): any
---@field _draw function

---@class Techmino.Piano.Layout
Expand Down Expand Up @@ -442,11 +442,11 @@ function scene.keyDown(key,isRep,keyCode)
if layout.keyMap[keyCode] then
if isRep then return end
local note=layout.keyMap[keyCode]+offset
if isKeyDown('lshift') then note=note+1 end
if isKeyDown('lctrl') then note=note-1 end
if isShiftDown() then note=note+1 end
if isCtrlDown() then note=note-1 end
_param.tune=note-26
_param.volume=1
_param.param[2]=release*1.0594630943592953^(_param.tune)
_param.volume=isKeyDown('lalt') and .26 or 1
_param.param[2]=(isKeyDown('space') and 4200 or release)*1.0594630943592953^(_param.tune)
activeEventMap[keyCode]=FMOD.effect(inst,_param)
elseif key=='f3' then
release=clamp(release-50,0,2600)
Expand All @@ -460,14 +460,23 @@ function scene.keyDown(key,isRep,keyCode)
if key=='tab' then
stopAllSounds()
inst=TABLE.next(instList,inst) or instList[1]
elseif key=='rshift' then
offset=clamp(offset+(isKeyDown('ralt') and 12 or isKeyDown('rctrl') and 0.5 or 1),-12,24)
elseif key=='rctrl' then
offset=clamp(offset-(isKeyDown('ralt') and 12 or isKeyDown('rshift') and 0.5 or 1),-12,24)
elseif key=='space' then
-- TODO
elseif key=='ralt' then
-- TODO
elseif key=='f1' then
stopAllSounds()
layout=layoutData[(TABLE.find(layoutData,layout)-2)%#layoutData+1]
elseif key=='f2' then
layout=layoutData[TABLE.find(layoutData,layout)%#layoutData+1]
elseif key=='right' then
offset=clamp(offset+(isKeyDown('left') and 0.5 or 1),-12,24)
elseif key=='left' then
offset=clamp(offset-(isKeyDown('right') and 0.5 or 1),-12,24)
elseif key=='up' then
offset=clamp(offset+12,-12,24)
elseif key=='down' then
offset=clamp(offset-12,-12,24)
elseif key=='escape' then
if sureCheck('back') then SCN.back() end
end
Expand Down

0 comments on commit 6a3e2cf

Please sign in to comment.