Audacity 3.2.0
Classes | Typedefs | Functions | Variables
anonymous_namespace{WaveTrack.cpp} Namespace Reference

Classes

struct  SampleAccessArgs
 
struct  SplitInfo
 
struct  WaveTrackData
 

Typedefs

template<typename FloatType >
using BufferCharType = std::conditional_t< std::is_const_v< std::remove_pointer_t< FloatType > >, constSamplePtr, samplePtr >
 

Functions

bool AreAligned (const WaveClipPointers &a, const WaveClipPointers &b)
 
Track::LinkType ToLinkType (int value)
 
WaveClipHolders::const_iterator FindClip (const WaveClipHolders &list, const WaveClip *clip, int *distance=nullptr)
 
WaveClipHolders::iterator FindClip (WaveClipHolders &list, const WaveClip *clip, int *distance=nullptr)
 
void RoundToNearestClipSample (const WaveTrack &track, double &t)
 
template<typename BufferType >
SampleAccessArgs< BufferType > GetSampleAccessArgs (const WaveClip &clip, double startOrEndTime, BufferType buffer, size_t totalToRead, size_t alreadyRead, bool forward)
 
template<typename Cont1 , typename Cont2 >
Cont1 FillSortedClipArray (const Cont2 &mClips)
 

Variables

static const ChannelGroup::Attachments::RegisteredFactory waveTrackDataFactory
 
ProjectFormatExtensionsRegistry::Extension smartClipsExtension ([](const AudacityProject &project) -> ProjectFormatVersion { const TrackList &trackList=TrackList::Get(project);for(auto wt :trackList.Any< const WaveTrack >()) for(const auto pChannel :TrackList::Channels(wt)) for(const auto &clip :pChannel->GetAllClips()) if(clip->GetTrimLeft() > 0.0||clip->GetTrimRight() > 0.0) return { 3, 1, 0, 0 };return BaseProjectFormatVersion;})
 
ProjectFormatExtensionsRegistry::Extension stretchedClipsExtension ([](const AudacityProject &project) -> ProjectFormatVersion { const TrackList &trackList=TrackList::Get(project);for(auto wt :trackList.Any< const WaveTrack >()) for(const auto pChannel :TrackList::Channels(wt)) for(const auto &clip :pChannel->GetAllClips()) if(clip->GetStretchRatio() !=1.0) return { 3, 4, 0, 0 };return BaseProjectFormatVersion;})
 

Typedef Documentation

◆ BufferCharType

template<typename FloatType >
using anonymous_namespace{WaveTrack.cpp}::BufferCharType = typedef std::conditional_t< std::is_const_v<std::remove_pointer_t<FloatType> >, constSamplePtr, samplePtr>

Definition at line 3233 of file WaveTrack.cpp.

Function Documentation

◆ AreAligned()

bool anonymous_namespace{WaveTrack.cpp}::AreAligned ( const WaveClipPointers a,
const WaveClipPointers b 
)

Definition at line 701 of file WaveTrack.cpp.

702{
703 if (a.size() != b.size())
704 return false;
705
706 const auto compare = [](const WaveClip* a, const WaveClip* b) {
707 // clips are aligned if both sequence start/end
708 // points and play start/end points of the first clip match
709 // the corresponding points of the other clip
710 return a->GetPlayStartTime() == b->GetPlayStartTime() &&
711 a->GetSequenceStartTime() == b->GetSequenceStartTime() &&
712 a->GetPlayEndTime() == b->GetPlayEndTime() &&
713 a->GetSequenceEndTime() == b->GetSequenceEndTime();
714 };
715
716 return std::mismatch(a.begin(), a.end(), b.begin(), compare).first == a.end();
717}
This allows multiple clips to be a part of one WaveTrack.
Definition: WaveClip.h:113
double GetSequenceStartTime() const noexcept
Definition: WaveClip.cpp:1415
double GetPlayStartTime() const noexcept override
Definition: WaveClip.cpp:1305
double GetPlayEndTime() const override
Definition: WaveClip.cpp:1315
double GetSequenceEndTime() const
Definition: WaveClip.cpp:1428

Referenced by WaveTrack::LinkConsistencyFix().

Here is the caller graph for this function:

◆ FillSortedClipArray()

template<typename Cont1 , typename Cont2 >
Cont1 anonymous_namespace{WaveTrack.cpp}::FillSortedClipArray ( const Cont2 &  mClips)

Definition at line 4400 of file WaveTrack.cpp.

