remove C++11'isms from libptformat. back to C++98 compat.
[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) const {
43                         return (strcasecmp(this->filename.c_str(),
44                                         other.filename.c_str()) < 0);
45                 }
46
47                 bool operator ==(const struct wav& other) const {
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                 track ()
69                         : index (0)
70                         , playlist (0)
71                 {
72                         memset ((void*)&reg, 0, sizeof(region_t));
73                 }
74
75                 track (std::string n, uint16_t i, uint8_t p, region_t *r)
76                         : name (n)
77                         , index (i)
78                         , playlist (p)
79                 {
80                         set_region (r);
81                 }
82
83                 void set_region (region_t *r) {
84                         memcpy ((void*)&reg, (void*)r, sizeof(region_t));
85                 }
86
87                 std::string name;
88                 uint16_t    index;
89                 uint8_t     playlist;
90                 region_t    reg;
91
92                 bool operator ==(const struct track& other) {
93                         return (this->name == other.name);
94                 }
95         } track_t;
96
97         std::vector<wav_t> audiofiles;
98         std::vector<region_t> regions;
99         std::vector<track_t> tracks;
100
101         static bool regionexistsin(std::vector<region_t> reg, uint16_t index) {
102                 std::vector<region_t>::iterator begin = reg.begin();
103                 std::vector<region_t>::iterator finish = reg.end();
104                 std::vector<region_t>::iterator found;
105
106                 wav_t w = { std::string(""), 0, 0, 0 };
107                 region_t r = { std::string(""), index, 0, 0, 0, w };
108
109                 if ((found = std::find(begin, finish, r)) != finish) {
110                         return true;
111                 }
112                 return false;
113         }
114
115         static bool wavexistsin(std::vector<wav_t> wv, uint16_t index) {
116                 std::vector<wav_t>::iterator begin = wv.begin();
117                 std::vector<wav_t>::iterator finish = wv.end();
118                 std::vector<wav_t>::iterator found;
119
120                 wav_t w = { std::string(""), index, 0, 0 };
121
122                 if ((found = std::find(begin, finish, w)) != finish) {
123                         return true;
124                 }
125                 return false;
126         }
127
128         int64_t sessionrate;
129         int64_t targetrate;
130         uint8_t version;
131
132         unsigned char c0;
133         unsigned char c1;
134         unsigned char *ptfunxored;
135         uint64_t len;
136
137 private:
138         bool foundin(std::string haystack, std::string needle);
139         void parse(void);
140         void unxor10(void);
141         void setrates(void);
142         void parse5header(void);
143         void parse7header(void);
144         void parse8header(void);
145         void parse9header(void);
146         void parse10header(void);
147         void parserest5(void);
148         void parserest89(void);
149         void parserest10(void);
150         void parseaudio5(void);
151         void parseaudio(void);
152         void resort(std::vector<wav_t> *ws);
153         uint8_t mostfrequent(uint32_t start, uint32_t stop);
154         std::vector<wav_t> actualwavs;
155         float ratefactor;
156         std::string extension;
157         unsigned char key10a;
158         unsigned char key10b;
159 };
160
161
162 #endif