LoginSignup
1
0

More than 3 years have passed since last update.

VCVのPlugin Development Tutorialを試してみた。

Last updated at Posted at 2021-02-23

VCVPlugin Development Tutorial をWindows10+MSYS2で試してみた。
 1. VCV RACK ver1.1.6をインストール。
 2. MSYS2は、msys2-x86_64-20210105を使用した。適当な場所に置く。
 3. 開発環境をpacmanを使って構築
   pacman -Syu
   pacman -Su git wget make tar unzip zip mingw-w64-x86_64-gcc mingw-w64-x86_64-gdb \
   mingw-w64-x86_64-cmake autoconf automake mingw-w64-x86_64-libtool mingw-w64-x86_64-jq python

 4. Rack-SDK-1.16を落とし、MSYS2の /home/user_name/Rack-SDK に展開。
 5. RACK_DIR=/home/user_name/Rack-SDK を設定する。
 6. $RACK_DIR/helper.py createplugin MyPlugin を実行し フォルダ MyPlugin が作られる。
 7. 質問を適当に答えていくと、plugin.jsonが作られる。
 8. Makefileも作られるので、一旦、makeでエラーなく終了することを確認する。
 9. ~/Rack-SDK/MyPlugin/resの元に、MyModule.svgを置く。
 10. cd ~/Rack-SDK
 10. $RACK_DIR/helper.py createmodule MyModule res/MyModule.svg src/MyModule.cpp を実行する。
 11. cd ~/Rack-SDK/src にMyModule.cppが作られる。
 12. MyModule.cpp plugin.cpp plugin.hpp を下記のように編集する。
 13. make
 14. make dist
 15. make install
 16. VCVを立ち上げると、MyPluginが認識される。
 17. 認識されない場合は、Help->Open user folder で開いた場所のlogを見て。
 
MyModule.cpp



    MyModule() {
        config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS);
        configParam(PITCH_PARAM, 0.f, 1.f, 0.f, "");
    }

    float phase = 0.f;
    float blinkPhase = 0.f;

    void process(const ProcessArgs& args) override {
        // Compute the frequency from the pitch parameter and input
        float pitch = params[PITCH_PARAM].getValue();
        pitch += inputs[PITCH_INPUT].getVoltage();
        pitch = clamp(pitch, -4.f, 4.f);
        // The default pitch is C4 = 261.6256f
        float freq = dsp::FREQ_C4 * std::pow(2.f, pitch);

        // Accumulate the phase
        phase += freq * args.sampleTime;
        if (phase >= 0.5f)
            phase -= 1.f;

        // Compute the sine output
        float sine = std::sin(2.f * M_PI * phase);
        // Audio signals are typically +/-5V
        // https://vcvrack.com/manual/VoltageStandards.html
        outputs[SINE_OUTPUT].setVoltage(5.f * sine);

        // Blink light at 1Hz
        blinkPhase += args.sampleTime;
        if (blinkPhase >= 1.f)
            blinkPhase -= 1.f;
        lights[BLINK_LIGHT].setBrightness(blinkPhase < 0.5f ? 1.f : 0.f);
    }
 };

plugin.cpp

#include "plugin.hpp"


Plugin* pluginInstance;


void init(Plugin* p) {
    pluginInstance = p;

    // Add modules here
    p->addModel(modelMyModule);

    // Any other plugin initialization may go here.
    // As an alternative, consider lazy-loading assets and lookup tables when your module is created to reduce startup times of Rack.
}     

plugin.hpp

#pragma once
#include <rack.hpp>


using namespace rack;

// Declare the Plugin, defined in plugin.cpp
extern Plugin* pluginInstance;

// Declare each Model, defined in each module source file
extern Model* modelMyModule;

1
0
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
1
0