<commit_before>//
//  VolumeControl.swift
//  FaderBar
//
//  Created by iain on 04/12/16.
//  Copyright © 2016 iain. All rights reserved.
//

import Foundation

class VolumeControl {
    /// Timer used for scheduling
    var timer: Timer;
    
    /// Initial volume when schedule started
    var initialVolume: Double;
    
    /// Time (in seconds) between volume changes
    var interval: UInt;
    
    /// Amount to change volume;
    var delta: Double;
    
    /**
     
        Initialises a volume control with default parameters
     
        - Returns: A new volume control
     
    */
    init() {
        self.timer = Timer();
        self.initialVolume = 0.0;
        self.interval = 30;
        self.delta = 0.0;
    }
    
    /**
       
        Set the volume based on the delta from the current volume.
     
    */
    @objc func changeVolume() {
        let currentVolume = Double(NSSound.systemVolume());
        let newVolume = Float(currentVolume - delta);
        
        if (newVolume > 0) {
            NSSound.setSystemVolume(newVolume);
            
            self.showNotification(message: "Volume decreased by \(delta) to \(newVolume)")
        } else {
            NSSound.setSystemVolume(0.0);
            
            self.showNotification(message: "Sound muted")
            
            self.timer.invalidate();
        }
    }
    
    /**
     
        Show a notification
     
        - Parameter message: The notification contents
     
    */
    func showNotification(message:String) -> Void {
        let notification = NSUserNotification()
        notification.title = "Volume changed"
        notification.informativeText = message
        notification.soundName = nil
        
        NSUserNotificationCenter.default.deliver(notification)
    }
    
    /**
     
        Start the volume reduction schedule
     
    */
    func startShrinkage() -> Void {
        self.timer.invalidate();
        
        initialVolume = Double(NSSound.systemVolume());
        
        delta = initialVolume / Double(interval);
        
        self.timer = Timer.scheduledTimer(timeInterval: 30, target: self, selector: #selector(self.changeVolume), userInfo: nil, repeats: true);
    }
    
    /**
        
        Cancel the volume scheduling and return to originally set volume
     
    */
    func cancelShrinkage() -> Void {
        self.timer.invalidate();
        
        NSSound.setSystemVolume(Float(initialVolume));
    }
}<commit_msg>would you believe it, it works<commit_after>//
//  VolumeControl.swift
//  FaderBar
//
//  Created by iain on 04/12/16.
//  Copyright © 2016 iain. All rights reserved.
//

import Foundation

class VolumeControl {
    /// Time (in seconds) between volume changes
    let interval: UInt;
    
    /// Timer used for scheduling
    var timer: Timer;
    
    /// Initial volume when schedule started
    var initialVolume: Double;
    
    /// Amount to change volume;
    var delta: Double;
    
    /// Length of fade (in seconds)
    var fadeLength: Double;
    
    /**
     
        Initialises a volume control with default parameters
     
        - Returns: A new volume control
     
    */
    init() {
        self.timer = Timer();
        self.initialVolume = 0.0;
        self.interval = 30;
        self.delta = 0.0;
        self.fadeLength = 1800.0;
    }
    
    /**
       
        Set the volume based on the delta from the current volume.
     
    */
    @objc func changeVolume() {
        let currentVolume = Double(NSSound.systemVolume());
        let newVolume = Float(currentVolume - delta);
        
        if (newVolume > 0) {
            NSSound.setSystemVolume(newVolume);
            
            self.showNotification(message: "Volume decreased by \(delta) to \(newVolume)")
        } else {
            NSSound.setSystemVolume(0.0);
            
            self.showNotification(message: "Sound muted")
            
            self.timer.invalidate();
        }
    }
    
    /**
     
        Show a notification
     
        - Parameter message: The notification contents
     
    */
    func showNotification(message:String) -> Void {
        let notification = NSUserNotification()
        notification.title = "Volume changed"
        notification.informativeText = message
        notification.soundName = nil
        
        NSUserNotificationCenter.default.deliver(notification)
    }
    
    /**
     
        Start the volume reduction schedule
     
    */
    func startShrinkage() -> Void {
        self.timer.invalidate();
        
        self.initialVolume = Double(NSSound.systemVolume());
        
        // calculate change per interval from number of times timer is called
        self.delta = self.initialVolume / (self.fadeLength / Double(self.interval));
        
        self.timer = Timer.scheduledTimer(timeInterval: 30, target: self, selector: #selector(self.changeVolume), userInfo: nil, repeats: true);
    }
    
    /**
        
        Cancel the volume scheduling and return to originally set volume
     
    */
    func cancelShrinkage() -> Void {
        self.timer.invalidate();
        
        NSSound.setSystemVolume(Float(initialVolume));
        
        self.showNotification(message: "Timer cancelled, volume reset")
    }
}
{'fraction_non_alphanumeric': 0.09461756373937677, 'fraction_numerical': 0.008876298394711992, 'mean_word_length': 1.7597707139134966, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '1025963', 'n_tokens_mistral': 1457, 'n_tokens_neox': 1390, 'n_words': 374}