Skip to content

Commit 815e5ae

Browse files
committed
init commit
1 parent beec04e commit 815e5ae

File tree

4 files changed

+245
-0
lines changed

4 files changed

+245
-0
lines changed

Knob+Touches.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
// Knob+Touches.swift
3+
// Swift Synth
4+
//
5+
// Created by Matthew Fecher on 1/9/16.
6+
// Copyright © 2016 AudioKit. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
extension Knob {
12+
13+
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
14+
for touch in touches {
15+
let touchPoint = touch.location(in: self)
16+
lastX = touchPoint.x
17+
lastY = touchPoint.y
18+
}
19+
}
20+
21+
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
22+
for touch in touches {
23+
let touchPoint = touch.location(in: self)
24+
setPercentagesWithTouchPoint(touchPoint)
25+
}
26+
}
27+
28+
}

KnobStyleKit.swift

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
//
2+
// KnobStyleKit.swift
3+
// UISpike
4+
//
5+
// Created by Matthew Fecher on 7/20/17.
6+
// Copyright © 2017 AudioKit. All rights reserved.
7+
//
8+
// Generated by PaintCode
9+
// http://www.paintcodeapp.com
10+
//
11+
// This code was generated by Trial version of PaintCode, therefore cannot be used for commercial purposes.
12+
//
13+
14+
15+
16+
import Cocoa
17+
18+
public class KnobStyleKit : NSObject {
19+
20+
//// Drawing Methods
21+
22+
@objc dynamic public class func drawKnobCanvas(frame targetFrame: NSRect = NSRect(x: 0, y: 0, width: 120, height: 120), resizing: ResizingBehavior = .aspectFit, knobValue: CGFloat = 1) {
23+
//// General Declarations
24+
let context = NSGraphicsContext.current()!.cgContext
25+
26+
//// Resize to Target Frame
27+
NSGraphicsContext.saveGraphicsState()
28+
let resizedFrame: NSRect = resizing.apply(rect: NSRect(x: 0, y: 0, width: 120, height: 120), target: targetFrame)
29+
context.translateBy(x: resizedFrame.minX, y: resizedFrame.minY)
30+
context.scaleBy(x: resizedFrame.width / 120, y: resizedFrame.height / 120)
31+
let resizedShadowScale: CGFloat = min(resizedFrame.width / 120, resizedFrame.height / 120)
32+
33+
34+
//// Color Declarations
35+
let black = NSColor(red: 0, green: 0, blue: 0, alpha: 1)
36+
let shadowColor = NSColor(red: 1, green: 0.596, blue: 0, alpha: 1)
37+
let knobBottom = NSColor(red: 0.18, green: 0.18, blue: 0.192, alpha: 1)
38+
let knobLight = NSColor(red: 0.498, green: 0.498, blue: 0.51, alpha: 1)
39+
let knobTop2 = NSColor(red: 0.141, green: 0.141, blue: 0.161, alpha: 1)
40+
let orange2 = NSColor(red: 0.902, green: 0.533, blue: 0.008, alpha: 1)
41+
42+
//// Gradient Declarations
43+
let edge2 = NSGradient(colors: [knobBottom, knobBottom.blended(withFraction: 0.5, of: knobTop2)!, knobTop2, knobTop2.blended(withFraction: 0.5, of: knobLight)!, knobLight], atLocations: [0.0, 0.23, 0.41, 0.73, 1.0], colorSpace: NSColorSpace.sRGB)!
44+
let lowerKnobGradient2 = NSGradient(colors: [knobTop2, knobBottom, knobLight], atLocations: [0.0, 0.51, 1.0], colorSpace: NSColorSpace.sRGB)!
45+
46+
//// Shadow Declarations
47+
let shadow2 = NSShadow()
48+
shadow2.shadowColor = NSColor.black.withAlphaComponent(0.46)
49+
shadow2.shadowOffset = NSSize(width: 2, height: -8)
50+
shadow2.shadowBlurRadius = 5
51+
let shadow3 = NSShadow()
52+
shadow3.shadowColor = knobLight.withAlphaComponent(0.41 * knobLight.alphaComponent)
53+
shadow3.shadowOffset = NSSize(width: 0, height: -10)
54+
shadow3.shadowBlurRadius = 5
55+
let shadow4 = NSShadow()
56+
shadow4.shadowColor = shadowColor
57+
shadow4.shadowOffset = NSSize(width: 0, height: 0)
58+
shadow4.shadowBlurRadius = 12
59+
60+
//// Variable Declarations
61+
let knobAngle: CGFloat = -240 * knobValue
62+
63+
//// Knob
64+
//// BlackBackground Drawing
65+
let blackBackgroundPath = NSBezierPath(ovalIn: NSRect(x: 0, y: 0, width: 120, height: 120))
66+
black.setFill()
67+
blackBackgroundPath.fill()
68+
69+
70+
//// GradientKnob 2 Drawing
71+
let gradientKnob2Path = NSBezierPath(ovalIn: NSRect(x: 9, y: 9, width: 102, height: 102))
72+
lowerKnobGradient2.draw(in: gradientKnob2Path, angle: 90)
73+
74+
75+
//// GradientKnob Drawing
76+
let gradientKnobPath = NSBezierPath(ovalIn: NSRect(x: 15, y: 15, width: 90, height: 90))
77+
NSGraphicsContext.saveGraphicsState()
78+
context.setShadow(offset: NSSize(width: shadow2.shadowOffset.width * resizedShadowScale, height: shadow2.shadowOffset.height * resizedShadowScale), blur: shadow2.shadowBlurRadius * resizedShadowScale, color: shadow2.shadowColor!.cgColor)
79+
context.beginTransparencyLayer(auxiliaryInfo: nil)
80+
edge2.draw(in: gradientKnobPath, angle: 90)
81+
context.endTransparencyLayer()
82+
83+
////// GradientKnob Inner Shadow
84+
NSGraphicsContext.saveGraphicsState()
85+
NSRectClip(gradientKnobPath.bounds)
86+
context.setShadow(offset: NSSize.zero, blur: 0, color: nil)
87+
88+
context.setAlpha(shadow3.shadowColor!.alphaComponent)
89+
context.beginTransparencyLayer(auxiliaryInfo: nil)
90+
let gradientKnobOpaqueShadow = NSShadow()
91+
gradientKnobOpaqueShadow.shadowColor = shadow3.shadowColor!.withAlphaComponent(1)
92+
gradientKnobOpaqueShadow.shadowOffset = NSSize(width: shadow3.shadowOffset.width * resizedShadowScale, height: shadow3.shadowOffset.height * resizedShadowScale)
93+
gradientKnobOpaqueShadow.shadowBlurRadius = shadow3.shadowBlurRadius * resizedShadowScale
94+
gradientKnobOpaqueShadow.set()
95+
96+
context.setBlendMode(.sourceOut)
97+
context.beginTransparencyLayer(auxiliaryInfo: nil)
98+
99+
gradientKnobOpaqueShadow.shadowColor!.setFill()
100+
gradientKnobPath.fill()
101+
102+
context.endTransparencyLayer()
103+
context.endTransparencyLayer()
104+
NSGraphicsContext.restoreGraphicsState()
105+
106+
NSGraphicsContext.restoreGraphicsState()
107+
108+
109+
110+
//// IndicatorGroup
111+
//// Indicator Drawing
112+
NSGraphicsContext.saveGraphicsState()
113+
context.translateBy(x: 60, y: 60)
114+
context.rotate(by: (knobAngle - 240) * CGFloat.pi/180)
115+
116+
let indicatorPath = NSBezierPath(rect: NSRect(x: -3, y: 29, width: 6, height: 17))
117+
NSGraphicsContext.saveGraphicsState()
118+
context.setShadow(offset: NSSize(width: shadow4.shadowOffset.width * resizedShadowScale, height: shadow4.shadowOffset.height * resizedShadowScale), blur: shadow4.shadowBlurRadius * resizedShadowScale, color: shadow4.shadowColor!.cgColor)
119+
orange2.setFill()
120+
indicatorPath.fill()
121+
NSGraphicsContext.restoreGraphicsState()
122+
123+
124+
NSGraphicsContext.restoreGraphicsState()
125+
126+
NSGraphicsContext.restoreGraphicsState()
127+
128+
}
129+
130+
131+
132+
133+
@objc(KnobStyleKitResizingBehavior)
134+
public enum ResizingBehavior: Int {
135+
case aspectFit /// The content is proportionally resized to fit into the target rectangle.
136+
case aspectFill /// The content is proportionally resized to completely fill the target rectangle.
137+
case stretch /// The content is stretched to match the entire target rectangle.
138+
case center /// The content is centered in the target rectangle, but it is NOT resized.
139+
140+
public func apply(rect: NSRect, target: NSRect) -> NSRect {
141+
if rect == target || target == NSRect.zero {
142+
return rect
143+
}
144+
145+
var scales = NSSize.zero
146+
scales.width = abs(target.width / rect.width)
147+
scales.height = abs(target.height / rect.height)
148+
149+
switch self {
150+
case .aspectFit:
151+
scales.width = min(scales.width, scales.height)
152+
scales.height = scales.width
153+
case .aspectFill:
154+
scales.width = max(scales.width, scales.height)
155+
scales.height = scales.width
156+
case .stretch:
157+
break
158+
case .center:
159+
scales.width = 1
160+
scales.height = 1
161+
}
162+
163+
var result = rect.standardized
164+
result.size.width *= scales.width
165+
result.size.height *= scales.height
166+
result.origin.x = target.minX + (target.width - result.width) / 2
167+
result.origin.y = target.minY + (target.height - result.height) / 2
168+
return result
169+
}
170+
}
171+
}

