Midiplugin

Hi all,
I have some problems. I’m new in cpp and JUCE. I’m trying to create a combo with CC midi programs. I’m trying to get the name of CC and add as new item in combo. This is my code.

for (int i = 0; i <= 127; i++)
{

    String name = MidiMessage::getControllerName(i);
    String cbName = "";

    if (name.isNotEmpty())
    {
        cbName =  name + "CC " + std::to_string(i);
        // 2. cbName = "CC " +  std::to_string(i) + name;
    }
    else if (name.isEmpty())
    {
        cbName = "CC " + i;
    }
        

    int s = i + 1;
        

    cbControlChange.addItem(cbName, s);
}

The problems are:

  1. Some CC are defined as null and name.isNotEmpty doesn’t work. I recieved that I’m trying to create combo with empty label.

  2. If I change the label order (2) when isNotEmpty. I get an error and i cant find out why - it’s just concat strings

  3. Why I can’t create and intem in Combox with index of 0? I got and error.

sorry for my english and sorry I’m web/app developer and I trying to adapt to cpp

Kind regards

This is what I get

The function getControllerName:

Returns the name of a controller type number, or nullptr if unknown for this controller number.

so why not just add a case in your if statement to deal with nullptrs (that’s it, when the name is unknown for that message)?
Something like (I didn’t test this):

String cbName = "";

if (MidiMessage::getControllerName(i) != nullptr)
{
    String name = MidiMessage::getControllerName(i);
    if (name.isNotEmpty())
    {
        cbName =  name + "CC " + std::to_string(i);
        // 2. cbName = "CC " +  std::to_string(i) + name;
    }
    else if (name.isEmpty())
    {
        cbName = "CC " + i;
    }
}
else
{
     cbName = "unknown";
}

There is a tutorial for Combobox: JUCE: Tutorial: The ComboBox class
and the documentation: JUCE: ComboBox Class Reference

Hi, Thanks. It works like a charm