<commit_before>//
//  AKCallbackInstrument.swift
//  AudioKit
//
//  Created by <NAME>, revision history on Github.
//  Copyright © 2016 AudioKit. All rights reserved.
//

/// Function type for MIDI callbacks
public typealias AKMIDICallback = (AKMIDIStatus, MIDINoteNumber, MIDIVelocity) -> Void

/// MIDI Instrument that triggers functions on MIDI note on/off commands
public class AKCallbackInstrument: AKMIDIInstrument {

    // MARK: Properties

    /// All callbacks that will get triggered by MIDI events
    public var callbacks = [AKMIDICallback]()

    /// Initialize the callback instrument
    ///
    /// - parameter callback: Initial callback
    ///
    public init(callback: AKMIDICallback) {
        super.init()
        let midi = AKMIDI()
        self.enableMIDI(midi.client, name: "callback midi in")
        callbacks.append(callback)
        avAudioNode = AVAudioMixerNode()
        AudioKit.engine.attachNode(self.avAudioNode)
    }

    private func triggerCallbacks(status: AKMIDIStatus,
                                  noteNumber: MIDINoteNumber,
                                  velocity: MIDIVelocity) {
        for callback in callbacks {
            callback(status, noteNumber, velocity)
        }
    }

    /// Will trigger in response to any noteOn Message
    ///
    /// - Parameters:
    ///   - noteNumber: MIDI Note Number being started
    ///   - velocity:   MIDI Velocity (0-127)
    ///   - channel:    MIDI Channel
    ///
    override public func start(noteNumber noteNumber: MIDINoteNumber,
                                          velocity: MIDIVelocity,
                                          channel: MIDIChannel) {
        triggerCallbacks(.NoteOn, noteNumber: noteNumber, velocity: velocity)
    }

    /// Will trigger in response to any noteOff Message
    ///
    /// - Parameters:
    ///   - noteNumber: MIDI Note Number being stopped
    ///   - velocity:   MIDI Velocity (0-127)
    ///   - channel:    MIDI Channel<commit_msg>AKCallbackInstrument more usable<commit_after>//
//  AKCallbackInstrument.swift
//  AudioKit
//
//  Created by <NAME>, revision history on Github.
//  Copyright © 2016 AudioKit. All rights reserved.
//

/// Function type for MIDI callbacks
public typealias AKMIDICallback = (AKMIDIStatus, MIDINoteNumber, MIDIVelocity) -> Void

/// MIDI Instrument that triggers functions on MIDI note on/off commands
public class AKCallbackInstrument: AKMIDIInstrument {

    // MARK: Properties

    /// All callbacks that will get triggered by MIDI events
    public var callback: AKMIDICallback?

    /// Initialize the callback instrument
    ///
    /// - parameter callback: Initial callback
    ///
    public init(callback: AKMIDICallback) {
        super.init()
        let midi = AKMIDI()
        self.enableMIDI(midi.client, name: "callback midi in")
        self.callback = callback
        avAudioNode = AVAudioMixerNode()
        AudioKit.engine.attachNode(self.avAudioNode)
    }

    private func triggerCallbacks(status: AKMIDIStatus,
                                  noteNumber: MIDINoteNumber,
                                  velocity: MIDIVelocity) {
        if callback != nil {
            callback!(status, noteNumber, velocity)
        }
    }

    /// Will trigger in response to any noteOn Message
    ///
    /// - Parameters:
    ///   - noteNumber: MIDI Note Number being started
    ///   - velocity:   MIDI Velocity (0-127)
    ///   - channel:    MIDI Channel
    ///
    override public func start(noteNumber noteNumber: MIDINoteNumber,
                                          velocity: MIDIVelocity,
                                          channel: MIDIChannel) {
        triggerCallbacks(.NoteOn, noteNumber: noteNumber, velocity: velocity)
    }

    /// Will trigger in response to any noteOff Message
    ///
    /// - Parameters:
    ///   - noteNumber: MIDI Note Number being stopped
    ///   - velocity:   MIDI Velocity (0-127)
    ///   - channel:    MIDI Channel
{'fraction_non_alphanumeric': 0.09403209628886659, 'fraction_numerical': 0.006018054162487462, 'mean_word_length': 1.9244868035190617, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7312551', 'n_tokens_mistral': 1144, 'n_tokens_neox': 1057, 'n_words': 313}