4401 {
4402 Cont1 clips;
4403 for (const auto &clip : mClips)
4404 clips.push_back(clip.get());
4405 std::sort(clips.begin(), clips.end(),
4406 [](const WaveClip *a, const WaveClip *b)
4407 { return a->GetPlayStartTime() < b->GetPlayStartTime(); });
4408 return clips;
4409 }

◆ FindClip() [1/2]

WaveClipHolders::const_iterator anonymous_namespace{WaveTrack.cpp}::FindClip ( const WaveClipHolders list,
const WaveClip clip,
int *  distance = nullptr 
)

Definition at line 1890 of file WaveTrack.cpp.

1891 {
1892 if (distance)
1893 *distance = 0;
1894 auto it = list.begin();
1895 for (const auto end = list.end(); it != end; ++it)
1896 {
1897 if (it->get() == clip)
1898 break;
1899 if (distance)
1900 ++*distance;
1901 }
1902 return it;
1903 }
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:159

References PackedArray::end().

Here is the call graph for this function:

◆ FindClip() [2/2]

WaveClipHolders::iterator anonymous_namespace{WaveTrack.cpp}::FindClip ( WaveClipHolders list,
const WaveClip clip,
int *  distance = nullptr 
)

Definition at line 1906 of file WaveTrack.cpp.

1907 {
1908 if (distance)
1909 *distance = 0;
1910 auto it = list.begin();
1911 for (const auto end = list.end(); it != end; ++it)
1912 {
1913 if (it->get() == clip)
1914 break;
1915 if (distance)
1916 ++*distance;
1917 }
1918 return it;
1919 }

References PackedArray::end().

Referenced by WaveTrack::GetClipIndex(), WaveTrack::HandleClear(), WaveTrack::JoinOne(), WaveTrack::MergeOneClipPair(), and WaveTrack::RemoveAndReturnClip().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetSampleAccessArgs()

template<typename BufferType >
SampleAccessArgs< BufferType > anonymous_namespace{WaveTrack.cpp}::GetSampleAccessArgs ( const WaveClip clip,
double  startOrEndTime,
BufferType  buffer,
size_t  totalToRead,
size_t  alreadyRead,
bool  forward 
)

Definition at line 3245 of file WaveTrack.cpp.

3248{
3249 assert(totalToRead >= alreadyRead);
3250 const auto remainingToRead = totalToRead - alreadyRead;
3251 const auto sampsInClip = clip.GetVisibleSampleCount();
3252 const auto sampsPerSec = clip.GetRate() / clip.GetStretchRatio();
3253 if (forward)
3254 {
3255 const auto startTime =
3256 std::max(startOrEndTime - clip.GetPlayStartTime(), 0.);
3257 const sampleCount startSamp { std::round(startTime * sampsPerSec) };
3258 if (startSamp >= sampsInClip)
3259 return { nullptr, sampleCount { 0u }, 0u };
3260 const auto len =
3261 limitSampleBufferSize(remainingToRead, sampsInClip - startSamp);
3262 return { reinterpret_cast<BufferCharType<BufferType>>(
3263 buffer + alreadyRead),
3264 startSamp, len };
3265 }
3266 else
3267 {
3268 const auto endTime = std::min(
3269 startOrEndTime - clip.GetPlayStartTime(), clip.GetPlayDuration());
3270 const sampleCount endSamp { std::round(endTime * sampsPerSec) };
3271 const auto startSamp =
3272 std::max(endSamp - remainingToRead, sampleCount { 0 });
3273 // `len` cannot be greater than `remainingToRead`, itself a `size_t` ->
3274 // safe cast.
3275 const auto len = (endSamp - startSamp).as_size_t();
3276 if (len == 0 || startSamp >= sampsInClip)
3277 return { nullptr, sampleCount { 0u }, 0u };
3278 const auto bufferEnd = buffer + remainingToRead;
3279 return { reinterpret_cast<BufferCharType<BufferType>>(bufferEnd - len),
3280 startSamp, len };
3281 }
3282}
int min(int a, int b)
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: SampleCount.cpp:22
double GetStretchRatio() const override
Definition: WaveClip.cpp:348
sampleCount GetVisibleSampleCount() const override
Definition: WaveClip.cpp:1347
int GetRate() const override
Definition: WaveClip.h:166
double GetPlayDuration() const
Definition: WaveClip.cpp:1327
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:19
fastfloat_really_inline void round(adjusted_mantissa &am, callback cb) noexcept
Definition: fast_float.h:2512

