Skip to content

Commit

Permalink
0.0.2
Browse files Browse the repository at this point in the history
Update Swift 4.2
Add FretboardScrollView
  • Loading branch information
cemolcay committed Sep 21, 2018
1 parent ac5a424 commit 2d9134a
Show file tree
Hide file tree
Showing 17 changed files with 815 additions and 663 deletions.
4 changes: 2 additions & 2 deletions Examples/Example Mac/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class ViewController: NSViewController {
override func viewDidLoad() {
super.viewDidLoad()

let chord = Chord(type: .maj, key: .e)
let firstPosition = chord.notes(octaves: fretboardView?.fretboard.octaves ?? [2, 3, 4])
let chord = Chord(type: ChordType(third: .major), key: Key(type: .e))
let firstPosition = chord.pitches(octaves: fretboardView?.fretboard.octaves ?? [2, 3, 4])
fretboardView?.fretboard.direction = .vertical
fretboardView?.fretboard.startIndex = 0
fretboardView?.isChordModeOn = true
Expand Down
3 changes: 1 addition & 2 deletions Examples/Example TV/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
// Override point for customization after application launch.
return true
}
Expand Down
2 changes: 1 addition & 1 deletion Examples/Example TV/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()

let chord = Chord(type: .maj, key: .a)
let chord = Chord(type: ChordType(third: .major), key: Key(type: .a))

verticalFretboard?.fretboard.direction = .vertical
verticalFretboard?.fretboard.select(chord: chord)
Expand Down
3 changes: 1 addition & 2 deletions Examples/Example iOS/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
// Override point for customization after application launch.
return true
}
Expand Down
5 changes: 3 additions & 2 deletions Examples/Example iOS/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12118" systemVersion="16E195" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14313.18" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12086"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14283.14"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand Down
2 changes: 1 addition & 1 deletion Examples/Example iOS/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()

let chord = Chord(type: .maj, key: .a)
let chord = Chord(type: ChordType(third: .major), key: Key(type: .a))
fretboardView?.fretboard.select(chord: chord)
}
}
Expand Down
4 changes: 2 additions & 2 deletions Fretboard.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Pod::Spec.new do |s|
#

s.name = "Fretboard"
s.version = "0.0.1"
s.version = "0.0.2"
s.summary = "Customisable guitar fretboard view for iOS, tvOS and macOS with CoreGraphics"

# This description is used to generate tags and improve search results.
Expand Down Expand Up @@ -54,7 +54,7 @@ Demo
Requierments
----
* Swift 3.0+
* Swift 4.0+
* iOS 8.0+
* tvOS 9.0+
* macOS 10.9+
Expand Down
239 changes: 121 additions & 118 deletions Fretboard.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions Fretboard.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?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>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
11 changes: 6 additions & 5 deletions Podfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
swift_version="4.2"

target 'Fretboard iOS' do
use_frameworks!
Expand Down Expand Up @@ -34,8 +35,8 @@ target 'Example TV' do
pod 'Fretboard', :path => '.'
end

post_install do |installer|
installer.pods_project.build_configurations.each do |config|
config.build_settings['LD_RUNPATH_SEARCH_PATHS'] = ['$(FRAMEWORK_SEARCH_PATHS)']
end
end
#post_install do |installer|
# installer.pods_project.build_configurations.each do |config|
# config.build_settings['LD_RUNPATH_SEARCH_PATHS'] = ['$(FRAMEWORK_SEARCH_PATHS)']
# end
#end
19 changes: 12 additions & 7 deletions Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
PODS:
- CenterTextLayer (0.0.1)
- CenterTextLayer (0.0.2)
- Fretboard (0.0.1):
- CenterTextLayer
- MusicTheorySwift
- MusicTheorySwift (0.0.4)
- MusicTheorySwift (1.1.0)

DEPENDENCIES:
- CenterTextLayer
- Fretboard (from `.`)
- MusicTheorySwift

