1
1
Zoadian 11 жил өмнө
parent
commit
bf4d165a83

+ 37 - 7
drumduino/channel.cpp

@@ -13,7 +13,27 @@ Channel::Channel(int channel, ChannelSettings& channelSettings, QWidget* parent)
 {
 	ui.setupUi(this);
 
+	//QPalette::ColorRole
+	ui.dialFactor->setBackgroundRole(QPalette::ColorRole::Highlight);
+	//ui.dialFactor->setPalette(qApp->palette());
+
+	QGraphicsDropShadowEffect* effect = new QGraphicsDropShadowEffect();
+	effect->setBlurRadius(30);
+	effect->setOffset(0, 0);
+	ui.btnSumScan->setGraphicsEffect(effect);
+
 	_curvePlot->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
+	_curvePlot->setBackground(qApp->palette().button());
+	QPen pen(qApp->palette().midlight().color());
+	pen.setStyle(Qt::PenStyle::DotLine);
+	_curvePlot->xAxis->grid()->setPen(pen);
+	_curvePlot->yAxis->grid()->setPen(pen);
+	_curvePlot->xAxis2->grid()->setPen(pen);
+	_curvePlot->yAxis2->grid()->setPen(pen);
+	_curvePlot->xAxis->setTicks(false);
+	_curvePlot->yAxis->setTicks(false);
+	_curvePlot->xAxis2->setTicks(false);
+	_curvePlot->yAxis2->setTicks(false);
 	ui.layoutCurvePlot->addWidget(_curvePlot);
 
 	QStringList notes;
@@ -25,10 +45,12 @@ Channel::Channel(int channel, ChannelSettings& channelSettings, QWidget* parent)
 		oktaves << QString::number(int(i / 12) - 1) + " " + notes[i % 12] + "";
 	}
 
+
 	ui.cbNote->clear();
 	ui.cbNote->addItems(oktaves);
 
-	_curvePlot->addGraph();
+	auto curve = _curvePlot->addGraph();
+	curve->setPen(QPen(qApp->palette().buttonText().color()));
 	_curvePlot->xAxis->setRange(0, 127);
 	_curvePlot->yAxis->setRange(0, 127);
 	_curvePlot->setMinimumHeight(60);
@@ -57,6 +79,8 @@ Channel::Channel(int channel, ChannelSettings& channelSettings, QWidget* parent)
 
 	connect(ui.dialThreshold, &QDial::valueChanged, [this](int value) {_channelSettings.threshold = value; update(); });
 
+	connect(ui.btnSumScan, &QPushButton::toggled, [this](bool checked) {_channelSettings.sum = checked; update(); });
+
 	connect(ui.dialScanTime, &QDial::valueChanged, [this](int value) {_channelSettings.scanTime = value; update(); });
 
 	connect(ui.dialMaskTime, &QDial::valueChanged, [this](int value) {_channelSettings.maskTime = value; update(); });
@@ -85,26 +109,32 @@ void Channel::update()
 
 	ui.cbNote->setCurrentIndex(_channelSettings.note);
 
-	//ui.labelThreshold->setText(QString::number(_channelSettings.threshold));
 	ui.dialThreshold->setValue(_channelSettings.threshold);
 
-	//ui.labelScanTime->setText(QString::number(_channelSettings.scanTime));
+	ui.btnSumScan->setChecked(_channelSettings.sum);
+
 	ui.dialScanTime->setValue(_channelSettings.scanTime);
 
-	//ui.labelMaskTime->setText(QString::number(_channelSettings.maskTime));
 	ui.dialMaskTime->setValue(_channelSettings.maskTime);
 
 	ui.cbCurveType->setCurrentIndex(_channelSettings.curve.type);
 
-	//ui.labelValue->setText(QString::number(_channelSettings.curveValue));
 	ui.dialValue->setValue(_channelSettings.curve.value);
 
-	//ui.labelOffset->setText(QString::number(_channelSettings.curveOffset));
 	ui.dialOffset->setValue(_channelSettings.curve.offset);
 
-	//ui.labelFactor->setText(QString::number(_channelSettings.curveFactor));
 	ui.dialFactor->setValue(_channelSettings.curve.factor);
 
