<commit_before>//
//  ChirpView.swift
//  microjam
//
//  Created by <NAME> on 22/11/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import UIKit

/// View class for short touch-interaction musical performances.
class ChirpView: UIImageView {
    var lastPoint : CGPoint?
    var recording = false
    var playing = false
    var swiped = false
    var started = false
    var startTime = Date()
    var performance : ChirpPerformance?
    let defaultRecordingColour : CGColor = UIColor.red.cgColor
    var recordingColour : CGColor?
    let defaultPlaybackColour : CGColor = UIColor.green.cgColor
    var playbackColour : CGColor?
    let CG_INIT_POINT = CGPoint(x:0,y:0)
    let imageSize : Double = 300.0
    // Pd File Vars
    var openPatch : PdFile?
    var openPatchDollarZero : Int32?
    var openPatchName = ""
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        self.isMultipleTouchEnabled = true
        self.startNewPerformance()
    }
    
    /// Closes the recording and returns the performance.
    func closeRecording() -> ChirpPerformance? {
        self.recording = false
        if let output = self.performance {
            output.image = self.image!
            output.performer = UserDefaults.standard.string(forKey: SettingsKeys.performerKey)!
            output.instrument = SoundSchemes.namesForKeys[UserDefaults.standard.integer(forKey: SettingsKeys.soundSchemeKey)]!
            output.date = Date()
            return output
        }
        return nil
    }
    
    /// Resets the ChirpView for a new performance and returns the last performance.
    func reset() -> ChirpPerformance {
        print("ChirpView: Reset Called")
        self.performance?.image = self.image!
        // FIXME: overwrites the date each time a chirpview is reset.
        self.performance?.date = Date()
        let output = self.performance
        self.startNewPerformance()
        return output!
    }
    
    // Initialise the ChirpView for a new performance
    func startNewPerformance() {
        print("ChirpView: New Performance")
        self.recording = false
        self.playing = false
        self.started = false
        self.lastPoint = CG_INIT_POINT
        self.swiped = false
        self.image = UIImage()
        self.performance = ChirpPerformance()
        self.recordingColour = self.performance?.colour.cgColor ?? defaultRecordingColour
        
    }
    

    
    //MARK: - touch interaction
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        self.superview?.touchesBegan(touches, with: event)
        if (!self.started) {
            self.startTime = Date()
            self.started = true
        }
        self.swiped = false
        self.lastPoint = touches.first?.location(in: self)
        let size = touches.first?.majorRadius
        self.drawDot(at: self.lastPoint!, withColour: self.recordingColour ?? self.defaultRecordingColour)
        self.makeSound(at: self.lastPoint!, withRadius: size!)
        self.recordTouch(at: self.lastPoint!, withRadius: size!, thatWasMoving:false)
    }
    
    override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
        self.swiped = true
        let currentPoint = touches.first?.location(in:self)
        self.drawLine(from:self.lastPoint!, to:currentPoint!, withColour:self.recordingColour ?? self.defaultRecordingColour)
        self.lastPoint = currentPoint
        let size = touches.first?.majorRadius
        self.makeSound(at: currentPoint!, withRadius: size!)
        self.recordTouch(at: currentPoint!, withRadius: size!, thatWasMoving: true)
    }
    <commit_msg>cleaning up Pd patch loading a bit<commit_after>//
//  ChirpView.swift
//  microjam
//
//  Created by <NAME> on 22/11/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import UIKit

/// View class for short touch-interaction musical performances.
class ChirpView: UIImageView {
    var lastPoint : CGPoint?
    var recording = false
    var playing = false
    var swiped = false
    var started = false
    var startTime = Date()
    var performance : ChirpPerformance?
    let defaultRecordingColour : CGColor = UIColor.red.cgColor
    var recordingColour : CGColor?
    let defaultPlaybackColour : CGColor = UIColor.green.cgColor
    var playbackColour : CGColor?
    let CG_INIT_POINT = CGPoint(x:0,y:0)
    let imageSize : Double = 300.0
    // Pd File Vars
    var openPatch : PdFile?
    var openPatchDollarZero : Int32?
    var openPatchName = ""
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        self.isMultipleTouchEnabled = true
        self.startNewPerformance()
    }
    
    /// Closes the recording and returns the performance.
    func closeRecording() -> ChirpPerformance? {
        self.recording = false
        if let output = self.performance {
            output.image = self.image!
            output.performer = UserDefaults.standard.string(forKey: SettingsKeys.performerKey)!
            output.instrument = SoundSchemes.namesForKeys[UserDefaults.standard.integer(forKey: SettingsKeys.soundSchemeKey)]!
            output.date = Date()
            return output
        }
        return nil
    }
    
    /// Resets the ChirpView for a new performance and returns the last performance.
    func reset() -> ChirpPerformance {
        print("ChirpView: Reset Called")
        self.performance?.image = self.image!
        // FIXME: overwrites the date each time a chirpview is reset.
        self.performance?.date = Date()
        let output = self.performance
        self.startNewPerformance()
        return output!
    }
    
    // Initialise the ChirpView for a new performance
    func startNewPerformance() {
        print("ChirpView: New Performance")
        self.recording = false
        self.playing = false
        self.started = false
        self.lastPoint = CG_INIT_POINT
        self.swiped = false
        self.image = UIImage()
        self.performance = ChirpPerformance()
        self.recordingColour = self.performance?.colour.cgColor ?? defaultRecordingColour
        self.reloadPatch()
    }
    
    //MARK: - touch interaction
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        self.superview?.touchesBegan(touches, with: event)
        if (!self.started) {
            self.startTime = Date()
            self.started = true
        }
        self.swiped = false
        self.lastPoint = touches.first?.location(in: self)
        let size = touches.first?.majorRadius
        self.drawDot(at: self.lastPoint!, withColour: self.recordingColour ?? self.defaultRecordingColour)
        self.makeSound(at: self.lastPoint!, withRadius: size!)
        self.recordTouch(at: self.lastPoint!, withRadius: size!, thatWasMoving:false)
    }
    
    override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
        self.swiped = true
        let currentPoint = touches.first?.location(in:self)
        self.drawLine(from:self.lastPoint!, to:currentPoint!, withColour:self.recordingColour ?? self.defaultRecordingColour)
        self.lastPoint = currentPoint
        let size = touches.first?.majorRadius
        self.makeSound(at: currentPoint!, withRadius: size!)
        self.recordTouch(at: currentPoint!, withRadius: size!, thatWasMoving: true)
    }
    
{'fraction_non_alphanumeric': 0.09460008120178644, 'fraction_numerical': 0.0048721071863581, 'mean_word_length': 2.5460652591170825, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '6308182', 'n_tokens_mistral': 2213, 'n_tokens_neox': 2092, 'n_words': 527}