Skip to content

Commit

Permalink
Remove print functions
Browse files Browse the repository at this point in the history
  • Loading branch information
cemolcay committed Feb 13, 2018
1 parent fd42919 commit 72ecae7
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 66 deletions.
17 changes: 1 addition & 16 deletions MIDITimeTableView/Source/MIDITimeTableHistory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class MIDITimeTableHistory {
/// Items holding in the history queue.
public private(set) var items = [MIDITimeTableHistoryItem]()
/// Current index of history. Defaults nothing, -1.
public private(set) var currentIndex = -1 { didSet { print(currentIndex) } }
public private(set) var currentIndex = -1
/// Limit of the history items. Defaults 10.
public var limit: Int { didSet{ limitDidChange() }}
/// Delegate that informs about changes.
Expand Down Expand Up @@ -84,23 +84,8 @@ public class MIDITimeTableHistory {
///
/// - Parameter item: Item to add to history.
public func append(item: MIDITimeTableHistoryItem) {
print("history appending", item.enumerated().flatMap{ [$0.offset: $0.element.cells.flatMap{$0}] }.description.replacingOccurrences(of: "), ", with: "\n"))

// var newHistory = [MIDITimeTableHistoryItem]()
// for (index, element) in items.enumerated() {
// if index > currentIndex {
// break
// }
// newHistory.append(element)
// }
// newHistory.append(item)

var newHistory = items.enumerated().filter({ $0.offset <= currentIndex }).map({ $0.element })
newHistory.append(item)

// var newHistory = Array(items.prefix(currentIndex + 1))
// newHistory.append(item)

newHistory = Array(newHistory.suffix(limit))
currentIndex = newHistory.count - 1
items = newHistory
Expand Down
101 changes: 51 additions & 50 deletions MIDITimeTableView/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ class ViewController: UIViewController, MIDITimeTableViewDataSource, MIDITimeTab
var rowData: [MIDITimeTableRowData] = [
MIDITimeTableRowData(
cells: [
// MIDITimeTableCellData(data: "C7", position: 0, duration: 4),
// MIDITimeTableCellData(data: "Dm7", position: 4, duration: 4),
// MIDITimeTableCellData(data: "G7b5", position: 8, duration: 4),
// MIDITimeTableCellData(data: "C7", position: 12, duration: 4),
MIDITimeTableCellData(data: "C7", position: 0, duration: 4),
MIDITimeTableCellData(data: "Dm7", position: 4, duration: 4),
MIDITimeTableCellData(data: "G7b5", position: 8, duration: 4),
MIDITimeTableCellData(data: "C7", position: 12, duration: 4),
],
headerCellView: HeaderCellView(title: "Chords"),
cellView: { cellData in
Expand All @@ -117,10 +117,10 @@ class ViewController: UIViewController, MIDITimeTableViewDataSource, MIDITimeTab

MIDITimeTableRowData(
cells: [
// MIDITimeTableCellData(data: "C", position: 0, duration: 1),
// MIDITimeTableCellData(data: "D", position: 4, duration: 1),
// MIDITimeTableCellData(data: "G", position: 8, duration: 1),
// MIDITimeTableCellData(data: "C", position: 12, duration: 1),
MIDITimeTableCellData(data: "C", position: 0, duration: 1),
MIDITimeTableCellData(data: "D", position: 4, duration: 1),
MIDITimeTableCellData(data: "G", position: 8, duration: 1),
MIDITimeTableCellData(data: "C", position: 12, duration: 1),
],
headerCellView: HeaderCellView(title: "Bass"),
cellView: { cellData in
Expand All @@ -130,25 +130,25 @@ class ViewController: UIViewController, MIDITimeTableViewDataSource, MIDITimeTab

MIDITimeTableRowData(
cells: [
// MIDITimeTableCellData(data: "C", position: 0, duration: 1),
// MIDITimeTableCellData(data: "C", position: 1, duration: 1),
// MIDITimeTableCellData(data: "C", position: 2, duration: 1),
// MIDITimeTableCellData(data: "C", position: 3, duration: 1),
//
// MIDITimeTableCellData(data: "D", position: 4, duration: 1),
// MIDITimeTableCellData(data: "D", position: 5, duration: 1),
// MIDITimeTableCellData(data: "D", position: 6, duration: 1),
// MIDITimeTableCellData(data: "D", position: 7, duration: 1),
//
// MIDITimeTableCellData(data: "G", position: 8, duration: 1),
// MIDITimeTableCellData(data: "G", position: 9, duration: 1),
// MIDITimeTableCellData(data: "G", position: 10, duration: 1),
// MIDITimeTableCellData(data: "G", position: 11, duration: 1),
//
// MIDITimeTableCellData(data: "C", position: 12, duration: 1),
// MIDITimeTableCellData(data: "C", position: 13, duration: 1),
// MIDITimeTableCellData(data: "C", position: 14, duration: 1),
// MIDITimeTableCellData(data: "C", position: 15, duration: 1),
MIDITimeTableCellData(data: "C", position: 0, duration: 1),
MIDITimeTableCellData(data: "C", position: 1, duration: 1),
MIDITimeTableCellData(data: "C", position: 2, duration: 1),
MIDITimeTableCellData(data: "C", position: 3, duration: 1),

MIDITimeTableCellData(data: "D", position: 4, duration: 1),
MIDITimeTableCellData(data: "D", position: 5, duration: 1),
MIDITimeTableCellData(data: "D", position: 6, duration: 1),
MIDITimeTableCellData(data: "D", position: 7, duration: 1),

MIDITimeTableCellData(data: "G", position: 8, duration: 1),
MIDITimeTableCellData(data: "G", position: 9, duration: 1),
MIDITimeTableCellData(data: "G", position: 10, duration: 1),
MIDITimeTableCellData(data: "G", position: 11, duration: 1),

MIDITimeTableCellData(data: "C", position: 12, duration: 1),
MIDITimeTableCellData(data: "C", position: 13, duration: 1),
MIDITimeTableCellData(data: "C", position: 14, duration: 1),
MIDITimeTableCellData(data: "C", position: 15, duration: 1),
],
headerCellView: HeaderCellView(title: "Melody"),
cellView: { cellData in
Expand All @@ -159,16 +159,16 @@ class ViewController: UIViewController, MIDITimeTableViewDataSource, MIDITimeTab
MIDITimeTableRowData(
cells: [
MIDITimeTableCellData(data: "C", position: 0, duration: 0.5),
// MIDITimeTableCellData(data: "C", position: 2, duration: 0.5),
//
// MIDITimeTableCellData(data: "D", position: 4, duration: 0.5),
// MIDITimeTableCellData(data: "D", position: 6, duration: 0.5),
//
// MIDITimeTableCellData(data: "G", position: 8, duration: 0.5),
// MIDITimeTableCellData(data: "G", position: 10, duration: 0.5),
//
// MIDITimeTableCellData(data: "C", position: 12, duration: 0.5),
// MIDITimeTableCellData(data: "C", position: 14, duration: 0.5),
MIDITimeTableCellData(data: "C", position: 2, duration: 0.5),

MIDITimeTableCellData(data: "D", position: 4, duration: 0.5),
MIDITimeTableCellData(data: "D", position: 6, duration: 0.5),

MIDITimeTableCellData(data: "G", position: 8, duration: 0.5),
MIDITimeTableCellData(data: "G", position: 10, duration: 0.5),

MIDITimeTableCellData(data: "C", position: 12, duration: 0.5),
MIDITimeTableCellData(data: "C", position: 14, duration: 0.5),
],
headerCellView: HeaderCellView(title: "Synths"),
cellView: { cellData in
Expand Down Expand Up @@ -240,20 +240,21 @@ class ViewController: UIViewController, MIDITimeTableViewDataSource, MIDITimeTab
}

func midiTimeTableView(_ midiTimeTableView: MIDITimeTableView, didDelete cells: [MIDITimeTableCellIndex]) {
var deletingIndices = [Int: [Int]]() // [rowIndex: [colIndex]]
for cell in cells {
if deletingIndices[cell.row] == nil {
deletingIndices[cell.row] = [cell.index]
} else {
deletingIndices[cell.row]?.append(cell.index)
deletingIndices[cell.row]?.sort()
}
}

for (row, col) in deletingIndices {
rowData[row].cells = rowData[row].cells.enumerated().filter({ !col.contains($0.offset) }).map({ $0.element })
}
// var deletingIndices = [Int: [Int]]() // [rowIndex: [colIndex]]
// for cell in cells {
// if deletingIndices[cell.row] == nil {
// deletingIndices[cell.row] = [cell.index]
// } else {
// deletingIndices[cell.row]?.append(cell.index)
// deletingIndices[cell.row]?.sort()
// }
// }
//
// for (row, col) in deletingIndices {
// rowData[row].cells = rowData[row].cells.enumerated().filter({ !col.contains($0.offset) }).map({ $0.element })
// }

rowData.removeCells(at: cells)
timeTableView?.reloadData()
updateHistoryButtons()
}
Expand Down

0 comments on commit 72ecae7

Please sign in to comment.