Browse Source

clean up

pull/1639/head
bsp2 7 years ago
parent
commit
b2c59ca533
2 changed files with 61 additions and 80 deletions
  1. +61
    -76
      plugins/community/repos/Template_shared/src/MyModule.cpp
  2. +0
    -4
      plugins/community/repos/Template_shared/src/Template.cpp

+ 61
- 76
plugins/community/repos/Template_shared/src/MyModule.cpp View File

@@ -1,98 +1,83 @@
#include "Template.hpp" #include "Template.hpp"


struct MyModule : Module { struct MyModule : Module {
enum ParamIds {
PITCH_PARAM,
NUM_PARAMS
};
enum InputIds {
PITCH_INPUT,
NUM_INPUTS
};
enum OutputIds {
SINE_OUTPUT,
NUM_OUTPUTS
};
enum LightIds {
BLINK_LIGHT,
NUM_LIGHTS
};
float phase = 0.0f;
float blinkPhase = 0.0f;
MyModule() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {}
void step() override;
// For more advanced Module features, read Rack's engine.hpp header file
// - toJson, fromJson: serialization of internal data
// - onSampleRateChange: event triggered by a change of sample rate
// - onReset, onRandomize, onCreate, onDelete: implements special behavior when user clicks these from the context menu
enum ParamIds {
PITCH_PARAM,
NUM_PARAMS
};
enum InputIds {
PITCH_INPUT,
NUM_INPUTS
};
enum OutputIds {
SINE_OUTPUT,
NUM_OUTPUTS
};
enum LightIds {
BLINK_LIGHT,
NUM_LIGHTS
};
float phase = 0.0f;
float blinkPhase = 0.0f;
MyModule() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {}
void step() override;
// For more advanced Module features, read Rack's engine.hpp header file
// - toJson, fromJson: serialization of internal data
// - onSampleRateChange: event triggered by a change of sample rate
// - onReset, onRandomize, onCreate, onDelete: implements special behavior when user clicks these from the context menu
}; };




void MyModule::step() { void MyModule::step() {
// Implement a simple sine oscillator
float deltaTime = engineGetSampleTime();
// Compute the frequency from the pitch parameter and input
float pitch = params[PITCH_PARAM].value;
pitch += inputs[PITCH_INPUT].value;
pitch = clamp(pitch, -4.0f, 4.0f);
// The default pitch is C4
float freq = 261.626f * powf(2.0f, pitch);
// Accumulate the phase
phase += freq * deltaTime;
if (phase >= 1.0f)
phase -= 1.0f;
// Compute the sine output
float sine = sinf(float(2.0f * M_PI) * phase);
outputs[SINE_OUTPUT].value = 5.0f * sine;
// Blink light at 1Hz
blinkPhase += deltaTime;
if (blinkPhase >= 1.0f)
blinkPhase -= 1.0f;
lights[BLINK_LIGHT].value = (blinkPhase < 0.5f) ? 1.0f : 0.0f;
// Implement a simple sine oscillator
float deltaTime = engineGetSampleTime();
// Compute the frequency from the pitch parameter and input
float pitch = params[PITCH_PARAM].value;
pitch += inputs[PITCH_INPUT].value;
pitch = clamp(pitch, -4.0f, 4.0f);
// The default pitch is C4
float freq = 261.626f * powf(2.0f, pitch);
// Accumulate the phase
phase += freq * deltaTime;
if (phase >= 1.0f)
phase -= 1.0f;
// Compute the sine output
float sine = sinf(float(2.0f * M_PI) * phase);
outputs[SINE_OUTPUT].value = 5.0f * sine;
// Blink light at 1Hz
blinkPhase += deltaTime;
if (blinkPhase >= 1.0f)
blinkPhase -= 1.0f;
lights[BLINK_LIGHT].value = (blinkPhase < 0.5f) ? 1.0f : 0.0f;
} }




