Fix to PT5 format, (stereo tracks still not fully supported)
[ardour.git] / libs / ptformat / ptfformat.h
1 /*
2     Copyright (C) 2015  Damien Zammit
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 3 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14 */
15 #ifndef PTFFORMAT_H
16 #define PTFFORMAT_H
17
18 #include <string>
19 #include <algorithm>
20 #include <vector>
21 #include <stdint.h>
22
23 class PTFFormat {
24 public:
25         PTFFormat();
26         ~PTFFormat();
27
28         /* Return values:       0            success
29                                 -1           could not open file as ptf
30         */
31         int load(std::string path, int64_t targetsr);
32
33         typedef struct wav {
34                 std::string filename;
35                 uint16_t    index;
36
37                 int64_t     posabsolute;
38                 int64_t     length;
39
40                 bool operator ==(const struct wav& other) {
41                         return (this->filename == other.filename ||
42                                 this->index == other.index);
43                 }
44
45         } wav_t;
46
47         typedef struct region {
48                 std::string name;
49                 uint16_t    index;
50                 int64_t     startpos;
51                 int64_t     sampleoffset;
52                 int64_t     length;
53                 wav_t       wave;
54
55                 bool operator ==(const struct region& other) {
56                         return (this->index == other.index);
57                 }
58         } region_t;
59
60         typedef struct track {
61                 std::string name;
62                 uint16_t    index;
63                 uint8_t     playlist;
64                 region_t    reg;
65
66                 bool operator ==(const struct track& other) {
67                         return (this->name == other.name);
68                 }
69         } track_t;
70
71         std::vector<wav_t> audiofiles;
72         std::vector<region_t> regions;
73         std::vector<track_t> tracks;
74
75         static bool regionexistsin(std::vector<region_t> reg, uint16_t index) {
76                 std::vector<region_t>::iterator begin = reg.begin();
77                 std::vector<region_t>::iterator finish = reg.end();
78                 std::vector<region_t>::iterator found;
79
80                 wav_t w = { std::string(""), 0, 0, 0 };
81                 region_t r = { std::string(""), index, 0, 0, 0, w };
82
83                 if ((found = std::find(begin, finish, r)) != finish) {
84                         return true;
85                 }
86                 return false;
87         }
88
89         static bool wavexistsin(std::vector<wav_t> wv, uint16_t index) {
90                 std::vector<wav_t>::iterator begin = wv.begin();
91                 std::vector<wav_t>::iterator finish = wv.end();
92                 std::vector<wav_t>::iterator found;
93
94                 wav_t w = { std::string(""), index, 0, 0 };
95
96                 if ((found = std::find(begin, finish, w)) != finish) {
97                         return true;
98                 }
99                 return false;
100         }
101
102         int64_t sessionrate;
103         int64_t targetrate;
104         uint8_t version;
105
106         unsigned char c0;
107         unsigned char c1;
108         unsigned char *ptfunxored;
109         int len;
110
111 private:
112         bool foundin(std::string haystack, std::string needle);
113         void parse(void);
114         void unxor10(void);
115         void setrates(void);
116         void parse5header(void);
117         void parse7header(void);
118         void parse8header(void);
119         void parse9header(void);
120         void parse10header(void);
121         void parserest5(void);
122         void parserest89(void);
123         void parserest10(void);
124         void parseaudio5(void);
125         void parseaudio(void);
126         std::vector<wav_t> actualwavs;
127         float ratefactor;
128         std::string extension;
129         unsigned char key10a;
130         unsigned char key10b;
131 };
132
133
134 #endif