martin-lueders / ML_modules

free modules for VCV Rack
BSD 3-Clause "New" or "Revised" License
90 stars 18 forks source link

Building an own Plugin #40

Closed ATGC2 closed 6 years ago

ATGC2 commented 6 years ago

Hello Mr. Lueders,

could You help me please, to build my own Plugin? The Plugin should be an Voltage Generator, it consist in a Regulator from -12V to +12V with your Volt Display. The Code is as shown below:


include "Logical.hpp"

include "dsp/digital.hpp"

include

include

//------------------------------ struct VoltGenerator : Module { enum ParamIds { VOLT_PARAM, NUM_PARAMS }; enum OutputIds { VOLT_OUTPUT, NUM_OUTPUTS }; enum LightIds { BLINK_LIGHT, NUM_LIGHTS };

float phase = 0.0;
float blinkPhase = 0.0;

VoltGenerator() : Module(NUM_PARAMS, NUM_OUTPUTS, NUM_LIGHTS) { volts = 0.0f; };

void step() override;
float volts;

}; //------------------------------ void VoltGenerator::step() { float v = params[VOLT_PARAM].value; outputs[VOLT_OUTPUT].value = v; lights[BLINK_LIGHT].value = fabs(v)/12.0; volts = 0.9 * volts + 0.1; } //------------------------------ struct VoltDisplayWidget : TransparentWidget {

float  *value;
bool *on;

std::shared_ptr<Font> font;

VoltDisplayWidget() {
    font = Font::load(assetPlugin(plugin, "res/Segment7Standard.ttf"));
};

void draw(NVGcontext *vg) {
    NVGcolor backgroundColor = nvgRGB(0x20, 0x20, 0x20);
    NVGcolor borderColor = nvgRGB(0x10, 0x10, 0x10);
    nvgBeginPath(vg);
    nvgRoundedRect(vg, 0.0, 0.0, box.size.x, box.size.y, 4.0);
    nvgFillColor(vg, backgroundColor);
    nvgFill(vg);
    nvgStrokeWidth(vg, 1.0);
    nvgStrokeColor(vg, borderColor);
    nvgStroke(vg);

    nvgFontSize(vg, 18);
    nvgFontFaceId(vg, font->handle);
    nvgTextLetterSpacing(vg, 2.5);

    char display_string[10];

    sprintf(display_string,"%6.2f",*value);

    Vec textPos = Vec(6.0f, 17.0f);

    NVGcolor textColor = nvgRGB(0xdf, 0xd2, 0x2c);
    nvgFillColor(vg, nvgTransRGBA(textColor, 16));
    nvgText(vg, textPos.x, textPos.y, "~~~~~~", NULL);

    textColor = nvgRGB(0xda, 0xe9, 0x29);
    nvgFillColor(vg, nvgTransRGBA(textColor, 16));
    nvgText(vg, textPos.x, textPos.y, "\\\\\\\\\\\\", NULL);

    if(*on) {
        textColor = nvgRGB(0xf0, 0x00, 0x00);
        nvgFillColor(vg, textColor);
        nvgText(vg, textPos.x, textPos.y, display_string, NULL);
    };
}

struct VoltDisplayWidget::VoltGeneratorWidget {
    VoltGeneratorWidget(VoltGenerator *module);
    TextField ** label;
};

VoltGeneratorWidget::VoltGenerator(VoltGenerator *module) : ModuleWidget(module) {

box.size = Vec(15*8, 380);

{
    SVGPanel *panel = new SVGPanel();
    panel->box.size = box.size;
    panel->setBackground(SVG::load(assetPlugin(plugin,"res/VoltGenerator.svg")));
    addChild(panel);
}

const float delta_y = 70;

addChild(Widget::create<ScrewSilver>(Vec(15, 0)));
addChild(Widget::create<ScrewSilver>(Vec(15, 365)));

    VoltDisplayWidget *display = new VoltDisplayWidget();
    display->box.pos = Vec(10,90+delta_y);
    display->box.size = Vec(100, 20);
    display->value = &module->volts;
    addChild(display);

}

};

Model *modelVoltGenerator = Model::create<VoltGenerator, VoltGeneratorWidget>("Logical", "VoltGenerator", "VoltGenerator", LOGICTAG);


The Compiler Error:


