kwave
18.07.70
|
#include <Track.h>
Public Slots | |
void | toggleSelection () |
void | defragment () |
Signals | |
void | sigSamplesInserted (Kwave::Track *src, sample_index_t offset, sample_index_t length) |
void | sigSamplesDeleted (Kwave::Track *src, sample_index_t offset, sample_index_t length) |
void | sigSamplesModified (Kwave::Track *src, sample_index_t offset, sample_index_t length) |
void | sigSelectionChanged (bool selected) |
Public Member Functions | |
Track () | |
Track (sample_index_t length, QUuid *uuid) | |
virtual | ~Track () |
sample_index_t | length () |
Kwave::Writer * | openWriter (Kwave::InsertMode mode, sample_index_t left=0, sample_index_t right=0) |
Kwave::SampleReader * | openReader (Kwave::ReaderMode mode, sample_index_t left=0, sample_index_t right=SAMPLE_INDEX_MAX) |
Kwave::Stripe::List | stripes (sample_index_t left, sample_index_t right) |
bool | mergeStripes (const Kwave::Stripe::List &stripes) |
void | deleteRange (sample_index_t offset, sample_index_t length, bool make_gap=false) |
bool | insertSpace (sample_index_t offset, sample_index_t shift) |
bool | selected () const |
void | select (bool select) |
const QUuid & | uuid () const |
Protected Member Functions | |
bool | writeSamples (Kwave::InsertMode mode, sample_index_t offset, const Kwave::SampleArray &buffer, unsigned int buf_offset, unsigned int length) |
void | use () |
void | release () |
Private Member Functions | |
sample_index_t | unlockedLength () |
void | unlockedDelete (sample_index_t offset, sample_index_t length, bool make_gap=false) |
bool | appendAfter (Stripe *stripe, sample_index_t offset, const Kwave::SampleArray &buffer, unsigned int buf_offset, unsigned int length) |
void | moveRight (sample_index_t offset, sample_index_t shift) |
void | appendStripe (sample_index_t length) |
Stripe | splitStripe (Stripe &stripe, unsigned int offset) |
bool | mergeStripe (Kwave::Stripe &stripe) |
void | dump () |
Stripe * | newStripe (sample_index_t start, unsigned int length) |
Private Attributes | |
QMutex | m_lock |
QReadWriteLock | m_lock_usage |
QList< Stripe > | m_stripes |
bool | m_selected |
QUuid | m_uuid |
Friends | |
class | Kwave::TrackWriter |
Kwave::Track::Track | ( | ) |
Kwave::Track::Track | ( | sample_index_t | length, |
QUuid * | uuid | ||
) |
Constructor. Creates an empty track with a specified length.
length | the length in samples |
uuid | unique ID of the track, can be null |
Definition at line 65 of file Track.cpp.
References appendStripe(), Kwave::Stripe::length(), m_stripes, Kwave::Stripe::resize(), STRIPE_LENGTH_MAXIMUM, and STRIPE_LENGTH_OPTIMAL.
|
virtual |
Destructor.
Definition at line 79 of file Track.cpp.
References m_lock, m_lock_usage, and m_stripes.
|
private |
Append samples after a given stripe.
stripe | the stripe after which to instert. Null pointer is allowed, in this case a new stripe is created |
offset | position where the new data should start |
buffer | array with samples |
buf_offset | offset within the buffer |
length | number of samples to write |
Definition at line 478 of file Track.cpp.
References Kwave::Stripe::append(), Kwave::Stripe::end(), length(), Kwave::Stripe::length(), m_stripes, Kwave::SampleArray::size(), STRIPE_LENGTH_MAXIMUM, and Kwave::toUint().
Referenced by writeSamples().
|
private |
Append a new stripe with a given length.
length | number of samples, zero is allowed |
Definition at line 92 of file Track.cpp.
References m_stripes, Kwave::Stripe::resize(), sigSamplesInserted(), STRIPE_LENGTH_MAXIMUM, Kwave::toUint(), and unlockedLength().
Referenced by Track().
|
slot |
do some defragmentation of stripes
Definition at line 696 of file Track.cpp.
References Kwave::Stripe::combine(), Kwave::Stripe::end(), Kwave::Stripe::length(), m_lock, m_stripes, Kwave::Stripe::start(), STRIPE_LENGTH_MAXIMUM, STRIPE_LENGTH_MINIMUM, and Kwave::toUint().
Referenced by deleteRange(), mergeStripes(), and openWriter().
void Kwave::Track::deleteRange | ( | sample_index_t | offset, |
sample_index_t | length, | ||
bool | make_gap = false |
||
) |
Deletes a range of samples
offset | index of the first sample |
length | number of samples |
make_gap | if true, make a gap into the list of stripes instead of moving the stuff from right to left |
Definition at line 293 of file Track.cpp.
References defragment(), m_lock, sigSamplesDeleted(), and unlockedDelete().
Referenced by Kwave::Signal::deleteRange().
|
private |
dump the list of stripes, for debugging
for debugging only
Definition at line 775 of file Track.cpp.
References Kwave::Stripe::end(), Kwave::Stripe::length(), m_stripes, and Kwave::Stripe::start().
bool Kwave::Track::insertSpace | ( | sample_index_t | offset, |
sample_index_t | shift | ||
) |
Inserts space at a given offset by moving all stripes that are are starting at or after the given offset right.
offset | position after which everything is moved right |
shift | distance of the shift [samples] |
Definition at line 314 of file Track.cpp.
References Kwave::Stripe::end(), Kwave::Stripe::length(), m_lock, m_stripes, moveRight(), Kwave::Stripe::resize(), sigSamplesInserted(), splitStripe(), Kwave::Stripe::start(), Kwave::toUint(), and unlockedLength().
Referenced by Kwave::Signal::insertSpace().
sample_index_t Kwave::Track::length | ( | ) |
Returns the length of the track. This is equivalent to the position of the last sample of the last Stripe.
Definition at line 173 of file Track.cpp.
References m_lock, and unlockedLength().
Referenced by appendAfter(), Kwave::Signal::length(), Kwave::SignalManager::loadFile(), openReader(), Kwave::TrackPixmap::repaint(), unlockedDelete(), and Kwave::TrackPixmap::validateBuffer().
|
private |
Merge a single stripe into the track.
stripe | the stripe to merge |
Definition at line 133 of file Track.cpp.
References Kwave::Stripe::end(), m_stripes, Kwave::Stripe::start(), and unlockedDelete().
Referenced by mergeStripes().
bool Kwave::Track::mergeStripes | ( | const Kwave::Stripe::List & | stripes | ) |
Merge a list of stripes into the track.
stripes | list of stripes |
Definition at line 251 of file Track.cpp.
References defragment(), Kwave::Stripe::List::left(), m_lock, mergeStripe(), Kwave::Stripe::List::right(), and sigSamplesModified().
Referenced by Kwave::Signal::mergeStripes().
|
private |
Move all stripes after an offset to the right. Only looks at the start position of the stripes, comparing with ">=", if the start of a stripe is at the given offset, it will not be moved!
offset | position after which everything is moved right |
shift | distance of the shift [samples] |
Definition at line 546 of file Track.cpp.
References m_stripes, Kwave::Stripe::setStart(), and Kwave::Stripe::start().
Referenced by insertSpace(), and writeSamples().
|
private |
Creates a new stripe with a start position and a length.
start | offset of the first sample |
length | number of samples, zero is allowed |
Kwave::SampleReader * Kwave::Track::openReader | ( | Kwave::ReaderMode | mode, |
sample_index_t | left = 0 , |
||
sample_index_t | right = SAMPLE_INDEX_MAX |
||
) |
Opens a stream for reading samples. If the last position is omitted, the value UINT_MAX will be used.
mode | read mode, see Kwave::ReaderMode |
left | first offset to be read (default = 0) |
right | last position to read (default = UINT_MAX) |
Definition at line 274 of file Track.cpp.
References length(), m_lock, stripes(), and unlockedLength().
Referenced by Kwave::Signal::openReader(), and Kwave::TrackPixmap::validateBuffer().
Kwave::Writer * Kwave::Track::openWriter | ( | Kwave::InsertMode | mode, |
sample_index_t | left = 0 , |
||
sample_index_t | right = 0 |
||
) |
Opens a stream for writing samples, starting at a sample position.
mode | specifies where and how to insert |
left | start of the input (only useful in insert and overwrite mode) |
right | end of the input (only useful with overwrite mode) |
Definition at line 188 of file Track.cpp.
References Kwave::connect(), and defragment().
Referenced by Kwave::Signal::openWriter().
|
protected |
decrements the usage counter (read lock to m_lock_usage)
Definition at line 769 of file Track.cpp.
References m_lock_usage.
Referenced by Kwave::TrackWriter::~TrackWriter().
void Kwave::Track::select | ( | bool | select | ) |
Sets the "selected" flag.
Definition at line 464 of file Track.cpp.
References m_selected, selected(), and sigSelectionChanged().
Referenced by toggleSelection().
|
inline |
Returns the "selected" flag.
Definition at line 137 of file Track.h.
Referenced by Kwave::TrackPixmap::repaint(), select(), toggleSelection(), and Kwave::TrackView::TrackView().
|
signal |
Emitted if data has been removed from the track.
src | source track of the signal (*this) |
offset | position from which the data was removed |
length | number of samples deleted |
Referenced by deleteRange().
|
signal |
Emitted if the track has grown. This implies a modification of the inserted data, so no extra sigSamplesModified is emitted.
src | source track of the signal (*this) |
offset | position from which the data was inserted |
length | number of samples inserted |
Referenced by appendStripe(), insertSpace(), and writeSamples().
|
signal |
Emitted if some data within the track has been modified.
src | source track of the signal (*this) |
offset | position from which the data was modified |
length | number of samples modified |
Referenced by mergeStripes(), and writeSamples().
|
signal |
Emitted whenever the selection of the track has changed.
selected | true if selected, false if unselected |
Referenced by select().
|
private |
Split a stripe into two stripes. The new stripe will be created from the right portion of the given stripe and the original stripe will be shrinked to it's new size. The newly created stripe will be inserted into m_stripes after the old one.
stripe | the stripe to be split |
offset | the offset within the stripe, which becomes the first sample in the new stripe |
Definition at line 111 of file Track.cpp.
References Kwave::Stripe::length(), Kwave::Stripe::resize(), and Kwave::Stripe::start().
Referenced by insertSpace(), unlockedDelete(), and writeSamples().
Kwave::Stripe::List Kwave::Track::stripes | ( | sample_index_t | left, |
sample_index_t | right | ||
) |
Get a list of stripes that matches a given range of samples
left | offset of the first sample |
right | offset of the last sample |
Definition at line 209 of file Track.cpp.
References Kwave::Stripe::deleteRange(), Kwave::Stripe::end(), Kwave::Stripe::length(), m_lock, m_stripes, Kwave::Stripe::resize(), Kwave::Stripe::setStart(), Kwave::Stripe::start(), and Kwave::toUint().
Referenced by openReader(), and Kwave::Signal::stripes().
|
slot |
toggles the selection of the slot on/off
Definition at line 472 of file Track.cpp.
References select(), and selected().
|
private |
Deletes a range of samples, used internally by deleteRange()
offset | index of the first sample |
length | number of samples |
make_gap | if true, make a gap into the list of stripes instead of moving the stuff from right to left |
Definition at line 360 of file Track.cpp.
References Kwave::Stripe::deleteRange(), Kwave::Stripe::end(), length(), Kwave::Stripe::length(), m_stripes, Kwave::Stripe::setStart(), splitStripe(), Kwave::Stripe::start(), and Kwave::toUint().
Referenced by deleteRange(), mergeStripe(), and writeSamples().
|
private |
Returns the current length of the stripe in samples. This function uses no locks and is therefore reserved for internal usage from within locked functions.
Definition at line 180 of file Track.cpp.
References Kwave::Stripe::length(), m_stripes, and Kwave::Stripe::start().
Referenced by appendStripe(), insertSpace(), length(), and openReader().
|
protected |
increments the usage counter (read lock to m_lock_usage)
Definition at line 763 of file Track.cpp.
References m_lock_usage.
Referenced by Kwave::TrackWriter::TrackWriter().
|
inline |
returns the unique ID of this track instance
Definition at line 143 of file Track.h.
Referenced by Kwave::SelectionTracker::slotTrackDeleted(), and Kwave::SelectionTracker::slotTrackInserted().
|
protected |
Write a block of samples. If necessary it starts, appends to, or splits a stripe.
mode | a InsertMode (append/overwrite/insert) |
offset | position where to start the write operation |
buffer | array with samples |
buf_offset | offset within the buffer |
length | number of samples to write |
Definition at line 561 of file Track.cpp.
References Kwave::Append, appendAfter(), Kwave::Stripe::end(), Kwave::Insert, Kwave::Stripe::length(), m_lock, m_stripes, moveRight(), Kwave::Overwrite, sigSamplesInserted(), sigSamplesModified(), splitStripe(), Kwave::Stripe::start(), Kwave::toUint(), and unlockedDelete().
Referenced by Kwave::TrackWriter::write().
|
friend |
|
private |
lock for access to the whole track
Definition at line 308 of file Track.h.
Referenced by defragment(), deleteRange(), insertSpace(), length(), mergeStripes(), openReader(), stripes(), writeSamples(), and ~Track().
|
private |
|
private |
|
private |
list of stripes (a track actually is a container for stripes)
Definition at line 314 of file Track.h.
Referenced by appendAfter(), appendStripe(), defragment(), dump(), insertSpace(), mergeStripe(), moveRight(), stripes(), Track(), unlockedDelete(), unlockedLength(), writeSamples(), and ~Track().