Skip to content

Commit e168184

Browse files
committed
MIDIEvent.NoteOn: midi1ZeroVelocityAsNoteOff now defaults to false
1 parent 8992768 commit e168184

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

Sources/MIDIKitCore/Events/MIDIEvent/Channel Voice/Note/NoteOn/NoteOn.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ extension MIDIEvent {
2626
/// UMP Group (`0x0 ... 0xF`)
2727
public var group: UInt4 = 0x0
2828

29-
/// For MIDI 1.0, transmit velocity of 0 as a Note Off event.
29+
/// For MIDI 1.0, translate velocity of 0 as a Note Off event.
3030
public var midi1ZeroVelocityAsNoteOff: Bool = true
3131

3232
/// Channel Voice Message: Note On
@@ -38,15 +38,15 @@ extension MIDIEvent {
3838
/// - channel: Channel Number (`0x0 ... 0xF`)
3939
/// - attribute: MIDI 2.0 Channel Voice Attribute
4040
/// - group: UMP Group (`0x0 ... 0xF`)
41-
/// - midi1ZeroVelocityAsNoteOff: For MIDI 1.0, transmit velocity of 0 as a Note Off
41+
/// - midi1ZeroVelocityAsNoteOff: For MIDI 1.0, translate velocity of 0 as a Note Off
4242
/// event.
4343
public init(
4444
note: UInt7,
4545
velocity: MIDIEvent.NoteVelocity,
4646
attribute: MIDIEvent.NoteAttribute = .none,
4747
channel: UInt4,
4848
group: UInt4 = 0x0,
49-
midi1ZeroVelocityAsNoteOff: Bool = true
49+
midi1ZeroVelocityAsNoteOff: Bool = false
5050
) {
5151
self.note = MIDINote(note)
5252
self.velocity = velocity
@@ -65,15 +65,15 @@ extension MIDIEvent {
6565
/// - channel: Channel Number (`0x0 ... 0xF`)
6666
/// - attribute: MIDI 2.0 Channel Voice Attribute
6767
/// - group: UMP Group (`0x0 ... 0xF`)
68-
/// - midi1ZeroVelocityAsNoteOff: For MIDI 1.0, transmit velocity of 0 as a Note Off
68+
/// - midi1ZeroVelocityAsNoteOff: For MIDI 1.0, translate velocity of 0 as a Note Off
6969
/// event.
7070
public init(
7171
note: MIDINote,
7272
velocity: MIDIEvent.NoteVelocity,
7373
attribute: MIDIEvent.NoteAttribute = .none,
7474
channel: UInt4,
7575
group: UInt4 = 0x0,
76-
midi1ZeroVelocityAsNoteOff: Bool = true
76+
midi1ZeroVelocityAsNoteOff: Bool = false
7777
) {
7878
self.note = note
7979
self.velocity = velocity
@@ -119,14 +119,14 @@ extension MIDIEvent {
119119
/// - channel: Channel Number (`0x0 ... 0xF`)
120120
/// - attribute: MIDI 2.0 Channel Voice Attribute
121121
/// - group: UMP Group (`0x0 ... 0xF`)
122-
/// - midi1ZeroVelocityAsNoteOff: For MIDI 1.0, transmit velocity of 0 as a Note Off event.
122+
/// - midi1ZeroVelocityAsNoteOff: For MIDI 1.0, translate velocity of 0 as a Note Off event.
123123
public static func noteOn(
124124
_ note: UInt7,
125125
velocity: NoteVelocity,
126126
attribute: NoteAttribute = .none,
127127
channel: UInt4,
128128
group: UInt4 = 0x0,
129-
midi1ZeroVelocityAsNoteOff: Bool = true
129+
midi1ZeroVelocityAsNoteOff: Bool = false
130130
) -> Self {
131131
.noteOn(
132132
.init(
@@ -149,14 +149,14 @@ extension MIDIEvent {
149149
/// - channel: Channel Number (`0x0 ... 0xF`)
150150
/// - attribute: MIDI 2.0 Channel Voice Attribute
151151
/// - group: UMP Group (`0x0 ... 0xF`)
152-
/// - midi1ZeroVelocityAsNoteOff: For MIDI 1.0, transmit velocity of 0 as a Note Off event.
152+
/// - midi1ZeroVelocityAsNoteOff: For MIDI 1.0, translate velocity of 0 as a Note Off event.
153153
public static func noteOn(
154154
_ note: MIDINote,
155155
velocity: NoteVelocity,
156156
attribute: NoteAttribute = .none,
157157
channel: UInt4,
158158
group: UInt4 = 0x0,
159-
midi1ZeroVelocityAsNoteOff: Bool = true
159+
midi1ZeroVelocityAsNoteOff: Bool = false
160160
) -> Self {
161161
.noteOn(
162162
.init(

Tests/MIDIKitSMFTests/Event/Events/Event Note On Tests.swift

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,29 +69,43 @@ final class Event_NoteOn_Tests: XCTestCase {
6969
XCTAssertEqual(event.channel, 0)
7070
}
7171

72-
func testMIDI1SMFRawBytes_Velocity0_Defaulted() {
72+
func testMIDI1SMFRawBytes_Velocity0_NoTranslation() {
7373
let event = MIDIFileEvent.NoteOn(
7474
note: 60,
7575
velocity: .midi1(0x00),
76-
channel: 0
76+
channel: 0,
77+
midi1ZeroVelocityAsNoteOff: false
7778
)
7879

7980
let bytes: [UInt8] = event.midi1SMFRawBytes()
8081

81-
XCTAssertEqual(bytes, [0x80, 0x3C, 0x00]) // interpreted as Note Off
82+
XCTAssertEqual(bytes, [0x90, 0x3C, 0x00])
8283
}
8384

8485
func testMIDI1SMFRawBytes_Velocity0_TranslateOff() {
8586
let event = MIDIFileEvent.NoteOn(
8687
note: 60,
8788
velocity: .midi1(0x00),
8889
channel: 0,
89-
midi1ZeroVelocityAsNoteOff: false
90+
midi1ZeroVelocityAsNoteOff: true
9091
)
9192

9293
let bytes: [UInt8] = event.midi1SMFRawBytes()
9394

94-
XCTAssertEqual(bytes, [0x90, 0x3C, 0x00])
95+
XCTAssertEqual(bytes, [0x80, 0x3C, 0x00]) // interpreted as Note Off
96+
}
97+
98+
func testMIDI1SMFRawBytes_Velocity1_TranslateOff() {
99+
let event = MIDIFileEvent.NoteOn(
100+
note: 60,
101+
velocity: .midi1(0x01),
102+
channel: 0,
103+
midi1ZeroVelocityAsNoteOff: true
104+
)
105+
106+
let bytes: [UInt8] = event.midi1SMFRawBytes()
107+
108+
XCTAssertEqual(bytes, [0x90, 0x3C, 0x01])
95109
}
96110
}
97111

0 commit comments

Comments
 (0)