findByName static method

ScalePattern findByName(
  1. String name, {
  2. Type? type,
})

Implementation

static ScalePattern findByName(String name, {Type? type}) {
  _initializeBuiltinPatterns();
  ScalePattern? scalePattern;

  //if no type is specified, search for ScalePattern first, then Mode if nothing found
  if (type == null) {
    scalePattern = _byName['$name $ScalePattern'];
    if (scalePattern == null) scalePattern = _byName['$name $Mode'];
    if (scalePattern == null)
      throw new FormatException('$name is not a ScalePattern name');
  } else {
    //user has specified a type, if wrong type used or no scale pattern found, throw an exception
    assert(['$Mode', '$ScalePattern'].contains('$type'));
    scalePattern = _byName['$name $type'];
    if (scalePattern == null)
      throw new FormatException(
          '$name is not a ScalePattern name with specific type $type');
  }

  return scalePattern;
}