Skip to content

Commit 6a774fa

Browse files
committed
Swift 3 conversion, 2nd pass
Signed-off-by: Guillaume Laurent <glaurent@telegraph-road.org>
1 parent 6e51080 commit 6a774fa

File tree

5 files changed

+31
-31
lines changed

5 files changed

+31
-31
lines changed

Source/Calculators/NoteCalculator.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ public struct NoteCalculator {
1717
// MARK: - Bounds
1818

1919
public static var indexBounds: (minimum: Int, maximum: Int) {
20-
let minimum = try! index(frequency: Config.minimumFrequency)
21-
let maximum = try! index(frequency: Config.maximumFrequency)
20+
let minimum = try! index(Config.minimumFrequency)
21+
let maximum = try! index(Config.maximumFrequency)
2222

2323
return (minimum: minimum, maximum: maximum)
2424
}
2525

2626
public static var octaveBounds: (minimum: Int, maximum: Int) {
2727
let bounds = indexBounds
28-
let minimum = try! octave(index: bounds.minimum)
29-
let maximum = try! octave(index: bounds.maximum)
28+
let minimum = try! octave(bounds.minimum)
29+
let maximum = try! octave(bounds.maximum)
3030

3131
return (minimum: minimum, maximum: maximum)
3232
}
@@ -49,7 +49,7 @@ public struct NoteCalculator {
4949

5050
// MARK: - Pitch Notations
5151

52-
public static func frequency(index: Int) throws -> Double {
52+
public static func frequency(_ index: Int) throws -> Double {
5353
guard isValidIndex(index) else {
5454
throw PitchError.invalidPitchIndex
5555
}
@@ -60,7 +60,7 @@ public struct NoteCalculator {
6060
return pow(2, power) * Standard.frequency
6161
}
6262

63-
public static func letter(index: Int) throws -> Note.Letter {
63+
public static func letter(_ index: Int) throws -> Note.Letter {
6464
guard isValidIndex(index) else {
6565
throw PitchError.invalidPitchIndex
6666
}
@@ -81,7 +81,7 @@ public struct NoteCalculator {
8181
return letters[lettersIndex]
8282
}
8383

84-
public static func octave(index: Int) throws -> Int {
84+
public static func octave(_ index: Int) throws -> Int {
8585
guard isValidIndex(index) else {
8686
throw PitchError.invalidPitchIndex
8787
}
@@ -98,7 +98,7 @@ public struct NoteCalculator {
9898

9999
// MARK: - Pitch Index
100100

101-
public static func index(frequency: Double) throws -> Int {
101+
public static func index(_ frequency: Double) throws -> Int {
102102
guard PitchCalculator.isValidFrequency(frequency) else {
103103
throw PitchError.invalidFrequency
104104
}
@@ -108,7 +108,7 @@ public struct NoteCalculator {
108108
return Int(round(count * log2(frequency / Standard.frequency)))
109109
}
110110

111-
public static func index(letter: Note.Letter, octave: Int) throws -> Int {
111+
public static func index(_ letter: Note.Letter, octave: Int) throws -> Int {
112112
guard isValidOctave(octave) else {
113113
throw PitchError.invalidOctave
114114
}

Source/Calculators/PitchCalculator.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,21 @@ public struct PitchCalculator {
2727
frequency: frequency - note.frequency,
2828
percentage: (frequency - note.frequency) * 100
2929
/ abs(note.frequency - closestNote.frequency),
30-
cents: try cents(frequency1: note.frequency, frequency2: frequency)
30+
cents: try cents(note.frequency, frequency2: frequency)
3131
)
3232

3333
let secondOffset = Pitch.Offset(
3434
note: closestNote,
3535
frequency: frequency - closestNote.frequency,
3636
percentage: (frequency - closestNote.frequency) * 100
3737
/ abs(note.frequency - closestNote.frequency),
38-
cents: try cents(frequency1: closestNote.frequency, frequency2: frequency)
38+
cents: try cents(closestNote.frequency, frequency2: frequency)
3939
)
4040

4141
return Pitch.Offsets(firstOffset, secondOffset)
4242
}
4343

44-
public static func cents(frequency1: Double, frequency2: Double) throws -> Double {
44+
public static func cents(_ frequency1: Double, frequency2: Double) throws -> Double {
4545
guard isValidFrequency(frequency1)
4646
&& isValidFrequency(frequency2)
4747
else { throw PitchError.invalidFrequency }

Source/Calculators/WaveCalculator.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ public struct WaveCalculator {
1111

1212
public static var periodBounds: (minimum: Double, maximum: Double) {
1313
let bounds = wavelengthBounds
14-
let minimum = try! period(wavelength: bounds.minimum)
15-
let maximum = try! period(wavelength: bounds.maximum)
14+
let minimum = try! period(bounds.minimum)
15+
let maximum = try! period(bounds.maximum)
1616

1717
return (minimum: minimum, maximum: maximum)
1818
}
@@ -37,31 +37,31 @@ public struct WaveCalculator {
3737

3838
// MARK: - Conversions
3939

40-
public static func frequency(wavelength: Double) throws -> Double {
40+
public static func frequency(_ wavelength: Double) throws -> Double {
4141
guard isValidWavelength(wavelength) else {
4242
throw PitchError.invalidWavelength
4343
}
4444

4545
return AcousticWave.speed / wavelength
4646
}
4747

48-
public static func wavelength(frequency: Double) throws -> Double {
48+
public static func wavelength(frequency frequency: Double) throws -> Double {
4949
guard PitchCalculator.isValidFrequency(frequency) else {
5050
throw PitchError.invalidFrequency
5151
}
5252

5353
return AcousticWave.speed / frequency
5454
}
5555

56-
public static func wavelength(period: Double) throws -> Double {
56+
public static func wavelength(period period: Double) throws -> Double {
5757
guard isValidPeriod(period) else {
5858
throw PitchError.invalidPeriod
5959
}
6060

6161
return period * AcousticWave.speed
6262
}
6363

64-
public static func period(wavelength: Double) throws -> Double {
64+
public static func period(_ wavelength: Double) throws -> Double {
6565
guard isValidWavelength(wavelength) else {
6666
throw PitchError.invalidWavelength
6767
}

Source/Data/AcousticWave.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public struct AcousticWave {
2727

2828
self.frequency = frequency
2929
wavelength = try WaveCalculator.wavelength(frequency: frequency)
30-
period = try WaveCalculator.period(wavelength: wavelength)
30+
period = try WaveCalculator.period(wavelength)
3131
}
3232

3333
public init(wavelength: Double) throws {
@@ -36,8 +36,8 @@ public struct AcousticWave {
3636
}
3737

3838
self.wavelength = wavelength
39-
frequency = try WaveCalculator.frequency(wavelength: wavelength)
40-
period = try WaveCalculator.period(wavelength: wavelength)
39+
frequency = try WaveCalculator.frequency(wavelength)
40+
period = try WaveCalculator.period(wavelength)
4141
}
4242

4343
public init(period: Double) throws {
@@ -47,6 +47,6 @@ public struct AcousticWave {
4747

4848
self.period = period
4949
wavelength = try WaveCalculator.wavelength(period: period)
50-
frequency = try WaveCalculator.frequency(wavelength: wavelength)
50+
frequency = try WaveCalculator.frequency(wavelength)
5151
}
5252
}

Source/Data/Note.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,25 @@ public struct Note {
3434

3535
public init(index: Int) throws {
3636
self.index = index
37-
letter = try NoteCalculator.letter(index: index)
38-
octave = try NoteCalculator.octave(index: index)
39-
frequency = try NoteCalculator.frequency(index: index)
37+
letter = try NoteCalculator.letter(index)
38+
octave = try NoteCalculator.octave(index)
39+
frequency = try NoteCalculator.frequency(index)
4040
wave = try AcousticWave(frequency: frequency)
4141
}
4242

4343
public init(frequency: Double) throws {
44-
index = try NoteCalculator.index(frequency: frequency)
45-
letter = try NoteCalculator.letter(index: index)
46-
octave = try NoteCalculator.octave(index: index)
47-
self.frequency = try NoteCalculator.frequency(index: index)
44+
index = try NoteCalculator.index(frequency)
45+
letter = try NoteCalculator.letter(index)
46+
octave = try NoteCalculator.octave(index)
47+
self.frequency = try NoteCalculator.frequency(index)
4848
wave = try AcousticWave(frequency: frequency)
4949
}
5050

5151
public init(letter: Letter, octave: Int) throws {
5252
self.letter = letter
5353
self.octave = octave
54-
index = try NoteCalculator.index(letter: letter, octave: octave)
55-
frequency = try NoteCalculator.frequency(index: index)
54+
index = try NoteCalculator.index(letter, octave: octave)
55+
frequency = try NoteCalculator.frequency(index)
5656
wave = try AcousticWave(frequency: frequency)
5757
}
5858

0 commit comments

Comments
 (0)