From 1e1036e705b20ea407bbb922e40c0f44147b3691 Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Thu, 14 Jan 2016 21:47:06 +0800 Subject: Innocent Treasure. (WTF) --- ChangeLog | 4 ++++ qmpmainwindow.cpp | 24 +++++++++++++++++++----- qmpmainwindow.hpp | 4 ++++ qmpmainwindow.ui | 3 +++ qmpmidiplay.cpp | 4 +++- qmpmidiplay.hpp | 5 +++-- qmpmidiread.cpp | 21 +++++++++++++-------- qmpplistwindow.cpp | 20 ++++++++++++++++++++ qmpplistwindow.hpp | 5 +++++ qmpplistwindow.ui | 3 +++ 10 files changed, 77 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7c008c7..254f93a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2016-01-14 0.6.2 beta +Drag 'n' drop. +Do not quit the program when trying to load a unsupported file. + 2016-01-13 0.6.2 beta Hopefully this fixed several critical bugs... diff --git a/qmpmainwindow.cpp b/qmpmainwindow.cpp index 6e88f37..646f3ad 100644 --- a/qmpmainwindow.cpp +++ b/qmpmainwindow.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include "qmpmainwindow.hpp" @@ -122,6 +123,19 @@ void qmpMainWindow::moveEvent(QMoveEvent *event) qmpSettingsWindow::getSettingsIntf()->setValue("DialogStatus/MainW",event->pos()); } } +void qmpMainWindow::dropEvent(QDropEvent *event) +{ + QList l=event->mimeData()->urls(); + QStringList sl; + for(int i=0;iinsertItems(sl); +} +void qmpMainWindow::dragEnterEvent(QDragEnterEvent *event) +{ + //if(event->mimeData()->hasFormat("application/x-midi")) + event->acceptProposedAction(); +} void qmpMainWindow::updateWidgets() { @@ -148,7 +162,7 @@ void qmpMainWindow::updateWidgets() chnlw->on_pbUnmute_clicked();chnlw->on_pbUnsolo_clicked(); QString fns=plistw->getNextItem(); ui->lbFileName->setText(QUrl(fns).fileName()); - player->playerLoadFile(fns.toStdString().c_str()); + if(!player->playerLoadFile(fns.toStdString().c_str()))return; char ts[100]; sprintf(ts,"%02d:%02d",(int)player->getFtime()/60,(int)player->getFtime()%60); ui->lbFinTime->setText(ts); @@ -236,7 +250,7 @@ void qmpMainWindow::on_pbPlayPause_clicked() if(!fns.length())return(void)(playing=false); } ui->lbFileName->setText(QUrl(fns).fileName()); - player->playerLoadFile(fns.toStdString().c_str()); + if(!player->playerLoadFile(fns.toStdString().c_str()))return; char ts[100]; sprintf(ts,"%02d:%02d",(int)player->getFtime()/60,(int)player->getFtime()%60); ui->lbFinTime->setText(ts); @@ -353,7 +367,7 @@ void qmpMainWindow::on_pbPrev_clicked() ui->hsTimer->setValue(0);chnlw->on_pbUnmute_clicked();chnlw->on_pbUnsolo_clicked(); QString fns=plistw->getPrevItem();if(fns.length()==0)return on_pbStop_clicked(); ui->lbFileName->setText(QUrl(fns).fileName()); - player->playerLoadFile(fns.toStdString().c_str()); + if(!player->playerLoadFile(fns.toStdString().c_str()))return; char ts[100]; sprintf(ts,"%02d:%02d",(int)player->getFtime()/60,(int)player->getFtime()%60); ui->lbFinTime->setText(ts); @@ -373,7 +387,7 @@ void qmpMainWindow::on_pbNext_clicked() ui->hsTimer->setValue(0);chnlw->on_pbUnmute_clicked();chnlw->on_pbUnsolo_clicked(); QString fns=plistw->getNextItem();if(fns.length()==0)return on_pbStop_clicked(); ui->lbFileName->setText(QUrl(fns).fileName()); - player->playerLoadFile(fns.toStdString().c_str()); + if(!player->playerLoadFile(fns.toStdString().c_str()))return; char ts[100]; sprintf(ts,"%02d:%02d",(int)player->getFtime()/60,(int)player->getFtime()%60); ui->lbFinTime->setText(ts); @@ -396,7 +410,7 @@ void qmpMainWindow::selectionChanged() chnlw->on_pbUnmute_clicked();chnlw->on_pbUnsolo_clicked(); QString fns=plistw->getSelectedItem(); ui->lbFileName->setText(QUrl(fns).fileName()); - player->playerLoadFile(fns.toStdString().c_str()); + if(!player->playerLoadFile(fns.toStdString().c_str()))return; char ts[100]; sprintf(ts,"%02d:%02d",(int)player->getFtime()/60,(int)player->getFtime()%60); ui->lbFinTime->setText(ts); diff --git a/qmpmainwindow.hpp b/qmpmainwindow.hpp index 331fc15..fad2d8e 100644 --- a/qmpmainwindow.hpp +++ b/qmpmainwindow.hpp @@ -5,6 +5,8 @@ #include #include #include +#include +#include #include #include #include @@ -29,6 +31,8 @@ class qmpMainWindow:public QMainWindow explicit qmpMainWindow(QWidget *parent = 0); void closeEvent(QCloseEvent *event); void moveEvent(QMoveEvent *event); + void dropEvent(QDropEvent *event); + void dragEnterEvent(QDragEnterEvent *event); ~qmpMainWindow(); CMidiPlayer* getPlayer(){return player;} QTimer* getTimer(){return timer;} diff --git a/qmpmainwindow.ui b/qmpmainwindow.ui index 1439166..0764e09 100644 --- a/qmpmainwindow.ui +++ b/qmpmainwindow.ui @@ -22,6 +22,9 @@ 245 + + true + QMidiPlayer diff --git a/qmpmidiplay.cpp b/qmpmidiplay.cpp index 70fe91b..be5a60d 100644 --- a/qmpmidiplay.cpp +++ b/qmpmidiplay.cpp @@ -183,12 +183,14 @@ void CMidiPlayer::playerPanic() for(int i=0;i<16;++i)fluid_synth_all_notes_off(synth,i); //for(int i=0;i<16;++i)for(int j=0;j<128;++j)fluid_synth_noteoff(synth,i,j); } -void CMidiPlayer::playerLoadFile(const char* fn) +bool CMidiPlayer::playerLoadFile(const char* fn) { midiFile=new CMidiFile(fn); + if(!midiFile->isValid())return false; divs=midiFile->getDivision(); fileTimer1Pass(); fileTimer2Pass(); + return true; } void CMidiPlayer::playerInit() { diff --git a/qmpmidiplay.hpp b/qmpmidiplay.hpp index dc09393..188a796 100644 --- a/qmpmidiplay.hpp +++ b/qmpmidiplay.hpp @@ -26,7 +26,7 @@ class CMidiFile uint32_t eventc,std;//standard 0=? 1=GM 2=GM2 3=GS 4=XG uint32_t fmt,trk,divs; FILE *f; - int byteread; + int byteread,valid; uint32_t notes,curt,curid; void error(int fatal,const char* format,...); @@ -47,6 +47,7 @@ class CMidiFile uint32_t getStandard(); const char* getTitle(); const char* getCopyright(); + bool isValid(); }; class CMidiPlayer { @@ -78,7 +79,7 @@ class CMidiPlayer public: CMidiPlayer(); ~CMidiPlayer(); - void playerLoadFile(const char* fn); + bool playerLoadFile(const char* fn); void playerInit(); void fluidInitialize(); void playerDeinit(); diff --git a/qmpmidiread.cpp b/qmpmidiread.cpp index c9fff34..f09f9e0 100644 --- a/qmpmidiread.cpp +++ b/qmpmidiread.cpp @@ -18,7 +18,7 @@ void CMidiFile::error(int fatal,const char* format,...) va_list ap; va_start(ap,format);vfprintf(stderr,format,ap);va_end(ap); fprintf(stderr," at %#lx\n",ftell(f)); - if(fatal)exit(2); + if(fatal)throw 2; } uint32_t CMidiFile::readSW() { @@ -215,13 +215,17 @@ CMidiFile::CMidiFile(const char* fn) { if(title)delete[] title; if(copyright)delete[] copyright; - title=copyright=NULL;notes=0;std=0; - if(!(f=fopen(fn,"rb")))exit((printf("E: file %s doesn't exist!\n",fn),2)); - chunkReader(1); - for(uint32_t i=0;i #include #include +#include +#include #include "qmpplistwindow.hpp" #include "ui_qmpplistwindow.h" #include "qmpmainwindow.hpp" @@ -100,6 +102,20 @@ void qmpPlistWindow::moveEvent(QMoveEvent *event) } } +void qmpPlistWindow::dropEvent(QDropEvent *event) +{ + QList l=event->mimeData()->urls(); + QStringList sl; + for(int i=0;imimeData()->hasFormat("application/x-midi")) + event->acceptProposedAction(); +} + void qmpPlistWindow::emptyList() { ui->lwFiles->clear(); @@ -108,6 +124,10 @@ void qmpPlistWindow::insertItem(QString i) { ui->lwFiles->addItem(new QListWidgetItem(i)); } +void qmpPlistWindow::insertItems(QStringList il) +{ + ui->lwFiles->addItems(il); +} void qmpPlistWindow::on_pbAdd_clicked() { diff --git a/qmpplistwindow.hpp b/qmpplistwindow.hpp index e86ec96..6ceeb60 100644 --- a/qmpplistwindow.hpp +++ b/qmpplistwindow.hpp @@ -5,6 +5,8 @@ #include #include #include +#include +#include #include namespace Ui { @@ -21,6 +23,8 @@ class qmpPlistWindow : public QDialog void showEvent(QShowEvent *event); void closeEvent(QCloseEvent *event); void moveEvent(QMoveEvent *event); + void dropEvent(QDropEvent *event); + void dragEnterEvent(QDragEnterEvent *event); int getRepeat(); QString getFirstItem(); QString getNextItem(); @@ -28,6 +32,7 @@ class qmpPlistWindow : public QDialog QString getSelectedItem(); void emptyList(); void insertItem(QString i); + void insertItems(QStringList il); signals: void dialogClosing(); void selectionChanging(); diff --git a/qmpplistwindow.ui b/qmpplistwindow.ui index c4e6fbc..99124df 100644 --- a/qmpplistwindow.ui +++ b/qmpplistwindow.ui @@ -245,6 +245,9 @@ 221 + + false + true -- cgit v1.2.3