=== modified file 'mixxx/src/mixxxkeyboard.cpp' --- mixxx/src/mixxxkeyboard.cpp 2011-10-16 02:09:36 +0000 +++ mixxx/src/mixxxkeyboard.cpp 2011-12-07 22:43:16 +0000 @@ -34,86 +34,89 @@ delete m_pKbdConfigObject; } -bool MixxxKeyboard::eventFilter(QObject *, QEvent * e) -{ - if (e->type()==QEvent::KeyPress) - { +bool MixxxKeyboard::eventFilter(QObject *, QEvent * e) { + if (e->type() == QEvent::KeyPress) { QKeyEvent * ke = (QKeyEvent *)e; - //qDebug() << "press"; +#ifdef __OSX__ + // On Mac OSX the nativeScanCode is empty http://doc.qt.nokia.com/4.7/qkeyevent.html#nativeScanCode + // We may loose the release event if a the shift key is pressed later + // and there is character shift like "1" -> "!" + int keyId = ke->key(); +#else + int keyId = ke->nativeScanCode(); +#endif + bool autoRepeat = ke->isAutoRepeat(); - if (kbdPress(getKeySeq(ke), false, autoRepeat)) { - // Add key to active key list - if (!autoRepeat) - m_qActiveKeyList.append(ke->key()); - - return true; + //qDebug() << "key event =" << ke->key() << "AutoRepeat =" << autoRepeat; + + if (!autoRepeat) { + QString keystring = getKeySeq(ke); + if (!keystring.isEmpty()) + { + // Check if a shortcut is defined + ConfigKey * pConfigKey = m_pKbdConfigObject->get(ConfigValueKbd(keystring)); + + if (pConfigKey) + { + ControlObject::getControl(*pConfigKey)->queueFromMidi(NOTE_ON, 1); + // Add key to active key list + m_qActiveKeyList.append(QPair(keyId,pConfigKey)); + return true; + } + } + } else { + // Run through list of active keys to see if the released key is active + // Just for returning true if we are consuming this key event + QListIterator > it(m_qActiveKeyList); + while (it.hasNext()) { + if (it.next().first == keyId) + { + return true; + } + } } - } - else if (e->type()==QEvent::KeyRelease) - { + } else if (e->type()==QEvent::KeyRelease) { QKeyEvent * ke = (QKeyEvent *)e; +#ifdef __OSX__ + // On Mac OSX the nativeScanCode is empty + int keyId = ke->key(); +#else + int keyId = ke->nativeScanCode(); +#endif + bool autoRepeat = ke->isAutoRepeat(); + + //qDebug() << "key event =" << ke->key() << ke->nativeVirtualKey() << ke->nativeScanCode(); + // Run through list of active keys to see if the released key is active - int key = -1; - QListIterator it(m_qActiveKeyList); - - while (it.hasNext()) - { - key = it.next(); - if (key == ke->key()) + // use removeAll because there my be doublets because of lost release events on Mac OSX + bool react = false; + for (int i = m_qActiveKeyList.size() - 1; i >= 0; i--) { + if (m_qActiveKeyList[i].first == keyId) { - //qDebug() << "release"; - - bool autoRepeat = ke->isAutoRepeat(); - if (kbdPress(getKeySeq(ke), true, autoRepeat)) { - if (!autoRepeat) { - //qDebug() << "release else"; - m_qActiveKeyList.removeOne(key); + if(!autoRepeat) { + if (!react) { + ControlObject::getControl(*(m_qActiveKeyList[i].second))->queueFromMidi(NOTE_OFF, 0); + react = true; // Do not return here because of possible doublets on Mac OSX + // due to lost release events } + m_qActiveKeyList.removeAt(i); + } else { return true; } - return false; } } + return react; } - return false; } -bool MixxxKeyboard::kbdPress(QKeySequence k, bool release, bool autoRepeat) -{ - bool react = false; - - if (!k.isEmpty()) - { - // Check if a shortcut is defined - ConfigKey * pConfigKey = m_pKbdConfigObject->get(ConfigValueKbd(k)); - - react = pConfigKey != NULL; - - if (pConfigKey && !autoRepeat) - { - if (release) { - //qDebug() << "Sending MIDI NOTE_OFF"; - ControlObject::getControl(*pConfigKey)->queueFromMidi(NOTE_OFF, 0); - } - else - { - //qDebug() << "Sending MIDI NOTE_ON"; - ControlObject::getControl(*pConfigKey)->queueFromMidi(NOTE_ON, 1); - } - } - } - return react; -} - -QKeySequence MixxxKeyboard::getKeySeq(QKeyEvent * e) -{ - QString modseq = QString::null; - QString keyseq = QString::null; - +QString MixxxKeyboard::getKeySeq(QKeyEvent * e) +{ + QString modseq; + QString keyseq; if (e->modifiers() & Qt::ShiftModifier) modseq += "Shift+"; @@ -127,12 +130,13 @@ if (e->modifiers() & Qt::MetaModifier) modseq += "Meta+"; - keyseq = (QString)QKeySequence(e->key()); + keyseq = e->text(); - QString seq = modseq + keyseq; - QKeySequence k = QKeySequence(seq); - //qDebug() << "keyboard press: " << k; - return k; + if(!keyseq.isEmpty()) { // avoid returning e.g. "Meta+" + keyseq = modseq + keyseq; + } + qDebug() << "keyboard press: " << keyseq; + return keyseq; } ConfigObject* MixxxKeyboard::getKeyboardConfig() { === modified file 'mixxx/src/mixxxkeyboard.h' --- mixxx/src/mixxxkeyboard.h 2010-11-01 05:08:58 +0000 +++ mixxx/src/mixxxkeyboard.h 2011-12-05 19:06:43 +0000 @@ -43,11 +43,10 @@ ConfigObject* getKeyboardConfig(); private: - bool kbdPress(QKeySequence k, bool release, bool autoRepeat); - /** Returns a valid QKeySequency with modifier keys from a QKeyEvent */ - QKeySequence getKeySeq(QKeyEvent *e); + /** Returns a valid QString with modifier keys from a QKeyEvent */ + QString getKeySeq(QKeyEvent *e); /** List containing keys which is currently pressed */ - QList m_qActiveKeyList; + QList > m_qActiveKeyList; /** Pointer to keyboard config object */ ConfigObject *m_pKbdConfigObject; };