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.

187 lines
6.4KB

  1. /*
  2. Copyright (C) 2006-2011 Nasca Octavian Paul
  3. Author: Nasca Octavian Paul
  4. Copyright (C) 2017 Xenakios
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of version 2 of the GNU General Public License
  7. as published by the Free Software Foundation.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License (version 2) for more details.
  12. You should have received a copy of the GNU General Public License (version 2)
  13. along with this program; if not, write to the Free Software Foundation,
  14. Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  15. */
  16. #pragma once
  17. #include "../JuceLibraryCode/JuceHeader.h"
  18. #include "PS_Source/PaulStretchControl.h"
  19. class MyThumbCache;
  20. const int cpi_main_volume = 0;
  21. const int cpi_stretchamount = 1;
  22. const int cpi_fftsize = 2;
  23. const int cpi_pitchshift = 3;
  24. const int cpi_frequencyshift = 4;
  25. const int cpi_soundstart = 5;
  26. const int cpi_soundend = 6;
  27. const int cpi_freeze = 7;
  28. const int cpi_spreadamount = 8;
  29. const int cpi_compress = 9;
  30. const int cpi_loopxfadelen = 10;
  31. const int cpi_numharmonics = 11;
  32. const int cpi_harmonicsfreq = 12;
  33. const int cpi_harmonicsbw = 13;
  34. const int cpi_harmonicsgauss = 14;
  35. const int cpi_octavesm2 = 15;
  36. const int cpi_octavesm1 = 16;
  37. const int cpi_octaves0 = 17;
  38. const int cpi_octaves1 = 18;
  39. const int cpi_octaves15 = 19;
  40. const int cpi_octaves2 = 20;
  41. const int cpi_tonalvsnoisebw = 21;
  42. const int cpi_tonalvsnoisepreserve = 22;
  43. const int cpi_filter_low = 23;
  44. const int cpi_filter_high = 24;
  45. const int cpi_onsetdetection = 25;
  46. const int cpi_capture_enabled = 26;
  47. const int cpi_num_outchans = 27;
  48. const int cpi_pause_enabled = 28;
  49. const int cpi_max_capture_len = 29;
  50. const int cpi_passthrough = 30;
  51. class MyPropertiesFile
  52. {
  53. public:
  54. MyPropertiesFile()
  55. {
  56. PropertiesFile::Options poptions;
  57. poptions.applicationName = "PaulXStretch3";
  58. poptions.folderName = "PaulXStretch3";
  59. poptions.commonToAllUsers = false;
  60. poptions.doNotSave = false;
  61. poptions.storageFormat = PropertiesFile::storeAsXML;
  62. poptions.millisecondsBeforeSaving = 1000;
  63. poptions.ignoreCaseOfKeyNames = false;
  64. poptions.processLock = nullptr;
  65. poptions.filenameSuffix = ".xml";
  66. poptions.osxLibrarySubFolder = "Application Support";
  67. m_props_file = std::make_unique<PropertiesFile>(poptions);
  68. }
  69. std::unique_ptr<PropertiesFile> m_props_file;
  70. };
  71. class PaulstretchpluginAudioProcessor : public AudioProcessor,
  72. public MultiTimer
  73. {
  74. public:
  75. PaulstretchpluginAudioProcessor();
  76. ~PaulstretchpluginAudioProcessor();
  77. //==============================================================================
  78. void prepareToPlay (double sampleRate, int samplesPerBlock) override;
  79. void releaseResources() override;
  80. #ifndef JucePlugin_PreferredChannelConfigurations
  81. bool isBusesLayoutSupported (const BusesLayout& layouts) const override;
  82. #endif
  83. void processBlock (AudioSampleBuffer&, MidiBuffer&) override;
  84. //==============================================================================
  85. AudioProcessorEditor* createEditor() override;
  86. bool hasEditor() const override;
  87. //==============================================================================
  88. const String getName() const override;
  89. bool acceptsMidi() const override;
  90. bool producesMidi() const override;
  91. bool isMidiEffect () const override;
  92. double getTailLengthSeconds() const override;
  93. //==============================================================================
  94. int getNumPrograms() override;
  95. int getCurrentProgram() override;
  96. void setCurrentProgram (int index) override;
  97. const String getProgramName (int index) override;
  98. void changeProgramName (int index, const String& newName) override;
  99. //==============================================================================
  100. void getStateInformation (MemoryBlock& destData) override;
  101. void setStateInformation (const void* data, int sizeInBytes) override;
  102. AudioParameterFloat* getFloatParameter(int index)
  103. {
  104. return dynamic_cast<AudioParameterFloat*>(getParameters()[index]);
  105. }
  106. void setRecordingEnabled(bool b);
  107. bool isRecordingEnabled() { return m_is_recording; }
  108. double getRecordingPositionPercent();
  109. String setAudioFile(File f);
  110. File getAudioFile() { return m_current_file; }
  111. Range<double> getTimeSelection();
  112. SharedResourcePointer<AudioFormatManager> m_afm;
  113. SharedResourcePointer<MyPropertiesFile> m_propsfile;
  114. StretchAudioSource* getStretchSource() { return m_stretch_source.get(); }
  115. double getPreBufferingPercent();
  116. void timerCallback(int id) override;
  117. double getSampleRateChecked();
  118. int m_abnormal_output_samples = 0;
  119. AudioPlayHead::CurrentPositionInfo m_playposinfo;
  120. bool m_play_when_host_plays = false;
  121. bool m_capture_when_host_plays = false;
  122. bool m_use_backgroundbuffering = true;
  123. void resetParameters();
  124. void setPreBufferAmount(int x);
  125. int getPreBufferAmount();
  126. bool m_load_file_with_state = true;
  127. private:
  128. bool m_prebuffering_inited = false;
  129. AudioBuffer<float> m_recbuffer;
  130. double m_max_reclen = 10.0;
  131. bool m_is_recording = false;
  132. int m_rec_pos = 0;
  133. void finishRecording(int lenrecorded);
  134. bool m_using_memory_buffer = true;
  135. int m_cur_num_out_chans = 2;
  136. CriticalSection m_cs;
  137. File m_current_file;
  138. Time m_current_file_date;
  139. TimeSliceThread m_bufferingthread;
  140. std::unique_ptr<StretchAudioSource> m_stretch_source;
  141. std::unique_ptr<MyBufferingAudioSource> m_buffering_source;
  142. int m_prebuffer_amount = 1;
  143. bool m_recreate_buffering_source = true;
  144. int m_fft_size_to_use = 1024;
  145. double m_last_outpos_pos = 0.0;
  146. double m_last_in_pos = 0.0;
  147. std::vector<int> m_bufamounts{ 4096,8192,16384,32768,65536,262144 };
  148. ProcessParameters m_ppar;
  149. void setFFTSize(double size);
  150. void startplay(Range<double> playrange, int numoutchans, int maxBlockSize, String& err);
  151. SharedResourcePointer<MyThumbCache> m_thumbcache;
  152. AudioParameterInt* m_outchansparam = nullptr;
  153. int m_curmaxblocksize = 0;
  154. double m_cur_sr = 0.0;
  155. bool m_last_host_playing = false;
  156. AudioBuffer<float> m_input_buffer;
  157. std::vector<float> m_reset_pars;
  158. //==============================================================================
  159. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PaulstretchpluginAudioProcessor)
  160. };