Skip to content

Commit

Permalink
Merge pull request #26 from orchetect/dev
Browse files Browse the repository at this point in the history
Internal namespace update
  • Loading branch information
orchetect authored Aug 5, 2021
2 parents a8992da + 2d01a38 commit 59770c1
Show file tree
Hide file tree
Showing 19 changed files with 57 additions and 57 deletions.
2 changes: 1 addition & 1 deletion Sources/MIDIKit/Common/Types/MIDIKitIntegerProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ extension MIDIKitIntegerProtocol {
}

public init<T: BinaryInteger>(clamping source: T) {
let clamped = Storage(Int(source).clamped(to: Self.min(Int.self)...Self.max(Int.self)))
let clamped = Storage(Int(source).otcClamped(to: Self.min(Int.self)...Self.max(Int.self)))
self.init(clamped)
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/MIDIKit/Common/Types/UInt14.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ extension MIDI {
/// init(zeroMidpointFloat: 0.5) == 12287
/// init(zeroMidpointFloat: 1.0) == 16383 == .max
public init<T: BinaryFloatingPoint>(unitIntervalAroundZero: T) {
let unitIntervalAroundZero = unitIntervalAroundZero.clamped(to: (-1.0)...(1.0))
let unitIntervalAroundZero = unitIntervalAroundZero.otcClamped(to: (-1.0)...(1.0))

if unitIntervalAroundZero > 0.0 {
value = 8192 + Storage(unitIntervalAroundZero * 8191)
Expand Down
10 changes: 5 additions & 5 deletions Sources/MIDIKit/Common/Utilities/Clamped.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ extension Comparable {
// ie: 5.0.clamped(to: 7.0...10.0)
// ie: "a".clamped(to: "b"..."h")
/// Returns the value clamped to the passed range.
@inlinable internal func clamped(to limits: ClosedRange<Self>) -> Self {
@inlinable internal func otcClamped(to limits: ClosedRange<Self>) -> Self {

min(max(self, limits.lowerBound), limits.upperBound)

Expand All @@ -33,7 +33,7 @@ extension Comparable {
// ie: 5.0.clamped(to: 300.00...)
// ie: "a".clamped(to: "b"...)
/// Returns the value clamped to the passed range.
@inlinable internal func clamped(to limits: PartialRangeFrom<Self>) -> Self {
@inlinable internal func otcClamped(to limits: PartialRangeFrom<Self>) -> Self {

max(self, limits.lowerBound)

Expand All @@ -43,7 +43,7 @@ extension Comparable {
// ie: 400.0.clamped(to: ...300.0)
// ie: "k".clamped(to: ..."h")
/// Returns the value clamped to the passed range.
@inlinable internal func clamped(to limits: PartialRangeThrough<Self>) -> Self {
@inlinable internal func otcClamped(to limits: PartialRangeThrough<Self>) -> Self {

min(self, limits.upperBound)

Expand All @@ -61,7 +61,7 @@ extension Strideable {
// ie: 400.clamped(to: ..<300)
// won't work for String
/// Returns the value clamped to the passed range.
@inlinable internal func clamped(to limits: PartialRangeUpTo<Self>) -> Self {
@inlinable internal func otcClamped(to limits: PartialRangeUpTo<Self>) -> Self {

// advanced(by:) requires Strideable, not available on just Comparable
min(self, limits.upperBound.advanced(by: -1))
Expand All @@ -75,7 +75,7 @@ extension Strideable where Self.Stride: SignedInteger {
// ie: 5.clamped(to: 7..<10)
// won't work for String
/// Returns the value clamped to the passed range.
@inlinable internal func clamped(to limits: Range<Self>) -> Self {
@inlinable internal func otcClamped(to limits: Range<Self>) -> Self {

// index(before:) only available on SignedInteger
min(max(self, limits.lowerBound), limits.index(before: limits.upperBound))
Expand Down
4 changes: 2 additions & 2 deletions Sources/MIDIKit/Common/Utilities/SafeDispatchTimer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,14 @@ extension MIDI.SafeDispatchTimer {

switch self {
case .hertz(let hz):
value = 1.0 / hz.clamped(to: 0.00001...)
value = 1.0 / hz.otcClamped(to: 0.00001...)

case .seconds(let secs):
value = secs

}

return value.clamped(to: 0.000_000_001...) // 1 nanosecond min
return value.otcClamped(to: 0.000_000_001...) // 1 nanosecond min

}

Expand Down
16 changes: 8 additions & 8 deletions Sources/MIDIKit/Common/Utilities/String.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Foundation
extension String {

/// Wraps a string with double-quotes (`"`)
@inlinable internal var quoted: Self {
@inlinable internal var otcQuoted: Self {

"\"\(self)\""

Expand All @@ -37,7 +37,7 @@ extension StringProtocol {
///
/// "A string 123".only(.alphanumerics)`
///
public func only(_ characterSet: CharacterSet) -> String {
public func otcOnly(_ characterSet: CharacterSet) -> String {

self.map { characterSet.contains(UnicodeScalar("\($0)")!) ? "\($0)" : "" }
.joined()
Expand All @@ -46,23 +46,23 @@ extension StringProtocol {

/// **OTCore:**
/// Returns a string preserving only characters from the passed string and removing all other characters.
public func only(characters: String) -> String {
public func otcOnly(characters: String) -> String {

self.only(CharacterSet(charactersIn: characters))
self.otcOnly(CharacterSet(charactersIn: characters))

}

/// **OTCore:**
/// Returns a string containing only alphanumeric characters and removing all other characters.
public var onlyAlphanumerics: String {
public var otcOnlyAlphanumerics: String {

self.only(.alphanumerics)
self.otcOnly(.alphanumerics)

}

/// **OTCore:**
/// Returns a string removing all characters from the passed CharacterSet.
public func removing(_ characterSet: CharacterSet) -> String {
public func otcRemoving(_ characterSet: CharacterSet) -> String {

self.components(separatedBy: characterSet)
.joined()
Expand All @@ -71,7 +71,7 @@ extension StringProtocol {

/// **OTCore:**
/// Returns a string removing all characters from the passed string.
public func removing(characters: String) -> String {
public func otcRemoving(characters: String) -> String {

self.components(separatedBy: CharacterSet(charactersIn: characters))
.joined()
Expand Down
2 changes: 1 addition & 1 deletion Sources/MIDIKit/IO/CoreMIDI/CoreMIDI Connections.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ extension MIDI.IO {
result = MIDIThruConnectionDispose(thruConnection)

if result != noErr {
//Log.debug("MIDI: Persistent connections: deletion of connection matching owner ID \(persistentOwnerID.quoted) with number \(thruConnection) failed.")
//Log.debug("MIDI: Persistent connections: deletion of connection matching owner ID \(persistentOwnerID.otcQuoted) with number \(thruConnection) failed.")
} else {
disposeCount += 1
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/MIDIKit/IO/CoreMIDI/CoreMIDI Properties Get.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ extension MIDI.IO {
guard let unwrappedVal = val?.takeRetainedValue() else {
val?.release()
throw MIDI.IO.MIDIError.readError(
"Got nil while reading MIDIEndpointRef property value \((forProperty as String).quoted)"
"Got nil while reading MIDIEndpointRef property value \((forProperty as String).otcQuoted)"
)
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/MIDIKit/IO/Managed/Input.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ extension MIDI.IO.Input: CustomStringConvertible {
uniqueIDString = "\(unwrappedUniqueID)"
}

return "Input(name: \(endpointName.quoted), uniqueID: \(uniqueIDString))"
return "Input(name: \(endpointName.otcQuoted), uniqueID: \(uniqueIDString))"

}

Expand Down
2 changes: 1 addition & 1 deletion Sources/MIDIKit/IO/Managed/InputConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ extension MIDI.IO.InputConnection: CustomStringConvertible {
var outputEndpointName: String = "?"
if let unwrappedOutputEndpointRef = outputEndpointRef,
let getName = try? MIDI.IO.getName(of: unwrappedOutputEndpointRef) {
outputEndpointName = "\(getName)".quoted
outputEndpointName = "\(getName)".otcQuoted
}

var outputEndpointRefString: String = "nil"
Expand Down
2 changes: 1 addition & 1 deletion Sources/MIDIKit/IO/Managed/Output.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ extension MIDI.IO.Output: CustomStringConvertible {
uniqueIDString = "\(unwrappedUniqueID)"
}

return "Output(name: \(endpointName.quoted), uniqueID: \(uniqueIDString))"
return "Output(name: \(endpointName.otcQuoted), uniqueID: \(uniqueIDString))"

}

Expand Down
2 changes: 1 addition & 1 deletion Sources/MIDIKit/IO/Managed/OutputConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ extension MIDI.IO.OutputConnection: CustomStringConvertible {
var inputEndpointName: String = "?"
if let unwrappedInputEndpointRef = inputEndpointRef,
let getName = try? MIDI.IO.getName(of: unwrappedInputEndpointRef) {
inputEndpointName = "\(getName)".quoted
inputEndpointName = "\(getName)".otcQuoted
}

var inputEndpointRefString: String = "nil"
Expand Down
2 changes: 1 addition & 1 deletion Sources/MIDIKit/IO/Managed/ThruConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ extension MIDI.IO.ThruConnection {
// Log.debug("MIDI: Thru Connection: Successfully formed non-persistent connection.")
//
//case .persistent(let ownerID):
// Log.debug("MIDI: Thru Connection: Successfully formed persistent connection with ID //\(ownerID.quoted).")
// Log.debug("MIDI: Thru Connection: Successfully formed persistent connection with ID //\(ownerID.otcQuoted).")
//}

}
Expand Down
2 changes: 1 addition & 1 deletion Sources/MIDIKit/IO/Manager/Manager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ extension MIDI.IO {
) {

// set up dedicated manager queue
var clientNameForQueue = clientName.onlyAlphanumerics
var clientNameForQueue = clientName.otcOnlyAlphanumerics
if clientNameForQueue.isEmpty { clientNameForQueue = UUID().uuidString }
let queueName = (Bundle.main.bundleIdentifier ?? "unknown") + ".midiManager." + clientNameForQueue
queue = DispatchQueue(label: queueName,
Expand Down
2 changes: 1 addition & 1 deletion Sources/MIDIKit/IO/Objects/Device/Device.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ extension MIDI.IO.Device {
extension MIDI.IO.Device: CustomDebugStringConvertible {

public var debugDescription: String {
"Device(name: \(name.quoted), uniqueID: \(uniqueID), exists: \(exists)"
"Device(name: \(name.otcQuoted), uniqueID: \(uniqueID), exists: \(exists)"
}

}
Expand Down
4 changes: 2 additions & 2 deletions Sources/MIDIKit/IO/Objects/Endpoint/EndpointIDCriteria.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ extension MIDI.IO.EndpointIDCriteria: CustomStringConvertible {

switch self {
case .name(let endpointName):
return "EndpointName: \(endpointName.quoted)"
return "EndpointName: \(endpointName.otcQuoted)"

case .displayName(let displayName):
return "EndpointDisplayName: \(displayName.quoted))"
return "EndpointDisplayName: \(displayName.otcQuoted))"

case .uniqueID(let uID):
return "UniqueID: \(uID)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ extension MIDI.IO.InputEndpoint {
extension MIDI.IO.InputEndpoint: CustomDebugStringConvertible {

public var debugDescription: String {
"InputEndpoint(name: \(name.quoted), uniqueID: \(uniqueID), exists: \(exists)"
"InputEndpoint(name: \(name.otcQuoted), uniqueID: \(uniqueID), exists: \(exists)"
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ extension MIDI.IO.OutputEndpoint {
extension MIDI.IO.OutputEndpoint: CustomDebugStringConvertible {

public var debugDescription: String {
"OutputEndpoint(name: \(name.quoted), uniqueID: \(uniqueID), exists: \(exists)"
"OutputEndpoint(name: \(name.otcQuoted), uniqueID: \(uniqueID), exists: \(exists)"
}

}
2 changes: 1 addition & 1 deletion Sources/MIDIKit/IO/Objects/Entity/Entity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ extension MIDI.IO.Entity {
extension MIDI.IO.Entity: CustomDebugStringConvertible {

public var debugDescription: String {
"Entity(name: \(name.quoted), uniqueID: \(uniqueID), exists: \(exists)"
"Entity(name: \(name.otcQuoted), uniqueID: \(uniqueID), exists: \(exists)"
}

}
52 changes: 26 additions & 26 deletions Tests/MIDIKitTests/Common/Utilities/Clamped Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,50 +24,50 @@ class Utilities_ClampedTests: XCTestCase {

// .clamped(ClosedRange)

XCTAssertEqual( 5.clamped(to: 7...10), 7 )
XCTAssertEqual( 8.clamped(to: 7...10), 8 )
XCTAssertEqual( 20.clamped(to: 7...10), 10 )
XCTAssertEqual( 5.otcClamped(to: 7...10), 7 )
XCTAssertEqual( 8.otcClamped(to: 7...10), 8 )
XCTAssertEqual( 20.otcClamped(to: 7...10), 10 )

XCTAssertEqual( 5.0.clamped(to: 7.0...10.0), 7.0)
XCTAssertEqual( 8.0.clamped(to: 7.0...10.0), 8.0)
XCTAssertEqual( 20.0.clamped(to: 7.0...10.0), 10.0)
XCTAssertEqual( 5.0.otcClamped(to: 7.0...10.0), 7.0)
XCTAssertEqual( 8.0.otcClamped(to: 7.0...10.0), 8.0)
XCTAssertEqual( 20.0.otcClamped(to: 7.0...10.0), 10.0)

XCTAssertEqual( "a".clamped(to: "b"..."h"), "b" )
XCTAssertEqual( "c".clamped(to: "b"..."h"), "c" )
XCTAssertEqual( "k".clamped(to: "b"..."h"), "h" )
XCTAssertEqual( "a".otcClamped(to: "b"..."h"), "b" )
XCTAssertEqual( "c".otcClamped(to: "b"..."h"), "c" )
XCTAssertEqual( "k".otcClamped(to: "b"..."h"), "h" )

// .clamped(Range)

XCTAssertEqual( 5.clamped(to: 7..<10), 7 )
XCTAssertEqual( 8.clamped(to: 7..<10), 8 )
XCTAssertEqual( 20.clamped(to: 7..<10), 9 )
XCTAssertEqual( 5.otcClamped(to: 7..<10), 7 )
XCTAssertEqual( 8.otcClamped(to: 7..<10), 8 )
XCTAssertEqual( 20.otcClamped(to: 7..<10), 9 )

// .clamped(PartialRangeFrom)

XCTAssertEqual( 5.clamped(to: 300...), 300 )
XCTAssertEqual( 400.clamped(to: 300...), 400 )
XCTAssertEqual( 5.otcClamped(to: 300...), 300 )
XCTAssertEqual( 400.otcClamped(to: 300...), 400 )

XCTAssertEqual( 5.0.clamped(to: 300.00...), 300.0)
XCTAssertEqual(400.0.clamped(to: 300.00...), 400.0)
XCTAssertEqual( 5.0.otcClamped(to: 300.00...), 300.0)
XCTAssertEqual(400.0.otcClamped(to: 300.00...), 400.0)

XCTAssertEqual( "a".clamped(to: "b"...), "b" )
XCTAssertEqual( "g".clamped(to: "b"...), "g" )
XCTAssertEqual( "a".otcClamped(to: "b"...), "b" )
XCTAssertEqual( "g".otcClamped(to: "b"...), "g" )

// .clamped(PartialRangeThrough)

XCTAssertEqual(200 .clamped(to: ...300), 200 )
XCTAssertEqual(400 .clamped(to: ...300), 300 )
XCTAssertEqual(200 .otcClamped(to: ...300), 200 )
XCTAssertEqual(400 .otcClamped(to: ...300), 300 )

XCTAssertEqual(200.0.clamped(to: ...300.0), 200.0)
XCTAssertEqual(400.0.clamped(to: ...300.0), 300.0)
XCTAssertEqual(200.0.otcClamped(to: ...300.0), 200.0)
XCTAssertEqual(400.0.otcClamped(to: ...300.0), 300.0)

XCTAssertEqual( "a".clamped(to: ..."h"), "a" )
XCTAssertEqual( "k".clamped(to: ..."h"), "h" )
XCTAssertEqual( "a".otcClamped(to: ..."h"), "a" )
XCTAssertEqual( "k".otcClamped(to: ..."h"), "h" )

// .clamped(PartialRangeUpTo)

XCTAssertEqual(200 .clamped(to: ..<300), 200 )
XCTAssertEqual(400 .clamped(to: ..<300), 299 )
XCTAssertEqual(200 .otcClamped(to: ..<300), 200 )
XCTAssertEqual(400 .otcClamped(to: ..<300), 299 )

}

Expand Down

0 comments on commit 59770c1

Please sign in to comment.