#include <QStringList>
#include <QTime>
#include <QTimer>
#include <QWidget>
#include <QtDebug>
#include <QGLFormat>
#include <QGLShaderProgram>
#include <QGuiApplication>
#include <QWindow>
#include <QOpenGLFunctions>
#include "waveform/waveformwidgetfactory.h"
#include "control/controlpotmeter.h"
#include "waveform/sharedglcontext.h"
#include "waveform/widgets/emptywaveformwidget.h"
#include "waveform/widgets/softwarewaveformwidget.h"
#include "waveform/widgets/hsvwaveformwidget.h"
#include "waveform/widgets/rgbwaveformwidget.h"
#include "waveform/widgets/qthsvwaveformwidget.h"
#include "waveform/widgets/qtrgbwaveformwidget.h"
#include "waveform/widgets/glrgbwaveformwidget.h"
#include "waveform/widgets/glwaveformwidget.h"
#include "waveform/widgets/glsimplewaveformwidget.h"
#include "waveform/widgets/qtwaveformwidget.h"
#include "waveform/widgets/qtsimplewaveformwidget.h"
#include "waveform/widgets/glslwaveformwidget.h"
#include "waveform/widgets/glvsynctestwidget.h"
#include "waveform/widgets/qtvsynctestwidget.h"
#include "waveform/widgets/waveformwidgetabstract.h"
#include "widget/wwaveformviewer.h"
#include "waveform/guitick.h"
#include "waveform/visualsmanager.h"
#include "waveform/vsyncthread.h"
#include "util/cmdlineargs.h"
#include "util/performancetimer.h"
#include "util/timer.h"
#include "util/math.h"
namespace {
// Returns true if the given waveform should be rendered.
bool shouldRenderWaveform(WaveformWidgetAbstract* pWaveformWidget) {
if (pWaveformWidget == nullptr ||
pWaveformWidget->getWidth() == 0 ||
pWaveformWidget->getHeight() == 0) {
return false;
}
auto glw = dynamic_cast<QGLWidget*>(pWaveformWidget->getWidget());
if (glw == nullptr) {
// Not a QGLWidget. We can simply use QWidget::isVisible.
auto qwidget = dynamic_cast<QWidget*>(pWaveformWidget->getWidget());
return qwidget != nullptr && qwidget->isVisible();
}
if (glw == nullptr || !glw->isValid() || !glw->isVisible()) {
return false;
}
// Strangely, a widget can have non-zero width/height, be valid and visible,
// yet still not show up on the screen. QWindow::isExposed tells us this.
auto window = glw->windowHandle();
if (window == nullptr || !window->isExposed()) {
return false;
}
return true;
}
} // anonymous namespace
///////////////////////////////////////////
WaveformWidgetAbstractHandle::WaveformWidgetAbstractHandle()
: m_type(WaveformWidgetType::Count_WaveformwidgetType) {
}
///////////////////////////////////////////
WaveformWidgetHolder::WaveformWidgetHolder()
: m_waveformWidget(NULL),
m_waveformViewer(NULL),
m_skinContextCache(UserSettingsPointer(), QString()) {
}
WaveformWidgetHolder::WaveformWidgetHolder(WaveformWidgetAbstract* waveformWidget,
WWaveformViewer* waveformViewer,
const QDomNode& node,
const SkinContext& parentContext)
: m_waveformWidget(waveformWidget),
m_waveformViewer(waveformViewer),
m_skinNodeCache(node.cloneNode()),
m_skinContextCache(&parentContext) {
}
///////////////////////////////////////////
WaveformWidgetFactory::WaveformWidgetFactory()
// Set an empty waveform initially. We will set the correct one when skin load finishes.
// Concretely, we want to set a non-GL waveform when loading the skin so that the window
// loads correctly.
: m_type(WaveformWidgetType::EmptyWaveform),
m_config(0),
m_skipRender(false),
m_frameRate(30),
m_endOfTrackWarningTime(30),
m_defaultZoom(WaveformWidgetRenderer::s_waveformDefaultZoom),
m_zoomSync(false),
m_overviewNormalized(false),
m_openGlAvailable(false),
m_openGlesAvailable(false),
m_openGLShaderAvailable(false),
m_beatGridAlpha(90),
m_vsyncThread(nullptr),
m_pGuiTick(nullptr),
m_pVisualsManager(nullptr),
m_frameCnt(0),
m_actualFrameRate(0),
m_vSyncType(0),
m_playMarkerPosition(WaveformWidgetRenderer::s_defaultPlayMarkerPosition) {
m_visualGain[All] = 1.0;
m_visualGain[Low] = 1.0;
m_visualGain[Mid] = 1.0;
m_visualGain[High] = 1.0;
QGLWidget* pGlWidget = SharedGLContext::getWidget();
if (pGlWidget && pGlWidget->isValid()) {
// will be false if SafeMode is enabled
pGlWidget->show();
// Without a makeCurrent, hasOpenGLShaderPrograms returns false on Qt 5.
// and QGLFormat::openGLVersionFlags() returns the maximum known version
pGlWidget->makeCurrent();
QGLFormat::OpenGLVersionFlags version = QGLFormat::openGLVersionFlags();
auto rendererString = QString();
if (QOpenGLContext::currentContext()) {
auto glFunctions = QOpenGLFunctions();
glFunctions.initializeOpenGLFunctions();
QString versionString(QLatin1String(
reinterpret_cast<const char*>(glFunctions.glGetString(GL_VERSION