summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim E. Real <termtech@rogers.com>2010-01-19 22:29:32 +0000
committerTim E. Real <termtech@rogers.com>2010-01-19 22:29:32 +0000
commitd65bd2bca695098fb038d9f3611d775bf66a3581 (patch)
tree5a34ce515b629c67080ab4d04c8595f9fa117f80
parent81753873d72dcc9767f5967ddc482ee7bc8c3c15 (diff)
Fixed compressed med/midi/kar files.
-rw-r--r--muse/ChangeLog7
-rw-r--r--muse/muse/app.cpp25
-rw-r--r--muse/muse/exportmidi.cpp3
-rw-r--r--muse/muse/globals.cpp38
-rw-r--r--muse/muse/globals.h2
-rw-r--r--muse/muse/midifile.cpp7
-rw-r--r--muse/muse/widgets/filedialog.cpp47
7 files changed, 120 insertions, 9 deletions
diff --git a/muse/ChangeLog b/muse/ChangeLog
index 23c01f91..3bcfdc8c 100644
--- a/muse/ChangeLog
+++ b/muse/ChangeLog
@@ -1,3 +1,10 @@
+19.01.2010
+ * Fixed: Saving/loading compressed .gz/.bz2 MusE .med files, + loading compressed .mid/.kar files (save broken, off for now). (T356)
+ - Changed filedialog.cpp:getSaveFileName() and MusE::loadProjectFile1.
+ - Added seperate save file dialog filters in globals.cpp.
+ - Disabled exporting of compressed midi/karaoke files (.mid/.kar) for now because
+ a compressed file is opened as a pipe, and pipes can't seek, resulting in a
+ corrupted midi file in MidiFile::writeTrack().
18.01.2010
* Added: Piano roll and drum editor edit menus: "Select prev/next part". With default hotkeys Alt+Left/Right. (T356)
- This is an easy way to switch parts when multiple part editing in one window (via Ctrl-E or Ctrl-D).
diff --git a/muse/muse/app.cpp b/muse/muse/app.cpp
index 9c9d5aa5..4fdcf825 100644
--- a/muse/muse/app.cpp
+++ b/muse/muse/app.cpp
@@ -1479,11 +1479,18 @@ void MusE::loadProjectFile1(const QString& name, bool songTemplate, bool loadAll
museProject = fi.dirPath(true);
project.setFile(name);
}
- QString ex = fi.extension(false).lower();
- if (ex.length() == 3)
- ex += ".";
- ex = ex.left(4);
- if (ex.isEmpty() || ex == "med.") {
+ // Changed by T356. 01/19/2010. We want the complete extension here.
+ //QString ex = fi.extension(false).lower();
+ //if (ex.length() == 3)
+ // ex += ".";
+ //ex = ex.left(4);
+ QString ex = fi.extension(true).lower();
+ QString mex = ex.section('.', -1, -1);
+ if((mex == "gz") || (mex == "bz2"))
+ mex = ex.section('.', -2, -2);
+
+ //if (ex.isEmpty() || ex == "med.") {
+ if (ex.isEmpty() || mex == "med") {
//
// read *.med file
//
@@ -1510,14 +1517,15 @@ void MusE::loadProjectFile1(const QString& name, bool songTemplate, bool loadAll
}
}
}
- else if (ex == "mid." || ex == "kar.") {
+ //else if (ex == "mid." || ex == "kar.") {
+ else if (mex == "mid." || mex == "kar.") {
setConfigDefaults();
if (!importMidi(name, false))
setUntitledProject();
}
else {
QMessageBox::critical(this, QString("MusE"),
- tr("Unknown File Format"));
+ tr("Unknown File Format: ") + ex);
setUntitledProject();
}
if (!songTemplate) {
@@ -1872,7 +1880,8 @@ void MusE::showTransport(bool flag)
bool MusE::saveAs()
{
// QString name = getSaveFileName(museProject, med_file_pattern, this,
- QString name = getSaveFileName(QString(""), med_file_pattern, this,
+// QString name = getSaveFileName(QString(""), med_file_pattern, this,
+ QString name = getSaveFileName(QString(""), med_file_save_pattern, this,
tr("MusE: Save As"));
bool ok = false;
if (!name.isEmpty()) {
diff --git a/muse/muse/exportmidi.cpp b/muse/muse/exportmidi.cpp
index 66ecbc3f..5a6c889e 100644
--- a/muse/muse/exportmidi.cpp
+++ b/muse/muse/exportmidi.cpp
@@ -112,7 +112,8 @@ void MusE::exportMidi()
{
MFile file(QString("midis"), QString(".mid"));
- FILE* fp = file.open("w", midi_file_pattern, this, false, true,
+ //FILE* fp = file.open("w", midi_file_pattern, this, false, true,
+ FILE* fp = file.open("w", midi_file_save_pattern, this, false, true,
tr("MusE: Export Midi"));
if (fp == 0)
return;
diff --git a/muse/muse/globals.cpp b/muse/muse/globals.cpp
index 0bd63dec..12a5f862 100644
--- a/muse/muse/globals.cpp
+++ b/muse/muse/globals.cpp
@@ -99,8 +99,43 @@ const char* midi_file_pattern[] = {
"All Files (*)",
0
};
+
+//FIXME: By T356 01/19/2010
+// If saving as a compressed file (gz or bz2),
+// the file is a pipe, and pipes can't seek !
+// This results in a corrupted midi file from MidiFile::writeTrack().
+// So exporting compressed midi has simply been disabled here for now...
+/*
+const char* midi_file_save_pattern[] = {
+ "Midi (*.mid)",
+ "gzip compressed Midi (*.mid.gz)",
+ "bzip2 compressed Midi (*.mid.bz2)",
+ "Karaoke (*.kar)",
+ "gzip compressed karaoke (*.kar.gz)",
+ "bzip2 compressed karaoke (*.kar.bz2)",
+ "All Files (*)",
+ 0
+ };
+*/
+const char* midi_file_save_pattern[] = {
+ "Midi (*.mid)",
+ "Karaoke (*.kar)",
+ "All Files (*)",
+ 0
+ };
+
const char* med_file_pattern[] = {
"med Files (*.med *.med.gz *.med.bz2)",
+ "gzip compressed med Files (*.med.gz)",
+ "bzip2 compressed med Files (*.med.bz2)",
+ "Uncompressed med Files (*.med)",
+ "All Files (*)",
+ 0
+ };
+const char* med_file_save_pattern[] = {
+ "med Files (*.med)",
+ "gzip compressed med Files (*.med.gz)",
+ "bzip2 compressed med Files (*.med.bz2)",
"All Files (*)",
0
};
@@ -113,11 +148,14 @@ const char* image_file_pattern[] = {
0
};
+// Not used.
+/*
const char* ctrl_file_pattern[] = {
"ctrl Files (*.ctrl *.ctrl.gz *.ctrl.bz2)",
"All Files (*)",
0
};
+*/
const char* part_file_pattern[] = {
"part Files (*.mpt)",
diff --git a/muse/muse/globals.h b/muse/muse/globals.h
index ad3483d8..fb4e42b1 100644
--- a/muse/muse/globals.h
+++ b/muse/muse/globals.h
@@ -67,7 +67,9 @@ extern int realTimePriority;
extern int midiRTPrioOverride;
extern const char* midi_file_pattern[]; //!< File name pattern for midi files
+extern const char* midi_file_save_pattern[]; //!< File name pattern for saving midi files
extern const char* med_file_pattern[]; //!< File name pattern for muse project files
+extern const char* med_file_save_pattern[]; //!< File name pattern for saving muse project files
extern const char* image_file_pattern[]; //!< File name pattern for image files (gfx)
extern const char* ctrl_file_pattern[]; //!< File name pattern for controller-files
extern const char* part_file_pattern[]; //!< File name pattern for part files
diff --git a/muse/muse/midifile.cpp b/muse/muse/midifile.cpp
index 4a66e384..319152d7 100644
--- a/muse/muse/midifile.cpp
+++ b/muse/muse/midifile.cpp
@@ -500,6 +500,13 @@ int MidiFile::readEvent(MidiPlayEvent* event, MidiFileTrack* t)
bool MidiFile::writeTrack(const MidiFileTrack* t)
{
+ //FIXME: By T356 01/19/2010
+ // If saving as a compressed file (gz or bz2),
+ // the file is a pipe, and pipes can't seek !
+ // This results in a corrupted midi file.
+ // So exporting compressed midi has been disabled (elsewhere)
+ // for now...
+
const MPEventList* events = &(t->events);
write("MTrk", 4);
int lenpos = ftell(fp);
diff --git a/muse/muse/widgets/filedialog.cpp b/muse/muse/widgets/filedialog.cpp
index 372c059e..ba599a3c 100644
--- a/muse/muse/widgets/filedialog.cpp
+++ b/muse/muse/widgets/filedialog.cpp
@@ -304,6 +304,53 @@ QString getSaveFileName(const QString &startWith,
if (dlg->exec() == QDialog::Accepted) {
result = dlg->selectedFile();
}
+
+ // Added by T356.
+ QString filt = dlg->selectedFilter();
+ int p2 = filt.findRev(')');
+ if(p2 != -1)
+ {
+ int p1 = filt.findRev('*', p2);
+ if(p1 != -1)
+ {
+ filt = filt.mid(p1 + 1, p2 - p1 - 1);
+ // Do we have a valid extension?
+ if(!filt.isEmpty())
+ {
+ // If the rightmost characters of the filename do not already contain
+ // the extension, add the extension to the filename.
+ if(result.right(filt.length()) != filt)
+ result += filt;
+ }
+ else
+ {
+ // Works, but no, we want to allow saving as any name without an extension...
+ /*
+ // Force the filter list to the first one (the preferred one), and then get the filter.
+ dlg->setSelectedFilter(0);
+ filt = dlg->selectedFilter();
+ p2 = filt.findRev(')');
+ if(p2 != -1)
+ {
+ p1 = filt.findRev('*', p2);
+ if(p1 != -1)
+ {
+ filt = filt.mid(p1 + 1, p2 - p1 - 1);
+ // Do we have a valid extension?
+ if(!filt.isEmpty())
+ {
+ // If the rightmost characters of the filename do not already contain
+ // the extension, add the extension to the filename.
+ if(result.right(filt.length()) != filt)
+ result += filt;
+ }
+ }
+ }
+ */
+ }
+ }
+ }
+
delete dlg;
return result;
}