From 49b6f998b636b5ff931fce70219d3bf1be1c89c8 Mon Sep 17 00:00:00 2001 From: MrZ_26 <1046101471@qq.com> Date: Fri, 22 Nov 2024 00:01:18 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=80=E5=8C=96piano=E5=B0=8F=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F=E8=BD=AC=E8=B0=83=E5=BF=AB=E6=8D=B7=E9=94=AE=E7=94=A8?= =?UTF-8?q?=E6=B3=95=EF=BC=8C=E5=87=8F=E5=B0=91=E8=AF=AF=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=E7=9A=84=E5=8F=AF=E8=83=BD=E6=80=A7=EF=BC=8C=E5=85=81=E8=AE=B8?= =?UTF-8?q?0.5=E7=9A=84=E8=B0=83=E6=95=B4=20=E5=88=87=E5=B8=83=E5=B1=80?= =?UTF-8?q?=E6=97=B6=E4=B9=9F=E4=BC=9A=E6=B8=85=E7=A9=BA=E6=89=80=E6=9C=89?= =?UTF-8?q?=E7=89=A9=E4=BB=B6=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/scene_app/piano.lua | 61 +++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 34 deletions(-) diff --git a/assets/scene_app/piano.lua b/assets/scene_app/piano.lua index 6934f5a4..d7fd3cb3 100644 --- a/assets/scene_app/piano.lua +++ b/assets/scene_app/piano.lua @@ -411,10 +411,13 @@ local layout=layoutList[1] ---@type Zenitha.Scene local scene={} -function scene.load() +local function stopAllSounds() for _,effect in next,activeEventMap do effect:stop(FMOD.FMOD_STUDIO_STOP_ALLOWFADEOUT) end TABLE.clearAll(activeEventMap) TABLE.clearAll(objPool) +end +function scene.load() + stopAllSounds() stopBgm() inst='square_wave' offset=0 @@ -434,48 +437,38 @@ local _param={ param={'release',1}, } function scene.keyDown(key,isRep,keyCode) - if not isRep and layout.keyMap[keyCode] then + if layout.keyMap[keyCode] then + if isRep then return end local note=layout.keyMap[keyCode]+offset - if isShiftDown() then note=note+1 end - if isCtrlDown() then note=note-1 end + if isKeyDown('lshift') then note=note+1 end + if isKeyDown('lctrl') then note=note-1 end _param.tune=note-26 _param.volume=1 _param.param[2]=release*1.0594630943592953^(note-26) activeEventMap[keyCode]=FMOD.effect(inst,_param) - elseif key=='tab' then - inst=TABLE.next(instList,inst) or instList[1] - elseif key=='lalt' then - local d=0 - if isShiftDown() then d=d+12 end - if isCtrlDown() then d=d-12 end - if d==0 then - offset=MATH.clamp(offset-1,-12,24) - else - offset=MATH.clamp(offset+d,-12,24) - end - elseif key=='ralt' then - local d=0 - if isShiftDown() then d=d+12 end - if isCtrlDown() then d=d-12 end - if d==0 then - offset=MATH.clamp(offset+1,-12,24) - else - offset=MATH.clamp(offset+d,-12,24) - end - elseif key=='f1' then - layout=layoutList[(TABLE.find(layoutList,layout)-2)%#layoutList+1] - elseif key=='f2' then - layout=layoutList[TABLE.find(layoutList,layout)%#layoutList+1] elseif key=='f3' then - release=math.max(release-100,0) + release=MATH.clamp(release-50,0,2600) elseif key=='f4' then - release=math.min(release+100,2600) + release=MATH.clamp(release+50,0,2600) elseif key=='f5' then - presets.rollNote.setSpeed(presets.rollNote.getSpeed()-100) + presets.rollNote.setSpeed(MATH.clamp(presets.rollNote.getSpeed()/1.2,100,1000)) elseif key=='f6' then - presets.rollNote.setSpeed(presets.rollNote.getSpeed()+100) - elseif key=='escape' then - if sureCheck('back') then SCN.back() end + presets.rollNote.setSpeed(MATH.clamp(presets.rollNote.getSpeed()*1.2,100,1000)) + elseif not isRep then + if key=='tab' then + stopAllSounds() + inst=TABLE.next(instList,inst) or instList[1] + elseif key=='rshift' then + offset=MATH.clamp(offset+(isKeyDown('ralt') and 12 or isKeyDown('rctrl') and 0.5 or 1),-12,24) + elseif key=='rctrl' then + offset=MATH.clamp(offset-(isKeyDown('ralt') and 12 or isKeyDown('rshift') and 0.5 or 1),-12,24) + elseif key=='f1' then + layout=layoutList[(TABLE.find(layoutList,layout)-2)%#layoutList+1] + elseif key=='f2' then + layout=layoutList[TABLE.find(layoutList,layout)%#layoutList+1] + elseif key=='escape' then + if sureCheck('back') then SCN.back() end + end end return true end