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

Close

[8a7247]: libkwave / Track.cpp Maximize Restore History

Download this file

Track.cpp    123 lines (106 with data), 3.7 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
/***************************************************************************
Track.cpp - collects one or more stripes in one track
-------------------
begin : Feb 10 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 "mt/Mutex.h"
#include "mt/MutexGuard.h"
#include "mt/MutexSet.h"
#include "libkwave/SampleInputStream.h"
#include "libkwave/Stripe.h"
#include "libkwave/Track.h"
//***************************************************************************
Track::Track()
:m_stripes(), m_lock_stripes()
{
}
//***************************************************************************
Track::Track(unsigned int length)
:m_stripes(), m_lock_stripes()
{
appendStripe(length);
}
//***************************************************************************
Stripe *Track::appendStripe(unsigned int length)
{
MutexGuard lock(m_lock_stripes);
Stripe *s = new Stripe(length);
ASSERT(s);
if (s) m_stripes.append(s);
debug("Track::appendStripe(%d): new stripe at %p", length, s);
return s;
}
//***************************************************************************
//void Track::appendSamples(const QArray<sample_t> &samples)
//{
// if (!samples.size()) return; // nothing to do
//
// // find the last stripe
// MutexGuard lock(m_lock_stripes);
// Stripe *s = 0;
// if (m_stripes.count() == 0) {
// // no stripe yet, add a new one
// s = new Stripe(samples);
// ASSERT(s);
// if (!s || (s->length() < samples.count()) ) {
// warning("allocating first stripe of track failed.");
// return;
// }
// } else {
// // get the last stripe
// s = m_stripes.last();
// }
//
// ASSERT(s);
// if (!s) {
// warning("no last stripe for appending data?");
// return;
// }
//
// // append samples to the last stripe
// *s << samples;
//
//}
//***************************************************************************
SampleInputStream *Track::openInputStream(InsertMode mode,
unsigned int left, unsigned int right)
{
MutexGuard lock(m_lock_stripes);
MutexSet stripe_locks;
QList<Stripe> stripes;
switch (mode) {
case Append: {
debug("Track::openInputStream(apppend)");
// create a new stripe
Stripe *s = new Stripe(0);
ASSERT(s);
if (!s) return 0;
// add to our stripes list and lock it
m_stripes.append(s);
stripe_locks.addLock(s->mutex());
// use new created stripe as start
stripes.append(s);
break;
}
case Insert:
debug("Track::openInputStream(insert, %u)", left);
break;
case Overwrite:
debug("Track::openInputStream(overwrite, %u, %u)", left, right);
break;
}
return new SampleInputStream(*this, stripes,
stripe_locks, mode, left, right);
}
//***************************************************************************
//***************************************************************************