-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial proof-of-concept for adding scopes.
- Loading branch information
Showing
26 changed files
with
1,285 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright (c) 2015 Meltytech, LLC | ||
* Author: Brian Matherly <code@brianmatherly.com> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
#include "scopecontroller.h" | ||
#include "widgets/scopes/audiowaveformscopewidget.h" | ||
#include "widgets/scopes/videowaveformscopewidget.h" | ||
#include "docks/scopedock.h" | ||
#include "settings.h" | ||
#include <QDebug> | ||
#include <QMainWindow> | ||
#include <QMenu> | ||
|
||
ScopeController::ScopeController(QMainWindow* mainWindow, QMenu* menu) | ||
: QObject(mainWindow) | ||
{ | ||
qDebug() << "begin"; | ||
QMenu* scopeMenu = menu->addMenu(tr("Scopes")); | ||
createScopeDock<AudioWaveformScopeWidget>(mainWindow, scopeMenu); | ||
if (!Settings.playerGPU()) { | ||
createScopeDock<VideoWaveformScopeWidget>(mainWindow, scopeMenu); | ||
} | ||
qDebug() << "end"; | ||
} | ||
|
||
void ScopeController::onFrameDisplayed(const SharedFrame& frame) | ||
{ | ||
emit newFrame(frame); | ||
} | ||
|
||
template<typename ScopeTYPE> void ScopeController::createScopeDock(QMainWindow* mainWindow, QMenu* menu) | ||
{ | ||
ScopeWidget* scopeWidget = new ScopeTYPE(); | ||
ScopeDock* scopeDock = new ScopeDock(this, scopeWidget); | ||
scopeDock->hide(); | ||
menu->addAction(scopeDock->toggleViewAction()); | ||
mainWindow->addDockWidget(Qt::RightDockWidgetArea, scopeDock); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright (c) 2015 Meltytech, LLC | ||
* Author: Brian Matherly <code@brianmatherly.com> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef SCOPECONTROLLER_H | ||
#define SCOPECONTROLLER_H | ||
|
||
#include <QObject> | ||
#include <QString> | ||
#include "sharedframe.h" | ||
|
||
class QMainWindow; | ||
class QMenu; | ||
class QWidget; | ||
|
||
class ScopeController Q_DECL_FINAL : public QObject | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
ScopeController(QMainWindow* mainWindow, QMenu* menu); | ||
|
||
public slots: | ||
void onFrameDisplayed(const SharedFrame& frame); | ||
|
||
signals: | ||
void newFrame(const SharedFrame& frame); | ||
|
||
private: | ||
template<typename ScopeTYPE> void createScopeDock(QMainWindow* mainWindow, QMenu* menu); | ||
|
||
}; | ||
|
||
#endif // SCOPECONTROLLER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
/* | ||
* Copyright (c) 2015 Meltytech, LLC | ||
* Author: Brian Matherly <code@brianmatherly.com> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef DATAQUEUE_H | ||
#define DATAQUEUE_H | ||
|
||
#include <QList> | ||
#include <QMutex> | ||
#include <QWaitCondition> | ||
#include <QMutexLocker> | ||
|
||
/*! | ||
\class DataQueue | ||
\brief The DataQueue provides a thread save container for passing data between | ||
objects. | ||
\threadsafe | ||
DataQueue provides a limited size container for passing data between objects. | ||
One object can add data to the queue by calling push() while another object | ||
can remove items from the queue by calling pop(). | ||
DataQueue provides configurable behavior for handling overflows. It can | ||
discard the oldest, discard the newest or block the object calling push() | ||
until room has been freed in the queue bu another object calling pop(). | ||
DataQueue is threadsave and is therefore most appropriate when passing data | ||
between objects operating in different thread contexts. | ||
*/ | ||
|
||
template <class T> | ||
class DataQueue | ||
{ | ||
public: | ||
//! Overflow behavior modes. | ||
typedef enum { | ||
OverflowModeDiscardOldest = 0, //!< Discard oldest items | ||
OverflowModeDiscardNewest, //!< Discard newest items | ||
OverflowModeWait //!< Wait for space to be free | ||
} OverflowMode; | ||
|
||
/*! | ||
Constructs a DataQueue. | ||
The \a size will be the maximum queue size and the \a mode will dictate | ||
overflow behavior. | ||
*/ | ||
explicit DataQueue(int maxSize, OverflowMode mode); | ||
|
||
//! Destructs a DataQueue. | ||
virtual ~DataQueue(); | ||
|
||
/*! | ||
Pushes an item into the queue. | ||
If the queue is full and overflow mode is OverflowModeWait then this | ||
function will block until pop() is called. | ||
*/ | ||
void push(const T& item); | ||
|
||
/*! | ||
Pops an item from the queue. | ||
If the queue is empty then this function will block. If blocking is | ||
undesired, then check the return of count() before calling pop(). | ||
*/ | ||
T pop(); | ||
|
||
//! Returns the number of items in the queue. | ||
int count() const; | ||
|
||
private: | ||
QList<T> m_queue; | ||
int m_maxSize; | ||
OverflowMode m_mode; | ||
mutable QMutex m_mutex; | ||
QWaitCondition m_notEmptyCondition; | ||
QWaitCondition m_notFullCondition; | ||
}; | ||
|
||
template <class T> | ||
DataQueue<T>::DataQueue(int maxSize, OverflowMode mode) | ||
: m_queue() | ||
, m_maxSize(maxSize) | ||
, m_mode(mode) | ||
, m_mutex(QMutex::NonRecursive) | ||
, m_notEmptyCondition() | ||
, m_notFullCondition() | ||
{ | ||
} | ||
|
||
template <class T> | ||
DataQueue<T>::~DataQueue() | ||
{ | ||
} | ||
|
||
template <class T> | ||
void DataQueue<T>::push(const T& item) | ||
{ | ||
m_mutex.lock(); | ||
if (m_queue.size() == m_maxSize) { | ||
switch(m_mode) { | ||
case OverflowModeDiscardOldest: | ||
m_queue.removeFirst(); | ||
m_queue.append(item); | ||
break; | ||
case OverflowModeDiscardNewest: | ||
// This item is the newest so discard it and exit | ||
break; | ||
case OverflowModeWait: | ||
m_notFullCondition.wait(&m_mutex); | ||
m_queue.append(item); | ||
break; | ||
} | ||
} else { | ||
m_queue.append(item); | ||
if (m_queue.size() == 1) { | ||
m_notEmptyCondition.wakeOne(); | ||
} | ||
} | ||
m_mutex.unlock(); | ||
} | ||
|
||
template <class T> | ||
T DataQueue<T>::pop() | ||
{ | ||
T retVal; | ||
m_mutex.lock(); | ||
if (m_queue.size() == 0) { | ||
m_notEmptyCondition.wait(&m_mutex); | ||
} | ||
retVal = m_queue.takeFirst(); | ||
if (m_mode == OverflowModeWait && m_queue.size() == m_maxSize - 1) { | ||
m_notFullCondition.wakeOne(); | ||
} | ||
m_mutex.unlock(); | ||
return retVal; | ||
} | ||
|
||
template <class T> | ||
int DataQueue<T>::count() const | ||
{ | ||
QMutexLocker locker(&m_mutex); | ||
return m_queue.size(); | ||
} | ||
|
||
#endif // DATAQUEUE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright (c) 2015 Meltytech, LLC | ||
* Author: Brian Matherly <code@brianmatherly.com> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "scopedock.h" | ||
#include "controllers/scopecontroller.h" | ||
#include <QDebug> | ||
#include <QtWidgets/QScrollArea> | ||
#include <QAction> | ||
|
||
ScopeDock::ScopeDock(ScopeController* scopeController, ScopeWidget* scopeWidget) : | ||
QDockWidget() | ||
, m_scopeController(scopeController) | ||
, m_scopeWidget(scopeWidget) | ||
{ | ||
qDebug() << "begin"; | ||
setObjectName(m_scopeWidget->objectName() + "Dock"); | ||
QScrollArea *scrollArea = new QScrollArea(); | ||
scrollArea->setFrameShape(QFrame::NoFrame); | ||
scrollArea->setWidgetResizable(true); | ||
scrollArea->setWidget(m_scopeWidget); | ||
QDockWidget::setWidget(scrollArea); | ||
QDockWidget::setWindowTitle(m_scopeWidget->getTitle()); | ||
|
||
connect(toggleViewAction(), SIGNAL(toggled(bool)), this, SLOT(onActionToggled(bool))); | ||
qDebug() << "end"; | ||
} | ||
|
||
void ScopeDock::onActionToggled(bool checked) | ||
{ | ||
if(checked) { | ||
connect(m_scopeController, SIGNAL(newFrame(const SharedFrame&)), m_scopeWidget, SLOT(onNewFrame(const SharedFrame&))); | ||
} else { | ||
disconnect(m_scopeController, SIGNAL(newFrame(const SharedFrame&)), m_scopeWidget, SLOT(onNewFrame(const SharedFrame&))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright (c) 2015 Meltytech, LLC | ||
* Author: Brian Matherly <code@brianmatherly.com> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef SCOPEDOCK_H | ||
#define SCOPEDOCK_H | ||
|
||
#include "widgets/scopes/scopewidget.h" | ||
#include <QDockWidget> | ||
#include <QObject> | ||
|
||
class ScopeController; | ||
|
||
class ScopeDock Q_DECL_FINAL : public QDockWidget | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
explicit ScopeDock(ScopeController* scopeController, ScopeWidget* scopeWidget); | ||
|
||
private: | ||
ScopeController* m_scopeController; | ||
ScopeWidget* m_scopeWidget; | ||
|
||
void setWidget(QWidget * widget); // Private to disallow use | ||
|
||
private slots: | ||
void onActionToggled(bool checked); | ||
}; | ||
|
||
#endif // SCOPEDOCK_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.