+	auto effect = static_cast<QGraphicsDropShadowEffect*>(ui.btnSumScan->graphicsEffect());
+
+	if(_channelSettings.sum) {
+		effect->setColor(QColor(0xff9966));
+	}
+
+	else {
+		effect->setColor(QColor(0, 0, 0, 0));
+	}
+
 	{
 		QVector<qreal> x(128);
 		QVector<qreal> y(128);

+ 7 - 0
drumduino/channel.h

@@ -24,6 +24,13 @@ private:
 
 public:
 	void update();
+
+	void triggered(byte maxValue, byte sumValue, byte calcValue)
+	{
+		ui.pbMax->setValue(maxValue);
+		ui.pbSum->setValue(sumValue);
+		ui.pbOut->setValue(calcValue);
+	}
 };
 
 #endif // CHANNEL_H

+ 180 - 45
drumduino/channel.ui

@@ -7,7 +7,7 @@
     <x>0</x>
     <y>0</y>
     <width>144</width>
-    <height>492</height>
+    <height>626</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -76,10 +76,19 @@
    </item>
    <item>
     <widget class="QGroupBox" name="groupBox">
+     <property name="layoutDirection">
+      <enum>Qt::LeftToRight</enum>
+     </property>
      <property name="title">
       <string>Sensor</string>
      </property>
+     <property name="alignment">
+      <set>Qt::AlignCenter</set>
+     </property>
      <layout class="QGridLayout" name="gridLayout_3">
+      <property name="sizeConstraint">
+       <enum>QLayout::SetDefaultConstraint</enum>
+      </property>
       <item row="1" column="0">
        <widget class="QDial" name="dialThreshold">
         <property name="sizePolicy">
@@ -108,7 +117,17 @@
         </property>
        </widget>
       </item>
-      <item row="3" column="0">
+      <item row="0" column="0">
+       <widget class="QLabel" name="label_21">
+        <property name="text">
+         <string>Threshold</string>
+        </property>
+        <property name="alignment">
+         <set>Qt::AlignCenter</set>
+        </property>
+       </widget>
+      </item>
+      <item row="4" column="0">
        <widget class="QDial" name="dialScanTime">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
@@ -136,27 +155,33 @@
         </property>
        </widget>
       </item>
-      <item row="0" column="0">
-       <widget class="QLabel" name="label_21">
+      <item row="2" column="0">
+       <widget class="QLabel" name="label_8">
         <property name="text">
-         <string>Threshold</string>
+         <string>Scan</string>
         </property>
         <property name="alignment">
          <set>Qt::AlignCenter</set>
         </property>
        </widget>
       </item>
-      <item row="2" column="0">
-       <widget class="QLabel" name="label_8">
+      <item row="2" column="1">
+       <widget class="QLabel" name="label_11">
+        <property name="maximumSize">
+         <size>
+          <width>16777215</width>
+          <height>16777215</height>
+         </size>
+        </property>
         <property name="text">
-         <string>Scan</string>
+         <string>Mask</string>
         </property>
         <property name="alignment">
          <set>Qt::AlignCenter</set>
         </property>
        </widget>
       </item>
-      <item row="3" column="1">
+      <item row="4" column="1">
        <widget class="QDial" name="dialMaskTime">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
@@ -173,6 +198,9 @@
         <property name="toolTip">
          <string>how many samples will be ignored after a note was played.</string>
         </property>
+        <property name="layoutDirection">
+         <enum>Qt::LeftToRight</enum>
+        </property>
         <property name="maximum">
          <number>127</number>
         </property>
@@ -184,10 +212,51 @@
         </property>
        </widget>
       </item>
