Exemplo n.º 1
0
TEST_F(PortMidiEnumeratorTest, InputOutputPortsLinked) {
    // Identical device names should link.
    ASSERT_TRUE(shouldLinkInputToOutput(
        "Vestax VCI-100",
        "Vestax VCI-100"));

    // Different device names should not link.
    ASSERT_FALSE(shouldLinkInputToOutput(
        "Vestax VCI-100",
        "Vestax VCI-300"));

    // Ports with From or To in them that are otherwise equal should link.
    ASSERT_TRUE(shouldLinkInputToOutput(
        "From: Vestax VCI-100",
        "To: Vestax VCI-100"));

    // Ports with From or To in them that are otherwise equal should link. Case
    // does not matter.
    ASSERT_TRUE(shouldLinkInputToOutput(
        "frOm: Vestax VCI-100",
        "tO: Vestax VCI-100"));

    // Ports that match the pattern "$DEVICE MIDI $INSTANCE ..." should link.

    ASSERT_TRUE(shouldLinkInputToOutput(
        "Vestax VCI-100 MIDI 1",
        "Vestax VCI-100 MIDI 1"));

    // Stuff after $INSTANCE doesn't matter.
    ASSERT_TRUE(shouldLinkInputToOutput(
        "Vestax VCI-100 MIDI 1 OtherJunk",
        "Vestax VCI-100 MIDI 1 123 Doesn't Matter"));

    // Name is case-insensitive.
    ASSERT_TRUE(shouldLinkInputToOutput(
        "Vestax VCI-100 MIDI 1 OtherJunk",
        "VesTaX VCI-100 MIDI 1 123 Doesn't Matter"));

    // Different $INSTANCE matters.
    ASSERT_FALSE(shouldLinkInputToOutput(
        "Vestax VCI-100 MIDI 1 OtherJunk",
        "Vestax VCI-100 MIDI 2 123 Doesn't Matter"));

    // Different $INSTANCE with no trailing stuff matters.
    ASSERT_FALSE(shouldLinkInputToOutput(
        "Vestax VCI-100 MIDI 1",
        "Vestax VCI-100 MIDI 12"));

    // Extra stuff only on one doesn't matter.
    ASSERT_TRUE(shouldLinkInputToOutput(
        "Vestax VCI-100 MIDI 12",
        "Vestax VCI-100 MIDI 12 123 Something Else"));

    // Bug 1033375 - contain string 'to' in device name, strip
    // ' input port ' and ' output port ' from strings
    ASSERT_TRUE(shouldLinkInputToOutput(
        "Traktor Kontrol X1 - 1 MIDI input port 0",
        "Traktor Kontrol X1 - 1 MIDI output port 0"));

    // Bug 1033375 - contain string 'to' in device name, strip
    // ' input port ' and ' output port ' from strings not done
    // because of invalid strings
    ASSERT_TRUE(shouldLinkInputToOutput(
        "Traktor Kontrol X1 - 1 MIDI input 0",
        "Traktor Kontrol X1 - 1 MIDI output 0"));

    // Strip ' input ' from inputs and ' output ' from outputs.

    // Lemur Daemon shows 8 port pairs named like: 'Daemon Input 1' and 'Daemon
    // Output 2'
    ASSERT_TRUE(shouldLinkInputToOutput("Daemon Input 1", "Daemon Output 1"));
    ASSERT_TRUE(shouldLinkInputToOutput("Daemon Input 2", "Daemon Output 2"));
    ASSERT_TRUE(shouldLinkInputToOutput("Daemon InPuT 2", "Daemon OuTpuT 2"));
    ASSERT_TRUE(shouldLinkInputToOutput("Daemon Input 1234", "Daemon Output 1234"));
    ASSERT_TRUE(shouldLinkInputToOutput("Daemon Input ", "Daemon Output "));
    ASSERT_TRUE(shouldLinkInputToOutput("Daemon Input 1", "daemon output 1"));
    ASSERT_TRUE(shouldLinkInputToOutput("Daemon Input 1", "Daemon Input 1"));
    ASSERT_FALSE(shouldLinkInputToOutput("Daemon Input", "Daemon Output"));
    ASSERT_FALSE(shouldLinkInputToOutput("Daemon Input 1234", "Daemon Output 5678"));
    ASSERT_FALSE(shouldLinkInputToOutput("Daemon Input 1", "Daemon Output 1 "));
    ASSERT_FALSE(shouldLinkInputToOutput("Daemon Input 1", "Daemon Output 11"));
    ASSERT_FALSE(shouldLinkInputToOutput("Daemon Input 2", "Daemon Output 12"));

    // Dangling numerals after the device name but before MIDI are fine.
    ASSERT_TRUE(shouldLinkInputToOutput(
        "Vestax VCI-100 2 MIDI 12",
        "Vestax VCI-100 2 MIDI 12 123 Something Else"));

    // Different $DEVICE matters.
    ASSERT_FALSE(shouldLinkInputToOutput(
        "Vestax VCI-100 MIDI 1",
        "Vestax VCI-300 MIDI 1"));

    // Non-numeral extra stuff following a lone numeral after the device name
    // doesn't matter.
    ASSERT_TRUE(shouldLinkInputToOutput(
        "nanoKONTROL2 1 CTRL",
        "nanoKONTROL2 1 SLIDER/KNOB"));

    // Extra stuff with a numeral following a lone numeral after the device name
    // doesn't get linked.
    ASSERT_FALSE(shouldLinkInputToOutput(
        "nanoKONTROL2 1 1 CTRL",
        "nanoKONTROL2 1 SLIDER/KNOB"));

    // If the device name has a numeral dangling off of it we should not get
    // confused by that.
    ASSERT_FALSE(shouldLinkInputToOutput(
        "nanoKONTROL 2 1 CTRL",
        "nanoKONTROL 2 3 SLIDER/KNOB"));

}
Exemplo n.º 2
0
/** Enumerate the MIDI devices
  * This method needs a bit of intelligence because PortMidi (and the underlying MIDI APIs) like to split
  * output and input into separate devices. Eg. PortMidi would tell us the Hercules is two half-duplex devices.
  * To help simplify a lot of code, we're going to aggregate these two streams into a single full-duplex device.
  */
