Fixing a thousand bugs
This commit is contained in:
@ -12,13 +12,12 @@ declare global {
|
||||
random(index: number): T;
|
||||
rand(index: number): T;
|
||||
degrade(amount: number): T;
|
||||
repeatAll(amount: number): T;
|
||||
repeatPair(amount: number): T;
|
||||
repeat(amount: number): T;
|
||||
repeatEven(amount: number): T;
|
||||
repeatOdd(amount: number): T;
|
||||
beat(division: number): T;
|
||||
b(division: number): T;
|
||||
bar(): T;
|
||||
pulse(): T;
|
||||
pick(): T;
|
||||
loop(index: number): T;
|
||||
shuffle(): this;
|
||||
@ -26,7 +25,6 @@ declare global {
|
||||
scaleArp(scaleName: string): this;
|
||||
rotate(steps: number): this;
|
||||
unique(): this;
|
||||
in(value: T): boolean;
|
||||
square(): number[];
|
||||
sqrt(): number[];
|
||||
gen(min: number, max: number, times: number): number[];
|
||||
@ -34,10 +32,6 @@ declare global {
|
||||
}
|
||||
|
||||
export const makeArrayExtensions = (api: UserAPI) => {
|
||||
Array.prototype.in = function <T>(this: T[], value: T): boolean {
|
||||
return this.includes(value);
|
||||
};
|
||||
|
||||
Array.prototype.square = function (): number[] {
|
||||
/**
|
||||
* @returns New array with squared values.
|
||||
@ -113,22 +107,19 @@ export const makeArrayExtensions = (api: UserAPI) => {
|
||||
);
|
||||
};
|
||||
|
||||
Array.prototype.bar = function() {
|
||||
Array.prototype.bar = function (value: number = 1) {
|
||||
/**
|
||||
* Returns an element from an array based on the current bar.
|
||||
*
|
||||
* @param array - The array of values to pick from
|
||||
*/
|
||||
if (value === 1) {
|
||||
return this[api.app.clock.time_position.bar % this.length];
|
||||
};
|
||||
|
||||
Array.prototype.pulse = function() {
|
||||
/**
|
||||
* Returns an element from an array based on the current pulse.
|
||||
*
|
||||
* @param array - The array of values to pick from
|
||||
*/
|
||||
return this[api.app.clock.time_position.pulse % this.length];
|
||||
} else {
|
||||
return this[
|
||||
Math.floor(api.app.clock.time_position.bar / value) % this.length
|
||||
];
|
||||
}
|
||||
};
|
||||
|
||||
Array.prototype.beat = function (divisor: number = 1) {
|
||||
@ -228,7 +219,7 @@ export const makeArrayExtensions = (api: UserAPI) => {
|
||||
return this;
|
||||
};
|
||||
|
||||
Array.prototype.repeatAll = function <T>(this: T[], amount: number = 1) {
|
||||
Array.prototype.repeat = function <T>(this: T[], amount: number = 1) {
|
||||
/**
|
||||
* Repeats all elements in the array n times.
|
||||
*
|
||||
@ -250,7 +241,7 @@ export const makeArrayExtensions = (api: UserAPI) => {
|
||||
return this;
|
||||
};
|
||||
|
||||
Array.prototype.repeatPair = function <T>(this: T[], amount: number = 1) {
|
||||
Array.prototype.repeatOdd = function <T>(this: T[], amount: number = 1) {
|
||||
/**
|
||||
* Repeats all elements in the array n times, except for the
|
||||
* elements at odd indexes.
|
||||
@ -280,7 +271,7 @@ export const makeArrayExtensions = (api: UserAPI) => {
|
||||
return this;
|
||||
};
|
||||
|
||||
Array.prototype.repeatOdd = function <T>(this: T[], amount: number = 1) {
|
||||
Array.prototype.repeatEven = function <T>(this: T[], amount: number = 1) {
|
||||
/**
|
||||
* Repeats all elements in the array n times, except for the
|
||||
* elements at even indexes.
|
||||
|
||||
@ -164,7 +164,7 @@ export abstract class Event {
|
||||
return this.modify(func);
|
||||
};
|
||||
|
||||
private modify = (func: Function): Event => {
|
||||
modify = (func: Function): Event => {
|
||||
/**
|
||||
* Returns a transformed Event. This function is used internally by the
|
||||
* other functions of this class. It is just a wrapper for the function
|
||||
|
||||
@ -6,11 +6,11 @@ export const patterns = (application: Editor): string => {
|
||||
return `
|
||||
# Patterns
|
||||
|
||||
Music really comes to life when you start playing with algorithmic patterns. They can be used to describe a melody, a rhythm, a texture, a set of custom parameters or anything else you can think of. Topos comes with a lot of different abstractions to deal with musical patterns of increasing complexity. Some knowledge of patterns and how to use them will help you to break out of simple loops and repeating structures.
|
||||
Playing with fixed values is fine but what if you could give more life to your parameters? Having parameters that can vary over time is important to describe melodies, rhythms, complex textures, etc. Topos comes with a lot of different abstractions to deal with musical patterns of increasing complexity. Some knowledge of patterns and how to use them will help you to break out of simple loops and repeating structures.
|
||||
|
||||
## Working with Arrays
|
||||
## Arrays
|
||||
|
||||
JavaScript is using [Arrays](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) as a data structure for lists. Topos is extending them with custom methods that allow you to enter softly into a universe of musical patterns. These methods can often be chained to compose a more complex expression: <ic>[1, 2, 3].repeatOdd(5).palindrome().beat()</ic>.
|
||||
One of the most basic JavaScript data structures is [Arrays](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array). Topos is extending this data structure with custom methods that makes it usable for describing patterns that evolve over time. These methods can often be chained to compose more complex expressions: <ic>[1, 2, 3].repeatOdd(5).palindrome().beat()</ic>.
|
||||
|
||||
- <ic>beat(division: number)</ic>: this method will return the next value in the list every _n_ pulses. By default, <ic>1</ic> equals to one beat but integer and floating point number values are supported as well. This method is extremely powerful and can be used for many different purposes. Check out the examples.
|
||||
|
||||
@ -52,8 +52,7 @@ flip(4)::beat(2)::snd('pad').n(2).shape(.5).orbit(2).room(0.9).size(0.9).release
|
||||
false
|
||||
)}
|
||||
|
||||
- <ic>pulse()</ic>: returns the index of the list corresponding to the current pulse (with wrapping). This method will return a different value for each pulse.
|
||||
- <ic>bar()</ic>: returns the index of the list corresponding to the current bar (with wrapping). This method will return a different value for each bar.
|
||||
- <ic>bar(value: number = 1)</ic>: returns the next value every bar (if <ic>value = 1</ic>). Using a larger value will return the next value every <ic>n</ic> bars.
|
||||
|
||||
${makeExample(
|
||||
"A simple drumbeat in no time!",
|
||||
@ -126,8 +125,8 @@ beat(.25)::snd('amencutup').n([1,2,3,4,5,6,7,8,9].degrade(20).loop($(1))).out()
|
||||
true
|
||||
)}
|
||||
|
||||
- <ic>repeatAll(amount: number)</ic>: repeat every list elements _n_ times.
|
||||
- <ic>repeatPair(amount: number)</ic>: repeaet every pair element of the list _n_ times.
|
||||
- <ic>repeat(amount: number)</ic>: repeat every list elements _n_ times.
|
||||
- <ic>repeatEven(amount: number)</ic>: repeaet every pair element of the list _n_ times.
|
||||
- <ic>repeatOdd(amount: number)</ic>: repeaet every odd element of the list _n_ times.
|
||||
|
||||
${makeExample(
|
||||
|
||||
Reference in New Issue
Block a user