1
1

channel.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. //QPalette::ColorRole
  12. ui.dialFactor->setBackgroundRole(QPalette::ColorRole::Highlight);
  13. //ui.dialFactor->setPalette(qApp->palette());
  14. QGraphicsDropShadowEffect* effect = new QGraphicsDropShadowEffect();
  15. effect->setBlurRadius(30);
  16. effect->setOffset(0, 0);
  17. ui.btnSumScan->setGraphicsEffect(effect);
  18. _curvePlot->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
  19. _curvePlot->setBackground(qApp->palette().button());
  20. QPen pen(qApp->palette().midlight().color());
  21. pen.setStyle(Qt::PenStyle::DotLine);
  22. _curvePlot->xAxis->grid()->setPen(pen);
  23. _curvePlot->yAxis->grid()->setPen(pen);
  24. _curvePlot->xAxis2->grid()->setPen(pen);
  25. _curvePlot->yAxis2->grid()->setPen(pen);
  26. _curvePlot->xAxis->setTicks(false);
  27. _curvePlot->yAxis->setTicks(false);
  28. _curvePlot->xAxis2->setTicks(false);
  29. _curvePlot->yAxis2->setTicks(false);
  30. ui.layoutCurvePlot->addWidget(_curvePlot);
  31. QStringList notes;
  32. notes << "C" << "C#" << "D" << "D#" << "E" << "F" << "F#" << "G" << "G#" << "A" << "A#" << "B";
  33. QStringList oktaves;
  34. for(int i = 0; i < 128; ++i) {
  35. oktaves << QString::number(int(i / 12) - 1) + " " + notes[i % 12] + "";
  36. }
  37. ui.cbNote->clear();
  38. ui.cbNote->addItems(oktaves);
  39. auto curve = _curvePlot->addGraph();
  40. curve->setPen(QPen(qApp->palette().buttonText().color()));
  41. _curvePlot->xAxis->setRange(0, 127);
  42. _curvePlot->yAxis->setRange(0, 127);
  43. _curvePlot->setMinimumHeight(60);
  44. //auto thresholdCurve = _curvePlot->addGraph(_curvePlot->xAxis, _curvePlot->yAxis);
  45. //thresholdCurve->setPen(QPen(Qt::red));
  46. _curvePlot->axisRect()->setAutoMargins(QCP::msNone);
  47. _curvePlot->axisRect()->setMargins(QMargins(1, 1, 1, 1));
  48. ui.leName->setPlaceholderText("Channel " + QString::number(channel + 1));
  49. update();
  50. connect(ui.leName, &QLineEdit::editingFinished, [this]() {
  51. auto name = ui.leName->text();
  52. memset(_channelSettings.name, 0, sizeof(_channelSettings.name));
  53. auto size = std::min((size_t)name.size() * sizeof(QChar), sizeof(_channelSettings.name) - 1);
  54. memcpy(_channelSettings.name, name.data(), size);
  55. update();
  56. });
  57. connect(ui.cbSensor, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), [this](int index) {_channelSettings.type = (Type)index; update(); });
  58. connect(ui.cbNote, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), [this](int index) {_channelSettings.note = index; update(); });
  59. connect(ui.dialThreshold, &QDial::valueChanged, [this](int value) {_channelSettings.threshold = value; update(); });
  60. connect(ui.btnSumScan, &QPushButton::toggled, [this](bool checked) {_channelSettings.sum = checked; update(); });
  61. connect(ui.dialScanTime, &QDial::valueChanged, [this](int value) {_channelSettings.scanTime = value; update(); });
  62. connect(ui.dialMaskTime, &QDial::valueChanged, [this](int value) {_channelSettings.maskTime = value; update(); });
  63. connect(ui.cbCurveType, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), [this](int index) { _channelSettings.curve.type = (Curve)index; update(); });
  64. connect(ui.dialValue, &QDial::valueChanged, [this](int value) {_channelSettings.curve.value = value; update(); });
  65. connect(ui.dialOffset, &QDial::valueChanged, [this](int value) {_channelSettings.curve.offset = value; update(); });
  66. connect(ui.dialFactor, &QDial::valueChanged, [this](int value) {_channelSettings.curve.factor = value; update(); });
  67. }
  68. Channel::~Channel()
  69. {
  70. }
  71. void Channel::update()
  72. {
  73. QString name(_channelSettings.name);
  74. ui.leName->setText(name);
  75. ui.cbSensor->setCurrentIndex(_channelSettings.type);
  76. ui.cbNote->setCurrentIndex(_channelSettings.note);
  77. ui.dialThreshold->setValue(_channelSettings.threshold);
  78. ui.btnSumScan->setChecked(_channelSettings.sum);
  79. ui.dialScanTime->setValue(_channelSettings.scanTime);
  80. ui.dialMaskTime->setValue(_channelSettings.maskTime);
  81. ui.cbCurveType->setCurrentIndex(_channelSettings.curve.type);
  82. ui.dialValue->setValue(_channelSettings.curve.value);
  83. ui.dialOffset->setValue(_channelSettings.curve.offset);
  84. ui.dialFactor->setValue(_channelSettings.curve.factor);
  85. auto effect = static_cast<QGraphicsDropShadowEffect*>(ui.btnSumScan->graphicsEffect());
  86. if(_channelSettings.sum) {
  87. effect->setColor(QColor(0xff9966));
  88. }
  89. else {
  90. effect->setColor(QColor(0, 0, 0, 0));
  91. }
  92. {
  93. QVector<qreal> x(128);
  94. QVector<qreal> y(128);
  95. for(auto i = 0; i < 128; ++i) {
  96. x[i] = i;
  97. y[i] = calcCurve(_channelSettings.curve, i) ;
  98. }
  99. _curvePlot->graph(0)->setData(x, y);
  100. }
  101. //{
  102. // QVector<qreal> x(2);
  103. // QVector<qreal> y(2);
  104. //
  105. // x[0] = 0;
  106. // x[1] = 127;
  107. // y[0] = _channelSettings.threshold;
  108. // y[1] = _channelSettings.threshold;
  109. // _curvePlot->graph(1)->setData(x, y);
  110. //}
  111. _curvePlot->replot();
  112. }