Fixed pt import start offsets and samplerate mismatch offsets
[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->index == other.index);
42                 }
43
44         } wav_t;
45
46         typedef struct region {
47                 std::string name;
48                 uint16_t    index;
49                 int64_t     startpos;
50                 int64_t     sampleoffset;
51                 int64_t     length;
52                 wav_t       wave;
53
54                 bool operator ==(const struct region& other) {
55                         return (this->index == other.index);
56                 }
57         } region_t;
58
59         typedef struct track {
60                 std::string name;
61                 uint16_t    index;
62                 uint8_t     playlist;
63                 region_t    reg;
64
65                 bool operator ==(const struct track& other) {
66                         return (this->index == other.index);
67                 }
68         } track_t;
69
70         std::vector<wav_t> audiofiles;
71         std::vector<region_t> regions;
72         std::vector<track_t> tracks;
73
74         static bool trackexistsin(std::vector<track_t> tr, uint16_t index) {
75                 std::vector<track_t>::iterator begin = tr.begin();
76                 std::vector<track_t>::iterator finish = tr.end();
77                 std::vector<track_t>::iterator found;
78
79                 track_t f = { std::string(""), index };
80
81                 if ((found = std::find(begin, finish, f)) != finish) {
82                         return true;
83                 }
84                 return false;
85         }
86
87         static bool regionexistsin(std::vector<region_t> reg, uint16_t index) {
88                 std::vector<region_t>::iterator begin = reg.begin();
89                 std::vector<region_t>::iterator finish = reg.end();
90                 std::vector<region_t>::iterator found;
91
92                 region_t r = { std::string(""), index };
93
94                 if ((found = std::find(begin, finish, r)) != finish) {
95                         return true;
96                 }
97                 return false;
98         }
99
100         static bool wavexistsin(std::vector<wav_t> wv, uint16_t index) {
101                 std::vector<wav_t>::iterator begin = wv.begin();
102                 std::vector<wav_t>::iterator finish = wv.end();
103                 std::vector<wav_t>::iterator found;
104
105                 wav_t w = { std::string(""), index };
106
107                 if ((found = std::find(begin, finish, w)) != finish) {
108                         return true;
109                 }
110                 return false;
111         }
112
113         int64_t sessionrate;
114         int64_t targetrate;
115         uint8_t version;
116
117         unsigned char c0;
118         unsigned char c1;
119         unsigned char *ptfunxored;
120         int len;
121
122 private:
123         bool foundin(std::string haystack, std::string needle);
124         void parse(void);
125         void setrates(void);
126         void parse8header(void);
127         void parse9header(void);
128         void parserest(void);
129         std::vector<wav_t> actualwavs;
130         float ratefactor;
131 };
132
133
134 #endif