Computer keyboard into piano keyboard with AutoHotkey - keyboard

I want to be able to use my computer keyboard as a piano keyboard, however the default version of AutoHotkey only supports one "voice" at a time. I tried running an instance for each note, but that doesn't fix it if I press the same note repeatedly.
I found this thread on how this might be solved with the BASS library, but I'm pretty green when it comes to coding and so I'm not certain how to incorporate the library into my simple code.
Here's another similar forum that might solve things, but it has a delay and the overlapping solution doesn't really solve my issue.
This is such a simple idea (play sound when a button is pressed), but somehow it's way out of my depth. Currently my code looks like this:
~1::
SoundPlay, C:\Users\Fires\Downloads\2489__jobro__piano-ff\39187__jobro__piano-ff-040.wav
for each note
Edit:
~a::
FileDelete, %A_ScriptDIR%\Sound1.AHK
FileAppend,
(
SoundPlay, C:\Users\Fires\Desktop\New folder (4)\043.wav, Wait
), %A_ScriptDir%\Sound1.AHK
Run, %A_ScriptDIR%\Sound1.AHK
Return
is what I am using now, but it's still iffy when two are pressed at the same time.

Its likely due to the "Wait". according to the documentation:
https://autohotkey.com/docs/commands/SoundPlay.htm
"If a file is playing and the current script plays a second file, the first file will be stopped so that the second one can play. On some systems, certain file types might stop playing even when an entirely separate script plays a new file."
It looks like this is an "issue" with AutoHotKey. And its not possible to open multiple "voices" or simultaneous sounds. it is completely possible to make a C# program that does the same thing, I've done it before. and i have bits of the code now still (it plays midi sounds, instead of wavs, but same concept play notes asynchronously).

Related

Where can I find documentation for the preview() and show() function for VideoClips?

I just want to see how exactly they work, and I can't seem to find them in either moviepy or pygame's websites. Basically I just want to see at what time a user presses a specific key during a clip, and record that time/possibly insert an image at that time while the movie is playing. I know moviepy does that already to some extent, but it's only for mouse clicks.
Thank you for your time.
I found the source code but no answer. I ended up editing the source code, and while that works, I would much rather do something else than that if possible.
To have a more elaborate answer to the rest of my question, basically it's not something I think is feasible to directly edit the video file WHILE it's playing. I also don't know if it would be a good idea to save every single and just combine them. I was able to find an extremely efficient, but niche solution by modifying the preview frame while it plays, and having that persist across every new frame. Then I saved JUST the overlay to a file, and can use that however else I feel.
I have seen no other threads/users actually deal with moviepy in this way, so feel free to PM me or ask on the thread if you want more info.
Source code here

Open a new window for a milisecond in python(3x)

I'm making a small game where you have to guess if the answer is cp1 or cp2 and I want to give the user some sort of hint. One way of doing that I think is by flashing the answer for a nano or milisecond to user, i.e. a new window would open with a : . Any ideas as to how to do this?
[...] flashing the answer for a nano or millisecond to user [....] in a new window [...]
A millisecond is too short (both for the human player -read about the persistence of vision- and for the Python interpreter); your screen is probably refreshed at 60Hz. Consider flashing for at least one tenth of a second (and probably more than that, you'll need to experiment, and you might make the flashing delay or period configurable). How to do that depends upon the widget toolkit you are using.
If using something above GTK, you'll need to find the Python binding to g_timeout_add, see also this.
If you use something above libSDL (e.g. pygame_sdl2), you need something related to its timers.
There are many other widgets or graphical frameworks usable from Python, and you need to choose one (look also into PyQt). Each of them has its own way to deal with timing, delays, windows, graphical display of text inside a window, etc...
If your system is Linux, see also time(7) for a general overview of time related things. Event loops (like those in graphics libraries) are built above a multiplexing system call such as poll(2) (or the old select, etc...).
You need to spend several days in reading more, choosing your graphical toolkit, before coding a single line of code of your game (which might need more code than what you imagine now).
I think the closest you can easily get to this affect is to just print to the console, but don't print the new-line (\n), just the carriage return (\r). This way you can write over the text after a couple of milliseconds. We do need to know the length of the thing we are printing so that we can be sure to completely override it with the next print.
The code for this would look something like:
import time
ms = 100
s = 'cp1'
print(s, end='\r')
time.sleep(ms / 1000)
print(' ' * len(s))

simple keyboard event handler in D

I am trying to make a simple keypress handler that I can recycle into any program I'd like to make in D. In my search I can only really find information on how to do this in C, namely by using getch() to read characters from the command line input buffer. But I don't neccessarily want to run a program on the command line. Much like every other program in existence. I've been looking everywhere for this, even on Dlang.org , and haven't found a satisfactory answer yet.
In my specific case I'm trying to make a simple game as a project to help me learn D and I realized that I needed keypress handling so I could, at the very least, navigate menus I'd create in a more natural way so I could properly test my game.
I would eventually like this system to be usable on both windows and linux interchangably, probably just by detecting the operating system the program is running on at launch and then choosing the right code to run to make it all work. But that will come later. Right now i just want to know how to build a simple Keypress event handler that can trigger a function or method or whatever I want as soon as I press the key and have it work in a windows environment.

ALSA async callbacks?

The ALSA documentation seems to be very lacking... Basically, I need to play sounds asynchronously, be able to stop (all) sounds, and get a callback when one has finished playing successfully.
I can mostly do the first 2, its just the latter I'm having trouble with.
Does anyone know any snippets that may enlighten me?
Further Details:
Basically the user will be browsing a collection of sounds, when they hover over one, it should play it, and when they go onto the next one, that one should stop very quickly, and the next should play etc.... This will happen fast. The last one they heard in its entirety should be selected (hence why I need the callback if a whole sound plays successfully, as atm the one selected isn't necessarily the one they least heard, due to threading)
I don't really want to use any libraries other than libasound.

How do I tell if a button is being held down in OpenGL/Glut? (linux)

This is a similar problem: Link
Which was solved by calling GetAsyncKeyState(). While all fine and dandy, I need a Linux alternative. I need to know if a button is being held down, not just being pressed (because of the keyboard buffer delay). Does anything like this exist in the OpenGL/Glut libraries, or will I have to look elsewhere?
I have never used Glut, but I know that many people will say SDL is better. I have used SDL and I like it a lot. It does everything Glut does and a lot more. In SDL, you can use SDL_PollEvent() to get key state without the keyboard buffer delay.
Edit: I know almost nothing about Glut, but it looks like you can use glutKeyboardFunc to detect normal keys, and glutSpecialFunc for keys that do not generate ASCII characters (such as shift). I'm not sure if there is a better way, as this doesn't seem very nice.
You can detect when a keypress event occurs, record that state, and then listen for a key release event.
As said, you will have to make your own state machine, which is easy. But you also need to use this callback method I think.
http://pyopengl.sourceforge.net/documentation/manual/glutKeyboardUpFunc.3GLUT.xml

Resources