<commit_before>// [VexFlow](http://vexflow.com) - Copyright (c) <NAME> 2013.
// Co-author: <NAME>
//
// ## Description
//
// This file implements various types of clefs that can be rendered on a stave.
//
// See `tests/clef_tests.js` for usage examples.

import { Vex } from './vex';
import { StaveModifier } from './stavemodifier';
import { Glyph } from './glyph';
import { Stave } from './stave';

export interface ClefAnnotation {
  code: string;
  line: number;
  x_shift: number;
  point: number;
}

export interface ClefType {
  point?: number;
  code: string;
  line?: number;
}

// To enable logging for this class, set `Vex.Flow.Clef.DEBUG` to `true`.
function L(
  // eslint-disable-next-line
  ...args: any []) {
  if (Clef.DEBUG) Vex.L('Vex.Flow.Clef', args);
}

export class Clef extends StaveModifier {
  static DEBUG: boolean;

  annotation?: ClefAnnotation;
  clef: ClefType = Clef.types['treble'];

  protected glyph?: Glyph;
  protected attachment?: Glyph;
  protected size?: string;
  protected type?: string;

  static get CATEGORY(): string {
    return 'clefs';
  }

  // Every clef name is associated with a glyph code from the font file
  // and a default stave line number.
  static get types(): Record<string, ClefType> {
    return {
      treble: {
        code: 'gClef',
        line: 3,
      },
      bass: {
        code: 'fClef',
        line: 1,
      },
      alto: {
        code: 'cClef',
        line: 2,
      },
      tenor: {
        code: 'cClef',
        line: 1,
      },
      percussion: {
        code: 'restMaxima',
        line: 2,
      },
      soprano: {
        code: 'cClef',
        line: 4,
      },
      'mezzo-soprano': {
        code: 'cClef',
        line: 3,
      },
      'baritone-c': {
        code: 'cClef',
        line: 0,
      },
      'baritone-f': {
        code: 'fClef',
        line: 2,
      },
      subbass: {
        code: 'fClef',
        line: 0,
      },
      french: {
        code: 'gClef',
        line: 4,
      },
      tab: {
        code: '6stringTabClef',
      },
    };
  }

  // Create a new clef. The parameter `clef` must be a key from
  // `Clef.types`.
  constructor(type: string, size?: string, annotation?: string) {
    super();
    this.setAttribute('type', 'Clef');

    this.setPosition(StaveModifier.Position.BEGIN);
    this.setType(type, size, annotation);
    this.setWidth(this.musicFont.lookupMetric(`clef.${this.size}.width`));
    L('Creating clef:', type);
  }

  getCategory(): string {
    return Clef.CATEGORY;
  }

