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

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工程的大致结构解析。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值