# How to render an Edit to a new file audio file?

**URL:** <https://forum.juce.com/t/how-to-render-an-edit-to-a-new-file-audio-file/35136>\
**Category:** Tracktion Engine\
**Created:** [September 8, 2019, 2:23pm UTC](https://forum.juce.com/t/how-to-render-an-edit-to-a-new-file-audio-file/35136 "2019-09-08T14:23:08Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![xenakios](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/xenakios/32/4047_2.png) [@xenakios](https://forum.juce.com/u/xenakios)\
**Post date:** [September 8, 2019, 2:23pm UTC](https://forum.juce.com/t/how-to-render-an-edit-to-a-new-file-audio-file/35136/1 "2019-09-08T14:23:08Z")

</div>

I am guessing the needed functionality is in the Renderer class, but I just can’t figure out how to hook it all up correctly. Is it allowed to attempt to render an edit that is currently playing back in real time? If not, is there an easy way to make a temporary clone of the edit for the rendering?

My current code is as follows. Probably completely wrong, but the only way was to do guess work. The code fails when trying to create the rendering audio node, a nullptr is returned :

```auto
WavAudioFormat wavformat;
				te::Renderer::Parameters pars{ edit };
				pars.engine = &engine;
				pars.destFile = File("C:\\MusicAudio\\sourcesamples\\dirac\\te_export1.wav");
				pars.audioFormat = &wavformat;
				pars.time = { 0.0,1.0 };
				auto node = te::Renderer::createRenderingAudioNode(pars);
				if (node)
				{
					te::Renderer::RenderTask task{ "foo task",pars,node };
					while (task.runJob() != ThreadPoolJob::jobHasFinished)
					{
						Thread::sleep(10);
					}
					delete node;
					Logger::writeToLog("Render job finished");
				}
				else Logger::writeToLog("Could not create node");
```

---

<div class="post-metadata">

**Author:** ![RolandMR](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/rolandmr/32/641_2.png) [@RolandMR](https://forum.juce.com/u/RolandMR)\
**Post date:** [September 9, 2019, 4:20pm UTC](https://forum.juce.com/t/how-to-render-an-edit-to-a-new-file-audio-file/35136/2 "2019-09-09T16:20:18Z")

</div>

No, you can’t render an edit while it’s playing, mainly because there is only one copy of the plugins loaded, and they can’t be used for both playback and render at the same time.

The easiest way to do a render is with the static function `Renderer::renderToFile`

`Renderer::renderToFile ("Render"), outputFile, edit, { start, end }, tracksToDo);`

To create a copy of an edit, first I’d `edit.flushState()` and then `edit.state.createCopy()` and pass the ValueTree to a new edit.

---

<div class="post-metadata">

**Author:** ![bwall](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/bwall/32/618_2.png) [@bwall](https://forum.juce.com/u/bwall)\
**Post date:** [March 12, 2020, 11:13pm UTC](https://forum.juce.com/t/how-to-render-an-edit-to-a-new-file-audio-file/35136/3 "2020-03-12T23:13:41Z")

</div>

I’m using the code below, and not having any luck.

```auto
			juce::BigInteger tracksToDo{ 0 };

			for (auto i = 0; i < tracks.size(); i++)
				tracksToDo.setBit(i);

			te::EditTimeRange range{ 0.0, 34.0 };

			File renderFile{ File::getSpecialLocation(File::userDesktopDirectory).getChildFile("render.wav") };

			te::Renderer::renderToFile("Render", renderFile, edit, range, tracksToDo);

```

Th edit has five tracks with a few audio clips each.

I get nothing. No errors. No render file.

What am I missing?

---

<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:** [March 13, 2020, 1:11pm UTC](https://forum.juce.com/t/how-to-render-an-edit-to-a-new-file-audio-file/35136/4 "2020-03-13T13:11:01Z")

</div>

What are you trying to render? Are you sure there is content within that time range?

Have you stepped through the `renderToFile` method at all? It could be something simple like there is not content on the clips etc.

---

<div class="post-metadata">

**Author:** ![bwall](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/bwall/32/618_2.png) [@bwall](https://forum.juce.com/u/bwall)\
**Post date:** [March 13, 2020, 3:49pm UTC](https://forum.juce.com/t/how-to-render-an-edit-to-a-new-file-audio-file/35136/5 "2020-03-13T15:49:33Z")

</div>

Yes, all of the clips are in that time range.

On stepping through, I was hitting the jassert for the progress bar. So, instead, I needed to use this syntax;

```auto
te::Renderer::renderToFile("Render", renderFile, edit, range, tracksToDo, true, {}, false);

```

And now I am getting my render file!

So, now, two questions.

1. What are the downsides to setting `useThread = false` in `te::Renderer::renderToFile`?
2. What is the correct way to set up the progressbar so that I can have `useThread = 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:** [March 13, 2020, 4:48pm UTC](https://forum.juce.com/t/how-to-render-an-edit-to-a-new-file-audio-file/35136/6 "2020-03-13T16:48:23Z")

</div>

If you don’t use a thread, it will render on the calling thread and you won’t be able to cancel or get progress to it in order to display to your users.

To use a thread you’ll have to implement `runTaskWithProgressBar` in your `UIBehaviour` subclass.  
There’s an example of this just clearing our CI but you can take a look at a rough idea here: [Problem implementing runTaskWithProgressBar(te::ThreadPoolJobWithProgress& job)](https://forum.juce.com/t/problem-implementing-runtaskwithprogressbar-te-threadpooljobwithprogress-job/37405/2)

---

<div class="post-metadata">

**Author:** ![bwall](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/bwall/32/618_2.png) [@bwall](https://forum.juce.com/u/bwall)\
**Post date:** [March 13, 2020, 7:23pm UTC](https://forum.juce.com/t/how-to-render-an-edit-to-a-new-file-audio-file/35136/7 "2020-03-13T19:23:03Z")

</div>

Your help is always much appreciated.

I think I’ll wait for the `runTaskWithProgressBar` example coming through at the moment.

Thank you.

---

<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:** [March 15, 2020, 9:17am UTC](https://forum.juce.com/t/how-to-render-an-edit-to-a-new-file-audio-file/35136/8 "2020-03-15T09:17:01Z")

</div>

Ok, you can see a minimal example of this now here: [https://github.com/Tracktion/tracktion\_engine/blob/develop/examples/TestRunner.h](https://github.com/Tracktion/tracktion_engine/blob/develop/examples/TestRunner.h)

---

<div class="post-metadata">

**Author:** ![Jaytheway](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jaytheway/32/11615_2.png) [@Jaytheway](https://forum.juce.com/u/Jaytheway)\
**Post date:** [April 12, 2020, 1:34pm UTC](https://forum.juce.com/t/how-to-render-an-edit-to-a-new-file-audio-file/35136/9 "2020-04-12T13:34:11Z")

</div>

Hi, I’m having issues trying to do the same. Render works, but it only renders first track. Here’s how I’m setting tracks to render:

```
	juce::BigInteger tracksToDo{ 0 };

	for (auto i = 0; i < numOfTracks; i++) {
		tracksToDo.setBit(i);
	}

```

Literally the same way, just passing an **int** for the number of tracks instead of size of an array.  
In debugging it shows that there’s indeed correct number of bits set to 1, but rendered file plays as if there’s only the first track.

---

<div class="post-metadata">

**Author:** ![Jaytheway](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jaytheway/32/11615_2.png) [@Jaytheway](https://forum.juce.com/u/Jaytheway)\
**Post date:** [April 12, 2020, 1:46pm UTC](https://forum.juce.com/t/how-to-render-an-edit-to-a-new-file-audio-file/35136/10 "2020-04-12T13:46:46Z")

</div>

Found the issue. There were hidden utility tracks at first indexes. And for some reason Rendered doesn’t exclude them by default.

---

<div class="post-metadata">

**Author:** ![Jaytheway](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jaytheway/32/11615_2.png) [@Jaytheway](https://forum.juce.com/u/Jaytheway)\
**Post date:** [April 12, 2020, 4:54pm UTC](https://forum.juce.com/t/how-to-render-an-edit-to-a-new-file-audio-file/35136/11 "2020-04-12T16:54:58Z")

</div>

I have a question though. What would be the use case for `Clips*` parameter and how to use it?

---

<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:** [April 14, 2020, 10:34am UTC](https://forum.juce.com/t/how-to-render-an-edit-to-a-new-file-audio-file/35136/12 "2020-04-14T10:34:38Z")

</div>

You can choose to render only specific clips from a track.  
It’s probably not useful in most cases though, if you did want to use it, just add the clips to the `allowedClips` member that you want to include. Everything else won’t appear in the render.

---

<div class="post-metadata">

**Author:** ![Jaytheway](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jaytheway/32/11615_2.png) [@Jaytheway](https://forum.juce.com/u/Jaytheway)\
**Post date:** [April 14, 2020, 10:57am UTC](https://forum.juce.com/t/how-to-render-an-edit-to-a-new-file-audio-file/35136/13 "2020-04-14T10:57:34Z")

</div>

Just to clarify. I would have to create `Renderer::Parameters` with populated `allowedClips`, and use this function instead: `static juce::File renderToFile (const juce::String& taskDescription, const Parameters& params);` ? Or I can just pass an array of Clip\* to this function:  
` static bool renderToFile (const juce::String& taskDescription, const juce::File& outputFile, Edit& edit, EditTimeRange range, const juce::BigInteger& tracksToDo, bool usePlugins = true, juce::Array<Clip*> clips = {}, bool useThread = 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:** [April 14, 2020, 11:03am UTC](https://forum.juce.com/t/how-to-render-an-edit-to-a-new-file-audio-file/35136/14 "2020-04-14T11:03:53Z")

</div>

You can just pass an `Array<Clip*>` to `renderToFile`, it does all the rest internally.
