adding b as shortcut
This commit is contained in:
@ -59,7 +59,7 @@ export class UserAPI {
|
|||||||
MidiConnection: MidiConnection = new MidiConnection();
|
MidiConnection: MidiConnection = new MidiConnection();
|
||||||
load: samples;
|
load: samples;
|
||||||
|
|
||||||
constructor(public app: Editor) {}
|
constructor(public app: Editor) { }
|
||||||
|
|
||||||
_loadUniverseFromInterface = (universe: string) => {
|
_loadUniverseFromInterface = (universe: string) => {
|
||||||
this.app.loadUniverse(universe as string);
|
this.app.loadUniverse(universe as string);
|
||||||
@ -1017,6 +1017,7 @@ export class UserAPI {
|
|||||||
);
|
);
|
||||||
return results.some((value) => value === true);
|
return results.some((value) => value === true);
|
||||||
};
|
};
|
||||||
|
b = this.beat;
|
||||||
|
|
||||||
public pulse = (...n: number[]): boolean => {
|
public pulse = (...n: number[]): boolean => {
|
||||||
const results: boolean[] = n.map(
|
const results: boolean[] = n.map(
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { type UserAPI } from "./API";
|
import { type UserAPI } from "./API";
|
||||||
import { safeScale, stepsToScale } from "zifferjs";
|
import { safeScale, stepsToScale } from "zifferjs";
|
||||||
export {};
|
export { };
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface Array<T> {
|
interface Array<T> {
|
||||||
@ -16,6 +16,7 @@ declare global {
|
|||||||
repeatPair(amount: number): T;
|
repeatPair(amount: number): T;
|
||||||
repeatOdd(amount: number): T;
|
repeatOdd(amount: number): T;
|
||||||
beat(division: number): T;
|
beat(division: number): T;
|
||||||
|
b(division: number): T;
|
||||||
bar(): T;
|
bar(): T;
|
||||||
pulse(): T;
|
pulse(): T;
|
||||||
pick(): T;
|
pick(): T;
|
||||||
@ -37,14 +38,14 @@ export const makeArrayExtensions = (api: UserAPI) => {
|
|||||||
return this.includes(value);
|
return this.includes(value);
|
||||||
};
|
};
|
||||||
|
|
||||||
Array.prototype.square = function (): number[] {
|
Array.prototype.square = function(): number[] {
|
||||||
/**
|
/**
|
||||||
* @returns New array with squared values.
|
* @returns New array with squared values.
|
||||||
*/
|
*/
|
||||||
return this.map((x: number) => x * x);
|
return this.map((x: number) => x * x);
|
||||||
};
|
};
|
||||||
|
|
||||||
Array.prototype.sqrt = function (): number[] {
|
Array.prototype.sqrt = function(): number[] {
|
||||||
/**
|
/**
|
||||||
* @returns New array with square roots of values. Throws if any element is negative.
|
* @returns New array with square roots of values. Throws if any element is negative.
|
||||||
*/
|
*/
|
||||||
@ -53,7 +54,7 @@ export const makeArrayExtensions = (api: UserAPI) => {
|
|||||||
return this.map((x: number) => Math.sqrt(x));
|
return this.map((x: number) => Math.sqrt(x));
|
||||||
};
|
};
|
||||||
|
|
||||||
Array.prototype.add = function (amount: number): number[] {
|
Array.prototype.add = function(amount: number): number[] {
|
||||||
/**
|
/**
|
||||||
* @param amount - The value to add to each element in the array.
|
* @param amount - The value to add to each element in the array.
|
||||||
* @returns New array with added values.
|
* @returns New array with added values.
|
||||||
@ -61,7 +62,7 @@ export const makeArrayExtensions = (api: UserAPI) => {
|
|||||||
return this.map((x: number) => x + amount);
|
return this.map((x: number) => x + amount);
|
||||||
};
|
};
|
||||||
|
|
||||||
Array.prototype.sub = function (amount: number): number[] {
|
Array.prototype.sub = function(amount: number): number[] {
|
||||||
/**
|
/**
|
||||||
* @param amount - The value to subtract from each element in the array.
|
* @param amount - The value to subtract from each element in the array.
|
||||||
* @returns New array with subtracted values.
|
* @returns New array with subtracted values.
|
||||||
@ -69,7 +70,7 @@ export const makeArrayExtensions = (api: UserAPI) => {
|
|||||||
return this.map((x: number) => x - amount);
|
return this.map((x: number) => x - amount);
|
||||||
};
|
};
|
||||||
|
|
||||||
Array.prototype.mult = function (amount: number): number[] {
|
Array.prototype.mult = function(amount: number): number[] {
|
||||||
/**
|
/**
|
||||||
* @param amount - The value to multiply with each element in the array.
|
* @param amount - The value to multiply with each element in the array.
|
||||||
* @returns New array with multiplied values.
|
* @returns New array with multiplied values.
|
||||||
@ -77,7 +78,7 @@ export const makeArrayExtensions = (api: UserAPI) => {
|
|||||||
return this.map((x: number) => x * amount);
|
return this.map((x: number) => x * amount);
|
||||||
};
|
};
|
||||||
|
|
||||||
Array.prototype.div = function (amount: number): number[] {
|
Array.prototype.div = function(amount: number): number[] {
|
||||||
/**
|
/**
|
||||||
* @param amount - The value to divide each element in the array by.
|
* @param amount - The value to divide each element in the array by.
|
||||||
* @returns New array with divided values. Throws if division by zero.
|
* @returns New array with divided values. Throws if division by zero.
|
||||||
@ -86,7 +87,7 @@ export const makeArrayExtensions = (api: UserAPI) => {
|
|||||||
return this.map((x: number) => x / amount);
|
return this.map((x: number) => x / amount);
|
||||||
};
|
};
|
||||||
|
|
||||||
Array.prototype.pick = function () {
|
Array.prototype.pick = function() {
|
||||||
/**
|
/**
|
||||||
* Returns a random element from an array.
|
* Returns a random element from an array.
|
||||||
*
|
*
|
||||||
@ -95,7 +96,7 @@ export const makeArrayExtensions = (api: UserAPI) => {
|
|||||||
return this[Math.floor(api.randomGen() * this.length)];
|
return this[Math.floor(api.randomGen() * 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.
|
||||||
* @param min - The minimum value of the random numbers
|
* @param min - The minimum value of the random numbers
|
||||||
@ -112,7 +113,7 @@ export const makeArrayExtensions = (api: UserAPI) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
Array.prototype.bar = function () {
|
Array.prototype.bar = function() {
|
||||||
/**
|
/**
|
||||||
* Returns an element from an array based on the current bar.
|
* Returns an element from an array based on the current bar.
|
||||||
*
|
*
|
||||||
@ -121,7 +122,7 @@ export const makeArrayExtensions = (api: UserAPI) => {
|
|||||||
return this[api.app.clock.time_position.bar % this.length];
|
return this[api.app.clock.time_position.bar % this.length];
|
||||||
};
|
};
|
||||||
|
|
||||||
Array.prototype.pulse = function () {
|
Array.prototype.pulse = function() {
|
||||||
/**
|
/**
|
||||||
* Returns an element from an array based on the current pulse.
|
* Returns an element from an array based on the current pulse.
|
||||||
*
|
*
|
||||||
@ -130,7 +131,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.beat = function (divisor: number = 1) {
|
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(
|
||||||
@ -138,8 +139,9 @@ export const makeArrayExtensions = (api: UserAPI) => {
|
|||||||
);
|
);
|
||||||
return this[slice_count % this.length];
|
return this[slice_count % this.length];
|
||||||
};
|
};
|
||||||
|
Array.prototype.b = Array.prototype.beat;
|
||||||
|
|
||||||
Array.prototype.shuffle = function () {
|
Array.prototype.shuffle = function() {
|
||||||
/**
|
/**
|
||||||
* Shuffles the array in place.
|
* Shuffles the array in place.
|
||||||
*
|
*
|
||||||
@ -158,7 +160,7 @@ export const makeArrayExtensions = (api: UserAPI) => {
|
|||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
Array.prototype.rotate = function (steps: number) {
|
Array.prototype.rotate = function(steps: number) {
|
||||||
/**
|
/**
|
||||||
* Rotates the array in place.
|
* Rotates the array in place.
|
||||||
*
|
*
|
||||||
@ -178,7 +180,7 @@ export const makeArrayExtensions = (api: UserAPI) => {
|
|||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
Array.prototype.unique = function () {
|
Array.prototype.unique = function() {
|
||||||
/**
|
/**
|
||||||
* Removes duplicate elements from the array in place.
|
* Removes duplicate elements from the array in place.
|
||||||
*
|
*
|
||||||
@ -211,7 +213,7 @@ export const makeArrayExtensions = (api: UserAPI) => {
|
|||||||
if (this.length <= 1) {
|
if (this.length <= 1) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
for (let i = 0; i < this.length; ) {
|
for (let i = 0; i < this.length;) {
|
||||||
const rand = api.randomGen() * 100;
|
const rand = api.randomGen() * 100;
|
||||||
if (rand < amount) {
|
if (rand < amount) {
|
||||||
if (this.length > 1) {
|
if (this.length > 1) {
|
||||||
@ -324,7 +326,7 @@ export const makeArrayExtensions = (api: UserAPI) => {
|
|||||||
return left_to_right.concat(right_to_left);
|
return left_to_right.concat(right_to_left);
|
||||||
};
|
};
|
||||||
|
|
||||||
Array.prototype.loop = function (index: number) {
|
Array.prototype.loop = function(index: number) {
|
||||||
/**
|
/**
|
||||||
* Returns an element from the array based on the index.
|
* Returns an element from the array based on the index.
|
||||||
* The index will wrap over the array.
|
* The index will wrap over the array.
|
||||||
@ -335,7 +337,7 @@ export const makeArrayExtensions = (api: UserAPI) => {
|
|||||||
return this[index % this.length];
|
return this[index % this.length];
|
||||||
};
|
};
|
||||||
|
|
||||||
Array.prototype.random = function () {
|
Array.prototype.random = function() {
|
||||||
/**
|
/**
|
||||||
* Returns a random element from the array.
|
* Returns a random element from the array.
|
||||||
*
|
*
|
||||||
@ -346,7 +348,7 @@ export const makeArrayExtensions = (api: UserAPI) => {
|
|||||||
Array.prototype.rand = Array.prototype.random;
|
Array.prototype.rand = Array.prototype.random;
|
||||||
};
|
};
|
||||||
|
|
||||||
Array.prototype.scale = function (
|
Array.prototype.scale = function(
|
||||||
scale: string = "major",
|
scale: string = "major",
|
||||||
base_note: number = 0
|
base_note: number = 0
|
||||||
) {
|
) {
|
||||||
@ -370,7 +372,7 @@ Array.prototype.scale = function (
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Array.prototype.scaleArp = function (
|
Array.prototype.scaleArp = function(
|
||||||
scaleName: string = "major",
|
scaleName: string = "major",
|
||||||
boundary: number = 0
|
boundary: number = 0
|
||||||
) {
|
) {
|
||||||
|
|||||||
Reference in New Issue
Block a user