Skip to content

Commit

Permalink
Merge pull request #1 from cemolcay/classify
Browse files Browse the repository at this point in the history
Separate structs and type enums for Note, Scale and Chord
  • Loading branch information
cemolcay authored Jan 7, 2017
2 parents b0a6d55 + f3a11d9 commit 3a2b6f9
Show file tree
Hide file tree
Showing 40 changed files with 9,592 additions and 1,093 deletions.
9 changes: 5 additions & 4 deletions AudioKitHelper/AudioKitHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public class MTScaleOscillator: MTOscillator {
}

public func generateSound() -> Int {
let randomNote = scale.notes.randomElement()
return randomNote.midiKey(octave: octave)
let notes = scale.notes(octave: octave)
return notes.randomElement().midiNote
}

public func playRandom() {
Expand All @@ -57,14 +57,15 @@ public class MTChordOscillator {

public init(chord: Chord) {
self.chord = chord
banks = chord.notes.map({ _ in MTOscillator() })
banks = chord.notes(octave: octave).map({ _ in MTOscillator() })
output = AKMixer()
banks.forEach({ output.connect($0.output) })
}

public func play() {
let notes = chord.notes(octave: octave)
for i in 0..<banks.count {
banks[i].play(midi: chord.notes[i].midiKey(octave: octave))
banks[i].play(midi: notes[i].midiNote)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>AudioKitHelper.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>2</integer>
<integer>5</integer>
</dict>
<key>MusicTheory.xcscheme</key>
<dict>
Expand All @@ -17,7 +17,7 @@
<key>MusicTheoryTests.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
<integer>4</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
Expand Down
84 changes: 44 additions & 40 deletions MusicTheory/Dataset.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,52 +8,48 @@

import Foundation

// MARK: - Scale Extension
public extension Scale {
// MARK: - ScaleType Extension

/// Generates an array of all `Scale` values based on desired `Note`.
///
/// - Parameter key: The `Note` value of scales base.
/// - Returns: All scales in desired key `Note`.
public static func all(of key: Note) -> [Scale] {
public extension ScaleType {

/// An array of all `ScaleType` values.
public static var all: [ScaleType] {
return [
.major(key: key),
.minor(key: key),
.harmonicMinor(key: key),
.dorian(key: key),
.phrygian(key: key),
.lydian(key: key),
.mixolydian(key: key),
.locrian(key: key)
.major,
.minor,
.harmonicMinor,
.dorian,
.phrygian,
.lydian,
.mixolydian,
.locrian
]
}
}

// MARK: - Chord Extension
public extension Chord {
// MARK: - ChordType Extension

/// Generates an array of all `Chord` values based on desired `Note`.
///
/// - Parameter key: The `Note` value of chords base.
/// - Returns: All Chords in desired key `Note`.
public static func all(of key: Note) -> [Chord] {
public extension ChordType {

/// An array of all `ChordType` values.
public static var all: [ChordType] {
return [
.maj(key: key),
.min(key: key),
.aug(key: key),
.b5(key: key),
.dim(key: key),
.sus(key: key),
.sus2(key: key),
.M6(key: key),
.m6(key: key),
.dom7(key: key),
.M7(key: key),
.m7(key: key),
.aug7(key: key),
.dim7(key: key),
.M7b5(key: key),
.m7b5(key: key)
.maj,
.min,
.aug,
.b5,
.dim,
.sus,
.sus2,
.M6,
.m6,
.dom7,
.M7,
.m7,
.aug7,
.dim7,
.M7b5,
.m7b5
]
}
}
Expand All @@ -66,7 +62,11 @@ public class Dataset {
/// - Returns: Returns array of midi note sequences which are also array of `Int`s.
public class func generateAllScales() -> [[Int]] {
var scales = [[Int]]()
Note.all.forEach({ Scale.all(of: $0).forEach({ scales.append($0.midiNotes) }) })
for scale in ScaleType.all {
for note in NoteType.all {
scales.append(Scale(type: scale, key: note).notes(octave: 0).map({ $0.midiNote }))
}
}
return scales
}

Expand All @@ -75,7 +75,11 @@ public class Dataset {
/// - Returns: Returns array of midi note sequences which are also array of `Int`s.
public class func generateAllChords() -> [[Int]] {
var chords = [[Int]]()
Note.all.forEach({ Chord.all(of: $0).forEach({ chords.append($0.midiNotes) }) })
for chord in ChordType.all {
for note in NoteType.all {
chords.append(Chord(type: chord, key: note).notes(octave: 0).map({ $0.midiNote }))
}
}
return chords
}
}
Loading

0 comments on commit 3a2b6f9

Please sign in to comment.