From b2c59ca533237503ba23dfcf34372515f7ab926b Mon Sep 17 00:00:00 2001 From: bsp2 Date: Fri, 13 Jul 2018 21:03:48 +0200 Subject: [PATCH] clean up --- .../repos/Template_shared/src/MyModule.cpp | 137 ++++++++---------- .../repos/Template_shared/src/Template.cpp | 4 - 2 files changed, 61 insertions(+), 80 deletions(-) diff --git a/plugins/community/repos/Template_shared/src/MyModule.cpp b/plugins/community/repos/Template_shared/src/MyModule.cpp index fcf0b4f0..92889577 100644 --- a/plugins/community/repos/Template_shared/src/MyModule.cpp +++ b/plugins/community/repos/Template_shared/src/MyModule.cpp @@ -1,98 +1,83 @@ #include "Template.hpp" 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() { - // 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 { - 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::load(assetPlugin(plugin, "res/MyModule.svg")); - printf("xxx template_shared: SVG::load() OK\n"); - setPanel(svg); - printf("xxx template_shared: setPanel() OK\n"); - - addChild(Widget::create(Vec(RACK_GRID_WIDTH, 0))); - printf("xxx template_shared: 1 addChild() OK\n"); - addChild(Widget::create(Vec(box.size.x - 2 * RACK_GRID_WIDTH, 0))); - printf("xxx template_shared: 2 addChild() OK\n"); - addChild(Widget::create(Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH))); - printf("xxx template_shared: 3 addChild() OK\n"); - addChild(Widget::create(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(Vec(RACK_GRID_WIDTH, 0))); + addChild(Widget::create(Vec(box.size.x - 2 * RACK_GRID_WIDTH, 0))); + addChild(Widget::create(Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH))); + addChild(Widget::create(Vec(box.size.x - 2 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH))); - addParam(ParamWidget::create(Vec(28, 87), module, MyModule::PITCH_PARAM, -3.0, 3.0, 0.0)); - printf("xxx template_shared: addParam() OK\n"); + addParam(ParamWidget::create(Vec(28, 87), module, MyModule::PITCH_PARAM, -3.0, 3.0, 0.0)); - addInput(Port::create(Vec(33, 186), Port::INPUT, module, MyModule::PITCH_INPUT)); - printf("xxx template_shared: addInput() OK\n"); + addInput(Port::create(Vec(33, 186), Port::INPUT, module, MyModule::PITCH_INPUT)); - addOutput(Port::create(Vec(33, 275), Port::OUTPUT, module, MyModule::SINE_OUTPUT)); - printf("xxx template_shared: addOutput() OK\n"); + addOutput(Port::create(Vec(33, 275), Port::OUTPUT, module, MyModule::SINE_OUTPUT)); - addChild(ModuleLightWidget::create>(Vec(41, 59), module, MyModule::BLINK_LIGHT)); - printf("xxx template_shared: addChild() OK\n"); - } + addChild(ModuleLightWidget::create>(Vec(41, 59), module, MyModule::BLINK_LIGHT)); + } }; // Specify the Module and ModuleWidget subclass, human-readable diff --git a/plugins/community/repos/Template_shared/src/Template.cpp b/plugins/community/repos/Template_shared/src/Template.cpp index d1eb9933..4c24729a 100644 --- a/plugins/community/repos/Template_shared/src/Template.cpp +++ b/plugins/community/repos/Template_shared/src/Template.cpp @@ -1,6 +1,5 @@ #include #include "Template.hpp" -// extern "C" extern int glfwInit(void); RACK_PLUGIN_MODEL_DECLARE(Template_shared, MyModule); @@ -16,7 +15,4 @@ RACK_PLUGIN_INIT(Template_shared) { // 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. printf("hello from Template_shared plugin!\n"); - - // glfwInit(); - }