Skip to content

Commit 5e35a92

Browse files
authored
Merge pull request #1 from AudioKit/stress-testing
Pre release (code review needed)
2 parents 27aed9a + 34296c5 commit 5e35a92

File tree

10 files changed

+69
-55
lines changed

10 files changed

+69
-55
lines changed

Demo/MIDITrackViewDemo.xcodeproj/project.pbxproj

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10-
607E99BD2B0D0D97005D1988 /* RUSH_E_FINAL.mid in Resources */ = {isa = PBXBuildFile; fileRef = 607E99BC2B0D0D97005D1988 /* RUSH_E_FINAL.mid */; };
11-
607E99BE2B0D0D97005D1988 /* RUSH_E_FINAL.mid in Resources */ = {isa = PBXBuildFile; fileRef = 607E99BC2B0D0D97005D1988 /* RUSH_E_FINAL.mid */; };
1210
608EEBB42A16DC2B00C88590 /* Sounds in Resources */ = {isa = PBXBuildFile; fileRef = 608EEBB32A16DC2B00C88590 /* Sounds */; };
1311
608EEBB52A16DC2B00C88590 /* Sounds in Resources */ = {isa = PBXBuildFile; fileRef = 608EEBB32A16DC2B00C88590 /* Sounds */; };
1412
60A16CD72A18485400F225CB /* MIDITrackData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60A16CD62A18485400F225CB /* MIDITrackData.swift */; };
@@ -33,7 +31,6 @@
3331
/* End PBXBuildFile section */
3432

3533
/* Begin PBXFileReference section */
36-
607E99BC2B0D0D97005D1988 /* RUSH_E_FINAL.mid */ = {isa = PBXFileReference; lastKnownFileType = audio.midi; path = RUSH_E_FINAL.mid; sourceTree = "<group>"; };
3734
608EEBB32A16DC2B00C88590 /* Sounds */ = {isa = PBXFileReference; lastKnownFileType = folder; path = Sounds; sourceTree = "<group>"; };
3835
608EEBB62A16E84400C88590 /* MIDITrackViewDemo--iOS--Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = "MIDITrackViewDemo--iOS--Info.plist"; sourceTree = "<group>"; };
3936
60A16CD62A18485400F225CB /* MIDITrackData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MIDITrackData.swift; sourceTree = "<group>"; };
@@ -99,7 +96,6 @@
9996
608EEBB32A16DC2B00C88590 /* Sounds */,
10097
60B0B5222A12D56900DAAAF7 /* type0Demo.mid */,
10198
60C33E91296AA0C60066D196 /* type1Demo.mid */,
102-
607E99BC2B0D0D97005D1988 /* RUSH_E_FINAL.mid */,
10399
60A16CD92A1848E000F225CB /* Conductor.swift */,
104100
60A16CD62A18485400F225CB /* MIDITrackData.swift */,
105101
60D3325F2915C6B300EAD0D7 /* MIDITrackViewDemo.swift */,
@@ -227,7 +223,6 @@
227223
60D332622915C6B400EAD0D7 /* Assets.xcassets in Resources */,
228224
60B0B5242A12D56900DAAAF7 /* type0Demo.mid in Resources */,
229225
608EEBB52A16DC2B00C88590 /* Sounds in Resources */,
230-
607E99BE2B0D0D97005D1988 /* RUSH_E_FINAL.mid in Resources */,
231226
60C33E93296AA0C60066D196 /* type1Demo.mid in Resources */,
232227
);
233228
runOnlyForDeploymentPostprocessing = 0;
@@ -239,7 +234,6 @@
239234
60D332882915CAA300EAD0D7 /* Assets.xcassets in Resources */,
240235
60B0B5232A12D56900DAAAF7 /* type0Demo.mid in Resources */,
241236
608EEBB42A16DC2B00C88590 /* Sounds in Resources */,
242-
607E99BD2B0D0D97005D1988 /* RUSH_E_FINAL.mid in Resources */,
243237
60C33E92296AA0C60066D196 /* type1Demo.mid in Resources */,
244238
);
245239
runOnlyForDeploymentPostprocessing = 0;
@@ -467,7 +461,7 @@
467461
CODE_SIGN_STYLE = Automatic;
468462
CURRENT_PROJECT_VERSION = 1;
469463
DEVELOPMENT_ASSET_PATHS = "";
470-
DEVELOPMENT_TEAM = 6CV59M265C;
464+
DEVELOPMENT_TEAM = "";
471465
ENABLE_PREVIEWS = YES;
472466
GENERATE_INFOPLIST_FILE = YES;
473467
INFOPLIST_FILE = "MIDITrackViewDemo--iOS--Info.plist";
@@ -499,7 +493,7 @@
499493
CODE_SIGN_STYLE = Automatic;
500494
CURRENT_PROJECT_VERSION = 1;
501495
DEVELOPMENT_ASSET_PATHS = "";
502-
DEVELOPMENT_TEAM = 6CV59M265C;
496+
DEVELOPMENT_TEAM = "";
503497
ENABLE_PREVIEWS = YES;
504498
GENERATE_INFOPLIST_FILE = YES;
505499
INFOPLIST_FILE = "MIDITrackViewDemo--iOS--Info.plist";

