Add samples preload option

This commit is contained in:
Anton Duda 2025-10-24 03:35:43 +03:00
parent 4dfbb743ad
commit 0ef71cd431
4 changed files with 38 additions and 16 deletions

View file

@ -7,12 +7,11 @@ import VueEntry from './App.vue'
import { StrudelConfig } from './services/StrudelConfig'
import { strudelStateField } from './editor/StrudelPlugin'
import { highlightExtension } from './editor/StrudelHighlight'
import { samples } from '@/strudel/init.js'
import './editor/SyntaxHighlighting.js'
import { createStrudelBlock } from './commands/createStrudelBlock'
export interface StrudelSettings {}
interface PluginData {}
export default class StrudelPlugin extends Plugin {
@ -119,5 +118,23 @@ class StrudelSettingTab extends PluginSettingTab {
await this.plugin.saveSettings()
})
)
new Setting(containerEl)
.setName('Samples to preload')
.setDesc('URLs of audio samples to preload on startup for faster access.')
.addTextArea((text) =>
text
.setPlaceholder('Enter sample URLs, one per line')
.setValue(StrudelConfig.getInstance().samplesToPreload.join('\n') || '')
.onChange(async (value) => {
StrudelConfig.getInstance().samplesToPreload = value
.split('\n')
.map((line) => line.trim())
.filter((line) => line.length > 0)
await this.plugin.saveSettings()
samples(StrudelConfig.getInstance().samplesToPreload)
})
)
}
}

View file

@ -3,6 +3,7 @@ import { normalizePath } from '@/helpers/pathHelpers'
interface StrudelConfigData {
cacheDir: string | null
saveToCache: boolean
samplesToPreload: string[]
}
export class StrudelConfig {
@ -10,6 +11,14 @@ export class StrudelConfig {
public cacheDir: string | null = null
public saveToCache = true
public samplesToPreload: string[] = [
'https://raw.githubusercontent.com/felixroos/dough-samples/main/tidal-drum-machines.json',
'https://raw.githubusercontent.com/felixroos/dough-samples/main/piano.json',
'https://raw.githubusercontent.com/felixroos/dough-samples/main/Dirt-Samples.json',
'https://raw.githubusercontent.com/felixroos/dough-samples/main/EmuSP12.json',
'https://raw.githubusercontent.com/felixroos/dough-samples/main/vcsl.json',
'https://raw.githubusercontent.com/felixroos/dough-samples/main/mridangam.json',
]
// eslint-disable-next-line @typescript-eslint/no-empty-function
private constructor() {}
@ -26,6 +35,7 @@ export class StrudelConfig {
if (data.saveToCache !== undefined) {
this.saveToCache = data.saveToCache
}
this.samplesToPreload = data.samplesToPreload ? [...data.samplesToPreload] : []
}
public getCacheDir(): string | null {
@ -36,6 +46,7 @@ export class StrudelConfig {
return {
cacheDir: this.cacheDir,
saveToCache: this.saveToCache,
samplesToPreload: this.samplesToPreload,
}
}
}

View file

@ -3,9 +3,10 @@ import { App } from 'obsidian'
import { ref } from 'vue'
import { EditorView } from '@codemirror/view'
import { MarkdownView, WorkspaceLeaf } from 'obsidian'
import { initStrudel as init, recalculateMiniLocations } from '@/strudel/init.js'
import { initStrudel as init, samples } from '@/strudel/init.js'
import { highlightMiniLocations, updateMiniLocations } from '@/editor/StrudelHighlight'
import { Drawer, drawPianoroll } from '@/strudel/draw/index.mjs'
import { StrudelConfig } from '@/services/StrudelConfig'
export class GlobalStore {
private static instance: GlobalStore
@ -122,6 +123,7 @@ export class GlobalStore {
}
},
})
samples(StrudelConfig.getInstance().samplesToPreload)
this.strudelInitialized.value = true
this.drawer = new Drawer(

View file

@ -10,10 +10,7 @@ import * as superdough from './superdough/index.mjs'
import * as supradough from './supradough/index.mjs'
import * as xen from './xen/index.mjs'
import { Pattern } from './core/pattern.mjs'
// import { evalScope, setTime } from './core/clockworker.js'
import { initAudioOnFirstClick, webaudioRepl } from './webaudio/index.mjs'
// import { registerSoundfonts } from './soundfonts/index.mjs';
import { evaluate as _evaluate } from './transpiler/index.mjs'
import { miniAllStrings } from './mini/index.mjs'
@ -22,8 +19,6 @@ export async function initStrudel(options = {}) {
options.miniAllStrings !== false && miniAllStrings()
const repl = webaudioRepl({ ...options, transpiler: transpiler.transpiler })
await superdough.samples('github:tidalcycles/dirt-samples')
superdough.registerSynthSounds()
soundfonts.registerSoundfonts()
@ -31,15 +26,12 @@ export async function initStrudel(options = {}) {
setTimeout(() => repl.scheduler.now())
// Pattern.prototype.play = function () {
// repl.setPattern(this, true)
// return this
// }
return repl
}
export function recalculateMiniLocations(code) {
const { miniLocations } = transpiler.transpiler(code)
return miniLocations
export function samples(urls) {
for (const url of urls) {
superdough.samples(url)
}
}