Rename functions as intended

This commit is contained in:
2023-09-16 23:48:13 +02:00
parent 075159e3da
commit 647a3afa6f
2 changed files with 28 additions and 34 deletions

View File

@ -938,7 +938,7 @@ export class UserAPI {
// Time markers // Time markers
// ============================================================= // =============================================================
bar = (): number => { cbar = (): number => {
/** /**
* Returns the current bar number * Returns the current bar number
* *
@ -947,7 +947,7 @@ export class UserAPI {
return this.app.clock.time_position.bar + 1; return this.app.clock.time_position.bar + 1;
}; };
tick = (): number => { ctick = (): number => {
/** /**
* Returns the current tick number * Returns the current tick number
* *
@ -956,7 +956,7 @@ export class UserAPI {
return this.app.clock.tick + 1; return this.app.clock.tick + 1;
}; };
pulse = (): number => { cpulse = (): number => {
/** /**
* Returns the current pulse number * Returns the current pulse number
* *
@ -965,7 +965,7 @@ export class UserAPI {
return this.app.clock.time_position.pulse + 1; return this.app.clock.time_position.pulse + 1;
}; };
beat = (): number => { cbeat = (): number => {
/** /**
* Returns the current beat number * Returns the current beat number
* *
@ -1008,7 +1008,7 @@ export class UserAPI {
// Time Filters // Time Filters
// ============================================================= // =============================================================
public mod = (...n: number[]): boolean => { public beat = (...n: number[]): boolean => {
const results: boolean[] = n.map( const results: boolean[] = n.map(
(value) => (value) =>
this.app.clock.pulses_since_origin % Math.floor(value * this.ppqn()) === this.app.clock.pulses_since_origin % Math.floor(value * this.ppqn()) ===
@ -1017,13 +1017,16 @@ export class UserAPI {
return results.some((value) => value === true); return results.some((value) => value === true);
}; };
public modpulse = (...n: number[]): boolean => { public pulse = (...n: number[]): boolean => {
const results: boolean[] = n.map( const results: boolean[] = n.map(
(value) => this.app.clock.pulses_since_origin % value === 0 (value) => this.app.clock.pulses_since_origin % value === 0
); );
return results.some((value) => value === true); return results.some((value) => value === true);
}; };
modp = this.modpulse;
// =============================================================
// Modulo basd time filters
// =============================================================
public modbar = (...n: number[]): boolean => { public modbar = (...n: number[]): boolean => {
const results: boolean[] = n.map( const results: boolean[] = n.map(
@ -1032,18 +1035,12 @@ export class UserAPI {
); );
return results.some((value) => value === true); return results.some((value) => value === true);
}; };
modb = this.modbar;
// Original implementation // =============================================================
// public div = (chunk: number): boolean => { // Other core temporal functions
// const time_pos = this.app.clock.pulses_since_origin; // =============================================================
// const current_chunk = Math.floor(
// time_pos / Math.floor(chunk * this.ppqn())
// );
// return current_chunk % 2 === 0;
// };
public div = (chunk: number, ratio: number = 50): boolean => { public flip = (chunk: number, ratio: number = 50): boolean => {
/** /**
* Determines if the current time position is in the first * Determines if the current time position is in the first
* or second half of a given time chunk. * or second half of a given time chunk.
@ -1065,6 +1062,10 @@ export class UserAPI {
return current_chunk % 2 === 0; return current_chunk % 2 === 0;
}; };
// =============================================================
// "On" Filters
// =============================================================
public onbar = ( public onbar = (
bars: number[] | number, bars: number[] | number,
n: number = this.app.clock.time_signature[0] n: number = this.app.clock.time_signature[0]
@ -1095,7 +1096,7 @@ export class UserAPI {
if (decimal_part <= 0) if (decimal_part <= 0)
decimal_part = decimal_part + this.ppqn() * this.nominator(); decimal_part = decimal_part + this.ppqn() * this.nominator();
final_pulses.push( final_pulses.push(
integral_part === this.beat() && this.pulse() === decimal_part integral_part === this.cbeat() && this.cpulse() === decimal_part
); );
}); });
return final_pulses.some((p) => p == true); return final_pulses.some((p) => p == true);
@ -1199,7 +1200,7 @@ export class UserAPI {
rotate: number = 0 rotate: number = 0
): boolean => { ): boolean => {
return ( return (
this.mod(div) && this._euclidean_cycle(pulses, length, rotate).div(div) this.beat(div) && this._euclidean_cycle(pulses, length, rotate).div(div)
); );
}; };
@ -1249,7 +1250,7 @@ export class UserAPI {
*/ */
let convert: string = n.toString(2); let convert: string = n.toString(2);
let tobin: boolean[] = convert.split("").map((x: string) => x === "1"); let tobin: boolean[] = convert.split("").map((x: string) => x === "1");
return this.mod(div) && tobin.div(div); return this.beat(div) && tobin.div(div);
}; };
// ============================================================= // =============================================================

View File

@ -14,12 +14,11 @@ declare global {
repeatAll(amount: number): T; repeatAll(amount: number): T;
repeatPair(amount: number): T; repeatPair(amount: number): T;
repeatOdd(amount: number): T; repeatOdd(amount: number): T;
beat(): T; beat(division: number): T;
bar(): T; bar(): T;
pulse(): T; pulse(): T;
pick(): T; pick(): T;
loop(index: number): T; loop(index: number): T;
div(division: number): T;
shuffle(): this; shuffle(): this;
rotate(steps: number): this; rotate(steps: number): this;
unique(): this; unique(): this;
@ -93,15 +92,6 @@ export const makeArrayExtensions = (api: UserAPI) => {
return this[Math.floor(api.randomGen() * this.length)]; return this[Math.floor(api.randomGen() * this.length)];
}; };
Array.prototype.beat = function (beat: number = 1) {
/**
* Returns the element corresponding to the current beat
*
* @returns The element corresponding to the current beat
*/
return this[(api.app.clock.beats_since_origin / beat) % this.length];
};
Array.prototype.gen = function (min: number, max: number, times: number) { Array.prototype.gen = function (min: number, max: number, times: number) {
/** /**
* Returns an array of random numbers. * Returns an array of random numbers.
@ -110,10 +100,13 @@ export const makeArrayExtensions = (api: UserAPI) => {
* @param times - The number of random numbers to generate * @param times - The number of random numbers to generate
* @returns An array of random numbers * @returns An array of random numbers
*/ */
if(times < 1) { if (times < 1) {
return []; return [];
} }
return Array.from({ length: times }, () => Math.floor(api.randomGen() * (max - min + 1)) + min); return Array.from(
{ length: times },
() => Math.floor(api.randomGen() * (max - min + 1)) + min
);
}; };
Array.prototype.bar = function () { Array.prototype.bar = function () {
@ -134,7 +127,7 @@ export const makeArrayExtensions = (api: UserAPI) => {
return this[api.app.clock.time_position.pulse % this.length]; return this[api.app.clock.time_position.pulse % this.length];
}; };
Array.prototype.div = function (divisor: number) { Array.prototype.beat = function (divisor: number = 1) {
const chunk_size = divisor; // Get the first argument (chunk size) const chunk_size = divisor; // Get the first argument (chunk size)
const timepos = api.app.clock.pulses_since_origin; const timepos = api.app.clock.pulses_since_origin;
const slice_count = Math.floor( const slice_count = Math.floor(