Current_alternative ... where do we start?

So I have some printouts to just show what current_alternative is.
At boot up, current_alternative == 0.
But then advancing one by using this style code

TransitionEffectL<TrDoEffectAlwaysX<TrInstant,EFFECT_ALT_SOUND,ModF<Sum<AltF,Int<1>>,Int<7>>,Int<-1>>,EFFECT_USER1>

it’s still current_alternative == 0?
From there on it’s correctly incrementing but still offset by -1.
I have everything working right, but curious why the first change doesn’t advance as expected.

Also, why all the ModF<Sum< stuff? What is actually happening there in plain english?

The calculation is just doing alt = (alt + 1) % 7.
Not sure what would be causing the lag-by-one though…

If you generated from my library you need to make sure you review the comments provided for how to set up the font. The library keeps track of what you’re selecting and provides the code AND set up instructions to match. If you’re not setting the font up as it expects it won’t work properly.

The isolated layer may be made from the library initially, because I wouldn’t use Sum<> on my own. I just searched my config folder for TrDoEffect and used it in conjunction with ColorSelect<AltF .
I’m using alt sounds folders 0 through 6, and all works as intended, it’s just the debug printouts seemed illogical as the current_alternative was still 0 after the first increment.

It’s not important really, just a late night “huh?” while coding up a style and a prop file.

Could depend on WHEN the printout is coming into play, if it’s printing out BEFORE the alt actually changed then it would always be off by 1.

With the library the Sum<> and ModF<> functions are triggered based on what is selected by the user and has corresponding font set up instructions in the comment section, it’s not a “universal” way to do AltF, it’s specific to the options and implementation you selected. The library assembles the code to meet the specific style the user is building, that will change as different selections are made. So this would be one way to do this for one specific set up, but not necessarily the best for setting up other uses ;-).

For what it’s worth, This style simply “charges up” to a max level of 6 (so 7 total steps), and resets back to 0 when FIRE is pressed.

Font is setup like this:

./Fallout/alt000/altchng.wav
./Fallout/alt000/blast.wav
./Fallout/alt000/hum.wav
./Fallout/alt001/altchng.wav
./Fallout/alt001/blast.wav
./Fallout/alt001/hum.wav
./Fallout/alt002/altchng.wav
./Fallout/alt002/blast.wav
./Fallout/alt002/hum.wav
./Fallout/alt003/altchng.wav
./Fallout/alt003/blast.wav
./Fallout/alt003/hum.wav
./Fallout/alt004/altchng.wav
./Fallout/alt004/blast.wav
./Fallout/alt004/hum.wav
./Fallout/alt005/altchng.wav
./Fallout/alt005/blast.wav
./Fallout/alt005/hum.wav
./Fallout/alt006/altchng.wav
./Fallout/alt006/blast.wav
./Fallout/alt006/hum.wav
./Fallout/boot.wav
./Fallout/empty.wav
./Fallout/font.wav
./Fallout/maxcharge.wav
./Fallout/quote01.wav
./Fallout/tracks/wasteland.wav

here’s the button event code with the printouts:

  // Crank to charge
      case EVENTID(BUTTON_AUX, EVENT_FIRST_SAVED_CLICK_SHORT, MODE_ON):
          PVLOG_DEBUG << "**** current_alternative BEFORE = " << current_alternative << "\n";
        if (current_alternative == 6) {
          hybrid_font.PlayCommon(&SFX_maxcharge);
          return true;
        } else {
          PVLOG_DEBUG << "**** EFFECT_USER1 - Next Phase **\n";
          SaberBase::DoEffect(EFFECT_USER1, 0);
          PVLOG_DEBUG << "**** current_alternative AFTER = " << current_alternative << "\n";
        }
        return true;

  // Trigger to fire
      case EVENTID(BUTTON_POWER, EVENT_PRESSED, MODE_ON):
          PVLOG_DEBUG << "**** current_alternative At BOOT = " << current_alternative << "\n";
        if (current_alternative == 0) {
          PVLOG_DEBUG << "**** No charge = EMPTY - No FIRE **\n";
          SaberBase::DoEffect(EFFECT_EMPTY, 0);
        } else {
          PVLOG_DEBUG << "**** FIRE ****\n";
          SaberBase::DoEffect(EFFECT_FIRE, 0);
          ResetCurrentAlternative();
        }
        return true;

