Skip to content

Commit

Permalink
Reverted sysextest.cpp to previous version and added warning flag to …
Browse files Browse the repository at this point in the history
…configure.ac
  • Loading branch information
garyscavone committed Mar 26, 2014
1 parent 653a2a1 commit b07a6e0
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 4 deletions.
4 changes: 2 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ AC_ARG_ENABLE(debug,
[AC_SUBST( cppflag, [] ) AC_SUBST( cxxflag, [-O3] ) AC_SUBST( object_path, [Release] ) AC_MSG_RESULT(no)])

# Set paths if prefix is defined
if test x"$prefix" != x && test x$prefix != xNONE; then
if test "x$prefix" != "x" && test "x$prefix" != "xNONE"; then
LIBS="$LIBS -L$prefix/lib"
CPPFLAGS="$CPPFLAGS -I$prefix/include"
fi
Expand All @@ -41,7 +41,7 @@ CXXFLAGS="$cxxflag"

# Check compiler and use -Wall if gnu.
if [test $GXX = "yes" ;] then
AC_SUBST( cxxflag, [-Wall] )
AC_SUBST( cxxflag, ["-Wall -Wextra"] )
fi

CXXFLAGS="$CXXFLAGS $cxxflag"
Expand Down
61 changes: 59 additions & 2 deletions tests/sysextest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ void usage( void ) {
#define SLEEP( milliseconds ) usleep( (unsigned long) (milliseconds * 1000.0) )
#endif

// 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( RtMidi *rtmidi );

void mycallback( double deltatime, std::vector< unsigned char > *message, void *userData )
{
unsigned int nBytes = message->size();
Expand Down Expand Up @@ -60,8 +65,8 @@ int main( int argc, char *argv[] )
midiin->ignoreTypes( false, true, true );

try {
midiin->openVirtualPort( "MyVirtualInputPort" );
midiout->openPort( 0 );
if ( chooseMidiPort( midiin ) == false ) goto cleanup;
if ( chooseMidiPort( midiout ) == false ) goto cleanup;
}
catch ( RtMidiError &error ) {
error.printMessage();
Expand Down Expand Up @@ -93,3 +98,55 @@ int main( int argc, char *argv[] )

return 0;
}

bool chooseMidiPort( RtMidi *rtmidi )
{
bool isInput = false;
if ( typeid( *rtmidi ) == typeid( RtMidiIn ) )
isInput = true;

if ( isInput )
std::cout << "\nWould you like to open a virtual input port? [y/N] ";
else
std::cout << "\nWould you like to open a virtual output port? [y/N] ";

std::string keyHit;
std::getline( std::cin, keyHit );
if ( keyHit == "y" ) {
rtmidi->openVirtualPort();
return true;
}

std::string portName;
unsigned int i = 0, nPorts = rtmidi->getPortCount();
if ( nPorts == 0 ) {
if ( isInput )
std::cout << "No input ports available!" << std::endl;
else
std::cout << "No output 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);
if ( isInput )
std::cout << " Input port #" << i << ": " << portName << '\n';
else
std::cout << " Output port #" << i << ": " << portName << '\n';
}

do {
std::cout << "\nChoose a port number: ";
std::cin >> i;
} while ( i >= nPorts );
}

std::cout << std::endl;
rtmidi->openPort( i );

return true;
}

0 comments on commit b07a6e0

Please sign in to comment.