From f58d61261e43839a9c5d3faaed88ba17ad805216 Mon Sep 17 00:00:00 2001 From: Sergey Ukolov Date: Sun, 31 Oct 2021 17:41:54 +0300 Subject: [PATCH] Added the Bar Phase output. --- plugins/Cardinal/src/HostTime.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/plugins/Cardinal/src/HostTime.cpp b/plugins/Cardinal/src/HostTime.cpp index 0077cfa..fbd7416 100644 --- a/plugins/Cardinal/src/HostTime.cpp +++ b/plugins/Cardinal/src/HostTime.cpp @@ -30,7 +30,8 @@ struct HostTime : Module { kHostTimeBar, kHostTimeBeat, kHostTimeClock, - kHostTimePhase, + kHostTimeBarPhase, + kHostTimeBeatPhase, kHostTimeCount }; @@ -94,21 +95,24 @@ struct HostTime : Module { const bool hasBar = pulseBar.process(args.sampleTime); const bool hasBeat = pulseBeat.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[kHostTimeReset].setBrightnessSmooth(hasReset ? 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[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[kHostTimeReset].setVoltage(hasReset ? 10.0f : 0.0f); outputs[kHostTimeBar].setVoltage(hasBar ? 10.0f : 0.0f); outputs[kHostTimeBeat].setVoltage(hasBeat ? 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(Vec(startX, startY + 2 * padding), module, HostTime::kHostTimeBar)); addOutput(createOutput(Vec(startX, startY + 3 * padding), module, HostTime::kHostTimeBeat)); addOutput(createOutput(Vec(startX, startY + 4 * padding), module, HostTime::kHostTimeClock)); - addOutput(createOutput(Vec(startX, startY + 5 * padding), module, HostTime::kHostTimePhase)); + addOutput(createOutput(Vec(startX, startY + 5 * padding), module, HostTime::kHostTimeBarPhase)); + addOutput(createOutput(Vec(startX, startY + 6 * padding), module, HostTime::kHostTimeBeatPhase)); const float x = startX + 28; addChild(createLightCentered> (Vec(x, startY + 0 * padding + 12), module, HostTime::kHostTimeRolling)); @@ -141,7 +146,8 @@ struct HostTimeWidget : ModuleWidget { addChild(createLightCentered> (Vec(x, startY + 2 * padding + 12), module, HostTime::kHostTimeBar)); addChild(createLightCentered>(Vec(x, startY + 3 * padding + 12), module, HostTime::kHostTimeBeat)); addChild(createLightCentered>(Vec(x, startY + 4 * padding + 12), module, HostTime::kHostTimeClock)); - addChild(createLightCentered>(Vec(x, startY + 5 * padding + 12), module, HostTime::kHostTimePhase)); + addChild(createLightCentered>(Vec(x, startY + 5 * padding + 12), module, HostTime::kHostTimeBarPhase)); + addChild(createLightCentered>(Vec(x, startY + 6 * padding + 12), module, HostTime::kHostTimeBeatPhase)); } 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, 3, "Beat"); 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); }