I'm trying to make a piece of software using C++ that plays a .wav audio sample when a certain MIDI key is pressed. The best way I thought about doing this is using an if
statement (if there's an easier way I would much appreciate it, but I'm quite the novice to programming so please keep it simple).
Having looked online, I've found out that different MIDI keys correspond to different NOTE ON messages (for example, NOTE ON 60 would correspond to middle C), so basically I'm just looking for how to say "when NOTE ON 60 is received, play X .wav file". I've also found out that the status for NOTE ON is 9n
, so would this mean the computer would receive 9x60
(using the 60 = Middle C example)?
After this I would just need to find out how to play an audio sample, which I believe would be the following, using sndfile.h
:
SNDFILE *sndFile = sf_open("Sample1.wav").
Any help would be very greatly appreciated.