diff options
| author | julian laplace <julescarbon@gmail.com> | 2023-05-09 17:44:31 +0200 |
|---|---|---|
| committer | julian laplace <julescarbon@gmail.com> | 2023-05-09 17:44:31 +0200 |
| commit | 199f7c731886bd8e8ac0d28bd15ebec241255594 (patch) | |
| tree | 3122029522f44a105805bcb8f171f8b13fb956d8 /src/relabi/index.js | |
| parent | 0cac17666313c660b2fb6d18bea1aa844b060cbe (diff) | |
rendering dots
Diffstat (limited to 'src/relabi/index.js')
| -rw-r--r-- | src/relabi/index.js | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/src/relabi/index.js b/src/relabi/index.js index e392a27..89e4ce9 100644 --- a/src/relabi/index.js +++ b/src/relabi/index.js @@ -33,13 +33,13 @@ export default class Relabi { this.updateTime = 1; this.steps = 50; this.waves = waves || [ - { type: "sine", frequency: randrange(0.5, 1.5) }, - { type: "sine", frequency: randrange(0.75, 2.25) }, - { type: "sine", frequency: randrange(1, 3) }, - { type: "sine", frequency: randrange(2, 4) }, + { type: "triangle", frequency: randrange(0.5, 1.5) }, + { type: "triangle", frequency: randrange(0.75, 2.25) }, + { type: "triangle", frequency: randrange(1, 3) }, + { type: "triangle", frequency: randrange(2, 4) }, ]; this.bounds = bounds; - this.previousValue = 0; + this.previousValue = null; this.canvas = new RelabiCanvas({ relabi: this, parent }); } @@ -51,8 +51,8 @@ export default class Relabi { this.stop(); this.clock = new Tone.Clock((time) => { const values = this.generate(time); - this.canvas.append(time, values); - this.play(values); + const notes = this.play(values); + this.canvas.append(time, values, notes); }, this.updateTime); this.clock.start(); } @@ -77,8 +77,11 @@ export default class Relabi { let value; let values = []; + // Overshoot the line slightly each time + let stepCount = this.steps + 20; + // Generate several events per second - for (step = 0; step < this.steps; step += 1) { + for (step = 0; step < stepCount; step += 1) { // Time offset for this event const timeOffset = time + (step * this.updateTime) / this.steps; @@ -109,6 +112,7 @@ export default class Relabi { let index; let step; let noteCount = 0; + const notes = []; for (step = 0; step < this.steps; step += 1) { // Get the next value @@ -117,13 +121,23 @@ export default class Relabi { // Compute whether we crossed a boundary, and which direction for (index = 0; index < boundsCount; index += 1) { const bound = this.bounds[index]; - if (value < bound.level && bound.level < previousValue) { + if ( + value < bound.level && + bound.level < previousValue && + previousValue !== null + ) { // Going down this.trigger(time, bound.sounds[0]); + notes.push([time, bound.level, true]); noteCount += 1; - } else if (value > bound.level && bound.level > previousValue) { + } else if ( + value > bound.level && + bound.level > previousValue && + previousValue !== null + ) { // Going up this.trigger(time, bound.sounds[1]); + notes.push([time, bound.level, false]); noteCount += 1; } } @@ -134,6 +148,9 @@ export default class Relabi { // Store the latest value this.previousValue = previousValue; + + // Return the notes + return notes; } /** |
