Skip to content

Commit

Permalink
add sounds() function to print loaded sounds
Browse files Browse the repository at this point in the history
  • Loading branch information
felixroos committed Feb 28, 2025
1 parent da9017a commit d19b8a8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions panels/strudel.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

window.parent.strudel = strudel;
window.parent.strudelWindow = window;
window.parent.sounds = () => strudel.printSounds();
console.log('[strudel] waiting for document click to init');
window.parent.document.addEventListener('click', async function interaction() {
window.parent.document.removeEventListener('click', interaction);
Expand Down
39 changes: 39 additions & 0 deletions src/strudel.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,44 @@ export class StrudelSession {
this.enableAutoAnalyze = true;
this.init();
}
printSounds() {
const sounds = this.webaudio?.soundMap.get();
let lines = [''];

let lastGroup;
Object.entries(sounds).forEach(([key, sound]) => {
if (key === '_base') {
return;
}
if (sound.data.baseUrl?.includes('tidal-drum-machines')) {
return;
}
const sounds = sound.data.samples;
const [group, ...rest] = key.split('_');
if (rest.length && group !== lastGroup) {
lines.push(`----- ${group} -----`);
lines.push('');
lastGroup = group;
} else if (!rest.length && lastGroup !== '') {
lines.push(`----------`);
lines.push('');
lastGroup = '';
}
let extra = '';
if (Array.isArray(sounds)) {
extra = `:${sounds.length}`;
}

let name = key;
/* if (group === lastGroup && key.length > group.length) {
name = key.slice(group.length + 1);
} */
lines[lines.length - 1] += ` ${name}${extra}`;
lines[lines.length - 1] = lines[lines.length - 1].trim();
});

console.log(lines.join('\n'));
}

loadSamples() {
const ds = 'https://raw.githubusercontent.com/felixroos/dough-samples/main/';
Expand Down Expand Up @@ -79,6 +117,7 @@ export class StrudelSession {
);
try {
await Promise.all([this.loadSamples(), registerSynthSounds(), registerSoundfonts()]);
this.printSounds();
} catch (err) {
this.onError(err);
}
Expand Down

0 comments on commit d19b8a8

Please sign in to comment.