Browse Source

Added the Bar Phase output.

tags/22.02
Sergey Ukolov Filipe Coelho <falktx@falktx.com> 3 years ago
parent
commit
f58d61261e
1 changed files with 16 additions and 7 deletions
  1. +16
    -7
      plugins/Cardinal/src/HostTime.cpp

+ 16
- 7
plugins/Cardinal/src/HostTime.cpp View File

@@ -30,7 +30,8 @@ struct HostTime : Module {
kHostTimeBar, kHostTimeBar,
kHostTimeBeat, kHostTimeBeat,
kHostTimeClock, kHostTimeClock,
kHostTimePhase,
kHostTimeBarPhase,
kHostTimeBeatPhase,
kHostTimeCount kHostTimeCount
}; };


@@ -94,21 +95,24 @@ struct HostTime : Module {
const bool hasBar = pulseBar.process(args.sampleTime); const bool hasBar = pulseBar.process(args.sampleTime);
const bool hasBeat = pulseBeat.process(args.sampleTime); const bool hasBeat = pulseBeat.process(args.sampleTime);
const bool hasClock = pulseClock.process(args.sampleTime); const bool hasClock = pulseClock.process(args.sampleTime);
const float phase = pcontext->ticksPerBeat > 0.0 ? pcontext->tick / pcontext->ticksPerBeat : 0.0;
const float beatPhase = pcontext->ticksPerBeat > 0.0 ? pcontext->tick / pcontext->ticksPerBeat : 0.0;
const float barPhase = pcontext->beatsPerBar > 0 ? ((float) (pcontext->beat - 1) + beatPhase) / pcontext->beatsPerBar : 0.0;


lights[kHostTimeRolling].setBrightness(playing ? 1.0f : 0.0f); lights[kHostTimeRolling].setBrightness(playing ? 1.0f : 0.0f);
lights[kHostTimeReset].setBrightnessSmooth(hasReset ? 1.0f : 0.0f, args.sampleTime * 0.5f); lights[kHostTimeReset].setBrightnessSmooth(hasReset ? 1.0f : 0.0f, args.sampleTime * 0.5f);
lights[kHostTimeBar].setBrightnessSmooth(hasBar ? 1.0f : 0.0f, args.sampleTime * 0.5f); lights[kHostTimeBar].setBrightnessSmooth(hasBar ? 1.0f : 0.0f, args.sampleTime * 0.5f);
lights[kHostTimeBeat].setBrightnessSmooth(hasBeat ? 1.0f : 0.0f, args.sampleTime); lights[kHostTimeBeat].setBrightnessSmooth(hasBeat ? 1.0f : 0.0f, args.sampleTime);
lights[kHostTimeClock].setBrightnessSmooth(hasClock ? 1.0f : 0.0f, args.sampleTime * 2.0f); lights[kHostTimeClock].setBrightnessSmooth(hasClock ? 1.0f : 0.0f, args.sampleTime * 2.0f);
lights[kHostTimePhase].setBrightness(phase);
lights[kHostTimeBarPhase].setBrightness(barPhase);
lights[kHostTimeBeatPhase].setBrightness(beatPhase);


outputs[kHostTimeRolling].setVoltage(playing ? 10.0f : 0.0f); outputs[kHostTimeRolling].setVoltage(playing ? 10.0f : 0.0f);
outputs[kHostTimeReset].setVoltage(hasReset ? 10.0f : 0.0f); outputs[kHostTimeReset].setVoltage(hasReset ? 10.0f : 0.0f);
outputs[kHostTimeBar].setVoltage(hasBar ? 10.0f : 0.0f); outputs[kHostTimeBar].setVoltage(hasBar ? 10.0f : 0.0f);
outputs[kHostTimeBeat].setVoltage(hasBeat ? 10.0f : 0.0f); outputs[kHostTimeBeat].setVoltage(hasBeat ? 10.0f : 0.0f);
outputs[kHostTimeClock].setVoltage(hasClock ? 10.0f : 0.0f); outputs[kHostTimeClock].setVoltage(hasClock ? 10.0f : 0.0f);
outputs[kHostTimePhase].setVoltage(phase * 10.0f);
outputs[kHostTimeBarPhase].setVoltage(barPhase * 10.0f);
outputs[kHostTimeBeatPhase].setVoltage(beatPhase * 10.0f);
} }
} }
}; };
@@ -133,7 +137,8 @@ struct HostTimeWidget : ModuleWidget {
addOutput(createOutput<PJ301MPort>(Vec(startX, startY + 2 * padding), module, HostTime::kHostTimeBar)); addOutput(createOutput<PJ301MPort>(Vec(startX, startY + 2 * padding), module, HostTime::kHostTimeBar));
addOutput(createOutput<PJ301MPort>(Vec(startX, startY + 3 * padding), module, HostTime::kHostTimeBeat)); addOutput(createOutput<PJ301MPort>(Vec(startX, startY + 3 * padding), module, HostTime::kHostTimeBeat));
addOutput(createOutput<PJ301MPort>(Vec(startX, startY + 4 * padding), module, HostTime::kHostTimeClock)); addOutput(createOutput<PJ301MPort>(Vec(startX, startY + 4 * padding), module, HostTime::kHostTimeClock));
addOutput(createOutput<PJ301MPort>(Vec(startX, startY + 5 * padding), module, HostTime::kHostTimePhase));
addOutput(createOutput<PJ301MPort>(Vec(startX, startY + 5 * padding), module, HostTime::kHostTimeBarPhase));
addOutput(createOutput<PJ301MPort>(Vec(startX, startY + 6 * padding), module, HostTime::kHostTimeBeatPhase));


const float x = startX + 28; const float x = startX + 28;
addChild(createLightCentered<SmallLight<GreenLight>> (Vec(x, startY + 0 * padding + 12), module, HostTime::kHostTimeRolling)); addChild(createLightCentered<SmallLight<GreenLight>> (Vec(x, startY + 0 * padding + 12), module, HostTime::kHostTimeRolling));
@@ -141,7 +146,8 @@ struct HostTimeWidget : ModuleWidget {
addChild(createLightCentered<SmallLight<RedLight>> (Vec(x, startY + 2 * padding + 12), module, HostTime::kHostTimeBar)); addChild(createLightCentered<SmallLight<RedLight>> (Vec(x, startY + 2 * padding + 12), module, HostTime::kHostTimeBar));
addChild(createLightCentered<SmallLight<YellowLight>>(Vec(x, startY + 3 * padding + 12), module, HostTime::kHostTimeBeat)); addChild(createLightCentered<SmallLight<YellowLight>>(Vec(x, startY + 3 * padding + 12), module, HostTime::kHostTimeBeat));
addChild(createLightCentered<SmallLight<YellowLight>>(Vec(x, startY + 4 * padding + 12), module, HostTime::kHostTimeClock)); addChild(createLightCentered<SmallLight<YellowLight>>(Vec(x, startY + 4 * padding + 12), module, HostTime::kHostTimeClock));
addChild(createLightCentered<SmallLight<YellowLight>>(Vec(x, startY + 5 * padding + 12), module, HostTime::kHostTimePhase));
addChild(createLightCentered<SmallLight<YellowLight>>(Vec(x, startY + 5 * padding + 12), module, HostTime::kHostTimeBarPhase));
addChild(createLightCentered<SmallLight<YellowLight>>(Vec(x, startY + 6 * padding + 12), module, HostTime::kHostTimeBeatPhase));
} }


void drawOutputLine(NVGcontext* const vg, const uint offset, const char* const text) void drawOutputLine(NVGcontext* const vg, const uint offset, const char* const text)
@@ -174,7 +180,10 @@ struct HostTimeWidget : ModuleWidget {
drawOutputLine(args.vg, 2, "Bar"); drawOutputLine(args.vg, 2, "Bar");
drawOutputLine(args.vg, 3, "Beat"); drawOutputLine(args.vg, 3, "Beat");
drawOutputLine(args.vg, 4, "Clock"); drawOutputLine(args.vg, 4, "Clock");
drawOutputLine(args.vg, 5, "Phase");

nvgFontSize(args.vg, 11);
drawOutputLine(args.vg, 5, "Bar Phase");
drawOutputLine(args.vg, 6, "Beat Phase");


ModuleWidget::draw(args); ModuleWidget::draw(args);
} }


Loading…
Cancel
Save