<commit_before>
import {Dryad} from 'dryadic';
import {defRecv, defFree, defLoad} from '../server/osc/msg.js';
import path from 'path';
import fs from 'fs';

const StateKeys = {
  SYNTH_DEFS: 'SYNTH_DEFS'
};


/**
 * Compile a SynthDef from sclang source code
 *
 * `synthDef` is set in the context for children Dryads to access.
 * It is an object:
 * - .name
 * - .bytes
 * - .synthDesc object with descriptive meta data
 *
 * `synthDefName` is set in context for children Dryads
 *
 * options:
 *  - source      - sclang source code to compile
 *  - compileFrom - path of .scd file to compile
 *  - watch       - watch compileFrom file and recompile on changes
 *  - saveToDir   - path to save compiled .scsyndef to after compiling
 *  - loadFrom    - path of .scsyndef file to load to server
 */
export default class SCSynthDef extends Dryad {

  // saveToDir, watch=false,
  // constructor(source, compileFrom, loadFrom, children=[]) {
  //   super({source, compileFrom, loadFrom}, children);
  // }

  /**
   * If there is no SCLang in the parent context,
   * then this will wrap itself in an SCLang (language interpreter).
   */
  requireParent() {
    return 'SCLang';
  }

  prepareForAdd() {
    if (this.properties.source) {
      return {
        synthDef: (context) => {
          return this.compileSource(context, this.properties.source)
            .then((result) => this._sendSynthDef(context, result));
        }
      };
    }
    if (this.properties.compileFrom) {
      return {
        synthDef: (context) => {
          return this.compileFrom(context, this.properties.compileFrom)
            .then((result) => this._sendSynthDef(context, result));<commit_msg>SCSynthDef: only require SCLang if compiling options were specified. If just loading from scsyndef file then an interpreter not needed.<commit_after>
import {Dryad} from 'dryadic';
import {defRecv, defFree, defLoad} from '../server/osc/msg.js';
import path from 'path';
import fs from 'fs';

const StateKeys = {
  SYNTH_DEFS: 'SYNTH_DEFS'
};


/**
 * Compile a SynthDef from sclang source code
 *
 * `synthDef` is set in the context for children Dryads to access.
 * It is an object:
 * - .name
 * - .bytes
 * - .synthDesc object with descriptive meta data
 *
 * `synthDefName` is set in context for children Dryads
 *
 * options:
 *  - source      - sclang source code to compile
 *  - compileFrom - path of .scd file to compile
 *  - watch       - watch compileFrom file and recompile on changes
 *  - saveToDir   - path to save compiled .scsyndef to after compiling
 *  - loadFrom    - path of .scsyndef file to load to server
 */
export default class SCSynthDef extends Dryad {

  // saveToDir, watch=false,
  // constructor(source, compileFrom, loadFrom, children=[]) {
  //   super({source, compileFrom, loadFrom}, children);
  // }

  /**
   * If there is no SCLang in the parent context,
   * then this will wrap itself in an SCLang (language interpreter).
   */
  requireParent() {
    if (this.properties.source || this.properties.compileFrom) {
      return 'SCLang';
    }
  }

  prepareForAdd() {
    if (this.properties.source) {
      return {
        synthDef: (context) => {
          return this.compileSource(context, this.properties.source)
            .then((result) => this._sendSynthDef(context, result));
        }
      };
    }
    if (this.properties.compileFrom) {
      return {
        synthDef: (context) => {
          return this.compileFrom(context, this.properties.compileFrom)
            .then((result) => this._sendSynthDef(context, result));
{'fraction_non_alphanumeric': 0.11360448807854137, 'fraction_numerical': 0.0, 'mean_word_length': 2.7855626326963905, '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': '1172418', 'n_tokens_mistral': 1109, 'n_tokens_neox': 1081, 'n_words': 345}