saebekassebil/teoria — pull request #3 by LukeHorvat (2012-07-13 05:27:00+00:00)
Title: Added TeoriaScale.name

I have encountered situations where I had created a `TeoriaScale` object, and then later on wanted to refer to the name of the scale originally supplied to the constructor, but had no means of doing so. So I added a `name` field to the `TeoriaScale` class, which is automatically assigned a value in its constructor.

So if you supply a scale name string to `TeoriaScale`'s constructor, it will simply set the `name` field to that string. Example:

```javascript
teoria.scale('c', 'mixolydian').name; //returns "mixolydian"
```

And if you supply an array of intervals as the scale to `TeoriaScale`'s constructor, it will lookup the name based on whether a matching array can be found in `teoria.scale.scales`. The lookup is O(N^2) because you are storing the scale arrays in an object literal. Whether that is acceptable or not is up to you, but since there aren't that many scales, I think it is. Example:

```javascript
teoria.scale('c', ['M2', 'M3', 'P5', 'M6']).name //returns "majorpentatonic"
```

And obviously if you specify a scale array that doesn't match any of the arrays in `teoria.scale.scales`, the `name` field remains `undefined`, which is expected behaviour to me. Example:
```javascript
teoria.scale('c', ['M2', 'm3', 'P4', 'm7']).name //returns undefined
```

However, it should be noted that if you specify an array that matches multiple scale arrays in `teoria.scale.scales` (e.g. a scale that is aeolian would also be minor), only the first match will set the `name` field. Again, you'll need to decide whether that is acceptable. Example:

```javascript
teoria.scale('c', 'aeolian').name //returns "aeolian"
teoria.scale('c', ['M2', 'm3', 'P4', 'P5', 'm6', 'm7']).name //always returns "minor"
```