build
This commit is contained in:
parent
68b481af6e
commit
1d4129e84d
8 changed files with 94 additions and 66 deletions
23
docs/dist/midi.js
vendored
23
docs/dist/midi.js
vendored
|
|
@ -24,12 +24,12 @@ Pattern.prototype.midi = function(output, channel = 1) {
|
|||
if (output?.constructor?.name === "Pattern") {
|
||||
throw new Error(`.midi does not accept Pattern input. Make sure to pass device name with single quotes. Example: .midi('${WebMidi.outputs?.[0]?.name || "IAC Driver Bus 1"}')`);
|
||||
}
|
||||
return this.fmap((value) => ({
|
||||
...value,
|
||||
onTrigger: (time, event) => {
|
||||
value = value.value || value;
|
||||
if (!isNote(value)) {
|
||||
throw new Error("not a note: " + value);
|
||||
return this._withEvent((event) => {
|
||||
const onTrigger = (time, event2) => {
|
||||
let note = event2.value;
|
||||
const velocity = event2.context?.velocity ?? 0.9;
|
||||
if (!isNote(note)) {
|
||||
throw new Error("not a note: " + note);
|
||||
}
|
||||
if (!WebMidi.enabled) {
|
||||
throw new Error(`🎹 WebMidi is not enabled. Supported Browsers: https://caniuse.com/?search=webmidi`);
|
||||
|
|
@ -43,13 +43,14 @@ Pattern.prototype.midi = function(output, channel = 1) {
|
|||
}
|
||||
const timingOffset = WebMidi.time - Tone.context.currentTime * 1e3;
|
||||
time = time * 1e3 + timingOffset;
|
||||
device.playNote(value, channel, {
|
||||
device.playNote(note, channel, {
|
||||
time,
|
||||
duration: event.duration * 1e3 - 5,
|
||||
velocity: 0.9
|
||||
duration: event2.duration * 1e3 - 5,
|
||||
velocity
|
||||
});
|
||||
}
|
||||
}));
|
||||
};
|
||||
return event.setContext({...event.context, onTrigger});
|
||||
});
|
||||
};
|
||||
export function useWebMidi(props) {
|
||||
const {ready, connected, disconnected} = props;
|
||||
|
|
|
|||
7
docs/dist/tone.js
vendored
7
docs/dist/tone.js
vendored
|
|
@ -24,6 +24,7 @@ Pattern.prototype.tone = function(instrument) {
|
|||
return this._withEvent((event) => {
|
||||
const onTrigger = (time, event2) => {
|
||||
let note = event2.value;
|
||||
let velocity = event2.context?.velocity ?? 0.75;
|
||||
switch (instrument.constructor.name) {
|
||||
case "PluckSynth":
|
||||
instrument.triggerAttack(note, time);
|
||||
|
|
@ -33,10 +34,10 @@ Pattern.prototype.tone = function(instrument) {
|
|||
break;
|
||||
case "Piano":
|
||||
instrument.keyDown({note, time, velocity: 0.5});
|
||||
instrument.keyUp({note, time: time + event2.duration});
|
||||
instrument.keyUp({note, time: time + event2.duration, velocity});
|
||||
break;
|
||||
case "Sampler":
|
||||
instrument.triggerAttackRelease(note, event2.duration, time);
|
||||
instrument.triggerAttackRelease(note, event2.duration, time, velocity);
|
||||
break;
|
||||
case "Players":
|
||||
if (!instrument.has(event2.value)) {
|
||||
|
|
@ -47,7 +48,7 @@ Pattern.prototype.tone = function(instrument) {
|
|||
player.stop(time + event2.duration);
|
||||
break;
|
||||
default:
|
||||
instrument.triggerAttackRelease(note, event2.duration, time);
|
||||
instrument.triggerAttackRelease(note, event2.duration, time, velocity);
|
||||
}
|
||||
};
|
||||
return event.setContext({...event.context, instrument, onTrigger});
|
||||
|
|
|
|||
41
docs/dist/tunes.js
vendored
41
docs/dist/tunes.js
vendored
|
|
@ -463,20 +463,29 @@ export const blippyRhodes = `Promise.all([
|
|||
"<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")
|
||||
export const wavyKalimba = `sampler({
|
||||
C5: 'https://freesound.org/data/previews/536/536549_11935698-lq.mp3'
|
||||
}).then((kalimba)=>{
|
||||
const delay = new FeedbackDelay(1/3, .5).chain(vol(.2), out());
|
||||
kalimba = kalimba.chain(vol(0.6).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")
|
||||
.velocity("<.8 .3 .6>*8")
|
||||
.slow(2)
|
||||
.tone(kalimba),
|
||||
"<c2 c2 f2 [[F2 C2] db2]>"
|
||||
.scale(scales)
|
||||
.scaleTranspose("[0 <2 4>]*2")
|
||||
.struct("x*4")
|
||||
.velocity("<.8 .5>*4")
|
||||
.velocity(0.8)
|
||||
.slow(2)
|
||||
.tone(kalimba)
|
||||
)
|
||||
.legato("<.4 .8 1 1.2 1.4 1.6 1.8 2>/8")
|
||||
.fast(1)
|
||||
})`;
|
||||
|
|
|
|||
4
docs/dist/useRepl.js
vendored
4
docs/dist/useRepl.js
vendored
|
|
@ -52,14 +52,14 @@ function useRepl({tune, defaultSynth, autolink = true, onEvent, onDraw}) {
|
|||
onEvent: useCallback((time, event) => {
|
||||
try {
|
||||
onEvent?.(event);
|
||||
const {onTrigger} = event.context;
|
||||
const {onTrigger, velocity} = event.context;
|
||||
if (!onTrigger) {
|
||||
const note = event.value;
|
||||
if (!isNote(note)) {
|
||||
throw new Error("not a note: " + note);
|
||||
}
|
||||
if (defaultSynth) {
|
||||
defaultSynth.triggerAttackRelease(note, event.duration, time);
|
||||
defaultSynth.triggerAttackRelease(note, event.duration, time, velocity);
|
||||
} else {
|
||||
throw new Error("no defaultSynth passed to useRepl.");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue