{"size": 1710, "ext": "js", "max_stars_repo_path": "modules/LSViewer/src/LSNoteView.js", "max_stars_repo_name": "MSD200X/SonyCSL-Paris-LeadsheetJS", "max_stars_repo_stars_event_min_datetime": "2015-12-07T09:12:15.000Z", "max_stars_repo_stars_event_max_datetime": "2016-05-17T08:32:34.000Z", "max_issues_repo_path": "modules/LSViewer/src/LSNoteView.js", "max_issues_repo_name": "MSD200X/SonyCSL-Paris-LeadsheetJS", "max_issues_repo_issues_event_min_datetime": "2016-05-04T13:16:30.000Z", "max_issues_repo_issues_event_max_datetime": "2016-05-17T12:32:16.000Z", "max_forks_repo_path": "modules/LSViewer/src/LSNoteView.js", "max_forks_repo_name": "MSD200X/SonyCSL-Paris-LeadsheetJS", "max_forks_repo_forks_event_min_datetime": "2016-04-20T08:39:23.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-29T10:09:39.000Z"}
{"max_stars_count": 8, "max_issues_count": 2, "max_forks_count": 2, "avg_line_length": 26.71875, "max_line_length": 111, "alphanum_fraction": 0.6578947368}

define(['vexflow', 'modules/converters/MusicCSLJson/src/NoteModel_CSLJson'], function(Vex, NoteModel_CSLJson) {
	/**
    * LSNoteView is a module called by LSViewer to draw notes
    * @exports LSViewer/LSNoteView
    */
	function LSNoteView(note) {
		this.vexflowNote = createVexflowNote(note);
		this.note = note;


		/**
		 * @param  {NoteModel} note
		 * @return {Vex.Flow.StaveNote}
		 */
		function createVexflowNote(note) {

			var cslNote = NoteModel_CSLJson.exportToMusicCSLJSON(note);
			if (note.isRest){
				cslNote.keys[0] = "B/4";
			}
			var vexflowNote = new Vex.Flow.StaveNote(cslNote);
			if (parseInt(vexflowNote.keyProps[0].octave, null) >= 5) {
				vexflowNote.setStemDirection(-1);
			}
			var accidental = [];
			var i;
			for (i = 0; i < note.getNumPitches(); i++) {
				accidental.push(note.getAccidental(i));
			}
			//accidental can either be a string (for monophony) or an array (for polyphony)
			for (var acc in accidental) {
				if (accidental[acc] != null && accidental[acc].length !== 0)
					vexflowNote.addAccidental(acc, new Vex.Flow.Accidental(accidental[acc]));
			}
			var dot = note.getDot();

			if (dot) {
				for (i = 0; i < dot; i++) vexflowNote.addDot(0);
			}
			//if (note.isRest)
			return vexflowNote;
		}

	}
	LSNoteView.prototype.getVexflowNote = function() {
		return this.vexflowNote;
	};

	LSNoteView.prototype.getArea = function() {
		var boundingBox = this.vexflowNote.getBoundingBox();
			
		return {
			x: boundingBox.x,
			y: this.vexflowNote.stave.y,
			w: boundingBox.w,
			h: boundingBox.h
		};
	};
	LSNoteView.prototype.isBeamable = function() {
		return (/^\d+$/).test(this.vexflowNote.duration) && !this.note.isRest;
	};
	return LSNoteView;
});