-      <item row="2" column="1">
-       <widget class="QLabel" name="label_11">
+      <item row="1" column="1">
+       <widget class="QPushButton" name="btnSumScan">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
+        </property>
+        <property name="maximumSize">
+         <size>
+          <width>50</width>
+          <height>50</height>
+         </size>
+        </property>
+        <property name="font">
+         <font>
+          <pointsize>12</pointsize>
+          <weight>50</weight>
+          <bold>false</bold>
+         </font>
+        </property>
+        <property name="styleSheet">
+         <string notr="true">QPushButton { margin:9px 6px 9px 6px;  padding-bottom:2px; } QPushButton:checked {  background-color: #ff9966; }</string>
+        </property>
         <property name="text">
-         <string>Mask</string>
+         <string>∑</string>
+        </property>
+        <property name="checkable">
+         <bool>true</bool>
+        </property>
+        <property name="checked">
+         <bool>false</bool>
+        </property>
+        <property name="autoExclusive">
+         <bool>false</bool>
+        </property>
+        <property name="flat">
+         <bool>false</bool>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="1">
+       <widget class="QLabel" name="label_4">
+        <property name="text">
+         <string>Sum</string>
         </property>
         <property name="alignment">
          <set>Qt::AlignCenter</set>
@@ -199,18 +268,23 @@
      <zorder>dialThreshold</zorder>
      <zorder>label_8</zorder>
      <zorder>dialScanTime</zorder>
-     <zorder>dialMaskTime</zorder>
      <zorder>label_11</zorder>
+     <zorder>btnSumScan</zorder>
+     <zorder>dialMaskTime</zorder>
+     <zorder>label_4</zorder>
     </widget>
    </item>
    <item>
     <widget class="QGroupBox" name="groupBox_2">
      <property name="title">
-      <string>Curve</string>
+      <string>Curve Form</string>
+     </property>
+     <property name="alignment">
+      <set>Qt::AlignCenter</set>
      </property>
      <layout class="QGridLayout" name="gridLayout_2">
-      <item row="2" column="0">
-       <widget class="QDial" name="dialValue">
+      <item row="5" column="1">
+       <widget class="QDial" name="dialFactor">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
           <horstretch>0</horstretch>
@@ -223,8 +297,8 @@
           <height>50</height>
          </size>
         </property>
-        <property name="toolTip">
-         <string>change the shape of the curve</string>
+        <property name="minimum">
+         <number>0</number>
         </property>
         <property name="maximum">
          <number>127</number>
@@ -304,31 +378,8 @@
         </property>
        </widget>
       </item>
-      <item row="8" column="0" colspan="2">
-       <layout class="QVBoxLayout" name="layoutCurvePlot"/>
-      </item>
-      <item row="4" column="0">
-       <widget class="QLabel" name="label">
-        <property name="text">
-         <string>Y-Offset</string>
-        </property>
-        <property name="alignment">
-         <set>Qt::AlignCenter</set>
-        </property>
-       </widget>
-      </item>
-      <item row="4" column="1">
-       <widget class="QLabel" name="label_2">
-        <property name="text">
-         <string>Y-Factor</string>
-        </property>
-        <property name="alignment">
-         <set>Qt::AlignCenter</set>
-        </property>
-       </widget>
-      </item>
-      <item row="5" column="1">
-       <widget class="QDial" name="dialFactor">
+      <item row="2" column="0">
+       <widget class="QDial" name="dialValue">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
           <horstretch>0</horstretch>
@@ -341,8 +392,8 @@
           <height>50</height>
          </size>
         </property>
-        <property name="minimum">
-         <number>0</number>
+        <property name="toolTip">
+         <string>change the shape of the curve</string>
         </property>
         <property name="maximum">
          <number>127</number>
@@ -355,6 +406,29 @@
         </property>
        </widget>
       </item>
+      <item row="4" column="1">
+       <widget class="QLabel" name="label_2">
+        <property name="text">
+         <string>Y-Factor</string>
+        </property>
+        <property name="alignment">
+         <set>Qt::AlignCenter</set>
+        </property>
+       </widget>
+      </item>
+      <item row="4" column="0">
+       <widget class="QLabel" name="label">
+        <property name="text">
+         <string>Y-Offset</string>
+        </property>
+        <property name="alignment">
+         <set>Qt::AlignCenter</set>
+        </property>
+       </widget>
+      </item>
+      <item row="8" column="0" colspan="2">
+       <layout class="QVBoxLayout" name="layoutCurvePlot"/>
+      </item>
      </layout>
      <zorder>cbCurveType</zorder>
      <zorder>dialOffset</zorder>
@@ -363,6 +437,67 @@
      <zorder>label</zorder>
      <zorder>label_2</zorder>
      <zorder>dialFactor</zorder>
+     <zorder></zorder>
+    </widget>
+   </item>
+   <item>
+    <widget class="QGroupBox" name="groupBox_3">
+     <property name="alignment">
+      <set>Qt::AlignCenter</set>
+     </property>
+     <layout class="QHBoxLayout" name="horizontalLayout">
+      <item>
+       <widget class="QProgressBar" name="pbMax">
+        <property name="maximum">
+         <number>127</number>
+        </property>
+        <property name="value">
+         <number>24</number>
+        </property>
+        <property name="textVisible">
+         <bool>false</bool>
+        </property>
+        <property name="orientation">
+         <enum>Qt::Vertical</enum>
+        </property>
+       </widget>
+      </item>
+      <item>
+       <widget class="QProgressBar" name="pbSum">
+        <property name="maximum">
+         <number>127</number>
+        </property>
+        <property name="value">
+         <number>24</number>
+        </property>
+        <property name="textVisible">
+         <bool>false</bool>
+        </property>
+        <property name="orientation">
+         <enum>Qt::Vertical</enum>
+        </property>
+       </widget>
+      </item>
+      <item>
+       <widget class="QProgressBar" name="pbOut">
+        <property name="styleSheet">
+         <string notr="true"/>
+        </property>
+        <property name="maximum">
+         <number>127</number>
+        </property>
+        <property name="value">
+         <number>24</number>
+        </property>
+        <property name="textVisible">
+         <bool>false</bool>
+        </property>
+        <property name="orientation">
+         <enum>Qt::Vertical</enum>
+        </property>
+       </widget>
+      </item>
+     </layout>
     </widget>
    </item>
   </layout>

+ 144 - 73
drumduino/drumduino.cpp

@@ -16,6 +16,11 @@ size_t mapChannels(size_t channel)
 	return port * CHAN_CNT + pinMapping[chan];
 }
 
