Select Git revision
PluginEditor.h
PluginEditor.h 4.01 KiB
/*
==============================================================================
This file contains the basic framework code for a JUCE plugin editor.
==============================================================================
*/
#pragma once
#include <JuceHeader.h>
#include "PluginProcessor.h"
//==============================================================================
/**
*/
class Test2AudioProcessorEditor : public juce::AudioProcessorEditor, public juce::Slider::Listener, private juce::Timer
{
public:
Test2AudioProcessorEditor(Test2AudioProcessor &);
~Test2AudioProcessorEditor();
//==============================================================================
void paint(juce::Graphics &) override;
void resized() override;
private:
// This reference is provided as a quick way for your editor to
// access the processor object that created it.
Test2AudioProcessor &processor;
juce::Slider posSlider;
void sliderValueChanged(juce::Slider *slider) override
{
DBG("slider changed");
// if (slider == &posSlider)
// durationSlider.setValue(1.0 / frequencySlider.getValue(), dontSendNotification);
// else if (slider == &durationSlider)
// frequencySlider.setValue(1.0 / durationSlider.getValue(), dontSendNotification);
}
// is this the way
juce::Label positionLabel, timecodeDisplayLabel; // = juce::Label("Position", "Position : 0");
// or something like
//juce::Label positionLabel = {"Position"};
// should it be here or in the cpp file
// do we even need a cpp file, seems easier to do everything in the
// class declaration as we do not need to repeat the type name for each
// member function.
void timerCallback() override
{
positionLabel.setText("Pos : " + std::to_string(processor.position), juce::dontSendNotification);
updateTimecodeDisplay(processor.lastPosInfo);
repaint();
}
// Updates the text in our position label.
void updateTimecodeDisplay(juce::AudioPlayHead::CurrentPositionInfo pos)
{
juce::MemoryOutputStream displayText;
displayText << "[" << juce::SystemStats::getJUCEVersion() << "] "
<< juce::String(pos.bpm, 2) << " bpm, "
<< pos.timeSigNumerator << '/' << pos.timeSigDenominator
<< " - " << timeToTimecodeString(pos.timeInSeconds)
<< " - " << quarterNotePositionToBarsBeatsString(pos.ppqPosition, pos.timeSigNumerator, pos.timeSigDenominator);
if (pos.isRecording)
displayText << " (recording)";
else if (pos.isPlaying)
displayText << " (playing)";
timecodeDisplayLabel.setText(displayText.toString(), juce::dontSendNotification);
}
//==============================================================================
// quick-and-dirty function to format a timecode string
static juce::String timeToTimecodeString(double seconds)
{
auto millisecs = juce::roundToInt(seconds * 1000.0);
auto absMillisecs = std::abs(millisecs);
return juce::String::formatted("%02d:%02d:%02d.%03d",
millisecs / 3600000,
(absMillisecs / 60000) % 60,
(absMillisecs / 1000) % 60,
absMillisecs % 1000);
}
// quick-and-dirty function to format a bars/beats string
static juce::String quarterNotePositionToBarsBeatsString(double quarterNotes, int numerator, int denominator)
{
if (numerator == 0 || denominator == 0)
return "1|1|000";
auto quarterNotesPerBar = (numerator * 4 / denominator);
auto beats = (fmod(quarterNotes, quarterNotesPerBar) / quarterNotesPerBar) * numerator;
auto bar = ((int)quarterNotes) / quarterNotesPerBar + 1;
auto beat = ((int)beats) + 1;
auto ticks = ((int)(fmod(beats, 1.0) * 960.0 + 0.5));
return juce::String::formatted("%d|%d|%03d", bar, beat, ticks);
}
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Test2AudioProcessorEditor)
};