2 Copyright (C) 2015 Damien Zammit
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.
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.
23 #include "ptformat/visibility.h"
25 class LIBPTFORMAT_API PTFFormat {
30 /* Return values: 0 success
31 -1 could not open file as ptf
33 int load(std::string path, int64_t targetsr);
42 bool operator <(const struct wav_t& other) const {
43 return (strcasecmp(this->filename.c_str(),
44 other.filename.c_str()) < 0);
47 bool operator ==(const struct wav_t& other) const {
48 return (this->filename == other.filename ||
49 this->index == other.index);
61 typedef struct region {
68 std::vector<midi_ev_t> midi;
70 bool operator ==(const struct region& other) {
71 return (this->index == other.index);
75 typedef struct track {
81 bool operator ==(const struct track& other) {
82 return (this->name == other.name);
86 std::vector<wav_t> audiofiles;
87 std::vector<region_t> regions;
88 std::vector<track_t> tracks;
90 static bool regionexistsin(std::vector<region_t> reg, uint16_t index) {
91 std::vector<region_t>::iterator begin = reg.begin();
92 std::vector<region_t>::iterator finish = reg.end();
93 std::vector<region_t>::iterator found;
95 wav_t w = { std::string(""), 0, 0, 0 };
96 std::vector<midi_ev_t> m;
97 region_t r = { std::string(""), index, 0, 0, 0, w, m};
99 if ((found = std::find(begin, finish, r)) != finish) {
105 static bool wavexistsin(std::vector<wav_t> wv, uint16_t index) {
106 std::vector<wav_t>::iterator begin = wv.begin();
107 std::vector<wav_t>::iterator finish = wv.end();
108 std::vector<wav_t>::iterator found;
110 wav_t w = { std::string(""), index, 0, 0 };
112 if ((found = std::find(begin, finish, w)) != finish) {
126 unsigned char *ptfunxored;
130 bool foundin(std::string haystack, std::string needle);
132 bool parse_version();
133 uint8_t gen_xor_delta(uint8_t xor_value, uint8_t mul, bool negative);
135 void parse5header(void);
136 void parse7header(void);
137 void parse8header(void);
138 void parse9header(void);
139 void parse10header(void);
140 void parserest5(void);
141 void parserest89(void);
142 void parserest10(void);
143 void parseaudio5(void);
144 void parseaudio(void);
145 void parsemidi(void);
146 void resort(std::vector<wav_t>& ws);
147 std::vector<wav_t> actualwavs;
149 std::string extension;
150 unsigned char key10a;
151 unsigned char key10b;