Tidying up core (#256)

* remove _ prefixes except for functions to be patternified
* categorise pattern methods
* experimental support for `.add.squeeze` and friends as alternative to `.addSqueeze`
* `every` is now an alias for `firstOf` with additional `lastOf` (which every will become an alias for next)
This commit is contained in:
Alex McLean 2022-11-22 08:51:25 +00:00 committed by GitHub
parent 4cf412b93d
commit e1a532500e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 738 additions and 603 deletions

View file

@ -12,6 +12,6 @@ import { describe, it, expect } from 'vitest';
describe('tonal', () => {
it('Should run tonal functions ', () => {
expect(pure('c3').scale('C major').scaleTranspose(1)._firstCycleValues).toEqual(['D3']);
expect(pure('c3').scale('C major').scaleTranspose(1).firstCycleValues).toEqual(['D3']);
});
});

View file

@ -75,7 +75,7 @@ function scaleOffset(scale, offset, note) {
*/
Pattern.prototype._transpose = function (intervalOrSemitones) {
return this._withHap((hap) => {
return this.withHap((hap) => {
const interval = !isNaN(Number(intervalOrSemitones))
? Interval.fromSemitones(intervalOrSemitones /* as number */)
: String(intervalOrSemitones);
@ -111,7 +111,7 @@ Pattern.prototype._transpose = function (intervalOrSemitones) {
*/
Pattern.prototype._scaleTranspose = function (offset /* : number | string */) {
return this._withHap((hap) => {
return this.withHap((hap) => {
if (!hap.context.scale) {
throw new Error('can only use scaleTranspose after .scale');
}
@ -142,7 +142,7 @@ Pattern.prototype._scaleTranspose = function (offset /* : number | string */) {
*/
Pattern.prototype._scale = function (scale /* : string */) {
return this._withHap((hap) => {
return this.withHap((hap) => {
let note = hap.value;
const asNumber = Number(note);
if (!isNaN(asNumber)) {

View file

@ -51,7 +51,7 @@ Pattern.prototype.voicings = function (range) {
}
return this.fmapNested((event) => {
lastVoicing = getVoicing(event.value, lastVoicing, range);
return stack(...lastVoicing)._withContext(() => ({
return stack(...lastVoicing).withContext(() => ({
locations: event.context.locations || [],
}));
});