Lines 1-5
Link Here
|
1 |
/*************************************************************************** |
1 |
/*************************************************************************** |
2 |
Track.h - collects one or more stripes in one track |
2 |
Track.h - collects one or more stripes in one track |
3 |
------------------- |
3 |
------------------- |
4 |
begin : Feb 09 2001 |
4 |
begin : Feb 09 2001 |
5 |
copyright : (C) 2001 by Thomas Eschenbacher |
5 |
copyright : (C) 2001 by Thomas Eschenbacher |
Lines 33-280
Link Here
|
33 |
#include "libkwave/Stripe.h" |
33 |
#include "libkwave/Stripe.h" |
34 |
|
34 |
|
35 |
class SampleReader; |
35 |
class SampleReader; |
36 |
namespace Kwave { class TrackWriter; } |
|
|
37 |
namespace Kwave { class Writer; } |
38 |
|
36 |
|
39 |
//*************************************************************************** |
37 |
//*************************************************************************** |
40 |
class KDE_EXPORT Track: public QObject |
38 |
namespace Kwave { |
41 |
{ |
39 |
|
42 |
Q_OBJECT |
40 |
class TrackWriter; |
43 |
public: |
41 |
class Writer; |
44 |
/** |
42 |
|
45 |
* Default constructor. Creates a new and empty track with |
43 |
class KDE_EXPORT Track: public QObject |
46 |
* zero-length and no stripes |
44 |
{ |
47 |
*/ |
45 |
Q_OBJECT |
48 |
Track(); |
46 |
public: |
49 |
|
47 |
/** |
50 |
/** |
48 |
* Default constructor. Creates a new and empty track with |
51 |
* Constructor. Creates an empty track with one stripe |
49 |
* zero-length and no stripes |
52 |
* with specified length. |
50 |
*/ |
53 |
*/ |
51 |
Track(); |
54 |
Track(sample_index_t length); |
52 |
|
55 |
|
53 |
/** |
56 |
/** |
54 |
* Constructor. Creates an empty track with one stripe |
57 |
* Destructor. |
55 |
* with specified length. |
58 |
*/ |
56 |
*/ |
59 |
virtual ~Track(); |
57 |
Track(sample_index_t length); |
60 |
|
58 |
|
61 |
/** |
59 |
/** |
62 |
* Returns the length of the track. This is equivalent |
60 |
* Destructor. |
63 |
* to the position of the last sample of the last Stripe. |
61 |
*/ |
64 |
*/ |
62 |
virtual ~Track(); |
65 |
sample_index_t length(); |
63 |
|
66 |
|
64 |
/** |
67 |
/** |
65 |
* Returns the length of the track. This is equivalent |
68 |
* Opens a stream for writing samples, starting at a |
66 |
* to the position of the last sample of the last Stripe. |
69 |
* sample position. |
67 |
*/ |
70 |
* @param mode specifies where and how to insert |
68 |
sample_index_t length(); |
71 |
* @param left start of the input (only useful in insert and |
69 |
|
72 |
* overwrite mode) |
70 |
/** |
73 |
* @param right end of the input (only useful with overwrite mode) |
71 |
* Opens a stream for writing samples, starting at a |
74 |
* @see InsertMode |
72 |
* sample position. |
75 |
*/ |
73 |
* @param mode specifies where and how to insert |
76 |
Kwave::Writer *openWriter(InsertMode mode, |
74 |
* @param left start of the input (only useful in insert and |
77 |
sample_index_t left = 0, sample_index_t right = 0); |
75 |
* overwrite mode) |
78 |
|
76 |
* @param right end of the input (only useful with overwrite mode) |
79 |
/** |
77 |
* @see InsertMode |
80 |
* Opens a stream for reading samples. If the the last position |
78 |
*/ |
81 |
* is omitted, the value UINT_MAX will be used. |
79 |
Kwave::Writer *openWriter(InsertMode mode, |
82 |
* @param mode read mode, see Kwave::ReaderMode |
80 |
sample_index_t left = 0, |
83 |
* @param left first offset to be read (default = 0) |
81 |
sample_index_t right = 0); |
84 |
* @param right last position to read (default = UINT_MAX) |
82 |
|
85 |
*/ |
83 |
/** |
86 |
SampleReader *openSampleReader(Kwave::ReaderMode mode, |
84 |
* Opens a stream for reading samples. If the the last position |
87 |
sample_index_t left = 0, |
85 |
* is omitted, the value UINT_MAX will be used. |
88 |
sample_index_t right = SAMPLE_INDEX_MAX); |
86 |
* @param mode read mode, see Kwave::ReaderMode |
89 |
|
87 |
* @param left first offset to be read (default = 0) |
90 |
/** |
88 |
* @param right last position to read (default = UINT_MAX) |
91 |
* Deletes a range of samples |
89 |
*/ |
92 |
* @param offset index of the first sample |
90 |
SampleReader *openSampleReader(Kwave::ReaderMode mode, |
93 |
* @param length number of samples |
91 |
sample_index_t left = 0, |
94 |
* @param make_gap if true, make a gap into the list of stripes |
92 |
sample_index_t right = SAMPLE_INDEX_MAX); |
95 |
* instead of moving the stuff from right to left |
93 |
|
96 |
*/ |
94 |
/** |
97 |
void deleteRange(sample_index_t offset, sample_index_t length, |
95 |
* Deletes a range of samples |
98 |
bool make_gap = false); |
96 |
* @param offset index of the first sample |
99 |
|
97 |
* @param length number of samples |
100 |
/** |
98 |
* @param make_gap if true, make a gap into the list of stripes |
101 |
* Inserts space at a given offset by moving all stripes that are |
99 |
* instead of moving the stuff from right to left |
102 |
* are starting at or after the given offset right. |
100 |
*/ |
103 |
* |
101 |
void deleteRange(sample_index_t offset, sample_index_t length, |
104 |
* @param offset position after which everything is moved right |
102 |
bool make_gap = false); |
105 |
* @param shift distance of the shift [samples] |
103 |
|
106 |
* @return true if succeeded, false if failed (OOM?) |
104 |
/** |
107 |
*/ |
105 |
* Inserts space at a given offset by moving all stripes that are |
108 |
bool insertSpace(sample_index_t offset, sample_index_t shift); |
106 |
* are starting at or after the given offset right. |
109 |
|
107 |
* |
110 |
/** Returns the "selected" flag. */ |
108 |
* @param offset position after which everything is moved right |
111 |
inline bool selected() const { return m_selected; } |
109 |
* @param shift distance of the shift [samples] |
112 |
|
110 |
* @return true if succeeded, false if failed (OOM?) |
113 |
/** Sets the "selected" flag. */ |
111 |
*/ |
114 |
void select(bool select); |
112 |
bool insertSpace(sample_index_t offset, sample_index_t shift); |
115 |
|
113 |
|
116 |
public slots: |
114 |
/** Returns the "selected" flag. */ |
117 |
|
115 |
inline bool selected() const { return m_selected; } |
118 |
/** toggles the selection of the slot on/off */ |
116 |
|
119 |
void toggleSelection(); |
117 |
/** Sets the "selected" flag. */ |
120 |
|
118 |
void select(bool select); |
121 |
signals: |
119 |
|
122 |
|
120 |
public slots: |
123 |
/** |
121 |
|
124 |
* Emitted if the track has grown. This implies a modification of |
122 |
/** toggles the selection of the slot on/off */ |
125 |
* the inserted data, so no extra sigSamplesModified is emitted. |
123 |
void toggleSelection(); |
126 |
* @param src source track of the signal (*this) |
124 |
|
127 |
* @param offset position from which the data was inserted |
125 |
signals: |
128 |
* @param length number of samples inserted |
126 |
|
129 |
* @see sigSamplesModified |
127 |
/** |
130 |
*/ |
128 |
* Emitted if the track has grown. This implies a modification of |
131 |
void sigSamplesInserted(Track *src, sample_index_t offset, |
129 |
* the inserted data, so no extra sigSamplesModified is emitted. |
132 |
sample_index_t length); |
130 |
* @param src source track of the signal (*this) |
133 |
|
131 |
* @param offset position from which the data was inserted |
134 |
/** |
132 |
* @param length number of samples inserted |
135 |
* Emitted if data has been removed from the track. |
133 |
* @see sigSamplesModified |
136 |
* @param src source track of the signal (*this) |
134 |
*/ |
137 |
* @param offset position from which the data was removed |
135 |
void sigSamplesInserted(Kwave::Track *src, sample_index_t offset, |
138 |
* @param length number of samples deleted |
136 |
sample_index_t length); |
139 |
*/ |
137 |
|
140 |
void sigSamplesDeleted(Track *src, sample_index_t offset, |
138 |
/** |
141 |
sample_index_t length); |
139 |
* Emitted if data has been removed from the track. |
142 |
|
140 |
* @param src source track of the signal (*this) |
143 |
/** |
141 |
* @param offset position from which the data was removed |
144 |
* Emitted if some data within the track has been modified. |
142 |
* @param length number of samples deleted |
145 |
* @param src source track of the signal (*this) |
143 |
*/ |
146 |
* @param offset position from which the data was modified |
144 |
void sigSamplesDeleted(Kwave::Track *src, sample_index_t offset, |
147 |
* @param length number of samples modified |
145 |
sample_index_t length); |
148 |
*/ |
146 |
|
149 |
void sigSamplesModified(Track *src, sample_index_t offset, |
147 |
/** |
150 |
sample_index_t length); |
148 |
* Emitted if some data within the track has been modified. |
151 |
|
149 |
* @param src source track of the signal (*this) |
152 |
/** |
150 |
* @param offset position from which the data was modified |
153 |
* Emitted whenever the selection of the track has changed. |
151 |
* @param length number of samples modified |
154 |
* @param selected true if selected, false if unselected |
152 |
*/ |
155 |
*/ |
153 |
void sigSamplesModified(Kwave::Track *src, sample_index_t offset, |
156 |
void sigSelectionChanged(bool selected); |
154 |
sample_index_t length); |
157 |
|
155 |
|
158 |
private: |
156 |
/** |
159 |
/** |
157 |
* Emitted whenever the selection of the track has changed. |
160 |
* Returns the current length of the stripe in samples. This |
158 |
* @param selected true if selected, false if unselected |
161 |
* function uses no locks and is therefore reserved for internal |
159 |
*/ |
162 |
* usage from within locked functions. |
160 |
void sigSelectionChanged(bool selected); |
163 |
* @note this must be private, it does no locking ! |
161 |
|
164 |
*/ |
162 |
private: |
165 |
sample_index_t unlockedLength(); |
163 |
/** |
166 |
|
164 |
* Returns the current length of the stripe in samples. This |
167 |
/** |
165 |
* function uses no locks and is therefore reserved for internal |
168 |
* Deletes a range of samples, used internally by deleteRange() |
166 |
* usage from within locked functions. |
169 |
* @param offset index of the first sample |
167 |
* @note this must be private, it does no locking ! |
170 |
* @param length number of samples |
168 |
*/ |
171 |
* @param make_gap if true, make a gap into the list of stripes |
169 |
sample_index_t unlockedLength(); |
172 |
* instead of moving the stuff from right to left |
170 |
|
173 |
*/ |
171 |
/** |
174 |
void unlockedDelete(sample_index_t offset, sample_index_t length, |
172 |
* Deletes a range of samples, used internally by deleteRange() |
175 |
bool make_gap = false); |
173 |
* @param offset index of the first sample |
176 |
|
174 |
* @param length number of samples |
177 |
/** |
175 |
* @param make_gap if true, make a gap into the list of stripes |
178 |
* Append samples after a given stripe. |
176 |
* instead of moving the stuff from right to left |
179 |
* |
177 |
*/ |
180 |
* @param stripe the stripe after which to instert. Null pointer is |
178 |
void unlockedDelete(sample_index_t offset, sample_index_t length, |
181 |
* allowed, in this case a new stripe is created |
179 |
bool make_gap = false); |
182 |
* @param offset position where the new data should start |
180 |
|
183 |
* @param buffer array with samples |
181 |
/** |
184 |
* @param buf_offset offset within the buffer |
182 |
* Append samples after a given stripe. |
185 |
* @param length number of samples to write |
183 |
* |
186 |
* @return true if successful, false if failed (e.g. out of memory) |
184 |
* @param stripe the stripe after which to instert. Null pointer is |
187 |
*/ |
185 |
* allowed, in this case a new stripe is created |
188 |
bool appendAfter(Stripe *stripe, sample_index_t offset, |
186 |
* @param offset position where the new data should start |
189 |
const Kwave::SampleArray &buffer, |
187 |
* @param buffer array with samples |
190 |
unsigned int buf_offset, unsigned int length); |
188 |
* @param buf_offset offset within the buffer |
191 |
|
189 |
* @param length number of samples to write |
192 |
/** |
190 |
* @return true if successful, false if failed (e.g. out of memory) |
193 |
* Move all stripes after an offset to the right. Only looks at the |
191 |
*/ |
194 |
* start position of the stripes, comparing with ">=", if the start |
192 |
bool appendAfter(Stripe *stripe, sample_index_t offset, |
195 |
* of a stripe is at the given offset, it will not be moved! |
193 |
const Kwave::SampleArray &buffer, |
196 |
* |
194 |
unsigned int buf_offset, unsigned int length); |
197 |
* @param offset position after which everything is moved right |
195 |
|
198 |
* @param shift distance of the shift [samples] |
196 |
/** |
199 |
*/ |
197 |
* Move all stripes after an offset to the right. Only looks at the |
200 |
void moveRight(sample_index_t offset, sample_index_t shift); |
198 |
* start position of the stripes, comparing with ">=", if the start |
201 |
|
199 |
* of a stripe is at the given offset, it will not be moved! |
202 |
/** |
200 |
* |
203 |
* Append a new stripe with a given length. |
201 |
* @param offset position after which everything is moved right |
204 |
* |
202 |
* @param shift distance of the shift [samples] |
205 |
* @param length number of samples, zero is allowed |
203 |
*/ |
206 |
*/ |
204 |
void moveRight(sample_index_t offset, sample_index_t shift); |
207 |
void appendStripe(sample_index_t length); |
205 |
|
208 |
|
206 |
/** |
209 |
/** |
207 |
* Append a new stripe with a given length. |
210 |
* Split a stripe into two stripes. The new stripe will be created |
208 |
* |
211 |
* from the right portion of the given stripe and the original |
209 |
* @param length number of samples, zero is allowed |
212 |
* stripe will be shrinked to it's new size. The newly created stripe |
210 |
*/ |
213 |
* will be inserted into m_stripes after the old one. |
211 |
void appendStripe(sample_index_t length); |
214 |
* |
212 |
|
215 |
* @param stripe the stripe to be split |
213 |
/** |
216 |
* @param offset the offset within the stripe, which becomes the first |
214 |
* Split a stripe into two stripes. The new stripe will be created |
217 |
* sample in the new stripe |
215 |
* from the right portion of the given stripe and the original |
218 |
* @return the new created stripe |
216 |
* stripe will be shrinked to it's new size. The newly created stripe |
219 |
*/ |
217 |
* will be inserted into m_stripes after the old one. |
220 |
Stripe splitStripe(Stripe &stripe, unsigned int offset); |
218 |
* |
221 |
|
219 |
* @param stripe the stripe to be split |
222 |
/** |
220 |
* @param offset the offset within the stripe, which becomes the first |
223 |
* dump the list of stripes, for debugging |
221 |
* sample in the new stripe |
224 |
* @internal for debugging only |
222 |
* @return the new created stripe |
225 |
*/ |
223 |
*/ |
226 |
void dump(); |
224 |
Stripe splitStripe(Stripe &stripe, unsigned int offset); |
227 |
|
225 |
|
228 |
protected: |
226 |
/** |
229 |
|
227 |
* dump the list of stripes, for debugging |
230 |
friend class Kwave::TrackWriter; |
228 |
* @internal for debugging only |
231 |
|
229 |
*/ |
232 |
/** |
230 |
void dump(); |
233 |
* Write a block of samples. If necessary it starts, appends to, |
231 |
|
234 |
* or splits a stripe. |
232 |
protected: |
235 |
* |
233 |
|
236 |
* @param mode a InsertMode (append/overwrite/insert) |
234 |
friend class Kwave::TrackWriter; |
237 |
* @param offset position where to start the write operation |
235 |
|
238 |
* @param buffer array with samples |
236 |
/** |
239 |
* @param buf_offset offset within the buffer |
237 |
* Write a block of samples. If necessary it starts, appends to, |
240 |
* @param length number of samples to write |
238 |
* or splits a stripe. |
241 |
* @return true if successful, false if failed (e.g. out of memory) |
239 |
* |
242 |
*/ |
240 |
* @param mode a InsertMode (append/overwrite/insert) |
243 |
bool writeSamples(InsertMode mode, |
241 |
* @param offset position where to start the write operation |
244 |
sample_index_t offset, |
242 |
* @param buffer array with samples |
245 |
const Kwave::SampleArray &buffer, |
243 |
* @param buf_offset offset within the buffer |
246 |
unsigned int buf_offset, |
244 |
* @param length number of samples to write |
247 |
unsigned int length); |
245 |
* @return true if successful, false if failed (e.g. out of memory) |
248 |
|
246 |
*/ |
249 |
/** increments the usage counter (read lock to m_lock_usage) */ |
247 |
bool writeSamples(InsertMode mode, |
250 |
void use(); |
248 |
sample_index_t offset, |
251 |
|
249 |
const Kwave::SampleArray &buffer, |
252 |
/** decrements the usage counter (read lock to m_lock_usage) */ |
250 |
unsigned int buf_offset, |
253 |
void release(); |
251 |
unsigned int length); |
254 |
|
252 |
|
255 |
private: |
253 |
/** increments the usage counter (read lock to m_lock_usage) */ |
256 |
|
254 |
void use(); |
257 |
/** |
255 |
|
258 |
* Creates a new stripe with a start position and a length. |
256 |
/** decrements the usage counter (read lock to m_lock_usage) */ |
259 |
* @param start offset of the first sample |
257 |
void release(); |
260 |
* @param length number of samples, zero is allowed |
258 |
|
261 |
* @note this must be private, it does no locking ! |
259 |
private: |
262 |
*/ |
260 |
|
263 |
Stripe *newStripe(sample_index_t start, unsigned int length); |
261 |
/** |
264 |
|
262 |
* Creates a new stripe with a start position and a length. |
265 |
private: |
263 |
* @param start offset of the first sample |
266 |
/** read/write lock for access to the whole track */ |
264 |
* @param length number of samples, zero is allowed |
267 |
QReadWriteLock m_lock; |
265 |
* @note this must be private, it does no locking ! |
268 |
|
266 |
*/ |
269 |
/** lock to protect against deletion while the track is in use */ |
267 |
Stripe *newStripe(sample_index_t start, unsigned int length); |
270 |
QReadWriteLock m_lock_usage; |
268 |
|
271 |
|
269 |
private: |
272 |
/** list of stripes (a track actually is a container for stripes) */ |
270 |
/** read/write lock for access to the whole track */ |
273 |
QList<Stripe> m_stripes; |
271 |
QReadWriteLock m_lock; |
274 |
|
272 |
|
275 |
/** True if the track is selected */ |
273 |
/** lock to protect against deletion while the track is in use */ |
276 |
bool m_selected; |
274 |
QReadWriteLock m_lock_usage; |
277 |
|
275 |
|
278 |
}; |
276 |
/** list of stripes (a track actually is a container for stripes) */ |
|
|
277 |
QList<Stripe> m_stripes; |
278 |
|
279 |
/** True if the track is selected */ |
280 |
bool m_selected; |
281 |
|
282 |
}; |
283 |
} |
279 |
|
284 |
|
280 |
#endif /* _TRACK_H_ */ |
285 |
#endif /* _TRACK_H_ */ |