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.

189 lines
5.6KB

  1. /*
  2. ==============================================================================
  3. This file was auto-generated!
  4. It contains the basic framework code for a JUCE plugin editor.
  5. ==============================================================================
  6. */
  7. #pragma once
  8. #include "../JuceLibraryCode/JuceHeader.h"
  9. #include "PluginProcessor.h"
  10. #include <memory>
  11. #include <vector>
  12. inline void attachCallback(Button& button, std::function<void()> callback)
  13. {
  14. struct ButtonCallback : public Button::Listener,
  15. private ComponentListener
  16. {
  17. ButtonCallback(Button& b, std::function<void()> f) : target(b), fn(f)
  18. {
  19. target.addListener(this);
  20. target.addComponentListener(this);
  21. }
  22. ~ButtonCallback()
  23. {
  24. target.removeListener(this);
  25. }
  26. void componentBeingDeleted(Component&) override { delete this; }
  27. void buttonClicked(Button*) override { fn(); }
  28. Button& target;
  29. std::function<void()> fn;
  30. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ButtonCallback)
  31. };
  32. new ButtonCallback(button, callback);
  33. }
  34. class ParameterComponent : public Component,
  35. public Slider::Listener
  36. {
  37. public:
  38. ParameterComponent(AudioProcessorParameter* par) : m_par(par)
  39. {
  40. addAndMakeVisible(&m_label);
  41. m_label.setText(par->getName(50),dontSendNotification);
  42. AudioParameterFloat* floatpar = dynamic_cast<AudioParameterFloat*>(par);
  43. if (floatpar)
  44. {
  45. m_slider = std::make_unique<Slider>();
  46. m_slider->setRange(floatpar->range.start, floatpar->range.end, floatpar->range.interval);
  47. m_slider->setValue(*floatpar, dontSendNotification);
  48. m_slider->addListener(this);
  49. addAndMakeVisible(m_slider.get());
  50. }
  51. AudioParameterChoice* choicepar = dynamic_cast<AudioParameterChoice*>(par);
  52. if (choicepar)
  53. {
  54. }
  55. AudioParameterBool* boolpar = dynamic_cast<AudioParameterBool*>(par);
  56. if (boolpar)
  57. {
  58. }
  59. }
  60. void resized() override
  61. {
  62. m_label.setBounds(0, 0, 200, 24);
  63. if (m_slider)
  64. m_slider->setBounds(m_label.getRight() + 1, 0, getWidth() - 2 - m_label.getWidth(), 24);
  65. }
  66. void sliderValueChanged(Slider* slid) override
  67. {
  68. AudioParameterFloat* floatpar = dynamic_cast<AudioParameterFloat*>(m_par);
  69. *floatpar = slid->getValue();
  70. }
  71. void updateComponent()
  72. {
  73. AudioParameterFloat* floatpar = dynamic_cast<AudioParameterFloat*>(m_par);
  74. if (m_slider != nullptr && (float)m_slider->getValue() != *floatpar)
  75. {
  76. m_slider->setValue(*floatpar, dontSendNotification);
  77. }
  78. }
  79. private:
  80. Label m_label;
  81. AudioProcessorParameter* m_par = nullptr;
  82. std::unique_ptr<Slider> m_slider;
  83. std::unique_ptr<ComboBox> m_combobox;
  84. std::unique_ptr<ToggleButton> m_togglebut;
  85. };
  86. class WaveformComponent : public Component, public ChangeListener, public Timer
  87. {
  88. public:
  89. WaveformComponent(AudioFormatManager* afm);
  90. ~WaveformComponent();
  91. void changeListenerCallback(ChangeBroadcaster* cb) override;
  92. void paint(Graphics& g) override;
  93. void setAudioFile(File f);
  94. const File& getAudioFile() const { return m_curfile; }
  95. void setAudioBuffer(AudioBuffer<float>* buf, int samplerate, int len);
  96. void beginAddingAudioBlocks(int channels, int samplerate, int totalllen);
  97. void addAudioBlock(AudioBuffer<float>& buf, int samplerate, int pos);
  98. void timerCallback() override;
  99. std::function<double()> CursorPosCallback;
  100. std::function<void(double)> SeekCallback;
  101. std::function<void(Range<double>, int)> TimeSelectionChangedCallback;
  102. void mouseDown(const MouseEvent& e) override;
  103. void mouseUp(const MouseEvent& e) override;
  104. void mouseDrag(const MouseEvent& e) override;
  105. void mouseMove(const MouseEvent& e) override;
  106. Range<double> getTimeSelection()
  107. {
  108. if (m_time_sel_start >= 0.0 && m_time_sel_end>m_time_sel_start + 0.001)
  109. return { m_time_sel_start, m_time_sel_end };
  110. return { 0.0, 1.0 };
  111. }
  112. void setTimeSelection(Range<double> rng)
  113. {
  114. if (m_lock_timesel_set == true)
  115. return;
  116. if (rng.isEmpty())
  117. rng = { -1.0,1.0 };
  118. m_time_sel_start = rng.getStart();
  119. m_time_sel_end = rng.getEnd();
  120. repaint();
  121. }
  122. void setFileCachedRange(std::pair<Range<double>, Range<double>> rng);
  123. void setTimerEnabled(bool b);
  124. void setViewRange(Range<double> rng);
  125. Value ShowFileCacheRange;
  126. void setRecordingPosition(double pos) { m_rec_pos = pos; }
  127. private:
  128. AudioThumbnailCache m_thumbcache;
  129. std::unique_ptr<AudioThumbnail> m_thumb;
  130. Range<double> m_view_range{ 0.0,1.0 };
  131. int m_time_sel_drag_target = 0;
  132. double m_time_sel_start = -1.0;
  133. double m_time_sel_end = -1.0;
  134. double m_drag_time_start = 0.0;
  135. bool m_mousedown = false;
  136. bool m_didseek = false;
  137. bool m_didchangetimeselection = false;
  138. int m_topmargin = 0;
  139. int getTimeSelectionEdge(int x, int y);
  140. std::pair<Range<double>, Range<double>> m_file_cached;
  141. File m_curfile;
  142. Image m_waveimage;
  143. OpenGLContext m_ogl;
  144. bool m_use_opengl = false;
  145. double m_rec_pos = 0.0;
  146. bool m_lock_timesel_set = false;
  147. };
  148. class PaulstretchpluginAudioProcessorEditor : public AudioProcessorEditor,
  149. public MultiTimer
  150. {
  151. public:
  152. PaulstretchpluginAudioProcessorEditor (PaulstretchpluginAudioProcessor&);
  153. ~PaulstretchpluginAudioProcessorEditor();
  154. void paint (Graphics&) override;
  155. void resized() override;
  156. void timerCallback(int id) override;
  157. void setAudioFile(File f);
  158. void setAudioBuffer(AudioBuffer<float>* buf, int samplerate, int len);
  159. void beginAddingAudioBlocks(int channels, int samplerate, int totalllen);
  160. void addAudioBlock(AudioBuffer<float>& buf, int samplerate, int pos);
  161. WaveformComponent m_wavecomponent;
  162. private:
  163. PaulstretchpluginAudioProcessor& processor;
  164. std::vector<std::shared_ptr<ParameterComponent>> m_parcomps;
  165. ToggleButton m_rec_enable;
  166. TextButton m_import_button;
  167. Label m_info_label;
  168. void chooseFile();
  169. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PaulstretchpluginAudioProcessorEditor)
  170. };