+unsigned long g_lastTime = 0;
+
+uint64_t g_timeSum = 0;
+uint64_t g_frameTime = 0;
+
 bool readNextFrame(std::shared_ptr<Serial>& serial, DrumduinoProc& proc)
 {
 AGAIN:
@@ -26,17 +31,28 @@ AGAIN:
 	}
 
 	byte sentinel;
-	serial->readBytes(&sentinel, 1);
+	serial->readBytes(&sentinel, sizeof(sentinel));
 
 	if(sentinel != 0xf0) {
 		goto AGAIN;
 	}
 
 	byte manufacturer;
-	serial->readBytes(&manufacturer, 1);
+	serial->readBytes(&manufacturer, sizeof(manufacturer));
+
+	unsigned long time1;
+	serial->readBytes((byte*)&time1, sizeof(time1));
+
+	unsigned long time2;
+	serial->readBytes((byte*)&time2, sizeof(time2));
+
 
-	unsigned long time;
-	serial->readBytes((byte*)&time, sizeof(unsigned long));
+	auto timeDiff1 = time1 - g_lastTime;
+	auto timeDiff2 = time2 - time1;
+
+	g_lastTime = time2;
+	g_frameTime = timeDiff1 + timeDiff2;
+	g_timeSum += g_frameTime;
 
 	auto& frame = proc.frameBuffer[proc.frameCounter % BufferSize];
 	serial->readBytes(frame.data(), frame.size());
@@ -58,7 +74,7 @@ void midiNoteOn(std::shared_ptr<MidiOut>& midiOut, byte channel, byte note, byte
 	midiOut->send(message);
 }
 
-void processFrame(std::shared_ptr<MidiOut>& midiOut, DrumduinoProc& proc, const Settings& settings)
+void processFrame(DrumduinoProc& proc, const Settings& settings, std::function<void(size_t channel, byte maxValue, byte sumValue)> fnOnNote)
 {
 	const auto& lastFrame = proc.frameBuffer[(proc.frameCounter - 1) % BufferSize];
 	const auto& currentFrame = proc.frameBuffer[proc.frameCounter % BufferSize];
@@ -70,6 +86,7 @@ void processFrame(std::shared_ptr<MidiOut>& midiOut, DrumduinoProc& proc, const
 		auto& state = proc.states[channel];
 		auto& triggerFrame = proc.triggers[channel];
 		auto& maxValue = proc.maxs[channel];
+		auto& sumValue = proc.sums[channel];
 
 		const auto& channelSettings = settings.channelSettings[channel];
 
@@ -87,6 +104,7 @@ STATE_AGAIN:
 						state = StateScan;
 						triggerFrame = proc.frameCounter;
 						maxValue = currentValue;
+						sumValue = currentValue;
 						//fallthrough
 					}
 
@@ -94,10 +112,11 @@ STATE_AGAIN:
 					case StateScan: {
 						if(proc.frameCounter < triggerFrame + channelSettings.scanTime) {
 							maxValue = std::max(currentValue, maxValue);
+							sumValue += currentValue;
 							break;
 						}
 
-						midiNoteOn(midiOut, settings.midiChannel, channelSettings.note, calcCurve(channelSettings.curve, maxValue));
+						fnOnNote(channel, maxValue, sumValue / channelSettings.scanTime);
 						state = StateMask;
 						//fallthrough
 
@@ -175,96 +194,148 @@ Drumduino::Drumduino(QWidget* parent)
 	});
 
 
