LoginSignup
15
13

More than 5 years have passed since last update.

JUCEでVSTプラグインを作るときにGUIを実装するのが面倒な時に役立つTips

Last updated at Posted at 2018-10-30

はじめに

JUCEは、C++言語によるマルチメディア系アプリケーションの開発を支援するフレームワークです。JUCEはオーディオやMIDIを扱うアプリケーションに特化したAPI群が整備されているため、簡単に楽器アプリケーションを実装することができます。
JUCEにはオーディオプラグインを開発するためのテンプレートが充実しています。VST/AudioUnit/AAX/RTASプラグインといった、DTMで広く使われている主要なオーディオプラグインをビルドすることができます。

オーディオプラグインを構成するクラス

JUCEでは、プロジェクト作成時に2つのクラスによってオーディオプラグイン(VSTプラグイン)が構成されます。

  • xxxAudioProcessorクラス...オーディオプラグインのインターフェース
  • xxxAudioProcessorEditorクラス...オーディオプラグインのGUIを定義するクラス

GUIの実装が面倒な時ってありますよね?

下の図は私が実際に作成したプラグイン・シンセサイザーです。パラメーターが20個以上あるので、GUIの実装もそれなりに時間を費やしました。
でも、例えばプロトタイプ段階での開発であったり、特定のアルゴリズムをテストする目的であれば、GUIに凝る必要が無いのが実際の所だと思います。

SimpleSynth.PNG

汎用的なGUIを表示する機能を利用する

JUCEライブラリには、汎用的なGUIを生成してくれるGenericAudioProcessorEditorクラスが提供されています。以下に、その使い方を簡単に示します。
※APIリファレンス https://docs.juce.com/master/classGenericAudioProcessorEditor.html

パラメータを追加する

プロセッサー側のクラス(xxxAudioProcessorクラス)にパラメータを追加する処理を実装します。



// コンストラクタ
xxxAudioProcessor::xxxAudioProcessor()
#ifndef JucePlugin_PreferredChannelConfigurations
     : AudioProcessor (BusesProperties()
                     #if ! JucePlugin_IsMidiEffect
                      #if ! JucePlugin_IsSynth
                       .withInput  ("Input",  AudioChannelSet::stereo(), true)
                      #endif
                       .withOutput ("Output", AudioChannelSet::stereo(), true)
                     #endif
                       )
#endif
{
    AudioParameterFloat* parameter1 = new AudioParameterFloat("PARAMETER_1", "PARAMETER_1", -36.f, 6.f, -3.0f);
    AudioParameterInt* parameter2 = new AudioParameterInt("PARAMETER_2", "PARAMETER_2", 1, 128, 8);
    AudioParameterBool* parameter3 = new AudioParameterBool("PARAMETER_3", "PARAMETER_3", true);

    addParameter(parameter1);
    addParameter(parameter2);
    addParameter(parameter3);
}

xxxAudioProcessor::createEditor関数の返り値を変更する

AudioProcessorEditor* xxxAudioProcessor::createEditor()
{
    return new xxxAudioProcessorEditor (*this);
}

↓ GenericAudioProcessorEditorクラスのインスタンスを返すように変更する

AudioProcessorEditor* xxxAudioProcessor::createEditor()
{
    return new GenericAudioProcessorEditor(this);
}

GUIにパラメータ操作用のコンポーネントが自動で配置される

上記の実装を加えてビルドすると、このように、GUIにパラメータ操作用のコンポーネントが自動で配置されます。
Generic.PNG

15
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
13