fix soundfonts + samples without base
This commit is contained in:
parent
4e282dac5b
commit
720b1eeb27
2 changed files with 17 additions and 6 deletions
|
|
@ -93,7 +93,7 @@ export const loadGithubSamples = async (path, nameFn) => {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export const samples = (sampleMap, baseUrl = sampleMap._base) => {
|
export const samples = (sampleMap, baseUrl = sampleMap._base || '') => {
|
||||||
sampleCache.current = {
|
sampleCache.current = {
|
||||||
...sampleCache.current,
|
...sampleCache.current,
|
||||||
...Object.fromEntries(
|
...Object.fromEntries(
|
||||||
|
|
|
||||||
|
|
@ -113,6 +113,17 @@ const getSampleBufferSource = async (s, n, note) => {
|
||||||
return bufferSource;
|
return bufferSource;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const splitSN = (s, n) => {
|
||||||
|
if (!s.includes(':')) {
|
||||||
|
return [s, n];
|
||||||
|
}
|
||||||
|
let [s2, n2] = s.split(':');
|
||||||
|
if (isNaN(Number(s2))) {
|
||||||
|
return [s, n];
|
||||||
|
}
|
||||||
|
return [s2, n2];
|
||||||
|
};
|
||||||
|
|
||||||
Pattern.prototype.out = function () {
|
Pattern.prototype.out = function () {
|
||||||
return this.onTrigger(async (t, hap, ct) => {
|
return this.onTrigger(async (t, hap, ct) => {
|
||||||
const ac = getAudioContext();
|
const ac = getAudioContext();
|
||||||
|
|
@ -146,11 +157,11 @@ Pattern.prototype.out = function () {
|
||||||
gain *= velocity; // legacy fix for velocity
|
gain *= velocity; // legacy fix for velocity
|
||||||
// the chain will hold all audio nodes that connect to each other
|
// the chain will hold all audio nodes that connect to each other
|
||||||
const chain = [];
|
const chain = [];
|
||||||
if (typeof s === 'string' && s.includes(':')) {
|
if (typeof s === 'string') {
|
||||||
[s, n] = s.split(':');
|
[s, n] = splitSN(s, n);
|
||||||
}
|
}
|
||||||
if (typeof note === 'string' && note.includes(':')) {
|
if (typeof note === 'string') {
|
||||||
[note, n] = note.split(':');
|
[note, n] = splitSN(note, n);
|
||||||
}
|
}
|
||||||
if (!s || ['sine', 'square', 'triangle', 'sawtooth'].includes(s)) {
|
if (!s || ['sine', 'square', 'triangle', 'sawtooth'].includes(s)) {
|
||||||
// with synths, n and note are the same thing
|
// with synths, n and note are the same thing
|
||||||
|
|
@ -222,7 +233,7 @@ Pattern.prototype.out = function () {
|
||||||
if (soundfont || choke) {
|
if (soundfont || choke) {
|
||||||
const env = ac.createGain();
|
const env = ac.createGain();
|
||||||
const releaseLength = 0.1;
|
const releaseLength = 0.1;
|
||||||
env.gain.value = 1;
|
env.gain.value = .6;
|
||||||
env.gain.setValueAtTime(env.gain.value, t + duration);
|
env.gain.setValueAtTime(env.gain.value, t + duration);
|
||||||
env.gain.linearRampToValueAtTime(0, t + duration + releaseLength);
|
env.gain.linearRampToValueAtTime(0, t + duration + releaseLength);
|
||||||
// env.gain.linearRampToValueAtTime(0, t + duration + releaseLength);
|
// env.gain.linearRampToValueAtTime(0, t + duration + releaseLength);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue