Esempio n. 1
0
void rtmidi_in_cancel_callback (RtMidiInPtr device)
{
#if defined(__NO_EXCEPTIONS__)
    RtMidiIn* rtm = (RtMidiIn*) device->ptr;
    rtm->resetError();
    rtm->cancelCallback ();
    if (rtm->isError()) {
        device->ok  = false;
        device->msg = rtm->getError().what ();
    }
    else {
        delete (CallbackProxyUserData*) device->data;
        device->data = 0;
    }
#else
    try {
        ((RtMidiIn*) device->ptr)->cancelCallback ();
        delete (CallbackProxyUserData*) device->data;
        device->data = 0;
    } catch (const RtMidiError & err) {
        device->ok  = false;
        device->msg = err.what ();
    }
#endif
}
Esempio 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;
}
Esempio n. 3
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;
}
	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;
	}
Esempio n. 5
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;
}
Esempio n. 6
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();
    }
}
Esempio n. 7
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!";
                }
            }
        }
    }
}
Esempio n. 8
0
t_CKBOOL MidiInManager::open( MidiIn * min, t_CKINT device_num )
{
    // see if port not already open
    if( device_num >= (t_CKINT)the_mins.capacity() || !the_mins[device_num] )
    {
        // allocate the buffer
        CBufferAdvance * cbuf = new CBufferAdvance;
        if( !cbuf->initialize( BUFFER_SIZE, sizeof(MidiMsg) ) )
        {
            if( !min->m_suppress_output )
                EM_error2( 0, "MidiIn: couldn't allocate CBuffer for port %i...", device_num );
            delete cbuf;
            return FALSE;
        }

        // allocate
        RtMidiIn * rtmin = new RtMidiIn;
        try {
            rtmin->openPort( device_num );
            rtmin->setCallback( cb_midi_input, cbuf );
        } catch( RtError & err ) {
            if( !min->m_suppress_output )
            {
                // print it
                EM_error2( 0, "MidiIn: couldn't open MIDI port %i...", device_num );
                err.getMessage();
                // const char * e = err.getMessage().c_str();
                // EM_error2( 0, "...(%s)", err.getMessage().c_str() );
            }
            delete cbuf;
            return FALSE;
        }

        // resize?
        if( device_num >= (t_CKINT)the_mins.capacity() )
        {
            t_CKINT size = the_mins.capacity() * 2;
            if( device_num >= size ) size = device_num + 1;
            the_mins.resize( size );
            the_bufs.resize( size );
        }

        // put cbuf and rtmin in vector for future generations
        the_mins[device_num] = rtmin;
        the_bufs[device_num] = cbuf;
    }

    // set min
    min->min = the_mins[device_num];
    // found
    min->m_buffer = the_bufs[device_num];
    // get an index into your (you are min here) own buffer, 
    // and a free ticket to your own workshop
    min->m_read_index = min->m_buffer->join( (Chuck_Event *)min->SELF );
    min->m_device_num = (t_CKUINT)device_num;

    // done
    return TRUE;
}
Esempio n. 9
0
bool MidiInRt::openVirtual()
{
    RtMidiIn *midiin = lazyInstance();
    m_midiin->closePort();
    m_errorSignaled = false;
    midiin->openVirtualPort(defaultPortName().toStdString());
    return !m_errorSignaled;
}
Esempio n. 10
0
bool MidiInRt::open(unsigned port)
{
    RtMidiIn *midiin = lazyInstance();
    m_midiin->closePort();
    m_errorSignaled = false;
    midiin->openPort(port, defaultPortName().toStdString());
    return !m_errorSignaled;
}
Esempio n. 11
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;
}
Esempio n. 12
0
value rtmidi_in_cancelcallback(value obj) {
  RtMidiIn *midiin = (RtMidiIn *)(intptr_t)val_float(obj);
  midiin->cancelCallback();
  if (callback_root) {
    delete callback_root;
    callback_root = NULL;
  }
  return alloc_null();
}
Esempio n. 13
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;
}
// ******************************************
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;
}
Esempio n. 15
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;
}
void midiInfo()
{
    cout << "MIDI INFO port = " << portopt << endl;

    std::vector<unsigned char> message;
    double stamp;
    int nBytes;
    int i;

#ifdef MARSYAS_MIDIIO  
    RtMidiIn *midiin = NULL;  
    try {
        midiin = new RtMidiIn();
    }
    catch (RtError3 &error) {
        error.printMessage();
        exit(1);
    }


    try {
        midiin->openPort(portopt);
    }
    catch (RtError3 &error) {
        error.printMessage();
        exit(1);

    }

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


    while(1) 

    {  

        stamp = midiin->getMessage( &message );
        nBytes = message.size();
        if (nBytes >0)
        {

            for ( i=0; i<nBytes; i++ )
                std::cout << "Byte " << i << " = " << (int)message[i] << ", ";
            if ( nBytes > 0 )
                std::cout << "stamp = " << stamp << '\n';
        }

        usleep(10);

    }

#endif

}
Esempio n. 17
0
value rtmidi_in_getmessage(value obj) {
  RtMidiIn *midiin = (RtMidiIn *)(intptr_t)val_float(obj);
  std::vector<unsigned char> message;
  double stamp = midiin->getMessage(&message);
  // ignore stamp for now
  value ret = alloc_array(message.size());
  for (int i = 0; i < message.size(); ++i) {
    val_array_set_i(ret, i, alloc_int(message[i]));
  }
  return ret;
}
Esempio n. 18
0
RtMidiIn *MidiInRt::lazyInstance()
{
    RtMidiIn *midiin = m_midiin;
    if(!midiin) {
        unsigned bufferSize = 1024;
        midiin = m_midiin = new RtMidiIn(
            RtMidi::UNSPECIFIED, defaultClientName().toStdString(), bufferSize);
        midiin->setCallback(&onReceive, this);
        midiin->setErrorCallback(&onError, this);
    }
    return midiin;
}
Esempio n. 19
0
bool MidiInRt::canOpenVirtual()
{
    RtMidiIn *midiin = lazyInstance();
    switch(midiin->getCurrentApi())
    {
    default:
        return true;
    case RtMidi::WINDOWS_MM:
    case RtMidi::RTMIDI_DUMMY:
        return false;
    }
}
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);
        }
    }
}
Esempio n. 21
0
void *MIDIReadThread(FREContext ctx)
{
	printf("MIDI Start read thread\n");
	std::vector<unsigned char> message;
	int nBytes;
	double stamp;

	while(!exitRunThread)
	{
		//printf("Check thread, %i devices\n",openMidiIn.size());
		for(unsigned int di=0;di<openMidiIn.size();di++)
		{
			
			RtMidiIn * in = openMidiIn[di];

			while(true)
			{
				stamp = in->getMessage(&message );
				nBytes = message.size();

				if(nBytes == 3) //complete midi message
				{
			
					midiMessage m;
					m.device = in;
					m.stamp = stamp;
					m.status = message[0];
					//printf("Status %i from %i\n",m.status,in);
					m.data1 = message[1];
					m.data2 = message[2];

					messageQueue.push_back(m);

					FREDispatchStatusEventAsync(ctx,(const uint8_t *)"data",(const uint8_t *)"none");
					
				}else if(nBytes == 0) break;
			}

		}

		// Sleep for 10 milliseconds ... platform-dependent.
		Sleep( 1 );
	   //FREDispatchStatusEventAsync(ctx,(const uint8_t *)"data",(const uint8_t *)"myo");
	}

	printf("Exit Run Thread !\n");

	return 0;
}
Esempio n. 22
0
double rtmidi_in_get_message (RtMidiInPtr device, 
                              unsigned char *message,
                              size_t *size)
{
#if defined(__NO_EXCEPTIONS__)
    // FIXME: use allocator to achieve efficient buffering
    std::vector<unsigned char> v;
    RtMidiIn* rtm = (RtMidiIn*) device->ptr;
    rtm->resetError();
    double ret = rtm->getMessage (&v);
    if (rtm->isError()) {
        device->ok  = false;
        device->msg = rtm->getError().what ();
        return -1;
    }

    if (v.size () > 0 && v.size() <= *size) {
        memcpy (message, v.data (), (int) v.size ());
    }

    *size = v.size();
    return ret;
#else
    try {
        // FIXME: use allocator to achieve efficient buffering
        std::vector<unsigned char> v;
        double ret = ((RtMidiIn*) device->ptr)->getMessage (&v);

        if (v.size () > 0 && v.size() <= *size) {
            memcpy (message, v.data (), (int) v.size ());
        }

        *size = v.size();
        return ret;
    } 
    catch (const RtMidiError & err) {
        device->ok  = false;
        device->msg = err.what ();
        return -1;
    }
    catch (...) {
        device->ok  = false;
        device->msg = "Unknown error";
        return -1;
    }
#endif
}
Esempio n. 23
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);
                }
            }
        }
    }
