         }
     }
 
-    private var midiDocument: Document! {
+    private var midiDocument: Document? {
         return document as? Document
     }
 

        // Also, don't do it for untitled, unsaved documents which have no fileURL yet, because that's annoying.
        // Similarly, don't do it if "Ask to keep changes when closing documents" is turned on.

        if midiDocument.fileURL != nil && !UserDefaults.standard.bool(forKey: "NSCloseAlwaysConfirmsChanges") {
            let change = NSDocument.ChangeType(rawValue: (NSDocument.ChangeType.changeDone.rawValue | NSDocument.ChangeType.changeDiscardable.rawValue))!
            midiDocument.updateChangeCount(change)

    // MARK: Filter

    func updateFilterControls() {
        guard let midiDocument = midiDocument else { return }

        let currentMask = midiDocument.filterMask.rawValue

        // Each filter checkbox has a tag with the mask of filters that it is based on.
