Work on offline render stuff
This commit is contained in:
		@@ -611,6 +611,13 @@ double StretchAudioSource::getInfileLengthSeconds()
 | 
				
			|||||||
	return (double)m_inputfile->info.nsamples / m_inputfile->info.samplerate;
 | 
						return (double)m_inputfile->info.nsamples / m_inputfile->info.samplerate;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					double StretchAudioSource::getInfileSamplerate()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (m_inputfile == nullptr)
 | 
				
			||||||
 | 
							return 0.0;
 | 
				
			||||||
 | 
						return m_inputfile->info.samplerate;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void StretchAudioSource::setRate(double rate)
 | 
					void StretchAudioSource::setRate(double rate)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if (rate == m_playrate)
 | 
						if (rate == m_playrate)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -56,6 +56,7 @@ public:
 | 
				
			|||||||
	double getInfilePositionPercent();
 | 
						double getInfilePositionPercent();
 | 
				
			||||||
	double getInfilePositionSeconds();
 | 
						double getInfilePositionSeconds();
 | 
				
			||||||
	double getInfileLengthSeconds();
 | 
						double getInfileLengthSeconds();
 | 
				
			||||||
 | 
						double getInfileSamplerate();
 | 
				
			||||||
	void setRate(double rate);
 | 
						void setRate(double rate);
 | 
				
			||||||
	double getRate() 
 | 
						double getRate() 
 | 
				
			||||||
	{ 
 | 
						{ 
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -526,24 +526,43 @@ void PaulstretchpluginAudioProcessor::saveCaptureBuffer()
 | 
				
			|||||||
	m_threadpool->addJob(task);
 | 
						m_threadpool->addJob(task);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
String PaulstretchpluginAudioProcessor::offlineRender(File outputfile)
 | 
					String PaulstretchpluginAudioProcessor::offlineRender(OfflineRenderParams renderpars)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	File outputfiletouse = outputfile.getNonexistentSibling();
 | 
						File outputfiletouse = renderpars.outputfile.getNonexistentSibling();
 | 
				
			||||||
	ValueTree state = getStateTree(false, false);
 | 
						ValueTree state{ getStateTree(false, false) };
 | 
				
			||||||
	auto processor = std::make_shared<PaulstretchpluginAudioProcessor>();
 | 
						auto processor = std::make_shared<PaulstretchpluginAudioProcessor>();
 | 
				
			||||||
 | 
						
 | 
				
			||||||
	processor->setStateFromTree(state);
 | 
						processor->setStateFromTree(state);
 | 
				
			||||||
	int blocksize = 2048;
 | 
						double outsr{ renderpars.outsr };
 | 
				
			||||||
 | 
						if (outsr < 10.0)
 | 
				
			||||||
 | 
							outsr = processor->getStretchSource()->getInfileSamplerate();
 | 
				
			||||||
 | 
						Logger::writeToLog(outputfiletouse.getFullPathName() + " " + String(outsr) + " " + String(renderpars.outputformat));
 | 
				
			||||||
 | 
						return {};
 | 
				
			||||||
 | 
						int blocksize{ 2048 };
 | 
				
			||||||
	int numoutchans = *processor->getIntParameter(cpi_num_outchans);
 | 
						int numoutchans = *processor->getIntParameter(cpi_num_outchans);
 | 
				
			||||||
	processor->prepareToPlay(44100.0, blocksize);
 | 
						processor->prepareToPlay(renderpars.outsr, blocksize);
 | 
				
			||||||
 | 
						
 | 
				
			||||||
	double t0 = *processor->getFloatParameter(cpi_soundstart);
 | 
						double t0 = *processor->getFloatParameter(cpi_soundstart);
 | 
				
			||||||
	double t1 = *processor->getFloatParameter(cpi_soundend);
 | 
						double t1 = *processor->getFloatParameter(cpi_soundend);
 | 
				
			||||||
	sanitizeTimeRange(t0, t1);
 | 
						sanitizeTimeRange(t0, t1);
 | 
				
			||||||
	double outsr = processor->getSampleRateChecked();
 | 
						
 | 
				
			||||||
	WavAudioFormat wavformat;
 | 
						WavAudioFormat wavformat;
 | 
				
			||||||
	FileOutputStream* outstream = outputfiletouse.createOutputStream();
 | 
						FileOutputStream* outstream = outputfiletouse.createOutputStream();
 | 
				
			||||||
	if (outstream == nullptr)
 | 
						if (outstream == nullptr)
 | 
				
			||||||
		return "Could not create output file";
 | 
							return "Could not create output file";
 | 
				
			||||||
	auto writer = wavformat.createWriterFor(outstream, getSampleRateChecked(), numoutchans, 32, StringPairArray(), 0);
 | 
						int oformattouse{ 16 };
 | 
				
			||||||
 | 
						bool clipoutput{ false };
 | 
				
			||||||
 | 
						if (renderpars.outputformat == 1)
 | 
				
			||||||
 | 
							oformattouse = 24;
 | 
				
			||||||
 | 
						if (renderpars.outputformat == 2)
 | 
				
			||||||
 | 
							oformattouse = 32;
 | 
				
			||||||
 | 
						if (renderpars.outputformat == 3)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							oformattouse = 32;
 | 
				
			||||||
 | 
							clipoutput = true;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						auto writer = wavformat.createWriterFor(outstream, getSampleRateChecked(), numoutchans, 
 | 
				
			||||||
 | 
							oformattouse, StringPairArray(), 0);
 | 
				
			||||||
	if (writer == nullptr)
 | 
						if (writer == nullptr)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		delete outstream;
 | 
							delete outstream;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -120,6 +120,19 @@ public:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
class PaulstretchpluginAudioProcessorEditor;
 | 
					class PaulstretchpluginAudioProcessorEditor;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct OfflineRenderParams
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						OfflineRenderParams(File ofile, double osr, int oformat, double omaxdur, int onumloops, CallOutBox* ocb=nullptr) :
 | 
				
			||||||
 | 
							outputfile(ofile), outsr(osr), outputformat(oformat), maxoutdur(omaxdur), numloops(onumloops), cbox(ocb)
 | 
				
			||||||
 | 
						{}
 | 
				
			||||||
 | 
						File outputfile;
 | 
				
			||||||
 | 
						double outsr = 44100.0;
 | 
				
			||||||
 | 
						double maxoutdur = 3600.0;
 | 
				
			||||||
 | 
						int numloops = 1;
 | 
				
			||||||
 | 
						int outputformat = 0; // 0=16 bit pcm, 1=24 bit pcm, 2=32 bit float, 3=32 bit float clipped
 | 
				
			||||||
 | 
						CallOutBox* cbox = nullptr;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class PaulstretchpluginAudioProcessor  : public AudioProcessor, 
 | 
					class PaulstretchpluginAudioProcessor  : public AudioProcessor, 
 | 
				
			||||||
	public MultiTimer, public VSTCallbackHandler, public AudioProcessorParameter::Listener
 | 
						public MultiTimer, public VSTCallbackHandler, public AudioProcessorParameter::Listener
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@@ -201,7 +214,7 @@ public:
 | 
				
			|||||||
	bool m_load_file_with_state = true;
 | 
						bool m_load_file_with_state = true;
 | 
				
			||||||
	ValueTree getStateTree(bool ignoreoptions, bool ignorefile);
 | 
						ValueTree getStateTree(bool ignoreoptions, bool ignorefile);
 | 
				
			||||||
	void setStateFromTree(ValueTree tree);
 | 
						void setStateFromTree(ValueTree tree);
 | 
				
			||||||
	String offlineRender(File outputfile);
 | 
						String offlineRender(OfflineRenderParams renderpars);
 | 
				
			||||||
	std::atomic<int> m_offline_render_state{ -1 };
 | 
						std::atomic<int> m_offline_render_state{ -1 };
 | 
				
			||||||
	std::atomic<bool> m_offline_render_cancel_requested{ false };
 | 
						std::atomic<bool> m_offline_render_cancel_requested{ false };
 | 
				
			||||||
	std::atomic<int> m_capture_save_state{ 0 };
 | 
						std::atomic<int> m_capture_save_state{ 0 };
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -81,13 +81,13 @@ RenderSettingsComponent::RenderSettingsComponent (PaulstretchpluginAudioProcesso
 | 
				
			|||||||
	setSize (600, 400);
 | 
						setSize (600, 400);
 | 
				
			||||||
	comboBoxSamplerate.setSelectedId(1);
 | 
						comboBoxSamplerate.setSelectedId(1);
 | 
				
			||||||
    comboBoxBitDepth.setSelectedId(3);
 | 
					    comboBoxBitDepth.setSelectedId(3);
 | 
				
			||||||
	String lastexportfile = ""; // g_propsfile->getValue("last_export_file");
 | 
						String lastexportfile = m_proc->m_propsfile->m_props_file->getValue(ID_lastrenderpath);
 | 
				
			||||||
	auto sep = File::getSeparatorChar();
 | 
						auto sep = File::getSeparatorChar();
 | 
				
			||||||
	File temp(lastexportfile);
 | 
						File temp(lastexportfile);
 | 
				
			||||||
	if (temp.getParentDirectory().exists())
 | 
						if (temp.getParentDirectory().exists())
 | 
				
			||||||
		outfileNameEditor.setText(lastexportfile, dontSendNotification);
 | 
							outfileNameEditor.setText(lastexportfile, dontSendNotification);
 | 
				
			||||||
	else
 | 
						else
 | 
				
			||||||
		outfileNameEditor.setText(File::getSpecialLocation(File::userDocumentsDirectory).getFullPathName()+sep+"untitled.wav",
 | 
							outfileNameEditor.setText(File::getSpecialLocation(File::userDocumentsDirectory).getFullPathName()+sep+"pxsrender.wav",
 | 
				
			||||||
			dontSendNotification);
 | 
								dontSendNotification);
 | 
				
			||||||
	numLoopsEditor.setVisible(m_proc->getStretchSource()->isLoopingEnabled());
 | 
						numLoopsEditor.setVisible(m_proc->getStretchSource()->isLoopingEnabled());
 | 
				
			||||||
	label3.setVisible(m_proc->getStretchSource()->isLoopingEnabled());
 | 
						label3.setVisible(m_proc->getStretchSource()->isLoopingEnabled());
 | 
				
			||||||
@@ -158,21 +158,24 @@ void RenderSettingsComponent::buttonClicked (Button* buttonThatWasClicked)
 | 
				
			|||||||
		outfile = File(outfileNameEditor.getText());
 | 
							outfile = File(outfileNameEditor.getText());
 | 
				
			||||||
		if (outfile.getParentDirectory().exists()==false)
 | 
							if (outfile.getParentDirectory().exists()==false)
 | 
				
			||||||
			return;
 | 
								return;
 | 
				
			||||||
		int64_t numLoops = 0; 
 | 
							int numLoops = 0; 
 | 
				
			||||||
		if (numLoopsEditor.isVisible())
 | 
							if (numLoopsEditor.isVisible())
 | 
				
			||||||
			numLoops = numLoopsEditor.getText().getLargeIntValue();
 | 
								numLoops = numLoopsEditor.getText().getLargeIntValue();
 | 
				
			||||||
		numLoops = jlimit<int64_t>(0, 1000000, numLoops);
 | 
							numLoops = jlimit<int>(0, 1000000, numLoops);
 | 
				
			||||||
		int sampleRate = comboBoxSamplerate.getSelectedId();
 | 
							int sampleRate = comboBoxSamplerate.getSelectedId();
 | 
				
			||||||
		if (sampleRate == 1)
 | 
							if (sampleRate == 1)
 | 
				
			||||||
			sampleRate = 0;
 | 
								sampleRate = 0;
 | 
				
			||||||
		double maxrenderlen = m_editorMaxOutDuration.getText().getDoubleValue()*3600.0;
 | 
							double maxrenderlen = m_editorMaxOutDuration.getText().getDoubleValue()*3600.0;
 | 
				
			||||||
		maxrenderlen = jlimit(1.0, 1000000.0, maxrenderlen);
 | 
							maxrenderlen = jlimit(1.0, 1000000.0, maxrenderlen);
 | 
				
			||||||
		m_proc->offlineRender(File(outfileNameEditor.getText()));
 | 
							int oformat = comboBoxBitDepth.getSelectedId() - 1;
 | 
				
			||||||
		//m_main->renderToFile(File(outfileNameEditor.getText()),numLoops,
 | 
							if (oformat == 2 && m_toggleFloatClip.getToggleState())
 | 
				
			||||||
		//	comboBoxBitDepth.getSelectedId()-1,sampleRate,m_toggleFloatClip.getToggleState(),maxrenderlen);
 | 
								oformat = 3;
 | 
				
			||||||
		auto pardlg = dynamic_cast<CallOutBox*>(getParentComponent());
 | 
							OfflineRenderParams renderpars{ File(outfileNameEditor.getText()),(double)comboBoxSamplerate.getSelectedId(),
 | 
				
			||||||
 | 
								oformat,maxrenderlen,numLoops };
 | 
				
			||||||
 | 
							m_proc->m_propsfile->m_props_file->setValue(ID_lastrenderpath, outfileNameEditor.getText());
 | 
				
			||||||
 | 
							m_proc->offlineRender(renderpars);
 | 
				
			||||||
 | 
							if (auto pardlg = dynamic_cast<CallOutBox*>(getParentComponent()); pardlg!=nullptr)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			if (pardlg != nullptr)
 | 
					 | 
				
			||||||
			pardlg->exitModalState(1);
 | 
								pardlg->exitModalState(1);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -51,6 +51,7 @@ private:
 | 
				
			|||||||
	Label m_labelMaxOutDuration;
 | 
						Label m_labelMaxOutDuration;
 | 
				
			||||||
	TextEditor m_editorMaxOutDuration;
 | 
						TextEditor m_editorMaxOutDuration;
 | 
				
			||||||
	ToggleButton m_toggleFloatClip;
 | 
						ToggleButton m_toggleFloatClip;
 | 
				
			||||||
 | 
						String ID_lastrenderpath{ "lastrenderpath" };
 | 
				
			||||||
	//==============================================================================
 | 
						//==============================================================================
 | 
				
			||||||
    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (RenderSettingsComponent)
 | 
					    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (RenderSettingsComponent)
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user