Esempio n. 24
0
  void Cursynth::setupMidi() {
    RtMidiIn* midi_in = new RtMidiIn();
    if (midi_in->getPortCount() <= 0) {
      std::cout << "No midi devices found.\n";
    }

    // Setup MIDI callbacks for every MIDI device.
    // TODO: Have a menu for only enabling some MIDI devices.
    for (unsigned int i = 0; i < midi_in->getPortCount(); ++i) {
      RtMidiIn* device = new RtMidiIn();
      device->openPort(i);
      device->setCallback(&midiCallback, (void*)this);
      midi_ins_.push_back(device);
    }

    delete midi_in;
  }
Esempio n. 25
0
static VALUE rtMidiIn_connect(VALUE self, VALUE port)
{
	RtMidiIn *device;
	Data_Get_Struct(self, RtMidiIn, device);
	
	try {
		device->openPort(NUM2INT(port));
		device->ignoreTypes( false, false, false );
	}
	catch(RtError &error)
	{
		rb_warn("could not open port");
		return Qfalse;
	}
	
	return Qtrue;
}
Esempio n. 26
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;
}
Esempio n. 27
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;
}
Esempio n. 28
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;
    }
Esempio n. 29
0
static VALUE rtMidiIn_getData(VALUE self)
{
	RtMidiIn *device;
	Data_Get_Struct(self, RtMidiIn, device);

	std::vector<unsigned char> message;
	VALUE messages = rb_ary_new();
	try {
		double stamp = device->getMessage(&message);
		for(int x = 0; x < message.size(); x++)
		{
			rb_ary_push(messages, INT2FIX((int)message[x]));
		}
	}
	catch(RtError &error)
	{
		rb_warn("getData failed");
	}
	
	return messages;
}
Esempio n. 30
0
	FREObject closeInputDevice(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[])
	{
		int pointer = 0;
		FREGetObjectAsInt32(argv[0],&pointer);
		
		try
		{
			RtMidiIn *in = (RtMidiIn *)pointer;
			if(in->isPortOpen()) in->closePort();
			removeDeviceIn(in);
			delete in;
			//printf("Num open midi devices %i\n",openMidiIn.size());
		}catch(std::exception e)
		{
			printf("Error closing input device.\n");
		}

		FREObject result;
		FRENewObjectFromBool(true,&result);
		return result;
	}