1
1

channel.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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.leName, &QLineEdit::editingFinished, [this]() {
  32. auto name = ui.leName->text();
  33. memset(_channelSettings.name, 0, sizeof(_channelSettings.name));
  34. auto size = std::min((size_t)name.size() * sizeof(QChar), sizeof(_channelSettings.name) - 1);
  35. memcpy(_channelSettings.name, name.data(), size);
  36. update();
  37. });
  38. connect(ui.cbSensor, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), [this](int index) {_channelSettings.type = (Type)index; update(); });
  39. connect(ui.cbNote, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), [this](int index) {_channelSettings.note = index; update(); });
  40. connect(ui.dialThreshold, &QDial::valueChanged, [this](int value) {_channelSettings.threshold = value; update(); });
  41. connect(ui.dialScanTime, &QDial::valueChanged, [this](int value) {_channelSettings.scanTime = value; update(); });
  42. connect(ui.dialMaskTime, &QDial::valueChanged, [this](int value) {_channelSettings.maskTime = value; update(); });
  43. connect(ui.cbCurveType, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), [this](int index) { _channelSettings.curve.type = (Curve)index; update(); });
  44. connect(ui.dialValue, &QDial::valueChanged, [this](int value) {_channelSettings.curve.value = value; update(); });
  45. connect(ui.dialOffset, &QDial::valueChanged, [this](int value) {_channelSettings.curve.offset = value; update(); });
  46. connect(ui.dialFactor, &QDial::valueChanged, [this](int value) {_channelSettings.curve.factor = value; update(); });
  47. }
  48. Channel::~Channel()
  49. {
  50. }
  51. void Channel::update()
  52. {
  53. QString name(_channelSettings.name);
  54. ui.leName->setText(name);
  55. ui.cbSensor->setCurrentIndex(_channelSettings.type);
  56. ui.cbNote->setCurrentIndex(_channelSettings.note);
  57. //ui.labelThreshold->setText(QString::number(_channelSettings.threshold));
  58. ui.dialThreshold->setValue(_channelSettings.threshold);
  59. //ui.labelScanTime->setText(QString::number(_channelSettings.scanTime));
  60. ui.dialScanTime->setValue(_channelSettings.scanTime);
  61. //ui.labelMaskTime->setText(QString::number(_channelSettings.maskTime));
  62. ui.dialMaskTime->setValue(_channelSettings.maskTime);
  63. ui.cbCurveType->setCurrentIndex(_channelSettings.curve.type);
  64. //ui.labelValue->setText(QString::number(_channelSettings.curveValue));
  65. ui.dialValue->setValue(_channelSettings.curve.value);
  66. //ui.labelOffset->setText(QString::number(_channelSettings.curveOffset));
  67. ui.dialOffset->setValue(_channelSettings.curve.offset);
  68. //ui.labelFactor->setText(QString::number(_channelSettings.curveFactor));
  69. ui.dialFactor->setValue(_channelSettings.curve.factor);
  70. {
  71. QVector<qreal> x(128);
  72. QVector<qreal> y(128);
  73. for(auto i = 0; i < 128; ++i) {
  74. x[i] = i;
  75. y[i] = calcCurve(_channelSettings.curve, i) ;
  76. }
  77. _curvePlot->graph(0)->setData(x, y);
  78. }
  79. //{
  80. // QVector<qreal> x(2);
  81. // QVector<qreal> y(2);
  82. //
  83. // x[0] = 0;
  84. // x[1] = 127;
  85. // y[0] = _channelSettings.threshold;
  86. // y[1] = _channelSettings.threshold;
  87. // _curvePlot->graph(1)->setData(x, y);
  88. //}
  89. _curvePlot->replot();
  90. }