|
| 1 | +ofxMidi |
| 2 | +======= |
| 3 | +<p align="center"> |
| 4 | +<img src="https://raw.github.com/danomatika/ofxMidi/master/res/midi_din.png"/> |
| 5 | +</p> |
| 6 | + |
| 7 | +Midi input and output addon for openFrameworks |
| 8 | + |
| 9 | +Copyright (c) [Dan Wilcox](danomatika.com) 2011-2013<br/> |
| 10 | +(original implementation by Chris O'Shea, Arturo Castro, Kyle McDonald) |
| 11 | + |
| 12 | +BSD Simplified License. |
| 13 | + |
| 14 | +For information on usage and redistribution, and for a DISCLAIMER OF ALL |
| 15 | +WARRANTIES, see the file, "LICENSE.txt," in this distribution. |
| 16 | + |
| 17 | +See Documentation on [Github](https://github.com/danomatika/ofxMidi) and the [OpenFrameworks Forum post](http://forum.openframeworks.cc/index.php/topic,2435.0.html). |
| 18 | + |
| 19 | +OpenFrameworks is a cross platform open source toolkit for creative coding in C++. |
| 20 | + |
| 21 | +[http://www.openframeworks.cc](http://www.openframeworks.cc) |
| 22 | + |
| 23 | +Description |
| 24 | +----------- |
| 25 | + |
| 26 | +ofxMidi provides [Music Instrument Digial Interface](http://en.wikipedia.org/wiki/Musical_Instrument_Digital_Interface) IO capability to an OpenFrameworks app |
| 27 | + |
| 28 | +* ofxMidiIn: a single midi input port, derive from the ofxMidiListener class to receive messages |
| 29 | +* ofxMidiMessage: a received midi message |
| 30 | +* ofxMidiOut: a single midi output port, includes a stream << interface |
| 31 | + |
| 32 | +This project utilizes [RtMidi](http://www.music.mcgill.ca/~gary/rtmidi/) for Mac, Windows, & Linux and [PGMidi](https://github.com/petegoodliffe/PGMidi) on iOS. |
| 33 | + |
| 34 | +Installation |
| 35 | +------------ |
| 36 | + |
| 37 | +To use ofxMidi, first you need to download and install OpenFrameworks. ofxMidi is currently developed against the current stable version of Open Frameworks on github. |
| 38 | + |
| 39 | +To get a copy of the repository you can download the source from [http://github.com/danomatika/ofxMidi/zipball/master](http://github.com/danomatika/ofxMidi/zipball/master) or, alternatively, you can use git clone: |
| 40 | +<pre> |
| 41 | +git clone git://github.com/danomatika/ofxMidi.git |
| 42 | +</pre> |
| 43 | + |
| 44 | +The addon should sit in `openFrameworks/addons/ofxMidi/`. |
| 45 | + |
| 46 | +#### Which version to use? |
| 47 | + |
| 48 | +If you are using a stable version (007, ...) of OpenFrameworks then you want to use a git tag of ofxMidi for that version. You can select the tag in the Github "Current Branch" menu or clone and check it out using git. |
| 49 | + |
| 50 | +For example, the following commands will clone ofxMidi and switch to the OF 007 tagged version: |
| 51 | +<pre> |
| 52 | +git clone git://github.com/danomatika/ofxMidi.git |
| 53 | +cd ofxPd |
| 54 | +git checkout 007 |
| 55 | +</pre> |
| 56 | + |
| 57 | +Midi Routing |
| 58 | +------------ |
| 59 | + |
| 60 | +### Mac OSX |
| 61 | + |
| 62 | +Checkout a useful app for midi port routing called [MIDI Patchbay](http://notahat.com/midi_patchbay). |
| 63 | + |
| 64 | +### Linux |
| 65 | + |
| 66 | +Check out the Alsa utility apps aconnect & aconnectgui as well as the qjackctl gui for midi port routing control. |
| 67 | + |
| 68 | +### Windows |
| 69 | + |
| 70 | +Windows dosen't come with a virtual MIDI routing system like Linux (ALSA) and OSX (CoreMIDI). |
| 71 | + |
| 72 | +If you want to connect your ofxMidi app to other software (synths, DAWs, etc) check out [loopMIDI](http://www.tobias-erichsen.de/loopMIDI.html). Run the app and create a few virtual ports which you can then connect to within your software. |
| 73 | + |
| 74 | +Running the Example Project |
| 75 | +--------------------------- |
| 76 | + |
| 77 | +The example projects are in the ofxMidi/example-input/ or ofxMidi/example-output/ folders. |
| 78 | + |
| 79 | +### OSX |
| 80 | + |
| 81 | +Open the Xcode project, select the project scheme, and hit "Run". |
| 82 | + |
| 83 | +### Linux |
| 84 | + |
| 85 | +Open the Code::Blocks .workspace and hit F9 to build. Optionally, you can build the example with the Makefile. |
| 86 | + |
| 87 | +To built and run it on the terminal: |
| 88 | +<pre> |
| 89 | +make |
| 90 | +make run |
| 91 | +</pre> |
| 92 | + |
| 93 | +### Windows |
| 94 | + |
| 95 | +An example Visual Studio solution as well as a Codeblocks workspace are included. |
| 96 | + |
| 97 | +Creating a New ofxMidi Project |
| 98 | +------------------------------ |
| 99 | + |
| 100 | +_Note: These instructions are for manually creating a new project. You do not need to follow these steps if you use the ProjecGenerator app, except for Xcode where you currently need to add the CoreMIDI framework._ |
| 101 | + |
| 102 | +To develop your own project based on ofxMidi, simply copy the example project and rename it. You probably want to put it in your apps folder, for example, after copying: |
| 103 | +<pre> |
| 104 | +openFrameworks/addons/ofxPd/exampleInput/ => openFrameworks/apps/myApps/exampleInput/ |
| 105 | +</pre> |
| 106 | + |
| 107 | +It must be 3 levels down in the openframeworks folder structure. |
| 108 | + |
| 109 | +Then rename the folder: |
| 110 | +<pre> |
| 111 | +openFrameworks/apps/myApps/myPdProject/ |
| 112 | +</pre> |
| 113 | + |
| 114 | +#### Xcode |
| 115 | + |
| 116 | +Rename the project in Xcode (do not rename the .xcodeproj file in Finder!): |
| 117 | +* Xcode Menu->Project->Rename |
| 118 | + |
| 119 | +#### Codeblocks (Win & Linux) |
| 120 | + |
| 121 | +* rename the *.cbp and *.workspace files |
| 122 | +* open the workspace and readd the renamed project file by dragging it onto the project tree (it will complain about the missing project you renamed) |
| 123 | +* if you renamed the project *folder* make sure to set the project name to this folder name or C::B will not be able to run the binary: |
| 124 | + * right click on project in the tree (not the workspace) |
| 125 | + * Properties...->Title |
| 126 | + |
| 127 | +#### Visual Studio |
| 128 | + |
| 129 | +* rename the *.sln, *.vcxproj, & *.vcxproj.filters files |
| 130 | +* open the solution and delete the old project from the projects tree |
| 131 | +* go to File->Add->Existing Projects/Solutions and select the *.vcxproj file |
| 132 | +* right click on the project in the projects tree and rename it |
| 133 | + |
| 134 | +Adding ofxMidi to an Existing Project |
| 135 | +------------------------------------- |
| 136 | + |
| 137 | +_Note: These instructions are for manually adding ofxMidi to a project. You do not need to follow these steps if you use the ProjecGenerator app to regenerate your project files, except for Xcode where you currently need to add the CoreMIDI framework._ |
| 138 | + |
| 139 | +### Xcode |
| 140 | + |
| 141 | +* create a new group "ofxMidi" |
| 142 | +* drag these directories from ofxMidi into this new group: `ofxMidi/src` |
| 143 | + * if building for OSX, remove the src/ios & libs/pgmidi folder references |
| 144 | + * if building for iOS, remove the src/desktop & libs/rtmidi folder references |
| 145 | +* add the CoreMIDI framework to your project |
| 146 | + * click on your project in the sidebar |
| 147 | + * select the Summary tab |
| 148 | + * click the + under Linked Frameworks & Libraries |
| 149 | + * search for and select the CoreMIDI.framework from the list |
| 150 | +* add the following directories to your search path in your project's Project.xconfig file (See the Project.xconfig of the example project.): |
| 151 | + <pre> |
| 152 | +../../../addons/ofxMidi/src |
| 153 | +../../../addons/ofxMidi/libs/rtmidi |
| 154 | +</pre> |
| 155 | + |
| 156 | +### Linux Makefiles/CodeBlocks |
| 157 | + |
| 158 | +* edit addons.make in your project folder and add the following line to the end of the file: |
| 159 | + <pre>ofxMidi</pre> |
| 160 | + |
| 161 | +### Win Codeblocks & Visual Studio |
| 162 | + |
| 163 | +* add the ofxMidi sources to the project tree |
| 164 | + <pre> |
| 165 | +ofxMidi/src |
| 166 | +ofxMidi/libs/rtmidi |
| 167 | +</pre> |
| 168 | + * Codeblocks: right click on the project in the project tree and select Add Files Recursively... |
| 169 | + * Visual Studio: drag the ofxMidi/src & ofxMidi/libs/rtmidi folder onto the project tree |
| 170 | +* add the following search paths: |
| 171 | + <pre> |
| 172 | +..\\..\\..\addons\ofxMidi\src |
| 173 | +..\\..\\..\addons\ofxMidi\libs\rtmidi |
| 174 | +</pre> |
| 175 | +* Codeblocks |
| 176 | + * right click on the project in the project tree and select Build Options... |
| 177 | + * select the project name in the tree, not release or debug |
| 178 | + * Search directories tab->Add |
| 179 | +* Visual Studio |
| 180 | + * right click on the project in the project tree and select Properties |
| 181 | + * set the Configuration to All Configurations |
| 182 | + * Configuration Properties->C/C++->General->Additional Directories |
| 183 | + |
| 184 | +KNOWN ISSUES |
| 185 | +------------ |
| 186 | + |
| 187 | +### Using static ofxMidi objects on Linux causes seg faults |
| 188 | + |
| 189 | +Avoid creating static ofxMidiIn / ofxMidiOut objects on Linux as the compiler seems to set creation order so they are created *before* ALSA is ready. This leads to a confirmed seg fault on Ubuntu and probably all other flavors of Linux using ALSA. The midi apis on Windows and OSX do not share this problem. |
| 190 | + |
| 191 | +Instead create a static ofPtr and initialize it later: |
| 192 | + |
| 193 | + // in .h: |
| 194 | + |
| 195 | + class MyClass { |
| 196 | + |
| 197 | + ... |
| 198 | + |
| 199 | + static ofPtr<ofxMidiOut> s_midiOut; |
| 200 | + |
| 201 | + ... |
| 202 | + |
| 203 | + } |
| 204 | + |
| 205 | + // in .cpp: |
| 206 | + |
| 207 | + ofPtr<ofxMidiOut> MyClass::s_midiOut; |
| 208 | + |
| 209 | + ... |
| 210 | + |
| 211 | + // initialize somewhere else |
| 212 | + void MyClass::setup() { |
| 213 | + if(s_midiOut == NULL) { |
| 214 | + s_midiOut = ofPtr<ofxMidiOut>(new ofxMidiOut("ofxMidi Client")); |
| 215 | + } |
| 216 | + } |
| 217 | + |
| 218 | + |
| 219 | +DEVELOPING |
| 220 | +---------- |
| 221 | + |
| 222 | +You can help develop ofxMidi on GitHub: [https://github.com/danomatika/ofxMidi](https://github.com/danomatika/ofxMidi) |
| 223 | + |
| 224 | +Create an account, clone or fork the repo, then request a push/merge. Please use the *develop* branch of updates and pull requests. |
| 225 | + |
| 226 | +If you find any bugs or suggestions please log them to GitHub as well. |
| 227 | + |
| 228 | +### Adding a Midi Backend |
| 229 | + |
| 230 | +If you want to add a new midi backend (Android, Jack, etc), you'll need two classes derived from ofxBaseMidiIn & ofxBaseMidiOut. |
| 231 | + |
| 232 | +Place your source files in a new folder named after your platform/library and add new include #ifdef flags to ofxMidiIn.h & ofxMidiIn.cpp. |
| 233 | + |
| 234 | +Last, you'll need to add specific #ifdef flags to the static port info ofxMidiIn/Out functions (listPorts, getPortName, etc). |
| 235 | + |
| 236 | +### Updating Midi Libraries |
| 237 | + |
| 238 | +RtMidi & PGMidi can be updated by running the `update_rtmidi.sh` or `update_pgmidi.sh` shell scripts in the scripts folder. |
| 239 | + |
| 240 | +For RtMidi, edit the version setting in the script header and run the script to download and place the RtMidi sources into `libs/rtmidi`. |
| 241 | + |
| 242 | +PGMidi sources are placed in `libs/pgmidi`. |
| 243 | + |
| 244 | +#### RtMidi.cpp include |
| 245 | + |
| 246 | +Next, make sure to add the following include to `RtMidi.cpp` at around line 38 or there will be link errors: |
| 247 | + |
| 248 | + #include "ofxConstants.h" |
| 249 | + |
0 commit comments