0

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.

  • The problem here is that your English is slightly off. In fact what you mean to say is _"**when** NOTE ON 60 is received, play X .wave file"_ and "when" differs hugely from "if", at least in C++ programming. As such, this is something of a broad question. – Lightness Races in Orbit Jun 07 '15 at 16:23
  • Ah okay, I'll edit that now. – David Benito Jun 07 '15 at 16:34

2 Answers2

0

you can use PortAudio it has everything that you can work with midi and your wave files

  • Ah great! And how would I code "when NOTE ON 60 is received, play X .wav file" with PortAudio? Thanks very much for your reply by the way! – David Benito Jun 09 '15 at 17:38
0

you can implement a stream function with portAudio and check with portMidi that when note c4 for example is pressed, play that file look at there documentation