forked from 0xfe/vexflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtickable.js
75 lines (62 loc) · 2.29 KB
/
tickable.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
// Vex Flow
// Copyright Mohit Cheppudira <[email protected]>
//
// The tickable interface. Tickables are things that sit on a score and
// have a duration, i.e., they occupy space in the musical rendering dimension.
/** @constructor */
Vex.Flow.Tickable = function() {
this.init();
}
Vex.Flow.Tickable.prototype.init = function() {
this.ticks = 0;
this.width = 0;
this.x_shift = 0; // Shift from tick context
this.voice = null;
this.tickContext = null;
this.modifierContext = null;
this.modifiers = [];
this.preFormatted = false;
// This flag tells the formatter to ignore this tickable during
// formatting and justification. It is set by tickables such as BarNote.
this.ignore_ticks = false;
}
/** optional, if tickable has modifiers **/
Vex.Flow.Tickable.prototype.addToModifierContext = function(mc) {
this.modifierContext = mc;
// Add modifiers to modifier context (if any)
this.preFormatted = false;
}
/** optional, if tickable has modifiers **/
Vex.Flow.Tickable.prototype.addModifier = function(mod) {
this.modifiers.push(mod);
this.preFormatted = false;
return this;
}
Vex.Flow.Tickable.prototype.setTickContext = function(tc) {
this.tickContext = tc;
this.preFormatted = false;
}
Vex.Flow.Tickable.prototype.preFormat = function() {
if (preFormatted) return;
this.width = 0;
if (this.modifierContext) {
this.modifierContext.preFormat();
this.width += this.modifierContext.getWidth();
}
// Calculate any extra width required.
}
// Formatters and preformatters use ticks and width to calculate the position
// of these tickables.
Vex.Flow.Tickable.prototype.getTicks = function() { return this.ticks; }
Vex.Flow.Tickable.prototype.shouldIgnoreTicks = function() {
return this.ignore_ticks; }
Vex.Flow.Tickable.prototype.getWidth = function() { return this.width; }
// Formatters will set the X value of the tickable.
Vex.Flow.Tickable.prototype.setXShift = function(x) { this.x_shift = x; }
// Every tickable must be associated with a voice. This allows formatters
// and preFormatter to associate them with the right modifierContexts.
Vex.Flow.Tickable.prototype.getVoice = function() {
if (!this.voice) throw new Vex.RERR("NoVoice", "Tickable has no voice.");
return this.voice;
}
Vex.Flow.Tickable.prototype.setVoice = function(voice) { this.voice= voice; }