Last active
May 12, 2018 05:19
-
-
Save ixsiid/7ce660568d435be527b2507a94a6b946 to your computer and use it in GitHub Desktop.
create midi interface and connect fluidsynth
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cstdlib> | |
#include <smf.h> | |
#include <algorithm> | |
#include <chrono> | |
#include <thread> | |
#include <unistd.h> | |
#include "RtMidi.h" | |
static std::string outClientName = std::string("MKT Output Client"); | |
static std::string outPortName = std::string("MKT Output Port"); | |
static std::string targetOut = std::string("FLUID"); | |
void mycallback(double deltatime, std::vector<unsigned char> *message, void *userData) {} | |
int outPortIndex findMidiPort (std::string outPortName, RtMidi * midi) { | |
try { | |
unsigned int nPorts = midi->getPortCount(); | |
for (unsigned int i=0; i<nPorts; i++) { | |
std::string portName = midi->getPortName(i); | |
std::string::size_type loc = portName.find(outPortName, 0); | |
if (loc != std::string::npos) return i; | |
} | |
} catch (RtMidiError &error) { | |
error.printMessage(); | |
} | |
return -1; | |
} | |
int main() | |
{ | |
RtMidi * midiout = new RtMidiOut(); | |
int outPort = findMidiPort(targetOut, midiout); | |
if (outPort < 0) { | |
std::cout << "Not found target port" << std::endl; | |
exit(1); | |
} | |
midiout->openPort(outPort, outPortName); | |
while (true) { | |
int chr = std::cin.get(); | |
if (chr == 'q') break; | |
} | |
delete midiout; | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment