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