예제 #1
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;
}
예제 #2
0
bool MidiInputController::enablePort(int portNumber) {
    if(portNumber < 0)
        return false;

    try {
        MidiInputCallback *callback = new MidiInputCallback;
        RtMidiIn *rtMidiIn = new RtMidiIn;

        cout << "Enabling MIDI port " << portNumber << " (" << rtMidiIn->getPortName(portNumber) << ")\n";

        rtMidiIn->openPort(portNumber);				// Open the port
        rtMidiIn->ignoreTypes(true, true, true);	// Ignore sysex, timing, active sensing

        callback->controller = this;
        callback->midiIn = rtMidiIn;
        callback->inputNumber = portNumber;

        rtMidiIn->setCallback(MidiInputController::rtMidiStaticCallback, callback);

        activePorts_[portNumber] = callback;
    }
    catch(...) {
        return false;
    }

    return true;
}
예제 #3
0
void RtMidiDriver::start(const QList<bool> &deviceStatuses){
    setInputDevicesStatus(deviceStatuses);

    if(!hasInputDevices()){
        return;
    }
    stop();

    for(int deviceIndex=0; deviceIndex < inputDevicesEnabledStatuses.size(); deviceIndex++) {
        if(deviceIndex < midiStreams.size()){
            RtMidiIn* stream = midiStreams.at(deviceIndex);
            if(stream && inputDevicesEnabledStatuses.at(deviceIndex)){//device is globally enabled?
                if(!stream->isPortOpen()){
                    try{
                        qCInfo(jtMidi) << "Starting MIDI in " << QString::fromStdString(stream->getPortName(deviceIndex));
                        stream->openPort(deviceIndex);
                    }
                    catch(RtMidiError e){
                        qCCritical(jtMidi) << "Error opening midi port " << QString::fromStdString(e.getMessage());
                    }
                }
                else{
                    qCCritical(jtMidi) << "Port " << QString::fromStdString(stream->getPortName(deviceIndex)) << " already opened!";
                }
            }
        }
    }
}
예제 #4
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;
}
예제 #5
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;
}
예제 #6
0
	FREObject openInputDevice(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[])
	{
		
		int index = 0;
		FREGetObjectAsInt32(argv[0],&index);

		//printf("Native MIDI :: open input device %i\n",index);
		
		int pointer = -1;
		try {
			RtMidiIn* in = new RtMidiIn();
			in->openPort(index);
			openMidiIn.push_back(in);

			pointer = (int)in;
			printf("Open midi pointer : %i (%s), num open devices :  %i\n",pointer,in->getPortName(index).c_str(),openMidiIn.size());
			// Don't ignore sysex, timing, or active sensing messages.
			midiin->ignoreTypes( false, false, false );

		}
		catch ( RtMidiError &error ) {
			error.printMessage();
		}		
		
		FREObject result;
		FRENewObjectFromInt32(pointer,&result);
		return result;
	}
예제 #7
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();
    }
}
예제 #8
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;
}
예제 #9
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;
}
예제 #10
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);
                }
            }
        }
    }
예제 #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
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;
}
예제 #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
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;
}
예제 #15
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;

}
예제 #16
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;
}
예제 #17
0
value rtmidi_in_getportname(value obj, value port) {
  RtMidiIn *midiin = (RtMidiIn *)(intptr_t)val_float(obj);
  return alloc_string(midiin->getPortName(val_int(port)).c_str());
}