  setType(type: string, size?: string, annotation?: string): this {
    this.type = type;
    this.clef = Clef.types[type];
    if (size === undefined) {
      this.size = 'default';
    } else {
      this.size = size;
    }
    this.clef.point = this.musicFont.lookupMetric(`clef.${this.size}.point`, 0);
    this.glyph = new Glyph(this.clef.code, this.clef.point ?? 0, {
      category: `clef.${this.clef.code}.${this.size}`,
    });

    // If an annotation, such as 8va, is specified, add it to the Clef object.
    if (annotation !== undefined) {
      const code = this.musicFont.lookupMetric(`clef.annotations.${annotation}.smuflCode`);
      const point = this.musicFont.lookupMetric(`clef.annotations.${annotation}.${this.size}.point`);
      const line = this.musicFont.lookupMetric(`clef.annotations.${annotation}.${this.size}.${this.type}.line`);
      const x_shift = this.musicFont.lookupMetric(`clef.annotations.${annotation}.${this.size}.${this.type}.shiftX`);

      this.annotation = { code, point, line, x_shift };
<commit_msg>review comments<commit_after>// [VexFlow](http://vexflow.com) - Copyright (c) <NAME> 2013.
// Co-author: <NAME>
//
// ## Description
//
// This file implements various types of clefs that can be rendered on a stave.
//
// See `tests/clef_tests.js` for usage examples.

import { Vex } from './vex';
import { StaveModifier } from './stavemodifier';
import { Glyph } from './glyph';
import { Stave } from './stave';

export interface ClefAnnotation {
  code: string;
  line: number;
  x_shift: number;
  point: number;
}

export interface ClefType {
  point: number;
  code: string;
  line?: number;
}

// To enable logging for this class, set `Vex.Flow.Clef.DEBUG` to `true`.
function L(
  // eslint-disable-next-line
  ...args: any []) {
  if (Clef.DEBUG) Vex.L('Vex.Flow.Clef', args);
}

export class Clef extends StaveModifier {
  static DEBUG: boolean;

  annotation?: ClefAnnotation;
  clef: ClefType = Clef.types['treble'];

  protected glyph?: Glyph;
  protected attachment?: Glyph;
  protected size?: string;
  protected type?: string;

  static get CATEGORY(): string {
    return 'clefs';
  }

  // Every clef name is associated with a glyph code from the font file
  // and a default stave line number.
  static get types(): Record<string, ClefType> {
    return {
      treble: {
        code: 'gClef',
        line: 3,
        point: 0,
      },
      bass: {
        code: 'fClef',
        line: 1,
        point: 0,
      },
      alto: {
        code: 'cClef',
        line: 2,
        point: 0,
      },
      tenor: {
        code: 'cClef',
        line: 1,
        point: 0,
      },
      percussion: {
        code: 'restMaxima',
        line: 2,
        point: 0,
      },
      soprano: {
        code: 'cClef',
        line: 4,
        point: 0,
      },
      'mezzo-soprano': {
        code: 'cClef',
        line: 3,
        point: 0,
      },
      'baritone-c': {
        code: 'cClef',
        line: 0,
        point: 0,
      },
      'baritone-f': {
        code: 'fClef',
        line: 2,
        point: 0,
      },
      subbass: {
        code: 'fClef',
        line: 0,
        point: 0,
      },
      french: {
        code: 'gClef',
        line: 4,
        point: 0,
      },
      tab: {
        code: '6stringTabClef',
        point: 0,
      },
    };
  }

  // Create a new clef. The parameter `clef` must be a key from
  // `Clef.types`.
  constructor(type: string, size?: string, annotation?: string) {
    super();
    this.setAttribute('type', 'Clef');

    this.setPosition(StaveModifier.Position.BEGIN);
    this.setType(type, size, annotation);
    this.setWidth(this.musicFont.lookupMetric(`clef.${this.size}.width`));
    L('Creating clef:', type);
  }

  getCategory(): string {
    return Clef.CATEGORY;
  }

  setType(type: string, size?: string, annotation?: string): this {
    this.type = type;
    this.clef = Clef.types[type];
    if (size === undefined) {
      this.size = 'default';
    } else {
      this.size = size;
    }
    this.clef.point = this.musicFont.lookupMetric(`clef.${this.size}.point`, 0);
    this.glyph = new Glyph(this.clef.code, this.clef.point, {
      category: `clef.${this.clef.code}.${this.size}`,
    });

    // If an annotation, such as 8va, is specified, add it to the Clef object.
    if (annotation !== undefined) {
      const code = this.musicFont.lookupMetric(`clef.annotations.${annotation}.smuflCode`);
      const point = this.musicFont.lookupMetric(`clef.annotations.${annotation}.${this.size}.point`);
      const line = this.musicFont.lookupMetric(`clef.annotations.${annotation}.${this.size}.${this.type}.line`);
      const x_shift = this.musicFont.lookupMetric(`clef.annotations.${annotation}.${this.size}.${this.type}.shiftX`);

      this.annotation = { code, point, line, x_shift };

{'fraction_non_alphanumeric': 0.15721649484536082, 'fraction_numerical': 0.006646771568095496, 'mean_word_length': 2.3151978417266186, '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': '854991', 'n_tokens_mistral': 2603, 'n_tokens_neox': 2479, 'n_words': 612}