What should I do?
mainWindow.reset (new MainWindow ("ProcessorEditor", new ProcessorEditor(audioProcessor), *this));
This code at line 32 of the Main.cpp file outputs the error Use of undeclared identifier ‘processor’.
And there is also an error “Allocating an object of abstract class type AudioProcessorClass”
I don’t know what to do Because I am new to C++.
How do I do?
I have the following files.
- KeyboardGUI.h
- KeyboardGUI.cpp
- OscComponent.h
- OscComponent.cpp
- WavetableOscillator.h
- Main.cpp
- PluginEditor.h
- PluginEditor.cpp
- PluginProcessor.h
//PluginEditor.h
#pragma once
#include "JuceHeader.h"
#include "OscComponent.h"
#include "KeyboardGUI.h"
#include "PluginProcessor.h"
class ProcessorEditor : public juce::AudioProcessorEditor
{
public:
ProcessorEditor (AudioProcessorClass& audioProcessor);
~ProcessorEditor() override;
private:
AudioProcessorClass& audioProcessor;
OscComponent osc1;
KeyboardGUI keyboardGUI;
};
//PluginEditor.cpp
#include <JuceHeader.h>
#include "PluginProcessor.h"
#include "PluginEditor.h"
#include "OscComponent.h"
ProcessorEditor::ProcessorEditor(AudioProcessorClass& processor):AudioProcessorEditor (&processor),audioProcessor (processor), osc1 (audioProcessor.audioProcessorValueTreeState, "OSC1"),keyboardGUI()
{
addAndMakeVisible(osc1);
addAndMakeVisible(keyboardGUI);
}
//PluginProcessor.h
#pragma once
#include <JuceHeader.h>
class AudioProcessorClass : public juce::AudioProcessor
{
public:
AudioProcessorClass();
~AudioProcessorClass() override;
juce::AudioProcessorValueTreeState audioProcessorValueTreeState;
};
//Main.cpp
#include <JuceHeader.h>
#include "PluginProcessor.h"
#include "PluginEditor.h"
class Application : public juce::JUCEApplication
{
public:
Application() = default;
const juce::String getApplicationName() override { return "ProcessorEditor"; }
const juce::String getApplicationVersion() override { return "1.0.0"; }
void initialise (const juce::String&) override
{
mainWindow.reset (new MainWindow ("ProcessorEditor", new ProcessorEditor(audioProcessor), *this));
}
void shutdown() override { mainWindow = nullptr; }
private:
class MainWindow : public juce::DocumentWindow
{
public:
MainWindow (const juce::String& name, juce::Component* c, JUCEApplication& a)
: DocumentWindow (name, juce::Desktop::getInstance().getDefaultLookAndFeel()
.findColour (ResizableWindow::backgroundColourId),
juce::DocumentWindow::allButtons),
app (a)
{
setUsingNativeTitleBar (true);
setContentOwned (c, true);
#if JUCE_ANDROID || JUCE_IOS
setFullScreen (true);
#else
setResizable (true, false);
setResizeLimits (300, 250, 10000, 10000);
centreWithSize (getWidth(), getHeight());
#endif
setVisible (true);
}
void closeButtonPressed() override
{
app.systemRequestedQuit();
}
private:
JUCEApplication& app;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainWindow)
};
std::unique_ptr<MainWindow> mainWindow;
};
START_JUCE_APPLICATION (Application)
//OscComponent.h
#pragma once
#include <JuceHeader.h>
#include "WavetableOscillator.h"
#include "KeyboardGUI.h"
class OscComponent : public juce::AudioAppComponent
{
public:
OscComponent(juce::AudioProcessorValueTreeState& audioProcessorValueTreeState,juce::String oscId);
~OscComponent() override;
void resized() override;
void createWavetable()//追加
{
audioBuffer.setSize (1, (int) NumSamples);
audioBuffer.clear();
auto* samples = audioBuffer.getWritePointer (0);
samples[NumSamples] = samples[0];
auto angleDelta = juce::MathConstants<double>::twoPi / (double) (NumSamples - 1);
auto currentAngle = 0.0;
for (unsigned int i = 0; i < NumSamples; ++i)
{
auto sample = std::sin (currentAngle); // [5]
samples[i] = (float) sample;
currentAngle += angleDelta;
}
};
void prepareToPlay (int, double sampleRate) override
{
auto numberOfOscillators = 2;
for (auto i = 0; i < numberOfOscillators; ++i)
{
auto* oscillator = new WavetableOscillator(audioBuffer);
auto midiNote = juce::Random::getSystemRandom().nextDouble() * 36.0 + 48.0; // [3]
auto frequency = 440.0 * pow (2.0, (midiNote - 69.0) / 12.0); // [4]
oscillator->setFrequency ((float) frequency, (float) sampleRate); // [5]
oscillators.add(oscillator);
}
level = 0.25f / (float) numberOfOscillators; // [6]
};
void releaseResources() override {};
void getNextAudioBlock (const juce::AudioSourceChannelInfo& bufferToFill) override
{
auto* leftBuffer = bufferToFill.buffer->getWritePointer (0, bufferToFill.startSample); // [7]
auto* rightBuffer = bufferToFill.buffer->getWritePointer (1, bufferToFill.startSample);
bufferToFill.clearActiveBufferRegion();
for (auto oscillatorIndex = 0; oscillatorIndex < oscillators.size(); ++oscillatorIndex)
{
auto* oscillator = oscillators.getUnchecked (oscillatorIndex); // [8]
for (auto sample = 0; sample < bufferToFill.numSamples; ++sample)
{
auto levelSample = oscillator->getNextSample() * level; // [9]
leftBuffer[sample] += levelSample; // [10]
rightBuffer[sample] += levelSample;
}
}
}
private:
juce::ComboBox ComboBox;
juce::Label ComboBoxLabel { "Wave Type", "Wave Type" };
std::unique_ptr<juce::AudioProcessorValueTreeState::ComboBoxAttachment> ComboBoxAttachment;
const unsigned int NumSamples= 1 << 7;
float level = 0.0f;
juce::AudioSampleBuffer audioBuffer;
juce::OwnedArray<WavetableOscillator> oscillators;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OscComponent)
};
//OscComponent.cpp
#include <JuceHeader.h>
#include "OscComponent.h"
OscComponent::OscComponent(juce::AudioProcessorValueTreeState& audioProcessorValueTreeState,juce::String oscId)
{
juce::StringArray choices { "Sine", "Saw", "Square" ,"triangle"};
ComboBox.addItemList (choices, 1);
ComboBox.setSelectedItemIndex (0);
addAndMakeVisible (ComboBox);
ComboBoxAttachment = std::make_unique<juce::AudioProcessorValueTreeState::ComboBoxAttachment>(audioProcessorValueTreeState, ComboBox);
ComboBoxLabel.setJustificationType (juce::Justification::left);
addAndMakeVisible (ComboBoxLabel);
ComboBox.setColour(ComboBox::backgroundColourId, Colours::red);
ComboBoxLabel.setColour(Label::textColourId, Colours::red);
setSize (400, 50);
};
OscComponent::~OscComponent()
{
shutdownAudio();
};
void OscComponent::resized()
{
const auto labelHeight = 20;
ComboBoxLabel.setBounds (0, 0, 90, labelHeight);
ComboBox.setBounds (0, 20, 90, 30);
}
midiKeyboardState(),keyboardComponent(midiKeyboardState, juce::MidiKeyboardComponent::horizontalKeyboard)
void createWavetable()
{
};
//KeyboardGUI.h
#pragma once
#include <JuceHeader.h>
class KeyboardGUI : public juce::Component, juce::MidiKeyboardState::Listener
{
public:
KeyboardGUI();
~KeyboardGUI() override;
void resized() override;
void handleNoteOn(juce::MidiKeyboardState*, int midiChannel, int midiNoteNumber, float velocity) override {}
void handleNoteOff(juce::MidiKeyboardState*, int midiChannel, int midiNoteNumber, float velocity) override {}
private:
void timerCallback();
juce::MidiKeyboardState midiKeyboardState;
juce::MidiKeyboardComponent keyboardComponent;
};
//KeyboardGUI.cpp
#include <JuceHeader.h>
#include "KeyboardGUI.h"
#include "OscComponent.h"
KeyboardGUI::KeyboardGUI(): midiKeyboardState(),keyboardComponent(midiKeyboardState, juce::MidiKeyboardComponent::horizontalKeyboard)
{
midiKeyboardState.addListener(this);
addAndMakeVisible(keyboardComponent);
};
KeyboardGUI::~KeyboardGUI()
{
};
void KeyboardGUI::resized()
{
keyboardComponent.setBounds(getLocalBounds());
};
//WavetableOscillator.h
#pragma once
#include <JuceHeader.h>
class WavetableOscillator
{
public:
WavetableOscillator (const juce::AudioSampleBuffer& wavetableToUse)
: wavetable (wavetableToUse),
tableSize (wavetable.getNumSamples() - 1)
{
juce::Logger::outputDebugString("WavetableOscillator.h");
jassert (wavetable.getNumChannels() == 0);
};
void setFrequency (float frequency, float sampleRate)
{
auto tableSizeOverSampleRate = (float) wavetable.getNumSamples() / sampleRate;
tableDelta = frequency * tableSizeOverSampleRate;
}
forcedinline float getNextSample() noexcept
{
auto tableSize = (unsigned int) wavetable.getNumSamples();
auto index0 = (unsigned int) currentIndex; // [6]
auto index1 = index0 == (tableSize - 1) ? (unsigned int) 0 : index0 + 1;
auto frac = currentIndex - (float) index0; // [7]
auto* table = wavetable.getReadPointer (0); // [8]
auto value0 = table[index0];
auto value1 = table[index1];
auto currentSample = value0 + frac * (value1 - value0); // [9]
if ((currentIndex += tableDelta) > (float) tableSize) // [10]
currentIndex -= (float) tableSize;
return currentSample;
}
private:
const juce::AudioSampleBuffer& wavetable;
const int tableSize;
float currentIndex = 0.0f, tableDelta = 0.0f;
};