-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVNote.swift
81 lines (70 loc) · 1.92 KB
/
VNote.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//
// VNote.swift
// tablution
//
// Created by Ian McCowan on 10/25/14.
//
//
import Foundation
public class VNote: NSObject {
dynamic var fret:Int
var preMark:PreNoteMark = .None
var postMark:PostNoteMark = .None
class func NO_FRET() -> Int {
return -1
}
init(fret:Int) {
self.fret = fret
}
class func noteAtFret(theFret:Int) -> VNote {
return VNote(fret: theFret)
}
class func blankNote() -> VNote {
return VNote(fret: VNote.NO_FRET())
}
func stringValue() -> String {
// FIXME: This is probably not the way to do this.
// Drawing-wise, the fret number shouldn't move when you add a mark,
// but there's no easy way to avoid it doing this.
let pre = self.preMark == .None ? "" : "\(self.preMark.rawValue)"
let post = self.postMark == .None ? "" : "\(self.postMark.rawValue)"
return "\(pre)\(self.fret)\(post)"
}
func stringValueOrDash() -> String {
if (self.fret == VNote.NO_FRET()) {
return "-"
}
else {
return self.stringValue()
}
}
public override func isEqual(other:AnyObject?) -> Bool {
if let otherNote = other as? VNote {
return otherNote.fret == self.fret
}
else {
return false
}
}
func hasFret() -> Bool {
return (self.fret != VNote.NO_FRET())
}
func setMark(markChar: Character) {
if let mark = PreNoteMark(rawValue: markChar) {
if self.preMark == mark {
self.preMark = .None
}
else {
self.preMark = mark
}
}
else if let mark = PostNoteMark(rawValue: markChar) {
if self.postMark == mark {
self.postMark = .None
}
else {
self.postMark = mark
}
}
}
}