File tree 2 files changed +54
-0
lines changed
Sources/MIDIKit/Events/Event/System Exclusive/SysEx7
Tests/MIDIKitTests/Events/Event/SysEx 2 files changed +54
-0
lines changed Original file line number Diff line number Diff line change @@ -64,6 +64,34 @@ extension MIDI.Event {
64
64
65
65
}
66
66
67
+ extension MIDI . Event . SysEx7 {
68
+
69
+ /// Returns the raw MIDI 1.0 message bytes that comprise the event as a human-readable string of hex characters.
70
+ ///
71
+ /// By default the string is returned separated by spaces (ie: `"F7 01 02 03 F0"`).
72
+ ///
73
+ /// A custom separator may be used or pass `nil` for no separator (ie: `"F7010203F0"`).
74
+ public func midi1RawHexString(
75
+ leadingF0: Bool = true ,
76
+ trailingF7: Bool = true ,
77
+ separator: String ? = " "
78
+ ) -> String {
79
+
80
+ let bytes = midi1RawBytes ( leadingF0: leadingF0,
81
+ trailingF7: trailingF7)
82
+
83
+ if let separator = separator {
84
+ return bytes. hex. stringValues ( padTo: 2 , prefixes: false )
85
+ . joined ( separator: separator)
86
+ } else {
87
+ return bytes. hex. stringValues ( padTo: 2 , prefixes: false )
88
+ . joined ( )
89
+ }
90
+
91
+ }
92
+
93
+ }
94
+
67
95
extension MIDI . Event . SysEx7 {
68
96
69
97
/// Returns the raw MIDI 1.0 message bytes that comprise the event.
Original file line number Diff line number Diff line change @@ -188,6 +188,32 @@ final class SysEx7Tests: XCTestCase {
188
188
189
189
}
190
190
191
+ func testSysEx7_midi1RawHexString( ) throws {
192
+
193
+ let sysEx = MIDI . Event. SysEx7 ( manufacturer: . oneByte( 0x41 ) , data: [ 0x01 , 0x34 ] )
194
+
195
+ XCTAssertEqual (
196
+ sysEx. midi1RawHexString ( ) ,
197
+ " F0 41 01 34 F7 "
198
+ )
199
+
200
+ XCTAssertEqual (
201
+ sysEx. midi1RawHexString ( leadingF0: false , trailingF7: false ) ,
202
+ " 41 01 34 "
203
+ )
204
+
205
+ XCTAssertEqual (
206
+ sysEx. midi1RawHexString ( separator: nil ) ,
207
+ " F0410134F7 "
208
+ )
209
+
210
+ XCTAssertEqual (
211
+ sysEx. midi1RawHexString ( separator: " , " ) ,
212
+ " F0, 41, 01, 34, F7 "
213
+ )
214
+
215
+ }
216
+
191
217
func testUniversalSysEx7RawHexString_Typical( ) throws {
192
218
193
219
// space delimiter
You can’t perform that action at this time.
0 commit comments