UNPKG

satie

Version:

A sheet music renderer for the web

100 lines (99 loc) 4.26 kB
/** * This file is part of Satie music engraver <https://github.com/jnetterf/satie>. * Copyright (C) Joshua Netterfield <joshua.ca> 2015 - present. * * Satie is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * Satie is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with Satie. If not, see <http://www.gnu.org/licenses/>. */ "use strict"; var __extends = (this && this.__extends) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; var musicxml_interfaces_1 = require("musicxml-interfaces"); var react_1 = require("react"); var lodash_1 = require("lodash"); var private_views_dot_1 = require("./private_views_dot"); var private_views_glyph_1 = require("./private_views_glyph"); var private_smufl_1 = require("./private_smufl"); var implAttributes_accidentalView_1 = require("./implAttributes_accidentalView"); var implChord_noteheadView_1 = require("./implChord_noteheadView"); var $AccidentalView = react_1.createFactory(implAttributes_accidentalView_1.default); var $Dot = react_1.createFactory(private_views_dot_1.default); var $NoteheadView = react_1.createFactory(implChord_noteheadView_1.default); var $Glyph = react_1.createFactory(private_views_glyph_1.default); var NoteView = (function (_super) { __extends(NoteView, _super); function NoteView() { return _super !== null && _super.apply(this, arguments) || this; } NoteView.prototype.render = function () { var _this = this; var spec = this.props.spec; if (spec.printObject === false) { return null; } var defaultX = this.props.defaultX || spec.defaultX; var noteheadGlyph = this.props.noteheadGlyph; var right = private_smufl_1.getRight(noteheadGlyph); var left = private_smufl_1.getLeft(noteheadGlyph); var hasParens = spec.notehead && spec.notehead.parentheses; return react_1.DOM.g(null, $NoteheadView({ key: "h", notehead: noteheadGlyph, spec: { color: spec.color, defaultX: defaultX, defaultY: 0, type: spec.notehead ? spec.notehead.type : musicxml_interfaces_1.NoteheadType.Normal } }), spec.dots && spec.printDot !== false ? lodash_1.map(spec.dots, function (dot, idx) { return $Dot({ fill: dot.color, key: "_1_" + idx, radius: 2.4, x: defaultX + right + 6 + 6 * idx, y: _this.context.originY - _this.props.spec.defaultY - (dot.defaultY + (dot.relativeY || 0)) }); }) : null, this.props.spec.accidental ? $AccidentalView({ key: "a", spec: this.props.spec.accidental, noteDefaultX: defaultX, }) : null, hasParens && $Glyph({ glyphName: "noteheadParenthesisRight", fill: "black", y: this.context.originY - this.props.spec.defaultY, x: defaultX + right + 2 }), hasParens && $Glyph({ glyphName: "noteheadParenthesisLeft", fill: "black", y: this.context.originY - this.props.spec.defaultY, x: defaultX + left - 5 })); }; NoteView.prototype.getChildContext = function () { return { originY: this.context.originY - this.props.spec.defaultY }; }; return NoteView; }(react_1.Component)); NoteView.childContextTypes = { originY: react_1.PropTypes.number.isRequired }; NoteView.contextTypes = { originY: react_1.PropTypes.number.isRequired }; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = NoteView; ;