forked from 0xfe/vexflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeysignature.js
82 lines (70 loc) · 2.02 KB
/
keysignature.js
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
// Vex Flow Notation
// Implements key signatures
//
// Requires vex.js.
/**
* @constructor
*/
Vex.Flow.KeySignature = function(keySpec) {
if (arguments.length > 0) this.init(keySpec);
}
Vex.Flow.KeySignature.prototype = new Vex.Flow.StaveModifier();
Vex.Flow.KeySignature.prototype.constructor = Vex.Flow.KeySignature;
Vex.Flow.KeySignature.superclass = Vex.Flow.StaveModifier.prototype;
Vex.Flow.KeySignature.prototype.init = function(key_spec) {
Vex.Flow.KeySignature.superclass.init();
this.glyphFontScale = 38;
this.accList = Vex.Flow.keySignature(key_spec);
}
Vex.Flow.KeySignature.prototype.addAccToStave = function(stave, acc) {
var glyph = new Vex.Flow.Glyph(acc.glyphCode, this.glyphFontScale);
this.placeGlyphOnLine(glyph, stave, acc.line)
stave.addGlyph(glyph);
}
Vex.Flow.KeySignature.prototype.addModifier = function(stave) {
this.convertAccLines(stave.clef, this.accList[0].glyphCode);
for (var i = 0; i < this.accList.length; ++i) {
this.addAccToStave(stave, this.accList[i]);
}
}
Vex.Flow.KeySignature.prototype.addToStave = function(stave, firstGlyph) {
if (this.accList.length == 0)
return this;
if (!firstGlyph) {
stave.addGlyph(this.makeSpacer(this.padding));
}
this.addModifier(stave);
return this;
}
Vex.Flow.KeySignature.prototype.convertAccLines = function(clef, code) {
var offset = 0.0; // if clef === "treble"
var tenorSharps;
var isTenorSharps = ((clef === "tenor") && (code === "v18")) ? true : false;
switch (clef) {
case "bass":
offset = 1;
break;
case "alto":
offset = 0.5;
break;
case "tenor":
if (!isTenorSharps) {
offset = -0.5;
}
break;
}
// Special-case for TenorSharps
if (isTenorSharps) {
tenorSharps = [3, 1, 2.5, 0.5, 2, 0, 1.5];
for (var i = 0; i < this.accList.length; ++i) {
this.accList[i].line = tenorSharps[i];
}
}
else {
if (clef != "treble") {
for (var i = 0; i < this.accList.length; ++i) {
this.accList[i].line += offset;
}
}
}
}