Repository navigation
Expand file tree
/
Copy pathmake-fixtures.mjs
More file actions
100 lines (90 loc) · 3.89 KB
/
Copy pathmake-fixtures.mjs
File metadata and controls
100 lines (90 loc) · 3.89 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env node
// Regenerates the Guitar Pro test fixtures in e2e/fixtures/. Run with
// `node scripts/make-fixtures.mjs` after changing a song below, and commit the output.
//
// The songs are original (written for Smart Beat's tests), so they are safe to
// commit. They are written in alphaTex and saved as Guitar Pro 7 (.gp) with
// alphaTab's exporter.
import { mkdirSync, writeFileSync } from "node:fs";
import path from "node:path";
import * as alphaTab from "@coderline/alphatab";
import { ROOT } from "./npm-packages.mjs";
const OUTPUT_DIR = path.join(ROOT, "e2e", "fixtures");
/**
* Four tracks (guitar, bass, drums, piano). Bars 1–2 are at 60 BPM and bars
* 3–4 at 120 BPM, so the song lasts exactly 2 × 4 s + 2 × 2 s = 12 s.
* The bass has its own mixer values (volume 12/16, balance 4/16 = left) and
* the piano starts muted, to check that the mixer starts from the file.
*/
const PRACTICE_SONG = String.raw`
\title "Practice Song"
\artist "Smart Beat"
\tempo 60
\track "Guitar"
\staff {score tabs}
\instrument 29
:4 0.6 2.6 3.6 0.6 | 0.5 2.5 3.5 0.5 | \tempo 120 :4 0.4 2.4 3.4 0.4 | 0.3 2.3 3.3 0.3
\track "Bass" { volume 12 balance 4 }
\staff {tabs}
\tuning (G2 D2 A1 E1)
\instrument 33
:2 0.4 0.4 | 0.3 0.3 | 0.4 0.4 | 0.3 0.3
\track "Drums"
\instrument percussion
\articulation defaults
:4 ("Kick (hit)" "Hi-Hat (closed)") "Hi-Hat (closed)" ("Snare (hit)" "Hi-Hat (closed)") "Hi-Hat (closed)" |
:4 ("Kick (hit)" "Hi-Hat (closed)") "Hi-Hat (closed)" ("Snare (hit)" "Hi-Hat (closed)") "Hi-Hat (closed)" |
:8 ("Kick (hit)" "Hi-Hat (closed)") "Hi-Hat (closed)" "Hi-Hat (closed)" "Hi-Hat (closed)" ("Snare (hit)" "Hi-Hat (closed)") "Hi-Hat (closed)" "Hi-Hat (closed)" "Hi-Hat (closed)" |
:8 ("Kick (hit)" "Hi-Hat (closed)") "Hi-Hat (closed)" "Hi-Hat (closed)" "Hi-Hat (closed)" ("Snare (hit)" "Hi-Hat (closed)") "Hi-Hat (closed)" "Hi-Hat (closed)" "Hi-Hat (closed)"
\track "Piano" { mute }
\staff {score}
\instrument 0
:1 (C4 E4 G4) | (A3 C4 E4) | (F3 A3 C4) | (G3 B3 D4)
`;
/**
* One guitar, for the song's structure, techniques, lyrics and chords.
* Bars 1–3: an intro repeated once with a 1st and a 2nd ending; bar 4 has
* the Segno (verse, in G), bar 5 "To Coda", bar 6 "D.S. al Coda", bar 7 the
* Coda at 150 BPM. It plays bars 1 2 1 3 4 5 6 4 5 7: nine bars of 2.4 s at
* 100 BPM and the Coda's 1.6 s, 23.2 s in all.
*/
const STRUCTURE_SONG = String.raw`
\title "Structure Song"
\artist "Smart Beat"
\tempo 100
\track "Guitar"
\staff {score tabs}
\instrument 25
\lyrics "Ev-ery bar we sing a lit-tle more of this song for you and me"
\chord "G" 3 0 0 0 2 3
\section "Intro" \ro :4 3.6 5.6 7.6 5.6 |
\ae 1 \rc 2 3.5 5.5 7.5 5.5 |
\ae 2 5.4 7.4 9.4 7.4 |
\section "Verse" \ks G \jump Segno 3.6{ch "G"} 5.6{pm} 7.6{h} 5.6 |
\jump DaCoda 5.3{v} 7.3{b (0 4)} 5.3{sl} 7.3 |
\jump DalSegnoAlCoda :2 12.1{nh} 12.2 |
\section "Coda" \jump Coda \tempo 150 :1 (3.6 2.5 0.4 0.3 0.2 3.1)
`;
const settings = new alphaTab.Settings();
function writeGp7(name, tex) {
const score = alphaTab.importer.ScoreLoader.loadAlphaTex(tex, settings);
const bytes = new alphaTab.exporter.Gp7Exporter().export(score, settings);
writeFileSync(path.join(OUTPUT_DIR, name), bytes);
console.log(`✓ e2e/fixtures/${name} (${score.tracks.length} tracks, ${bytes.length} bytes)`);
}
/**
* Passes the desktop app's signature check (GP5 header) but is not a valid
* song, so the score renderer has to report it as damaged.
*/
function writeCorruptGp5(name) {
const version = "FICHIER GUITAR PRO v5.00";
const bytes = Buffer.alloc(64, 0xff);
bytes[0] = version.length;
bytes.write(version, 1, "latin1");
writeFileSync(path.join(OUTPUT_DIR, name), bytes);
console.log(`✓ e2e/fixtures/${name} (${bytes.length} bytes)`);
}
mkdirSync(OUTPUT_DIR, { recursive: true });
writeGp7("practice-song.gp", PRACTICE_SONG);
writeGp7("structure-song.gp", STRUCTURE_SONG);
writeCorruptGp5("corrupt.gp5");