Skip to content

Commit

Permalink
Merge pull request #239 from tidalcycles/load-samples-from-url
Browse files Browse the repository at this point in the history
Load samples from url
  • Loading branch information
felixroos committed Nov 2, 2022
2 parents 240a893 + d8843e6 commit 5eae156
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
8 changes: 7 additions & 1 deletion packages/webaudio/sampler.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,13 @@ export const loadGithubSamples = async (path, nameFn) => {
*
*/

export const samples = (sampleMap, baseUrl = sampleMap._base || '') => {
export const samples = async (sampleMap, baseUrl = sampleMap._base || '') => {
if (typeof sampleMap === 'string') {
const base = sampleMap.split('/').slice(0, -1).join('/');
return fetch(sampleMap)
.then((res) => res.json())
.then((json) => samples(json, baseUrl || json._base || base));
}
sampleCache.current = {
...sampleCache.current,
...Object.fromEntries(
Expand Down
14 changes: 4 additions & 10 deletions repl/src/prebake.mjs
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
import { Pattern, toMidi } from '@strudel.cycles/core';
import { samples } from '@strudel.cycles/webaudio';

const loadSamples = async (url, baseDir = '') => {
await fetch(url)
.then((res) => res.json())
.then((json) => samples(json, baseDir));
};

export async function prebake({ isMock = false, baseDir = '.' } = {}) {
if (!isMock) {
// https://archive.org/details/SalamanderGrandPianoV3
// License: CC-by http://creativecommons.org/licenses/by/3.0/ Author: Alexander Holm
loadSamples('piano.json', `${baseDir}/piano/`);
samples('piano.json', `${baseDir}/piano/`);
// https://github.com/sgossner/VCSL/
// https://api.github.com/repositories/126427031/contents/
// LICENSE: CC0 general-purpose
loadSamples('vcsl.json', 'github:sgossner/VCSL/master/');
loadSamples('tidal-drum-machines.json', 'github:ritchse/tidal-drum-machines/main/machines/');
loadSamples('EmuSP12.json', `${baseDir}/EmuSP12/`);
samples('vcsl.json', 'github:sgossner/VCSL/master/');
samples('tidal-drum-machines.json', 'github:ritchse/tidal-drum-machines/main/machines/');
samples('EmuSP12.json', `${baseDir}/EmuSP12/`);
}
}

Expand Down

0 comments on commit 5eae156

Please sign in to comment.