Improve MIDI search and add browser playback engines.

This commit is contained in:
b1rdmania
2025-12-18 14:25:38 +00:00
parent 4fdc6984bc
commit 2c9d06d8d7
30 changed files with 2080 additions and 93 deletions
+14
View File
@@ -2,6 +2,7 @@ import fs from 'fs/promises';
import path from 'path';
import crypto from 'crypto';
import { ScoreUtils } from '../utils/ScoreUtils.js';
import { SimpleMIDI } from '../utils/SimpleMIDI.js';
import type { CacheEntry } from '../types.js';
export class MIDIFetchService {
@@ -14,6 +15,19 @@ export class MIDIFetchService {
async fetch(url: string): Promise<{ success: boolean; data?: ArrayBuffer; error?: string }> {
try {
// Only generate synthetic MIDI for explicit synthetic URLs or when enabled
if (url.startsWith('synthetic:') || url.includes('mock') ||
(process.env.USE_SYNTHETIC_FETCH === '1')) {
console.log(`Generating synthetic MIDI for: ${url}`);
const songName = url.startsWith('synthetic:')
? url.replace('synthetic:', '')
: url.split('/').pop()?.replace('.mid', '') || 'test';
const syntheticBuffer = SimpleMIDI.generateValidMIDI(songName);
console.log(`Generated ${syntheticBuffer.byteLength} bytes of synthetic MIDI data`);
return { success: true, data: syntheticBuffer };
}
// Check cache first
const hash = this.hashUrl(url);
const cached = await this.getCached(hash);
+3
View File
@@ -1,15 +1,18 @@
import type { SearchAdapter, MIDICandidate } from '../types.js';
import { BitMidiAdapter } from '../adapters/BitMidiAdapter.js';
import { DongraysAdapter } from '../adapters/DongraysAdapter.js';
import { MockAdapter } from '../adapters/MockAdapter.js';
export class MIDISearchService {
private adapters: SearchAdapter[];
constructor() {
// Real MIDI adapters only - no mock
this.adapters = [
new BitMidiAdapter(),
new DongraysAdapter()
];
console.log('MIDISearchService initialized with real adapters:', this.adapters.map(a => a.name));
}
async search(query: string): Promise<MIDICandidate[]> {