and then using this blade style:

  StylePtr<Layers<Black,
    ColorSelect<AltF,TrFadeX<Int<1000>>,
      //Default
      Black,
      // 1 crank: 6%
      Mix<Sin<Int<30>,Int<2000>>,Rgb<30,0,0>,Red>,
      // 2 cranks: 18%
      Mix<Sin<Int<50>,Int<6000>,Int<2500>>,Rgb<30,0,0>,Red>,
      // 3 cranks: 31%
      Mix<Sin<Int<85>,Int<10000>,Int<6800>>,Rgb<30,0,0>,Red>,
      // 4 cranks: 44%
      Mix<Sin<Int<150>,Int<14400>,Int<9200>>,Rgb<30,0,0>,Red>,
      // 5 cranks: 52%
      Mix<Sin<Int<240>,Int<17000>,Int<12000>>,Rgb<30,0,0>,Red>,
      // 6 cranks: 64%
      Mix<Sin<Int<400>,Int<21000>,Int<15000>>,Rgb<30,0,0>,Red>>,
  // USER1 = next phase
  TransitionEffectL<TrDoEffectAlwaysX<TrInstant,EFFECT_ALT_SOUND,ModF<Sum<AltF,Int<1>>,Int<7>>,Int<-1>>,EFFECT_USER1>,
  // FIRE and reset to default phase
  TransitionEffectL<TrConcat<TrInstant,TrDoEffectAlwaysX<TrInstant,EFFECT_ALT_SOUND,Int<0>,Int<-1>>,HumpFlicker<White,Black,100>,TrDelay<200>,TrFade<700>>,EFFECT_FIRE>>(),

powering on , trying to fire, then incrementing to max and firing gives this result (trimmed down to relevant messages):


10:57:56.815 -> Playing Fallout/alt000/hum.wav
10:57:56.980 -> EVENT: Power-Pressed ON millis=8491
10:57:56.980 -> **** current_alternative At BOOT = 0
10:57:56.980 -> **** No charge = EMPTY - No FIRE **
10:57:56.980 -> unit = 0 vol = 0.50, Playing Fallout/empty.wav

10:57:58.814 -> Playing Fallout/alt000/hum.wav
10:58:00.389 -> EVENT: Aux-SavedShortclick#1 ON millis=11924
10:58:00.389 -> **** current_alternative BEFORE = 0
10:58:00.389 -> **** EFFECT_USER1 - Next Phase **
10:58:00.389 -> **** current_alternative AFTER = 0
10:58:00.418 -> unit = 0 vol = 0.50, Playing Fallout/alt001/hum.wav
10:58:00.418 -> unit = 2 vol = 0.50, Playing Fallout/alt001/altchng.wav

10:58:01.825 -> EVENT: Aux-SavedShortclick#1 ON millis=13349
10:58:01.825 -> **** current_alternative BEFORE = 1
10:58:01.825 -> **** EFFECT_USER1 - Next Phase **
10:58:01.825 -> **** current_alternative AFTER = 1
10:58:01.825 -> unit = 1 vol = 0.50, Playing Fallout/alt002/hum.wav
10:58:01.825 -> unit = 3 vol = 0.50, Playing Fallout/alt002/altchng.wav

10:58:03.261 -> EVENT: Aux-SavedShortclick#1 ON millis=14780
10:58:03.261 -> **** current_alternative BEFORE = 2
10:58:03.261 -> **** EFFECT_USER1 - Next Phase **
10:58:03.261 -> **** current_alternative AFTER = 2
10:58:03.261 -> unit = 0 vol = 0.50, Playing Fallout/alt003/hum.wav
10:58:03.261 -> unit = 2 vol = 0.50, Playing Fallout/alt003/altchng.wav

