GuitarTuner::GuitarTuner(QWidget *parent) : QMainWindow(parent) { // Set up the QML. m_guitarTunerUI = new QDeclarativeView(QUrl("qrc:/src/application.qml"), this); setCentralWidget(m_guitarTunerUI); m_guitarTunerUI->setResizeMode(QDeclarativeView::SizeRootObjectToView); qmlObject = m_guitarTunerUI->rootObject(); // Init audio output and input. initAudioOutput(); initAudioInput(); // Connect the quit signal of m_guitarTunerUI // into the close slot of this. connect(m_guitarTunerUI->engine(), SIGNAL(quit()), SLOT(close())); // Connect the signals from qmlObject into proper slots // of this and m_voicegenerator. connect(qmlObject, SIGNAL(muteStateChanged(bool)), SLOT(muteStateChanged(bool))); connect(qmlObject, SIGNAL(volumeChanged(qreal)), m_voicegenerator, SLOT(setAmplitude(qreal))); connect(qmlObject, SIGNAL(volumeChanged(qreal)), SLOT(setMaxVolumeLevel(qreal))); // Connect the modeChanged signal from qmlObject // into modeChanged slot of this class. connect(qmlObject, SIGNAL(modeChanged(bool)), SLOT(modeChanged(bool))); // Connect the microphoneSensitivityChanged signal from // m_guitarTunerUI into setCutOffPercentage slot of m_analyzer class. connect(qmlObject, SIGNAL(microphoneSensitivityChanged(qreal)), m_analyzer, SLOT(setCutOffPercentage(qreal))); // Connect the signals from m_analyzer into slots of qmlObject. connect(m_analyzer, SIGNAL(lowVoice()), qmlObject, SLOT(lowVoice())); connect(m_analyzer, SIGNAL(correctFrequency()), qmlObject, SLOT(correctFrequencyObtained())); connect(m_analyzer, SIGNAL(voiceDifference(QVariant)), qmlObject, SLOT(voiceDifferenceChanged(QVariant))); // Initialise the MaximumVoiceDifference // value of qmlObject with the value obtained from m_analyzer. qmlObject->setProperty("maxVoiceDifference", m_analyzer->getMaximumVoiceDifference()); // Connect the targetFrequencyChanged signal of qmlObject // into targetFrequencyChanged slot of this class. connect(qmlObject, SIGNAL(targetFrequencyChanged(qreal)), SLOT(targetFrequencyChanged(qreal))); // Start voice output or input by using the modeChanged function, // depending of the current mode. modeChanged(qmlObject->property("isInput").toBool()); }
/** * Changes the tone according to the new index. */ void GuitarTunerUI::changeTone(int newIndex) { m_currentToneIndex = newIndex; updateFrequencyByToneIndex(m_currentToneIndex); qDebug() << "targetFrequencyChanged" << m_currentToneFrequency; emit targetFrequencyChanged(m_currentToneFrequency); }