struct MyModuleWidget : ModuleWidget { struct MyModuleWidget : ModuleWidget {
MyModuleWidget(MyModule *module) : ModuleWidget(module) {
printf("xxx template_shared: global=%p\n", rack::global);
printf("xxx template_shared: global_ui=%p x\n", rack::global_ui);
printf("xxx template_shared: plugin=%p\n", plugin);
MyModuleWidget(MyModule *module) : ModuleWidget(module) {


std::shared_ptr<SVG> svg = SVG::load(assetPlugin(plugin, "res/MyModule.svg")); std::shared_ptr<SVG> svg = SVG::load(assetPlugin(plugin, "res/MyModule.svg"));
printf("xxx template_shared: SVG::load() OK\n");

setPanel(svg); setPanel(svg);


printf("xxx template_shared: setPanel() OK\n");

addChild(Widget::create<ScrewSilver>(Vec(RACK_GRID_WIDTH, 0)));
printf("xxx template_shared: 1 addChild() OK\n");
addChild(Widget::create<ScrewSilver>(Vec(box.size.x - 2 * RACK_GRID_WIDTH, 0)));
printf("xxx template_shared: 2 addChild() OK\n");
addChild(Widget::create<ScrewSilver>(Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
printf("xxx template_shared: 3 addChild() OK\n");
addChild(Widget::create<ScrewSilver>(Vec(box.size.x - 2 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
printf("xxx template_shared: 4 addChild() OK\n");
addChild(Widget::create<ScrewSilver>(Vec(RACK_GRID_WIDTH, 0)));
addChild(Widget::create<ScrewSilver>(Vec(box.size.x - 2 * RACK_GRID_WIDTH, 0)));
addChild(Widget::create<ScrewSilver>(Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
addChild(Widget::create<ScrewSilver>(Vec(box.size.x - 2 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));


addParam(ParamWidget::create<Davies1900hBlackKnob>(Vec(28, 87), module, MyModule::PITCH_PARAM, -3.0, 3.0, 0.0));
printf("xxx template_shared: addParam() OK\n");
addParam(ParamWidget::create<Davies1900hBlackKnob>(Vec(28, 87), module, MyModule::PITCH_PARAM, -3.0, 3.0, 0.0));


addInput(Port::create<PJ301MPort>(Vec(33, 186), Port::INPUT, module, MyModule::PITCH_INPUT));
printf("xxx template_shared: addInput() OK\n");
addInput(Port::create<PJ301MPort>(Vec(33, 186), Port::INPUT, module, MyModule::PITCH_INPUT));


addOutput(Port::create<PJ301MPort>(Vec(33, 275), Port::OUTPUT, module, MyModule::SINE_OUTPUT));
printf("xxx template_shared: addOutput() OK\n");
addOutput(Port::create<PJ301MPort>(Vec(33, 275), Port::OUTPUT, module, MyModule::SINE_OUTPUT));


addChild(ModuleLightWidget::create<MediumLight<RedLight>>(Vec(41, 59), module, MyModule::BLINK_LIGHT));
printf("xxx template_shared: addChild() OK\n");
}
addChild(ModuleLightWidget::create<MediumLight<RedLight>>(Vec(41, 59), module, MyModule::BLINK_LIGHT));
}
}; };


// Specify the Module and ModuleWidget subclass, human-readable // Specify the Module and ModuleWidget subclass, human-readable


+ 0
- 4
plugins/community/repos/Template_shared/src/Template.cpp View File

@@ -1,6 +1,5 @@
#include <stdio.h> #include <stdio.h>
#include "Template.hpp" #include "Template.hpp"
// extern "C" extern int glfwInit(void);


RACK_PLUGIN_MODEL_DECLARE(Template_shared, MyModule); RACK_PLUGIN_MODEL_DECLARE(Template_shared, MyModule);


@@ -16,7 +15,4 @@ RACK_PLUGIN_INIT(Template_shared) {
// Any other plugin initialization may go here. // 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. // As an alternative, consider lazy-loading assets and lookup tables when your module is created to reduce startup times of Rack.
printf("hello from Template_shared plugin!\n"); printf("hello from Template_shared plugin!\n");

// glfwInit();

} }

Loading…
Cancel
Save