+	connect(this, &Drumduino::updateChannelProgess, this, &Drumduino::slotUpdateChannelProgress, Qt::QueuedConnection);
+
+	try {
+		//_serial = std::make_shared<Serial>(L"COM3", 115200);
+		_serial = std::make_shared<Serial>(L"COM3", 2000000);
+		_midiOut = std::make_shared<MidiOut>(1);
+
+
+		_drumduinoThread = new DrumduinoThread(this, [this]() {
+			if(readNextFrame(_serial, _proc)) {
+				processFrame(_proc, _settings, [this](size_t channel, byte maxValue, byte sumValue) {
+					const auto& channelSettings = _settings.channelSettings[channel];
 
-	_serial = std::make_shared<Serial>(L"COM3", 115200);
-	_midiOut = std::make_shared<MidiOut>(1);
+					auto calcValue = 0;
 
+					if(channelSettings.sum) {
+						calcValue = calcCurve(channelSettings.curve, sumValue * 2);
+					}
+
+					else {
+						calcValue = calcCurve(channelSettings.curve, maxValue);
+					}
 
-	_drumduinoThread = new DrumduinoThread(this, [this]() {
-		if(readNextFrame(_serial, _proc)) {
-			processFrame(_midiOut, _proc, _settings);
+					midiNoteOn(_midiOut, _settings.midiChannel, channelSettings.note, calcValue);
+					emit updateChannelProgess(channel, maxValue, sumValue, calcValue);
+				});
 
 #if 1
-			_proc.stateBuffer[_proc.frameCounter % BufferSize] = _proc.states;
+				_proc.stateBuffer[_proc.frameCounter % BufferSize] = _proc.states;
 #endif
 
-			++_proc.frameCounter;
-		}
-	});
-	_drumduinoThread->start();
+				++_proc.frameCounter;
+			}
+		});
+		_drumduinoThread->start();
 
 
 
 #if 1
-	{
-		std::array<QCustomPlot*, PORT_CNT* CHAN_CNT> plots;
-
-		for(auto port = 0; port < PORT_CNT; ++port) {
-			auto wgtPort = ui.tabWidget->widget(ui.tabWidget->addTab(new PortTab(), "Graph_Port " + QString::number(port)));
-
-			auto table = new QTableWidget(CHAN_CNT, 1, wgtPort);
-			table->horizontalHeader()->setStretchLastSection(true);
-			table->verticalHeader()->setMinimumHeight(100);
-			table->horizontalHeader()->setVisible(false);
-			wgtPort->layout()->addWidget(table);
-
-			for(auto pin = 0; pin < CHAN_CNT; ++pin) {
-				auto channel = port * CHAN_CNT + pin;
-				auto wgtPlot = new QCustomPlot(table);
-				wgtPlot->addGraph();
-				table->setRowHeight(pin, 127);
-				table->setCellWidget(pin, 0, wgtPlot);
-
-				wgtPlot->xAxis->setRange(0, BufferSize);
-				wgtPlot->yAxis->setRange(0, 127);
-				wgtPlot->yAxis2->setRange(0, 2);
-				wgtPlot->yAxis2->setVisible(true);
-
-				auto stateGraph = wgtPlot->addGraph(wgtPlot->xAxis, wgtPlot->yAxis2);
-				stateGraph->setPen(QPen(Qt::red));
-				stateGraph->setLineStyle(QCPGraph::LineStyle::lsStepLeft);
-
-				plots[port * CHAN_CNT + pin] = wgtPlot;
+		{
+			std::array<QCustomPlot*, PORT_CNT* CHAN_CNT> plots;
+
+			for(auto port = 0; port < PORT_CNT; ++port) {
+				auto wgtPort = ui.tabWidget->widget(ui.tabWidget->addTab(new PortTab(), "Graph_Port " + QString::number(port)));
+
+				auto table = new QTableWidget(CHAN_CNT, 1, wgtPort);
+				table->horizontalHeader()->setStretchLastSection(true);
+				table->verticalHeader()->setMinimumHeight(100);
+				table->horizontalHeader()->setVisible(false);
+				wgtPort->layout()->addWidget(table);
+
+				for(auto pin = 0; pin < CHAN_CNT; ++pin) {
+					auto channel = port * CHAN_CNT + pin;
+					auto wgtPlot = new QCustomPlot(table);
+
+					wgtPlot->setBackground(qApp->palette().button());
+					QPen pen(qApp->palette().midlight().color());
+					pen.setStyle(Qt::PenStyle::DotLine);
+					wgtPlot->xAxis->grid()->setPen(pen);
+					wgtPlot->yAxis->grid()->setPen(pen);
+					wgtPlot->xAxis2->grid()->setPen(pen);
+					wgtPlot->yAxis2->grid()->setPen(pen);
+
+					wgtPlot->xAxis->setBasePen(qApp->palette().windowText().color());
+					wgtPlot->yAxis->setBasePen(qApp->palette().windowText().color());
+					wgtPlot->xAxis2->setBasePen(qApp->palette().windowText().color());
+					wgtPlot->yAxis2->setBasePen(qApp->palette().windowText().color());
+
+					wgtPlot->xAxis->setTickPen(qApp->palette().windowText().color());
+					wgtPlot->yAxis->setTickPen(qApp->palette().windowText().color());
+					wgtPlot->xAxis2->setTickPen(qApp->palette().windowText().color());
+					wgtPlot->yAxis2->setTickPen(qApp->palette().windowText().color());
+
+					auto curve = wgtPlot->addGraph();
+					curve->setPen(QPen(qApp->palette().buttonText().color()));
+					table->setRowHeight(pin, 127);
+					table->setCellWidget(pin, 0, wgtPlot);
+
+					wgtPlot->xAxis->setRange(0, BufferSize);
+					wgtPlot->yAxis->setRange(0, 127);
+					wgtPlot->yAxis2->setRange(0, 2);
+					wgtPlot->yAxis2->setVisible(true);
+
+					auto stateGraph = wgtPlot->addGraph(wgtPlot->xAxis, wgtPlot->yAxis2);
+					stateGraph->setPen(QPen(qApp->palette().highlight().color()));
+					stateGraph->setLineStyle(QCPGraph::LineStyle::lsStepLeft);
+
+					plots[port * CHAN_CNT + pin] = wgtPlot;
+				}
 			}
-		}
 
-		QTimer* timer = new QTimer(this);
-		connect(timer, &QTimer::timeout, [this, plots]() {
-			auto currentIndex = _proc.frameCounter % BufferSize;
-			QVector<qreal> x(BufferSize);
-			QVector<qreal> y(BufferSize);
-			QVector<qreal> s(BufferSize);
+			QTimer* timer = new QTimer(this);
+			connect(timer, &QTimer::timeout, [this, plots]() {
+				auto currentIndex = _proc.frameCounter % BufferSize;
+				QVector<qreal> x(BufferSize);
+				QVector<qreal> y(BufferSize);
+				QVector<qreal> s(BufferSize);
 
-			for(auto i = 0; i < BufferSize; ++i) {
-				x[i] = i;
-			}
+				for(auto i = 0; i < BufferSize; ++i) {
+					x[i] = i;
+				}
 
-			for(auto i = 0; i < PORT_CNT * CHAN_CNT; ++i) {
-				if(plots[i]->isVisible()) {
-					auto channel = mapChannels(i);
+				for(auto i = 0; i < PORT_CNT * CHAN_CNT; ++i) {
+					if(plots[i]->isVisible()) {
+						auto channel = mapChannels(i);
 
-					plots[i]->yAxis->setLabel(QString(_settings.channelSettings[i].name));
-					plots[i]->xAxis->setRange(x.front(), x.back());
+						plots[i]->yAxis->setLabel(QString(_settings.channelSettings[i].name));
+						plots[i]->xAxis->setRange(x.front(), x.back());
 
-					for(auto k = 0; k < BufferSize; ++k) {
-						y[k] = _proc.frameBuffer[k][channel];
-						s[k] = _proc.stateBuffer[k][i];
-					}
+						for(auto k = 0; k < BufferSize; ++k) {
+							y[k] = _proc.frameBuffer[k][channel];
+							s[k] = _proc.stateBuffer[k][i];
+						}
 
-					plots[i]->graph(0)->setData(x, y);
-					plots[i]->graph(1)->setData(x, s);
+						plots[i]->graph(0)->setData(x, y);
+						plots[i]->graph(1)->setData(x, s);
 
-					plots[i]->replot();
+						plots[i]->replot();
+					}
 				}
-			}
-		});
-		timer->start(1000 / 12);
-	}
+
+				setWindowTitle("drumduino - sampling each channel at " + QString::number(double(g_frameTime)) + "Hz");
+			});
+			timer->start(1000 / 12);
+		}
 #endif
+
+	}
+
+	catch(...)
+	{}
 }
 
 Drumduino::~Drumduino()
 {
-	_drumduinoThread->stop();
-	_drumduinoThread->wait();
+	if(_drumduinoThread) {
+		_drumduinoThread->stop();
+		_drumduinoThread->wait();
+	}
+}
+
+void Drumduino::slotUpdateChannelProgress(size_t channel, byte maxValue, byte sumValue, byte calcValue)
+{
+	_channels[channel]->triggered(maxValue, sumValue, calcValue);
 }

+ 10 - 32
drumduino/drumduino.h

@@ -9,7 +9,7 @@
 #include "qcustomplot.h"
 #include "settings.h"
 
-enum { BufferSize = 512 };
+enum { BufferSize = 1024 };
 
 enum State {
 	StateAwait,
@@ -26,6 +26,7 @@ struct DrumduinoProc {
 	std::array<State, PORT_CNT* CHAN_CNT> states;
 	std::array<uint64_t, PORT_CNT* CHAN_CNT> triggers;
 	std::array<byte, PORT_CNT* CHAN_CNT> maxs;
+	std::array<uint64_t, PORT_CNT* CHAN_CNT> sums;
 
 	std::array<std::array<State, PORT_CNT* CHAN_CNT>, BufferSize>  stateBuffer;
 
@@ -78,9 +79,7 @@ private:
 		if(dial && e->type() == QEvent::Paint) {
 			QPaintEvent* paintEvent = static_cast<QPaintEvent*>(e);
 
-
 			QStylePainter p(dial);
-
 			QStyleOptionSlider option;
 
 			option.initFrom(dial);
@@ -101,8 +100,11 @@ private:
 			option.tickPosition = QSlider::NoTicks;
 
 			option.tickInterval = dial->notchSize();
-
+/*
+			p.setPen(qApp->palette().buttonText().color());
+			p.setBrush(qApp->palette().buttonText().color());*/
 			p.drawComplexControl(QStyle::CC_Dial, option);
+			p.setPen(qApp->palette().buttonText().color());
 			p.drawText(dial->rect(), Qt::AlignCenter, QString::number(dial->value()));
 			return true;
 		}
@@ -110,36 +112,12 @@ private:
 		return QMainWindow::eventFilter(o, e);
 	}
 
+signals:
+	void updateChannelProgess(size_t channel, byte maxValue, byte sumValue, byte calcValue);
 
-#if 0
-
-public:
-	std::vector<QCustomPlot*> _plots;
-
-	bool _updateGraph;
-	qint64 _lasttime;
-	qint64 _startTime;
-
-private:
-
-	uint64_t _currentFrame;
-	std::array<std::array<byte, BufferSize>, PORT_CNT* CHAN_CNT> _frameBuffer;
-	std::array<std::array<State, BufferSize>, PORT_CNT* CHAN_CNT> _stateBuffer;
-	std::array<State, PORT_CNT* CHAN_CNT> _states;
-	std::array<uint64_t, PORT_CNT* CHAN_CNT> _triggers;
-	std::array<byte, PORT_CNT* CHAN_CNT> _max;
-
-
-	std::array<byte, PORT_CNT* CHAN_CNT> _maxVal;
-
-public:
-
-
+public slots:
+	void slotUpdateChannelProgress(size_t channel, byte maxValue, byte sumValue, byte calcValue);
 
-	void serialRead();
-	void updateGraph();
-	void handleFrame(const std::array<byte, PORT_CNT* CHAN_CNT>& frame, const uint64_t currentIndex);
-#endif
 };
 
 

+ 40 - 8
drumduino/main.cpp

@@ -2,16 +2,35 @@
 #include "drumduino.h"
 #include <QtWidgets/QApplication>
 
-int main(int argc, char *argv[])
+int main(int argc, char* argv[])
 {
 	QApplication::setStyle(QStyleFactory::create("Fusion"));
-    //QPalette p;
-    //p = qApp->palette();
-    //p.setColor(QPalette::Window, QColor(53,53,53));
-    //p.setColor(QPalette::Button, QColor(53,53,53));
-    //p.setColor(QPalette::Highlight, QColor(142,45,197));
-    //p.setColor(QPalette::ButtonText, QColor(255,255,255));
-    //qApp->setPalette(p);
+	QPalette p;
+	//p = qApp->palette();
+		
+	p.setColor(QPalette::Base, QColor(53, 53, 53)); // lineedit & progress background
+	p.setColor(QPalette::Window, QColor(53, 53, 53)); //window & combobox background
+	p.setColor(QPalette::Button, QColor(53, 53, 53)); //tab & button background (light)
+	p.setColor(QPalette::Text, QColor(255, 255, 255)); //combobox text
+	p.setColor(QPalette::ButtonText, QColor(255, 255, 255)); // button text
+	p.setColor(QPalette::WindowText, QColor(0xff6600)); // tab and onWindow text
+
+	p.setColor(QPalette::BrightText, QColor(0xff0000)); // ???
+	p.setColor(QPalette::Shadow, QColor(Qt::black)); // ???
+	p.setColor(QPalette::Dark, QColor(0xff6600)); // qdial notches
+	p.setColor(QPalette::Mid, QColor(43, 43, 43)); // ???
+	p.setColor(QPalette::Midlight, QColor(73, 73, 73)); // ???
+	p.setColor(QPalette::Light, QColor(93, 93, 93)); // ???
+	
+	p.setColor(QPalette::NoRole, QColor(0x00ff00)); // ???
+	p.setColor(QPalette::AlternateBase, QColor(0x00ff00)); // ???
+	p.setColor(QPalette::ToolTipBase, QColor(0x00ff00)); // ???
+	p.setColor(QPalette::Link, QColor(0x00ff00)); // ???
+	p.setColor(QPalette::LinkVisited, QColor(0x00ff00)); // ???
+
+	p.setColor(QPalette::HighlightedText, QColor(0xffffff)); //current selection text of combobox
+	p.setColor(QPalette::Highlight, QColor(0xff9966)); //combobox current selection background, progress chunk background
+	qApp->setPalette(p);
 
 
 	QApplication a(argc, argv);
@@ -19,3 +38,16 @@ int main(int argc, char *argv[])
 	w.show();
 	return a.exec();
 }
+
+/*
+WindowText, Button, Light, Midlight, Dark, Mid,
+                     Text, BrightText, ButtonText, Base, Window, Shadow,
+                     Highlight, HighlightedText,
+                     Link, LinkVisited,
+                     AlternateBase,
+                     NoRole,
+                     ToolTipBase, ToolTipText,
+                     NColorRoles = ToolTipText + 1,
+                     Foreground = WindowText, Background = Window
+
+                     */

+ 4 - 2
drumduino/settings.h

@@ -41,13 +41,15 @@ struct ChannelSettings {
 	qint64 scanTime;
 	qint64 maskTime;
 	CurveSettings curve;
+	bool sum;
 
 	ChannelSettings()
 		: type(TypeDisabled)
 		, note(35)
 		, threshold(25)
-		, scanTime(4)
-		, maskTime(10)
+		, scanTime(25)
+		, maskTime(35)
+		, sum(false)
 	{
 		memset(name, 0, sizeof(name));
 	}