Skip to content

Commit

Permalink
Update minor errors, logic, clarify definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
roux buciu committed May 2, 2020
1 parent 3e0ebfe commit 686c143
Show file tree
Hide file tree
Showing 30 changed files with 1,771 additions and 1,254 deletions.
Binary file added Swift Musicology/.DS_Store
Binary file not shown.
775 changes: 637 additions & 138 deletions Swift Musicology/Swift Musicology.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?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>SchemeUserState</key>
<dict>
<key>Swift Musicology.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
<key>SwiftMusicology iOS.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>2</integer>
</dict>
<key>SwiftMusicology macOS.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>5</integer>
</dict>
<key>SwiftMusicology tvOS.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>4</integer>
</dict>
<key>SwiftMusicology watchOS.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>3</integer>
</dict>
<key>SwiftMusicology.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
</dict>
</dict>
</dict>
</plist>
200 changes: 103 additions & 97 deletions Swift Musicology/Swift Musicology/Accidental.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,101 @@

import Foundation

/// Used for calculating values of the `Key`s and `Pitche`s.
// MARK: - Accidental Operations

/// Returns a new accidental by adding up two accidentals in the equation.
///
/// - Parameters:
/// - lhs: Left hand side of the equation.
/// - rhs: Right hand side of the equation.
/// - Returns: Returns the sum of two accidentals.
public func + (lhs: Accidental, rhs: Accidental) -> Accidental {
return Accidental(integerLiteral: lhs.rawValue + rhs.rawValue)
}

/// Returns a new accidental by substracting two accidentals in the equation.
///
/// - Parameters:
/// - lhs: Left hand side of the equation.
/// - rhs: Right hand side of the equation.
/// - Returns: Returns the difference of two accidentals.
public func - (lhs: Accidental, rhs: Accidental) -> Accidental {
return Accidental(integerLiteral: lhs.rawValue - rhs.rawValue)
}

/// Returns a new accidental by adding up an int to the accidental in the equation.
///
/// - Parameters:
/// - lhs: Left hand side of the equation.
/// - rhs: Right hand side of the equation.
/// - Returns: Returns the sum of two accidentals.
public func + (lhs: Accidental, rhs: Int) -> Accidental {
return Accidental(integerLiteral: lhs.rawValue + rhs)
}

/// Returns a new accidental by substracting an int from the accidental in the equation.
///
/// - Parameters:
/// - lhs: Left hand side of the equation.
/// - rhs: Right hand side of the equation.
/// - Returns: Returns the difference of two accidentals.
public func - (lhs: Accidental, rhs: Int) -> Accidental {
return Accidental(integerLiteral: lhs.rawValue - rhs)
}

/// Multiples an accidental with a multiplier.
///
/// - Parameters:
/// - lhs: Accidental you want to multiply.
/// - rhs: Multiplier.
/// - Returns: Returns a multiplied acceident.
public func * (lhs: Accidental, rhs: Int) -> Accidental {
return Accidental(integerLiteral: lhs.rawValue * rhs)
}

/// Divides an accidental with a multiplier
///
/// - Parameters:
/// - lhs: Accidental you want to divide.
/// - rhs: Multiplier.
/// - Returns: Returns a divided accidental.
public func / (lhs: Accidental, rhs: Int) -> Accidental {
return Accidental(integerLiteral: lhs.rawValue / rhs)
}

/// Checks if the two accidental is identical in terms of their semitone values.
///
/// - Parameters:
/// - lhs: Left hand side of the equation.
/// - rhs: Right hand side of the equation.
/// - Returns: Returns true if two accidentalals is identical.
public func == (lhs: Accidental, rhs: Accidental) -> Bool {
return lhs.rawValue == rhs.rawValue
}

/// Checks if the two accidental is exactly identical.
///
/// - Parameters:
/// - lhs: Left hand side of the equation.
/// - rhs: Right hand side of the equation.
/// - Returns: Returns true if two accidentalals is identical.
public func === (lhs: Accidental, rhs: Accidental) -> Bool {
switch (lhs, rhs) {
case (.natural, .natural):
return true
case let (.sharps(a), .sharps(b)):
return a == b
case let (.flats(a), .flats(b)):
return a == b
default:
return false
}
}


// MARK: - Accidental Definitions

