1
1

channel.cpp 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. ui.layoutCurvePlot->addWidget(_curvePlot);
  12. QStringList notes;
  13. notes << "C" << "C#" << "D" << "D#" << "E" << "F" << "F#" << "G" << "G#" << "A" << "A#" << "B";
  14. QStringList oktaves;
  15. for(int i = 0; i < 128; ++i) {
  16. oktaves << QString::number(int(i / 12) - 1) + " " + notes[i % 12] + "";
  17. }
  18. ui.cbNote->clear();
  19. ui.cbNote->addItems(oktaves);
  20. _curvePlot->addGraph();
  21. _curvePlot->xAxis->setRange(0, 127);
  22. _curvePlot->yAxis->setRange(0, 127);
  23. _curvePlot->setMinimumHeight(60);
  24. _curvePlot->axisRect()->setAutoMargins(QCP::msNone);
  25. _curvePlot->axisRect()->setMargins(QMargins(1, 1, 1, 1));
  26. ui.leName->setPlaceholderText("Channel " + QString::number(channel));
  27. updateUi();
  28. connect(ui.cbSensor, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), [this](int index) {_channelSettings.type = (Type)index; updateUi(); });
  29. connect(ui.cbNote, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), [this](int index) {_channelSettings.note = index; updateUi(); });
  30. connect(ui.dialThresold, &QDial::valueChanged, [this](int value) {_channelSettings.thresold = value; updateUi(); });
  31. connect(ui.dialScanTime, &QDial::valueChanged, [this](int value) {_channelSettings.scanTime = value; updateUi(); });
  32. connect(ui.dialMaskTime, &QDial::valueChanged, [this](int value) {_channelSettings.maskTime = value; updateUi(); });
  33. connect(ui.cbCurveType, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), [this](int index) { _channelSettings.curveType = (Curve)index; updateUi(); });
  34. connect(ui.dialOffset, &QDial::valueChanged, [this](int value) {_channelSettings.curveValue = value; updateUi(); });
  35. }
  36. Channel::~Channel()
  37. {
  38. }
  39. void Channel::updateUi()
  40. {
  41. ui.cbSensor->setCurrentIndex(_channelSettings.type);
  42. ui.cbNote->setCurrentIndex(_channelSettings.note);
  43. ui.labelThresold->setText(QString::number(_channelSettings.thresold));
  44. ui.dialThresold->setValue(_channelSettings.thresold);
  45. ui.labelScanTime->setText(QString::number(_channelSettings.scanTime));
  46. ui.dialScanTime->setValue(_channelSettings.scanTime);
  47. ui.labelMaskTime->setText(QString::number(_channelSettings.maskTime));
  48. ui.dialMaskTime->setValue(_channelSettings.maskTime);
  49. ui.cbCurveType->setCurrentIndex(_channelSettings.curveType);
  50. ui.labelOffset->setText(QString::number(_channelSettings.curveValue));
  51. ui.dialOffset->setValue(_channelSettings.curveValue);
  52. QVector<qreal> x(127);
  53. QVector<qreal> y(127);
  54. for(auto i = 0; i < 127; ++i) {
  55. x[i] = i;
  56. y[i] = calcCurve(_channelSettings.curveType, i, _channelSettings.curveValue);
  57. }
  58. _curvePlot->graph(0)->setData(x, y);
  59. _curvePlot->replot();
  60. }