Ejemplo n.º 1
0
t_CKBOOL MidiOutManager::open( MidiOut * mout, const std::string & name )
{
    t_CKINT device_num = -1;
    
    try 
    {
        RtMidiOut * rtmout = new RtMidiOut;
        
        t_CKINT count = rtmout->getPortCount();
        for(t_CKINT i = 0; i < count; i++)
        {
            std::string port_name = rtmout->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 = rtmout->getPortName( i );
                if( port_name.find( name ) != std::string::npos )
                {
                    device_num = i;
                    break;
                }
            }
        }
    }
    catch( RtMidiError & err )
    {
        if( !mout->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( mout, device_num );
    
    return result;
}
Ejemplo n.º 2
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;
}
Ejemplo n.º 3
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;
}
Ejemplo n.º 4
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;
}
Ejemplo n.º 5
0
int main(int argc, char* argv[])
{


    char filename[] = "doom-e1m1.mid";
      RtMidiOut *midiout = new RtMidiOut();
    string portName;
    
    nPorts = midiout->getPortCount();
 
    if(argc < 2)    {
        if ( nPorts == 0 )     cout << "No ports available!\n";
        for ( unsigned int i=0; i<nPorts; i++ ) {
            try { portName = midiout->getPortName(i);    }
             catch (RtError &error) {error.printMessage(); }
            cout << "  Output Port #" << i+1 << ": " << portName << '\n';
        }
    }else{
        int port = atoi(argv[1]);
          //midiout->openPort( port );

        cout << "Opening midi" << endl;    
        char *filef = argv[2];
        if(argc == 3)
            parser.Open(filef);
        else
            parser.Open(filename);
    
        tickspersecond = ( (parser.bpm / 30.0) * ( parser.tpb));
        cout << " Ticks per second: " << tickspersecond << endl;
        
        (void) signal(SIGINT, finish);
        tickcount = 0;

        Sequencer sequencers[parser.numtracks];
        SequencerRunning = true;
        for(int i=0;i<parser.numtracks;i++)    {
            sequencers[i].StartSequencer(i, &parser.mididata.tracks[i], port);
            sf::Sleep(0.01f);
        }
        sf::Sleep(1);
        timer.Reset();
        while(run)    {
            timecount = timer.GetElapsedTime();
            tickcount += timecount * tickspersecond;
            timer.Reset();
            //sf::Sleep(0.0001f);
        }
    }
    delete midiout;    
    finish(0);
    return 0;
}
Ejemplo n.º 6
0
    /**
     * 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);
                }
            }
        }
    }
Ejemplo n.º 7
0
QList<MidiDevice::Description> MidiDevice::enumerateOutputDevices()
{
    RtMidiOut midiOut;

    QList<MidiDevice::Description> devs;
    int n = midiOut.getPortCount();
    for (int i = 0; i < n; i++) {
        Description desc;
        desc.number = i;
        desc.type = Type_Output;
        try {
           desc.name = QString::fromStdString(midiOut.getPortName(i));
            devs.append(desc);
        } catch (RtMidiError &err) {
            Q_UNUSED(err);
        }
    }
    return devs;
    return devs;
}
Ejemplo n.º 8
0
void ofApp::midiSetup(){
	/////////////// MIDI SETUP ////////////////////////////////////////////////////////////////////////////////
		
	// Alterar ofxRtMidiOut.cpp ??
	//midiOut.listPorts(); // via instance
	int portaEscolhida = 0;

	static RtMidiOut s_midiOut;
	ofLogVerbose("MIDI") << "ofxMidiOut: " << s_midiOut.getPortCount() << " ports available";
	for(unsigned int i = 0; i < s_midiOut.getPortCount(); ++i){
		string PortName = s_midiOut.getPortName(i);
		PortName.pop_back();
		if (PortName.compare(0,3,"MMC")==0){ofLogVerbose("MIDI") << "PORTA MMC: " << i;portaEscolhida = i;};

		ofLogVerbose("MIDI") << "ofxMidiOut: " <<  i << ": " << PortName;
	}

	// connect
	if (midiOut.openPort(portaEscolhida))	// by number // Gera LOG
	{
		ofLogVerbose("MIDI") << "MIDI open: true"; 
	} else {
		ofLogVerbose("MIDI") << "MIDI open: false"; 
		ofApp::exit();
	}
	//midiOut.openPort("1");	// by name
	//midiOut.openVirtualPort("ofxMidiOut");		// open a virtual port
	
	for (int ii=0; ii<8; ii++){
		vol[ii].enable=1;
		vol[ii].test=0;
		vol[ii].volume=0;
	}
	vol2_inverse = 0;

	ofLogVerbose("SETUP") << "MIDI inicializado";
	/////////////// MIDI SETUP ////////////////////////////////////////////////////////////////////////////////

}
Ejemplo n.º 9
0
//-----------------------------------------------------------------------------
// name: probeMidiOut()
// desc: ...
//-----------------------------------------------------------------------------
void probeMidiOut()
{
    RtMidiOut * mout =  NULL;

    try {
        mout = new RtMidiOut;
    } catch( RtError & err ) {
        EM_error2b( 0, "%s", err.getMessageString() );
        return;
    }

    // get num
    t_CKUINT num = mout->getPortCount();
    EM_error2b( 0, "------( chuck -- %i MIDI outputs )-----", num );
    std::string s;
    for( t_CKUINT i = 0; i < num; i++ )
    {
        try { s = mout->getPortName( i ); }
        catch( RtError & err )
        { err.printMessage(); return; }
        EM_error2b( 0, "    [%i] : \"%s\"", i, s.c_str() );
    }
}
Ejemplo n.º 10
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;
}
Ejemplo n.º 11
0
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;
}
Ejemplo n.º 12
0
value rtmidi_out_getportname(value obj, value port) {
  RtMidiOut *midiout = (RtMidiOut *)(intptr_t)val_float(obj);
  return alloc_string(midiout->getPortName(val_int(port)).c_str());
}