kwave  18.07.70
Track.h
Go to the documentation of this file.
1 /***************************************************************************
2  Track.h - collects one or more stripes in one track
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 TRACK_H
19 #define TRACK_H
20 
21 #include "config.h"
22 #include <limits.h> // for UINT_MAX
23 
24 #include <QtGlobal>
25 #include <QList>
26 #include <QMutex>
27 #include <QObject>
28 #include <QReadWriteLock>
29 #include <QUuid>
30 
31 #include "libkwave/InsertMode.h"
32 #include "libkwave/ReaderMode.h"
33 #include "libkwave/SampleArray.h"
34 #include "libkwave/Stripe.h"
35 
36 //***************************************************************************
37 namespace Kwave
38 {
39 
40  class SampleReader;
41  class TrackWriter;
42  class Writer;
43 
44  class Q_DECL_EXPORT Track: public QObject
45  {
46  Q_OBJECT
47  public:
52  Track();
53 
59  Track(sample_index_t length, QUuid *uuid);
60 
64  virtual ~Track();
65 
70  sample_index_t length();
71 
82  Kwave::Writer *openWriter(Kwave::InsertMode mode,
83  sample_index_t left = 0,
84  sample_index_t right = 0);
85 
93  Kwave::SampleReader *openReader(Kwave::ReaderMode mode,
94  sample_index_t left = 0,
96 
104  Kwave::Stripe::List stripes(sample_index_t left,
105  sample_index_t right);
106 
113  bool mergeStripes(const Kwave::Stripe::List &stripes);
114 
123  void deleteRange(sample_index_t offset, sample_index_t length,
124  bool make_gap = false);
125 
134  bool insertSpace(sample_index_t offset, sample_index_t shift);
135 
137  inline bool selected() const { return m_selected; }
138 
140  void select(bool select);
141 
143  const QUuid &uuid() const { return m_uuid; }
144 
145  public slots:
146 
148  void toggleSelection();
149 
151  void defragment();
152 
153  signals:
154 
163  void sigSamplesInserted(Kwave::Track *src, sample_index_t offset,
164  sample_index_t length);
165 
172  void sigSamplesDeleted(Kwave::Track *src, sample_index_t offset,
173  sample_index_t length);
174 
181  void sigSamplesModified(Kwave::Track *src, sample_index_t offset,
182  sample_index_t length);
183 
188  void sigSelectionChanged(bool selected);
189 
190  private:
197  sample_index_t unlockedLength();
198 
206  void unlockedDelete(sample_index_t offset, sample_index_t length,
207  bool make_gap = false);
208 
220  bool appendAfter(Stripe *stripe, sample_index_t offset,
221  const Kwave::SampleArray &buffer,
222  unsigned int buf_offset, unsigned int length);
223 
232  void moveRight(sample_index_t offset, sample_index_t shift);
233 
239  void appendStripe(sample_index_t length);
240 
252  Stripe splitStripe(Stripe &stripe, unsigned int offset);
253 
254 
261  bool mergeStripe(Kwave::Stripe &stripe);
262 
267  void dump();
268 
269  protected:
270 
271  friend class Kwave::TrackWriter;
272 
284  bool writeSamples(Kwave::InsertMode mode,
285  sample_index_t offset,
286  const Kwave::SampleArray &buffer,
287  unsigned int buf_offset,
288  unsigned int length);
289 
291  void use();
292 
294  void release();
295 
296  private:
297 
304  Stripe *newStripe(sample_index_t start, unsigned int length);
305 
306  private:
308  QMutex m_lock;
309 
311  QReadWriteLock m_lock_usage;
312 
314  QList<Stripe> m_stripes;
315 
318 
320  QUuid m_uuid;
321  };
322 }
323 
324 #endif /* TRACK_H */
325 
326 //***************************************************************************
327 //***************************************************************************
bool selected() const
Definition: Track.h:137
QMutex m_lock
Definition: Track.h:308
QUuid m_uuid
Definition: Track.h:320
Definition: App.h:33
ReaderMode
Definition: ReaderMode.h:27
QList< Stripe > m_stripes
Definition: Track.h:314
const QUuid & uuid() const
Definition: Track.h:143
quint64 sample_index_t
Definition: Sample.h:28
QReadWriteLock m_lock_usage
Definition: Track.h:311
InsertMode
Definition: InsertMode.h:26
bool m_selected
Definition: Track.h:317
#define SAMPLE_INDEX_MAX
Definition: Sample.h:31