Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift 5 ready. Migrated to SPM (without breaking the Xcode-based build system) #45

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.build
.swiftpm
.DS_Store
xcuserdata
25 changes: 10 additions & 15 deletions MusicKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
965AF8C11AF7A1DA00D31E83 /* Protocols.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Protocols.swift; sourceTree = "<group>"; };
9662BFF01B058568008A053A /* IntervalQuality.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IntervalQuality.swift; sourceTree = "<group>"; };
96686DB41A573B7F00350A2D /* PitchTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PitchTests.swift; sourceTree = "<group>"; };
966E60FA1B0930E9005EE226 /* AlteredPentads.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; name = AlteredPentads.playground; path = ../Playgrounds/AlteredPentads.playground; sourceTree = "<group>"; };
966E60FA1B0930E9005EE226 /* AlteredPentads.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; name = AlteredPentads.playground; path = ../Playgrounds/AlteredPentads.playground; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
967070E81B0850AC00CB367E /* ChordExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChordExtensions.swift; sourceTree = "<group>"; };
967070EB1B08512A00CB367E /* ChordQualities.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChordQualities.swift; sourceTree = "<group>"; };
967070EE1B08649200CB367E /* ChordQualityTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChordQualityTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -536,6 +536,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
);
mainGroup = 96F299181A5663E500D7B006;
Expand Down Expand Up @@ -716,10 +717,6 @@
9691BB2E1A57C75500421B56 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
FRAMEWORK_SEARCH_PATHS = (
"$(SDKROOT)/Developer/Library/Frameworks",
"$(inherited)",
);
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
Expand All @@ -730,24 +727,20 @@
PRODUCT_BUNDLE_IDENTIFIER = "benzguo.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
9691BB2F1A57C75500421B56 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
FRAMEWORK_SEARCH_PATHS = (
"$(SDKROOT)/Developer/Library/Frameworks",
"$(inherited)",
);
INFOPLIST_FILE = MusicKitTests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.1;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "benzguo.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
VALIDATE_PRODUCT = YES;
};
name = Release;
Expand All @@ -765,15 +758,14 @@
"$(inherited)",
);
INFOPLIST_FILE = MusicKit/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 8.1;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "benzguo.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = MusicKit;
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
SWIFT_OBJC_BRIDGING_HEADER = "";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -787,15 +779,14 @@
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = MusicKit/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 8.1;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "benzguo.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = MusicKit;
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
SWIFT_OBJC_BRIDGING_HEADER = "";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
};
Expand Down Expand Up @@ -901,6 +892,7 @@
SKIP_INSTALL = YES;
SWIFT_OBJC_BRIDGING_HEADER = "";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -921,6 +913,7 @@
PRODUCT_NAME = MusicKit;
SKIP_INSTALL = YES;
SWIFT_OBJC_BRIDGING_HEADER = "";
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand All @@ -940,6 +933,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "benzguo.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -955,6 +949,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "benzguo.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
8 changes: 8 additions & 0 deletions MusicKit.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
32 changes: 16 additions & 16 deletions MusicKit/ChordQualities.swift
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import Foundation

public extension ChordQuality {
public static let Dyads = [
static let Dyads = [
ChordQuality.PowerChord,
]
public static let Triads = [
static let Triads = [
ChordQuality.Major,
ChordQuality.Minor,
ChordQuality.Augmented,
ChordQuality.Diminished,
ChordQuality.Sus2,
ChordQuality.Sus4,
]
public static let UnalteredTetrads = [
static let UnalteredTetrads = [
ChordQuality.DominantSeventh,
ChordQuality.MajorSeventh,
ChordQuality.MinorMajorSeventh,
Expand All @@ -22,7 +22,7 @@ ChordQuality.AugmentedSeventh,
ChordQuality.HalfDiminishedSeventh,
ChordQuality.DiminishedSeventh,
]
public static let AlteredTetrads = [
static let AlteredTetrads = [
ChordQuality.DominantSeventhFlatFive,
ChordQuality.MajorSeventhFlatFive,
ChordQuality.DominantSeventhSusFour,
Expand All @@ -39,7 +39,7 @@ ChordQuality.AddSharpEleven,
ChordQuality.MinorAddSharpEleven,
ChordQuality.AugmentedAddSharpEleven,
]
public static let UnalteredPentads = [
static let UnalteredPentads = [
ChordQuality.DominantNinth,
ChordQuality.MajorNinth,
ChordQuality.MinorMajorNinth,
Expand All @@ -49,7 +49,7 @@ ChordQuality.AugmentedNinth,
ChordQuality.HalfDiminishedNinth,
ChordQuality.DiminishedNinth,
]
public static let AlteredPentads = [
static let AlteredPentads = [
ChordQuality.DominantSeventhFlatNine,
ChordQuality.MajorSeventhFlatNine,
ChordQuality.MinorMajorSeventhFlatNine,
Expand All @@ -73,7 +73,7 @@ ChordQuality.DiminishedSeventhFlatThirteen,
ChordQuality.Dominant9Sus4,
ChordQuality.SixNine,
]
public static let UnalteredHexads = [
static let UnalteredHexads = [
ChordQuality.DominantEleventh,
ChordQuality.MajorEleventh,
ChordQuality.MinorMajorEleventh,
Expand All @@ -83,7 +83,7 @@ ChordQuality.AugmentedEleventh,
ChordQuality.HalfDiminishedEleventh,
ChordQuality.DiminishedEleventh,
]
public static let AlteredHexads = [
static let AlteredHexads = [
ChordQuality.DominantEleventhFlatNine,
ChordQuality.MajorEleventhFlatNine,
ChordQuality.MinorMajorEleventhFlatNine,
Expand Down Expand Up @@ -121,7 +121,7 @@ ChordQuality.MajorSeventhSharpElevenFlatThirteen,
ChordQuality.MinorMajorSeventhSharpElevenFlatThirteen,
ChordQuality.MinorSeventhSharpElevenFlatThirteen,
]
public static let UnalteredHeptads = [
static let UnalteredHeptads = [
ChordQuality.DominantThirteenth,
ChordQuality.MajorThirteenth,
ChordQuality.MinorMajorThirteenth,
Expand All @@ -131,7 +131,7 @@ ChordQuality.AugmentedThirteenth,
ChordQuality.HalfDiminishedThirteenth,
ChordQuality.DiminishedThirteenth,
]
public static let AlteredHeptads = [
static let AlteredHeptads = [
ChordQuality.DominantThirteenthFlatNine,
ChordQuality.MajorThirteenthFlatNine,
ChordQuality.MinorMajorThirteenthFlatNine,
Expand Down Expand Up @@ -173,11 +173,11 @@ ChordQuality.MajorSeventhFlatNineSharpElevenFlatThirteen,
ChordQuality.MinorMajorSeventhFlatNineSharpElevenFlatThirteen,
ChordQuality.MinorSeventhFlatNineSharpElevenFlatThirteen,
]
public static let Tetrads = ChordQuality.UnalteredTetrads + ChordQuality.AlteredTetrads
public static let Pentads = ChordQuality.UnalteredPentads + ChordQuality.AlteredPentads
public static let Hexads = ChordQuality.UnalteredHexads + ChordQuality.AlteredHexads
public static let Heptads = ChordQuality.UnalteredHeptads + ChordQuality.AlteredHeptads
public static let All = [
static let Tetrads = ChordQuality.UnalteredTetrads + ChordQuality.AlteredTetrads
static let Pentads = ChordQuality.UnalteredPentads + ChordQuality.AlteredPentads
static let Hexads = ChordQuality.UnalteredHexads + ChordQuality.AlteredHexads
static let Heptads = ChordQuality.UnalteredHeptads + ChordQuality.AlteredHeptads
static let All = [
ChordQuality.PowerChord,
ChordQuality.Major,
ChordQuality.Minor,
Expand Down Expand Up @@ -331,7 +331,7 @@ ChordQuality.MajorSeventhFlatNineSharpElevenFlatThirteen,
ChordQuality.MinorMajorSeventhFlatNineSharpElevenFlatThirteen,
ChordQuality.MinorSeventhFlatNineSharpElevenFlatThirteen,
]
public var name: String {
var name: String {
switch self {
case .PowerChord: return "PowerChord"
case .Major: return "Major"
Expand Down
10 changes: 7 additions & 3 deletions MusicKit/MIDI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import Foundation
import CoreMIDI
#if SWIFT_PACKAGE
import MKMIDIProc
#endif


open class MIDI {
/// Messages sent to the virtual MIDI source will be delivered on this channel.
Expand Down Expand Up @@ -63,11 +67,11 @@ open class MIDI {
let s = MIDIReceived(_virtualSource, packetList)
success = s == 0

packet.deinitialize()
packet.deinitialize(count: MemoryLayout<MIDIPacket>.size)
// this dealloc is superfluous; not sure why.
// packet.dealloc(sizeof(MIDIPacket))
packetList.deinitialize()
packetList.deallocate(capacity: MemoryLayout<MIDIPacketList>.size)
packetList.deinitialize(count: MemoryLayout<MIDIPacket>.size)
packetList.deallocate()
return success
}

Expand Down
3 changes: 3 additions & 0 deletions MusicKit/MIDIMessage.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Copyright (c) 2015 Ben Guo. All rights reserved.

import Foundation
#if SWIFT_PACKAGE
import MKMIDIProc
#endif

public protocol MIDIMessage {
/// The message's channel
Expand Down
4 changes: 2 additions & 2 deletions MusicKit/Pitch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ extension Pitch: CustomStringConvertible {

// MARK: Hashable
extension Pitch: Hashable {
public var hashValue: Int {
return midi.hashValue
public func hash(into hasher: inout Hasher) {
hasher.combine(midi)
}
}

Expand Down
14 changes: 7 additions & 7 deletions MusicKit/Temperament.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
// Copyright © 2017 benzguo. All rights reserved.
//

import Darwin

public struct Temperament: Equatable, Hashable {

public static let just = Temperament([1.0000, 1.0417, 1.1250, 1.2000,
Expand Down Expand Up @@ -82,15 +84,13 @@ public struct Temperament: Equatable, Hashable {
return lhs.ratios == rhs.ratios
}

public var hashValue: Int {
public func hash(into hasher: inout Hasher) {
if let ratio = ratios.first {
return ratios.dropFirst().reduce(ratio.hashValue, {
sum, value in
return sum ^ value.hashValue
hasher.combine(ratio)
ratios.dropFirst().forEach({
value in
hasher.combine(value)
})
}
else {
return 0
}
}
}
6 changes: 4 additions & 2 deletions MusicKit/Translation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ extension Translation:Equatable, Hashable {
lhs.numerals == rhs.numerals &&
lhs.showNatural == rhs.showNatural
}
public var hashValue: Int {
return self.language.hashValue ^ self.numerals.hashValue ^ self.showNatural.hashValue
public func hash(into hasher: inout Hasher) {
hasher.combine(self.language)
hasher.combine(self.numerals)
hasher.combine(self.showNatural)
}
}
1 change: 1 addition & 0 deletions MusicKit/include/headers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#import "../MusicKit.h"
Loading