1 /* BEGIN_COMMON_COPYRIGHT_HEADER 2 * (c)LGPL2+ 3 * 4 * Flacon - audio File Encoder 5 * https://github.com/flacon/flacon 6 * 7 * Copyright: 2017 8 * Alexander Sokoloff <sokoloff.a@gmail.com> 9 * 10 * This library is free software; you can redistribute it and/or 11 * modify it under the terms of the GNU Lesser General Public 12 * License as published by the Free Software Foundation; either 13 * version 2.1 of the License, or (at your option) any later version. 14 15 * This library is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 * Lesser General Public License for more details. 19 20 * You should have received a copy of the GNU Lesser General Public 21 * License along with this library; if not, write to the Free Software 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 23 * 24 * END_COMMON_COPYRIGHT_HEADER */ 25 26 #ifndef TOOLS_H 27 #define TOOLS_H 28 29 #include <QString> 30 #include <QStringList> 31 #include <QVector> 32 #include "wavheader.h" 33 #include "settings.h" 34 35 class QIODevice; 36 class Disc; 37 38 class TestCueFile 39 { 40 public: 41 explicit TestCueFile(const QString &fileName); 42 fileName()43 QString fileName() const { return mFileName; } 44 45 void setWavFile(const QString &value); wavFile()46 QString wavFile() const { return mWavFile; } 47 48 void addTrack(const QString &index0, const QString &index1); 49 void addTrack(const QString &index1); 50 51 void write(); 52 53 private: 54 struct TestCueTrack 55 { 56 QString index0; 57 QString index1; 58 TestCueTrackTestCueTrack59 TestCueTrack() : 60 index0(""), 61 index1("") 62 { 63 } 64 TestCueTrackTestCueTrack65 explicit TestCueTrack(const QString &index1) : 66 index0(""), 67 index1(index1) 68 { 69 } 70 TestCueTrackTestCueTrack71 TestCueTrack(const QString &index0, const QString &index1) : 72 index0(index0), 73 index1(index1) 74 { 75 } 76 }; 77 78 QString mFileName; 79 QString mWavFile; 80 QVector<TestCueTrack> mTracks; 81 }; 82 83 class TestSettings : public Settings 84 { 85 Q_OBJECT 86 public: TestSettings(const QString & fileName)87 TestSettings(const QString &fileName) : 88 Settings(fileName) { } 89 void apply(const QMap<QString, QVariant> &values); 90 }; 91 92 QString calcAudioHash(const QString &fileName); 93 bool compareAudioHash(const QString &file1, const QString &expected); 94 void writeHexString(const QString &str, QIODevice *out); 95 QByteArray writeHexString(const QString &str); 96 void createWavFile(const QString &fileName, const QString &header, const int duration = 0); 97 void createWavFile(const QString &fileName, quint16 bitsPerSample, quint32 sampleRate, uint durationSec); 98 void encodeAudioFile(const QString &wavFileName, const QString &outFileName); 99 void testFail(const QString &message, const char *file, int line); 100 101 #define FAIL(message) \ 102 do { \ 103 testFail(message, __FILE__, __LINE__); \ 104 } while (0) 105 106 Disc *loadFromCue(const QString &cueFile); 107 108 #endif // TOOLS_H 109