this can be done as two separate programs: a software synthesizer (like fluidsynth
) and a virtual midi keyboard (like vmpk
The synthesizer gets midi events from the virtual keyboard program, generates and mixes corresponding sounds. The midi keyboard program waits for user input on the hardware keyboard, translates scancodes into midi events and sends them to the synthesizer.
It is possible, of course, to invent a custom protocol instead of midi, but midi was designed special for this task.
Instead of playing multiple files it is reasonable to play a soundfont
. Many of them are freely available.
Another benefit from described architecture is that midi events can be both produced by the virtual midi keyboard and read from a standard midi file.