How do I insert an audio file into an empty WaveAudioClip?

I created an empty clip ( wave type). How do I insert an audio file after a created clip?

Here is the way I created the empty clip:

auto clip = audioTrack->insertNewClip (te::TrackItem::Type::wave, "WaveAudioClip", editTimeRange, nullptr)

I know there is a way with insertWaveClip(). But for my function I have to add it afterwards.

Haven’t tried myself, but maybe this method could be useful?

WaveAudioClip::addTake (const juce::File& f)

I already tried it but didn’t work for me.

You probably don’t want to add a take. Use Clip::getSourceFileReference

Hey @ToxVox
I’m not sure if this helps but what I’ve been doing is:

juce::File blah {"path"};
auto clip = audioTrack->insertNewClip (te::TrackItem::Type::wave, "WaveAudioClip", editTimeRange, nullptr)
clip.setCurrentSourceFile(blah);

In my case I was swapping around audio files in to clips. Seems like it might work in your case too. Apologies if I misunderstand!

Cheers, J

You don’t typically want to use setCurrentSourceFile as that won’t save the path to the Clip so it won’t get recalled when you load the session again. This just sets it temporarily for playback.

1 Like

This version works for me:

juce::File blah {"path"};
auto clip = audioTrack->insertNewClip (te::TrackItem::Type::wave, "WaveAudioClip", editTimeRange, nullptr);
clip->getSourceFileReference().setToDirectFileReference(blah, true);

Or should I use this function? SourceFileReference::setToProjectFileReference()