mirror of
https://codeberg.org/uzu/strudel
synced 2026-07-31 13:21:52 -04:00
build
This commit is contained in:
@@ -41709,11 +41709,11 @@ function useRepl({ tune , defaultSynth , autolink =true , onEvent , onDraw }) {
|
||||
onEvent: _react.useCallback((time, event)=>{
|
||||
try {
|
||||
onEvent?.(event);
|
||||
const { onTrigger } = event.context;
|
||||
const { onTrigger , velocity } = event.context;
|
||||
if (!onTrigger) {
|
||||
const note = event.value;
|
||||
if (!_tone.isNote(note)) throw new Error('not a note: ' + note);
|
||||
if (defaultSynth) defaultSynth.triggerAttackRelease(note, event.duration, time);
|
||||
if (defaultSynth) defaultSynth.triggerAttackRelease(note, event.duration, time, velocity);
|
||||
else throw new Error('no defaultSynth passed to useRepl.');
|
||||
/* console.warn('no instrument chosen', event);
|
||||
throw new Error(`no instrument chosen for ${JSON.stringify(event)}`); */ } else onTrigger(time, event);
|
||||
@@ -42641,6 +42641,13 @@ class Pattern {
|
||||
return this.withEventSpan((span)=>new TimeSpan(span.begin, span.begin.add(span.end.sub(span.begin).mul(value)))
|
||||
);
|
||||
}
|
||||
_velocity(velocity) {
|
||||
return this._withContext((context)=>({
|
||||
...context,
|
||||
velocity: (context.velocity || 1) * velocity
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
// methods of Pattern that get callable factories
|
||||
Pattern.prototype.patternified = [
|
||||
@@ -42650,7 +42657,8 @@ Pattern.prototype.patternified = [
|
||||
'early',
|
||||
'late',
|
||||
'duration',
|
||||
'legato'
|
||||
'legato',
|
||||
'velocity'
|
||||
];
|
||||
// methods that create patterns, which are added to patternified Pattern methods
|
||||
Pattern.prototype.factories = {
|
||||
@@ -56583,9 +56591,11 @@ Pattern.prototype.tone = function(instrument) {
|
||||
return this._withEvent((event1)=>{
|
||||
const onTrigger = (time, event)=>{
|
||||
let note = event.value;
|
||||
let velocity = event.context?.velocity ?? 0.75;
|
||||
switch(instrument.constructor.name){
|
||||
case 'PluckSynth':
|
||||
// note = getPlayableNoteValue(event);
|
||||
// velocity?
|
||||
instrument.triggerAttack(note, time);
|
||||
break;
|
||||
case 'NoiseSynth':
|
||||
@@ -56600,22 +56610,24 @@ Pattern.prototype.tone = function(instrument) {
|
||||
});
|
||||
instrument.keyUp({
|
||||
note,
|
||||
time: time + event.duration
|
||||
time: time + event.duration,
|
||||
velocity
|
||||
});
|
||||
break;
|
||||
case 'Sampler':
|
||||
// note = getPlayableNoteValue(event);
|
||||
instrument.triggerAttackRelease(note, event.duration, time);
|
||||
instrument.triggerAttackRelease(note, event.duration, time, velocity);
|
||||
break;
|
||||
case 'Players':
|
||||
if (!instrument.has(event.value)) throw new Error(`name "${event.value}" not defined for players`);
|
||||
const player = instrument.player(event.value);
|
||||
// velocity ?
|
||||
player.start(time);
|
||||
player.stop(time + event.duration);
|
||||
break;
|
||||
default:
|
||||
// note = getPlayableNoteValue(event);
|
||||
instrument.triggerAttackRelease(note, event.duration, time);
|
||||
instrument.triggerAttackRelease(note, event.duration, time, velocity);
|
||||
}
|
||||
};
|
||||
return event1.setContext({
|
||||
@@ -59361,30 +59373,32 @@ const outputByName = (name)=>WebMidi.getOutputByName(name)
|
||||
;
|
||||
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 (!_tone.isNote(value)) throw new Error('not a note: ' + value);
|
||||
if (!WebMidi.enabled) throw new Error(`🎹 WebMidi is not enabled. Supported Browsers: https://caniuse.com/?search=webmidi`);
|
||||
if (!WebMidi.outputs.length) throw new Error(`🔌 No MIDI devices found. Connect a device or enable IAC Driver.`);
|
||||
const device = output ? outputByName(output) : WebMidi.outputs[0];
|
||||
if (!device) throw new Error(`🔌 MIDI device '${output ? output : ''}' not found. Use one of ${WebMidi.outputs.map((o)=>`'${o.name}'`
|
||||
).join(' | ')}`);
|
||||
// console.log('midi', value, output);
|
||||
const timingOffset = WebMidi.time - _tone.context.currentTime * 1000;
|
||||
time = time * 1000 + timingOffset;
|
||||
// const inMs = '+' + (time - Tone.context.currentTime) * 1000;
|
||||
// await enableWebMidi()
|
||||
device.playNote(value, channel, {
|
||||
time,
|
||||
duration: event.duration * 1000 - 5,
|
||||
// velocity: velocity ?? 0.5,
|
||||
velocity: 0.9
|
||||
});
|
||||
}
|
||||
})
|
||||
);
|
||||
return this._withEvent((event1)=>{
|
||||
const onTrigger = (time, event)=>{
|
||||
let note = event.value;
|
||||
const velocity = event.context?.velocity ?? 0.9;
|
||||
if (!_tone.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`);
|
||||
if (!WebMidi.outputs.length) throw new Error(`🔌 No MIDI devices found. Connect a device or enable IAC Driver.`);
|
||||
const device = output ? outputByName(output) : WebMidi.outputs[0];
|
||||
if (!device) throw new Error(`🔌 MIDI device '${output ? output : ''}' not found. Use one of ${WebMidi.outputs.map((o)=>`'${o.name}'`
|
||||
).join(' | ')}`);
|
||||
// console.log('midi', value, output);
|
||||
const timingOffset = WebMidi.time - _tone.context.currentTime * 1000;
|
||||
time = time * 1000 + timingOffset;
|
||||
// const inMs = '+' + (time - Tone.context.currentTime) * 1000;
|
||||
// await enableWebMidi()
|
||||
device.playNote(note, channel, {
|
||||
time,
|
||||
duration: event.duration * 1000 - 5,
|
||||
velocity
|
||||
});
|
||||
};
|
||||
return event1.setContext({
|
||||
...event1.context,
|
||||
onTrigger
|
||||
});
|
||||
});
|
||||
};
|
||||
function useWebMidi(props) {
|
||||
const { ready , connected , disconnected } = props;
|
||||
@@ -110944,4 +110958,4 @@ exports.default = cx;
|
||||
|
||||
},{"@parcel/transformer-js/src/esmodule-helpers.js":"gkKU3"}]},["3uVTb"], "3uVTb", "parcelRequire94c2")
|
||||
|
||||
//# sourceMappingURL=index.dc7f72be.js.map
|
||||
//# sourceMappingURL=index.23fc2d31.js.map
|
||||
File diff suppressed because one or more lines are too long
@@ -11,6 +11,6 @@
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||
<script src="/tutorial/index.dc7f72be.js" defer=""></script>
|
||||
<script src="/tutorial/index.23fc2d31.js" defer=""></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user