|
|
@@ -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 |
|
|
|