10:58:04.898 -> EVENT: Aux-SavedShortclick#1 ON millis=16416
10:58:04.898 -> **** current_alternative BEFORE = 3
10:58:04.898 -> **** EFFECT_USER1 - Next Phase **
10:58:04.898 -> **** current_alternative AFTER = 3
10:58:04.898 -> unit = 1 vol = 0.50, Playing Fallout/alt004/hum.wav
10:58:04.898 -> unit = 3 vol = 0.50, Playing Fallout/alt004/altchng.wav

10:58:06.662 -> EVENT: Aux-SavedShortclick#1 ON millis=18203
10:58:06.662 -> **** current_alternative BEFORE = 4
10:58:06.694 -> **** EFFECT_USER1 - Next Phase **
10:58:06.694 -> **** current_alternative AFTER = 4
10:58:06.694 -> unit = 0 vol = 0.50, Playing Fallout/alt005/hum.wav
10:58:06.694 -> unit = 2 vol = 0.50, Playing Fallout/alt005/altchng.wav

10:58:08.689 -> EVENT: Aux-SavedShortclick#1 ON millis=20228
10:58:08.689 -> **** current_alternative BEFORE = 5
10:58:08.689 -> **** EFFECT_USER1 - Next Phase **
10:58:08.689 -> **** current_alternative AFTER = 5
10:58:08.721 -> unit = 1 vol = 0.50, Playing Fallout/alt006/hum.wav
10:58:08.721 -> unit = 2 vol = 0.50, Playing Fallout/alt006/altchng.wav

10:58:11.012 -> EVENT: Aux-SavedShortclick#1 ON millis=22543
10:58:11.012 -> **** current_alternative BEFORE = 6
10:58:11.012 -> unit = 0 vol = 0.50, Playing Fallout/maxcharge.wav

10:58:15.822 -> EVENT: Aux-SavedShortclick#1 ON millis=27358
10:58:15.823 -> **** current_alternative BEFORE = 6
10:58:15.823 -> unit = 0 vol = 0.50, Playing Fallout/maxcharge.wav

10:58:18.341 -> EVENT: Power-Pressed ON millis=29866
10:58:18.341 -> **** current_alternative At BOOT = 6
10:58:18.341 -> **** FIRE ****
10:58:18.341 -> unit = 0 vol = 0.50, Playing Fallout/alt006/blast.wav
10:58:18.341 -> unit = 2 vol = 0.50, Playing Fallout/alt000/hum.wav
10:58:18.372 -> unit = 3 vol = 0.50, Playing Fallout/alt000/altchng.wav

10:58:18.863 -> EVENT: Power-SavedShortclick ON millis=30375
10:58:20.334 -> Playing Fallout/alt000/hum.wav
10:58:21.644 -> EVENT: Power-Pressed ON millis=33173
10:58:21.644 -> **** current_alternative At BOOT = 0
10:58:21.644 -> **** No charge = EMPTY - No FIRE **
10:58:21.644 -> unit = 1 vol = 0.50, Playing Fallout/empty.wav
10:58:22.363 -> Playing Fallout/alt000/hum.wav

So the timing of the “AFTER” printout must just not be late enough in the runtime to pickup the change to the current_alternative, since the alt folder is incremented correctly, and the next button press printout of “BEFORE” shows the correct alt.

Just a weird timing thing I guess.

Anyway, it works. Thanks.

That’d be my guess, especially if it’s actually working correctly. Do you need the printouts or is it just for testing?

Not needed.
Initially, I had not accounted for the -1 offset and/or the fact that 0-6 is actually 7 steps, so I had the ModF V value set to 6 (needs to be 7).
Printouts were to track current_alternative and pointed me to my error.
However, seeing that the value didn’t increment after doing the EFFECT_USER1 was an anomaly that I just wanted to chase down for better understanding.

Gotcha, yeah ModF<> wraps to 0 when you get to V, so it would be 1 more than your desired range.

1 Like