You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

221 lines
7.6KB

  1. /*
  2. Copyright (C) 2017 Xenakios
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of version 3 of the GNU General Public License
  5. as published by the Free Software Foundation.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License (version 3) for more details.
  10. www.gnu.org/licenses
  11. */
  12. #include "PluginProcessor.h"
  13. //extern std::unique_ptr<PropertiesFile> g_propsfile;
  14. #include "RenderSettingsComponent.h"
  15. RenderSettingsComponent::RenderSettingsComponent (PaulstretchpluginAudioProcessor* mc)
  16. {
  17. m_proc = mc;
  18. addAndMakeVisible(&m_labelMaxOutDuration);
  19. m_labelMaxOutDuration.setText("Max output duration (hours) :", dontSendNotification);
  20. addAndMakeVisible(&m_editorMaxOutDuration);
  21. m_editorMaxOutDuration.setText("1.0", dontSendNotification);
  22. addAndMakeVisible(&m_toggleFloatClip);
  23. m_toggleFloatClip.setButtonText("Clip floating point output");
  24. m_toggleFloatClip.setToggleState(false, dontSendNotification);
  25. addAndMakeVisible(&labelSamplerate);
  26. labelSamplerate.setText("Sample rate :", dontSendNotification);
  27. addAndMakeVisible(&comboBoxSamplerate);
  28. comboBoxSamplerate.addItem("Source sample rate", 1);
  29. comboBoxSamplerate.addItem("44100", 44100);
  30. comboBoxSamplerate.addItem("48000", 48000);
  31. comboBoxSamplerate.addItem("88200", 88200);
  32. comboBoxSamplerate.addItem("96000", 96000);
  33. comboBoxSamplerate.addListener (this);
  34. addAndMakeVisible(&labelBitDepth);
  35. labelBitDepth.setText("Format :", dontSendNotification);
  36. addAndMakeVisible(&comboBoxBitDepth);
  37. comboBoxBitDepth.addItem (TRANS("16 bit PCM"), 1);
  38. comboBoxBitDepth.addItem (TRANS("24 bit PCM"), 2);
  39. comboBoxBitDepth.addItem (TRANS("32 bit floating point"), 3);
  40. comboBoxBitDepth.addListener (this);
  41. addAndMakeVisible(&buttonRender);
  42. buttonRender.setButtonText (TRANS("Render"));
  43. buttonRender.addListener (this);
  44. addAndMakeVisible(&label3);
  45. label3.setText("Number of loops\n(approximate) :", dontSendNotification);
  46. addAndMakeVisible(&numLoopsEditor);
  47. numLoopsEditor.setMultiLine (false);
  48. numLoopsEditor.setReturnKeyStartsNewLine (false);
  49. numLoopsEditor.setReadOnly (false);
  50. numLoopsEditor.setCaretVisible (true);
  51. numLoopsEditor.setText (TRANS("1"));
  52. addAndMakeVisible(&label4);
  53. label4.setText("Output file :\n", dontSendNotification);
  54. addAndMakeVisible(&outfileNameEditor);
  55. outfileNameEditor.setMultiLine (false);
  56. outfileNameEditor.setReturnKeyStartsNewLine (false);
  57. outfileNameEditor.setReadOnly (false);
  58. outfileNameEditor.setScrollbarsShown (true);
  59. outfileNameEditor.setCaretVisible (true);
  60. outfileNameEditor.addListener(this);
  61. addAndMakeVisible(&buttonSelectFile);
  62. buttonSelectFile.setTooltip("Open dialog to choose file to render to");
  63. buttonSelectFile.setButtonText (TRANS("..."));
  64. buttonSelectFile.addListener (this);
  65. setSize (600, 400);
  66. comboBoxSamplerate.setSelectedId(1);
  67. comboBoxBitDepth.setSelectedId(3);
  68. String lastexportfile = m_proc->m_propsfile->m_props_file->getValue(ID_lastrenderpath);
  69. auto sep = File::getSeparatorChar();
  70. File temp(lastexportfile);
  71. if (temp.getParentDirectory().exists())
  72. outfileNameEditor.setText(lastexportfile, dontSendNotification);
  73. else
  74. outfileNameEditor.setText(File::getSpecialLocation(File::userDocumentsDirectory).getFullPathName()+sep+"pxsrender.wav",
  75. dontSendNotification);
  76. numLoopsEditor.setVisible(m_proc->getStretchSource()->isLoopingEnabled());
  77. label3.setVisible(m_proc->getStretchSource()->isLoopingEnabled());
  78. }
  79. RenderSettingsComponent::~RenderSettingsComponent()
  80. {
  81. //g_propsfile->setValue("last_export_file",outfileNameEditor.getText());
  82. }
  83. //==============================================================================
  84. void RenderSettingsComponent::paint (Graphics& g)
  85. {
  86. g.fillAll (Colour (0xff323e44));
  87. }
  88. void RenderSettingsComponent::resized()
  89. {
  90. int xoffs = 8;
  91. int yoffs = 1;
  92. int labelw = 160;
  93. int labelh = 24;
  94. label4.setBounds(xoffs, yoffs, labelw, 24);
  95. outfileNameEditor.setBounds(label4.getRight()+1, yoffs, getWidth() - labelw - 34 - xoffs, 24);
  96. buttonSelectFile.setBounds(outfileNameEditor.getRight() + 1, yoffs, 31, 24);
  97. yoffs += 25;
  98. labelSamplerate.setBounds (xoffs, yoffs, labelw, labelh);
  99. comboBoxSamplerate.setBounds (labelSamplerate.getRight()+1, yoffs, 150, 24);
  100. yoffs += 25;
  101. labelBitDepth.setBounds (xoffs, yoffs, labelw, 24);
  102. comboBoxBitDepth.setBounds (labelBitDepth.getRight()+1, yoffs, 150, 24);
  103. m_toggleFloatClip.setBounds(comboBoxBitDepth.getRight() + 1, yoffs, 10, 24);
  104. m_toggleFloatClip.changeWidthToFitText();
  105. yoffs += 25;
  106. if (m_proc->getStretchSource()->isLoopingEnabled())
  107. {
  108. label3.setBounds(xoffs, yoffs, labelw, 48);
  109. numLoopsEditor.setBounds(label3.getRight() + 1, yoffs, 150, 24);
  110. yoffs += 50;
  111. }
  112. m_labelMaxOutDuration.setBounds(xoffs, yoffs, 220, 24);
  113. m_editorMaxOutDuration.setBounds(m_labelMaxOutDuration.getRight() + 1, yoffs, 50, 24);
  114. yoffs += 25;
  115. buttonRender.setBounds(getWidth() - 152, getHeight()-25, 150, 24);
  116. }
  117. void RenderSettingsComponent::comboBoxChanged (ComboBox* comboBoxThatHasChanged)
  118. {
  119. if (comboBoxThatHasChanged == &comboBoxBitDepth)
  120. {
  121. if (comboBoxBitDepth.getSelectedId() == 3)
  122. m_toggleFloatClip.setEnabled(true);
  123. else m_toggleFloatClip.setEnabled(false);
  124. }
  125. }
  126. void RenderSettingsComponent::buttonClicked (Button* buttonThatWasClicked)
  127. {
  128. if (buttonThatWasClicked == &buttonRender)
  129. {
  130. File outfile(outfileNameEditor.getText());
  131. if (outfile.getParentDirectory().exists()==false)
  132. buttonClicked(&buttonSelectFile);
  133. outfile = File(outfileNameEditor.getText());
  134. if (outfile.getParentDirectory().exists()==false)
  135. return;
  136. int numLoops = 0;
  137. if (numLoopsEditor.isVisible())
  138. numLoops = numLoopsEditor.getText().getLargeIntValue();
  139. numLoops = jlimit<int>(0, 1000000, numLoops);
  140. int sampleRate = comboBoxSamplerate.getSelectedId();
  141. if (sampleRate == 1)
  142. sampleRate = 0;
  143. double maxrenderlen = m_editorMaxOutDuration.getText().getDoubleValue()*3600.0;
  144. maxrenderlen = jlimit(1.0, 1000000.0, maxrenderlen);
  145. int oformat = comboBoxBitDepth.getSelectedId() - 1;
  146. if (oformat == 2 && m_toggleFloatClip.getToggleState())
  147. oformat = 3;
  148. OfflineRenderParams renderpars{ File(outfileNameEditor.getText()),(double)comboBoxSamplerate.getSelectedId(),
  149. oformat,maxrenderlen,numLoops };
  150. m_proc->m_propsfile->m_props_file->setValue(ID_lastrenderpath, outfileNameEditor.getText());
  151. m_proc->offlineRender(renderpars);
  152. if (auto pardlg = dynamic_cast<CallOutBox*>(getParentComponent()); pardlg!=nullptr)
  153. {
  154. pardlg->exitModalState(1);
  155. }
  156. return;
  157. }
  158. else if (buttonThatWasClicked == &buttonSelectFile)
  159. {
  160. File lastexportfolder; // File(g_propsfile->getValue("last_export_file")).getParentDirectory();
  161. FileChooser myChooser("Please select audio file to render...",
  162. lastexportfolder,
  163. "*.wav");
  164. if (myChooser.browseForFileToSave(true))
  165. {
  166. outfileNameEditor.setText(myChooser.getResult().getFullPathName(), dontSendNotification);
  167. }
  168. }
  169. }
  170. int RenderSettingsComponent::getPreferredHeight()
  171. {
  172. if (m_proc->getStretchSource()->isLoopingEnabled())
  173. return 180;
  174. return 150;
  175. }
  176. void RenderSettingsComponent::textEditorTextChanged(TextEditor & ed)
  177. {
  178. return;
  179. if (&ed == &outfileNameEditor)
  180. {
  181. File temp(outfileNameEditor.getText());
  182. if (temp.getParentDirectory().exists() == false)
  183. {
  184. Logger::writeToLog("directory does not exist");
  185. }
  186. if (temp.exists() == true)
  187. {
  188. File temp2 = temp.getNonexistentSibling();
  189. Logger::writeToLog(temp.getFullPathName() + " exists, will instead use " + temp2.getFullPathName());
  190. }
  191. }
  192. }