Demo/Shared/Conductor.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ class Conductor {
2626
drumsData = MIDITrackData(length: 0.0, height: 0.0, noteData: [])
2727
return
2828
}
29+
2930
midiInstrument.enableLooping()
3031
midiInstrument.loadMIDIFile(fromURL: url)
32+
3133
let arpNotes = midiInstrument.tracks[1].getMIDINoteData()
3234
let arpLength = midiInstrument.tracks[1].length
3335
let bassNotes = midiInstrument.tracks[2].getMIDINoteData()
@@ -36,6 +38,7 @@ class Conductor {
3638
let padLength = midiInstrument.tracks[3].length
3739
let drumNotes = midiInstrument.tracks[4].getMIDINoteData()
3840
let drumLength = midiInstrument.tracks[4].length
41+
3942
arpData = MIDITrackData(length: arpLength, height: 200.0, noteData: arpNotes)
4043
bassData = MIDITrackData(length: bassLength, height: 200.0, noteData: bassNotes)
4144
chordsData = MIDITrackData(length: padLength, height: 200.0, noteData: padNotes)

Demo/Shared/MIDITrackData.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import MIDITrackView
66

77
/// A class for holding the MIDINoteData to display in the MIDITrackView
88
class MIDITrackData {
9-
var midiNotes: [CGRect] = []
9+
var noteRects: [CGRect] = []
1010
var length: CGFloat = 0.0
1111
var height: CGFloat = 200.0
1212
var highNote: MIDINoteNumber = 0
@@ -28,7 +28,7 @@ class MIDITrackData {
2828
for note in noteData {
2929
let noteLevel = maxHeight - CGFloat(note.noteNumber - lowNote) * noteHeight
3030
let noteRect = CGRect(x: note.position.beats, y: noteLevel, width: note.duration.beats, height: self.noteHeight)
31-
self.midiNotes.append(noteRect)
31+
self.noteRects.append(noteRect)
3232
}
3333
}
3434
}

Demo/Shared/MIDITrackViewDemo.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ struct MIDITrackViewDemo: View {
2525

2626
init(conductor: Conductor) {
2727
self.conductor = conductor
28-
self.arpModel = MIDITrackViewModel(midiNotes: conductor.arpData.midiNotes, length: conductor.arpData.length, height: conductor.arpData.height, playPos: conductor.midiInstrument.currentPosition.beats, zoomLevel: 50.0, minimumZoom: 0.01, maximumZoom: 1000.0)
29-
self.chordsModel = MIDITrackViewModel(midiNotes: conductor.chordsData.midiNotes, length: conductor.chordsData.length, height: conductor.chordsData.height, playPos: conductor.midiInstrument.currentPosition.beats, zoomLevel: 50.0, minimumZoom: 0.01, maximumZoom: 1000.0)
30-
self.bassModel = MIDITrackViewModel(midiNotes: conductor.bassData.midiNotes, length: conductor.bassData.length, height: conductor.bassData.height, playPos: conductor.midiInstrument.currentPosition.beats, zoomLevel: 50.0, minimumZoom: 0.01, maximumZoom: 1000.0)
31-
self.drumsModel = MIDITrackViewModel(midiNotes: conductor.drumsData.midiNotes, length: conductor.drumsData.length, height: conductor.drumsData.height, playPos: conductor.midiInstrument.currentPosition.beats, zoomLevel: 50.0, minimumZoom: 0.01, maximumZoom: 1000.0)
28+
self.arpModel = MIDITrackViewModel(noteRects: conductor.arpData.noteRects, length: conductor.arpData.length, height: conductor.arpData.height, playhead: conductor.midiInstrument.currentPosition.beats, zoomLevel: 50.0, minimumZoom: 0.01, maximumZoom: 1000.0)
29+
self.chordsModel = MIDITrackViewModel(noteRects: conductor.chordsData.noteRects, length: conductor.chordsData.length, height: conductor.chordsData.height, playhead: conductor.midiInstrument.currentPosition.beats, zoomLevel: 50.0, minimumZoom: 0.01, maximumZoom: 1000.0)
30+
self.bassModel = MIDITrackViewModel(noteRects: conductor.bassData.noteRects, length: conductor.bassData.length, height: conductor.bassData.height, playhead: conductor.midiInstrument.currentPosition.beats, zoomLevel: 50.0, minimumZoom: 0.01, maximumZoom: 1000.0)
31+
self.drumsModel = MIDITrackViewModel(noteRects: conductor.drumsData.noteRects, length: conductor.drumsData.length, height: conductor.drumsData.height, playhead: conductor.midiInstrument.currentPosition.beats, zoomLevel: 50.0, minimumZoom: 0.01, maximumZoom: 1000.0)
3232
self.isPlaying = false
3333
self.timer = Timer.publish(every: 0.01, on: .main, in: .common).autoconnect()
3434
}

Demo/Shared/RUSH_E_FINAL.mid

-9.23 MB
Binary file not shown.

MIDITrackView.playground/Contents.swift

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,17 @@ import SwiftUI
44

55
struct MIDITrackViewDemo: View {
66
@State var model = MIDITrackViewModel(
7-
midiNotes: [
8-
MIDINote(position: 80, level: 5, length: 102, height: 5),
9-
MIDINote(position: 103, level: 23, length: 75, height: 5),
10-
MIDINote(position: 157, level: 36, length: 25, height: 5),
11-
MIDINote(position: 208, level: 5, length: 102, height: 5),
12-
MIDINote(position: 301, level: 23, length: 75, height: 5),
13-
MIDINote(position: 376, level: 36, length: 25, height: 5),
14-
MIDINote(position: 402, level: 5, length: 102, height: 5),
15-
MIDINote(position: 450, level: 23, length: 75, height: 5),
16-
MIDINote(position: 500, level: 36, length: 25, height: 5)
7+
noteRects: [
8+
CGRect(x: 0.5, y: 0.0, width: 1.0, height: 10.0),
9+
CGRect(x: 1.0, y: 20.0, width: 1.0, height: 10.0),
10+
CGRect(x: 1.5, y: 40.0, width: 5.0, height: 10.0)
1711
],
1812
length: 500,
19-
height: 200
13+
height: 200,
14+
playPos: 0.0,
15+
zoomLevel: 50.0,
16+
minimumZoom: 0.01,
17+
maximumZoom: 1000.0
2018
)
2119
public var body: some View {
2220
VStack {

Sources/MIDITrackView/Documentation.docc/Documentation.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,5 @@ This ``MIDITrackView`` provides a similar user interface to one seen in a Digita
1212

1313
### Properties
1414
- ``MIDITrackView/MIDITrackView/model``
15-
- ``MIDITrackView/MIDITrackView/playPos``
16-
- ``MIDITrackView/MIDITrackView/zoomLevel``
17-
- ``MIDITrackView/MIDITrackView/note``
1815
- ``MIDITrackView/MIDITrackView/trackColor``
1916
- ``MIDITrackView/MIDITrackView/noteColor``
20-
- ``MIDITrackView/MIDITrackView/playheadColor``
21-
- ``MIDITrackView/MIDITrackView/minimumZoom``
22-
- ``MIDITrackView/MIDITrackView/maximumZoom``
23-
- ``MIDITrackView/MIDITrackView/note``
444 KB
Loading

Sources/MIDITrackView/MIDITrackView.swift

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
import SwiftUI
44

5+
struct MIDINotesView: Shape {
6+
let noteRects: [CGRect]
7+
func path(in rect: CGRect) -> Path {
8+
var path = Path().path(in: rect)
9+
path.addRects(noteRects)
10+
return path
11+
}
12+
}
13+
514
/// A view representing a MIDI Track.
615
public struct MIDITrackView: View {
716
/// The model for the view which contains an array of MIDI notes (as `CGRect`), the track length, and the track height.
@@ -10,20 +19,24 @@ public struct MIDITrackView: View {
1019
private let trackColor: Color
1120
/// The color of the notes on the track.
1221
private let noteColor: Color
13-
public init(model: Binding<MIDITrackViewModel>, trackColor: SwiftUI.Color = Color.primary, noteColor: SwiftUI.Color = Color.accentColor) {
22+
public init(model: Binding<MIDITrackViewModel>,
23+
trackColor: SwiftUI.Color = Color.primary,
24+
noteColor: SwiftUI.Color = Color.accentColor) {
1425
_model = model
1526
self.trackColor = trackColor
1627
self.noteColor = noteColor
1728
}
1829

1930
public var body: some View {
20-
Canvas { context, size in
21-
context.scaleBy(x: model.getZoomLevel(), y: 1.0)
22-
context.fill(Rectangle().path(in: CGRect(x: 0.0, y: 0.0, width: model.getLength(), height: model.getHeight())), with: .color(trackColor))
23-
context.translateBy(x: -model.getPlayPos(), y: 0.0)
24-
var notePath = Path()
25-
notePath.addRects(model.getMIDINotes())
26-
context.fill(notePath, with: .color(noteColor))
31+
ZStack {
32+
RoundedRectangle(cornerRadius: 10.0).fill(trackColor)
33+
MIDINotesView(noteRects: model.getNoteRects())
34+
.transform(CGAffineTransformConcat(
35+
CGAffineTransform(translationX: -model.getPlayhead(), y: 0.0),
36+
CGAffineTransform(scaleX: model.getZoomLevel(), y: 1.0))
37+
)
38+
.fill(noteColor)
2739
}
40+
.drawingGroup()
2841
}
2942
}

Sources/MIDITrackView/MIDITrackViewModel.swift

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,26 @@
33
import SwiftUI
44

55
public struct MIDITrackViewModel {
6-
public init(midiNotes: [CGRect], length: CGFloat, height: CGFloat, playPos: Double, zoomLevel: Double, minimumZoom: Double, maximumZoom: Double) {
7-
self.midiNotes = midiNotes
6+
/// The model which holds data for the MIDITrackView
7+
/// - Parameters:
8+
/// - noteRects: the note rectangles rendered in the view
9+
/// - length: the length of the longest track
10+
/// - height: the height of the MIDI track
11+
/// - playhead: the playhead of the MIDI track
12+
/// - zoomLevel: the zoom level of the MIDI track
13+
/// - minimumZoom: the minimum zoom level for the MIDI track
14+
/// - maximumZoom: the maximum zoom level for the MIDI track
15+
public init(noteRects: [CGRect],
16+
length: CGFloat,
17+
height: CGFloat,
18+
playhead: Double,
19+
zoomLevel: Double,
20+
minimumZoom: Double,
21+
maximumZoom: Double) {
22+
self.noteRects = noteRects
823
self.length = length
924
self.height = height
10-
self.playPos = playPos
25+
self.playhead = playhead
1126
self.zoomLevel = zoomLevel
1227
self.minimumZoom = minimumZoom
1328
self.maximumZoom = maximumZoom
@@ -24,25 +39,23 @@ public struct MIDITrackViewModel {
2439
zoomLevel = max(min(newScale, maximumZoom), minimumZoom)
2540
}
2641
public mutating func zoomLevelGestureEnded() { lastZoomLevel = 1.0 }
27-
public mutating func updatePlayPos(newPos: Double) { playPos = newPos }
42+
public mutating func updatePlayPos(newPos: Double) { playhead = newPos }
43+
/// Get the zoom level of all the tracks in the view
2844
public func getZoomLevel() -> Double { return zoomLevel }
45+
/// Get the length of the longest track.
2946
public func getLength() -> CGFloat { return length }
47+
/// Get the height of all the tracks in the view.
3048
public func getHeight() -> CGFloat { return height }
31-
public func getPlayPos() -> Double { return playPos }
32-
public func getMIDINotes() -> [CGRect] { return midiNotes }
33-
/// The notes rendered in the view.
34-
private let midiNotes: [CGRect]
35-
/// The length of the longest track.
49+
/// The view's current play position (also the position which the playhead displays)
50+
public func getPlayhead() -> Double { return playhead }
51+
/// Get the note rectangles rendered in the view.
52+
public func getNoteRects() -> [CGRect] { return noteRects }
53+
private let noteRects: [CGRect]
3654
private let length: CGFloat
37-
/// The height of all the tracks in the view.
3855
private let height: CGFloat
39-
/// The view's current play position (also the position which the playhead displays)
40-
private var playPos: Double
41-
/// The zoom level of all the tracks in the view
56+
private var playhead: Double
4257
private var zoomLevel: Double
43-
/// The minimum zoom level.
4458
private let minimumZoom: Double
45-
/// The maximum zoom level.
4659
private let maximumZoom: Double
4760
private var lastZoomLevel: Double = 1.0
4861
}

0 commit comments

Comments
 (0)