References forward, WaveClip::GetPlayDuration(), WaveClip::GetPlayStartTime(), WaveClip::GetRate(), WaveClip::GetStretchRatio(), WaveClip::GetVisibleSampleCount(), limitSampleBufferSize(), min(), and fast_float::round().

Referenced by WaveTrack::GetFloatsFromTime(), and WaveTrack::SetFloatsFromTime().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RoundToNearestClipSample()

void anonymous_namespace{WaveTrack.cpp}::RoundToNearestClipSample ( const WaveTrack track,
double &  t 
)

Definition at line 3207 of file WaveTrack.cpp.

3208{
3209 const auto clip = track.GetClipAtTime(t);
3210 if (!clip)
3211 return;
3212 t = clip->SamplesToTime(clip->TimeToSamples(t - clip->GetPlayStartTime())) +
3213 clip->GetPlayStartTime();
3214}
double SamplesToTime(sampleCount s) const noexcept
Definition: WaveClip.cpp:1280
const WaveClip * GetClipAtTime(double time) const
Definition: WaveTrack.cpp:3759

References WaveTrack::GetClipAtTime(), and WaveClip::SamplesToTime().

Referenced by WaveTrack::GetFloatsFromTime(), and WaveTrack::SetFloatsFromTime().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ToLinkType()

Track::LinkType anonymous_namespace{WaveTrack.cpp}::ToLinkType ( int  value)

Definition at line 720 of file WaveTrack.cpp.

721{
722 if (value < 0)
724 else if (value > 3)
726 return static_cast<Track::LinkType>(value);
727}
LinkType
For two tracks describes the type of the linkage.
Definition: Channel.h:571
@ Group
compatibility with projects that were generated by older versions of Audacity

References ChannelGroup::Group, and ChannelGroup::None.

Referenced by WaveTrack::HandleXMLTag().

Here is the caller graph for this function:

Variable Documentation

◆ smartClipsExtension

ProjectFormatExtensionsRegistry::Extension anonymous_namespace{WaveTrack.cpp}::smartClipsExtension([](const AudacityProject &project) -> ProjectFormatVersion { const TrackList &trackList=TrackList::Get(project);for(auto wt :trackList.Any< const WaveTrack >()) for(const auto pChannel :TrackList::Channels(wt)) for(const auto &clip :pChannel->GetAllClips()) if(clip->GetTrimLeft() > 0.0||clip->GetTrimRight() > 0.0) return { 3, 1, 0, 0 };return BaseProjectFormatVersion;}) ( [] (const AudacityProject &project) -> ProjectFormatVersion { const TrackList &trackList=TrackList::Get(project);for(auto wt :trackList.Any< const WaveTrack >()) for(const auto pChannel :TrackList::Channels(wt)) for(const auto &clip :pChannel->GetAllClips()) if(clip->GetTrimLeft() > 0.0||clip->GetTrimRight() > 0.0) return { 3, 1, 0, 0 };return BaseProjectFormatVersion;}  )

◆ stretchedClipsExtension

ProjectFormatExtensionsRegistry::Extension anonymous_namespace{WaveTrack.cpp}::stretchedClipsExtension([](const AudacityProject &project) -> ProjectFormatVersion { const TrackList &trackList=TrackList::Get(project);for(auto wt :trackList.Any< const WaveTrack >()) for(const auto pChannel :TrackList::Channels(wt)) for(const auto &clip :pChannel->GetAllClips()) if(clip->GetStretchRatio() !=1.0) return { 3, 4, 0, 0 };return BaseProjectFormatVersion;}) ( [] (const AudacityProject &project) -> ProjectFormatVersion { const TrackList &trackList=TrackList::Get(project);for(auto wt :trackList.Any< const WaveTrack >()) for(const auto pChannel :TrackList::Channels(wt)) for(const auto &clip :pChannel->GetAllClips()) if(clip->GetStretchRatio() !=1.0) return { 3, 4, 0, 0 };return BaseProjectFormatVersion;}  )

◆ waveTrackDataFactory

const ChannelGroup::Attachments::RegisteredFactory anonymous_namespace{WaveTrack.cpp}::waveTrackDataFactory
static
Initial value:
{
[](auto &) { return std::make_unique<WaveTrackData>(); } }

Definition at line 613 of file WaveTrack.cpp.

Referenced by anonymous_namespace{WaveTrack.cpp}::WaveTrackData::Get().