-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add signature method for a scale. Closes #89 #91
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -181,6 +181,8 @@ The chroma number is ranging from pitch class C which is 0 to 11 which is B | |
#### Note#interval(interval) | ||
- A sugar function for calling teoria.interval(note, interval); | ||
|
||
Returns a new note based on the passed interval. | ||
|
||
Look at the documentation for `teoria.interval` | ||
|
||
#### Note#transpose(interval) | ||
|
@@ -415,6 +417,9 @@ scale step. E.g. 'first', 'second', 'fourth', 'seventh'. | |
|
||
*showOctaves* - A boolean meaning the same as `showOctaves` in `Note#solfege` | ||
|
||
#### Scale#signature() | ||
- Returns the sequence of notes representing the key signature of a scale | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you could add an example of how to use it, and which values the method returns, that'd be great! |
||
|
||
|
||
## teoria.interval(from, to) | ||
- A sugar function for the `#from` and `#between` methods of the same namespace and | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,6 +102,32 @@ Scale.prototype = { | |
this.tonic = scale.tonic; | ||
|
||
return this; | ||
}, | ||
|
||
/** | ||
* Get the sequence of notes representing key signature of a scale, in proper order. | ||
* There are two possible signatures for any scale: flats and sharps. | ||
* Sharps signature is got by traversing notes by P5 intervals to the right | ||
* till all the notes of the scale are covered. | ||
* Flats signature is got by traversing by P4 intervals to the left in the same manner, which is equal to reversed sharps. | ||
*/ | ||
signature: function() { | ||
var sequence = this.notes().sort(function (a, b) { | ||
var aCoord = a.coord[1] < 0 ? a.coord[1] + 12 : a.coord[1]; | ||
var bCoord = b.coord[1] < 0 ? b.coord[1] + 12 : b.coord[1]; | ||
return aCoord - bCoord; | ||
}); | ||
|
||
//if at least one flat - return flats signature | ||
if (sequence.some(function (note) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you could maybe break this into two lines (a bit more descriptive):
|
||
return note.accidentalValue() < 0; | ||
})) { | ||
sequence = sequence.reverse(); | ||
} | ||
|
||
return sequence.filter(function (note) { | ||
return note.accidentalValue() !== 0; | ||
}); | ||
} | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment isn't related the the PR. Please remove it.