[Stk] Midi In & Midi Out

dimoni@dimoni.demon.nl dimoni@dimoni.demon.nl
Sat, 9 Oct 2004 19:15:16 +0200


Hi there,

I am trying to obtain midi in and midi out using RtMidi tool.
When I compile the code

g++ -Wall -D__MACOSX_CORE__ -o midiInOut midiInOut.cpp -lpthread -lstk 
-framework CoreMidi -framework CoreFoundation

  I get the following:

midiInOut.cpp: In function `int main()':
midiInOut.cpp:54: warning: jump to label `cleanup'
midiInOut.cpp:21: warning:   from here
midiInOut.cpp:24: error:   crosses initialization of `unsigned int 
nPortsOut'

The code I am using is as follows:

#include <stk/RtMidi.h>
#include <iostream>

#include <signal.h>

bool done;
static void finish(int ignore){ done = true; }

int main()
{
   RtMidiIn *midiin = new RtMidiIn();
   RtMidiOut *midiout = new RtMidiOut();
   std::vector<unsigned char> message;

   // Check available ports.
   unsigned int nPortsIn = midiin->getPortCount();
   if ( nPortsIn == 0 ) {
        std::cout << "No midi in available!\n";
        goto cleanup;
   }
   midiin->openPort( 0 );

   unsigned int nPortsOut = midiout->getPortCount();   <----------- this 
is line 24,  error:   crosses initialization of `unsigned int 
nPortsOut'
   if ( nPortsOut == 0 ) {
        std::cout << "No midi out available!\n";
        goto cleanup;
   }
   midiout->openPort( 0 );

   // Don't ignore sysex, timing, or active sensing messages.
   midiin->ignoreTypes( false, false, false );

   // Install an interrupt handler function.
   done = false;
   (void) signal(SIGINT, finish);

   // Periodically check input queue.
   std::cout << "Reading MIDI from port ... quit with Ctrl-C.\n";
    while ( !done ) {
        midiin->getMessage( &message );
        midiout->sendMessage( &message );
   }

  // Clean up
  cleanup:
   delete midiin;
   delete midiout;
   return 0;
}

Could you please give me some advice?

Thanks

Eduard