Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[3e4acc]: libkwave / MultiTrackReader.cpp Maximize Restore History

Download this file

MultiTrackReader.cpp    159 lines (139 with data), 5.0 kB

  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
/***************************************************************************
MultiTrackReader.cpp - reader for multi-track signals
-------------------
begin : Sat Jun 30 2001
copyright : (C) 2001 by Thomas Eschenbacher
email : Thomas Eschenbacher <thomas.eschenbacher@gmx.de>
***************************************************************************/
/***************************************************************************
* *
* 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 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "config.h"
#include "libkwave/MultiTrackReader.h"
#include "libkwave/SampleReader.h"
#include "libkwave/SignalManager.h"
//***************************************************************************
MultiTrackReader::MultiTrackReader()
:Kwave::MultiTrackSource<SampleReader, false>(0,0),
m_first(0), m_last(0), m_canceled(false)
{
}
//***************************************************************************
MultiTrackReader::MultiTrackReader(Kwave::ReaderMode mode,
SignalManager &signal_manager,
const QList<unsigned int> &track_list,
sample_index_t first, sample_index_t last)
:Kwave::MultiTrackSource<SampleReader, false>(0),
m_first(first), m_last(last), m_canceled(false)
{
unsigned int index = 0;
foreach(unsigned int track, track_list) {
SampleReader *s = signal_manager.openSampleReader(
mode, track, first, last);
if (!s) break;
insert(index++, s);
Q_ASSERT(index == tracks());
}
}
//***************************************************************************
MultiTrackReader::~MultiTrackReader()
{
clear();
}
//***************************************************************************
sample_index_t MultiTrackReader::first() const
{
return m_first;
}
//***************************************************************************
sample_index_t MultiTrackReader::last() const
{
return m_last;
}
//***************************************************************************
bool MultiTrackReader::eof() const
{
const unsigned int c = tracks();
for (unsigned int r = 0; r < c; r++) {
SampleReader *reader = at(r);
Q_ASSERT(reader);
if (!reader) continue;
if (!reader->eof()) return false;
}
return true;
}
//***************************************************************************
void MultiTrackReader::proceeded()
{
qreal sum = 0;
qreal total = 0;
unsigned int track;
const unsigned int n_tracks = tracks();
for (track = 0; track < n_tracks; ++track) {
SampleReader *r = at(track);
if (r) {
sum += (r->pos() - r->first());
total += (r->last() - r->first() + 1);
}
}
emit progress(qreal(100.0) * sum / total);
}
//***************************************************************************
void MultiTrackReader::reset()
{
unsigned int track;
const unsigned int n_tracks = tracks();
for (track=0; track < n_tracks; ++track) {
SampleReader *r = at(track);
if (r) r->reset();
}
emit progress(0);
}
//***************************************************************************
bool MultiTrackReader::insert(unsigned int track, SampleReader *reader)
{
if (reader) {
connect(
reader, SIGNAL(proceeded()),
this, SLOT(proceeded()),
Qt::DirectConnection
);
}
return Kwave::MultiTrackSource<SampleReader, false>::insert(
track, reader);
}
//***************************************************************************
void MultiTrackReader::skip(sample_index_t count)
{
unsigned int track;
const unsigned int n_tracks = tracks();
for (track=0; track < n_tracks; ++track) {
SampleReader *r = at(track);
if (r) r->skip(count);
}
}
//***************************************************************************
void MultiTrackReader::seek(sample_index_t pos)
{
unsigned int track;
const unsigned int n_tracks = tracks();
for (track=0; track < n_tracks; ++track) {
SampleReader *r = at(track);
if (r) r->seek(pos);
}
}
//***************************************************************************
void MultiTrackReader::cancel()
{
m_canceled = true;
}
//***************************************************************************
using namespace Kwave;
#include "MultiTrackReader.moc"
//***************************************************************************
//***************************************************************************