Is there a way to programatically populate enums?

I am seeing that the enum data type is a useful one in iPlug2 development. I am new to C++ programming, and I wondered if its possible to programatically fill it, like for a sequencer that might need lots of values / name pairs. For example, below what if I wanted to name 32x kFluxDial

enum EParams { kFluxDial1Inner=0, kFluxDial1Outer, kFluxDial2Inner, kFluxDial2Outer, kFluxDial3Inner, kFluxDial3Outer, kFluxDial4Inner, kFluxDial4Outer, kNetstatus, kReScan, kNumParams };

enum is just a convenient way of linking sequential indexes to names

here is an example of how i might set up EParams in a step sequencer

#define NUM_STEPS 16

enum EParams
{
  kFirstParam = 0,
  ...  // declare all single params
  kPitchStart, // first set of NUM_STEPS params
  kLevelStart = kPitchStart + NUM_STEPS,  // start of second set of NUM_STEPS params
  kCutoffStart = kLevelStart + NUM_STEPS // start of 3rd set of NUM_STEPS params
  kNumParams = kCutoffStart + NUM_STEPS 
};

Then when declaring params, can do NUM_STEPS at once like…

InitParamRange(kPitchStart, kPitchStart + NUM_STEPS - 1, 1, "Note %i", 0, 0., 11., 1., "Semi", IParam::EFlags::kFlagStepped, "Note Steps");
InitParamRange(kLevelStart, kLevelStart + NUM_STEPS - 1, 1, "Level %i", 100., 0., 100., 0.01, "%", 0, "Level Steps");
InitParamRange(kCutoffStart, kCutoffStart + NUM_STEPS - 1, 1, "Cutoff %i", 0., -64., 64., 0.01, "st", 0, "Cutoff Steps");
2 Likes

brilliant , thankyou. I hadn’t come across InitParamRange() yet - very useful!

is there a similar method for IGraphics::AttachControl() which would need to go over all the parameters , and a related tag enum?

you can use a for loop for that

1 Like

In my learning context, here is the code that worked for me based on Oli’s suggestion. Indeed, I see now how enums are fast and useful.

    #define NBR_DUALDIALS 4

enum EParams
{
  kNetstatus = 0,
  kReScan,
  kDualDialInner,
  kDualDialOuter = kDualDialInner + NBR_DUALDIALS,
  kNumParams = kDualDialOuter + NBR_DUALDIALS
};

enum EControlTags
{
  kCtrlNetStatus = 0,
  kCtrlReScan,
  kCtrlFluxDial,
  kNumCtrlTags = kCtrlFluxDial + NBR_DUALDIALS
};

enum EControlDialTags
{
  kCtrlFluxDialInner = 0,
  kCtrlFluxDialOuter = kCtrlFluxDialInner + NBR_DUALDIALS,
  kNumCtrlFluxDials = kCtrlFluxDialOuter + NBR_DUALDIALS
};

and the param declaration and tag assignment

     InitParamRange(kDualDialInner, kDualDialInner + NBR_DUALDIALS - 1, 1, "Dual Dial %i", 0, 0., 1., 0,"%",0,"Inner Value");
      InitParamRange(kDualDialOuter, kDualDialOuter + NBR_DUALDIALS - 1, 1, "Dual Dial %i", 0, 0., 1., 0,"%",0,"Outer Value");

.....

for (int d=0; d<NBR_DUALDIALS; d++) {

  pGraphics->AttachControl
        (new NELDoubleDial(
                           b.SubRectVertical(NBR_DUALDIALS, d).GetCentredInside(100),
                           {kDualDialInner + d, kDualDialOuter + d}), kCtrlFluxDial+d
         );
  }