From e0e4f9f84bb8eed6cde71ff4d67286c2e26e4693 Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Sat, 9 Apr 2016 21:52:04 +0800 Subject: Blocked thread! --- ChangeLog | 4 ++++ qmidiplayer-desktop/qmpchannelswindow.cpp | 27 +++++++++++++++++++++++++-- qmidiplayer-desktop/qmpchannelswindow.hpp | 2 ++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index d737748..a8b8ead 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2016-04-09 0.7.1 beta +Add the fuse mechanism to avoid black midi blocking the +main thread. + 2016-04-08 0.7.1 beta Add MIDI activity indicator. Substract time taken by sending midi data from sleep time. diff --git a/qmidiplayer-desktop/qmpchannelswindow.cpp b/qmidiplayer-desktop/qmpchannelswindow.cpp index 3e43c3d..17c0893 100644 --- a/qmidiplayer-desktop/qmpchannelswindow.cpp +++ b/qmidiplayer-desktop/qmpchannelswindow.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -15,7 +16,7 @@ qmpChannelsWindow::qmpChannelsWindow(QWidget *parent) : connect(this,SIGNAL(dialogClosing()),parent,SLOT(dialogClosed())); mapper=qmpMainWindow::getInstance()->getPlayer()->getMidiMapper(); cha=new QPixmap(":/img/ledon.png");chi=new QPixmap(":/img/ledoff.png"); - cb=new qmpCWNoteOnCB(); + cb=new qmpCWNoteOnCB();fused=callbacksc=cbcnt=0; qmpMainWindow::getInstance()->getPlayer()->setNoteOnCallBack(cb,NULL); connect(cb,SIGNAL(onNoteOn()),this,SLOT(updateChannelActivity())); int devc=mapper->enumDevices(); @@ -78,6 +79,7 @@ void qmpChannelsWindow::moveEvent(QMoveEvent *event) void qmpChannelsWindow::updateChannelActivity() { + ++callbacksc; for(int i=0;i<16;++i) ui->twChannels->item(i,0)->setIcon( qmpMainWindow::getInstance()->getPlayer()->getChstates()[i]?*cha:*chi); @@ -89,7 +91,19 @@ void qmpChannelsWindow::channelWindowsUpdate() { for(int i=0;i<16;++i) ((QLabel*)ui->twChannels->cellWidget(i,4))->setText(""); - return; + connect(cb,SIGNAL(onNoteOn()),this,SLOT(updateChannelActivity())); + fused=0;return; + } + ++cbcnt; + if(cbcnt>15) + { + if(callbacksc>8192) + { + disconnect(cb,SIGNAL(onNoteOn()),this,SLOT(updateChannelActivity())); + fprintf(stderr,"Fuse!\n");fused=1; + } + cbcnt=0; + callbacksc=0; } for(int i=0;i<16;++i) { @@ -97,6 +111,15 @@ void qmpChannelsWindow::channelWindowsUpdate() int b,p; qmpMainWindow::getInstance()->getPlayer()->getChannelPreset(i,&b,&p,nm); sprintf(data,"%d:%d %s",b,p,nm); + if(fused) + { + if(strcmp(((QLabel*)ui->twChannels->cellWidget(i,4))-> + text().toStdString().c_str(),data)) + { + connect(cb,SIGNAL(onNoteOn()),this,SLOT(updateChannelActivity())); + fused=0; + } + } ((QLabel*)ui->twChannels->cellWidget(i,4))->setText(data); ui->twChannels->item(i,0)->setIcon( qmpMainWindow::getInstance()->getPlayer()->getChstates()[i]?*cha:*chi); diff --git a/qmidiplayer-desktop/qmpchannelswindow.hpp b/qmidiplayer-desktop/qmpchannelswindow.hpp index 80f427a..25c897a 100644 --- a/qmidiplayer-desktop/qmpchannelswindow.hpp +++ b/qmidiplayer-desktop/qmpchannelswindow.hpp @@ -97,6 +97,8 @@ class qmpChannelsWindow:public QDialog qmpMidiMapperRtMidi *mapper; QPixmap *cha,*chi; qmpCWNoteOnCB *cb; + //callback fuse... (avoid black midi blocking the main thread) + int callbacksc,cbcnt,fused; }; #endif // QMPCHANNELSWINDOW_H -- cgit v1.2.3