# Time Warp Temp File Woes?

**URL:** <https://forum.juce.com/t/time-warp-temp-file-woes/43509>\
**Category:** Tracktion Engine\
**Created:** [December 28, 2020, 7:30pm UTC](https://forum.juce.com/t/time-warp-temp-file-woes/43509 "2020-12-28T19:30:39Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![jrlanglois](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jrlanglois/32/21372_2.png) [@jrlanglois](https://forum.juce.com/u/jrlanglois)\
**Post date:** [December 28, 2020, 7:30pm UTC](https://forum.juce.com/t/time-warp-temp-file-woes/43509/1 "2020-12-28T19:30:39Z")

</div>

I’m not sure what is causing this, but I’m trying to create a basic edit + track + wave audio clip while calling `setWarpTime (true)`, and I’m hitting the only assertion in `AudioFile::deleteFile` where it can’t delete the temp file.

Any ideas?

---

<div class="post-metadata">

**Author:** ![jrlanglois](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jrlanglois/32/21372_2.png) [@jrlanglois](https://forum.juce.com/u/jrlanglois)\
**Post date:** [December 28, 2020, 7:43pm UTC](https://forum.juce.com/t/time-warp-temp-file-woes/43509/2 "2020-12-28T19:43:09Z")

</div>

This can be demonstrated by running the `PitchAndTimeDemo` pip and adding `clip->setWarpTime (true);` just after the line `clip->setAutoPitch (false);`.

---

<div class="post-metadata">

**Author:** ![jrlanglois](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jrlanglois/32/21372_2.png) [@jrlanglois](https://forum.juce.com/u/jrlanglois)\
**Post date:** [December 28, 2020, 8:09pm UTC](https://forum.juce.com/t/time-warp-temp-file-woes/43509/3 "2020-12-28T20:09:12Z")

</div>

Is it possible that `AudioFile::deleteFile` should look like this instead?

```auto
bool AudioFile::deleteFile() const
{
    CRASH_TRACER

    auto& afm = engine->getAudioFileManager();
    afm.checkFileForChangesAsync (*this);
    afm.releaseFile (*this);

    if (file.existsAsFile())
        return file.deleteFile();

    return true;
}

```

---

<div class="post-metadata">

**Author:** ![dave96](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/dave96/32/8487_2.png) [@dave96](https://forum.juce.com/u/dave96)\
**Post date:** [December 30, 2020, 4:36pm UTC](https://forum.juce.com/t/time-warp-temp-file-woes/43509/4 "2020-12-30T16:36:43Z")

</div>

Does that change actually work for you? Looking at the `juce::File` docs:

```auto
        @returns true if the file has been successfully deleted (or if it didn't exist to
                    begin with).

```

So the check to see if it exists shouldn’t be required…

Is something else holding on to the file handle like an audio thumbnail?  
And I assume this is on Windows? Deleting files is a real pain there as all file handles need to be closed for the operation to succeed.

---

<div class="post-metadata">

**Author:** ![jrlanglois](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jrlanglois/32/21372_2.png) [@jrlanglois](https://forum.juce.com/u/jrlanglois)\
**Post date:** [December 31, 2020, 2:40pm UTC](https://forum.juce.com/t/time-warp-temp-file-woes/43509/5 "2020-12-31T14:40:53Z")

</div>

Hm ok… based on those docs, I think what you’re saying about file handles still being in use seems likely. And yeah, I’m testing on Windows.

If you make the change I suggested above to the `PitchAndTimeDemo` pip, do you encounter the same thing?

---

<div class="post-metadata">

**Author:** ![jrlanglois](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jrlanglois/32/21372_2.png) [@jrlanglois](https://forum.juce.com/u/jrlanglois)\
**Post date:** [December 31, 2020, 3:17pm UTC](https://forum.juce.com/t/time-warp-temp-file-woes/43509/6 "2020-12-31T15:17:48Z")

</div>

The situation is getting stranger the more I try to use this feature in the provided PIP. Now I’m hitting, albeit sporadically, this assertion (on Win10 btw):

```auto
void Clip::setCurrentSourceFile (const juce::File& f)
{
    if (currentSourceFile != f)
    {
        jassert (f.existsAsFile());

```

What I’m thinking is happening is that the cached temp file somehow gets out of sync with what the audio clip recognises, and for some reason that cached file is gone before it gets set to the clip.

---

<div class="post-metadata">

**Author:** ![dave96](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/dave96/32/8487_2.png) [@dave96](https://forum.juce.com/u/dave96)\
**Post date:** [December 31, 2020, 5:32pm UTC](https://forum.juce.com/t/time-warp-temp-file-woes/43509/7 "2020-12-31T17:32:01Z")

</div>

The assert in `Clip::setCurrentSourceFile` is probably incorrect and can be ignored/removed. I think it’s because the source file is being set to a proxy file which doesn’t exist yet. The assertion was probably added by mistake when debugging a different part of the library.

I did try adding the `clip->setWarpTime (true);` but I don’t get any assertions when changing the pitch/tempo or loading a new file. Are you sure you haven’t made any other changes to the project?

---

<div class="post-metadata">

**Author:** ![jrlanglois](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jrlanglois/32/21372_2.png) [@jrlanglois](https://forum.juce.com/u/jrlanglois)\
**Post date:** [December 31, 2020, 5:43pm UTC](https://forum.juce.com/t/time-warp-temp-file-woes/43509/8 "2020-12-31T17:43:23Z")

</div>

> [@dave96](#):
>
> Are you sure you haven’t made any other changes to the project?

Absolutely. Nothing to JUCE, TE, nor the PIP beyond what I’ve described. Latest tip of develop for JUCE and TE.

---

<div class="post-metadata">

**Author:** ![jrlanglois](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jrlanglois/32/21372_2.png) [@jrlanglois](https://forum.juce.com/u/jrlanglois)\
**Post date:** [December 31, 2020, 5:44pm UTC](https://forum.juce.com/t/time-warp-temp-file-woes/43509/9 "2020-12-31T17:44:28Z")

</div>

> [@dave96](#):
>
> I think it’s because the source file is being set to a proxy file which doesn’t exist yet.

Does the proxy get generated regardless, even when not explicitly setting `setUsesProxy (true);` on the clip?

---

<div class="post-metadata">

**Author:** ![dave96](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/dave96/32/8487_2.png) [@dave96](https://forum.juce.com/u/dave96)\
**Post date:** [December 31, 2020, 5:46pm UTC](https://forum.juce.com/t/time-warp-temp-file-woes/43509/10 "2020-12-31T17:46:18Z")

</div>

`true` is the default. The time-stretching won’t and tempo syncing won’t work without that.

---

<div class="post-metadata">

**Author:** ![jrlanglois](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jrlanglois/32/21372_2.png) [@jrlanglois](https://forum.juce.com/u/jrlanglois)\
**Post date:** [December 31, 2020, 5:46pm UTC](https://forum.juce.com/t/time-warp-temp-file-woes/43509/11 "2020-12-31T17:46:44Z")

</div>

> [@dave96](#):
>
> I did try adding the `clip->setWarpTime (true);` but I don’t get any assertions when changing the pitch/tempo or loading a new file.

Please try closing the app via the normal exit button: I hit the assertion mentioned regularly with this method.

---

<div class="post-metadata">

**Author:** ![dave96](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/dave96/32/8487_2.png) [@dave96](https://forum.juce.com/u/dave96)\
**Post date:** [December 31, 2020, 6:00pm UTC](https://forum.juce.com/t/time-warp-temp-file-woes/43509/12 "2020-12-31T18:00:09Z")

</div>

Nope, still closes cleanly.  
Can I check what branch you’re on? There might have been some recent changes? I use the `tracktion_graph` branch most of the time but `develop` is pretty close to that.

---

<div class="post-metadata">

**Author:** ![jrlanglois](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jrlanglois/32/21372_2.png) [@jrlanglois](https://forum.juce.com/u/jrlanglois)\
**Post date:** [December 31, 2020, 6:07pm UTC](https://forum.juce.com/t/time-warp-temp-file-woes/43509/13 "2020-12-31T18:07:04Z")

</div>

`develop` for JUCE and TE.

---

<div class="post-metadata">

**Author:** ![dave96](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/dave96/32/8487_2.png) [@dave96](https://forum.juce.com/u/dave96)\
**Post date:** [December 31, 2020, 7:11pm UTC](https://forum.juce.com/t/time-warp-temp-file-woes/43509/14 "2020-12-31T19:11:22Z")

</div>

Can you try the `tracktion_graph` branch?

I’ve run this many times now and it always seems to succeed in `AudioFile::deleteFile()`.  
What is the call stack when you hit the assertion? I.e. what is causing the deletion?

---

<div class="post-metadata">

**Author:** ![jrlanglois](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jrlanglois/32/21372_2.png) [@jrlanglois](https://forum.juce.com/u/jrlanglois)\
**Post date:** [January 3, 2021, 7:45pm UTC](https://forum.juce.com/t/time-warp-temp-file-woes/43509/15 "2021-01-03T19:45:56Z")

</div>

When trying the `tracktion_graph` branch, the `AudioFile::deleteFile` assertion does NOT go away; it’s hit on app shutdown in my app.

 ![callstack - audio file assertion](https://us1.discourse-cdn.com/flex026/uploads/juce/original/2X/d/d428c7d0f18bb0f8f3eb47caef53ef4104d77039.png)

And the assertion in `Clip::setCurrentSourceFile` gets hit consistently now:

 ![Callstack - setCurrentSourceFile](https://us1.discourse-cdn.com/flex026/uploads/juce/original/2X/c/c3cb240fcdcadf91e184122efcc29c8fe3136555.png)

---

<div class="post-metadata">

**Author:** ![dave96](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/dave96/32/8487_2.png) [@dave96](https://forum.juce.com/u/dave96)\
**Post date:** [January 3, 2021, 10:27pm UTC](https://forum.juce.com/t/time-warp-temp-file-woes/43509/16 "2021-01-03T22:27:52Z")

</div>

Ok, looking at the stack trace it looks like it might still be rendering the proxy file when you close down and that’s why I wasn’t seeing it (I was only trying with very short samples than render in a couple of seconds).

It’s also important to note that this PitchAndTime demo was just a quick example to show the basics of matching an audio file to a pitch and tempo so any changes to the code could well throw up some unexpected consequences such as this.

I’ll try and take a look at this tomorrow when I’m back at work.

---

<div class="post-metadata">

**Author:** ![dave96](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/dave96/32/8487_2.png) [@dave96](https://forum.juce.com/u/dave96)\
**Post date:** [January 6, 2021, 11:27am UTC](https://forum.juce.com/t/time-warp-temp-file-woes/43509/17 "2021-01-06T11:27:43Z")

</div>

So I spent a bit of time trying to replicate this today with some longer MP3 files and I still can’t get it to hit the `deleteFile` assertion. (Using the tip of the `tracktion_graph` with only the `clip->setWarpTime(true);` line added).

Are you sure there isn’t anything else going on here? I notice in your stack trace you’ve redacted it which would indicate you’re not actually using the PitchAndTime PIP but your own app?

If I were to guess it looks like you’re closing the app whilst it’s still rendering some kind of proxy (there are several reasons this could be e.g. time-stretching or warp time) and that’s trying to delete the file while you have some handles open to the file somewhere else. That could be because you’re trying to draw it without using the `tracktion_engine::SmartThumbnail` class?

The only other thing I can think to try is dig in to the Windows `File::deleteFile` and get the reason the delete is failing. That might have some more information but will probably be because the file is open somewhere. If it is that, then maybe add some logging to `juce::FileInputStream` to track open/closes to the handles and see if there are any still in use by the time the deleteFile method is called?
