diff --git a/src/ArrayExtensions.ts b/src/ArrayExtensions.ts index 905b188..54771fa 100644 --- a/src/ArrayExtensions.ts +++ b/src/ArrayExtensions.ts @@ -26,6 +26,7 @@ declare global { in(value: T): boolean; square(): number[]; sqrt(): number[]; + gen(min: number, max: number, times: number): number[]; } } @@ -101,6 +102,20 @@ export const makeArrayExtensions = (api: UserAPI) => { return this[(api.app.clock.beats_since_origin / beat) % this.length]; }; + Array.prototype.gen = function (min: number, max: number, times: number) { + /** + * Returns an array of random numbers. + * @param min - The minimum value of the random numbers + * @param max - The maximum value of the random numbers + * @param times - The number of random numbers to generate + * @returns An array of random numbers + */ + if(times < 1) { + return []; + } + return Array.from({ length: times }, () => Math.floor(api.randomGen() * (max - min + 1)) + min); + }; + Array.prototype.bar = function () { /** * Returns an element from an array based on the current bar. @@ -137,7 +152,7 @@ export const makeArrayExtensions = (api: UserAPI) => { let currentIndex = this.length, randomIndex; while (currentIndex !== 0) { - randomIndex = Math.floor(Math.random() * currentIndex); + randomIndex = Math.floor(api.randomGen() * currentIndex); currentIndex--; [this[currentIndex], this[randomIndex]] = [ this[randomIndex], @@ -201,7 +216,7 @@ export const makeArrayExtensions = (api: UserAPI) => { return this; } for (let i = 0; i < this.length; ) { - const rand = Math.random() * 100; + const rand = api.randomGen() * 100; if (rand < amount) { if (this.length > 1) { this.splice(i, 1); @@ -329,7 +344,7 @@ export const makeArrayExtensions = (api: UserAPI) => { * * @returns A random element from the array */ - return this[Math.floor(Math.random() * this.length)]; + return this[Math.floor(api.randomGen() * this.length)]; }; Array.prototype.rand = Array.prototype.random; }; diff --git a/src/documentation/interface.ts b/src/documentation/interface.ts index 8c0f33a..a8d510f 100644 --- a/src/documentation/interface.ts +++ b/src/documentation/interface.ts @@ -24,7 +24,7 @@ Every Topos session is composed of several small scripts. A set of scripts is ca )} to ${key_shortcut("F9")}). - **the init script** (${key_shortcut( "Ctrl + I" - )}): _Evaluated on program load_. Used to set up the software the session to the desired state before playing (_bpm_, etc...). You can also access that script using the ${key_shortcut( + )}): _Evaluated on program load_. Used to set up the software the session to the desired state before playing, for example changing bpm or to initialize global variables (See Functions). You can also access that script using the ${key_shortcut( "F11" )} key. - **the note file** (${key_shortcut( diff --git a/src/documentation/keyboard.ts b/src/documentation/keyboard.ts index e594318..6a1604e 100644 --- a/src/documentation/keyboard.ts +++ b/src/documentation/keyboard.ts @@ -40,9 +40,8 @@ Topos is made to be controlled entirely with a keyboard. It is recommanded to st | Shortcut | Key | Description | |----------|-------|------------------------------------------------------------| |Evaluate|${key_shortcut("Ctrl + Enter")}| Evaluate the current script | -|Local Eval|${key_shortcut("Ctrl + F1")} to ${key_shortcut( - "Ctrl + F9" - )}|Local File Evaluation| +|Local Eval|${key_shortcut("Ctrl + F1")} to ${key_shortcut("Ctrl + F9")}|Local File Evaluation| +|Force Eval|${key_shortcut("Ctrl + Shift + Enter")}|Force evaluation of the current script| ## Special diff --git a/src/documentation/patterns.ts b/src/documentation/patterns.ts index ba5f8ff..a7dfcfb 100644 --- a/src/documentation/patterns.ts +++ b/src/documentation/patterns.ts @@ -98,7 +98,7 @@ mod([1,.5,.25].beat()) :: snd('sine') - random(index: number): pick a random element in the given list. - rand(index: number): shorter alias for the same method. - pick(): pick a random element in the list. - +- gen(min,max,length): generate a list of random numbers between _min_ and _max_ with a given _length_. ${makeExample( "Sipping some gasoline at the robot bar", @@ -114,6 +114,14 @@ mod([.5, 1].random() / 2) :: snd( true )} +${makeExample( + "Generate a list of random numbers", + ` + mod(0.5) && sound('arp').freq([].gen(300,600,10).div(3)).out() + `, + true +)} + - degrade(amount: number): removes _n_% of the list elements. Lists can be degraded as long as one element remains. The amount of degradation is given as a percentage. ${makeExample( diff --git a/src/main.ts b/src/main.ts index 57d71a9..25d5385 100644 --- a/src/main.ts +++ b/src/main.ts @@ -358,6 +358,16 @@ export class Editor { this.flashBackground("#404040", 200); } + // Shift + Ctrl + Enter: Evaluate the currently visible code block + if ( + (event.key === "Enter" && event.shiftKey && event.ctrlKey)) + { + event.preventDefault(); + this.currentFile().candidate = this.view.state.doc.toString(); + tryEvaluate(this, this.currentFile()); + this.flashBackground("#404040", 200); + } + // This is the modal to switch between universes if (event.ctrlKey && event.key === "b") { event.preventDefault();