Code-style consistency improvement:
Apply clang-format-all.sh using the _clang-format file through all the cpp/.h files. make sure not to apply it to certain serialization structures, since some parser expects the * as part of the name, instead of type. This commit contains no other changes aside from adding and applying clang-format-all.sh
This commit is contained in:
@@ -11,67 +11,65 @@
|
||||
#include <cstdlib>
|
||||
#include "RtMidi.h"
|
||||
|
||||
void usage( void ) {
|
||||
// Error function in case of incorrect command-line
|
||||
// argument specifications.
|
||||
std::cout << "\nuseage: cmidiin <port>\n";
|
||||
std::cout << " where port = the device to use (default = 0).\n\n";
|
||||
exit( 0 );
|
||||
void usage(void)
|
||||
{
|
||||
// Error function in case of incorrect command-line
|
||||
// argument specifications.
|
||||
std::cout << "\nuseage: cmidiin <port>\n";
|
||||
std::cout << " where port = the device to use (default = 0).\n\n";
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void mycallback( double deltatime, std::vector< unsigned char > *message, void *userData )
|
||||
void mycallback(double deltatime, std::vector<unsigned char> *message, void *userData)
|
||||
{
|
||||
unsigned int nBytes = message->size();
|
||||
for ( unsigned int i=0; i<nBytes; i++ )
|
||||
std::cout << "Byte " << i << " = " << (int)message->at(i) << ", ";
|
||||
if ( nBytes > 0 )
|
||||
std::cout << "stamp = " << deltatime << std::endl;
|
||||
unsigned int nBytes = message->size();
|
||||
for (unsigned int i = 0; i < nBytes; i++)
|
||||
std::cout << "Byte " << i << " = " << (int)message->at(i) << ", ";
|
||||
if (nBytes > 0)
|
||||
std::cout << "stamp = " << deltatime << std::endl;
|
||||
}
|
||||
|
||||
// This function should be embedded in a try/catch block in case of
|
||||
// an exception. It offers the user a choice of MIDI ports to open.
|
||||
// It returns false if there are no ports available.
|
||||
bool chooseMidiPort( RtMidiIn *rtmidi );
|
||||
bool chooseMidiPort(RtMidiIn *rtmidi);
|
||||
|
||||
int main( int argc, char *argv[] )
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
RtMidiIn *midiin = 0;
|
||||
RtMidiIn *midiin = 0;
|
||||
|
||||
// Minimal command-line check.
|
||||
if ( argc > 2 ) usage();
|
||||
// Minimal command-line check.
|
||||
if (argc > 2) usage();
|
||||
|
||||
// RtMidiIn constructor
|
||||
midiin = new RtMidiIn();
|
||||
|
||||
// RtMidiIn constructor
|
||||
midiin = new RtMidiIn();
|
||||
// Call function to select port.
|
||||
if (chooseMidiPort(midiin) == false) goto cleanup;
|
||||
|
||||
// Call function to select port.
|
||||
if ( chooseMidiPort( midiin ) == false ) goto cleanup;
|
||||
// Set our callback function. This should be done immediately after
|
||||
// opening the port to avoid having incoming messages written to the
|
||||
// queue instead of sent to the callback function.
|
||||
midiin->setCallback(&mycallback);
|
||||
|
||||
// Set our callback function. This should be done immediately after
|
||||
// opening the port to avoid having incoming messages written to the
|
||||
// queue instead of sent to the callback function.
|
||||
midiin->setCallback( &mycallback );
|
||||
// Don't ignore sysex, timing, or active sensing messages.
|
||||
midiin->ignoreTypes(false, false, false);
|
||||
|
||||
// Don't ignore sysex, timing, or active sensing messages.
|
||||
midiin->ignoreTypes( false, false, false );
|
||||
|
||||
std::cout << "\nReading MIDI input ... press <enter> to quit.\n";
|
||||
char input;
|
||||
std::cin.get(input);
|
||||
std::cout << "\nReading MIDI input ... press <enter> to quit.\n";
|
||||
char input;
|
||||
std::cin.get(input);
|
||||
std::cin.get(input);
|
||||
|
||||
cleanup:
|
||||
|
||||
delete midiin;
|
||||
|
||||
cleanup:
|
||||
|
||||
delete midiin;
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool chooseMidiPort( RtMidiIn *rtmidi )
|
||||
bool chooseMidiPort(RtMidiIn *rtmidi)
|
||||
{
|
||||
/*
|
||||
/*
|
||||
|
||||
std::cout << "\nWould you like to open a virtual input port? [y/N] ";
|
||||
|
||||
@@ -83,30 +81,35 @@ bool chooseMidiPort( RtMidiIn *rtmidi )
|
||||
}
|
||||
*/
|
||||
|
||||
std::string portName;
|
||||
unsigned int i = 0, nPorts = rtmidi->getPortCount();
|
||||
if ( nPorts == 0 ) {
|
||||
std::cout << "No input ports available!" << std::endl;
|
||||
return false;
|
||||
}
|
||||
std::string portName;
|
||||
unsigned int i = 0, nPorts = rtmidi->getPortCount();
|
||||
if (nPorts == 0)
|
||||
{
|
||||
std::cout << "No input ports available!" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( nPorts == 1 ) {
|
||||
std::cout << "\nOpening " << rtmidi->getPortName() << std::endl;
|
||||
}
|
||||
else {
|
||||
for ( i=0; i<nPorts; i++ ) {
|
||||
portName = rtmidi->getPortName(i);
|
||||
std::cout << " Input port #" << i << ": " << portName << '\n';
|
||||
}
|
||||
if (nPorts == 1)
|
||||
{
|
||||
std::cout << "\nOpening " << rtmidi->getPortName() << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < nPorts; i++)
|
||||
{
|
||||
portName = rtmidi->getPortName(i);
|
||||
std::cout << " Input port #" << i << ": " << portName << '\n';
|
||||
}
|
||||
|
||||
do {
|
||||
std::cout << "\nChoose a port number: ";
|
||||
std::cin >> i;
|
||||
} while ( i >= nPorts );
|
||||
}
|
||||
do
|
||||
{
|
||||
std::cout << "\nChoose a port number: ";
|
||||
std::cin >> i;
|
||||
} while (i >= nPorts);
|
||||
}
|
||||
|
||||
// std::getline( std::cin, keyHit ); // used to clear out stdin
|
||||
rtmidi->openPort( i );
|
||||
// std::getline( std::cin, keyHit ); // used to clear out stdin
|
||||
rtmidi->openPort(i);
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user