Proper way to add take to waveclip

Ok, I think I see the problem. Does changing that function to this fix it?

void WaveAudioClip::setCurrentTake (int takeIndex)
{
    CRASH_TRACER
    auto takesTree = getTakesTree();
    auto numTakes = takesTree.getNumChildren();
    jassert (isPositiveAndBelow (takeIndex, numTakes));
    takeIndex = jlimit (0, numTakes - 1, takeIndex);

    auto take = takesTree.getChild (takeIndex);
    jassert (take.isValid());

    auto takeSourceID = ProjectItemID::fromProperty (take, IDs::source);
    SourceFileReference fileRef (edit, take, IDs::source);
    auto mo = fileRef.getSourceProjectItem();
    invalidateCurrentTake();

    if (mo != nullptr || getCompManager().isTakeComp (takeIndex))
        sourceFileReference.setToProjectFileReference (takeSourceID);
    else if (! fileRef.isUsingProjectReference())
        sourceFileReference.source = fileRef.source.get();
    else
        takesTree.removeChild (take, getUndoManager());

    getCompManager().setActiveTakeIndex (takeIndex);
}

This is overflowing the stack frames :

 	tracktion_engine::WaveAudioClip::setCurrentTake(int takeIndex)	C++
 	tracktion_engine::CompManager::setActiveTakeIndex(int index)	C++
 	tracktion_engine::WaveAudioClip::setCurrentTake(int takeIndex)	C++
 	tracktion_engine::CompManager::setActiveTakeIndex(int index)	C++

It finally bails out with this:

juce::StringHolder::createUninitialisedBytes(unsigned __int64 numBytes)	C++
juce::StringHolder::createFromCharPointer(const juce::CharPointer_UTF8 start, const juce::CharPointer_UTF8 end)	C++
juce::String::String(juce::CharPointer_UTF8 start, juce::CharPointer_UTF8 end)	C++
juce::hexToString<...>(unsigned int v)	C++
juce::String::createHex(unsigned int n)	C++
juce::String::createHex<...>(int n)	C++
juce::String::toHexString<...>(int number)	C++
tracktion_engine::ProjectItemID::toString()	C++
tracktion_engine::WaveAudioClip::getCurrentTake()	C++
tracktion_engine::CompManager::getActiveTakeIndex()	C++
tracktion_engine::CompManager::setActiveTakeIndex(int index)	C++
tracktion_engine::WaveAudioClip::setCurrentTake(int takeIndex)	C++
tracktion_engine::CompManager::setActiveTakeIndex(int index)	C++
tracktion_engine::WaveAudioClip::setCurrentTake(int takeIndex)	C++
tracktion_engine::CompManager::setActiveTakeIndex(int index)	C++

Removing this call does what I need. I don’t know the implications of removing it though.

You can’t really remove that line or the CompManager will get out of sync with the takes.


I think the problem is in WaveAudioClip::getCurrentTake(). That expects the sourceFileReference to be a ProjectItemID. If you change line 228 to be

auto pid = sourceFileReference.source.get();

does that fix the recursion for you?


Sorry this is taking longer to fix than it should do. I don’t really have a test case for this so I’m just tracing it through as you report it, trying to break compatibility with the ProjectItemID paradigm that all our Waveform users rely on.

If you want to write a unit test that I can put in to the code base that shows the problem that would be easier for me to test against.

It sounds like adding takes weren’t meant to be done this way so I won’t go further down this rabbit hole. Especially if it potentially breaks something.

It’s not that they weren’t meant to be done this way, it’s just that they haven’t been done this way.
As I don’t have code for exactly what you’re doing, it’s difficult to change the existing code to enable it.

As I said though, if you can create a minimal test case, preferably in a UnitTest that demonstrates the problem, that’s a much easier position for me to start look to add support for this.