Add preliminary PTX support for Protools 10 and 11
[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 <cstring>
20 #include <algorithm>
21 #include <vector>
22 #include <stdint.h>
23 #include "ptformat/visibility.h"
24
25 class LIBPTFORMAT_API PTFFormat {
26 public:
27         PTFFormat();
28         ~PTFFormat();
29
30         /* Return values:       0            success
31                                 -1           could not open file as ptf
32         */
33         int load(std::string path, int64_t targetsr);
34
35         typedef struct wav {
36                 std::string filename;
37                 uint16_t    index;
38
39                 int64_t     posabsolute;
40                 int64_t     length;
41
42                 bool operator <(const struct wav& other) {
43                         return (strcasecmp(this->filename.c_str(),
44                                         other.filename.c_str()) < 0);
45                 }
46
47                 bool operator ==(const struct wav& other) {
48                         return (this->filename == other.filename ||
49                                 this->index == other.index);
50                 }
51
52         } wav_t;
53
54         typedef struct region {
55                 std::string name;
56                 uint16_t    index;
57                 int64_t     startpos;
58                 int64_t     sampleoffset;
59                 int64_t     length;
60                 wav_t       wave;
61
62                 bool operator ==(const struct region& other) {
63                         return (this->index == other.index);
64                 }
65         } region_t;
66
67         typedef struct track {
68                 std::string name;
69                 uint16_t    index;
70                 uint8_t     playlist;
71                 region_t    reg;
72
73                 bool operator ==(const struct track& other) {
74                         return (this->name == other.name);
75                 }
76         } track_t;
77
78         std::vector<wav_t> audiofiles;
79         std::vector<region_t> regions;
80         std::vector<track_t> tracks;
81
82         static bool regionexistsin(std::vector<region_t> reg, uint16_t index) {
83                 std::vector<region_t>::iterator begin = reg.begin();
84                 std::vector<region_t>::iterator finish = reg.end();
85                 std::vector<region_t>::iterator found;
86
87                 wav_t w = { std::string(""), 0, 0, 0 };
88                 region_t r = { std::string(""), index, 0, 0, 0, w };
89
90                 if ((found = std::find(begin, finish, r)) != finish) {
91                         return true;
92                 }
93                 return false;
94         }
95
96         static bool wavexistsin(std::vector<wav_t> wv, uint16_t index) {
97                 std::vector<wav_t>::iterator begin = wv.begin();
98                 std::vector<wav_t>::iterator finish = wv.end();
99                 std::vector<wav_t>::iterator found;
100
101                 wav_t w = { std::string(""), index, 0, 0 };
102
103                 if ((found = std::find(begin, finish, w)) != finish) {
104                         return true;
105                 }
106                 return false;
107         }
108
109         int64_t sessionrate;
110         int64_t targetrate;
111         uint8_t version;
112
113         unsigned char c0;
114         unsigned char c1;
115         unsigned char *ptfunxored;
116         uint64_t len;
117
118 private:
119         bool foundin(std::string haystack, std::string needle);
120         void parse(void);
121         void unxor10(void);
122         void setrates(void);
123         void parse5header(void);
124         void parse7header(void);
125         void parse8header(void);
126         void parse9header(void);
127         void parse10header(void);
128         void parserest5(void);
129         void parserest89(void);
130         void parserest10(void);
131         void parseaudio5(void);
132         void parseaudio(void);
133         void resort(std::vector<wav_t> *ws);
134         uint8_t mostfrequent(uint32_t start, uint32_t stop);
135         std::vector<wav_t> actualwavs;
136         float ratefactor;
137         std::string extension;
138         unsigned char key10a;
139         unsigned char key10b;
140 };
141
142
143 #endif