@@ -40,11 +40,18 @@ struct HostTime : TerminalModule {
4040 kHostTimeCount
4141 };
4242
43+ enum BarDivisions {
44+ Bars1 = 1 ,
45+ Bars4 = 4 ,
46+ Bars8 = 8
47+ };
48+
4349 const CardinalPluginContext* const pcontext;
4450
4551 rack::dsp::PulseGenerator pulseReset, pulseBar, pulseBeat, pulseClock;
4652 float sampleTime = 0 .0f ;
4753 uint32_t lastProcessCounter = 0 ;
54+ BarDivisions barDivision = Bars1;
4855 // cached time values
4956 struct {
5057 bool reset = true ;
@@ -122,7 +129,9 @@ struct HostTime : TerminalModule {
122129 {
123130 timeInfo.beat = 1 ;
124131 ++timeInfo.bar ;
125- pulseBar.trigger ();
132+
133+ if (timeInfo.bar % barDivision == 1 )
134+ pulseBar.trigger ();
126135 }
127136 }
128137
@@ -148,9 +157,10 @@ struct HostTime : TerminalModule {
148157 ? tick / pcontext->ticksPerBeat
149158 : 0 .0f ;
150159 const float barPhase = playingWithBBT && pcontext->beatsPerBar > 0
151- ? ((float ) (timeInfo.beat - 1 ) + beatPhase) / pcontext->beatsPerBar
160+ ? ((float )((timeInfo.bar - 1 ) % barDivision) + (timeInfo.beat - 1 ) + beatPhase)
161+ / (pcontext->beatsPerBar * barDivision)
152162 : 0 .0f ;
153-
163+
154164 lights[kHostTimeRolling ].setBrightness (playing ? 1 .0f : 0 .0f );
155165 lights[kHostTimeReset ].setBrightnessSmooth (hasReset ? 1 .0f : 0 .0f , args.sampleTime * 0 .5f );
156166 lights[kHostTimeBar ].setBrightnessSmooth (hasBar ? 1 .0f : 0 .0f , args.sampleTime * 0 .5f );
@@ -170,6 +180,20 @@ struct HostTime : TerminalModule {
170180
171181 void processTerminalOutput (const ProcessArgs&) override
172182 {}
183+
184+ json_t * dataToJson () override {
185+ json_t * rootJ = json_object ();
186+ json_object_set_new (rootJ, " barDivision" , json_integer (barDivision));
187+ return rootJ;
188+ }
189+
190+ void dataFromJson (json_t * rootJ) override {
191+ if (json_t * bdJ = json_object_get (rootJ, " barDivision" )) {
192+ int value = json_integer_value (bdJ);
193+ if (value == Bars1 || value == Bars4 || value == Bars8)
194+ barDivision = static_cast <BarDivisions>(value);
195+ }
196+ }
173197};
174198
175199// --------------------------------------------------------------------------------------------------------------------
@@ -286,6 +310,22 @@ struct HostTimeWidget : ModuleWidgetWith8HP {
286310
287311 ModuleWidget::drawLayer (args, layer);
288312 }
313+
314+ void appendContextMenu (Menu* menu) override {
315+ struct BarDivisionItem : MenuItem {
316+ HostTime* module ;
317+ HostTime::BarDivisions value;
318+ void onAction (const event::Action& e) override {
319+ module ->barDivision = value;
320+ }
321+ };
322+
323+ menu->addChild (new MenuSeparator);
324+ menu->addChild (construct<MenuLabel>(&MenuLabel::text, " Bar Division" ));
325+ menu->addChild (construct<BarDivisionItem>(&BarDivisionItem::text, " Bars/1" , &BarDivisionItem::module , module , &BarDivisionItem::value, HostTime::Bars1));
326+ menu->addChild (construct<BarDivisionItem>(&BarDivisionItem::text, " Bars/4" , &BarDivisionItem::module , module , &BarDivisionItem::value, HostTime::Bars4));
327+ menu->addChild (construct<BarDivisionItem>(&BarDivisionItem::text, " Bars/8" , &BarDivisionItem::module , module , &BarDivisionItem::value, HostTime::Bars8));
328+ }
289329};
290330#else
291331struct HostTimeWidget : ModuleWidget {
0 commit comments