From 99ccbebf8ce4e7070843fff94f2953c2818ca5c8 Mon Sep 17 00:00:00 2001 From: Robert Jonsson Date: Fri, 13 May 2011 20:18:01 +0000 Subject: find unused wave files --- muse2/ChangeLog | 1 + muse2/muse/app.cpp | 23 +++++- muse2/muse/app.h | 7 +- muse2/muse/widgets/CMakeLists.txt | 9 ++- muse2/muse/widgets/unusedwavefiles.cpp | 96 ++++++++++++++++++++++++ muse2/muse/widgets/unusedwavefiles.h | 25 +++++++ muse2/muse/widgets/unusedwavefiles.ui | 131 +++++++++++++++++++++++++++++++++ 7 files changed, 283 insertions(+), 9 deletions(-) create mode 100644 muse2/muse/widgets/unusedwavefiles.cpp create mode 100644 muse2/muse/widgets/unusedwavefiles.h create mode 100644 muse2/muse/widgets/unusedwavefiles.ui diff --git a/muse2/ChangeLog b/muse2/ChangeLog index 2e3fa20f..32382091 100644 --- a/muse2/ChangeLog +++ b/muse2/ChangeLog @@ -1,5 +1,6 @@ 13.05.2011: - New spanish translation from Cristian Ramos (rj) + - Added dialog to remove unused wave files (rj) - Changed default imported midi song type to GM. (Tim) 12.05.2011: - Changed template song "default.med" song type from NO to GM, to help new users. (Tim) diff --git a/muse2/muse/app.cpp b/muse2/muse/app.cpp index 59993911..c42a1a7c 100644 --- a/muse2/muse/app.cpp +++ b/muse2/muse/app.cpp @@ -55,6 +55,7 @@ #include "widgets/menutitleitem.h" #include "tools.h" #include "visibletracks.h" +#include "widgets/unusedwavefiles.h" #ifdef DSSI_SUPPORT #include "dssihost.h" @@ -966,6 +967,7 @@ MusE::MusE(int argc, char** argv) : QMainWindow() fileImportPartAction = new QAction(tr("Import Part"), this); fileImportWaveAction = new QAction(tr("Import Wave File"), this); + fileMoveWaveFiles = new QAction(tr("Find unused wave files"), this); quitAction = new QAction(tr("&Quit"), this); @@ -1000,10 +1002,9 @@ MusE::MusE(int argc, char** argv) : QMainWindow() scoreAllInOneSubsubmenu = new QMenu(tr("all parts in one staff"), this); scoreOneStaffPerTrackSubsubmenu = new QMenu(tr("one staff per part"), this); - scoreSubmenu->addMenu(scoreAllInOneSubsubmenu); - scoreSubmenu->addMenu(scoreOneStaffPerTrackSubsubmenu); - - updateScoreMenus(); + scoreSubmenu->addMenu(scoreAllInOneSubsubmenu); + scoreSubmenu->addMenu(scoreOneStaffPerTrackSubsubmenu); + updateScoreMenus(); startScoreEditAction = new QAction(*scoreIconSet, tr("New score window"), this); startPianoEditAction = new QAction(*pianoIconSet, tr("Pianoroll"), this); @@ -1075,6 +1076,7 @@ MusE::MusE(int argc, char** argv) : QMainWindow() autoClearAction = new QAction(QIcon(*automation_clear_dataIcon), tr("Clear Automation Data"), this); autoClearAction->setEnabled(false); + //-------- Settings Actions settingsGlobalAction = new QAction(QIcon(*settings_globalsettingsIcon), tr("Global Settings"), this); settingsShortcutsAction = new QAction(QIcon(*settings_configureshortcutsIcon), tr("Configure Shortcuts"), this); @@ -1116,6 +1118,7 @@ MusE::MusE(int argc, char** argv) : QMainWindow() connect(fileImportPartAction, SIGNAL(activated()), SLOT(importPart())); connect(fileImportWaveAction, SIGNAL(activated()), SLOT(importWave())); + connect(fileMoveWaveFiles, SIGNAL(activated()), SLOT(findUnusedWaveFiles())); connect(quitAction, SIGNAL(activated()), SLOT(quitDoc())); //-------- Edit connections @@ -1342,6 +1345,8 @@ MusE::MusE(int argc, char** argv) : QMainWindow() menu_file->addSeparator(); menu_file->addAction(fileImportWaveAction); menu_file->addSeparator(); + menu_file->addAction(fileMoveWaveFiles); + menu_file->addSeparator(); menu_file->addAction(quitAction); menu_file->addSeparator(); @@ -5098,6 +5103,7 @@ void MusE::execDeliveredScript(int id) //QString scriptfile = QString(INSTPREFIX) + SCRIPTSSUFFIX + deliveredScriptNames[id]; song->executeScript(song->getScriptPath(id, true).toLatin1().constData(), song->getSelectedMidiParts(), 0, false); // TODO: get quant from arranger } + //--------------------------------------------------------- // execUserScript //--------------------------------------------------------- @@ -5105,3 +5111,12 @@ void MusE::execUserScript(int id) { song->executeScript(song->getScriptPath(id, false).toLatin1().constData(), song->getSelectedMidiParts(), 0, false); // TODO: get quant from arranger } + +//--------------------------------------------------------- +// findUnusedWaveFiles +//--------------------------------------------------------- +void MusE::findUnusedWaveFiles() +{ + UnusedWaveFiles unused(muse); + unused.exec(); +} diff --git a/muse2/muse/app.h b/muse2/muse/app.h index 42aebf3b..e940c1ad 100644 --- a/muse2/muse/app.h +++ b/muse2/muse/app.h @@ -104,7 +104,8 @@ class MusE : public QMainWindow // File menu actions QAction *fileSaveAction, *fileOpenAction, *fileNewAction, *testAction; - QAction *fileSaveAsAction, *fileImportMidiAction, *fileExportMidiAction, *fileImportPartAction, *fileImportWaveAction, *quitAction; + QAction *fileSaveAsAction, *fileImportMidiAction, *fileExportMidiAction; + QAction *fileImportPartAction, *fileImportWaveAction, *fileMoveWaveFiles, *quitAction; // Edit Menu actions QAction *editCutAction, *editCopyAction, *editPasteAction, *editInsertAction, *editPasteCloneAction, *editPaste2TrackAction; @@ -160,7 +161,7 @@ class MusE : public QMainWindow QMenu *menu_file, *menuView, *menuSettings, *menu_help; QMenu *menuEdit, *menuStructure; - QMenu* menu_audio, *menuAutomation; + QMenu* menu_audio, *menuAutomation, *menuUtils; QMenu* menu_functions, *menuScriptPlugins; QMenu* select, *master, *midiEdit, *addTrack; @@ -247,6 +248,7 @@ class MusE : public QMainWindow void importWave(); void importPart(); void exportMidi(); + void findUnusedWaveFiles(); void toggleTransport(bool); void toggleMarker(bool); @@ -375,6 +377,7 @@ class MusE : public QMainWindow bool seqStart(); void setHeartBeat(); void importController(int, MidiPort*, int); + QString projectName() { return project.fileName(); } //QWidget* mixerWindow(); QWidget* mixer1Window(); QWidget* mixer2Window(); diff --git a/muse2/muse/widgets/CMakeLists.txt b/muse2/muse/widgets/CMakeLists.txt index 261c27a2..9a3f993a 100644 --- a/muse2/muse/widgets/CMakeLists.txt +++ b/muse2/muse/widgets/CMakeLists.txt @@ -75,7 +75,8 @@ QT4_WRAP_CPP (widget_mocs tools.h # ttoolbar.h ttoolbutton.h - velocity.h + unusedwavefiles.h + velocity.h verticalmeter.h view.h vscale.h @@ -109,7 +110,8 @@ file (GLOB widgets_ui_files songinfo.ui synthconfigbase.ui transformbase.ui - transposebase.ui + transposebase.ui + unusedwavefiles.ui velocitybase.ui ) QT4_WRAP_UI (widget_ui_headers ${widgets_ui_files}) @@ -175,7 +177,8 @@ file (GLOB widgets_source_files tools.cpp ttoolbar.cpp ttoolbutton.cpp - utils.cpp + unusedwavefiles.cpp + utils.cpp velocity.cpp verticalmeter.cpp view.cpp diff --git a/muse2/muse/widgets/unusedwavefiles.cpp b/muse2/muse/widgets/unusedwavefiles.cpp new file mode 100644 index 00000000..7cba1bd5 --- /dev/null +++ b/muse2/muse/widgets/unusedwavefiles.cpp @@ -0,0 +1,96 @@ +#include +#include +#include +#include +#include +#include +#include "unusedwavefiles.h" +#include "ui_unusedwavefiles.h" +#include "globals.h" +#include "app.h" + +UnusedWaveFiles::UnusedWaveFiles(QWidget *parent) : + QDialog(parent), + ui(new Ui::UnusedWaveFiles) +{ + + ui->setupUi(this); + ui->currentProjRadioButton->setChecked(true); + connect(ui->currentProjRadioButton, SIGNAL(clicked()), SLOT(findWaveFiles())); + connect(ui->allProjRadioButton, SIGNAL(clicked()), SLOT(findWaveFiles())); + findWaveFiles(); + +} + +void UnusedWaveFiles::findWaveFiles() +{ + ui->filelistWidget->clear(); + printf("museProject =%s\n", museProject.toLatin1().data()); +// QFileInfo proj(museProject); +// QString projPath = proj.absolutePath(); + QDir dir(museProject); + QStringList filter; + filter.append("*.wav"); + filter.append("*.ogg"); + allWaveFiles= dir.entryList(filter); + if (!allWaveFiles.count()) + return; + // get med files + QStringList medFiles; + if (ui->currentProjRadioButton->isChecked()) { + medFiles.append(muse->projectName()); + } else { + printf("get ALLL *.med files!\n"); + QStringList medFilter("*.med"); + medFiles = dir.entryList(medFilter); + } + foreach (QString medFile, medFiles) { + QString fname = museProject+"/"+ medFile; + //printf("fopen %s\n", fname.toLatin1().data()); + FILE *fp =fopen(fname.toLatin1().data(),"r"); + QTextStream fileContent(fp); + while (!fileContent.atEnd()) { + QString line = fileContent.readLine(); + if (line.contains(".wav") || line.contains(".ogg")) { // optimization + foreach (QString wav, allWaveFiles) { + //printf("checking wav [%s]\n", wav.toLatin1().data() ); + if (line.contains(wav)) { + //int beforeSize=allWaveFiles.size(); + allWaveFiles.removeOne(wav); + //printf("removed one from list, %d %d\n", beforeSize, allWaveFiles.size()); + break; + } + } + } + } + } + + ui->filelistWidget->addItems(allWaveFiles); + update(); +} + +UnusedWaveFiles::~UnusedWaveFiles() +{ + delete ui; +} + +void UnusedWaveFiles::accept() +{ + int ret = QMessageBox::question(this,"Move files", "Are you sure you want to move away the unused files?", + QMessageBox::Ok, QMessageBox::Cancel); + if (ret == QMessageBox::Ok) { + QDir currDir(museProject); + currDir.mkdir("unused"); + + foreach(QString file, allWaveFiles) { + QFile::rename(museProject+ "/"+file, museProject + "/unused/" +file); + // move the wca file if it exists + QFileInfo wf(museProject + "/" + file); + if (QFile::exists(museProject + "/" + wf.baseName()+".wca")) { + QFile::rename(museProject + "/" + wf.baseName()+".wca", museProject + "/unused/" +wf.baseName()+".wca"); + + } + } + } + QDialog::accept(); +} diff --git a/muse2/muse/widgets/unusedwavefiles.h b/muse2/muse/widgets/unusedwavefiles.h new file mode 100644 index 00000000..fd1f524c --- /dev/null +++ b/muse2/muse/widgets/unusedwavefiles.h @@ -0,0 +1,25 @@ +#ifndef UNUSEDWAVEFILES_H +#define UNUSEDWAVEFILES_H + +#include + +namespace Ui { + class UnusedWaveFiles; +} + +class UnusedWaveFiles : public QDialog +{ + Q_OBJECT + QStringList allWaveFiles; +public: + explicit UnusedWaveFiles(QWidget *parent = 0); + ~UnusedWaveFiles(); + +public slots: + void accept(); + void findWaveFiles(); +private: + Ui::UnusedWaveFiles *ui; +}; + +#endif // UNUSEDWAVEFILES_H diff --git a/muse2/muse/widgets/unusedwavefiles.ui b/muse2/muse/widgets/unusedwavefiles.ui new file mode 100644 index 00000000..65c8c804 --- /dev/null +++ b/muse2/muse/widgets/unusedwavefiles.ui @@ -0,0 +1,131 @@ + + + UnusedWaveFiles + + + + 0 + 0 + 508 + 241 + + + + Dialog + + + + + + List of unused audio files in current project directory: + + + + + + + + + Current project + + + + + + + All .med files +in current + directory + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + + Qt::Horizontal + + + + 98 + 17 + + + + + + + + Move files to 'unused' subdir + + + true + + + + + + + Cancel + + + + + + + + + + + cancelButton + clicked() + UnusedWaveFiles + reject() + + + 416 + 331 + + + 305 + 183 + + + + + moveButton + clicked() + UnusedWaveFiles + accept() + + + 266 + 321 + + + 305 + 183 + + + + + -- cgit v1.2.3