Modifying a foleys midikeyboardcomponent

I just got this wonderful module and have started to adapt the synth I’ve been working on but I’m a bit lost in how to access the midikeyboard component. I’d like to be able to change the keypressbaseoctave and also to keep it in focus so I can change sliders parameters while playing.
I looked in foleys_MagicJUCEFactories.cpp which is the only place I see midikeyboardComponent referenced and yes, I can change the constructor there but it seems there must be some better way.
Sorry for the noob question :slight_smile:

That’s actually a good question.

There are two possible ways to do it:
a) I could add a property for the value you want to modify. The MidiKeyboardComponent is so small, I would be willing to do that

b) Copy the MidiKeyboardItem and change the code there

In case you need a different MidiKeyboardState as well, you can add your own classes to the magicState like

myKeyboardState = magicState.createAndAddObject<MyCustomMidiState>("identifier", ...);

And connect to that one from a modified update() method of your component.
But it seems it’s not necessary.

Here is a patch you can use to try for yourself. If that works, I can add it:
MidiOctave-patch.txt (1.5 KB)

Thanks for the patch, it works as expected.

However let’s say I might want to change that value later through buttons or a slider, wouldn’t I need to have a reference to the keyboard instance?

Ok I see. You never access the gui components directly, because they can be deleted at any time.

The magicState has two connectors, one is the AudioParameter interface, that is shared with the host, and another properties based system. You can set such a property from e.g. a slider.
However, I didn’t find a fully dynamic approach yet. So the setBaseOctave method would have to be connected via a juce::Value. It can be done, but I would have to think a bit about it.