예제 #1
0
bool MidiInRt::getPortList(QVector<QString> &ports)
{
    RtMidiIn *midiin = lazyInstance();
#if (QT_VERSION < 0x050000) && defined(_WIN32)
    RtMidi::Api api = midiin->getCurrentApi();
#endif

    m_errorSignaled = false;
    unsigned count = midiin->getPortCount();
    if(m_errorSignaled)
        return false;

    ports.resize(count);
    for(unsigned i = 0; i < count; ++i)
    {
        m_errorSignaled = false;
#if (QT_VERSION < 0x050000) && defined(_WIN32)
        if(api == RtMidi::WINDOWS_MM)
        {
            MIDIINCAPSA deviceCaps;
            midiInGetDevCapsA(i, &deviceCaps, sizeof(MIDIINCAPSA));
            ports[i] = QString::fromLocal8Bit(deviceCaps.szPname);
        }
        else
#endif
        {
            std::string name = midiin->getPortName(i);
            if(m_errorSignaled)
                return false;
            ports[i] = QString::fromStdString(name);
        }
    }
    return true;
}
예제 #2
0
//-----------------------------------------------------------------------------
// name: probeMidiIn()
// desc: ...
//-----------------------------------------------------------------------------
void probeMidiIn()
{
    RtMidiIn * min = NULL;

    try {
        min = new RtMidiIn;;
    } catch( RtMidiError & err ) {
        EM_error2b( 0, "%s", err.getMessage().c_str() );
        return;
    }

    // get num
    t_CKUINT num = min->getPortCount();
    EM_error2b( 0, "------( chuck -- %i MIDI inputs )------", num );
    EM_reset_msg();
    
    std::string s;
    for( t_CKUINT i = 0; i < num; i++ )
    {
        try { s = min->getPortName( i ); }
        catch( RtMidiError & err )
        { err.printMessage(); return; }
        EM_error2b( 0, "    [%i] : \"%s\"", i, s.c_str() );
        
        EM_reset_msg();
    }
}
예제 #3
0
int main()
{
  // Create an api map.
  std::map<int, std::string> apiMap;
  apiMap[RtMidi::MACOSX_CORE] = "OS-X CoreMidi";
  apiMap[RtMidi::WINDOWS_MM] = "Windows MultiMedia";
  apiMap[RtMidi::UNIX_JACK] = "Jack Client";
  apiMap[RtMidi::LINUX_ALSA] = "Linux ALSA";
  apiMap[RtMidi::RTMIDI_DUMMY] = "RtMidi Dummy";

  std::vector< RtMidi::Api > apis;
  RtMidi :: getCompiledApi( apis );

  std::cout << "\nCompiled APIs:\n";
  for ( unsigned int i=0; i<apis.size(); i++ )
    std::cout << "  " << apiMap[ apis[i] ] << std::endl;

  RtMidiIn  *midiin = 0;
  RtMidiOut *midiout = 0;

  try {

    // RtMidiIn constructor ... exception possible
    midiin = new RtMidiIn();

    std::cout << "\nCurrent input API: " << apiMap[ midiin->getCurrentApi() ] << std::endl;

    // Check inputs.
    unsigned int nPorts = midiin->getPortCount();
    std::cout << "\nThere are " << nPorts << " MIDI input sources available.\n";

    for ( unsigned i=0; i<nPorts; i++ ) {
      std::string portName = midiin->getPortName(i);
      std::cout << "  Input Port #" << i+1 << ": " << portName << '\n';
    }

    // RtMidiOut constructor ... exception possible
    midiout = new RtMidiOut();

    std::cout << "\nCurrent output API: " << apiMap[ midiout->getCurrentApi() ] << std::endl;

    // Check outputs.
    nPorts = midiout->getPortCount();
    std::cout << "\nThere are " << nPorts << " MIDI output ports available.\n";

    for ( unsigned i=0; i<nPorts; i++ ) {
      std::string portName = midiout->getPortName(i);
      std::cout << "  Output Port #" << i+1 << ": " << portName << std::endl;
    }
    std::cout << std::endl;

  } catch ( RtMidiError &error ) {
    error.printMessage();
  }

  delete midiin;
  delete midiout;

  return 0;
}
예제 #4
0
////////////////////////////////////////////////////////////////////////////////
// SetupDialog::showEvent()
////////////////////////////////////////////////////////////////////////////////
///\brief   Message handler for the window show event.
///\param   [in] e: Description of the event.
////////////////////////////////////////////////////////////////////////////////
void SetupDialog::showEvent(QShowEvent* /*e*/)
{
  // Lock UI:
  blocked = true;

  // Get MIDI in properties:
  RtMidiIn midiIn;
  unsigned int portCnt = midiIn.getPortCount();
  if (portCnt > 0)
  {
    int selItem = -1;

    // Loop through MIDI ports:
    for (unsigned int i = 0; i < portCnt; i++)
    {
      // Get name of the port:
      QString name(midiIn.getPortName(i).c_str());

      // Does this match the currently selected option?
      if (name == inputName)
        selItem = i;

      // Add item to the combo box:
      ui->inputComboBox->addItem(name);
    }

    // Select current item, if any:
    ui->inputComboBox->setCurrentIndex(selItem);
  }

  // Get MIDI out properties:
  RtMidiOut midiOut;
  portCnt = midiOut.getPortCount();
  if (portCnt > 0)
  {
    int selItem = -1;

    // Loop through MIDI ports:
    for (unsigned int i = 0; i < portCnt; i++)
    {
      // Get name of the port:
      QString name(midiOut.getPortName(i).c_str());

      // Does this match the currently selected option?
      if (name == outputName)
        selItem = i;

      // Add item to the combo box:
      ui->outputComboBox->addItem(name);
    }

    // Select current item, if any:
    ui->outputComboBox->setCurrentIndex(selItem);
  }

  // Unlock UI:
  blocked = false;
}
예제 #5
0
t_CKBOOL MidiInManager::open( MidiIn * min, Chuck_VM * vm, const std::string & name )
{
    t_CKINT device_num = -1;
    
    try 
    {
        RtMidiIn * rtmin = new RtMidiIn;
        
        t_CKINT count = rtmin->getPortCount();
        for(t_CKINT i = 0; i < count; i++)
        {
            std::string port_name = rtmin->getPortName( i );
            if( port_name == name)
            {
                device_num = i;
                break;
            }
        }
        
        if( device_num == -1 )
        {
            // search by substring
            for(t_CKINT i = 0; i < count; i++)
            {
                std::string port_name = rtmin->getPortName( i );
                if( port_name.find( name ) != std::string::npos )
                {
                    device_num = i;
                    break;
                }
            }
        }
    }
    catch( RtMidiError & err )
    {
        if( !min->m_suppress_output )
        {
            // print it
            EM_error2( 0, "MidiOut: error locating MIDI port named %s", name.c_str() );
            err.getMessage();
            // const char * e = err.getMessage().c_str();
            // EM_error2( 0, "...(%s)", err.getMessage().c_str() );
        }
        return FALSE;
    }
    
    if(device_num == -1)
    {
        EM_error2( 0, "MidiOut: error locating MIDI port named %s", name.c_str() );
        return FALSE;
    }
    
    t_CKBOOL result = open( min, vm, device_num );
    
    return result;
}
예제 #6
0
int main(int argc, char** argv)
{

  if (argc != 2) {
    printf("Usage: synth file.sf2\n");
    exit(0);
  }

  LightFluidSynth *usynth;

  usynth = new LightFluidSynth();

  usynth->loadSF2(argv[1]);
//  usynth->loadSF2("tim.sf2");

  RtMidiIn *midiIn = new RtMidiIn();
  if (midiIn->getPortCount() == 0) {
    std::cout << "No MIDI ports available!\n";
  }
  midiIn->openPort(0);
  midiIn->setCallback( &midiCallback, (void *)usynth );
  midiIn->ignoreTypes( false, false, false );

//   RtAudio dac(RtAudio::LINUX_PULSE);
  RtAudio dac;
  RtAudio::StreamParameters rtParams;

  // Determine the number of devices available
  unsigned int devices = dac.getDeviceCount();
  // Scan through devices for various capabilities
  RtAudio::DeviceInfo info;
  for ( unsigned int i = 0; i < devices; i++ ) {
    info = dac.getDeviceInfo( i );
    if ( info.probed == true ) {
      std::cout << "device " << " = " << info.name;
      std::cout << ": maximum output channels = " << info.outputChannels << "\n";
    }
  }
//  rtParams.deviceId = 3;
  rtParams.deviceId = dac.getDefaultOutputDevice();
  rtParams.nChannels = 2;
  unsigned int bufferFrames = FRAME_SIZE;

  RtAudio::StreamOptions options;
  options.flags = RTAUDIO_SCHEDULE_REALTIME;

  dac.openStream( &rtParams, NULL, AUDIO_FORMAT, SAMPLE_RATE, &bufferFrames, &audioCallback, (void *)usynth, &options );
  dac.startStream();

  printf("\n\nPress Enter to stop\n\n");
  cin.get();
  dac.stopStream();

  delete(usynth);
  return 0;
}
예제 #7
0
// ******************************************
void shruthiEditorSettings::getDeviceInfo() {
// ******************************************
    RtMidiIn  *midiin = 0;
    RtMidiOut *midiout = 0;
    QString name;
  
    // Input ports:
    try {
        midiin = new RtMidiIn();
    }
    catch ( RtError &error ) {
        error.printMessage();
        exit( EXIT_FAILURE );
    }
    unsigned int numdev = midiin->getPortCount();
    
    std::cout << numdev << " midi input devices found.\n";

    for (unsigned int i=0; i < numdev; i++) {
        try {
            name = QString::fromStdString(midiin->getPortName(i));
        }
        catch ( RtError &error ) {
            error.printMessage();
            goto cleanup;
        }
        midi_input_device->addItem(name,i);
    }
    
    // Output ports:
    try {
        midiout = new RtMidiOut();
    }
    catch ( RtError &error ) {
        error.printMessage();
        exit( EXIT_FAILURE );
    }
    numdev = midiout->getPortCount();
    
    std::cout << numdev << " midi output devices found.\n";

    for (unsigned int i=0; i < numdev; i++) {
        try {
            name = QString::fromStdString(midiout->getPortName(i));
        }
        catch ( RtError &error ) {
            error.printMessage();
            goto cleanup;
        }
        midi_output_device->addItem(name,i);
    }
    
    cleanup:
    delete midiin;
    delete midiout;
}
void Midi::setup(){
    RtMidiIn *channels = new RtMidiIn();
    int port_number = channels->getPortCount();
    delete channels;
    if(port_number>0){
        active = true;
        for(int i = 0; i<port_number; i++){
            RtMidiIn *temp = new RtMidiIn();
            devices.push_back(temp);
            devices.at(i)->openPort(i);
            devices.at(i)->ignoreTypes(false,false,false);
        }
    }
}
예제 #9
0
파일: midi4l.cpp 프로젝트: aumhaa/MIDI4L
    /**
     * Get the list of available ports. 
     * Can be called repeatedly to regenerate the list if a MIDI device is plugged in or unplugged.
     */
    void refreshPorts() {
        char cPortName[MAX_STR_SIZE];
        
        inPortMap.clear();
        outPortMap.clear();

        if(midiin) {
            numInPorts = midiin->getPortCount();
            for ( int i=0; i<numInPorts; i++ ) {
                try {
                    std::string portName = midiin->getPortName(i);

                    // CME Xkey reports its name as "Xkey  ", which was a hassle to deal with in a Max patch, so auto-trim the names.
                    portName = trim(portName);
                    
                    strncpy(cPortName, portName.c_str(), MAX_STR_SIZE);
                    cPortName[MAX_STR_SIZE - 1] = NULL;
                    
                    inPortMap[gensym(cPortName)] = i;
                }
                catch ( RtMidiError &error ) {
                    printError("Error getting MIDI input port name", error);
                }
            }
        }
        
        if(midiout) {
            numOutPorts = midiout->getPortCount();
            for ( int i=0; i<numOutPorts; i++ ) {
                try {
                    std::string portName = midiout->getPortName(i);
                    
                    // CME Xkey reports its name as "Xkey  ", which was a hassle to deal with in a Max patch, so auto-trim the names.
                    portName = trim(portName);
                    
                    strncpy(cPortName, portName.c_str(), MAX_STR_SIZE);
                    cPortName[MAX_STR_SIZE - 1] = NULL;
                    
                    outPortMap[gensym(cPortName)] = i;
                }
                catch (RtMidiError &error) {
                    printError("Error getting MIDI output port name", error);
                }
            }
        }
    }
