2017-11-13 15:06:08 +00:00
|
|
|
/*
|
|
|
|
==============================================================================
|
|
|
|
|
|
|
|
This file was auto-generated!
|
|
|
|
|
|
|
|
It contains the basic framework code for a JUCE plugin editor.
|
|
|
|
|
|
|
|
==============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../JuceLibraryCode/JuceHeader.h"
|
|
|
|
#include "PluginProcessor.h"
|
2017-11-13 18:45:23 +00:00
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
2017-11-13 15:06:08 +00:00
|
|
|
|
2017-11-16 15:38:59 +00:00
|
|
|
inline void attachCallback(Button& button, std::function<void()> callback)
|
|
|
|
{
|
|
|
|
struct ButtonCallback : public Button::Listener,
|
|
|
|
private ComponentListener
|
|
|
|
{
|
|
|
|
ButtonCallback(Button& b, std::function<void()> f) : target(b), fn(f)
|
|
|
|
{
|
|
|
|
target.addListener(this);
|
|
|
|
target.addComponentListener(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
~ButtonCallback()
|
|
|
|
{
|
|
|
|
target.removeListener(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void componentBeingDeleted(Component&) override { delete this; }
|
|
|
|
void buttonClicked(Button*) override { fn(); }
|
|
|
|
|
|
|
|
Button& target;
|
|
|
|
std::function<void()> fn;
|
|
|
|
|
|
|
|
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ButtonCallback)
|
|
|
|
};
|
|
|
|
|
|
|
|
new ButtonCallback(button, callback);
|
|
|
|
}
|
|
|
|
|
2017-11-24 22:22:07 +00:00
|
|
|
class MySlider : public Slider
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MySlider(NormalisableRange<float>* range) : m_range(range)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
double proportionOfLengthToValue(double x) override
|
|
|
|
{
|
|
|
|
return m_range->convertFrom0to1(x);
|
|
|
|
}
|
|
|
|
double valueToProportionOfLength(double x) override
|
|
|
|
{
|
|
|
|
return m_range->convertTo0to1(x);
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
NormalisableRange<float>* m_range = nullptr;
|
|
|
|
};
|
|
|
|
|
2017-11-13 18:45:23 +00:00
|
|
|
class ParameterComponent : public Component,
|
2017-11-16 17:45:40 +00:00
|
|
|
public Slider::Listener, public Button::Listener
|
2017-11-13 18:45:23 +00:00
|
|
|
{
|
|
|
|
public:
|
2017-11-17 14:41:33 +00:00
|
|
|
ParameterComponent(AudioProcessorParameter* par, bool notifyOnlyOnRelease) : m_par(par)
|
2017-11-13 18:45:23 +00:00
|
|
|
{
|
|
|
|
addAndMakeVisible(&m_label);
|
|
|
|
m_label.setText(par->getName(50),dontSendNotification);
|
|
|
|
AudioParameterFloat* floatpar = dynamic_cast<AudioParameterFloat*>(par);
|
|
|
|
if (floatpar)
|
|
|
|
{
|
2017-11-24 22:22:07 +00:00
|
|
|
m_slider = std::make_unique<MySlider>(&floatpar->range);
|
2017-11-17 14:41:33 +00:00
|
|
|
m_notify_only_on_release = notifyOnlyOnRelease;
|
2017-11-13 18:45:23 +00:00
|
|
|
m_slider->setRange(floatpar->range.start, floatpar->range.end, floatpar->range.interval);
|
|
|
|
m_slider->setValue(*floatpar, dontSendNotification);
|
|
|
|
m_slider->addListener(this);
|
|
|
|
addAndMakeVisible(m_slider.get());
|
|
|
|
}
|
|
|
|
AudioParameterChoice* choicepar = dynamic_cast<AudioParameterChoice*>(par);
|
|
|
|
if (choicepar)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
AudioParameterBool* boolpar = dynamic_cast<AudioParameterBool*>(par);
|
|
|
|
if (boolpar)
|
|
|
|
{
|
2017-11-16 17:45:40 +00:00
|
|
|
m_togglebut = std::make_unique<ToggleButton>();
|
|
|
|
m_togglebut->setToggleState(*boolpar, dontSendNotification);
|
|
|
|
m_togglebut->addListener(this);
|
|
|
|
addAndMakeVisible(m_togglebut.get());
|
2017-11-13 18:45:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
void resized() override
|
|
|
|
{
|
|
|
|
m_label.setBounds(0, 0, 200, 24);
|
|
|
|
if (m_slider)
|
|
|
|
m_slider->setBounds(m_label.getRight() + 1, 0, getWidth() - 2 - m_label.getWidth(), 24);
|
2017-11-16 17:45:40 +00:00
|
|
|
if (m_togglebut)
|
|
|
|
m_togglebut->setBounds(m_label.getRight() + 1, 0, getWidth() - 2 - m_label.getWidth(), 24);
|
2017-11-13 18:45:23 +00:00
|
|
|
}
|
|
|
|
void sliderValueChanged(Slider* slid) override
|
|
|
|
{
|
2017-11-17 14:41:33 +00:00
|
|
|
if (m_notify_only_on_release == true)
|
|
|
|
return;
|
|
|
|
AudioParameterFloat* floatpar = dynamic_cast<AudioParameterFloat*>(m_par);
|
|
|
|
*floatpar = slid->getValue();
|
|
|
|
}
|
|
|
|
void sliderDragStarted(Slider* slid) override
|
|
|
|
{
|
|
|
|
m_dragging = true;
|
|
|
|
}
|
|
|
|
void sliderDragEnded(Slider* slid) override
|
|
|
|
{
|
|
|
|
m_dragging = false;
|
|
|
|
if (m_notify_only_on_release == false)
|
|
|
|
return;
|
2017-11-13 18:54:08 +00:00
|
|
|
AudioParameterFloat* floatpar = dynamic_cast<AudioParameterFloat*>(m_par);
|
|
|
|
*floatpar = slid->getValue();
|
|
|
|
}
|
2017-11-16 17:45:40 +00:00
|
|
|
void buttonClicked(Button* but) override
|
|
|
|
{
|
|
|
|
AudioParameterBool* boolpar = dynamic_cast<AudioParameterBool*>(m_par);
|
|
|
|
if (m_togglebut != nullptr && m_togglebut->getToggleState() != *boolpar)
|
|
|
|
{
|
|
|
|
*boolpar = m_togglebut->getToggleState();
|
|
|
|
}
|
|
|
|
}
|
2017-11-13 18:54:08 +00:00
|
|
|
void updateComponent()
|
|
|
|
{
|
|
|
|
AudioParameterFloat* floatpar = dynamic_cast<AudioParameterFloat*>(m_par);
|
2017-11-17 14:41:33 +00:00
|
|
|
if (m_slider != nullptr && m_dragging == false && (float)m_slider->getValue() != *floatpar)
|
2017-11-13 18:54:08 +00:00
|
|
|
{
|
|
|
|
m_slider->setValue(*floatpar, dontSendNotification);
|
|
|
|
}
|
2017-11-16 17:45:40 +00:00
|
|
|
AudioParameterBool* boolpar = dynamic_cast<AudioParameterBool*>(m_par);
|
|
|
|
if (m_togglebut != nullptr && m_togglebut->getToggleState() != *boolpar)
|
|
|
|
{
|
|
|
|
m_togglebut->setToggleState(*boolpar, dontSendNotification);
|
|
|
|
}
|
2017-11-13 18:45:23 +00:00
|
|
|
}
|
|
|
|
private:
|
|
|
|
Label m_label;
|
|
|
|
AudioProcessorParameter* m_par = nullptr;
|
2017-11-24 22:22:07 +00:00
|
|
|
std::unique_ptr<MySlider> m_slider;
|
2017-11-13 18:45:23 +00:00
|
|
|
std::unique_ptr<ComboBox> m_combobox;
|
|
|
|
std::unique_ptr<ToggleButton> m_togglebut;
|
2017-11-17 14:41:33 +00:00
|
|
|
bool m_notify_only_on_release = false;
|
|
|
|
bool m_dragging = false;
|
2017-11-13 18:45:23 +00:00
|
|
|
};
|
2017-11-13 15:06:08 +00:00
|
|
|
|
2017-11-23 17:36:46 +00:00
|
|
|
class MyThumbCache : public AudioThumbnailCache
|
|
|
|
{
|
|
|
|
public:
|
2017-11-24 22:22:07 +00:00
|
|
|
MyThumbCache() : AudioThumbnailCache(100) { /*Logger::writeToLog("Constructed AudioThumbNailCache");*/ }
|
|
|
|
~MyThumbCache() { /*Logger::writeToLog("Destructed AudioThumbNailCache");*/ }
|
2017-11-23 17:36:46 +00:00
|
|
|
};
|
|
|
|
|
2017-11-13 21:42:13 +00:00
|
|
|
class WaveformComponent : public Component, public ChangeListener, public Timer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
WaveformComponent(AudioFormatManager* afm);
|
|
|
|
~WaveformComponent();
|
|
|
|
void changeListenerCallback(ChangeBroadcaster* cb) override;
|
|
|
|
void paint(Graphics& g) override;
|
|
|
|
void setAudioFile(File f);
|
2017-11-16 14:58:04 +00:00
|
|
|
const File& getAudioFile() const { return m_curfile; }
|
2017-11-13 21:42:13 +00:00
|
|
|
void setAudioBuffer(AudioBuffer<float>* buf, int samplerate, int len);
|
2017-11-15 15:52:47 +00:00
|
|
|
void beginAddingAudioBlocks(int channels, int samplerate, int totalllen);
|
|
|
|
void addAudioBlock(AudioBuffer<float>& buf, int samplerate, int pos);
|
2017-11-13 21:42:13 +00:00
|
|
|
void timerCallback() override;
|
|
|
|
std::function<double()> CursorPosCallback;
|
|
|
|
std::function<void(double)> SeekCallback;
|
|
|
|
std::function<void(Range<double>, int)> TimeSelectionChangedCallback;
|
|
|
|
void mouseDown(const MouseEvent& e) override;
|
|
|
|
void mouseUp(const MouseEvent& e) override;
|
|
|
|
void mouseDrag(const MouseEvent& e) override;
|
|
|
|
void mouseMove(const MouseEvent& e) override;
|
|
|
|
Range<double> getTimeSelection()
|
|
|
|
{
|
|
|
|
if (m_time_sel_start >= 0.0 && m_time_sel_end>m_time_sel_start + 0.001)
|
|
|
|
return { m_time_sel_start, m_time_sel_end };
|
|
|
|
return { 0.0, 1.0 };
|
|
|
|
}
|
|
|
|
void setTimeSelection(Range<double> rng)
|
|
|
|
{
|
2017-11-16 14:58:04 +00:00
|
|
|
if (m_lock_timesel_set == true)
|
|
|
|
return;
|
2017-11-13 21:42:13 +00:00
|
|
|
if (rng.isEmpty())
|
|
|
|
rng = { -1.0,1.0 };
|
|
|
|
m_time_sel_start = rng.getStart();
|
|
|
|
m_time_sel_end = rng.getEnd();
|
|
|
|
repaint();
|
|
|
|
}
|
|
|
|
void setFileCachedRange(std::pair<Range<double>, Range<double>> rng);
|
|
|
|
void setTimerEnabled(bool b);
|
|
|
|
void setViewRange(Range<double> rng);
|
|
|
|
Value ShowFileCacheRange;
|
2017-11-15 15:52:47 +00:00
|
|
|
void setRecordingPosition(double pos) { m_rec_pos = pos; }
|
2017-11-13 21:42:13 +00:00
|
|
|
private:
|
2017-11-23 17:36:46 +00:00
|
|
|
SharedResourcePointer<MyThumbCache> m_thumbcache;
|
2017-11-13 21:42:13 +00:00
|
|
|
|
|
|
|
std::unique_ptr<AudioThumbnail> m_thumb;
|
|
|
|
Range<double> m_view_range{ 0.0,1.0 };
|
|
|
|
int m_time_sel_drag_target = 0;
|
|
|
|
double m_time_sel_start = -1.0;
|
|
|
|
double m_time_sel_end = -1.0;
|
|
|
|
double m_drag_time_start = 0.0;
|
|
|
|
bool m_mousedown = false;
|
|
|
|
bool m_didseek = false;
|
|
|
|
bool m_didchangetimeselection = false;
|
|
|
|
int m_topmargin = 0;
|
|
|
|
int getTimeSelectionEdge(int x, int y);
|
|
|
|
std::pair<Range<double>, Range<double>> m_file_cached;
|
|
|
|
File m_curfile;
|
|
|
|
Image m_waveimage;
|
|
|
|
OpenGLContext m_ogl;
|
|
|
|
bool m_use_opengl = false;
|
2017-11-15 15:52:47 +00:00
|
|
|
double m_rec_pos = 0.0;
|
2017-11-16 14:58:04 +00:00
|
|
|
bool m_lock_timesel_set = false;
|
2017-11-13 21:42:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-11-13 18:54:08 +00:00
|
|
|
class PaulstretchpluginAudioProcessorEditor : public AudioProcessorEditor,
|
2017-11-16 15:38:59 +00:00
|
|
|
public MultiTimer
|
2017-11-13 15:06:08 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
PaulstretchpluginAudioProcessorEditor (PaulstretchpluginAudioProcessor&);
|
|
|
|
~PaulstretchpluginAudioProcessorEditor();
|
2017-11-16 15:38:59 +00:00
|
|
|
void paint (Graphics&) override;
|
2017-11-13 15:06:08 +00:00
|
|
|
void resized() override;
|
2017-11-13 18:54:08 +00:00
|
|
|
void timerCallback(int id) override;
|
2017-11-13 21:42:13 +00:00
|
|
|
void setAudioFile(File f);
|
|
|
|
void setAudioBuffer(AudioBuffer<float>* buf, int samplerate, int len);
|
2017-11-15 15:52:47 +00:00
|
|
|
void beginAddingAudioBlocks(int channels, int samplerate, int totalllen);
|
|
|
|
void addAudioBlock(AudioBuffer<float>& buf, int samplerate, int pos);
|
2017-11-15 19:47:26 +00:00
|
|
|
WaveformComponent m_wavecomponent;
|
2017-11-13 15:06:08 +00:00
|
|
|
private:
|
|
|
|
PaulstretchpluginAudioProcessor& processor;
|
2017-11-13 18:45:23 +00:00
|
|
|
std::vector<std::shared_ptr<ParameterComponent>> m_parcomps;
|
2017-11-13 19:21:30 +00:00
|
|
|
ToggleButton m_rec_enable;
|
2017-11-14 16:14:14 +00:00
|
|
|
TextButton m_import_button;
|
2017-11-13 20:35:36 +00:00
|
|
|
Label m_info_label;
|
2017-11-16 15:38:59 +00:00
|
|
|
void chooseFile();
|
2017-11-13 15:06:08 +00:00
|
|
|
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PaulstretchpluginAudioProcessorEditor)
|
|
|
|
};
|
2017-11-23 17:12:29 +00:00
|
|
|
|