aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--qmpmainwindow.cpp24
-rw-r--r--qmpmainwindow.hpp4
-rw-r--r--qmpmainwindow.ui3
-rw-r--r--qmpmidiplay.cpp4
-rw-r--r--qmpmidiplay.hpp5
-rw-r--r--qmpmidiread.cpp21
-rw-r--r--qmpplistwindow.cpp20
-rw-r--r--qmpplistwindow.hpp5
-rw-r--r--qmpplistwindow.ui3
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 <cstdio>
#include <QUrl>
+#include <QMimeData>
#include <QDirIterator>
#include <QDesktopWidget>
#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<QUrl> l=event->mimeData()->urls();
+ QStringList sl;
+ for(int i=0;i<l.size();++i)
+ sl.push_back(l.at(i).path());
+ plistw->insertItems(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 <QTimer>
#include <QCloseEvent>
#include <QMoveEvent>
+#include <QDropEvent>
+#include <QDragEnterEvent>
#include <QAction>
#include <QMenu>
#include <thread>
@@ -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 @@
<height>245</height>
</size>
</property>
+ <property name="acceptDrops">
+ <bool>true</bool>
+ </property>
<property name="windowTitle">
<string>QMidiPlayer</string>
</property>
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<trk;i+=chunkReader(0));
- printf("%d note(s)\n",notes);
- fclose(f);
- std::sort(eventList,eventList+eventc,cmp);
+ title=copyright=NULL;notes=0;std=0;valid=1;
+ try
+ {
+ if(!(f=fopen(fn,"rb")))throw (fprintf(stderr,"E: file %s doesn't exist!\n",fn),2);
+ chunkReader(1);
+ for(uint32_t i=0;i<trk;i+=chunkReader(0));
+ printf("%d note(s)\n",notes);
+ fclose(f);
+ std::sort(eventList,eventList+eventc,cmp);
+ }
+ catch(int){fprintf(stderr,"E: %s is not a supported file.\n",fn);valid=0;}
}
CMidiFile::~CMidiFile()
{
@@ -233,5 +237,6 @@ uint32_t CMidiFile::getEventCount(){return eventc;}
uint32_t CMidiFile::getDivision(){return divs;}
uint32_t CMidiFile::getNoteCount(){return notes;}
uint32_t CMidiFile::getStandard(){return std;}
+bool CMidiFile::isValid(){return valid;}
const char* CMidiFile::getTitle(){return title;}
const char* CMidiFile::getCopyright(){return copyright;}
diff --git a/qmpplistwindow.cpp b/qmpplistwindow.cpp
index 85c33a3..a930a1d 100644
--- a/qmpplistwindow.cpp
+++ b/qmpplistwindow.cpp
@@ -3,6 +3,8 @@
#include <QFileDialog>
#include <QDirIterator>
#include <QSettings>
+#include <QUrl>
+#include <QMimeData>
#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<QUrl> l=event->mimeData()->urls();
+ QStringList sl;
+ for(int i=0;i<l.size();++i)
+ sl.push_back(l.at(i).path());
+ insertItems(sl);
+}
+void qmpPlistWindow::dragEnterEvent(QDragEnterEvent *event)
+{
+ //if(event->mimeData()->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 <QShowEvent>
#include <QCloseEvent>
#include <QMoveEvent>
+#include <QDropEvent>
+#include <QDragEnterEvent>
#include <QListWidgetItem>
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 @@
<height>221</height>
</rect>
</property>
+ <property name="acceptDrops">
+ <bool>false</bool>
+ </property>
<property name="dragEnabled">
<bool>true</bool>
</property>