Skip to content

Commit

Permalink
Added public inits to all MIDI.Event.* concrete types
Browse files Browse the repository at this point in the history
  • Loading branch information
orchetect committed Nov 5, 2021
1 parent b4c3e9e commit 74f4c37
Show file tree
Hide file tree
Showing 24 changed files with 325 additions and 1 deletion.
26 changes: 25 additions & 1 deletion Sources/MIDIKit/Events/Event/Channel Voice/CC/CC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,30 @@ extension MIDI.Event {
/// UMP Group (0x0...0xF)
public var group: MIDI.UInt4 = 0x0

public init(controller: Controller,
value: Value,
channel: MIDI.UInt4,
group: MIDI.UInt4 = 0x0) {

self.controller = controller
self.value = value
self.channel = channel
self.group = group

}

public init(controller: MIDI.UInt7,
value: Value,
channel: MIDI.UInt4,
group: MIDI.UInt4 = 0x0) {

self.controller = .init(number: controller)
self.value = value
self.channel = channel
self.group = group

}

}

}
Expand Down Expand Up @@ -64,7 +88,7 @@ extension MIDI.Event {
group: MIDI.UInt4 = 0x0) -> Self {

.cc(
.init(controller: .init(number: controller),
.init(controller: controller,
value: value,
channel: channel,
group: group)
Expand Down
28 changes: 28 additions & 0 deletions Sources/MIDIKit/Events/Event/Channel Voice/Note/CC/Note CC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,34 @@ extension MIDI.Event.Note {
/// UMP Group (0x0...0xF)
public var group: MIDI.UInt4 = 0x0

public init(note: MIDI.UInt7,
controller: CC.Controller,
value: UInt32,
channel: MIDI.UInt4,
group: MIDI.UInt4 = 0x0) {

self.note = note
self.controller = controller
self.value = value
self.channel = channel
self.group = group

}

public init(note: MIDI.Note,
controller: CC.Controller,
value: UInt32,
channel: MIDI.UInt4,
group: MIDI.UInt4 = 0x0) {

self.note = note.number
self.controller = controller
self.value = value
self.channel = channel
self.group = group

}

}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,30 @@ extension MIDI.Event.Note {
/// UMP Group (0x0...0xF)
public var group: MIDI.UInt4 = 0x0

public init(note: MIDI.UInt7,
optionFlags: Set<OptionFlag> = [],
channel: MIDI.UInt4,
group: MIDI.UInt4 = 0x0) {

self.note = note
self.optionFlags = optionFlags
self.channel = channel
self.group = group

}

public init(note: MIDI.Note,
optionFlags: Set<OptionFlag> = [],
channel: MIDI.UInt4,
group: MIDI.UInt4 = 0x0) {

self.note = note.number
self.optionFlags = optionFlags
self.channel = channel
self.group = group

}

}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ extension MIDI.Event.Note.Attribute {
/// 9-Bit fractional pitch above Note Number (i.e., fraction of one semitone).
public var fine: MIDI.UInt9

public init(coarse: MIDI.UInt7,
fine: MIDI.UInt9) {

self.coarse = coarse
self.fine = fine

}

}

}
Expand Down
28 changes: 28 additions & 0 deletions Sources/MIDIKit/Events/Event/Channel Voice/Note/Off/Note Off.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,34 @@ extension MIDI.Event.Note {
/// UMP Group (0x0...0xF)
public var group: MIDI.UInt4 = 0x0

public init(note: MIDI.UInt7,
velocity: MIDI.Event.Note.Velocity,
channel: MIDI.UInt4,
attribute: MIDI.Event.Note.Attribute = .none,
group: MIDI.UInt4 = 0x0) {

self.note = note
self.velocity = velocity
self.channel = channel
self.attribute = attribute
self.group = group

}

public init(note: MIDI.Note,
velocity: MIDI.Event.Note.Velocity,
channel: MIDI.UInt4,
attribute: MIDI.Event.Note.Attribute = .none,
group: MIDI.UInt4 = 0x0) {

self.note = note.number
self.velocity = velocity
self.channel = channel
self.attribute = attribute
self.group = group

}

}

}
Expand Down
32 changes: 32 additions & 0 deletions Sources/MIDIKit/Events/Event/Channel Voice/Note/On/Note On.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,38 @@ extension MIDI.Event.Note {
/// For MIDI 1.0, transmit velocity of 0 as a Note Off event.
public var midi1ZeroVelocityAsNoteOff: Bool = true

public init(note: MIDI.UInt7,
velocity: MIDI.Event.Note.Velocity,
channel: MIDI.UInt4,
attribute: MIDI.Event.Note.Attribute = .none,
group: MIDI.UInt4 = 0x0,
midi1ZeroVelocityAsNoteOff: Bool = true) {

self.note = note
self.velocity = velocity
self.channel = channel
self.attribute = attribute
self.group = group
self.midi1ZeroVelocityAsNoteOff = midi1ZeroVelocityAsNoteOff

}

public init(note: MIDI.Note,
velocity: MIDI.Event.Note.Velocity,
channel: MIDI.UInt4,
attribute: MIDI.Event.Note.Attribute = .none,
group: MIDI.UInt4 = 0x0,
midi1ZeroVelocityAsNoteOff: Bool = true) {

self.note = note.number
self.velocity = velocity
self.channel = channel
self.attribute = attribute
self.group = group
self.midi1ZeroVelocityAsNoteOff = midi1ZeroVelocityAsNoteOff

}

}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,30 @@ extension MIDI.Event.Note {
/// UMP Group (0x0...0xF)
public var group: MIDI.UInt4 = 0x0

public init(note: MIDI.UInt7,
value: Value,
channel: MIDI.UInt4,
group: MIDI.UInt4 = 0x0) {

self.note = note
self.value = value
self.channel = channel
self.group = group

}

public init(note: MIDI.Note,
value: Value,
channel: MIDI.UInt4,
group: MIDI.UInt4 = 0x0) {

self.note = note.number
self.value = value
self.channel = channel
self.group = group

}

}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,30 @@ extension MIDI.Event.Note {
/// UMP Group (0x0...0xF)
public var group: MIDI.UInt4 = 0x0

public init(note: MIDI.UInt7,
amount: Amount,
channel: MIDI.UInt4,
group: MIDI.UInt4 = 0x0) {

self.note = note
self.amount = amount
self.channel = channel
self.group = group

}

public init(note: MIDI.Note,
amount: Amount,
channel: MIDI.UInt4,
group: MIDI.UInt4 = 0x0) {

self.note = note.number
self.amount = amount
self.channel = channel
self.group = group

}

}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ extension MIDI.Event {
/// UMP Group (0x0...0xF)
public var group: MIDI.UInt4 = 0x0

public init(value: Value,
channel: MIDI.UInt4,
group: MIDI.UInt4 = 0x0) {

self.value = value
self.channel = channel
self.group = group

}

}

/// Channel Voice Message: Pitch Bend
Expand Down
10 changes: 10 additions & 0 deletions Sources/MIDIKit/Events/Event/Channel Voice/Pressure/Pressure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ extension MIDI.Event {
/// UMP Group (0x0...0xF)
public var group: MIDI.UInt4 = 0x0

public init(amount: Amount,
channel: MIDI.UInt4,
group: MIDI.UInt4 = 0x0) {

self.amount = amount
self.channel = channel
self.group = group

}

}

/// Channel Voice Message: Channel Pressure
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ extension MIDI.Event {
/// UMP Group (0x0...0xF)
public var group: MIDI.UInt4 = 0x0

public init(program: MIDI.UInt7,
bank: Bank,
channel: MIDI.UInt4,
group: MIDI.UInt4 = 0x0) {

self.program = program
self.bank = bank
self.channel = channel
self.group = group

}

}

/// Channel Voice Message: Program Change
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ extension MIDI.Event {
/// UMP Group (0x0...0xF)
public var group: MIDI.UInt4 = 0x0

public init(midiBeat: MIDI.UInt14,
group: MIDI.UInt4 = 0x0) {

self.midiBeat = midiBeat
self.group = group

}

}

/// System Common: Song Position Pointer
Expand Down
8 changes: 8 additions & 0 deletions Sources/MIDIKit/Events/Event/System Common/SongSelect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ extension MIDI.Event {
/// UMP Group (0x0...0xF)
public var group: MIDI.UInt4 = 0x0

public init(number: MIDI.UInt7,
group: MIDI.UInt4 = 0x0) {

self.number = number
self.group = group

}

}

/// System Common: Song Select
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ extension MIDI.Event {
/// UMP Group (0x0...0xF)
public var group: MIDI.UInt4 = 0x0

public init(dataByte: MIDI.UInt7,
group: MIDI.UInt4 = 0x0) {

self.dataByte = dataByte
self.group = group

}

}

/// System Common: Timecode Quarter-Frame
Expand Down
6 changes: 6 additions & 0 deletions Sources/MIDIKit/Events/Event/System Common/TuneRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ extension MIDI.Event {
/// UMP Group (0x0...0xF)
public var group: MIDI.UInt4 = 0x0

public init(group: MIDI.UInt4 = 0x0) {

self.group = group

}

}

/// System Common: Tune Request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ extension MIDI.Event {
/// UMP Group (0x0...0xF)
public var group: MIDI.UInt4 = 0x0

public init(bus: MIDI.UInt7 = 0,
group: MIDI.UInt4 = 0x0) {

self.bus = bus
self.group = group

}

}

/// Unofficial Bus Select (Status `0xF5`)
Expand Down
10 changes: 10 additions & 0 deletions Sources/MIDIKit/Events/Event/System Exclusive/SysEx/SysEx.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ extension MIDI.Event {
/// UMP Group (0x0...0xF)
public var group: MIDI.UInt4 = 0x0

public init(manufacturer: MIDI.Event.SysExManufacturer,
data: [MIDI.Byte],
group: MIDI.UInt4 = 0x0) {

self.manufacturer = manufacturer
self.data = data
self.group = group

}

}

/// System Exclusive: Manufacturer-specific
Expand Down
Loading

0 comments on commit 74f4c37

Please sign in to comment.