channel.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #include "stdafx.h"
  2. #include "channel.h"
  3. #include "curve.h"
  4. Channel::Channel(int channel, ChannelSettings& channelSettings, QWidget* parent)
  5. : QWidget(parent)
  6. , _channel(channel)
  7. , _channelSettings(channelSettings)
  8. , _curvePlot(new QCustomPlot(this))
  9. {
  10. ui.setupUi(this);
  11. _curvePlot->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
  12. ui.layoutCurvePlot->addWidget(_curvePlot);
  13. QStringList notes;
  14. notes << "C" << "C#" << "D" << "D#" << "E" << "F" << "F#" << "G" << "G#" << "A" << "A#" << "B";
  15. QStringList oktaves;
  16. for(int i = 0; i < 128; ++i) {
  17. oktaves << QString::number(int(i / 12) - 1) + " " + notes[i % 12] + "";
  18. }
  19. ui.cbNote->clear();
  20. ui.cbNote->addItems(oktaves);
  21. _curvePlot->addGraph();
  22. _curvePlot->xAxis->setRange(0, 127);
  23. _curvePlot->yAxis->setRange(0, 127);
  24. _curvePlot->setMinimumHeight(60);
  25. //auto thresholdCurve = _curvePlot->addGraph(_curvePlot->xAxis, _curvePlot->yAxis);
  26. //thresholdCurve->setPen(QPen(Qt::red));
  27. _curvePlot->axisRect()->setAutoMargins(QCP::msNone);
  28. _curvePlot->axisRect()->setMargins(QMargins(1, 1, 1, 1));
  29. ui.leName->setPlaceholderText("Channel " + QString::number(channel + 1));
  30. update();
  31. connect(ui.cbSensor, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), [this](int index) {_channelSettings.type = (Type)index; update(); });
  32. connect(ui.cbNote, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), [this](int index) {_channelSettings.note = index; update(); });
  33. connect(ui.dialThreshold, &QDial::valueChanged, [this](int value) {_channelSettings.threshold = value; update(); });
  34. connect(ui.dialScanTime, &QDial::valueChanged, [this](int value) {_channelSettings.scanTime = value; update(); });
  35. connect(ui.dialMaskTime, &QDial::valueChanged, [this](int value) {_channelSettings.maskTime = value; update(); });
  36. connect(ui.cbCurveType, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), [this](int index) { _channelSettings.curve.type = (Curve)index; update(); });
  37. connect(ui.dialValue, &QDial::valueChanged, [this](int value) {_channelSettings.curve.value = value; update(); });
  38. connect(ui.dialOffset, &QDial::valueChanged, [this](int value) {_channelSettings.curve.offset = value; update(); });
  39. connect(ui.dialFactor, &QDial::valueChanged, [this](int value) {_channelSettings.curve.factor = value; update(); });
  40. }
  41. Channel::~Channel()
  42. {
  43. }
  44. void Channel::update()
  45. {
  46. ui.cbSensor->setCurrentIndex(_channelSettings.type);
  47. ui.cbNote->setCurrentIndex(_channelSettings.note);
  48. //ui.labelThreshold->setText(QString::number(_channelSettings.threshold));
  49. ui.dialThreshold->setValue(_channelSettings.threshold);
  50. //ui.labelScanTime->setText(QString::number(_channelSettings.scanTime));
  51. ui.dialScanTime->setValue(_channelSettings.scanTime);
  52. //ui.labelMaskTime->setText(QString::number(_channelSettings.maskTime));
  53. ui.dialMaskTime->setValue(_channelSettings.maskTime);
  54. ui.cbCurveType->setCurrentIndex(_channelSettings.curve.type);
  55. //ui.labelValue->setText(QString::number(_channelSettings.curveValue));
  56. ui.dialValue->setValue(_channelSettings.curve.value);
  57. //ui.labelOffset->setText(QString::number(_channelSettings.curveOffset));
  58. ui.dialOffset->setValue(_channelSettings.curve.offset);
  59. //ui.labelFactor->setText(QString::number(_channelSettings.curveFactor));
  60. ui.dialFactor->setValue(_channelSettings.curve.factor);
  61. {
  62. QVector<qreal> x(128);
  63. QVector<qreal> y(128);
  64. for(auto i = 0; i < 128; ++i) {
  65. x[i] = i;
  66. y[i] = calcCurve(_channelSettings.curve, i) ;
  67. }
  68. _curvePlot->graph(0)->setData(x, y);
  69. }
  70. //{
  71. // QVector<qreal> x(2);
  72. // QVector<qreal> y(2);
  73. //
  74. // x[0] = 0;
  75. // x[1] = 127;
  76. // y[0] = _channelSettings.threshold;
  77. // y[1] = _channelSettings.threshold;
  78. // _curvePlot->graph(1)->setData(x, y);
  79. //}
  80. _curvePlot->replot();
  81. }