-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #111 from orchetect/dev
`.send(events:)`: Improved reliability of sending SysEx
- Loading branch information
Showing
4 changed files
with
66 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/// ------------------------------------------------------------------------------------ | ||
/// ------------------------------------------------------------------------------------ | ||
/// Borrowed from [OTCore 1.4.1](https://github.com/orchetect/OTCore) under MIT license. | ||
/// Methods herein are unit tested in OTCore, so no unit tests are necessary in MIDIKit. | ||
/// ------------------------------------------------------------------------------------ | ||
/// ------------------------------------------------------------------------------------ | ||
|
||
#if shouldTestCurrentPlatform | ||
|
||
import Foundation | ||
|
||
extension Collection { | ||
|
||
/// **OTCore:** | ||
/// Splits a `Collection` or `String` into groups of `length` characters, grouping from left-to-right. If `backwards` is true, right-to-left. | ||
@_disfavoredOverload | ||
internal func split(every: Int, | ||
backwards: Bool = false) -> [SubSequence] { | ||
|
||
var result: [SubSequence] = [] | ||
|
||
for i in stride(from: 0, to: count, by: every) { | ||
|
||
switch backwards { | ||
case true: | ||
let offsetEndIndex = index(endIndex, offsetBy: -i) | ||
let offsetStartIndex = index(offsetEndIndex, | ||
offsetBy: -every, | ||
limitedBy: startIndex) | ||
?? startIndex | ||
|
||
result.insert(self[offsetStartIndex..<offsetEndIndex], at: 0) | ||
|
||
case false: | ||
let offsetStartIndex = index(startIndex, offsetBy: i) | ||
let offsetEndIndex = index(offsetStartIndex, | ||
offsetBy: every, | ||
limitedBy: endIndex) | ||
?? endIndex | ||
|
||
result.append(self[offsetStartIndex..<offsetEndIndex]) | ||
|
||
} | ||
|
||
} | ||
|
||
return result | ||
|
||
} | ||
|
||
} | ||
|
||
#endif |