<commit_before>//
// Copyright (C) 2015 CosmicMind, Inc. <http://cosmicmind.io> and other CosmicMind contributors
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program located at the root of the software package
// in a file called LICENSE.  If not, see <http://www.gnu.org/licenses/>.
//

import UIKit
import AVFoundation

@objc(CapturePreviewViewDelegate)
public protocol CapturePreviewViewDelegate : MaterialDelegate {
	/**
		:name:	capturePreviewViewDidTapToFocusAtPoint
	*/
	optional func capturePreviewViewDidTapToFocusAtPoint(capturePreviewView: CapturePreviewView, point: CGPoint)
	
	/**
		:name:	capturePreviewViewDidTapToExposeAtPoint
	*/
	optional func capturePreviewViewDidTapToExposeAtPoint(capturePreviewView: CapturePreviewView, point: CGPoint)
}

public class CapturePreviewView : MaterialView, UIGestureRecognizerDelegate {
	//
	//	:name:	tapToFocusGesture
	//
	private var tapToFocusGesture: UITapGestureRecognizer?
	
	//
	//	:name:	tapToExposeGesture
	//
	private var tapToExposeGesture: UITapGestureRecognizer?
	
	/**
		:name:	previewLayer
	*/
	public private(set) lazy var previewLayer: AVCaptureVideoPreviewLayer = AVCaptureVideoPreviewLayer()
	
	/**
		:name:	capture
	*/
	public private(set) lazy var captureSession: CaptureSession = CaptureSession()
	
	/**
		:name:	tapToFocusEnabled
	*/
	public var tapToFocusEnabled: Bool {
		didSet {
			if tapToFocusEnabled {
				prepareTapGesture(&tapToFocusGesture, numberOfTapsRequired: 1, selector: "handleTapToFocusGesture:")
			} else {
				removeTapGesture(&tapToFocusGesture)
			}
		}
	}
	
	/**
		:name:	tapToExposeEnabled
	*/
	public var tapToExposeEnabled: Bool {
		didSet {
			if tapToExposeEnabled {
				prepareTapGesture(&tapToExposeGesture, numberOfTapsRequired: 2, selector: "handleTapToExposeGesture:")
			} else {
				removeTapGesture(&tapToExposeGesture)
			}
		}
	}
	
	/**
		:name:	init
	*/
	public required init?(coder aDecoder: NSCoder) {
		tapToFocusEnabled = true
		tapToExposeEnabled = true
		super.init(coder: aDecoder)
	}
	
	/**
		:name:	init
	*/
	public override init(frame: CGRect) {
		tapToFocusEnabled = true
		tapToExposeEnabled = true
		super.init(frame: frame)
	}
	
	/**
		:name:	init
	*/
	public convenience init() {<commit_msg>working tap recognizers for focus and exposure<commit_after>//
// Copyright (C) 2015 CosmicMind, Inc. <http://cosmicmind.io> and other CosmicMind contributors
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program located at the root of the software package
// in a file called LICENSE.  If not, see <http://www.gnu.org/licenses/>.
//

import UIKit
import AVFoundation

@objc(CapturePreviewViewDelegate)
public protocol CapturePreviewViewDelegate : MaterialDelegate {
	/**
		:name:	capturePreviewViewDidTapToFocusAtPoint
	*/
	optional func capturePreviewViewDidTapToFocusAtPoint(capturePreviewView: CapturePreviewView, point: CGPoint)
	
	/**
		:name:	capturePreviewViewDidTapToExposeAtPoint
	*/
	optional func capturePreviewViewDidTapToExposeAtPoint(capturePreviewView: CapturePreviewView, point: CGPoint)
}

public class CapturePreviewView : MaterialView, UIGestureRecognizerDelegate {
	//
	//	:name:	tapToFocusGesture
	//
	private var tapToFocusGesture: UITapGestureRecognizer?
	
	//
	//	:name:	tapToExposeGesture
	//
	private var tapToExposeGesture: UITapGestureRecognizer?
	
	/**
		:name:	previewLayer
	*/
	public private(set) lazy var previewLayer: AVCaptureVideoPreviewLayer = AVCaptureVideoPreviewLayer()
	
	/**
		:name:	capture
	*/
	public private(set) lazy var captureSession: CaptureSession = CaptureSession()
	
	/**
		:name:	tapToFocusEnabled
	*/
	public var tapToFocusEnabled: Bool {
		didSet {
			if tapToFocusEnabled {
				prepareTapGesture(&tapToFocusGesture, numberOfTapsRequired: 1, selector: "handleTapToFocusGesture:")
				if let v: UITapGestureRecognizer = tapToExposeGesture {
					tapToFocusGesture!.requireGestureRecognizerToFail(v)
				}
			} else {
				removeTapGesture(&tapToFocusGesture)
			}
		}
	}
	
	/**
		:name:	tapToExposeEnabled
	*/
	public var tapToExposeEnabled: Bool {
		didSet {
			if tapToExposeEnabled {
				prepareTapGesture(&tapToExposeGesture, numberOfTapsRequired: 2, selector: "handleTapToExposeGesture:")
				if let v: UITapGestureRecognizer = tapToFocusGesture {
					v.requireGestureRecognizerToFail(tapToExposeGesture!)
				}
			} else {
				removeTapGesture(&tapToExposeGesture)
			}
		}
	}
	
	/**
		:name:	init
	*/
	public required init?(coder aDecoder: NSCoder) {
		tapToFocusEnabled = true
		tapToExposeEnabled = true
		super.init(coder: aDecoder)
	}
	
	/**
		:name:	init
	*/
	public override init(frame: CGRect) {
		tapToFocusEnabled = true
		tapToExposeEnabled = true
		super.init(frame: frame)
	}
	
	/**
		:name:	init
	*/
	public convenience init() {
{'fraction_non_alphanumeric': 0.08931310720981762, 'fraction_numerical': 0.002386228055224135, 'mean_word_length': 4.225289403383793, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3806217', 'n_tokens_mistral': 2065, 'n_tokens_neox': 1815, 'n_words': 514}