예제 #10
0
QList<MidiDevice::Description> MidiDevice::enumerateInputDevices()
{
    RtMidiIn midiIn;

    QList<MidiDevice::Description> devs;
    int n = midiIn.getPortCount();
    for (int i = 0; i < n; i++) {
        Description desc;
        desc.number = i;
        desc.type = Type_Input;
        try {
            desc.name = QString::fromStdString(midiIn.getPortName(i));
            devs.append(desc);
        } catch (RtMidiError &err) {
            Q_UNUSED(err);
        }
    }
    return devs;
}
예제 #11
0
vector<pair<int, string> > MidiInputController::availableMidiDevices() {
    RtMidiIn rtMidiIn;

    vector<pair<int, string> > deviceList;

    try {
        int numDevices = rtMidiIn.getPortCount();

        for(int i = 0; i < numDevices; i++) {
            pair<int, string> p(i, rtMidiIn.getPortName(i));
            deviceList.push_back(p);
        }
    }
    catch(...) {
        deviceList.clear();
    }

    return deviceList;
}
예제 #12
0
    /* returns 0 on failure */
    int
    start_midi(int port)
    {
        if(midi.getPortCount() < 1) {
            std::cout << "No MIDI ports available!\n";
            return 0;
        }

        try {
            midi.openPort(port);
        } catch(RtError &error) {
            return 0;
        }

        // don't ignore sysex, timing, or active sensing messages
        midi.ignoreTypes(false, false, false);

        return 1;
    }
