Powered by Blogger.

Use RtMidi in Windows in a Microsoft Visual Studio C++ Project

Sunday, May 12, 2013

Create a "Win32 Console Application" in Visual Studio.


Name it, click OK.


Click next.


Deselect "Precompiled header" and select "Empty project", click Finish.

Add a C++ (.cpp) file, name it and click Add.


Copy the code of "midiout.cpp" from this link to your .cpp file.
Change "SLEEP" in the code to "Sleep". (Since we are using Windows)
Add "#include " at the beginning of the code.
Copy "RtMidi.cpp", "RtMidi.h" and "RtError.h" files to your project folder. You can find these files from here.

Right click on your project in VS -> Add -> Existing item.
Select and add above three files to your project.


Now your project file structure will look like this.


Add "#define __WINDOWS_MM__" line at the beginning of the "RtMidi.h" file.


Right click on your project in VS -> Properties.


Go to Configuration properties -> Linker -> Input. Add "winmm.lib" at the end of "Additional dependencies".


Click Apply and OK.

Go to Visual Studio project. Press "F7". Press "Control key + F5". Then you can see the command prompt and can hear a short beep. If so, your RtMidi now works fine. Good luck!


8 comments:

Anonymous said...

This was very helpful for setting up my RtMidi project. Thank you so much!

Anonymous said...

Thank you sooo much for this!

Anonymous said...

Thanks for filling in some of the documentation gaps.

Unknown said...

Thanks - this was very helpful.
I did have to make a couple of changes to get it to work with the latest version of RtMidi in Visual Studio 2017 on Windows 10.
- Firstly, there doesn't seem to be an RtError.h but it did'nt matter. (perhaps everything is in the one .h file now?)
- Secondly I had problems with linking the winmm.lib file - lot's of "unresolved external symbol" messages. I googles it and adding the line "#pragma comment(lib, "winmm.lib")" to RtMidi.h fixed this problem for me.

Anonymous said...

Thanks - this was very helpful.
I did have to make a couple of changes to get it to work with the latest version of RtMidi in Visual Studio 2017 on Windows 10.
- Firstly, there doesn't seem to be an RtError.h but it didn't matter. (perhaps everything is in the one .h file now?)
- Secondly I had problems with linking the winmm.lib file - lot's of "unresolved external symbol" messages. I googled it and adding the line "#pragma comment(lib, "winmm.lib")" to RtMidi.h fixed this problem for me.

Anonymous said...

It looks like in RtMidi v 3.0.0 you don't need to include the RtError.h file.
I got it to work successfully without, but when included, I got the error: about having 2 main sections. Cheers for this tutoprial. It's great.

Anonymous said...

This was extremely useful!! Thank you so much for your work clarifying the steps needed to get this running :) Never take this article down!

ForestCat said...

Thanx, man. Amazing how little info there is out there like this.