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.

158 lines
5.0KB

  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. class ParameterComponent : public Component,
  13. public Slider::Listener
  14. {
  15. public:
  16. ParameterComponent(AudioProcessorParameter* par) : m_par(par)
  17. {
  18. addAndMakeVisible(&m_label);
  19. m_label.setText(par->getName(50),dontSendNotification);
  20. AudioParameterFloat* floatpar = dynamic_cast<AudioParameterFloat*>(par);
  21. if (floatpar)
  22. {
  23. m_slider = std::make_unique<Slider>();
  24. m_slider->setRange(floatpar->range.start, floatpar->range.end, floatpar->range.interval);
  25. m_slider->setValue(*floatpar, dontSendNotification);
  26. m_slider->addListener(this);
  27. addAndMakeVisible(m_slider.get());
  28. }
  29. AudioParameterChoice* choicepar = dynamic_cast<AudioParameterChoice*>(par);
  30. if (choicepar)
  31. {
  32. }
  33. AudioParameterBool* boolpar = dynamic_cast<AudioParameterBool*>(par);
  34. if (boolpar)
  35. {
  36. }
  37. }
  38. void resized() override
  39. {
  40. m_label.setBounds(0, 0, 200, 24);
  41. if (m_slider)
  42. m_slider->setBounds(m_label.getRight() + 1, 0, getWidth() - 2 - m_label.getWidth(), 24);
  43. }
  44. void sliderValueChanged(Slider* slid) override
  45. {
  46. AudioParameterFloat* floatpar = dynamic_cast<AudioParameterFloat*>(m_par);
  47. *floatpar = slid->getValue();
  48. }
  49. void updateComponent()
  50. {
  51. AudioParameterFloat* floatpar = dynamic_cast<AudioParameterFloat*>(m_par);
  52. if (m_slider != nullptr && (float)m_slider->getValue() != *floatpar)
  53. {
  54. m_slider->setValue(*floatpar, dontSendNotification);
  55. }
  56. }
  57. private:
  58. Label m_label;
  59. AudioProcessorParameter* m_par = nullptr;
  60. std::unique_ptr<Slider> m_slider;
  61. std::unique_ptr<ComboBox> m_combobox;
  62. std::unique_ptr<ToggleButton> m_togglebut;
  63. };
  64. class WaveformComponent : public Component, public ChangeListener, public Timer
  65. {
  66. public:
  67. WaveformComponent(AudioFormatManager* afm);
  68. ~WaveformComponent();
  69. void changeListenerCallback(ChangeBroadcaster* cb) override;
  70. void paint(Graphics& g) override;
  71. void setAudioFile(File f);
  72. void setAudioBuffer(AudioBuffer<float>* buf, int samplerate, int len);
  73. void beginAddingAudioBlocks(int channels, int samplerate, int totalllen);
  74. void addAudioBlock(AudioBuffer<float>& buf, int samplerate, int pos);
  75. void timerCallback() override;
  76. std::function<double()> CursorPosCallback;
  77. std::function<void(double)> SeekCallback;
  78. std::function<void(Range<double>, int)> TimeSelectionChangedCallback;
  79. void mouseDown(const MouseEvent& e) override;
  80. void mouseUp(const MouseEvent& e) override;
  81. void mouseDrag(const MouseEvent& e) override;
  82. void mouseMove(const MouseEvent& e) override;
  83. Range<double> getTimeSelection()
  84. {
  85. if (m_time_sel_start >= 0.0 && m_time_sel_end>m_time_sel_start + 0.001)
  86. return { m_time_sel_start, m_time_sel_end };
  87. return { 0.0, 1.0 };
  88. }
  89. void setTimeSelection(Range<double> rng)
  90. {
  91. if (rng.isEmpty())
  92. rng = { -1.0,1.0 };
  93. m_time_sel_start = rng.getStart();
  94. m_time_sel_end = rng.getEnd();
  95. repaint();
  96. }
  97. void setFileCachedRange(std::pair<Range<double>, Range<double>> rng);
  98. void setTimerEnabled(bool b);
  99. void setViewRange(Range<double> rng);
  100. Value ShowFileCacheRange;
  101. void setRecordingPosition(double pos) { m_rec_pos = pos; }
  102. private:
  103. AudioThumbnailCache m_thumbcache;
  104. std::unique_ptr<AudioThumbnail> m_thumb;
  105. Range<double> m_view_range{ 0.0,1.0 };
  106. int m_time_sel_drag_target = 0;
  107. double m_time_sel_start = -1.0;
  108. double m_time_sel_end = -1.0;
  109. double m_drag_time_start = 0.0;
  110. bool m_mousedown = false;
  111. bool m_didseek = false;
  112. bool m_didchangetimeselection = false;
  113. int m_topmargin = 0;
  114. int getTimeSelectionEdge(int x, int y);
  115. std::pair<Range<double>, Range<double>> m_file_cached;
  116. File m_curfile;
  117. Image m_waveimage;
  118. OpenGLContext m_ogl;
  119. bool m_use_opengl = false;
  120. double m_rec_pos = 0.0;
  121. };
  122. class PaulstretchpluginAudioProcessorEditor : public AudioProcessorEditor,
  123. public MultiTimer, public Button::Listener
  124. {
  125. public:
  126. PaulstretchpluginAudioProcessorEditor (PaulstretchpluginAudioProcessor&);
  127. ~PaulstretchpluginAudioProcessorEditor();
  128. void buttonClicked(Button* but) override;
  129. //==============================================================================
  130. void paint (Graphics&) override;
  131. void resized() override;
  132. void timerCallback(int id) override;
  133. void setAudioFile(File f);
  134. void setAudioBuffer(AudioBuffer<float>* buf, int samplerate, int len);
  135. void beginAddingAudioBlocks(int channels, int samplerate, int totalllen);
  136. void addAudioBlock(AudioBuffer<float>& buf, int samplerate, int pos);
  137. private:
  138. PaulstretchpluginAudioProcessor& processor;
  139. std::vector<std::shared_ptr<ParameterComponent>> m_parcomps;
  140. ToggleButton m_rec_enable;
  141. TextButton m_import_button;
  142. Label m_info_label;
  143. WaveformComponent m_wavecomponent;
  144. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PaulstretchpluginAudioProcessorEditor)
  145. };