JUCE框架教程(5)——Plugin项目构造基础

发布于:2023-01-04 ⋅ 阅读:(410) ⋅ 点赞:(0)

JUCE框架教程(5)——Plugin项目构造基础

如何创建一个plguin工程
打开Projucer,新建一个工程,选择plug-in。这一次我们取名为pluginDemo
在这里插入图片描述
可以看到,JUCE为我们建立了四个文件:
PluginProcessor.cpp
PluginProcessor.h
PluginEditor.cpp
PluginEditor.h

总的来说,PluginProcessor就是我们实际操作数据,实现运算的地方,而PluginEditor相当于UI界面。
PluginProcessor.cpp

PlguinDemoAudioProcessor::PlguinDemoAudioProcessor()
#ifndef JucePlugin_PreferredChannelConfigurations
     : AudioProcessor (BusesProperties()
                     #if ! JucePlugin_IsMidiEffect
                      #if ! JucePlugin_IsSynth
                       .withInput  ("Input",  juce::AudioChannelSet::stereo(), true)
                      #endif
                       .withOutput ("Output", juce::AudioChannelSet::stereo(), true)
                     #endif
                       )
#endif
{
}

构造函数,我们创建的input,output或者是data都要在这里构建。

void PlguinDemoAudioProcessor::processBlock (juce::AudioBuffer<float>& buffer, juce::MidiBuffer& midiMessages)
{
    juce::ScopedNoDenormals noDenormals;
    auto totalNumInputChannels  = getTotalNumInputChannels();
    auto totalNumOutputChannels = getTotalNumOutputChannels();

    // In case we have more outputs than inputs, this code clears any output
    // channels that didn't contain input data, (because these aren't
    // guaranteed to be empty - they may contain garbage).
    // This is here to avoid people getting screaming feedback
    // when they first compile a plugin, but obviously you don't need to keep
    // this code if your algorithm always overwrites all the output channels.
    for (auto i = totalNumInputChannels; i < totalNumOutputChannels; ++i)
        buffer.clear (i, 0, buffer.getNumSamples());

    // This is the place where you'd normally do the guts of your plugin's
    // audio processing...
    // Make sure to reset the state if your inner loop is processing
    // the samples and the outer loop is handling the channels.
    // Alternatively, you can process the samples with the channels
    // interleaved by keeping the same state.
    for (int channel = 0; channel < totalNumInputChannels; ++channel)
    {
        auto* channelData = buffer.getWritePointer (channel);

        // ..do something to the data...
    }
}

项目进行处理的模块,我们大多数的操作都要在这里完成。
PluginEditor.cpp

PlguinDemoAudioProcessorEditor::PlguinDemoAudioProcessorEditor (PlguinDemoAudioProcessor& p)
    : AudioProcessorEditor (&p), audioProcessor (p)
{
    setSize (400, 300);
}

PlguinDemoAudioProcessorEditor::~PlguinDemoAudioProcessorEditor()
{
}

//==============================================================================
void PlguinDemoAudioProcessorEditor::paint (juce::Graphics& g)
{
    // (Our component is opaque, so we must completely fill the background with a solid colour)
    g.fillAll (getLookAndFeel().findColour (juce::ResizableWindow::backgroundColourId));

    g.setColour (juce::Colours::white);
    g.setFont (15.0f);
    g.drawFittedText ("Hello World!", getLocalBounds(), juce::Justification::centred, 1);
}

void PlguinDemoAudioProcessorEditor::resized()
{
    // This is generally where you'll want to lay out the positions of any
    // subcomponents in your editor..
}

如果熟悉GUI的同学应该很快就能明白,PlguinEditor其实和GUI的文件是完全一致的。我们通过构造函数设置大小,paint函数进行颜色等处理,resize函数编辑子组件。

以上就是Plug-in工程的大致结构解析。

本文含有隐藏内容,请 开通VIP 后查看