Posted: Wed May 27, 2020 8:03 pm Post subject: Synchronize Keypress
This is a sample of my project for a kindergarten that learns the basic musical note's purpose.
I am using an old 'Jurassic era' function from kernel32, it's a 'beep' function and uses it for a simple sound pad.
local cl = 15
local i
for i=1,8 do
local keyname= 'panel0'..i
local keyPanel=createPanel(frm)
_G[keyname]=keyPanel
keyPanel.Left = cl
keyPanel.Top = 10
keyPanel.Width = 30
keyPanel.Height = 120
keyPanel.Color = 0xffffff
cl = cl+35
end
function sBeep(freq, dur)
return executeCodeLocalEx('kernel32.Beep', freq, dur)
end
duration = 100
function keypressDown(sender, Key)
frm.setFocus()
if (Key == VK_Z) then
panel01.Color = 52582
sBeep(261, duration)
elseif (Key == VK_X) then
panel02.Color = 52582
sBeep(293, duration)
elseif (Key == VK_C) then
panel03.Color = 52582
sBeep(329, duration)
elseif (Key == VK_V) then
panel04.Color = 52582
sBeep(349, duration)
elseif (Key == VK_B) then
panel05.Color = 52582
sBeep(391, duration)
elseif (Key == VK_N) then
sBeep(440, duration)
panel06.Color = 52582
elseif (Key == VK_M) then
sBeep(493, duration)
panel07.Color = 52582
elseif (Key == VK_A) then
sBeep(523, duration)
panel08.Color = 52852
end
end
frm.OnKeyDown = keypressDown
function keypressUp(sender, Key)
frm.setFocus()
if (Key == VK_Z) then
panel01.Color = 0xffffff
elseif (Key == VK_X) then
panel02.Color = 0xffffff
elseif (Key == VK_C) then
panel03.Color = 0xffffff
elseif (Key == VK_V) then
panel04.Color = 0xffffff
elseif (Key == VK_B) then
panel05.Color = 0xffffff
elseif (Key == VK_N) then
panel06.Color = 0xffffff
elseif (Key == VK_M) then
panel07.Color = 0xffffff
elseif (Key == VK_A) then
panel08.Color = 0xffffff
end
end
frm.OnKeyUp = keypressUp
frm.Show()
Problem:
If the 'duration' higher than 100 (say 200), the pads color change when key pressed (down/up) has delayed as per milliseconds. Mean not Synchronize between output sounds, key down/key up and the panel color change.
Any solutions to fix it?. Use timer?.
Honestly, I avoid using timers because using timers not with the right precision will cause memory leaks. _________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Man, you should probably change the "beep" sound.
I think "beep" is not suitable for getting the right sound.
Otherwise, very fine calculations need to be made.
This may require a music teacher.
The number values you use in the chart below are available.
And I still think the "beep" sound is not suitable for toning.
EDIT ;
Code:
duration = 600
local clrTimer=createTimer() clrTimer.Interval=duration-100 clrTimer.Enabled=false
function Z() panel01.Color = 0x00ff00 sBeep(261, duration) clrTimer.Enabled=true end
function X() panel02.Color = 0x00ff00 sBeep(393, duration) clrTimer.Enabled=true end
function C() panel03.Color = 0x00ff00 sBeep(429, duration) clrTimer.Enabled=true end
function V() panel04.Color = 0x00ff00 sBeep(549, duration) clrTimer.Enabled=true end
function B() panel05.Color = 0x00ff00 sBeep(691, duration) clrTimer.Enabled=true end
function N() panel06.Color = 0x00ff00 sBeep(740, duration) clrTimer.Enabled=true end
function M() panel07.Color = 0x00ff00 sBeep(893, duration) clrTimer.Enabled=true end
function A() panel08.Color = 0x00ff00 sBeep(923, duration) clrTimer.Enabled=true end
Aylin: Man, you should probably change the "beep" sound.
Don't worry about the beep sound. I can change the beep sound to whatever sound wanted, for example, turn to real piano sound, stell drum bass sound, animal sound, etc. That is not a real important point.
For now, my goal is finding and providing the OOP logical programming for the events handler, such as clicking, key pressing, auto-playing, etc.
However, thank you for the sample script. _________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
I didn't think it could change with other sounds.
But the "beep" sound can play music in its current form.
It just doesn't sound like it sounds.
You are on good work again, congratulations.
I didn't think it could change with other sounds.
But the "beep" sound can play music in its current form.
It just doesn't sound like it sounds.
You are on good work again, congratulations.
local cl = 15
local i
for i=1,8 do
local keyname= 'panel0'..i
local keyPanel=createPanel(frm)
_G[keyname]=keyPanel
keyPanel.Left = cl
keyPanel.Top = 10
keyPanel.Width = 30
keyPanel.Height = 120
keyPanel.Color = 0xffffff
cl = cl+35
end
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum