kwave  18.07.70
Stripe.h
Go to the documentation of this file.
1 /***************************************************************************
2  Stripe.h - continuous block of samples
3  -------------------
4  begin : Feb 09 2001
5  copyright : (C) 2001 by Thomas Eschenbacher
6  email : Thomas Eschenbacher <thomas.eschenbacher@gmx.de>
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef STRIPE_H
19 #define STRIPE_H
20 
21 #include "config.h"
22 
23 #include <QtGlobal>
24 #include <QExplicitlySharedDataPointer>
25 #include <QMutex>
26 #include <QSharedData>
27 
28 #include "libkwave/MemoryManager.h"
29 #include "libkwave/Sample.h"
30 #include "libkwave/SampleArray.h"
31 
32 //***************************************************************************
33 namespace Kwave
34 {
35  class Q_DECL_EXPORT Stripe
36  {
37  public:
38 
42  Stripe();
43 
45  Stripe(const Stripe &other);
46 
51  Stripe(sample_index_t start);
52 
60  Stripe(sample_index_t start, const Kwave::SampleArray& samples);
61 
70  Stripe(sample_index_t start, Stripe& stripe, unsigned int offset);
71 
75  virtual ~Stripe();
76 
80  sample_index_t start() const;
81 
85  void setStart(sample_index_t start);
86 
90  unsigned int length() const;
91 
96  sample_index_t end() const;
97 
109  unsigned int resize(unsigned int length, bool initialize = true);
110 
118  unsigned int append(const Kwave::SampleArray &samples,
119  unsigned int offset,
120  unsigned int count);
121 
128  void deleteRange(unsigned int offset, unsigned int length);
129 
139  void overwrite(unsigned int offset, const Kwave::SampleArray &source,
140  unsigned int srcoff, unsigned int srclen);
141 
148  bool combine(unsigned int offset, Kwave::Stripe &other);
149 
161  unsigned int read(Kwave::SampleArray &buffer, unsigned int dstoff,
162  unsigned int offset, unsigned int length);
163 
172  void minMax(unsigned int first, unsigned int last,
173  sample_t &min, sample_t &max);
174 
179  Stripe &operator << (const Kwave::SampleArray &samples);
180 
182  bool operator == (const Stripe &other) const;
183 
185  Stripe &operator = (const Stripe &other);
186 
192  class List: public QList<Kwave::Stripe>
193  {
194  public:
195 
198  :QList<Kwave::Stripe>(), m_left(0), m_right(0)
199  {
200  }
201 
204  :QList<Kwave::Stripe>(), m_left(left), m_right(right)
205  {
206  }
207 
209  virtual ~List()
210  {
211  }
212 
214  inline sample_index_t left() const { return m_left; }
215 
217  inline sample_index_t right() const { return m_right; }
218 
219  private:
222 
225  };
226 
227  private:
228 
238  unsigned int resizeStorage(unsigned int length);
239 
240  private:
241 
248  {
249  public:
254  explicit MappedArray(Stripe &stripe);
255 
257  virtual ~MappedArray();
258 
269  unsigned int copy(unsigned int dst, unsigned int src,
270  unsigned int cnt);
271 
283  unsigned int read(Kwave::SampleArray &buffer, unsigned int dstoff,
284  unsigned int offset, unsigned int length);
285 
286  private:
287 
290 
293 
295  unsigned int m_length;
296  };
297 
298  private:
299 
301  sample_t *mapStorage();
302 
304  void unmapStorage();
305 
306  private:
307 
308  class StripeStorage: public QSharedData
309  {
310  public:
312  StripeStorage();
313 
315  StripeStorage(const StripeStorage &other);
316 
318  virtual ~StripeStorage();
319 
321  sample_t *map();
322 
324  void unmap();
325 
327  inline int mapCount() const { return m_map_count; }
328 
329  public:
330 
333 
335  unsigned int m_length;
336 
339 
340  private:
341 
343  QMutex m_lock;
344 
347 
350  };
351 
352  private:
353 
355  QMutex m_lock;
356 
358  QExplicitlySharedDataPointer<StripeStorage> m_data;
359 
360  };
361 }
362 
363 #endif /* STRIPE_H */
364 
365 //***************************************************************************
366 //***************************************************************************
Definition: App.h:33
sample_index_t left() const
Definition: Stripe.h:214
sample_index_t m_left
Definition: Stripe.h:221
sample_index_t right() const
Definition: Stripe.h:217
sample_t * m_mapped_storage
Definition: Stripe.h:349
unsigned int m_length
Definition: Stripe.h:295
quint64 sample_index_t
Definition: Sample.h:28
Kwave::Handle m_storage
Definition: Stripe.h:338
List(sample_index_t left, sample_index_t right)
Definition: Stripe.h:203
int Handle
Definition: MemoryManager.h:34
QMutex m_lock
Definition: Stripe.h:355
sample_index_t m_right
Definition: Stripe.h:224
virtual ~List()
Definition: Stripe.h:209
sample_index_t m_start
Definition: Stripe.h:332
qint32 sample_t
Definition: Sample.h:37
QExplicitlySharedDataPointer< StripeStorage > m_data
Definition: Stripe.h:358