-
Notifications
You must be signed in to change notification settings - Fork 255
Expand file tree
/
Copy pathPercussionTablature.test.ts
More file actions
129 lines (102 loc) · 4.79 KB
/
PercussionTablature.test.ts
File metadata and controls
129 lines (102 loc) · 4.79 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import { Note } from '@coderline/alphatab/model/Note';
import { Staff } from '@coderline/alphatab/model/Staff';
import { Track } from '@coderline/alphatab/model/Track';
import { Tuning } from '@coderline/alphatab/model/Tuning';
import { TabBarRendererFactory } from '@coderline/alphatab/rendering/TabBarRendererFactory';
import { Settings } from '@coderline/alphatab/Settings';
import { expect } from 'chai';
describe('PercussionTablature', () => {
describe('Note.isPercussion', () => {
it('returns true when percussionArticulation is set regardless of string', () => {
const note = new Note();
note.percussionArticulation = 36;
note.string = 6;
note.fret = 36;
expect(note.isPercussion).to.be.true;
expect(note.isStringed).to.be.true;
});
it('returns true when percussionArticulation is set without string', () => {
const note = new Note();
note.percussionArticulation = 38;
expect(note.isPercussion).to.be.true;
expect(note.isStringed).to.be.false;
});
it('returns false when percussionArticulation is not set', () => {
const note = new Note();
note.string = 1;
note.fret = 5;
expect(note.isPercussion).to.be.false;
expect(note.isStringed).to.be.true;
});
});
describe('Staff.finish', () => {
it('preserves showTablature and tuning for percussion with virtual tuning', () => {
const staff = new Staff();
staff.isPercussion = true;
staff.showTablature = true;
staff.stringTuning = new Tuning('', [0, 0, 0, 0, 0, 0], false);
staff.finish(new Settings());
expect(staff.showTablature).to.be.true;
expect(staff.tuning.length).to.equal(6);
expect(staff.displayTranspositionPitch).to.equal(0);
});
it('disables showTablature for percussion without tuning', () => {
const staff = new Staff();
staff.isPercussion = true;
staff.showTablature = true;
staff.stringTuning = new Tuning('', [], false);
staff.finish(new Settings());
expect(staff.showTablature).to.be.false;
expect(staff.tuning.length).to.equal(0);
});
it('resets displayTranspositionPitch for percussion', () => {
const staff = new Staff();
staff.isPercussion = true;
staff.displayTranspositionPitch = 12;
staff.stringTuning = new Tuning('', [0, 0, 0, 0, 0, 0], false);
staff.finish(new Settings());
expect(staff.displayTranspositionPitch).to.equal(0);
});
it('preserves showTablature for non-percussion with tuning', () => {
const staff = new Staff();
staff.isPercussion = false;
staff.showTablature = true;
staff.stringTuning = new Tuning('', [64, 59, 55, 50, 45, 40], false);
staff.finish(new Settings());
expect(staff.showTablature).to.be.true;
expect(staff.tuning.length).to.equal(6);
});
});
describe('TabBarRendererFactory.canCreate', () => {
function createStaff(isPercussion: boolean, showTablature: boolean, tuning: number[]): [Track, Staff] {
const track = new Track();
const staff = new Staff();
staff.isPercussion = isPercussion;
staff.showTablature = showTablature;
staff.stringTuning = new Tuning('', tuning, false);
staff.track = track;
track.staves.push(staff);
return [track, staff];
}
it('allows creation for percussion staff with virtual tuning and showTablature', () => {
const factory = new TabBarRendererFactory([]);
const [track, staff] = createStaff(true, true, [0, 0, 0, 0, 0, 0]);
expect(factory.canCreate(track, staff)).to.be.true;
});
it('rejects percussion staff when showTablature is false', () => {
const factory = new TabBarRendererFactory([]);
const [track, staff] = createStaff(true, false, [0, 0, 0, 0, 0, 0]);
expect(factory.canCreate(track, staff)).to.be.false;
});
it('rejects percussion staff without tuning', () => {
const factory = new TabBarRendererFactory([]);
const [track, staff] = createStaff(true, true, []);
expect(factory.canCreate(track, staff)).to.be.false;
});
it('allows creation for regular guitar staff', () => {
const factory = new TabBarRendererFactory([]);
const [track, staff] = createStaff(false, true, [64, 59, 55, 50, 45, 40]);
expect(factory.canCreate(track, staff)).to.be.true;
});
});
});