mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-15 15:49:36 +02:00
Define new virtual functions Track::GetIntervals (const and non-const)
This commit is contained in:
parent
c60bf1c994
commit
6510b859f3
@ -84,6 +84,28 @@ LabelTrack::LabelTrack(const LabelTrack &orig) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template< typename Container >
|
||||||
|
static Container MakeIntervals(const LabelArray &labels)
|
||||||
|
{
|
||||||
|
Container result;
|
||||||
|
size_t ii = 0;
|
||||||
|
for (const auto &label : labels)
|
||||||
|
result.emplace_back(
|
||||||
|
label.getT0(), label.getT1(),
|
||||||
|
std::make_unique<LabelTrack::IntervalData>( ii++ ) );
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto LabelTrack::GetIntervals() const -> ConstIntervals
|
||||||
|
{
|
||||||
|
return MakeIntervals<ConstIntervals>(mLabels);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto LabelTrack::GetIntervals() -> Intervals
|
||||||
|
{
|
||||||
|
return MakeIntervals<Intervals>(mLabels);
|
||||||
|
}
|
||||||
|
|
||||||
void LabelTrack::SetLabel( size_t iLabel, const LabelStruct &newLabel )
|
void LabelTrack::SetLabel( size_t iLabel, const LabelStruct &newLabel )
|
||||||
{
|
{
|
||||||
if( iLabel >= mLabels.size() ) {
|
if( iLabel >= mLabels.size() ) {
|
||||||
|
@ -155,6 +155,13 @@ public:
|
|||||||
int FindNextLabel(const SelectedRegion& currentSelection);
|
int FindNextLabel(const SelectedRegion& currentSelection);
|
||||||
int FindPrevLabel(const SelectedRegion& currentSelection);
|
int FindPrevLabel(const SelectedRegion& currentSelection);
|
||||||
|
|
||||||
|
struct IntervalData final : Track::IntervalData {
|
||||||
|
size_t index;
|
||||||
|
explicit IntervalData(size_t index) : index{index} {};
|
||||||
|
};
|
||||||
|
ConstIntervals GetIntervals() const override;
|
||||||
|
Intervals GetIntervals() override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void SortLabels();
|
void SortLabels();
|
||||||
|
|
||||||
|
@ -683,6 +683,20 @@ QuantizedTimeAndBeat NoteTrack::NearestBeatTime( double time ) const
|
|||||||
return { seq_time + GetOffset(), beat };
|
return { seq_time + GetOffset(), beat };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto NoteTrack::GetIntervals() const -> ConstIntervals
|
||||||
|
{
|
||||||
|
ConstIntervals results;
|
||||||
|
results.emplace_back( GetStartTime(), GetEndTime() );
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto NoteTrack::GetIntervals() -> Intervals
|
||||||
|
{
|
||||||
|
Intervals results;
|
||||||
|
results.emplace_back( GetStartTime(), GetEndTime() );
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
void NoteTrack::AddToDuration( double delta )
|
void NoteTrack::AddToDuration( double delta )
|
||||||
{
|
{
|
||||||
auto &seq = GetSeq();
|
auto &seq = GetSeq();
|
||||||
|
@ -185,6 +185,9 @@ public:
|
|||||||
mVisibleChannels = CHANNEL_BIT(c);
|
mVisibleChannels = CHANNEL_BIT(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ConstIntervals GetIntervals() const override;
|
||||||
|
Intervals GetIntervals() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
TrackKind GetKind() const override { return TrackKind::Note; }
|
TrackKind GetKind() const override { return TrackKind::Note; }
|
||||||
|
@ -1224,6 +1224,16 @@ std::shared_ptr<const Track> Track::SubstituteOriginalTrack() const
|
|||||||
return SharedPointer();
|
return SharedPointer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto Track::GetIntervals() const -> ConstIntervals
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
auto Track::GetIntervals() -> Intervals
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
// Serialize, not with tags of its own, but as attributes within a tag.
|
// Serialize, not with tags of its own, but as attributes within a tag.
|
||||||
void Track::WriteCommonXMLAttributes(
|
void Track::WriteCommonXMLAttributes(
|
||||||
XMLWriter &xmlFile, bool includeNameAndSelected) const
|
XMLWriter &xmlFile, bool includeNameAndSelected) const
|
||||||
@ -1269,6 +1279,8 @@ void Track::AdjustPositions()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TrackIntervalData::~TrackIntervalData() = default;
|
||||||
|
|
||||||
bool TrackList::HasPendingTracks() const
|
bool TrackList::HasPendingTracks() const
|
||||||
{
|
{
|
||||||
if ( !mPendingUpdates.empty() )
|
if ( !mPendingUpdates.empty() )
|
||||||
|
61
src/Track.h
61
src/Track.h
@ -181,6 +181,50 @@ private:
|
|||||||
long mValue;
|
long mValue;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//! Optional extra information about an interval, appropriate to a subtype of Track
|
||||||
|
struct TrackIntervalData {
|
||||||
|
virtual ~TrackIntervalData();
|
||||||
|
};
|
||||||
|
|
||||||
|
//! A start and an end time, and non-mutative access to optional extra information
|
||||||
|
/*! @invariant `Start() <= End()` */
|
||||||
|
class ConstTrackInterval {
|
||||||
|
public:
|
||||||
|
|
||||||
|
/*! @pre `start <= end` */
|
||||||
|
ConstTrackInterval( double start, double end,
|
||||||
|
std::unique_ptr<TrackIntervalData> pExtra = {} )
|
||||||
|
: start{ start }, end{ end }, pExtra{ std::move( pExtra ) }
|
||||||
|
{
|
||||||
|
wxASSERT( start <= end );
|
||||||
|
}
|
||||||
|
|
||||||
|
ConstTrackInterval( ConstTrackInterval&& ) = default;
|
||||||
|
ConstTrackInterval &operator=( ConstTrackInterval&& ) = default;
|
||||||
|
|
||||||
|
double Start() const { return start; }
|
||||||
|
double End() const { return end; }
|
||||||
|
const TrackIntervalData *Extra() const { return pExtra.get(); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
double start, end;
|
||||||
|
protected:
|
||||||
|
// TODO C++17: use std::any instead
|
||||||
|
std::unique_ptr< TrackIntervalData > pExtra;
|
||||||
|
};
|
||||||
|
|
||||||
|
//! A start and an end time, and mutative access to optional extra information
|
||||||
|
/*! @invariant `Start() <= End()` */
|
||||||
|
class TrackInterval : public ConstTrackInterval {
|
||||||
|
public:
|
||||||
|
using ConstTrackInterval::ConstTrackInterval;
|
||||||
|
|
||||||
|
TrackInterval(TrackInterval&&) = default;
|
||||||
|
TrackInterval &operator= (TrackInterval&&) = default;
|
||||||
|
|
||||||
|
TrackIntervalData *Extra() const { return pExtra.get(); }
|
||||||
|
};
|
||||||
|
|
||||||
//! Template generated base class for Track lets it host opaque UI related objects
|
//! Template generated base class for Track lets it host opaque UI related objects
|
||||||
using AttachedTrackObjects = ClientData::Site<
|
using AttachedTrackObjects = ClientData::Site<
|
||||||
Track, ClientData::Base, ClientData::SkipCopying, std::shared_ptr
|
Track, ClientData::Base, ClientData::SkipCopying, std::shared_ptr
|
||||||
@ -268,6 +312,23 @@ class AUDACITY_DLL_API Track /* not final */
|
|||||||
// original; else return this track
|
// original; else return this track
|
||||||
std::shared_ptr<const Track> SubstituteOriginalTrack() const;
|
std::shared_ptr<const Track> SubstituteOriginalTrack() const;
|
||||||
|
|
||||||
|
using IntervalData = TrackIntervalData;
|
||||||
|
using Interval = TrackInterval;
|
||||||
|
using Intervals = std::vector< Interval >;
|
||||||
|
using ConstInterval = ConstTrackInterval;
|
||||||
|
using ConstIntervals = std::vector< ConstInterval >;
|
||||||
|
|
||||||
|
//! Report times on the track where important intervals begin and end, for UI to snap to
|
||||||
|
/*!
|
||||||
|
Some intervals may be empty, and no ordering of the intervals is assumed.
|
||||||
|
*/
|
||||||
|
virtual ConstIntervals GetIntervals() const;
|
||||||
|
|
||||||
|
/*! @copydoc GetIntervals()
|
||||||
|
This overload exposes the extra data of the intervals as non-const
|
||||||
|
*/
|
||||||
|
virtual Intervals GetIntervals();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
mutable wxSize vrulerSize;
|
mutable wxSize vrulerSize;
|
||||||
|
|
||||||
|
@ -323,6 +323,27 @@ int WaveTrack::ZeroLevelYCoordinate(wxRect rect) const
|
|||||||
(int)((mDisplayMax / (mDisplayMax - mDisplayMin)) * rect.height);
|
(int)((mDisplayMax / (mDisplayMax - mDisplayMin)) * rect.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template< typename Container >
|
||||||
|
static Container MakeIntervals(const std::vector<WaveClipHolder> &clips)
|
||||||
|
{
|
||||||
|
Container result;
|
||||||
|
for (const auto &clip: clips) {
|
||||||
|
result.emplace_back( clip->GetStartTime(), clip->GetEndTime(),
|
||||||
|
std::make_unique<WaveTrack::IntervalData>( clip ) );
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto WaveTrack::GetIntervals() const -> ConstIntervals
|
||||||
|
{
|
||||||
|
return MakeIntervals<ConstIntervals>( mClips );
|
||||||
|
}
|
||||||
|
|
||||||
|
auto WaveTrack::GetIntervals() -> Intervals
|
||||||
|
{
|
||||||
|
return MakeIntervals<Intervals>( mClips );
|
||||||
|
}
|
||||||
|
|
||||||
Track::Holder WaveTrack::Clone() const
|
Track::Holder WaveTrack::Clone() const
|
||||||
{
|
{
|
||||||
return std::make_shared<WaveTrack>( *this );
|
return std::make_shared<WaveTrack>( *this );
|
||||||
|
@ -523,6 +523,20 @@ private:
|
|||||||
// bottom and top. Maybe that is out of bounds.
|
// bottom and top. Maybe that is out of bounds.
|
||||||
int ZeroLevelYCoordinate(wxRect rect) const;
|
int ZeroLevelYCoordinate(wxRect rect) const;
|
||||||
|
|
||||||
|
class IntervalData final : public Track::IntervalData {
|
||||||
|
public:
|
||||||
|
explicit IntervalData( const std::shared_ptr<WaveClip> &pClip )
|
||||||
|
: pClip{ pClip }
|
||||||
|
{}
|
||||||
|
std::shared_ptr<const WaveClip> GetClip() const { return pClip; }
|
||||||
|
std::shared_ptr<WaveClip> &GetClip() { return pClip; }
|
||||||
|
private:
|
||||||
|
std::shared_ptr<WaveClip> pClip;
|
||||||
|
};
|
||||||
|
|
||||||
|
ConstIntervals GetIntervals() const override;
|
||||||
|
Intervals GetIntervals() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//
|
//
|
||||||
// Protected variables
|
// Protected variables
|
||||||
|
Loading…
x
Reference in New Issue
Block a user