SPEC REPOS:
https://github.com/cocoapods/specs.git:
- CenterTextLayer
- MusicTheorySwift

EXTERNAL SOURCES:
Fretboard:
:path: "."

SPEC CHECKSUMS:
CenterTextLayer: 8ba737f794769c3bd0e3f28706b9edf6f787fbb7
Fretboard: 52ffccd4b5dde4428faf24c9ec0eca93cebb167e
MusicTheorySwift: 213563918695d0a2fa37a805a0ad63b090a12bfe
CenterTextLayer: 7fe5dab46ba3372c527f09a518a84f8be4a89e38
Fretboard: a98553977498e9a8629b0868c166ee2e7e984d32
MusicTheorySwift: 555d61fc174c36c7cb1a41cf20b54628ba6b3e32

PODFILE CHECKSUM: 3dcd1672aaf5baed9a47f386522228bed9ac645a
PODFILE CHECKSUM: 77ea5853003049ea9ee9a7142d1a75d5b1974978

COCOAPODS: 1.2.1.beta.1
COCOAPODS: 1.6.0.beta.1
27 changes: 19 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Demo
Requierments
----

* Swift 3.0+
* Swift 4.0+
* iOS 8.0+
* tvOS 9.0+
* macOS 10.9+
Expand All @@ -51,13 +51,13 @@ Fretboard uses [`MusicTheory`](https://github.com/cemolcay/MusicTheory) library
You need to select/unselect notes, chords or scales on `fretboard` property of your `FretboardView` instance.

``` swift
let chord = Chord(type: .maj, key: .a)
let chord = Chord(type: ChordType(third: .major), key: Key(type: .a))
fretboardView?.fretboard.select(chord: chord)

let scale = Scale(type: .major, key: .e)
let scale = Scale(type: .major, key: Key(type: .e, accidental: .flat))
fretboardView?.fretboard.select(scale: scale)

let note = Note(type: .a, octave: 2)
let note = Pitch(key: Key(type: .a), octave: 2)
fretboardView?.fretboard.select(note: note)

fretboardView?.fretboard.unselect(note: note)
Expand All @@ -76,10 +76,10 @@ Also, you can define custom tunings with `CustomTuning` struct with custom strin
``` swift
let tuning = CustomTuning(
strings: [
Note(type: .g, octave: 2),
Note(type: .d, octave: 2),
Note(type: .a, octave: 1),
Note(type: .e, octave: 1)
Pitch(key: Key(type: .g), octave: 2),
Pitch(key: Key(type: .d), octave: 2),
Pitch(key: Key(type: .a), octave: 1),
Pitch(key: Key(type: .e), octave: 1)
],
description: "My Custom Tuning")
fretboardView?.fretboard.tuning = tuning
Expand Down Expand Up @@ -108,6 +108,17 @@ Rendering note names on pressed notes and optional.
Also rendering fret numbers and strings names are optional too.
See the properties of `FretboardView`.

### FretboardScrollView

There is also a scroll view you can use in your iOS/tvOS/macOS apps that you can scroll your fretboard inside it. It has a `FretboardView` instance you can customise your fretboard directly.

``` swift
@IBOutlet weak var scrollView: FretboardScrollView?
scrollView?.fretboardView.fretStartIndex = appState.fretStartIndex
scrollView?.fretboardView.fretCount = appState.fretCount
scrollView?.fretboardView.fretboard.tuning = appState.tuning.tuning
```

FretBud
----

Expand Down
10 changes: 5 additions & 5 deletions Source/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@
for i in 0 ..< self.elementCount {
let type = self.element(at: i, associatedPoints: &points)
switch type {
case .moveToBezierPathElement:
case .moveTo:
path.move(to: points[0])
case .lineToBezierPathElement:
case .lineTo:
path.addLine(to: points[0])
case .curveToBezierPathElement:
case .curveTo:
path.addCurve(to: points[2], control1: points[0], control2: points[1])
case .closePathBezierPathElement:
case .closePath:
path.closeSubpath()
}
}
Expand All @@ -55,7 +55,7 @@

extension Collection where Indices.Iterator.Element == Index {
/// Returns the element at the specified index iff it is within bounds, otherwise nil.
subscript (safe index: Index) -> Generator.Element? {
subscript (safe index: Index) -> Iterator.Element? {
return indices.contains(index) ? self[index] : nil
}
}
22 changes: 11 additions & 11 deletions Source/Fretboard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public func ==(left: FretboardNote?, right: FretboardNote?) -> Bool {
/// Describes a note in fretboard.
public class FretboardNote {
/// Note that fretboard has.
public var note: Note
public var note: Pitch

/// Index of fret on fretboard.
public var fretIndex: Int
Expand All @@ -45,7 +45,7 @@ public class FretboardNote {
/// Initilizes with note value.
///
/// - Parameter note: Note on fretboard.
public init(note: Note, fretIndex: Int, stringIndex: Int) {
public init(note: Pitch, fretIndex: Int, stringIndex: Int) {
self.note = note
self.fretIndex = fretIndex
self.stringIndex = stringIndex
Expand Down Expand Up @@ -165,29 +165,29 @@ public class Fretboard {
/// Returns tuned strings by its direction.
/// Left to right higher pitches in vertical direction.
/// Bottom to top higer pitches in horizontal direction.
var strings: [Note] {
var strings: [Pitch] {
return direction == .horizontal ? tuning.strings.reversed() : tuning.strings
}

/// Returns sorted octave range in fretboard.
public var octaves: [Int] {
return Set<Int>(notes.flatMap({ $0 }).map({ $0.note.octave })).sorted()
return Set<Int>(notes.compactMap({ $0 }).map({ $0.note.octave })).sorted()
}

// MARK: Note Selection

/// Marks selected the notes in fretboard.
///
/// - Parameter note: To be selected note in fretboard.
public func select(note: Note) {
public func select(note: Pitch) {
notes.filter({ $0.note == note }).forEach({ $0.isSelected = true })
delegate?.fretboad(self, didSelectedNotesChange: notes)
}

/// Marks the notes selected in fretboard
///
/// - Parameter notes: Notes to be selected.
public func select(notes: [Note]) {
public func select(notes: [Pitch]) {
let hasNote: (FretboardNote) -> Bool = { fret in
return notes.contains(where: { $0 == fret.note })
}
Expand All @@ -200,8 +200,8 @@ public class Fretboard {
///
/// - Parameter chord: To be selected notes of chord in fretboard.
public func select(chord: Chord) {
let notes = chord.notes(octaves: octaves)
let hasNote: (Note) -> Bool = { note in
let notes = chord.pitches(octaves: octaves)
let hasNote: (Pitch) -> Bool = { note in
return notes.contains(where: { $0 == note })
}

Expand All @@ -213,8 +213,8 @@ public class Fretboard {
///
/// - Parameter scale: To be selected notes of scale in fretboard.
public func select(scale: Scale) {
let notes = scale.notes(octaves: octaves)
let hasNote: (Note) -> Bool = { note in
let notes = scale.pitches(octaves: octaves)
let hasNote: (Pitch) -> Bool = { note in
return notes.contains(where: { $0 == note })
}

Expand All @@ -225,7 +225,7 @@ public class Fretboard {
/// Marks unselect the notes in fretboard if its already selected.
///
/// - Parameter note: To be unselected note in fretboard.
public func unselect(note: Note) {
public func unselect(note: Pitch) {
notes.filter({ $0.note == note }).forEach({ $0.isSelected = false })
delegate?.fretboad(self, didSelectedNotesChange: notes)
}
Expand Down
Loading

0 comments on commit 2d9134a

Please sign in to comment.