|
|
|
|
|
|
|
|
var RelativeElement = function RelativeElement(c, dx, w, pitch, opt) { |
|
|
opt = opt || {}; |
|
|
this.x = 0; |
|
|
this.c = c; |
|
|
this.dx = dx; |
|
|
this.w = w; |
|
|
this.pitch = pitch; |
|
|
this.scalex = opt.scalex || 1; |
|
|
this.scaley = opt.scaley || 1; |
|
|
this.type = opt.type || "symbol"; |
|
|
this.pitch2 = opt.pitch2; |
|
|
this.linewidth = opt.linewidth; |
|
|
this.klass = opt.klass; |
|
|
this.anchor = opt.anchor ? opt.anchor : 'middle' |
|
|
this.top = pitch; |
|
|
if (this.pitch2 !== undefined && this.pitch2 > this.top) this.top = this.pitch2; |
|
|
this.bottom = pitch; |
|
|
if (this.pitch2 !== undefined && this.pitch2 < this.bottom) this.bottom = this.pitch2; |
|
|
if (opt.thickness) { |
|
|
this.top += opt.thickness / 2; |
|
|
this.bottom -= opt.thickness / 2; |
|
|
} |
|
|
if (opt.stemHeight) { |
|
|
if (opt.stemHeight > 0) |
|
|
this.top += opt.stemHeight; |
|
|
else |
|
|
this.bottom += opt.stemHeight; |
|
|
} |
|
|
if (opt.dim) |
|
|
this.dim = opt.dim; |
|
|
if (opt.position) |
|
|
this.position = opt.position; |
|
|
this.height = opt.height ? opt.height : 4; |
|
|
if (opt.top) |
|
|
this.top = opt.top; |
|
|
if (opt.bottom) |
|
|
this.bottom = opt.bottom; |
|
|
if (opt.name) |
|
|
this.name = opt.name; |
|
|
else if (this.c) |
|
|
this.name = this.c; |
|
|
else |
|
|
this.name = this.type; |
|
|
if (opt.realWidth) |
|
|
this.realWidth = opt.realWidth; |
|
|
else |
|
|
this.realWidth = this.w; |
|
|
this.centerVertically = false; |
|
|
switch (this.type) { |
|
|
case "debug": |
|
|
this.chordHeightAbove = this.height; |
|
|
break; |
|
|
case "lyric": |
|
|
if (opt.position && opt.position === 'below') |
|
|
this.lyricHeightBelow = this.height; |
|
|
else |
|
|
this.lyricHeightAbove = this.height; |
|
|
break; |
|
|
case "chord": |
|
|
if (opt.position && opt.position === 'below') |
|
|
this.chordHeightBelow = this.height; |
|
|
else |
|
|
this.chordHeightAbove = this.height; |
|
|
break; |
|
|
case "text": |
|
|
if (this.pitch === undefined) { |
|
|
if (opt.position && opt.position === 'below') |
|
|
this.chordHeightBelow = this.height; |
|
|
else |
|
|
this.chordHeightAbove = this.height; |
|
|
} else |
|
|
this.centerVertically = true; |
|
|
break; |
|
|
case "part": this.partHeightAbove = this.height; break; |
|
|
} |
|
|
}; |
|
|
|
|
|
RelativeElement.prototype.getChordDim = function () { |
|
|
if (this.type === "debug") |
|
|
return null; |
|
|
if (!this.chordHeightAbove && !this.chordHeightBelow) |
|
|
return null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var margin = 0; |
|
|
|
|
|
var offset = this.type === "chord" ? this.realWidth / 2 : 0; |
|
|
var left = this.x - offset - margin; |
|
|
var right = left + this.realWidth + margin; |
|
|
return { left: left, right: right }; |
|
|
}; |
|
|
|
|
|
RelativeElement.prototype.invertLane = function (total) { |
|
|
if (this.lane === undefined) |
|
|
this.lane = 0; |
|
|
this.lane = total - this.lane - 1; |
|
|
}; |
|
|
|
|
|
RelativeElement.prototype.putChordInLane = function (i) { |
|
|
this.lane = i; |
|
|
|
|
|
if (this.chordHeightAbove) |
|
|
this.chordHeightAbove = (this.height * 1.25) * this.lane; |
|
|
else |
|
|
this.chordHeightBelow = (this.height * 1.25) * this.lane; |
|
|
}; |
|
|
|
|
|
RelativeElement.prototype.getLane = function () { |
|
|
if (this.lane === undefined) |
|
|
return 0; |
|
|
return this.lane; |
|
|
}; |
|
|
|
|
|
RelativeElement.prototype.setX = function (x) { |
|
|
this.x = x + this.dx; |
|
|
}; |
|
|
|
|
|
module.exports = RelativeElement; |
|
|
|