/// Used for calculating values of the `Key` and `Pitch` objects.
public enum Accidental: Codable, Equatable, Hashable {

// Base definition of accidentals.
Expand All @@ -20,15 +114,19 @@ public enum Accidental: Codable, Equatable, Hashable {
case sharps(amount: Int)


// Human friendly definition of accidentals.
/// Reduce the `Key` or `Pitch` value one semitone below
public static let flat: Accidental = .flats(amount: 1)
/// Increases the `Key` or `Pitch` value one semitone above.
public static let sharp: Accidental = .sharps(amount: 1)
/// Reduces the `Key` or `Pitch` value amount two semitones below.
public static let doubleFlat: Accidental = .flats(amount: 2)
/// Increases the `Key` or `Pitch` value two semitones above.
public static let doubleSharp: Accidental = .sharps(amount: 2)

/// A flag for `description` function that determines if it should use double sharp
/// and double flat symbols. It's useful to set it to `false` where fonts do not
/// support those symbols. Defaults to `true`.
/// A flag for the `description` function that determines if it should use double
/// sharp and double flat symbols. This is mostly useful for instances where fonts
/// do not support those types of symbols; in that case, set to `false`.
/// Defaults to `true`.
public static var shouldUseDoubleFlatAndDoubleSharpNotation = true
}

Expand Down Expand Up @@ -132,95 +230,3 @@ extension Accidental: CustomStringConvertible {
}
}
}


// MARK: - Accidental Operations

/// Returns a new accidental by adding up two accidentals in the equation.
///
/// - Parameters:
/// - lhs: Left hand side of the equation.
/// - rhs: Right hand side of the equation.
/// - Returns: Returns the sum of two accidentals.
public func + (lhs: Accidental, rhs: Accidental) -> Accidental {
return Accidental(integerLiteral: lhs.rawValue + rhs.rawValue)
}

/// Returns a new accidental by substracting two accidentals in the equation.
///
/// - Parameters:
/// - lhs: Left hand side of the equation.
/// - rhs: Right hand side of the equation.
/// - Returns: Returns the difference of two accidentals.
public func - (lhs: Accidental, rhs: Accidental) -> Accidental {
return Accidental(integerLiteral: lhs.rawValue - rhs.rawValue)
}

/// Returns a new accidental by adding up an int to the accidental in the equation.
///
/// - Parameters:
/// - lhs: Left hand side of the equation.
/// - rhs: Right hand side of the equation.
/// - Returns: Returns the sum of two accidentals.
public func + (lhs: Accidental, rhs: Int) -> Accidental {
return Accidental(integerLiteral: lhs.rawValue + rhs)
}

/// Returns a new accidental by substracting an int from the accidental in the equation.
///
/// - Parameters:
/// - lhs: Left hand side of the equation.
/// - rhs: Right hand side of the equation.
/// - Returns: Returns the difference of two accidentals.
public func - (lhs: Accidental, rhs: Int) -> Accidental {
return Accidental(integerLiteral: lhs.rawValue - rhs)
}

/// Multiples an accidental with a multiplier.
///
/// - Parameters:
/// - lhs: Accidental you want to multiply.
/// - rhs: Multiplier.
/// - Returns: Returns a multiplied acceident.
public func * (lhs: Accidental, rhs: Int) -> Accidental {
return Accidental(integerLiteral: lhs.rawValue * rhs)
}

/// Divides an accidental with a multiplier
///
/// - Parameters:
/// - lhs: Accidental you want to divide.
/// - rhs: Multiplier.
/// - Returns: Returns a divided accidental.
public func / (lhs: Accidental, rhs: Int) -> Accidental {
return Accidental(integerLiteral: lhs.rawValue / rhs)
}

/// Checks if the two accidental is identical in terms of their semitone values.
///
/// - Parameters:
/// - lhs: Left hand side of the equation.
/// - rhs: Right hand side of the equation.
/// - Returns: Returns true if two accidentalals is identical.
public func == (lhs: Accidental, rhs: Accidental) -> Bool {
return lhs.rawValue == rhs.rawValue
}

/// Checks if the two accidental is exactly identical.
///
/// - Parameters:
/// - lhs: Left hand side of the equation.
/// - rhs: Right hand side of the equation.
/// - Returns: Returns true if two accidentalals is identical.
public func === (lhs: Accidental, rhs: Accidental) -> Bool {
switch (lhs, rhs) {
case (.natural, .natural):
return true
case let (.sharps(a), .sharps(b)):
return a == b
case let (.flats(a), .flats(b)):
return a == b
default:
return false
}
}
Loading

0 comments on commit 686c143

Please sign in to comment.