1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-29 02:40:05 +00:00

Misc code cleanups

This commit is contained in:
jules 2017-06-07 10:13:38 +01:00
parent 82f3ab616a
commit ebe5916c49
6 changed files with 77 additions and 109 deletions

View file

@ -47,8 +47,6 @@ class SineWaveVoice : public SynthesiserVoice
{
public:
SineWaveVoice()
: angleDelta (0.0),
tailOff (0.0)
{
}
@ -112,7 +110,6 @@ public:
}
private:
template <typename FloatType>
void processBlock (AudioBuffer<FloatType>& outputBuffer, int startSample, int numSamples)
{
@ -122,8 +119,7 @@ private:
{
while (--numSamples >= 0)
{
const FloatType currentSample =
static_cast<FloatType> (std::sin (currentAngle) * level * tailOff);
auto currentSample = static_cast<FloatType> (std::sin (currentAngle) * level * tailOff);
for (int i = outputBuffer.getNumChannels(); --i >= 0;)
outputBuffer.addSample (i, startSample, currentSample);
@ -146,7 +142,7 @@ private:
{
while (--numSamples >= 0)
{
const FloatType currentSample = static_cast<FloatType> (std::sin (currentAngle) * level);
auto currentSample = static_cast<FloatType> (std::sin (currentAngle) * level);
for (int i = outputBuffer.getNumChannels(); --i >= 0;)
outputBuffer.addSample (i, startSample, currentSample);
@ -158,17 +154,12 @@ private:
}
}
double currentAngle, angleDelta, level, tailOff;
double currentAngle = 0, angleDelta = 0, level = 0, tailOff = 0;
};
//==============================================================================
JuceDemoPluginAudioProcessor::JuceDemoPluginAudioProcessor()
: AudioProcessor (getBusesProperties()),
lastUIWidth (400),
lastUIHeight (200),
gainParam (nullptr),
delayParam (nullptr),
delayPosition (0)
: AudioProcessor (getBusesProperties())
{
lastPosInfo.resetToDefault();
@ -208,10 +199,12 @@ bool JuceDemoPluginAudioProcessor::isBusesLayoutSupported (const BusesLayout& la
return false;
// do not allow disabling the main buses
if (mainOutput.isDisabled()) return false;
if (mainOutput.isDisabled())
return false;
// only allow stereo and mono
if (mainOutput.size() > 2) return false;
if (mainOutput.size() > 2)
return false;
return true;
}
@ -308,13 +301,13 @@ void JuceDemoPluginAudioProcessor::applyDelay (AudioBuffer<FloatType>& buffer, A
for (int channel = 0; channel < getTotalNumOutputChannels(); ++channel)
{
FloatType* const channelData = buffer.getWritePointer (channel);
FloatType* const delayData = delayBuffer.getWritePointer (jmin (channel, delayBuffer.getNumChannels() - 1));
auto channelData = buffer.getWritePointer (channel);
auto delayData = delayBuffer.getWritePointer (jmin (channel, delayBuffer.getNumChannels() - 1));
delayPos = delayPosition;
for (int i = 0; i < numSamples; ++i)
{
const FloatType in = channelData[i];
auto in = channelData[i];
channelData[i] += delayData[delayPos];
delayData[delayPos] = (delayData[delayPos] + in) * delayLevel;
@ -363,8 +356,8 @@ void JuceDemoPluginAudioProcessor::getStateInformation (MemoryBlock& destData)
xml.setAttribute ("uiHeight", lastUIHeight);
// Store the values of all our parameters, using their param ID as the XML attribute
for (int i = 0; i < getNumParameters(); ++i)
if (AudioProcessorParameterWithID* p = dynamic_cast<AudioProcessorParameterWithID*> (getParameters().getUnchecked(i)))
for (auto* param : getParameters())
if (auto* p = dynamic_cast<AudioProcessorParameterWithID*> (param))
xml.setAttribute (p->paramID, p->getValue());
// then use this helper function to stuff it into the binary blob and return it..
@ -389,8 +382,8 @@ void JuceDemoPluginAudioProcessor::setStateInformation (const void* data, int si
lastUIHeight = jmax (xmlState->getIntAttribute ("uiHeight", lastUIHeight), 200);
// Now reload our parameters..
for (int i = 0; i < getNumParameters(); ++i)
if (AudioProcessorParameterWithID* p = dynamic_cast<AudioProcessorParameterWithID*> (getParameters().getUnchecked(i)))
for (auto* param : getParameters())
if (auto* p = dynamic_cast<AudioProcessorParameterWithID*> (param))
p->setValue ((float) xmlState->getDoubleAttribute (p->paramID, p->getValue()));
}
}

View file

@ -98,11 +98,11 @@ public:
// these are used to persist the UI's size - the values are stored along with the
// filter's other parameters, and the UI component will update them when it gets
// resized.
int lastUIWidth, lastUIHeight;
int lastUIWidth = 400, lastUIHeight = 200;
// Our parameters
AudioParameterFloat* gainParam;
AudioParameterFloat* delayParam;
AudioParameterFloat* gainParam = nullptr;
AudioParameterFloat* delayParam = nullptr;
private:
//==============================================================================
@ -115,7 +115,8 @@ private:
AudioBuffer<float> delayBufferFloat;
AudioBuffer<double> delayBufferDouble;
int delayPosition;
int delayPosition = 0;
Synthesiser synth;

View file

@ -70,7 +70,7 @@ void PluginWindow::closeAllCurrentlyOpenWindows()
delete activePluginWindows.getUnchecked (i);
Component dummyModalComp;
dummyModalComp.enterModalState();
dummyModalComp.enterModalState (false);
MessageManager::getInstance()->runDispatchLoopUntil (50);
}
}
@ -79,10 +79,8 @@ void PluginWindow::closeAllCurrentlyOpenWindows()
struct ProcessorProgramPropertyComp : public PropertyComponent,
private AudioProcessorListener
{
public:
ProcessorProgramPropertyComp (const String& name, AudioProcessor& p)
: PropertyComponent (name),
owner (p)
: PropertyComponent (name), owner (p)
{
owner.addListener (this);
}
@ -142,22 +140,19 @@ struct ProgramAudioProcessorEditor : public AudioProcessorEditor
panel.setBounds (getLocalBounds());
}
private:
PropertyPanel panel;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ProgramAudioProcessorEditor)
};
//==============================================================================
PluginWindow* PluginWindow::getWindowFor (AudioProcessorGraph::Node* const node,
WindowFormatType type)
PluginWindow* PluginWindow::getWindowFor (AudioProcessorGraph::Node* node, WindowFormatType type)
{
jassert (node != nullptr);
for (int i = activePluginWindows.size(); --i >= 0;)
if (activePluginWindows.getUnchecked(i)->owner == node
&& activePluginWindows.getUnchecked(i)->type == type)
return activePluginWindows.getUnchecked(i);
for (auto* w : activePluginWindows)
if (w->owner == node && w->type == type)
return w;
auto* processor = node->getProcessor();
AudioProcessorEditor* ui = nullptr;
@ -223,8 +218,7 @@ struct PinComponent : public Component,
public SettableTooltipClient
{
PinComponent (FilterGraph& g, uint32 id, int i, bool isIn)
: graph (g), pluginID (id),
index (i), isInput (isIn)
: graph (g), pluginID (id), index (i), isInput (isIn)
{
if (auto node = graph.getNodeForId (pluginID))
{
@ -261,10 +255,9 @@ struct PinComponent : public Component,
Path p;
p.addEllipse (w * 0.25f, h * 0.25f, w * 0.5f, h * 0.5f);
p.addRectangle (w * 0.4f, isInput ? (0.5f * h) : 0.0f, w * 0.2f, h * 0.5f);
Colour colour = (index == FilterGraph::midiChannelNumber ? Colours::red : Colours::green);
auto colour = (index == FilterGraph::midiChannelNumber ? Colours::red : Colours::green);
g.setColour (colour.withRotatedHue (static_cast<float> (busIdx) / 5.0f));
g.fillPath (p);

View file

@ -321,7 +321,8 @@ void MainHostWindow::addPluginsToMenu (PopupMenu& m) const
int i = 0;
for (auto* t : internalTypes)
m.addItem (++i, t->name, graphEditor->graph->getNodeForName (t->name) == nullptr);
m.addItem (++i, t->name + " (" + t->pluginFormatName + ")",
graphEditor->graph->getNodeForName (t->name) == nullptr);
}
m.addSeparator();