예제 #13
0
static VALUE rtMidiIn_getDeviceNames(VALUE self)
{
	RtMidiIn *device;
	Data_Get_Struct(self, RtMidiIn, device);
	VALUE devices = rb_ary_new();
	int numDevices = device->getPortCount();
	
	for(int x = 0; x < numDevices; x++)
	{
		rb_warn("trying port %i out of %x\n", x, numDevices);
		try {
			std::string portName = device->getPortName(x);
			rb_ary_push(devices, rb_str_new2(portName.c_str()));
		}
		catch(RtError &error)
		{
			rb_warn("could not get device name for port %i\n", x);
			return Qnil;
		}
	}
	return devices;
}
예제 #14
0
static VALUE rtMidiIn_getNumDevices(VALUE self)
{
	RtMidiIn *device;
	Data_Get_Struct(self, RtMidiIn, device);
	return INT2NUM(device->getPortCount());
}
예제 #15
0
파일: main.cpp 프로젝트: hnney/Stanford
int main (int argc, char ** argv)
{
    
    //parse tempo 
    if (argc>2)
    {
        cerr<<"Error in arguments\n";
        printHelp();
        exit(1);
    }
    else if (argc==2) 
    {
        g_tempo = atoi(argv[1]);
        if (g_tempo<40 && g_tempo>200)
        {
            cerr<<"Tempo out of bounds!\n";
            printHelp();
            exit(1);
        }
        tempoChange();
    }
    
    // set up fluid synth stuff
    // TODO: error checking!!!!
    g_settings = new_fluid_settings(); 
    g_synth = new_fluid_synth( g_settings );
    g_metronome = new_fluid_synth( g_settings );  
    
    
    //fluid_player_t* player;
    //player = new_fluid_player(g_synth);
    //fluid_player_add(player, "backing.mid");
    //fluid_player_play(player);

    
    
    if (fluid_synth_sfload(g_synth, "piano.sf2", 1) == -1)
    {
        cerr << "Error loading sound font" << endl;
        exit(1);
    }
    
    if (fluid_synth_sfload(g_metronome, "drum.sf2", 1) == -1)
    {
        cerr << "Error loading sound font" << endl;
        exit(1);
    }
    
    
    // RtAudio config + init

    // pointer to RtAudio object
    RtMidiIn * midiin = NULL;    
	RtAudio *  audio = NULL;
    unsigned int bufferSize = 512;//g_sixteenth/100;

    // MIDI config + init
    try 
    {
        midiin = new RtMidiIn();
    }
    catch( RtError & err ) {
        err.printMessage();
       // goto cleanup;
    }
    
    // Check available ports.
    if ( midiin->getPortCount() == 0 )
    {
        std::cout << "No ports available!\n";
       // goto cleanup;
    }
    // use the first available port
    if ( midiin->getPortCount() > 2)
        midiin->openPort( 1 );
    else 
        midiin->openPort( 0 );

    // set midi callback
    midiin->setCallback( &midi_callback );

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

    // create the object
    try
    {
        audio = new RtAudio();
        cerr << "buffer size: " << bufferSize << endl;
    }
        catch( RtError & err ) {
        err.printMessage();
        exit(1);
    }

    if( audio->getDeviceCount() < 1 )
    {
        // nopes
        cout << "no audio devices found!" << endl;
        exit( 1 );
    }
        
    // let RtAudio print messages to stderr.
    audio->showWarnings( true );

    // set input and output parameters
    RtAudio::StreamParameters iParams, oParams;
    iParams.deviceId = audio->getDefaultInputDevice();
    iParams.nChannels = 1;
    iParams.firstChannel = 0;
    oParams.deviceId = audio->getDefaultOutputDevice();
    oParams.nChannels = 2;
    oParams.firstChannel = 0;
        
    // create stream options
    RtAudio::StreamOptions options;

    // set the callback and start stream
    try
    {
        audio->openStream( &oParams, &iParams, RTAUDIO_FLOAT32, MY_SRATE, &bufferSize, &audioCallback, NULL, &options);
        audio->startStream();
        
        // test RtAudio functionality for reporting latency.
        cout << "stream latency: " << audio->getStreamLatency() << " frames" << endl;
    }
    catch( RtError & err )
    {
        err.printMessage();
        goto cleanup;
    }

    // wait for user input
    cout << "Type CTRL+C to quit:";
    
    //initialize graphics
    gfxInit(&argc,argv);
    
    // if we get here, stop!
    try
    {
        audio->stopStream();
    }
    catch( RtError & err )
    {
        err.printMessage();
    }

    // Clean up
    cleanup:
    if(audio)
    {
        audio->closeStream();
        delete audio;
    }

    
    return 0;
}
예제 #16
0
int main( int argc, char *argv[] )
{
  RtMidiIn *midiin = 0;
  std::vector<unsigned char> message;
  int nBytes, i;
  double stamp;

  // Minimal command-line check.
  if ( argc > 2 ) usage();

  // RtMidiIn constructor
  try {
    midiin = new RtMidiIn();
  }
  catch ( RtError &error ) {
    error.printMessage();
    exit( EXIT_FAILURE );
  }

  // Check available ports vs. specified.
  unsigned int port = 0;
  unsigned int nPorts = midiin->getPortCount();
  if ( argc == 2 ) port = (unsigned int) atoi( argv[1] );
  if ( port >= nPorts ) {
    delete midiin;
    std::cout << "Invalid port specifier!\n";
    usage();
  }

  try {
    midiin->openPort( port );
  }
  catch ( RtError &error ) {
    error.printMessage();
    goto cleanup;
  }

  // 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 ) {
    stamp = midiin->getMessage( &message );
    nBytes = message.size();
    for ( i=0; i<nBytes; i++ )
      std::cout << "Byte " << i << " = " << (int)message[i] << ", ";
    if ( nBytes > 0 )
      std::cout << "stamp = " << stamp << std::endl;

    // Sleep for 10 milliseconds.
    SLEEP( 10 );
  }

  // Clean up
 cleanup:
  delete midiin;

  return 0;
}
예제 #17
0
Driver::tCollDeviceDescriptor DriverMIDI::enumerate()
{
  M_LOG("[DriverMIDI] enumerate");
  Driver::tCollDeviceDescriptor collDevices;
  std::string portNameIn, portNameOut;
  RtMidiIn midiIn;
  RtMidiOut midiOut;
  std::mutex mtxDevices;

  std::vector<std::future<void>> pendingFutures;

  unsigned nPortsOut = midiOut.getPortCount();
  unsigned nPortsIn = midiIn.getPortCount();

  for (unsigned int iOut = 0; iOut < nPortsOut; iOut++)
  {
    try
    {
      portNameOut = midiOut.getPortName(iOut);
      if (portNameOut != "")
      {
        for (unsigned int iIn = 0; iIn < nPortsIn; iIn++)
        {
          try
          {
            portNameIn = midiIn.getPortName(iIn);
            if (portNameIn == portNameOut)
            {
              M_LOG("[DriverMIDI] out: " << portNameOut << " ->" << iOut);
              M_LOG("[DriverMIDI] in: " << portNameIn << " ->" << iIn);
              auto f = std::async(
                std::launch::async, [this, &mtxDevices, &collDevices, iIn, iOut]() {
                  bool received = false;
                  bool timeout = false;
                  RtMidiIn _midiIn;
                  RtMidiOut _midiOut;
                  std::vector<unsigned char> recv;
                  std::vector<unsigned char> sysExIdentity = {0xF0, 0x7E, 0x00, 0x06, 0x01, 0xF7};

                  _midiIn.openPort(iIn);
                  _midiIn.ignoreTypes(false);

                  _midiOut.openPort(iOut);
                  _midiOut.sendMessage(&sysExIdentity);

                  auto start = std::chrono::system_clock::now();
                  while (!received && !timeout)
                  {
                    _midiIn.getMessage(&recv);
                    auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(
                      std::chrono::system_clock::now() - start);
                    if (recv.size() > 0)
                    {
                      if (recv[0] == 0xF0 && recv[1] == 0x7E && recv[3] == 0x06 && recv[4] == 0x02)
                      {
                        received = true;
                        unsigned vendorId = recv[5];
                        unsigned productId = (recv[6] << 8) | recv[7];
                        std::lock_guard<std::mutex> lock(mtxDevices);
                        collDevices.emplace_back(_midiIn.getPortName(iIn),
                          DeviceDescriptor::Type::MIDI,
                          vendorId,
                          productId,
                          "",
                          iIn,
                          iOut);
                        M_LOG("[DriverMIDI] found device: " << vendorId << ":" << productId);
                      }
                    }
                    else if (duration > std::chrono::milliseconds(500))
                    {
                      timeout = true;
                      M_LOG("[DriverMIDI] identity reply timeout on port #" << iOut);
                    }
                  }
                  _midiIn.closePort();
                  _midiOut.closePort();
                });
              pendingFutures.push_back(std::move(f));
            }
          }
          catch (RtMidiError& error)
          {
			std::string strError(error.getMessage());
            M_LOG("[DriverMIDI] RtMidiError: " << strError);
          }
        }
      }
    }
    catch (RtMidiError& error)
    {
	  std::string strError(error.getMessage());
      M_LOG("[DriverMIDI] RtMidiError: " << strError);
    }
  }
  return collDevices;
}
예제 #18
0
value rtmidi_in_getportcount(value obj) {
  RtMidiIn *midiin = (RtMidiIn *)(intptr_t)val_float(obj);
  return alloc_int(midiin->getPortCount());
}
예제 #19
0
int MidiDevice::getNumberOfInputDevices()
{
    RtMidiIn midiIn;
    return midiIn.getPortCount();
}
예제 #20
0
int main( int argc, char *argv[] )
{
	//Dekrispator init
	randomGen_init();
	Synth_Init();
	//end Dekrispator init
	
//	FILE* f = fopen("bla.txt","wb");
//	fclose(f);
	
  TickData data;
  RtAudio dac;
  int i;

  //if ( argc < 2 || argc > 6 ) usage();

  // If you want to change the default sample rate (set in Stk.h), do
  // it before instantiating any objects!  If the sample rate is
  // specified in the command line, it will override this setting.
  Stk::setSampleRate( 44100.0 );

	{
	 RtMidiIn *midiin = 0;
	 midiin = new RtMidiIn();
	unsigned int i = 0, nPorts = midiin->getPortCount();
	if ( nPorts == 0 ) {
		std::cout << "No input Midi ports available, just running demo mode." << std::endl;
		delete midiin;
		midiin = 0;
	} else
	{
		for ( i=0; i<nPorts; i++ ) {
			std::string portName = midiin->getPortName(i);
			std::cout << "  Input port #" << i << ": " << portName << '\n';
		}

		delete midiin;
		midiin = 0;
		
		for ( i=0; i<nPorts && i<MAX_MIDI_DEVICES; i++ ) {
			data.messagers[data.numMessagers++].startMidiInput(i);
		}

		
	}
	
	}
	
	
  // Parse the command-line arguments.
  unsigned int port = 2001;
  for ( i=1; i<argc; i++ ) {
    if ( !strcmp( argv[i], "-is" ) ) {
      if ( i+1 < argc && argv[i+1][0] != '-' ) port = atoi(argv[++i]);
		if (data.numMessagers<MAX_MIDI_DEVICES)
		{
		data.messagers[data.numMessagers++].startSocketInput( port );
		}
    }
    else if (!strcmp( argv[i], "-ip" ) )
	{
		if (data.numMessagers<MAX_MIDI_DEVICES)
		{
      data.messagers[data.numMessagers++].startStdInput();
		}
	}
    else if ( !strcmp( argv[i], "-s" ) && ( i+1 < argc ) && argv[i+1][0] != '-')
      Stk::setSampleRate( atoi(argv[++i]) );
    else
      usage();
  }

  // Allocate the dac here.
  RtAudioFormat format = ( sizeof(StkFloat) == 8 ) ? RTAUDIO_FLOAT64 : RTAUDIO_FLOAT32;
  RtAudio::StreamParameters parameters;
  parameters.deviceId = dac.getDefaultOutputDevice();
  parameters.nChannels = 2;
  unsigned int bufferFrames = RT_BUFFER_SIZE;
  try {
    dac.openStream( &parameters, NULL, format, (unsigned int)Stk::sampleRate(), &bufferFrames, &tick, (void *)&data );
  }
  catch ( RtAudioError& error ) {
    error.printMessage();
    goto cleanup;
  }

  data.reverbs[0].setT60( data.t60 );
  data.reverbs[0].setEffectMix( 0.5 );
  data.reverbs[1].setT60( 2.0 );
  data.reverbs[1].setEffectMix( 0.2 );

 
  data.rateScaler = 22050.0 / Stk::sampleRate();

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

  // If realtime output, set our callback function and start the dac.
  try {
    dac.startStream();
  }
  catch ( RtAudioError &error ) {
    error.printMessage();
    goto cleanup;
  }

  // Setup finished.
  while ( !done ) {
    // Periodically check "done" status.
    Stk::sleep( 50 );
  }

  // Shut down the output stream.
  try {
    dac.closeStream();
  }
  catch ( RtAudioError& error ) {
    error.printMessage();
  }

 cleanup:

  return 0;

}
예제 #21
0
파일: Delayed.cpp 프로젝트: hnney/Stanford
//-----------------------------------------------------------------------------
// name: main()
// desc: entry point
//-----------------------------------------------------------------------------
int main( int argc, char ** argv )
{

 RtMidiIn *midiin = new RtMidiIn();

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

  midiin->openPort( 0 );

  // Set our callback function.  This should be done immediately after
  // opening the port to avoid having incoming messages written to the
  // queue.
  midiin->setCallback( &mycallback );

  // 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);


    // instantiate RtAudio object
    RtAudio audio;
    // variables
    unsigned int bufferBytes = 0;
    // frame size
    unsigned int numFrames = 512;
    
    // check for audio devices
    if( audio.getDeviceCount() < 1 )
    {
        // nopes
        cout << "no audio devices found!" << endl;
        exit( 1 );
    }
    
    // let RtAudio print messages to stderr.
    audio.showWarnings( true );
    
    // set input and output parameters
    RtAudio::StreamParameters iParams, oParams;
    iParams.deviceId = audio.getDefaultInputDevice();
    iParams.nChannels = MY_CHANNELS;
    iParams.firstChannel = 0;
    oParams.deviceId = audio.getDefaultOutputDevice();
    oParams.nChannels = MY_CHANNELS;
    oParams.firstChannel = 0;
    
    // create stream options
    RtAudio::StreamOptions options;
    
    // go for it
    try {
        // open a stream
        audio.openStream( &oParams, &iParams, MY_FORMAT, MY_SRATE, &numFrames, &callme, NULL, &options );
    }
    catch( RtError& e )
    {
        // error!
        cout << e.getMessage() << endl;
        exit( 1 );
    }
    
    // compute
    bufferBytes = numFrames * MY_CHANNELS * sizeof(SAMPLE);
    
    // test RtAudio functionality for reporting latency.
    cout << "stream latency: " << audio.getStreamLatency() << " frames" << endl;
    
    for( int i = 0; i < MY_NUMSTRINGS; i++ )
    {
        // intialize
        g_ks[i].init( MY_SRATE*2, 440, MY_SRATE );
	
    }
    
    // go for it
    try {
        // start stream
        audio.startStream();
	char input;
        std::cout << "Press any key to quit ";
	std::cin.get(input);
        
        // stop the stream.
        audio.stopStream();
    }
    catch( RtError& e )
    {
        // print error message
        cout << e.getMessage() << endl;
        goto cleanup;
    }
    
cleanup:
    // close if open
    if( audio.isStreamOpen() )
        audio.closeStream();
    delete midiin;
    
    // done
    return 0;
}
예제 #22
0
파일: midiprobe.cpp 프로젝트: aalex/stk
int main()
{
  RtMidiIn  *midiin = 0;
  RtMidiOut *midiout = 0;

  // RtMidiIn constructor
  try {
    midiin = new RtMidiIn();
  }
  catch ( RtError &error ) {
    error.printMessage();
    exit( EXIT_FAILURE );
  }

  // Check inputs.
  unsigned int nPorts = midiin->getPortCount();
  std::cout << "\nThere are " << nPorts << " MIDI input sources available.\n";
  std::string portName;
  unsigned int i;
  for ( i=0; i<nPorts; i++ ) {
    try {
      portName = midiin->getPortName(i);
    }
    catch ( RtError &error ) {
      error.printMessage();
      goto cleanup;
    }
    std::cout << "  Input Port #" << i+1 << ": " << portName << '\n';
  }

  // RtMidiOut constructor
  try {
    midiout = new RtMidiOut();
  }
  catch ( RtError &error ) {
    error.printMessage();
    exit( EXIT_FAILURE );
  }

  // Check outputs.
  nPorts = midiout->getPortCount();
  std::cout << "\nThere are " << nPorts << " MIDI output ports available.\n";
  for ( i=0; i<nPorts; i++ ) {
    try {
      portName = midiout->getPortName(i);
    }
    catch ( RtError &error ) {
      error.printMessage();
      goto cleanup;
    }
    std::cout << "  Output Port #" << i+1 << ": " << portName << '\n';
  }
  std::cout << '\n';

  // Clean up
 cleanup:
  delete midiin;
  delete midiout;

  return 0;
}