Mixxx

/home/maxime/Projets/Mixxx/1.10/mixxx/src/midi/portmidienumerator.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           portmidienumerator.cpp
00003                     PortMIDI Device Enumerator Class
00004                     --------------------------------
00005     begin                : Thu Feb 25 2010
00006     copyright            : (C) 2010 Sean M. Pappalardo
00007     email                : spappalardo@mixxx.org
00008 
00009 ***************************************************************************/
00010 
00011 /***************************************************************************
00012 *                                                                         *
00013 *   This program is free software; you can redistribute it and/or modify  *
00014 *   it under the terms of the GNU General Public License as published by  *
00015 *   the Free Software Foundation; either version 2 of the License, or     *
00016 *   (at your option) any later version.                                   *
00017 *                                                                         *
00018 ***************************************************************************/
00019 
00020 #include "midideviceportmidi.h"
00021 #include "portmidienumerator.h"
00022 
00023 PortMidiEnumerator::PortMidiEnumerator() : MidiDeviceEnumerator() {
00024 
00025 }
00026 
00027 PortMidiEnumerator::~PortMidiEnumerator() {
00028     qDebug() << "Deleting PortMIDI devices...";
00029     QListIterator<MidiDevice*> dev_it(m_devices);
00030     while (dev_it.hasNext()) {
00031         delete dev_it.next();
00032     }
00033 }
00034 
00040 QList<MidiDevice*> PortMidiEnumerator::queryDevices() {
00041     qDebug() << "Scanning PortMIDI devices:";
00042 
00043     int iNumDevices = Pm_CountDevices();
00044     
00045     QListIterator<MidiDevice*> dev_it(m_devices);
00046     while (dev_it.hasNext()) {
00047         delete dev_it.next();
00048     }
00049     
00050     m_devices.clear();
00051     
00052     const PmDeviceInfo *deviceInfo, *inputDeviceInfo, *outputDeviceInfo;
00053     int inputDevIndex, outputDevIndex;
00054     QMap<int,QString> unassignedOutputDevices;
00055     
00056     // Build a complete list of output devices for later pairing
00057     for (int i = 0; i < iNumDevices; i++)
00058     {
00059         deviceInfo = Pm_GetDeviceInfo(i);
00060         if (deviceInfo->output) {
00061             qDebug() << " Found output device" << "#" << i << deviceInfo->name;
00062             QString deviceName = deviceInfo->name;
00063             unassignedOutputDevices[i] = deviceName;
00064         }
00065     }
00066 
00067     // Search for input devices and pair them with output devices if applicable
00068     for (int i = 0; i < iNumDevices; i++)
00069     {
00070         deviceInfo = Pm_GetDeviceInfo(i);
00071 
00072         //If we found an input device
00073         if (deviceInfo->input)
00074         {
00075             qDebug() << " Found input device" << "#" << i << deviceInfo->name;
00076             inputDeviceInfo = deviceInfo;
00077             inputDevIndex = i;
00078 
00079             //Reset our output device variables before we look for one incase we find none.
00080             outputDeviceInfo = NULL;
00081             outputDevIndex = -1;
00082 
00083             //Search for a corresponding output device
00084             QMapIterator<int, QString> j(unassignedOutputDevices);
00085             while (j.hasNext()) {
00086                 j.next();
00087 
00088                 QString deviceName = inputDeviceInfo->name;
00089                 QString outputName = QString(j.value());
00090 
00091                 //Some device drivers prepend "To" and "From" to the names
00092                 //of their MIDI ports. If the output and input device names
00093                 //don't match, let's try trimming those words from the start,
00094                 //and seeing if they then match.
00095                 if (outputName != deviceName) {
00096                     // Ignore "From" text in the device names
00097                     if (deviceName.indexOf("from",0,Qt::CaseInsensitive)!=-1)
00098                         deviceName = deviceName.right(deviceName.length()-4);
00099                     // Ignore "To" text in the device names
00100                     if (outputName.indexOf("to",0,Qt::CaseInsensitive)!=-1)
00101                         outputName = outputName.right(outputName.length()-2);
00102                 }
00103 
00104                 if (outputName == deviceName) {
00105                     outputDevIndex = j.key();
00106                     outputDeviceInfo = Pm_GetDeviceInfo(outputDevIndex);
00107 
00108                     unassignedOutputDevices.remove(outputDevIndex);
00109 
00110                     qDebug() << "    Linking to output device #" << outputDevIndex << outputName;
00111                     break;
00112                 }
00113             }
00114 
00115             //So at this point in the code, we either have an input-only MIDI device (outputDeviceInfo == NULL)
00116             //or we've found a matching output MIDI device (outputDeviceInfo != NULL).
00117             
00118             //.... so create our (aggregate) MIDI device!            
00119             MidiDevicePortMidi *currentDevice = new MidiDevicePortMidi(/*new MidiControlProcessor(NULL)*/ NULL,
00120                                                                           inputDeviceInfo,
00121                                                                           outputDeviceInfo,
00122                                                                           inputDevIndex,
00123                                                                           outputDevIndex); 
00124             m_devices.push_back((MidiDevice*)currentDevice);
00125             
00126         }
00127 
00128 //         if (deviceInfo->input || deviceInfo->output)
00129 //         {
00130 //             MidiDevicePortMidi *currentDevice = new MidiDevicePortMidi(new MidiControlProcessor(NULL), deviceInfo, i);
00131 //             m_devices.push_back((MidiDevice*)currentDevice);
00132 //         }
00133     }
00134     return m_devices;
00135 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines