Skip to content

Commit

Permalink
MIDIFile: gained Hashable conformance (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
orchetect committed Mar 13, 2023
1 parent e168184 commit b88bbbc
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 11 deletions.
5 changes: 2 additions & 3 deletions Sources/MIDIKitSMF/MIDIFile/Chunk/Chunk.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ extension MIDIFile {
///
/// In ``MIDIFile``, the ``Chunk/Header`` chunk is managed automatically and is not instanced as
/// a ``MIDIFile/chunks`` member.
public enum Chunk: Equatable {
public enum Chunk: Equatable, Hashable {
case track(Track)
case other(UnrecognizedChunk)
}
}

extension MIDIFile.Chunk: CustomStringConvertible,
CustomDebugStringConvertible {
extension MIDIFile.Chunk: CustomStringConvertible, CustomDebugStringConvertible {
public var description: String {
switch self {
case let .track(track):
Expand Down
2 changes: 1 addition & 1 deletion Sources/MIDIKitSMF/MIDIFile/Chunk/Header.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ import MIDIKitCore

extension MIDIFile.Chunk {
/// Header: `MThd` chunk type.
public struct Header: Equatable {
public struct Header: Equatable, Hashable {
public static let staticIdentifier: String = "MThd"

public var format: MIDIFile.Format = .multipleTracksSynchronous
Expand Down
2 changes: 1 addition & 1 deletion Sources/MIDIKitSMF/MIDIFile/Chunk/Track.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import MIDIKitCore

extension MIDIFile.Chunk {
/// Track: `MTrk` chunk type.
public struct Track: Equatable {
public struct Track: Equatable, Hashable {
public static let staticIdentifier: String = "MTrk"

internal static let chunkEnd: [UInt8] = [0xFF, 0x2F, 0x00]
Expand Down
2 changes: 1 addition & 1 deletion Sources/MIDIKitSMF/MIDIFile/Chunk/UnrecognizedChunk.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import MIDIKitCore

extension MIDIFile.Chunk {
/// Unrecognized MIDI File Chunk.
public struct UnrecognizedChunk: MIDIFileChunk, Equatable {
public struct UnrecognizedChunk: MIDIFileChunk, Equatable, Hashable {
static let disallowedIdentifiers: [String] = [
Header().identifier,
Track().identifier
Expand Down
2 changes: 1 addition & 1 deletion Sources/MIDIKitSMF/MIDIFile/MIDIFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import MIDIKitCore
private let fileManager = FileManager.default

/// Standard MIDI Files (SMF) object. Read or write MIDI file contents.
public struct MIDIFile: Equatable {
public struct MIDIFile: Equatable, Hashable {
// MARK: - Properties

internal var header: Chunk.Header = .init()
Expand Down
5 changes: 2 additions & 3 deletions Sources/MIDIKitSMF/MIDIFile/Types/Format.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import MIDIKitCore
// MARK: - Format

extension MIDIFile {
public enum Format: UInt8, CaseIterable, Equatable {
public enum Format: UInt8, CaseIterable, Equatable, Hashable {
/// Type 0:
/// MIDI file contains one single track containing midi data on possibly all 16 midi
/// channels.
Expand All @@ -27,8 +27,7 @@ extension MIDIFile {
}
}

extension MIDIFile.Format: CustomStringConvertible,
CustomDebugStringConvertible {
extension MIDIFile.Format: CustomStringConvertible, CustomDebugStringConvertible {
public var description: String {
switch self {
case .singleTrack:
Expand Down
2 changes: 1 addition & 1 deletion Sources/MIDIKitSMF/MIDIFile/Types/TimeBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import MIDIKitCore

extension MIDIFile {
/// MIDI file timebase as described in the MIDI file header.
public enum TimeBase: Equatable {
public enum TimeBase: Equatable, Hashable {
/// Musical: Delta-time ticks per quarter note (PPQN / PPQ / PPQBase).
///
/// Common values: 96, 120, 480, 960. Cubase exports at 480 by default.
Expand Down

0 comments on commit b88bbbc

Please sign in to comment.