This commit is contained in:
Felix Roos 2022-03-06 10:40:07 +01:00
parent d5c79f697a
commit 629d36c63c
7 changed files with 184 additions and 53 deletions

6
docs/dist/tonal.js vendored
View file

@ -25,11 +25,11 @@ function scaleTranspose(scale, offset, note) {
while (Math.abs(i - noteIndex) < Math.abs(offset)) {
i += direction;
const index = mod(i, notes.length);
if (direction < 0 && n === "C") {
if (direction < 0 && n[0] === "C") {
o += direction;
}
n = notes[index];
if (direction > 0 && n === "C") {
if (direction > 0 && n[0] === "C") {
o += direction;
}
}
@ -42,7 +42,7 @@ Pattern.prototype._transpose = function(intervalOrSemitones) {
const semitones = typeof interval === "string" ? Interval.semitones(interval) || 0 : interval;
return event.withValue(() => event.value + semitones);
}
return event.withValue(() => Note.transpose(event.value, interval));
return event.withValue(() => Note.simplify(Note.transpose(event.value, interval)));
});
};
Pattern.prototype._scaleTranspose = function(offset) {

47
docs/dist/tone.js vendored
View file

@ -15,22 +15,39 @@ import {
NoiseSynth,
PluckSynth,
Sampler,
getDestination
getDestination,
Players
} from "../_snowpack/pkg/tone.js";
import {Piano} from "../_snowpack/pkg/@tonejs/piano.js";
const Pattern = _Pattern;
Pattern.prototype.tone = function(instrument) {
return this._withEvent((event) => {
const onTrigger = (time, event2) => {
if (instrument.constructor.name === "PluckSynth") {
instrument.triggerAttack(event2.value, time);
} else if (instrument.constructor.name === "NoiseSynth") {
instrument.triggerAttackRelease(event2.duration, time);
} else if (instrument.constructor.name === "Piano") {
instrument.keyDown({note: event2.value, time, velocity: 0.5});
instrument.keyUp({note: event2.value, time: time + event2.duration});
} else {
instrument.triggerAttackRelease(event2.value, event2.duration, time);
let note = event2.value;
switch (instrument.constructor.name) {
case "PluckSynth":
instrument.triggerAttack(note, time);
break;
case "NoiseSynth":
instrument.triggerAttackRelease(event2.duration, time);
break;
case "Piano":
instrument.keyDown({note, time, velocity: 0.5});
instrument.keyUp({note, time: time + event2.duration});
break;
case "Sampler":
instrument.triggerAttackRelease(note, event2.duration, time);
break;
case "Players":
if (!instrument.has(event2.value)) {
throw new Error(`name "${event2.value}" not defined for players`);
}
const player = instrument.player(event2.value);
player.start(time);
player.stop(time + event2.duration);
break;
default:
instrument.triggerAttackRelease(note, event2.duration, time);
}
};
return event.setContext({...event.context, instrument, onTrigger});
@ -46,7 +63,15 @@ export const monosynth = (options) => new MonoSynth(options);
export const noise = (options) => new NoiseSynth(options);
export const pluck = (options) => new PluckSynth(options);
export const polysynth = (options) => new PolySynth(options);
export const sampler = (options) => new Sampler(options);
export const sampler = (options, baseUrl) => new Promise((resolve) => {
const s = new Sampler(options, () => resolve(s), baseUrl);
});
export const players = (options, baseUrl = "") => {
options = !baseUrl ? options : Object.fromEntries(Object.entries(options).map(([key, value]) => [key, baseUrl + value]));
return new Promise((resolve) => {
const s = new Players(options, () => resolve(s));
});
};
export const synth = (options) => new Synth(options);
export const piano = async (options = {velocities: 1}) => {
const p = new Piano(options);

46
docs/dist/tunes.js vendored
View file

@ -434,3 +434,49 @@ export const barryHarris = `piano()
.slow(2)
.tone(p.toDestination()))
`;
export const blippyRhodes = `Promise.all([
players({
bd: 'samples/tidal/bd/BT0A0D0.wav',
sn: 'samples/tidal/sn/ST0T0S3.wav',
hh: 'samples/tidal/hh/000_hh3closedhh.wav'
}, 'https://loophole-letters.vercel.app/'),
sampler({
E1: 'samples/rhodes/MK2Md2000.mp3',
E2: 'samples/rhodes/MK2Md2012.mp3',
E3: 'samples/rhodes/MK2Md2024.mp3',
E4: 'samples/rhodes/MK2Md2036.mp3',
E5: 'samples/rhodes/MK2Md2048.mp3',
E6: 'samples/rhodes/MK2Md2060.mp3',
E7: 'samples/rhodes/MK2Md2072.mp3'
}, 'https://loophole-letters.vercel.app/')
])
.then(([drums, rhodes])=>{
const delay = new FeedbackDelay(1/12, .4).chain(vol(0.3), out());
rhodes = rhodes.chain(vol(0.5).connect(delay), out());
const bass = synth(osc('sawtooth8')).chain(vol(.5),out());
const scales = ['C major', 'C mixolydian', 'F lydian', ['F minor',slowcat('Db major','Db mixolydian')]];
const t = x => x.scale(sequence(...scales).slow(4));
return stack(
"<bd sn> <hh hh*2 hh*3>".tone(drums.chain(out())),
"<g4 c5 a4 [ab4 <eb5 f5>]>".apply(t).struct("x*8").apply(scaleTranspose("0 [-5,-2] -7 [-9,-2]")).legato(.2).slow(2).tone(rhodes),
//"<C^7 C7 F^7 [Fm7 <Db^7 Db7>]>".slow(2).voicings().struct("~ x").legato(.25).tone(rhodes),
"<c2 c3 f2 [[F2 C2] db2]>".legato("<1@3 [.3 1]>").slow(2).tone(bass),
).fast(3/2)
})`;
export const wavyRhodes = `sampler({
E1: 'MK2Md2000.mp3',
E2: 'MK2Md2012.mp3',
E3: 'MK2Md2024.mp3',
E4: 'MK2Md2036.mp3',
E5: 'MK2Md2048.mp3',
E6: 'MK2Md2060.mp3',
E7: 'MK2Md2072.mp3'
}, 'https://loophole-letters.vercel.app/samples/rhodes/').then((rhodes)=>{
const delay = new FeedbackDelay(1/6, .5).chain(vol(.2), out());
rhodes = rhodes.chain(vol(0.5).connect(delay), out());
const scales = sequence('C major', 'C mixolydian', 'F lydian', ['F minor', 'Db major']).slow(4);
return stack(
"[0 2 4 6 9 2 0 -2]*3".add("<0 2>/4").scale(scales).struct("x*8").slow(2).tone(rhodes),
"<c2 c2 f2 [[F2 C2] db2]>".scale(scales).scaleTranspose("[0 <2 4>]*2").struct("x*4").slow(2).tone(rhodes),
).legato("<.2 .4 .8 1 1.2 1.4 1.6 1.8 2>/8")
})`;