<commit_before>/**
 * @module node-serialosc
 * @author <NAME> <<EMAIL>>
 */

var _ = require('underscore');
var OscReceiver = require('osc-receiver');
var OscEmitter = require('osc-emitter');
var EventEmitter = require('events').EventEmitter;
var Grid = require('./lib/grid');
var Arc = require('./lib/arc');

/**
 * Receives OSC messages from serialosc directly
 * ie. not messages from actual devices
 * @type {OscReceiver}
 */
var receiver = new OscReceiver();

/**
 * Sends OSC messages to serialosc server directly
 * ie. not messages to actual devices
 * @type {OscEmitter}
 */
var serialoscEmitter = new OscEmitter();

/**
 * The SerialOSC object represents an instance of
 * serialosc running either on the local computer
 * or another computer on the network.
 *
 * The following options can be passed:
 *
 * opts.host -- the hostname to listen on (default: localhost)
 * opts.port -- the port to listen on (default: 4200);
 * opts.serialoscHost -- the hostname serialosc is listening on
 *                       (default localhost)
 * opts.serialoscPort -- the port serialosc is listening on
 *                       (default 12002)
 * 
 * @param {Object} opts options object
 * @constructor
 */
var SerialOSC = function (opts) {
  /**
   * An array of all devices that have been seen
   * @type {Array}
   */
  this.devices = [];

  /**
   * Configuration options
   * @type {Object}
   */
  opts = opts || {};

  /**
   * The hostname this process listens on
   * default: localhost
   * @type {String}
   */
  this.host = opts.host || 'localhost';

  /**
   * The port number this process listens on
   * default: 4200
   * @type {Number}
   */
  this.port = opts.port || 4200;

  /**
   * The hostname serialosc is listening on
   * default: localhost
   * @type {String}
   */
  this.serialoscHost = opts.serialoscHost || 'localhost';

  /**
   * The port serialosc is listening on
   * default: 12002
   * @type {Number}
   */
  this.serialoscPort = opts.serialoscPort || 12002;
};

/**
 * Extend the EventEmitter prototype
 * Provides .on(), .emit(), etc.
 */
SerialOSC.prototype = Object.create(EventEmitter.prototype);

/**
 * Begin listening for serialosc messages on host/port
 * Request a list of devices from serialosc
 * Emit 'device:add' and 'device:remove' events
 */
SerialOSC.prototype.start = function () {

  // begin listening on the app's serialosc listen host/port
  receiver.bind(this.port, this.host);

  // reference to the current SerialOSC object instance
  var self = this;

  // called when serialosc tells us about a device
  // ie. in response to /serialosc/list
  receiver.on('/serialosc/device', function () {
    // configure what we know about this device
    var deviceOpts = {
      id: arguments[0],
      model: arguments[1],
      host: self.host,
      deviceHost: self.serialoscHost,
      devicePort: arguments[2]
    };
    // check if we already know about this device
    var device = _.findWhere(self.devices, {
      id: deviceOpts.id,
      devicePort: deviceOpts.devicePort
    });
    // if not, create it, start it, add it to devices array
    if (!device) {
      var encoders = parseInt(deviceOpts.model.match(/monome arc (\d)/), 10);
      if (encoders) {
        device = new Arc();
        deviceOpts.type = 'arc';
        deviceOpts.encoders = encoders[1];
      } else {<commit_msg>make encoders an integer<commit_after>/**
 * @module node-serialosc
 * @author <NAME> <<EMAIL>>
 */

var _ = require('underscore');
var OscReceiver = require('osc-receiver');
var OscEmitter = require('osc-emitter');
var EventEmitter = require('events').EventEmitter;
var Grid = require('./lib/grid');
var Arc = require('./lib/arc');

/**
 * Receives OSC messages from serialosc directly
 * ie. not messages from actual devices
 * @type {OscReceiver}
 */
var receiver = new OscReceiver();

/**
 * Sends OSC messages to serialosc server directly
 * ie. not messages to actual devices
 * @type {OscEmitter}
 */
var serialoscEmitter = new OscEmitter();

/**
 * The SerialOSC object represents an instance of
 * serialosc running either on the local computer
 * or another computer on the network.
 *
 * The following options can be passed:
 *
 * opts.host -- the hostname to listen on (default: localhost)
 * opts.port -- the port to listen on (default: 4200);
 * opts.serialoscHost -- the hostname serialosc is listening on
 *                       (default localhost)
 * opts.serialoscPort -- the port serialosc is listening on
 *                       (default 12002)
 * 
 * @param {Object} opts options object
 * @constructor
 */
var SerialOSC = function (opts) {
  /**
   * An array of all devices that have been seen
   * @type {Array}
   */
  this.devices = [];

  /**
   * Configuration options
   * @type {Object}
   */
  opts = opts || {};

  /**
   * The hostname this process listens on
   * default: localhost
   * @type {String}
   */
  this.host = opts.host || 'localhost';

  /**
   * The port number this process listens on
   * default: 4200
   * @type {Number}
   */
  this.port = opts.port || 4200;

  /**
   * The hostname serialosc is listening on
   * default: localhost
   * @type {String}
   */
  this.serialoscHost = opts.serialoscHost || 'localhost';

  /**
   * The port serialosc is listening on
   * default: 12002
   * @type {Number}
   */
  this.serialoscPort = opts.serialoscPort || 12002;
};

/**
 * Extend the EventEmitter prototype
 * Provides .on(), .emit(), etc.
 */
SerialOSC.prototype = Object.create(EventEmitter.prototype);

/**
 * Begin listening for serialosc messages on host/port
 * Request a list of devices from serialosc
 * Emit 'device:add' and 'device:remove' events
 */
SerialOSC.prototype.start = function () {

  // begin listening on the app's serialosc listen host/port
  receiver.bind(this.port, this.host);

  // reference to the current SerialOSC object instance
  var self = this;

  // called when serialosc tells us about a device
  // ie. in response to /serialosc/list
  receiver.on('/serialosc/device', function () {
    // configure what we know about this device
    var deviceOpts = {
      id: arguments[0],
      model: arguments[1],
      host: self.host,
      deviceHost: self.serialoscHost,
      devicePort: arguments[2]
    };
    // check if we already know about this device
    var device = _.findWhere(self.devices, {
      id: deviceOpts.id,
      devicePort: deviceOpts.devicePort
    });
    // if not, create it, start it, add it to devices array
    if (!device) {
      var encoders = deviceOpts.model.match(/monome arc (\d)/);
      if (encoders) {
        device = new Arc();
        deviceOpts.type = 'arc';
        deviceOpts.encoders = parseInt(encoders[1], 10);
      } else {
{'fraction_non_alphanumeric': 0.12356706863182969, 'fraction_numerical': 0.00982581509602501, 'mean_word_length': 2.852064220183486, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '2901482', 'n_tokens_mistral': 2042, 'n_tokens_neox': 1993, 'n_words': 663}