void DlgPrefWaveform::slotResetToDefaults() { WaveformWidgetFactory* factory = WaveformWidgetFactory::instance(); // Get the default we ought to use based on whether the user has OpenGL or // not. WaveformWidgetType::Type defaultType = factory->autoChooseWidgetType(); int defaultIndex = waveformTypeComboBox->findData(defaultType); if (defaultIndex != -1 && waveformTypeComboBox->currentIndex() != defaultIndex) { waveformTypeComboBox->setCurrentIndex(defaultIndex); } allVisualGain->setValue(1.0); lowVisualGain->setValue(1.0); midVisualGain->setValue(1.0); highVisualGain->setValue(1.0); // Default zoom level is 3 in WaveformWidgetFactory. defaultZoomComboBox->setCurrentIndex(3 + 1); // Don't synchronize zoom by default. synchronizeZoomCheckBox->setChecked(false); // RGB overview. waveformOverviewComboBox->setCurrentIndex(2); // Don't normalize overview. normalizeOverviewCheckBox->setChecked(false); // 30FPS is the default frameRateSlider->setValue(30); endOfTrackWarningTimeSlider->setValue(30); // Waveform caching enabled. enableWaveformCaching->setChecked(true); enableWaveformGenerationWithAnalysis->setChecked(false); // Beat grid alpha default is 90 beatGridAlphaSlider->setValue(90); beatGridAlphaSpinBox->setValue(90); // 50 (center) is default playMarkerPositionSlider->setValue(50); }
void WaveformRendererHSV::draw(QPainter* painter, QPaintEvent* /*event*/) { const TrackPointer trackInfo = m_waveformRenderer->getTrackInfo(); if (!trackInfo) { return; } const Waveform* waveform = trackInfo->getWaveform(); if (waveform == NULL) { return; } const int dataSize = waveform->getDataSize(); if (dataSize <= 1) { return; } const WaveformData* data = waveform->data(); if (data == NULL) { return; } painter->save(); painter->setRenderHints(QPainter::Antialiasing, false); painter->setRenderHints(QPainter::HighQualityAntialiasing, false); painter->setRenderHints(QPainter::SmoothPixmapTransform, false); painter->setWorldMatrixEnabled(false); painter->resetTransform(); const double firstVisualIndex = m_waveformRenderer->getFirstDisplayedPosition() * dataSize; const double lastVisualIndex = m_waveformRenderer->getLastDisplayedPosition() * dataSize; const double offset = firstVisualIndex; // Represents the # of waveform data points per horizontal pixel. const double gain = (lastVisualIndex - firstVisualIndex) / (double)m_waveformRenderer->getWidth(); float allGain(1.0); allGain = m_waveformRenderer->getGain(); WaveformWidgetFactory* factory = WaveformWidgetFactory::instance(); allGain *= factory->getVisualGain(::WaveformWidgetFactory::All); // Save HSV of waveform color. NOTE(rryan): On ARM, qreal is float so it's // important we use qreal here and not double or float or else we will get // build failures on ARM. qreal h, s, v; // Get base color of waveform in the HSV format (s and v isn't use) m_pColors->getLowColor().getHsvF(&h, &s, &v); QColor color; float lo, hi, total; const float halfHeight = (float)m_waveformRenderer->getHeight()/2.0; const float heightFactor = allGain*halfHeight/255.0; //draw reference line painter->setPen(m_axesColor); painter->drawLine(0,halfHeight,m_waveformRenderer->getWidth(),halfHeight); for (int x = 0; x < m_waveformRenderer->getWidth(); ++x) { // Width of the x position in visual indices. const double xSampleWidth = gain * x; // Effective visual index of x const double xVisualSampleIndex = xSampleWidth + offset; // Our current pixel (x) corresponds to a number of visual samples // (visualSamplerPerPixel) in our waveform object. We take the max of // all the data points on either side of xVisualSampleIndex within a // window of 'maxSamplingRange' visual samples to measure the maximum // data point contained by this pixel. double maxSamplingRange = gain / 2.0; // Since xVisualSampleIndex is in visual-samples (e.g. R,L,R,L) we want // to check +/- maxSamplingRange frames, not samples. To do this, divide // xVisualSampleIndex by 2. Since frames indices are integers, we round // to the nearest integer by adding 0.5 before casting to int. int visualFrameStart = int(xVisualSampleIndex / 2.0 - maxSamplingRange + 0.5); int visualFrameStop = int(xVisualSampleIndex / 2.0 + maxSamplingRange + 0.5); const int lastVisualFrame = dataSize / 2 - 1; // We now know that some subset of [visualFrameStart, visualFrameStop] // lies within the valid range of visual frames. Clamp // visualFrameStart/Stop to within [0, lastVisualFrame]. visualFrameStart = math_max(math_min(lastVisualFrame, visualFrameStart), 0); visualFrameStop = math_max(math_min(lastVisualFrame, visualFrameStop), 0); int visualIndexStart = visualFrameStart * 2; int visualIndexStop = visualFrameStop * 2; int maxLow[2] = {0, 0}; int maxHigh[2] = {0, 0}; int maxMid[2] = {0, 0}; int maxAll[2] = {0, 0}; for (int i = visualIndexStart; i >= 0 && i + 1 < dataSize && i + 1 <= visualIndexStop; i += 2) { const WaveformData& waveformData = *(data + i); const WaveformData& waveformDataNext = *(data + i + 1); maxLow[0] = math_max(maxLow[0], (int)waveformData.filtered.low); maxLow[1] = math_max(maxLow[1], (int)waveformDataNext.filtered.low); maxMid[0] = math_max(maxMid[0], (int)waveformData.filtered.mid); maxMid[1] = math_max(maxMid[1], (int)waveformDataNext.filtered.mid); maxHigh[0] = math_max(maxHigh[0], (int)waveformData.filtered.high); maxHigh[1] = math_max(maxHigh[1], (int)waveformDataNext.filtered.high); maxAll[0] = math_max(maxAll[0], (int)waveformData.filtered.all); maxAll[1] = math_max(maxAll[1], (int)waveformDataNext.filtered.all); } if (maxAll[0] && maxAll[1]) { // Calculate sum, to normalize // Also multiply on 1.2 to prevent very dark or light color total = (maxLow[0] + maxLow[1] + maxMid[0] + maxMid[1] + maxHigh[0] + maxHigh[1]) * 1.2; // prevent division by zero if (total > 0) { // Normalize low and high (mid not need, because it not change the color) lo = (maxLow[0] + maxLow[1]) / total; hi = (maxHigh[0] + maxHigh[1]) / total; } else lo = hi = 0.0; // Set color color.setHsvF(h, 1.0-hi, 1.0-lo); painter->setPen(color); switch (m_alignment) { case Qt::AlignBottom : painter->drawLine( x, m_waveformRenderer->getHeight(), x, m_waveformRenderer->getHeight() - (int)(heightFactor*(float)math_max(maxAll[0],maxAll[1]))); break; case Qt::AlignTop : painter->drawLine( x, 0, x, (int)(heightFactor*(float)math_max(maxAll[0],maxAll[1]))); break; default : painter->drawLine( x, (int)(halfHeight-heightFactor*(float)maxAll[0]), x, (int)(halfHeight+heightFactor*(float)maxAll[1])); } } } painter->restore(); }
void QtWaveformRendererSimpleSignal::draw(QPainter* painter, QPaintEvent* /*event*/){ TrackPointer pTrack = m_waveformRenderer->getTrackInfo(); if (!pTrack) { return; } const Waveform* waveform = pTrack->getWaveform(); if (waveform == NULL) { return; } const int dataSize = waveform->getDataSize(); if (dataSize <= 1) { return; } const WaveformData* data = waveform->data(); if (data == NULL) { return; } painter->save(); painter->setRenderHint(QPainter::Antialiasing); painter->resetTransform(); WaveformWidgetFactory* factory = WaveformWidgetFactory::instance(); const double visualGain = factory->getVisualGain(WaveformWidgetFactory::All); double heightGain = visualGain*m_waveformRenderer->getGain()*(double)m_waveformRenderer->getHeight()/255.0; if (m_alignment == Qt::AlignTop) { painter->translate(0.0, 0.0); painter->scale(1.0, heightGain); } else if (m_alignment == Qt::AlignBottom) { painter->translate(0.0, m_waveformRenderer->getHeight()); painter->scale(1.0, heightGain); } else { painter->translate(0.0, m_waveformRenderer->getHeight()/2.0); painter->scale(1.0, 0.5*heightGain); } //draw reference line if (m_alignment == Qt::AlignCenter) { painter->setPen(m_pColors->getAxesColor()); painter->drawLine(0,0,m_waveformRenderer->getWidth(),0); } const double firstVisualIndex = m_waveformRenderer->getFirstDisplayedPosition() * dataSize; const double lastVisualIndex = m_waveformRenderer->getLastDisplayedPosition() * dataSize; m_polygon.clear(); m_polygon.reserve(2 * m_waveformRenderer->getWidth() + 2); m_polygon.append(QPointF(0.0, 0.0)); const double offset = firstVisualIndex; // Represents the # of waveform data points per horizontal pixel. const double gain = (lastVisualIndex - firstVisualIndex) / (double)m_waveformRenderer->getWidth(); //NOTE(vrince) Please help me find a better name for "channelSeparation" //this variable stand for merged channel ... 1 = merged & 2 = separated int channelSeparation = 2; if (m_alignment != Qt::AlignCenter) channelSeparation = 1; for (int channel = 0; channel < channelSeparation; ++channel) { int startPixel = 0; int endPixel = m_waveformRenderer->getWidth() - 1; int delta = 1; double direction = 1.0; //Reverse display for merged bottom channel if (m_alignment == Qt::AlignBottom) direction = -1.0; if (channel == 1) { startPixel = m_waveformRenderer->getWidth() - 1; endPixel = 0; delta = -1; direction = -1.0; // After preparing the first channel, insert the pivot point. m_polygon.append(QPointF(m_waveformRenderer->getWidth(), 0.0)); } for (int x = startPixel; (startPixel < endPixel) ? (x <= endPixel) : (x >= endPixel); x += delta) { // TODO(rryan) remove before 1.11 release. I'm seeing crashes // sometimes where the pointIndex is very very large. It hasn't come // back since adding locking, but I'm leaving this so that we can // get some info about it before crashing. (The crash usually // corrupts a lot of the stack). if (m_polygon.size() > 2 * m_waveformRenderer->getWidth() + 2) { qDebug() << "OUT OF CONTROL" << 2 * m_waveformRenderer->getWidth() + 2 << dataSize << channel << m_polygon.size() << x; } // Width of the x position in visual indices. const double xSampleWidth = gain * x; // Effective visual index of x const double xVisualSampleIndex = xSampleWidth + offset; // Our current pixel (x) corresponds to a number of visual samples // (visualSamplerPerPixel) in our waveform object. We take the max of // all the data points on either side of xVisualSampleIndex within a // window of 'maxSamplingRange' visual samples to measure the maximum // data point contained by this pixel. double maxSamplingRange = gain / 2.0; // Since xVisualSampleIndex is in visual-samples (e.g. R,L,R,L) we want // to check +/- maxSamplingRange frames, not samples. To do this, divide // xVisualSampleIndex by 2. Since frames indices are integers, we round // to the nearest integer by adding 0.5 before casting to int. int visualFrameStart = int(xVisualSampleIndex / 2.0 - maxSamplingRange + 0.5); int visualFrameStop = int(xVisualSampleIndex / 2.0 + maxSamplingRange + 0.5); // If the entire sample range is off the screen then don't calculate a // point for this pixel. const int lastVisualFrame = dataSize / 2 - 1; if (visualFrameStop < 0 || visualFrameStart > lastVisualFrame) { m_polygon.append(QPointF(x, 0.0)); continue; } // We now know that some subset of [visualFrameStart, // visualFrameStop] lies within the valid range of visual // frames. Clamp visualFrameStart/Stop to within [0, // lastVisualFrame]. visualFrameStart = math_max(math_min(lastVisualFrame, visualFrameStart), 0); visualFrameStop = math_max(math_min(lastVisualFrame, visualFrameStop), 0); int visualIndexStart = visualFrameStart * 2 + channel; int visualIndexStop = visualFrameStop * 2 + channel; // if (x == m_waveformRenderer->getWidth() / 2) { // qDebug() << "audioVisualRatio" << waveform->getAudioVisualRatio(); // qDebug() << "visualSampleRate" << waveform->getVisualSampleRate(); // qDebug() << "audioSamplesPerVisualPixel" << waveform->getAudioSamplesPerVisualSample(); // qDebug() << "visualSamplePerPixel" << visualSamplePerPixel; // qDebug() << "xSampleWidth" << xSampleWidth; // qDebug() << "xVisualSampleIndex" << xVisualSampleIndex; // qDebug() << "maxSamplingRange" << maxSamplingRange;; // qDebug() << "Sampling pixel " << x << "over [" << visualIndexStart << visualIndexStop << "]"; // } unsigned char maxAll = 0; for (int i = visualIndexStart; i >= 0 && i < dataSize && i <= visualIndexStop; i += channelSeparation) { const WaveformData& waveformData = *(data + i); unsigned char all = waveformData.filtered.all; maxAll = math_max(maxAll, all); } m_polygon.append(QPointF(x, (float)maxAll * direction)); } } //If channel are not displayed separatly we nne to close the loop properly if (channelSeparation == 1) { m_polygon.append(QPointF(m_waveformRenderer->getWidth(), 0.0)); } painter->setPen(m_borderPen); painter->setBrush(m_brush); painter->drawPolygon(&m_polygon[0], m_polygon.size()); painter->restore(); }
void WaveformRendererFilteredSignal::draw(QPainter* painter, QPaintEvent* /*event*/) { const TrackPointer trackInfo = m_waveformRenderer->getTrackInfo(); if (!trackInfo) { return; } const Waveform* waveform = trackInfo->getWaveform(); if (waveform == NULL) { return; } const int dataSize = waveform->getDataSize(); if (dataSize <= 1) { return; } const WaveformData* data = waveform->data(); if (data == NULL) { return; } painter->save(); painter->setRenderHints(QPainter::Antialiasing, false); painter->setRenderHints(QPainter::HighQualityAntialiasing, false); painter->setRenderHints(QPainter::SmoothPixmapTransform, false); painter->setWorldMatrixEnabled(false); painter->resetTransform(); const double firstVisualIndex = m_waveformRenderer->getFirstDisplayedPosition() * dataSize; const double lastVisualIndex = m_waveformRenderer->getLastDisplayedPosition() * dataSize; // Represents the # of waveform data points per horizontal pixel. const double gain = (lastVisualIndex - firstVisualIndex) / (double)m_waveformRenderer->getWidth(); // Per-band gain from the EQ knobs. float lowGain(1.0), midGain(1.0), highGain(1.0), allGain(1.0); if (m_pLowFilterControlObject && m_pMidFilterControlObject && m_pHighFilterControlObject) { lowGain = m_pLowFilterControlObject->get(); midGain = m_pMidFilterControlObject->get(); highGain = m_pHighFilterControlObject->get(); } allGain = m_waveformRenderer->getGain(); WaveformWidgetFactory* factory = WaveformWidgetFactory::instance(); allGain *= factory->getVisualGain(::WaveformWidgetFactory::All); lowGain *= factory->getVisualGain(WaveformWidgetFactory::Low); midGain *= factory->getVisualGain(WaveformWidgetFactory::Mid); highGain *= factory->getVisualGain(WaveformWidgetFactory::High); const float halfHeight = (float)m_waveformRenderer->getHeight()/2.0; const float heightFactor = m_alignment == Qt::AlignCenter ? allGain*halfHeight/255.0 : allGain*m_waveformRenderer->getHeight()/255.0; //draw reference line if (m_alignment == Qt::AlignCenter) { painter->setPen(m_axesColor); painter->drawLine(0,halfHeight,m_waveformRenderer->getWidth(),halfHeight); } int actualLowLineNumber = 0; int actualMidLineNumber = 0; int actualHighLineNumber = 0; for (int x = 0; x < m_waveformRenderer->getWidth(); ++x) { // Width of the x position in visual indices. const double xSampleWidth = gain * x; // Effective visual index of x const double xVisualSampleIndex = xSampleWidth + firstVisualIndex; // Our current pixel (x) corresponds to a number of visual samples // (visualSamplerPerPixel) in our waveform object. We take the max of // all the data points on either side of xVisualSampleIndex within a // window of 'maxSamplingRange' visual samples to measure the maximum // data point contained by this pixel. double maxSamplingRange = gain / 2.0; // Since xVisualSampleIndex is in visual-samples (e.g. R,L,R,L) we want // to check +/- maxSamplingRange frames, not samples. To do this, divide // xVisualSampleIndex by 2. Since frames indices are integers, we round // to the nearest integer by adding 0.5 before casting to int. int visualFrameStart = int(xVisualSampleIndex / 2.0 - maxSamplingRange + 0.5); int visualFrameStop = int(xVisualSampleIndex / 2.0 + maxSamplingRange + 0.5); // If the entire sample range is off the screen then don't calculate a // point for this pixel. const int lastVisualFrame = dataSize / 2 - 1; if (visualFrameStop < 0 || visualFrameStart > lastVisualFrame) { continue; } // We now know that some subset of [visualFrameStart, visualFrameStop] // lies within the valid range of visual frames. Clamp // visualFrameStart/Stop to within [0, lastVisualFrame]. visualFrameStart = math_max(math_min(lastVisualFrame, visualFrameStart), 0); visualFrameStop = math_max(math_min(lastVisualFrame, visualFrameStop), 0); int visualIndexStart = visualFrameStart * 2; int visualIndexStop = visualFrameStop * 2; // if (x == m_waveformRenderer->getWidth() / 2) { // qDebug() << "audioVisualRatio" << waveform->getAudioVisualRatio(); // qDebug() << "visualSampleRate" << waveform->getVisualSampleRate(); // qDebug() << "audioSamplesPerVisualPixel" << waveform->getAudioSamplesPerVisualSample(); // qDebug() << "visualSamplePerPixel" << visualSamplePerPixel; // qDebug() << "xSampleWidth" << xSampleWidth; // qDebug() << "xVisualSampleIndex" << xVisualSampleIndex; // qDebug() << "maxSamplingRange" << maxSamplingRange;; // qDebug() << "Sampling pixel " << x << "over [" << visualIndexStart << visualIndexStop << "]"; // } unsigned char maxLow[2] = {0, 0}; unsigned char maxMid[2] = {0, 0}; unsigned char maxHigh[2] = {0, 0}; for (int i = visualIndexStart; i >= 0 && i + 1 < dataSize && i + 1 <= visualIndexStop; i += 2) { const WaveformData& waveformData = *(data + i); const WaveformData& waveformDataNext = *(data + i + 1); maxLow[0] = math_max(maxLow[0], waveformData.filtered.low); maxLow[1] = math_max(maxLow[1], waveformDataNext.filtered.low); maxMid[0] = math_max(maxMid[0], waveformData.filtered.mid); maxMid[1] = math_max(maxMid[1], waveformDataNext.filtered.mid); maxHigh[0] = math_max(maxHigh[0], waveformData.filtered.high); maxHigh[1] = math_max(maxHigh[1], waveformDataNext.filtered.high); } if (maxLow[0] && maxLow[1]) { switch (m_alignment) { case Qt::AlignBottom : m_lowLines[actualLowLineNumber].setLine( x, m_waveformRenderer->getHeight(), x, m_waveformRenderer->getHeight() - (int)(heightFactor*lowGain*(float)math_max(maxLow[0],maxLow[1]))); break; case Qt::AlignTop : m_lowLines[actualLowLineNumber].setLine( x, 0, x, (int)(heightFactor*lowGain*(float)math_max(maxLow[0],maxLow[1]))); break; default : m_lowLines[actualLowLineNumber].setLine( x, (int)(halfHeight-heightFactor*(float)maxLow[0]*lowGain), x, (int)(halfHeight+heightFactor*(float)maxLow[1]*lowGain)); break; } actualLowLineNumber++; } if (maxMid[0] && maxMid[1]) { switch (m_alignment) { case Qt::AlignBottom : m_midLines[actualMidLineNumber].setLine( x, m_waveformRenderer->getHeight(), x, m_waveformRenderer->getHeight() - (int)(heightFactor*midGain*(float)math_max(maxMid[0],maxMid[1]))); break; case Qt::AlignTop : m_midLines[actualMidLineNumber].setLine( x, 0, x, (int)(heightFactor*midGain*(float)math_max(maxMid[0],maxMid[1]))); break; default : m_midLines[actualMidLineNumber].setLine( x, (int)(halfHeight-heightFactor*(float)maxMid[0]*midGain), x, (int)(halfHeight+heightFactor*(float)maxMid[1]*midGain)); break; } actualMidLineNumber++; } if (maxHigh[0] && maxHigh[1]) { switch (m_alignment) { case Qt::AlignBottom : m_highLines[actualHighLineNumber].setLine( x, m_waveformRenderer->getHeight(), x, m_waveformRenderer->getHeight() - (int)(heightFactor*highGain*(float)math_max(maxHigh[0],maxHigh[1]))); break; case Qt::AlignTop : m_highLines[actualHighLineNumber].setLine( x, 0, x, (int)(heightFactor*highGain*(float)math_max(maxHigh[0],maxHigh[1]))); break; default : m_highLines[actualHighLineNumber].setLine( x, (int)(halfHeight-heightFactor*(float)maxHigh[0]*highGain), x, (int)(halfHeight+heightFactor*(float)maxHigh[1]*highGain)); break; } actualHighLineNumber++; } } painter->setPen(QPen(QBrush(m_pColors->getLowColor()), 1)); if (m_pLowKillControlObject && m_pLowKillControlObject->get() == 0.0) { painter->drawLines(&m_lowLines[0], actualLowLineNumber); } painter->setPen(QPen(QBrush(m_pColors->getMidColor()), 1)); if (m_pMidKillControlObject && m_pMidKillControlObject->get() == 0.0) { painter->drawLines(&m_midLines[0], actualMidLineNumber); } painter->setPen(QPen(QBrush(m_pColors->getHighColor()), 1)); if (m_pHighKillControlObject && m_pHighKillControlObject->get() == 0.0) { painter->drawLines(&m_highLines[0], actualHighLineNumber); } painter->restore(); }
void GLWaveformRendererRGB::draw(QPainter* painter, QPaintEvent* /*event*/) { TrackPointer pTrack = m_waveformRenderer->getTrackInfo(); if (!pTrack) { return; } const Waveform* waveform = pTrack->getWaveform(); if (waveform == NULL) { return; } const int dataSize = waveform->getDataSize(); if (dataSize <= 1) { return; } const WaveformData* data = waveform->data(); if (data == NULL) { return; } double firstVisualIndex = m_waveformRenderer->getFirstDisplayedPosition() * dataSize; double lastVisualIndex = m_waveformRenderer->getLastDisplayedPosition() * dataSize; const int firstIndex = int(firstVisualIndex + 0.5); firstVisualIndex = firstIndex - firstIndex % 2; const int lastIndex = int(lastVisualIndex + 0.5); lastVisualIndex = lastIndex + lastIndex % 2; // Reset device for native painting painter->beginNativePainting(); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Per-band gain from the EQ knobs. float lowGain(1.0), midGain(1.0), highGain(1.0); if (m_pLowFilterControlObject && m_pMidFilterControlObject && m_pHighFilterControlObject) { lowGain = m_pLowFilterControlObject->get(); midGain = m_pMidFilterControlObject->get(); highGain = m_pHighFilterControlObject->get(); } WaveformWidgetFactory* factory = WaveformWidgetFactory::instance(); const double visualGain = factory->getVisualGain(::WaveformWidgetFactory::All); lowGain *= factory->getVisualGain(WaveformWidgetFactory::Low); midGain *= factory->getVisualGain(WaveformWidgetFactory::Mid); highGain *= factory->getVisualGain(WaveformWidgetFactory::High); if (m_alignment == Qt::AlignCenter) { glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(firstVisualIndex, lastVisualIndex, -255.0, 255.0, -10.0, 10.0); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glScalef(1.0f, visualGain * m_waveformRenderer->getGain(), 1.0f); glLineWidth(1.2); glDisable(GL_LINE_SMOOTH); // Draw reference line glBegin(GL_LINES); { glColor4f(m_axesColor_r, m_axesColor_g, m_axesColor_b, m_axesColor_a); glVertex2f(firstVisualIndex, 0); glVertex2f(lastVisualIndex, 0); } glEnd(); glLineWidth(1.2); glEnable(GL_LINE_SMOOTH); glBegin(GL_LINES); { for( int visualIndex = firstVisualIndex; visualIndex < lastVisualIndex; visualIndex += 2) { if( visualIndex < 0) continue; if( visualIndex > dataSize - 1) break; float left_low = lowGain * (float) data[visualIndex].filtered.low; float left_mid = midGain * (float) data[visualIndex].filtered.mid; float left_high = highGain * (float) data[visualIndex].filtered.high; float left_all = sqrtf(left_low * left_low + left_mid * left_mid + left_high * left_high); float left_red = left_low * m_lowColor.red() + left_mid * m_midColor.red() + left_high * m_highColor.red(); float left_green = left_low * m_lowColor.green() + left_mid * m_midColor.green() + left_high * m_highColor.green(); float left_blue = left_low * m_lowColor.blue() + left_mid * m_midColor.blue() + left_high * m_highColor.blue(); float left_max = MAX3(left_red, left_green, left_blue); if (left_max > 0.0f) { // Prevent division by zero glColor4f(left_red / left_max, left_green / left_max, left_blue / left_max, 0.8f); glVertex2f(visualIndex, 0.0f); glVertex2f(visualIndex, left_all); } float right_low = lowGain * (float) data[visualIndex+1].filtered.low; float right_mid = midGain * (float) data[visualIndex+1].filtered.mid; float right_high = highGain * (float) data[visualIndex+1].filtered.high; float right_all = sqrtf(right_low * right_low + right_mid * right_mid + right_high * right_high); float right_red = right_low * m_lowColor.red() + right_mid * m_midColor.red() + right_high * m_highColor.red(); float right_green = right_low * m_lowColor.green() + right_mid * m_midColor.green() + right_high * m_highColor.green(); float right_blue = right_low * m_lowColor.blue() + right_mid * m_midColor.blue() + right_high * m_highColor.blue(); float right_max = MAX3(right_red, right_green, right_blue); if (right_max > 0.0f) { // Prevent division by zero glColor4f(right_red / right_max, right_green / right_max, right_blue / right_max, 0.8f); glVertex2f(visualIndex, 0.0f); glVertex2f(visualIndex, -1.0f * right_all); } } } glEnd(); } else { // top || bottom glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); if( m_alignment == Qt::AlignBottom) glOrtho(firstVisualIndex, lastVisualIndex, 0.0, 255.0, -10.0, 10.0); else glOrtho(firstVisualIndex, lastVisualIndex, 255.0, 0.0, -10.0, 10.0); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glScalef(1.0f, visualGain * m_waveformRenderer->getGain(), 1.0f); glLineWidth(1.2); glEnable(GL_LINE_SMOOTH); glBegin(GL_LINES); { for( int visualIndex = firstVisualIndex; visualIndex < lastVisualIndex; visualIndex += 2) { if( visualIndex < 0) continue; if( visualIndex > dataSize - 1) break; float low = lowGain * (float) math_max(data[visualIndex].filtered.low, data[visualIndex+1].filtered.low); float mid = midGain * (float) math_max(data[visualIndex].filtered.mid, data[visualIndex+1].filtered.mid); float high = highGain * (float) math_max(data[visualIndex].filtered.high, data[visualIndex+1].filtered.high); float all = sqrtf(low * low + mid * mid + high * high); float red = low * m_lowColor.red() + mid * m_midColor.red() + high * m_highColor.red(); float green = low * m_lowColor.green() + mid * m_midColor.green() + high * m_highColor.green(); float blue = low * m_lowColor.blue() + mid * m_midColor.blue() + high * m_highColor.blue(); float max = MAX3(red, green, blue); if (max > 0.0f) { // Prevent division by zero glColor4f(red / max, green / max, blue / max, 0.9f); glVertex2f(float(visualIndex), 0.0f); glVertex2f(float(visualIndex), all); } } } glEnd(); } glPopMatrix(); glMatrixMode(GL_PROJECTION); glPopMatrix(); painter->endNativePainting(); }
DlgPrefWaveform::DlgPrefWaveform(QWidget* pParent, MixxxMainWindow* pMixxx, UserSettingsPointer pConfig, Library* pLibrary) : DlgPreferencePage(pParent), m_pConfig(pConfig), m_pLibrary(pLibrary), m_pMixxx(pMixxx) { setupUi(this); // Waveform overview init waveformOverviewComboBox->addItem(tr("Filtered")); // "0" waveformOverviewComboBox->addItem(tr("HSV")); // "1" waveformOverviewComboBox->addItem(tr("RGB")); // "2" // Populate waveform options. WaveformWidgetFactory* factory = WaveformWidgetFactory::instance(); QVector<WaveformWidgetAbstractHandle> handles = factory->getAvailableTypes(); for (int i = 0; i < handles.size(); ++i) { waveformTypeComboBox->addItem(handles[i].getDisplayName(), handles[i].getType()); } // Populate zoom options. for (int i = WaveformWidgetRenderer::s_waveformMinZoom; i <= WaveformWidgetRenderer::s_waveformMaxZoom; i++) { defaultZoomComboBox->addItem(QString::number(100/double(i), 'f', 1) + " %"); } // The GUI is not fully setup so connecting signals before calling // slotUpdate can generate rebootMixxxView calls. // TODO(XXX): Improve this awkwardness. slotUpdate(); connect(frameRateSpinBox, SIGNAL(valueChanged(int)), this, SLOT(slotSetFrameRate(int))); connect(endOfTrackWarningTimeSpinBox, SIGNAL(valueChanged(int)), this, SLOT(slotSetWaveformEndRender(int))); connect(beatGridAlphaSpinBox, SIGNAL(valueChanged(int)), this, SLOT(slotSetBeatGridAlpha(int))); connect(frameRateSlider, SIGNAL(valueChanged(int)), frameRateSpinBox, SLOT(setValue(int))); connect(frameRateSpinBox, SIGNAL(valueChanged(int)), frameRateSlider, SLOT(setValue(int))); connect(endOfTrackWarningTimeSlider, SIGNAL(valueChanged(int)), endOfTrackWarningTimeSpinBox, SLOT(setValue(int))); connect(endOfTrackWarningTimeSpinBox, SIGNAL(valueChanged(int)), endOfTrackWarningTimeSlider, SLOT(setValue(int))); connect(beatGridAlphaSlider, SIGNAL(valueChanged(int)), beatGridAlphaSpinBox, SLOT(setValue(int))); connect(beatGridAlphaSpinBox, SIGNAL(valueChanged(int)), beatGridAlphaSlider, SLOT(setValue(int))); connect(waveformTypeComboBox, SIGNAL(activated(int)), this, SLOT(slotSetWaveformType(int))); connect(defaultZoomComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotSetDefaultZoom(int))); connect(synchronizeZoomCheckBox, SIGNAL(clicked(bool)), this, SLOT(slotSetZoomSynchronization(bool))); connect(allVisualGain, SIGNAL(valueChanged(double)), this, SLOT(slotSetVisualGainAll(double))); connect(lowVisualGain, SIGNAL(valueChanged(double)), this, SLOT(slotSetVisualGainLow(double))); connect(midVisualGain, SIGNAL(valueChanged(double)), this, SLOT(slotSetVisualGainMid(double))); connect(highVisualGain, SIGNAL(valueChanged(double)), this, SLOT(slotSetVisualGainHigh(double))); connect(normalizeOverviewCheckBox, SIGNAL(toggled(bool)), this, SLOT(slotSetNormalizeOverview(bool))); connect(factory, SIGNAL(waveformMeasured(float,int)), this, SLOT(slotWaveformMeasured(float,int))); connect(waveformOverviewComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotSetWaveformOverviewType(int))); connect(clearCachedWaveforms, SIGNAL(clicked()), this, SLOT(slotClearCachedWaveforms())); connect(playMarkerPositionSlider, SIGNAL(valueChanged(int)), this, SLOT(slotSetPlayMarkerPosition(int))); }
void DlgPrefWaveform::slotUpdate() { WaveformWidgetFactory* factory = WaveformWidgetFactory::instance(); if (factory->isOpenGlAvailable() || factory->isOpenGlesAvailable()) { openGlStatusIcon->setText(factory->getOpenGLVersion()); } else { openGlStatusIcon->setText(tr("OpenGL not available") + ": " + factory->getOpenGLVersion()); } WaveformWidgetType::Type currentType = factory->getType(); int currentIndex = waveformTypeComboBox->findData(currentType); if (currentIndex != -1 && waveformTypeComboBox->currentIndex() != currentIndex) { waveformTypeComboBox->setCurrentIndex(currentIndex); } frameRateSpinBox->setValue(factory->getFrameRate()); frameRateSlider->setValue(factory->getFrameRate()); endOfTrackWarningTimeSpinBox->setValue(factory->getEndOfTrackWarningTime()); endOfTrackWarningTimeSlider->setValue(factory->getEndOfTrackWarningTime()); synchronizeZoomCheckBox->setChecked(factory->isZoomSync()); allVisualGain->setValue(factory->getVisualGain(WaveformWidgetFactory::All)); lowVisualGain->setValue(factory->getVisualGain(WaveformWidgetFactory::Low)); midVisualGain->setValue(factory->getVisualGain(WaveformWidgetFactory::Mid)); highVisualGain->setValue(factory->getVisualGain(WaveformWidgetFactory::High)); normalizeOverviewCheckBox->setChecked(factory->isOverviewNormalized()); // Round zoom to int to get a default zoom index. defaultZoomComboBox->setCurrentIndex(static_cast<int>(factory->getDefaultZoom()) - 1); playMarkerPositionSlider->setValue(factory->getPlayMarkerPosition() * 100); beatGridAlphaSpinBox->setValue(factory->beatGridAlpha()); beatGridAlphaSlider->setValue(factory->beatGridAlpha()); // By default we set RGB woverview = "2" int overviewType = m_pConfig->getValue( ConfigKey("[Waveform]","WaveformOverviewType"), 2); if (overviewType != waveformOverviewComboBox->currentIndex()) { waveformOverviewComboBox->setCurrentIndex(overviewType); } WaveformSettings waveformSettings(m_pConfig); enableWaveformCaching->setChecked(waveformSettings.waveformCachingEnabled()); enableWaveformGenerationWithAnalysis->setChecked( waveformSettings.waveformGenerationWithAnalysisEnabled()); calculateCachedWaveformDiskUsage(); }