File size: 1,032 Bytes
6367981
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
 * score-hashes.ts — Print all regulation hashes for a score's measures.
 *
 * Usage:
 *   npx tsx src/scripts/score-hashes.ts <score_id>
 *
 * Output: JSON array of SHA1 hash strings to stdout.
 */

import { starry } from 'starry-omr';
import { pool, query } from '../db/client.js';

const scoreId = process.argv[2];
if (!scoreId) {
	console.error('Usage: npx tsx src/scripts/score-hashes.ts <score_id>');
	process.exit(1);
}

const { rows } = await query('SELECT data FROM scores WHERE id = $1', [scoreId]);
if (!rows.length) {
	console.error(`Score not found: ${scoreId}`);
	process.exit(1);
}

const scoreData = rows[0].data;
const score = starry.recoverJSON(scoreData, starry);
score.assemble();
const spartito = score.makeSpartito();

const hashes = new Set<string>();
for (const measure of spartito.measures) {
	const editable = new starry.EditableMeasure(measure);
	for (const h of editable.regulationHashes) {
		hashes.add(h);
	}
}

console.log(JSON.stringify(Array.from(hashes)));
await pool.end();
process.exit(0);