summaryrefslogtreecommitdiff
path: root/libs/ptformat
diff options
context:
space:
mode:
authorDamien Zammit <damien@zamaudio.com>2016-04-16 16:31:44 +1000
committerRobin Gareus <robin@gareus.org>2016-04-16 12:21:12 +0200
commit277893b130f5ec1efa4aba44d92f038dad2793ef (patch)
tree7af786a3eb95a2a67ef1a80d5adbb2bbfa5f5253 /libs/ptformat
parent241f734af475cec96dcb6f9d1aad77a6e2ec2a8d (diff)
ptformat: Make PT import more resilient to bad user choices and display messages
Previously, libptformat would attempt to parse all kinds of files, now the library stops parsing when the version number and session rate is outside valid ranges, returning an error code to the caller. If there is a valid PT file detected, but some audio files are missing, Ardour now pops up an error message to inform the user that some files may be missing from the import. A success message is displayed otherwise. Signed-off-by: Damien Zammit <damien@zamaudio.com>
Diffstat (limited to 'libs/ptformat')
-rw-r--r--libs/ptformat/ptfformat.cc21
-rw-r--r--libs/ptformat/ptfformat.h2
2 files changed, 20 insertions, 3 deletions
diff --git a/libs/ptformat/ptfformat.cc b/libs/ptformat/ptfformat.cc
index 048c174918..8c3452c868 100644
--- a/libs/ptformat/ptfformat.cc
+++ b/libs/ptformat/ptfformat.cc
@@ -113,6 +113,7 @@ PTFFormat::load(std::string path, int64_t targetsr) {
uint64_t i;
uint64_t j;
int inv;
+ int err;
if (! (fp = fopen(path.c_str(), "rb"))) {
return -1;
@@ -257,8 +258,12 @@ PTFFormat::load(std::string path, int64_t targetsr) {
}
}
+ if (version < 5 || version > 12)
+ return -1;
targetrate = targetsr;
- parse();
+ err = parse();
+ if (err)
+ return -1;
return 0;
}
@@ -298,36 +303,48 @@ PTFFormat::unxor10(void)
}
}
-void
+int
PTFFormat::parse(void) {
if (version == 5) {
parse5header();
setrates();
+ if (sessionrate < 44100 || sessionrate > 192000)
+ return -1;
parseaudio5();
parserest5();
} else if (version == 7) {
parse7header();
setrates();
+ if (sessionrate < 44100 || sessionrate > 192000)
+ return -1;
parseaudio();
parserest89();
} else if (version == 8) {
parse8header();
setrates();
+ if (sessionrate < 44100 || sessionrate > 192000)
+ return -1;
parseaudio();
parserest89();
} else if (version == 9) {
parse9header();
setrates();
+ if (sessionrate < 44100 || sessionrate > 192000)
+ return -1;
parseaudio();
parserest89();
} else if (version == 10 || version == 11 || version == 12) {
parse10header();
setrates();
+ if (sessionrate < 44100 || sessionrate > 192000)
+ return -1;
parseaudio();
parserest10();
} else {
// Should not occur
+ return -1;
}
+ return 0;
}
void
diff --git a/libs/ptformat/ptfformat.h b/libs/ptformat/ptfformat.h
index 1ae362d672..785544daa0 100644
--- a/libs/ptformat/ptfformat.h
+++ b/libs/ptformat/ptfformat.h
@@ -117,7 +117,7 @@ public:
private:
bool foundin(std::string haystack, std::string needle);
- void parse(void);
+ int parse(void);
void unxor10(void);
void setrates(void);
void parse5header(void);