Closed josephktcheung closed 1 year ago
@aure please review, thanks.
Does this need to be a protocol? Could it simply be an array or dictionary of offsets instead?
Should the PianoSpacerProtocol
be in a separate file? (that might improve the diff too)
Does this need to be a protocol? Could it simply be an array or dictionary of offsets instead?
We need to reuse some existing methods / computed properties to help calculating spacing e.g. pitchRangeBoundedByNaturals
.
Besides space(pitch: Pitch) -> CGFloat
is a function https://github.com/AudioKit/Keyboard/pull/21/files#diff-ad016a649df2351705bd46700b71cb2b10df7ecd735faafdaca811d5f2a23673R46-R54, which I think may not be that easy to replace it with dictionary of offsets. User may want to specify space per pitch, and they may want to have their own way to calculate it using the pitch
parameter.
Should the
PianoSpacerProtocol
be in a separate file? (that might improve the diff too)
I've moved it to a new file. Please check.
Besides
space(pitch: Pitch) -> CGFloat
is a function https://github.com/AudioKit/Keyboard/pull/21/files#diff-ad016a649df2351705bd46700b71cb2b10df7ecd735faafdaca811d5f2a23673R46-R54, which I think may not be that easy to replace it with dictionary of offsets. User may want to specify space per pitch, and they may want to have their own way to calculate it using thepitch
parameter.
There are only 128 pitches (MIDI note numbers), so assuming this function is a pure function of pitch
, then it can be represented by a table of 128 values. It seems the protocol could just be a struct which is generated by some function.
Besides
space(pitch: Pitch) -> CGFloat
is a function https://github.com/AudioKit/Keyboard/pull/21/files#diff-ad016a649df2351705bd46700b71cb2b10df7ecd735faafdaca811d5f2a23673R46-R54, which I think may not be that easy to replace it with dictionary of offsets. User may want to specify space per pitch, and they may want to have their own way to calculate it using thepitch
parameter.There are only 128 pitches (MIDI note numbers), so assuming this function is a pure function of
pitch
, then it can be represented by a table of 128 values. It seems the protocol could just be a struct which is generated by some function.
@wtholliday, I've updated API to further limit the scope end user can modify. They can pass different ratio dictionaries to piano and vertical piano layout to change the spacing. Please check thanks.
This PR is to allow library user to define their own piano key spacing.
This is achieved by adding
initialSpacerRatio
,spacerRatio
andrelativeBlackKeyWidth
to customize the piano key spacing.