Skip to content

Automate generation of trumpet fingerings #18

@chrisglein

Description

@chrisglein

The fingerings for trumpet could be programmatically generated. I've done it by hand so far. And to speed up I threw together a quick programmatic conversion:
https://codepen.io/papasnewbag/pen/mdaVReV

It's dumb in one key way, in that it doesn't actually use the key so it doesn't get sharps and flats.

Key function (that would almost certainly be better baked into ABCJS, but this was quickest for me)

let convert = (input) => {
  let regex = new RegExp(/([a-gA-G][,']*\d*)/g);

  let mappings = {
    "A,": "2",
    'C': '13',
    'D': '12',
    'E': '2',
    'F': '0',
    'G': '12',
    'A': '2',
    'B': '123',
    'c': '13',
    'd': '12',
    'e': '2',
    'f': '0',
    'g': '12',
    'a': '2',
    'b': '123',
    'c,': '13',
    'd,': '12',
    'e,': '2',
    'f,': '0',
    'g,': '12',
    'a,': '2',
    'b,': '123',
  }

  let replacer = (match) => {
    // remove the digits from the end
    let note = match.replace(/[0-9]+$/, '');
    return ' ' + (mappings[note] ?? note);
  };
  
  let result = input;
  
  // no chords
  result = result.replaceAll(/(\"[\w\/\d]+\")/g, '');
  
  // no rests
  result = result.replaceAll(/(z\d*)/g, '');
  
  // no whitespace and no bars
  result = result.replaceAll(/(\s|\|)/g, '');
  
  // convert the notes to fingerings
  result = result.replaceAll(regex, replacer);

  return 'w:' + result;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions