22 #include <QMutexLocker> 23 #include <QReadLocker> 24 #include <QWriteLocker> 37 #define STRIPE_LENGTH_OPTIMAL (4UL * 1024UL * 1024UL) 46 #define STRIPE_LENGTH_MAXIMUM (STRIPE_LENGTH_OPTIMAL * 2) 55 #define STRIPE_LENGTH_MINIMUM (STRIPE_LENGTH_OPTIMAL / 2) 59 :m_lock(QMutex::Recursive), m_lock_usage(), m_stripes(), m_selected(true),
60 m_uuid(QUuid::createUuid())
67 m_uuid((uuid) ? *uuid : QUuid::createUuid())
85 QMutexLocker lock(&
m_lock);
114 Q_ASSERT(offset < stripe.
length());
117 if (!offset)
return 0;
121 if (!s.length())
return Stripe();
137 int index_before = -1;
151 while (it.hasNext()) {
152 const Stripe &s = it.next();
153 if (left > s.
end()) index_before =
m_stripes.indexOf(s);
156 if (index_before >= 0) {
160 m_stripes.insert(index_before + 1, stripe);
175 QMutexLocker lock(&
m_lock);
200 connect(stream, SIGNAL(destroyed(QObject*)),
202 Qt::DirectConnection);
212 QMutexLocker lock(&
m_lock);
217 if (!stripe.
length())
continue;
221 if (end < left)
continue;
222 if (start > right)
break;
224 if ((end <= right) && (start >= left)) {
226 stripes.append(stripe);
244 stripes.append(cropped);
253 bool succeeded =
true;
255 QMutexLocker lock(&
m_lock);
256 foreach (
Stripe stripe, stripes) {
277 QMutexLocker lock(&
m_lock);
280 if (right >= length) right = (
length) ? (length - 1) : 0;
302 QMutexLocker lock(&
m_lock);
317 if (!shift)
return true;
320 QMutexLocker lock(&
m_lock);
325 QMutableListIterator<Stripe> it(
m_stripes);
326 while (it.hasNext()) {
329 if (end < offset)
continue;
332 if (start >= offset)
break;
338 if (!new_stripe.
length())
return false;
339 it.insert(new_stripe);
348 Stripe s(offset + shift - 1);
369 QMutableListIterator<Stripe> it(
m_stripes);
371 while (it.hasPrevious()) {
372 Stripe &s = it.previous();
376 if (end < left)
break;
377 if (start > right)
continue;
379 if ((left <= start) && (right >= end)) {
390 if (end > right) end = right;
395 ((left <= s.
start()) && (right < s.
end())) ||
396 ((left > s.
start()) && (right >= s.
end())))
409 if (left <= s.
start()) {
422 if (!new_stripe.
length())
break;
424 it.insert(new_stripe);
445 if (!it.hasNext()) it.toFront();
447 while (it.hasNext()) {
451 Q_ASSERT(s.
start() != right);
452 if (s.
start() > right) {
480 unsigned int buf_offset,
unsigned int length)
482 Q_ASSERT(buf_offset + length <= buffer.
size());
483 if (buf_offset + length > buffer.
size())
return false;
487 if ((stripe) && (stripe->
end()+1 == offset) &&
490 unsigned int len =
length;
496 if (!stripe->
append(buffer, buf_offset, len))
504 int index_before = (stripe) ? (
m_stripes.indexOf(*stripe)) : -1;
513 Stripe new_stripe(offset);
516 if (!new_stripe.
append(buffer, buf_offset, len)) {
517 qWarning(
"Kwave::Track::appendAfter FAILED / OOM");
520 Q_ASSERT(new_stripe.
length() == len);
525 if (index_before >= 0) {
530 m_stripes.insert(index_before, new_stripe);
549 QMutableListIterator<Stripe> it(
m_stripes);
551 while (it.hasPrevious()) {
552 Stripe &s = it.previous();
554 if (start < offset)
break;
564 unsigned int buf_offset,
568 if (!length)
return true;
575 QMutexLocker _lock(&
m_lock);
594 Stripe *target_stripe = Q_NULLPTR;
595 Stripe *stripe_before = Q_NULLPTR;
596 QMutableListIterator<Stripe> it(
m_stripes);
597 while (it.hasNext()) {
603 if (offset >= st + len) stripe_before = &s;
605 if ((offset >= st) && (offset < st+len)) {
623 if (stripe_before && (offset == stripe_before->
start()+
637 if (!target_stripe || (offset == target_stripe->
start())) {
648 if (!new_stripe.
length()) {
671 QMutexLocker _lock(&
m_lock);
678 Stripe *stripe_before = Q_NULLPTR;
679 QMutableListIterator<Stripe> it(
m_stripes);
680 while (it.hasNext()) {
682 if (s.
start() >= offset)
break;
683 if (s.
end() < offset) stripe_before = &s;
685 appendAfter(stripe_before, offset, buffer, buf_offset, length);
716 QMutableListIterator<Kwave::Stripe> it(
m_stripes);
717 while (it.hasNext()) {
719 stripe = &(it.next());
720 if (!before)
continue;
728 const sample_index_t combined_len = stripe_end - before_start + 1;
744 stripe->
start() - before_start);
745 if (!before->
combine(offset, *stripe))
777 qDebug(
"------------------------------------");
778 unsigned int index = 0;
782 if (index && (start <= last_end))
783 qDebug(
"--- OVERLAP ---");
784 if (start > last_end+1)
785 qDebug(
" : GAP [%10lu - %10lu] (%10lu)",
786 static_cast<unsigned long int>(last_end + ((index) ? 1 : 0)),
787 static_cast<unsigned long int>(start - 1),
788 static_cast<unsigned long int>(start - last_end -
790 qDebug(
"#%6d: %p - [%10lu - %10lu] (%10lu)",
791 index++, static_cast<const void *>(&s),
792 static_cast<unsigned long int>(s.
start()),
793 static_cast<unsigned long int>(s.
end()),
794 static_cast<unsigned long int>(s.
length()));
797 qDebug(
"------------------------------------");
bool combine(unsigned int offset, Kwave::Stripe &other)
unsigned int append(const Kwave::SampleArray &samples, unsigned int offset, unsigned int count)
unsigned int length() const
void deleteRange(sample_index_t offset, sample_index_t length, bool make_gap=false)
sample_index_t left() const
void sigSamplesInserted(Kwave::Track *src, sample_index_t offset, sample_index_t length)
QList< Stripe > m_stripes
const QUuid & uuid() const
bool appendAfter(Stripe *stripe, sample_index_t offset, const Kwave::SampleArray &buffer, unsigned int buf_offset, unsigned int length)
sample_index_t right() const
Stripe splitStripe(Stripe &stripe, unsigned int offset)
Kwave::SampleReader * openReader(Kwave::ReaderMode mode, sample_index_t left=0, sample_index_t right=SAMPLE_INDEX_MAX)
bool mergeStripes(const Kwave::Stripe::List &stripes)
sample_index_t unlockedLength()
bool insertSpace(sample_index_t offset, sample_index_t shift)
bool connect(Kwave::StreamObject &source, const char *output, Kwave::StreamObject &sink, const char *input)
void deleteRange(unsigned int offset, unsigned int length)
unsigned int resize(unsigned int length, bool initialize=true)
sample_index_t start() const
#define STRIPE_LENGTH_MAXIMUM
void sigSamplesDeleted(Kwave::Track *src, sample_index_t offset, sample_index_t length)
sample_index_t end() const
bool mergeStripe(Kwave::Stripe &stripe)
#define STRIPE_LENGTH_OPTIMAL
#define STRIPE_LENGTH_MINIMUM
void sigSelectionChanged(bool selected)
bool writeSamples(Kwave::InsertMode mode, sample_index_t offset, const Kwave::SampleArray &buffer, unsigned int buf_offset, unsigned int length)
void setStart(sample_index_t start)
unsigned int size() const
Kwave::Writer * openWriter(Kwave::InsertMode mode, sample_index_t left=0, sample_index_t right=0)
void sigSamplesModified(Kwave::Track *src, sample_index_t offset, sample_index_t length)
QReadWriteLock m_lock_usage
Kwave::Stripe::List stripes(sample_index_t left, sample_index_t right)
void unlockedDelete(sample_index_t offset, sample_index_t length, bool make_gap=false)
void appendStripe(sample_index_t length)
void moveRight(sample_index_t offset, sample_index_t shift)