Cabbage Logo
Back to Cabbage Site

Change the base note that is played pressing a key on the PC keyboard

For my experimentations I needed a way to change the base note that is played when you press a key on the PC keyboard and you use the keyboard widget. I didn’t want to change the octave you play when you play notes on a true midi-keyboard or when you click directly the notes in the keyboard widget… Just set the base octave that is played when you press a key on the PC keyboard. Then I noticed that Juce has a function for that:

void MidiKeyboardComponent::setKeyPressBaseOctave(int newOctaveNumber)

but in Cabbage that function is hard-coded to a value of 3 that isn’t always what I need. So I made some mods to add an identifier “keypressbaseoctave” to the keyboard widget that allows you to set the octave you want to use for the PC keyboard keys.

So you can do, for example:

<Cabbage>
...
keyboard bounds(10, 192, 581, 95) keypressbaseoctave(5) value(30) whitenotecolour(255, 255, 255, 255) ...
...
</Cabbage>

Of course, if you don’t use the ‘keypressbaseoctave’ identifier, the default value will remain 3. If you are interested I can make a pull request with my changes.

P.S.: according to the Juce documentation, the value you pass to keypressbaseoctave(…) has to be between 0 and 10. For now I have not made checks on the range and I don’t know what happens if you pass a value outside that range…

Nice. Can you make a PR?

I made a PR, but I’m not used yet to github so I don’t know if it’s all right… And there are many changes that github made itself on the LF/CRLF line endings of some source files (so it looks like there are many more modified lines than they actually are).
Please, check if it’s all ok before pull in the master. There should be 5 files modified.

Now I see you modified some hours ago the same files I changed in my commit for the above mod… So I should create a new branch with your mods, remod them with my changes and then repull the request?

You may not need to. You probably don’t as we were working in 2 different areas. Your changes adult merge fine. I’ll let you know. Can’t merge from my phone :rofl: will have to wait till later

[edit] That merged fine. Thanks for contributing. :wink: I was meaning to add that for some time!