File: audex.h

package info (click to toggle)
audex 0.74~b1-1.1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 3,348 kB
  • sloc: cpp: 10,163; makefile: 7; sh: 3
file content (253 lines) | stat: -rw-r--r-- 6,810 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/* AUDEX CDDA EXTRACTOR
 * Copyright (C) 2007-2011 Marco Nelles (audex@maniatek.com)
 * <http://kde.maniatek.com/audex>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef AUDEX_HEADER
#define AUDEX_HEADER

#include <QQueue>
#include <QString>
#include <QDir>
#include <QTimer>

#include <KDebug>
#include <KLocale>
#include <KDiskFreeSpaceInfo>

#include "models/profilemodel.h"
#include "models/cddamodel.h"
#include "utils/patternparser.h"
#include "utils/playlist.h"
#include "utils/cddaextractthread.h"
#include "utils/wavefilewriter.h"
#include "utils/encoderwrapper.h"
#include "utils/tmpdir.h"
#include "utils/upload.h"
#include "utils/hashlist.h"
#include "utils/parameters.h"
#include "utils/cuesheetwriter.h"

#include "preferences.h"

class AudexJob : public QObject {
  Q_OBJECT
public:
  AudexJob(QObject *parent = 0) : QObject(parent) {
    source_filename = "";
    target_filename = "";
    _trackno = 0;
  }
  ~AudexJob() { }
  void setSourceFilename(const QString& n) { source_filename = n; }
  QString sourceFilename() const { return source_filename; }
  void setTargetFilename(const QString& n) { target_filename = n; }
  QString targetFilename() const { return target_filename; }
  void setTrackNo(const int t) { _trackno = t; }
  int trackNo() const { return _trackno; }
private:
  QString source_filename;
  QString target_filename;
  int _trackno;
};

class AudexJobs : public QObject {
  Q_OBJECT
public:
  AudexJobs(QObject *parent = 0) : QObject(parent) {
    job_in_progress = FALSE;
  }
  ~AudexJobs() {
    for (int i = 0; i < cache.count(); i++) {
      //make really sure all files are away
      QFile file(cache.at(i)->sourceFilename());
      if (file.exists()) file.remove();
      delete cache.at(i);
    }
  }
  AudexJob* orderJob() {
    if (job_queue.isEmpty()) {
      return NULL;
    } else {
      job_in_progress = TRUE;
      return job_queue.dequeue();
    }
  }
  void reportJobFinished() {
    job_in_progress = FALSE;
  }
  bool jobInProgress() {
    return job_in_progress;
  }
  bool pendingJobs() {
    return (job_queue.count() > 0);
  }
public slots:
  void addNewJob(const QString& sourceFilename, const QString& targetFilename, const int trackno) {
    AudexJob *j = new AudexJob();
    j->setSourceFilename(sourceFilename);
    j->setTargetFilename(targetFilename);
    j->setTrackNo(trackno);
    job_queue.enqueue(j);
    cache.append(j);
    emit newJobAvailable();
  }
signals:
  void newJobAvailable();
private:
  QQueue<AudexJob*> job_queue;
  QList<AudexJob*> cache;
  bool job_in_progress;
};

class Audex : public QObject {

  Q_OBJECT

public:
  Audex(QWidget* parent,
	ProfileModel *profile_model,
	CDDAModel *cdda_model);
  ~Audex();

  bool prepare();

public slots:
  void start();
  void cancel();

  const QStringList& extractProtocol();
  const QStringList& encoderProtocol();

private slots:
  void start_extract();
  void finish_extract();
  void start_encode();
  void finish_encode();

  void calculate_speed_extract();
  void calculate_speed_encode();

  void progress_extract(int percent_of_track, int sector, int overall_sectors_read);
  void progress_encode(int percent);

  void write_to_wave(const QByteArray& data);

  void start_ftp_transfer(const QString& filename);
  void progress_ftp_transfer(const int percent, const int overall);
  void finished_ftp_transfer(const QString& filename);

  void slot_error(const QString& message, const QString& details = QString());
  void slot_warning(const QString& message);
  void slot_info(const QString& message);

  void check_if_thread_still_running();

signals:
  void changedExtractTrack(int no, int total, const QString& artist, const QString& title);
  void changedEncodeTrack(int no, int total, const QString& filename);

  void progressExtractTrack(int percent);
  void progressExtractOverall(int percent);
  void progressEncodeTrack(int percent);
  void progressEncodeOverall(int percent);

  void speedExtract(double times);
  void speedEncode(double times);

  void ftpUploadStart(const QString& filename);
  void ftpUploadProgress(const int percent, const int overall);
  void ftpUploadFinished(const QString& filename);

  void finished(bool successful);

  void timeout();

  void error(const QString& message,
	const QString& details = QString());
  void warning(const QString& message);
  void info(const QString& message);

private:
  QWidget *parent;
  ProfileModel *profile_model;
  CDDAModel *cdda_model;
  EncoderWrapper *encoder_wrapper;
  CDDAExtractThread *cdda_extract_thread;
  AudexJobs *jobs;
  WaveFileWriter *wave_file_writer;
  TmpDir *tmp_dir;

  QString p_profile_name;
  QString p_suffix;
  bool p_single_file;

  bool construct_target_filename(QString& targetFilename,
	int trackno, int cdno, int gindex,
	const QString& artist, const QString& title,
	const QString& tartist, const QString& ttitle,
	const QString& date, const QString& genre,
	const QString& ext, const QString& basepath,
	bool fat_compatible, bool replacespaceswithunderscores,
        bool _2digitstracknum,
	bool overwrite_existing_files, bool is_first_track);
	
  bool construct_target_filename_for_singlefile(QString& targetFilename,
	int cdno,
	const QString& artist, const QString& title,
	const QString& date, const QString& genre,
	const QString& ext, const QString& basepath,
	bool overwrite_existing_files);

  bool check();

  QString tmp_path;
  QString target_dir;
  QStringList target_filename_list;

  bool _finished;
  bool _finished_successful;
  void request_finish(bool successful);
  void execute_finish();

  int process_counter;
  bool timeout_done;
  int timeout_counter;

  /*PROCESS 1: EXTRACTING*/
  QString ex_track_source_filename;
  QString ex_track_target_filename;
  int ex_track_index;
  int ex_track_count;
  QTimer *timer_extract;
  int current_sector;
  int last_measuring_point_sector;
  int overall_frames;

  /*PROCESS 2: ENCODING*/
  QString en_track_filename;
  QString en_track_target_filename;
  int en_track_index;
  int en_track_count;
  QTimer *timer_encode;
  int current_encoder_percent;
  int last_measuring_point_encoder_percent;

  qreal size_of_all_files_in_list(const QStringList& filenames) const;
  
};

#endif