@oletizi/audio-tools
Version:
Monorepo for hardware sampler utilities and format parsers
65 lines (51 loc) • 1.34 kB
Markdown
The `TranslateContext` can be customized by providing implementations of:
```typescript
interface TranslateContext {
fs: fileio; // File system operations
audioFactory: AudioFactory; // Audio file loading
audioTranslate: AudioTranslate; // Format conversion
}
```
```typescript
const customFactory: AudioFactory = {
loadFromFile: async (filepath) => {
// Custom implementation
return {
meta: { /* metadata */ },
filepath: filepath,
getSample: async () => { /* return Sample */ }
};
}
};
const ctx = {
...await newDefaultTranslateContext(),
audioFactory: customFactory
};
```
Create custom mapping logic by implementing `MapFunction`:
```typescript
const customMapper: MapFunction = (sources: AudioSource[]) => {
const keygroups: AbstractKeygroup[] = [];
// Your custom mapping logic
sources.forEach((source, index) => {
keygroups.push({
zones: [{
audioSource: source,
lowNote: 60 + index,
centerNote: 60 + index,
highNote: 60 + index,
lowVelocity: 0,
highVelocity: 127
}]
});
});
return keygroups;
};
// Use with map()
const result = await map(ctx, customMapper, opts);
```