| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
#ifndef QUTEGRAPH_H |
| 24 |
#define QUTEGRAPH_H |
| 25 |
|
| 26 |
#include "qutewidget.h" |
| 27 |
#include "csoundengine.h" |
| 28 |
#include "selectcolorbutton.h" |
| 29 |
#include "curve.h" |
| 30 |
|
| 31 |
class Curve; |
| 32 |
|
| 33 |
enum GraphType { GRAPH_FTABLE=1, GRAPH_AUDIOSIGNAL=2, GRAPH_SPECTRUM=3 }; |
| 34 |
|
| 35 |
|
| 36 |
class QuteGraph : public QuteWidget |
| 37 |
{ |
| 38 |
Q_OBJECT |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
public: |
| 45 |
QuteGraph(QWidget *parent); |
| 46 |
|
| 47 |
~QuteGraph(); |
| 48 |
|
| 49 |
virtual QString getWidgetLine(); |
| 50 |
virtual QString getWidgetXmlText(); |
| 51 |
virtual QString getWidgetType(); |
| 52 |
virtual void setWidgetGeometry(int x,int y,int width,int height); |
| 53 |
void setValue(double value); |
| 54 |
void setValue(QString text); |
| 55 |
|
| 56 |
void clearCurves(); |
| 57 |
void addCurve(Curve *curve); |
| 58 |
int getCurveIndex(Curve * curve); |
| 59 |
void setCurveData(Curve * curve); |
| 60 |
void setUd(CsoundUserData *ud) { m_ud = ud; } |
| 61 |
void showGrid(bool visible) { m_drawGrid = visible; } |
| 62 |
void showTableInfo(bool state) { |
| 63 |
m_drawTableInfo = state; |
| 64 |
setProperty("QCS_showTableInfo", state?"true":"false"); |
| 65 |
if(m_label != nullptr) { |
| 66 |
if(state) |
| 67 |
m_label->show(); |
| 68 |
else |
| 69 |
m_label->hide(); |
| 70 |
} |
| 71 |
} |
| 72 |
int findCurve(CurveType type, QString text); |
| 73 |
virtual void applyInternalProperties(); |
| 74 |
size_t spectrumGetPeak(Curve *curve, double freq, double relativeBandwidth); |
| 75 |
|
| 76 |
protected: |
| 77 |
CsoundUserData *m_ud; |
| 78 |
QLabel * m_label; |
| 79 |
QComboBox *m_pageComboBox; |
| 80 |
QLineEdit* name2LineEdit; |
| 81 |
QDoubleSpinBox *zoomxBox; |
| 82 |
QDoubleSpinBox *zoomyBox; |
| 83 |
QCheckBox *acceptTablesCheckBox; |
| 84 |
QCheckBox *acceptDisplaysCheckBox; |
| 85 |
QCheckBox *showSelectorCheckBox; |
| 86 |
QCheckBox *showGridCheckBox; |
| 87 |
QCheckBox *showTableInfoCheckBox; |
| 88 |
QCheckBox *showScrollbarsCheckBox; |
| 89 |
|
| 90 |
QVector<Curve *> curves; |
| 91 |
QVector<QVector <QGraphicsLineItem *> > lines; |
| 92 |
QVector<QGraphicsPolygonItem *> polygons; |
| 93 |
QVector<QPainterPath *>painterPaths; |
| 94 |
QVector<GraphType>graphtypes; |
| 95 |
|
| 96 |
QVector<QVector <QGraphicsLineItem *> > m_gridlines; |
| 97 |
QVector<QVector <QGraphicsTextItem *> > m_gridTextsX; |
| 98 |
QVector<QVector <QGraphicsTextItem *> > m_gridTextsY; |
| 99 |
|
| 100 |
|
| 101 |
QVector<QGraphicsTextItem*> m_spectrumPeakTexts; |
| 102 |
QVector<QGraphicsRectItem*> m_spectrumPeakMarkers; |
| 103 |
|
| 104 |
|
| 105 |
QPainterPath *gridPath; |
| 106 |
|
| 107 |
virtual void refreshWidget(); |
| 108 |
virtual void createPropertiesDialog(); |
| 109 |
virtual void applyProperties(); |
| 110 |
virtual void keyPressEvent(QKeyEvent *ev); |
| 111 |
virtual void mousePressEvent(QMouseEvent *ev); |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
public slots: |
| 116 |
void changeCurve(int index); |
| 117 |
void indexChanged(int index); |
| 118 |
void mouseReleased(); |
| 119 |
|
| 120 |
private: |
| 121 |
void drawFtable(Curve * curve, int index); |
| 122 |
void drawFtablePath(Curve * curve, int index); |
| 123 |
|
| 124 |
void drawSpectrum(Curve * curve, int index); |
| 125 |
void drawSpectrumPath(Curve * curve, int index); |
| 126 |
|
| 127 |
void drawSignal(Curve * curve, int index); |
| 128 |
void drawSignalPath(Curve * curve, int index); |
| 129 |
|
| 130 |
void scaleGraph(int index); |
| 131 |
int getTableNumForIndex(int index); |
| 132 |
int getIndexForTableNum(int GRAPH_FTABLE); |
| 133 |
void setInternalValue(double value); |
| 134 |
void drawGraph(Curve *curve, int index); |
| 135 |
void showScrollbars(bool show); |
| 136 |
void freezeSpectrum(bool status); |
| 137 |
|
| 138 |
QVector<double> frozenCurve; |
| 139 |
|
| 140 |
QGraphicsView* getView(int index); |
| 141 |
|
| 142 |
QMutex curveLock; |
| 143 |
bool m_grid; |
| 144 |
bool m_logx; |
| 145 |
bool m_logy; |
| 146 |
bool m_drawGrid; |
| 147 |
bool m_drawTableInfo; |
| 148 |
int m_numticksY; |
| 149 |
bool m_showScrollbars; |
| 150 |
double m_showPeakCenterFrequency; |
| 151 |
double m_showPeakRelativeBandwidth; |
| 152 |
bool m_showPeak; |
| 153 |
bool m_showPeakTemp; |
| 154 |
bool m_frozen; |
| 155 |
double m_lastPeakFreq; |
| 156 |
double m_lastTextMarkerY; |
| 157 |
double m_lastTextMarkerX; |
| 158 |
QString m_getPeakChannel; |
| 159 |
MYFLT *m_peakChannelPtr; |
| 160 |
bool m_mouseDragging; |
| 161 |
double m_showPeakTempFrequency; |
| 162 |
double m_dbRange; |
| 163 |
bool m_enableTables; |
| 164 |
bool m_enableDisplays; |
| 165 |
|
| 166 |
|
| 167 |
signals: |
| 168 |
void requestUpdateCurve(Curve *curve); |
| 169 |
|
| 170 |
}; |
| 171 |
|
| 172 |
class StackedLayoutWidget : public QStackedWidget |
| 173 |
{ |
| 174 |
Q_OBJECT |
| 175 |
public: |
| 176 |
StackedLayoutWidget(QWidget* parent) : QStackedWidget(parent) |
| 177 |
{ |
| 178 |
setFrameShape(QFrame::StyledPanel); |
| 179 |
} |
| 180 |
~StackedLayoutWidget() {} |
| 181 |
|
| 182 |
void setWidgetGeometry(int x,int y,int width,int height) |
| 183 |
{ |
| 184 |
setGeometry(x,y,width, height); |
| 185 |
setMaximumSize(width, height); |
| 186 |
} |
| 187 |
|
| 188 |
void clearCurves() |
| 189 |
{ |
| 190 |
QWidget *widget; |
| 191 |
widget = currentWidget(); |
| 192 |
while (widget != nullptr) { |
| 193 |
removeWidget(widget); |
| 194 |
widget = currentWidget(); |
| 195 |
} |
| 196 |
} |
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
}; |
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
class QuteTableWidget : public QWidget { |
| 212 |
Q_OBJECT |
| 213 |
|
| 214 |
public: |
| 215 |
QuteTableWidget(QWidget *parent = nullptr) |
| 216 |
: QWidget(parent) |
| 217 |
, m_tabnum(0) |
| 218 |
, m_ud(nullptr) |
| 219 |
, m_running(false) |
| 220 |
, m_data(nullptr) |
| 221 |
, m_tabsize(0) |
| 222 |
, m_margin(8) |
| 223 |
, m_maxy(1.0) |
| 224 |
, m_miny(-1.0) |
| 225 |
, m_autorange(true) |
| 226 |
, m_showGrid(true) |
| 227 |
, gridFont(QFont("Sans", 8)) |
| 228 |
, gridFontMetrics(QFont("Sans", 8)) |
| 229 |
{} |
| 230 |
virtual ~QuteTableWidget() override; |
| 231 |
void setUserData(CsoundUserData *ud) { |
| 232 |
mutex.lock(); m_ud = ud; mutex.unlock(); } |
| 233 |
void updateData(int tabnum); |
| 234 |
void setRunningStatus(int csoundRunning) { m_running = csoundRunning; } |
| 235 |
int currentTableNumber() { return m_tabnum; } |
| 236 |
void updatePath(); |
| 237 |
void setColor(QColor color) { m_color = color; } |
| 238 |
void setRange(double maxy=1.0); |
| 239 |
void showGrid(bool show) { m_showGrid = show; } |
| 240 |
void reset(); |
| 241 |
void paintGrid(QPainter *painter); |
| 242 |
void stop(CsoundUserData *ud) { |
| 243 |
mutex.lock(); |
| 244 |
m_ud = ud; |
| 245 |
reset(); |
| 246 |
mutex.unlock(); |
| 247 |
} |
| 248 |
|
| 249 |
protected: |
| 250 |
virtual void paintEvent(QPaintEvent *event) override; |
| 251 |
|
| 252 |
private: |
| 253 |
int m_tabnum; |
| 254 |
CsoundUserData *m_ud; |
| 255 |
bool m_running; |
| 256 |
QColor m_color; |
| 257 |
MYFLT *m_data; |
| 258 |
int m_tabsize; |
| 259 |
int m_margin; |
| 260 |
double m_maxy; |
| 261 |
double m_miny; |
| 262 |
bool m_autorange; |
| 263 |
QPainterPath m_path; |
| 264 |
|
| 265 |
QMutex mutex; |
| 266 |
bool m_showGrid; |
| 267 |
QFont gridFont; |
| 268 |
QFontMetrics gridFontMetrics; |
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
}; |
| 273 |
|
| 274 |
|
| 275 |
class QuteTable : public QuteWidget { |
| 276 |
Q_OBJECT |
| 277 |
|
| 278 |
public: |
| 279 |
QuteTable(QWidget *parent); |
| 280 |
~QuteTable(); |
| 281 |
virtual QString getWidgetLine() { return QString(""); } |
| 282 |
virtual QString getWidgetXmlText(); |
| 283 |
virtual QString getWidgetType() { return QString("BSBTableDisplay"); } |
| 284 |
|
| 285 |
virtual void applyInternalProperties(); |
| 286 |
virtual void createPropertiesDialog(); |
| 287 |
virtual void refreshWidget(); |
| 288 |
|
| 289 |
virtual void setCsoundUserData(CsoundUserData *ud); |
| 290 |
virtual void setValue(double value); |
| 291 |
virtual void setValue(QString s); |
| 292 |
virtual void setColor(QColor color); |
| 293 |
void setTableNumber(int tabnum); |
| 294 |
|
| 295 |
public slots: |
| 296 |
void onStop(); |
| 297 |
|
| 298 |
private: |
| 299 |
int m_tabnum; |
| 300 |
|
| 301 |
protected: |
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
virtual void applyProperties(); |
| 306 |
SelectColorButton *colorButton; |
| 307 |
QCheckBox *rangeCheckBox; |
| 308 |
QDoubleSpinBox *rangeSpinBox; |
| 309 |
QCheckBox *gridCheckBox; |
| 310 |
QMutex mutex; |
| 311 |
bool m_csoundRunning; |
| 312 |
|
| 313 |
}; |
| 314 |
|
| 315 |
class SpectralView : public QGraphicsView { |
| 316 |
Q_OBJECT |
| 317 |
|
| 318 |
public: |
| 319 |
|
| 320 |
SpectralView(QWidget *parent) : QGraphicsView(parent) {} |
| 321 |
|
| 322 |
~SpectralView(); |
| 323 |
|
| 324 |
virtual void mouseReleaseEvent(QMouseEvent *ev); |
| 325 |
|
| 326 |
|
| 327 |
signals: |
| 328 |
void mouseReleased(); |
| 329 |
|
| 330 |
}; |
| 331 |
|
| 332 |
|
| 333 |
#endif |