KnobView.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// KnobView.swift
3+
// SynthUISpike
4+
//
5+
// Created by Matthew Fecher on 7/20/17.
6+
// Copyright © 2017 Matthew Fecher. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
class KnobView: UIView {
12+
13+
/*
14+
// Only override draw() if you perform custom drawing.
15+
// An empty implementation adversely affects performance during animation.
16+
override func draw(_ rect: CGRect) {
17+
// Drawing code
18+
}
19+
*/
20+
21+
}

SynthUISpike/Assets.xcassets/AppIcon.appiconset/Contents.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
{
22
"images" : [
3+
{
4+
"idiom" : "iphone",
5+
"size" : "20x20",
6+
"scale" : "2x"
7+
},
8+
{
9+
"idiom" : "iphone",
10+
"size" : "20x20",
11+
"scale" : "3x"
12+
},
313
{
414
"idiom" : "iphone",
515
"size" : "29x29",
@@ -30,6 +40,16 @@
3040
"size" : "60x60",
3141
"scale" : "3x"
3242
},
43+
{
44+
"idiom" : "ipad",
45+
"size" : "20x20",
46+
"scale" : "1x"
47+
},
48+
{
49+
"idiom" : "ipad",
50+
"size" : "20x20",
51+
"scale" : "2x"
52+
},
3353
{
3454
"idiom" : "ipad",
3555
"size" : "29x29",
@@ -59,6 +79,11 @@
5979
"idiom" : "ipad",
6080
"size" : "76x76",
6181
"scale" : "2x"
82+
},
83+
{
84+
"idiom" : "ipad",
85+
"size" : "83.5x83.5",
86+
"scale" : "2x"
6287
}
6388
],
6489
"info" : {

0 commit comments

Comments
 (0)