I’m quite new to coding and am stuck on a solution and I thought might be a good opportunity for someone smarter than I am to show me how less smarter than them I am, ha.
Basically, I would like to map a piano roll based on user defined notes, we’ll call this our notePool rather than a scale since it can be any arrangement of notes.
- These notes are stored in a StringArray, e.g. “C”, “Db” “D” “E”, etc.
- This notePool is a sorted set (no duplicates) and always starts at C.
- The strings in the pool do not include octave numbers.
- The pianoRoll’s middle note is defined by a rootNote string.
- The pianoRoll is scrollable so this rootNote includes an octave number, like all other notes of course.
If my notePool is “C”, “D”, “E”, my pianoRoll rootNote is “D3”, and has 7 notes. The resulting pianoRoll from bottom to top should be “D2”, “E2”, “C3”, “D3”, “E3”, “C4”, “D4”.
In my attempt, I’m finding it difficult to get the octave numbers to be sorted like above, e.g. my solution is like above but the 2’s are 3’s…
Bonus problem: what if the given rootNote is not in the notePool? How to find the “nearest” note in the pool?
Of course I’m not expecting a full solution, but any thoughts on possible tried and true approaches or direction I can follow from someone experienced would be greatly appreciated.
Many thanks for your time and help!