カテゴリー
C++ JUCE

JUCE ComboBoxのSelectorID

ComboBoxをAudioProcessorValueTreeState::ComboBoxAttachmentを使わずにAPVTSのパラメターと連動させたい場合は以下のようにします。

こうすることで、SelectorIDのmax値を2000(でも2000000でも可)などにし、後々の拡張にも対応出来ます。setValue()の時、型をjuce::var()にキャストすることでホスト(DAW)のパラメータとして保存されるようです。

void comboBoxChanged(juce::ComboBox *comboBoxThatHasChanged) override 
{
  if (comboBoxThatHasChanged == &voicingSelector) 
  {
    controls.clear();
    int comboBoxSelectedIndex = comboBoxThatHasChanged->getSelectedId();
    if(comboBoxSelectedIndex != 0) 
    {
      DBG("comboBoxSelectedIndex " << comboBoxSelectedIndex);
      auto selectorIdParam = valueTreeState.getParameterAsValue(selectorIdString);
// need to cast to juce::var type in order to persist the value in Host...

selectorIdParam.setValue(juce::var(comboBoxSelectedIndex));
    }
  }
}

復習ですが、ComboBoxの基本的な使い方は以下。。。

// add the parent Component as a listener
// you should remove the listener in the deconstructor
comboBox.addListener(this);

// sets selector id
comboBox.setSelectedId(id, juce::dontSendNotification);