QList<Controller*> PortMidiEnumerator::queryDevices() {
    // Portmidi does not support hotplug: if any devices were already
    // loaded, return current list
    if (m_devices.length()>0)
        return m_devices;

    int iNumDevices = Pm_CountDevices();

    QListIterator<Controller*> dev_it(m_devices);
    while (dev_it.hasNext()) {
        delete dev_it.next();
    }

    m_devices.clear();

    const PmDeviceInfo* inputDeviceInfo = NULL;
    const PmDeviceInfo* outputDeviceInfo = NULL;
    int inputDevIndex = -1;
    int outputDevIndex = -1;
    QMap<int, QString> unassignedOutputDevices;

    // Build a complete list of output devices for later pairing
    for (int i = 0; i < iNumDevices; i++) {
        const PmDeviceInfo* deviceInfo = Pm_GetDeviceInfo(i);
        if (shouldBlacklistDevice(deviceInfo)) {
            continue;
        }
        if (deviceInfo->output) {
            qDebug() << " Found output device" << "#" << i << deviceInfo->name;
            QString deviceName = deviceInfo->name;
            unassignedOutputDevices[i] = deviceName;
        }
    }

    // Search for input devices and pair them with output devices if applicable
    for (int i = 0; i < iNumDevices; i++) {
        const PmDeviceInfo* deviceInfo = Pm_GetDeviceInfo(i);
        if (shouldBlacklistDevice(deviceInfo)) {
            continue;
        }

        //If we found an input device
        if (deviceInfo->input) {
            qDebug() << " Found input device" << "#" << i << deviceInfo->name;
            inputDeviceInfo = deviceInfo;
            inputDevIndex = i;

            //Reset our output device variables before we look for one incase we find none.
            outputDeviceInfo = NULL;
            outputDevIndex = -1;

            //Search for a corresponding output device
            QMapIterator<int, QString> j(unassignedOutputDevices);
            while (j.hasNext()) {
                j.next();

                QString deviceName = inputDeviceInfo->name;
                QString outputName = QString(j.value());

                if (shouldLinkInputToOutput(deviceName, outputName)) {
                    outputDevIndex = j.key();
                    outputDeviceInfo = Pm_GetDeviceInfo(outputDevIndex);

                    unassignedOutputDevices.remove(outputDevIndex);

                    qDebug() << "    Linking to output device #" << outputDevIndex << outputName;
                    break;
                }
            }

            // So at this point, we either have an input-only MIDI device
            // (outputDeviceInfo == NULL) or we've found a matching output MIDI
            // device (outputDeviceInfo != NULL).

            //.... so create our (aggregate) MIDI device!
            PortMidiController *currentDevice = new PortMidiController(
                inputDeviceInfo, outputDeviceInfo,
                inputDevIndex, outputDevIndex);
            m_devices.push_back(currentDevice);
        }

        // Is there a use-case for output-only devices (such as message
        // displays?) If so, handle them here.

        //else if (deviceInfo->output) {
        //    PortMidiController *currentDevice = new PortMidiController(deviceInfo, i);
        //    m_devices.push_back((MidiController*)currentDevice);
        //}
    }
    return m_devices;
}