c++ -std=c++11 -stdlib=libc++ -DSLUG=VoltGenerator -fPIC -I../../include -I../../dep/include -DVERSION=0.6.0 -MMD -MP -g -O3 -march=nocona -ffast-math -fno-finite-math-only -Wall -Wextra -Wno-unused-parameter -DARCH_MAC -mmacosx-version-min=10.7 -c -o build/src/VoltGenerator.cpp.o src/VoltGenerator.cpp src/VoltGenerator.cpp:83:31: error: no struct named 'VoltGeneratorWidget' in 'VoltDisplayWidget' struct VoltDisplayWidget::VoltGeneratorWidget {


src/VoltGenerator.cpp:83:31: error: extra qualification on member
      'VoltGeneratorWidget'
    struct VoltDisplayWidget::VoltGeneratorWidget {
           ~~~~~~~~~~~~~~~~~~~^
src/VoltGenerator.cpp:88:5: error: use of undeclared identifier
      'VoltGeneratorWidget'; did you mean 'VoltGenerator'?
    VoltGeneratorWidget::VoltGenerator(VoltGenerator *module) : ModuleWi...
    ^~~~~~~~~~~~~~~~~~~
    VoltGenerator
src/VoltGenerator.cpp:6:8: note: 'VoltGenerator' declared here
struct VoltGenerator : Module {
       ^
src/VoltGenerator.cpp:88:26: error: non-friend class member 'VoltGenerator'
      cannot have a qualified name
    VoltGeneratorWidget::VoltGenerator(VoltGenerator *module) : ModuleWi...
    ~~~~~~~~~~~~~~~~~~~~~^
src/VoltGenerator.cpp:114:58: error: unknown type name 'VoltGeneratorWidget';
      did you mean 'VoltGenerator'?
Model *modelVoltGenerator = Model::create<VoltGenerator, VoltGeneratorWidget>(...
                                                         ^~~~~~~~~~~~~~~~~~~
                                                         VoltGenerator
src/VoltGenerator.cpp:6:8: note: 'VoltGenerator' declared here
struct VoltGenerator : Module {
       ^
In file included from src/VoltGenerator.cpp:1:
In file included from src/Logical.hpp:1:
In file included from ../../include/rack.hpp:5:
In file included from ../../include/asset.hpp:4:
../../include/plugin.hpp:78:39: error: no matching constructor for
      initialization of 'VoltGenerator'
  ...TModuleWidget *moduleWidget = new TModuleWidget(module);
                                       ^             ~~~~~~
../../include/plugin.hpp:71:10: note: in instantiation of member function
      'rack::Model::create(std::string, std::string, std::string,
      rack::ModelTag)::TModel::createModuleWidget' requested here
                struct TModel : Model {
                       ^
src/VoltGenerator.cpp:114:36: note: in instantiation of function template
      specialization 'rack::Model::create<VoltGenerator, VoltGenerator,
      rack::ModelTag>' requested here
Model *modelVoltGenerator = Model::create<VoltGenerator, VoltGeneratorWi...
                                   ^
src/VoltGenerator.cpp:6:8: note: candidate constructor (the implicit move
      constructor) not viable: no known conversion from 'VoltGenerator *' to
      'VoltGenerator' for 1st argument; dereference the argument with *
struct VoltGenerator : Module {
       ^
src/VoltGenerator.cpp:6:8: note: candidate constructor (the implicit copy
      constructor) not viable: no known conversion from 'VoltGenerator *' to
      'const VoltGenerator' for 1st argument; dereference the argument with *
struct VoltGenerator : Module {
       ^
src/VoltGenerator.cpp:23:5: note: candidate constructor not viable: requires 0
      arguments, but 1 was provided
    VoltGenerator() : Module(NUM_PARAMS, NUM_OUTPUTS, NUM_LIGHTS) { volt...
    ^
In file included from src/VoltGenerator.cpp:1:
In file included from src/Logical.hpp:1:
In file included from ../../include/rack.hpp:5:
In file included from ../../include/asset.hpp:4:
../../include/plugin.hpp:83:39: error: no matching constructor for
      initialization of 'VoltGenerator'
  ...TModuleWidget *moduleWidget = new TModuleWidget(NULL);
                                       ^             ~~~~
../../include/plugin.hpp:71:10: note: in instantiation of member function
      'rack::Model::create(std::string, std::string, std::string,
      rack::ModelTag)::TModel::createModuleWidgetNull' requested here
                struct TModel : Model {
                       ^
src/VoltGenerator.cpp:114:36: note: in instantiation of function template
      specialization 'rack::Model::create<VoltGenerator, VoltGenerator,
      rack::ModelTag>' requested here
Model *modelVoltGenerator = Model::create<VoltGenerator, VoltGeneratorWi...
                                   ^
src/VoltGenerator.cpp:6:8: note: candidate constructor (the implicit move
      constructor) not viable: no known conversion from 'long' to
      'VoltGenerator' for 1st argument
struct VoltGenerator : Module {
       ^
src/VoltGenerator.cpp:6:8: note: candidate constructor (the implicit copy
      constructor) not viable: no known conversion from 'long' to
      'const VoltGenerator' for 1st argument
src/VoltGenerator.cpp:23:5: note: candidate constructor not viable: requires 0
      arguments, but 1 was provided
    VoltGenerator() : Module(NUM_PARAMS, NUM_OUTPUTS, NUM_LIGHTS) { volt...
    ^
7 errors generated.
make: *** [build/src/VoltGenerator.cpp.o] Error 1
____________________________________________________________________________________________________________
ATGC2 commented 6 years ago

the 3th. include should mean : and the 4th. include should mean:

ATGC2 commented 6 years ago

thank You in Advance Mr. Lueders.

ATGC2 commented 6 years ago

ok, i try once again the 3th. include should mean : sstream and the 4th. include should mean: iomanip

martin-lueders commented 6 years ago

Hi,

Sorry that I did not reply before. I am currently very busy with work.

Looking at your code, I do see two immediate errors:

VoltGeneratorWidget::VoltGenerator(VoltGenerator *module) : ModuleWidget(module) { ...

should be

VoltGeneratorWidget::VoltGeneratorWidget(VoltGenerator *module) : ModuleWidget(module) { ...

give that a try and see whether it fixes the problems.

Cheers, Martin