Add a FIFO class and use it to replace the code in bytestreamToUMP. #13
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Whilst reading through the bytestreamToUMP code I realized that the readIndex, writeIndex, bufferLength, and umpMessage fields are used together to form a FIFO/circular buffer. I've added a FIFO class to util.h and replaced those fields with an instance. The separates the responsibility of maintaining the FIFO and simplifies the more interesting code!
This new class also reduces overhead for a 4 element container to 1 byte vs. 3 integers previously and has the further benefit that is guards against under/overflow abuses.
This commit only affects the FIFO in this one header file. There is another in umpToMIDI1Protocol.cpp which should probably be switched over. I haven't done that yet because I want to limit the scope of this change.
That only leaves the quesiton of how to unit-test the code... For this kind of thing I usually use google test. Do you have a preference for how this is done? What would you think about adding it as an optional dependency?