forked from 0xfe/vexflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvibratobracket.js
72 lines (58 loc) · 2.21 KB
/
vibratobracket.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
// [VexFlow](http://vexflow.com) - Copyright (c) Mohit Muthanna 2010.
// Author: Balazs Forian-Szabo
//
// ## Description
//
// This file implements `VibratoBrackets`
// that renders vibrato effect between two notes.
import { Vex } from './vex';
import { Element } from './element';
import { Vibrato } from './vibrato';
// To enable logging for this class. Set `Vex.Flow.VibratoBracket.DEBUG` to `true`.
function L(...args) { if (VibratoBracket.DEBUG) Vex.L('Vex.Flow.VibratoBracket', args); }
export class VibratoBracket extends Element {
// bracket_data = {
// start: Vex.Flow.Note (optional)
// stop: Vex.Flow.Note (optional)
// };
// Either the stop or start note must be set, or both of them.
// A null value for the start or stop note indicates that the vibrato
// is drawn from the beginning or until the end of the stave accordingly.
constructor(bracket_data) {
super();
this.setAttribute('type', 'VibratoBracket');
this.start = bracket_data.start;
this.stop = bracket_data.stop;
this.line = 1;
this.render_options = {
harsh: false,
wave_height: 6,
wave_width: 4,
wave_girth: 2,
};
}
// Set line position of the vibrato bracket
setLine(line) { this.line = line; return this; }
setHarsh(harsh) { this.render_options.harsh = harsh; return this; }
// Draw the vibrato bracket on the rendering context
draw() {
const ctx = this.context;
this.setRendered();
const y = (this.start)
? this.start.getStave().getYForTopText(this.line)
: this.stop.getStave().getYForTopText(this.line);
// If start note is not set then vibrato will be drawn
// from the beginning of the stave
const start_x = (this.start)
? this.start.getAbsoluteX()
: this.stop.getStave().getTieStartX();
// If stop note is not set then vibrato will be drawn
// until the end of the stave
const stop_x = (this.stop)
? this.stop.getAbsoluteX() - this.stop.getWidth() - 5
: this.start.getStave().getTieEndX() - 10;
this.render_options.vibrato_width = stop_x - start_x;
L('Rendering VibratoBracket: start_x:', start_x, 'stop_x:', stop_x, 'y:', y);
Vibrato.renderVibrato(ctx, start_x, y, this.render_options);
}
}