From 6fabd14df1e8349d3611e2e21551bde140030231 Mon Sep 17 00:00:00 2001 From: aerhard Date: Sat, 5 Jul 2014 07:31:10 +0200 Subject: [PATCH 1/6] fixed typo;removed test dirs from bower-ignore --- bower.json | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/bower.json b/bower.json index 0ee183e..db726e3 100644 --- a/bower.json +++ b/bower.json @@ -3,7 +3,7 @@ "version": "0.1.0", "homepage": "http://tei-music-sig.github.io/MEItoVexFlow/", "authors": [ - "irochicken raffazizzi zolaemil aerhard" + "ironchicken raffazizzi zolaemil aerhard" ], "description": "MEI to VexFlow bridge library", "main": "meitovexflow.js", @@ -17,9 +17,7 @@ "ignore": [ "**/.*", "node_modules", - "bower_components", - "test", - "tests" + "bower_components" ], "dependencies": { "jquery": "~2.1.0", From 6009801bf070ec0fdd716a5924afdeaee96a3f9c Mon Sep 17 00:00:00 2001 From: aerhard Date: Sat, 5 Jul 2014 07:39:05 +0200 Subject: [PATCH 2/6] updated readme.md --- README.md | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 327f692..e7a03d6 100644 --- a/README.md +++ b/README.md @@ -21,19 +21,23 @@ $ bower install ## Usage -The library provides the function `render_notation` which takes four +The library provides the function `render_notation` which takes up to six arguments: - - `score` should be a markup fragment containing the MEI + - `xmlDoc` (XMLDocument) should be a markup fragment containing the MEI - - `target` should be an HTML element onto which the notation + - `target` (Element) should be an HTML element onto which the notation will be drawn - - `width` should be the width of the canvas (optional) + - `width` (Number) should be the width of the canvas in pixels. Defaults to 800 (optional) - - `height` should be the height of the canvas (optional) + - `height` (Number) should be the height of the canvas in pixels. Defaults to 350 (optional) -For sample function calls see the test cases in the 'tests' directory! + - `backend` (Vex.Flow.Renderer.Backends.CANVAS|Vex.Flow.Renderer.Backends.RAPHAEL) specifies the VexFlow backend to use. Defaults to Vex.Flow.Renderer.Backends.RAPHAEL (optional) + + - `options` (Object) may contain additional conversion and rendering parameters; see the comments on the default parameters in `src/Converter.js` for details (optional) + +For sample function calls see the test runs in the 'tests' directory! ## MeiLib.js @@ -61,7 +65,7 @@ comments within the source file meilib.js Only a small subset of MEI has so far been implemented. Many conventional aspects of common practice notation have been ignored -(such as repeat accidentals, stem directions). It's also important to +(such as repeat accidentals). It's also important to remember that VexFlow is a moving target, it's in constant development and so this code could break at any time. From e3b4ab8d8366dd8cbc79e1866c700b1475a6664e Mon Sep 17 00:00:00 2001 From: aerhard Date: Sat, 5 Jul 2014 07:56:46 +0200 Subject: [PATCH 3/6] fixe readme.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e7a03d6..fd5428f 100644 --- a/README.md +++ b/README.md @@ -33,9 +33,9 @@ arguments: - `height` (Number) should be the height of the canvas in pixels. Defaults to 350 (optional) - - `backend` (Vex.Flow.Renderer.Backends.CANVAS|Vex.Flow.Renderer.Backends.RAPHAEL) specifies the VexFlow backend to use. Defaults to Vex.Flow.Renderer.Backends.RAPHAEL (optional) + - `backend` (Vex.Flow.Renderer.Backends.CANVAS|Vex.Flow.Renderer.Backends.RAPHAEL) specifies the VexFlow backend to use. Defaults to Vex.Flow.Renderer.Backends.CANVAS (optional) - - `options` (Object) may contain additional conversion and rendering parameters; see the comments on the default parameters in `src/Converter.js` for details (optional) + - `options` (Object) may contain additional conversion and rendering options; see the comments on the default options in `src/Converter.js` for details (optional) For sample function calls see the test runs in the 'tests' directory! From c4a074dcf172dfdce596e25b3a0738ed762102d0 Mon Sep 17 00:00:00 2001 From: aerhard Date: Sat, 5 Jul 2014 07:57:19 +0200 Subject: [PATCH 4/6] restructured Interface.js --- src/Interface.js | 74 +++++++++++++++++++++++------------------------- 1 file changed, 36 insertions(+), 38 deletions(-) diff --git a/src/Interface.js b/src/Interface.js index 3d2f9d8..db4fce6 100644 --- a/src/Interface.js +++ b/src/Interface.js @@ -21,47 +21,45 @@ var MEI2VF = ( function(m2v, MeiLib, VF, $, undefined) { getStaffArea : function() { return m2v.Converter.prototype.getStaffArea(); } - } - }; - }(MEI2VF || {}, MeiLib, Vex.Flow, jQuery)); - -/** - * @property - */ -MEI2VF.rendered_measures = null; - -/** - * Basic rendering function. Uses the m2v.Converter's prototype as a - * singleton. No scaling; page layout information in the MEI code is ignored. - * @param {XMLDocument} xmlDoc The MEI XML Document - * @param {XMLElement} target An svg or canvas element - * @param {Number} width The width of the print space in pixels - * @param {Number} height The height of the print space in pixels - * @param {Number} backend Set to Vex.Flow.Renderer.Backends.RAPHAEL to - * render to a Raphael context; if falsy, Vex.Flow.Renderer.Backends.CANVAS - * is set - * @param {Object} options The options passed to the converter. For a list, see - * {@link MEI2VF.Converter MEI2VF.Converter} - */ -MEI2VF.render_notation = function(xmlDoc, target, width, height, backend, options) { - var ctx; - var cfg = options || {}; + }, + /** + * @property + */ + rendered_measures: null, + /** + * Main rendering function. Uses the Converter's prototype as a + * singleton. No scaling; page layout information in the MEI code is ignored. + * @param {XMLDocument} xmlDoc The MEI XML Document + * @param {XMLElement} target An svg or canvas element + * @param {Number} width The width of the print space in pixels + * @param {Number} height The height of the print space in pixels + * @param {Number} backend Set to Vex.Flow.Renderer.Backends.RAPHAEL to + * render to a Raphael context; if falsy, Vex.Flow.Renderer.Backends.CANVAS + * is set + * @param {Object} options The options passed to the converter. For a list, see + * {@link MEI2VF.Converter MEI2VF.Converter} + */ + render_notation: function (xmlDoc, target, width, height, backend, options) { + var ctx; + var cfg = options || {}; - ctx = new Vex.Flow.Renderer(target, backend || Vex.Flow.Renderer.Backends.CANVAS).getContext(); + ctx = new VF.Renderer(target, backend || VF.Renderer.Backends.CANVAS).getContext(); - width = width || 800; - height = height || 350; + width = width || 800; + height = height || 350; - if (+backend === Vex.Flow.Renderer.Backends.RAPHAEL) { - ctx.paper.setSize(width, height); - } - - cfg.page_width = width; + if (+backend === VF.Renderer.Backends.RAPHAEL) { + ctx.paper.setSize(width, height); + } - this.Converter.initConfig(cfg); - this.Converter.process(xmlDoc[0] || xmlDoc); - this.Converter.draw(ctx); - this.rendered_measures = this.Converter.getAllVexMeasureStaffs(); + cfg.page_width = width; -}; + this.Converter.initConfig(cfg); + this.Converter.process(xmlDoc[0] || xmlDoc); + this.Converter.draw(ctx); + this.rendered_measures = this.Converter.getAllVexMeasureStaffs(); + } + }; + + }(MEI2VF || {}, MeiLib, Vex.Flow, jQuery)); From eac4b205a595577482ae47bf1e357ca64a7e6d32 Mon Sep 17 00:00:00 2001 From: aerhard Date: Sat, 5 Jul 2014 07:57:19 +0200 Subject: [PATCH 5/6] added documentation; removed return statements in Interface.js --- README.md | 2 +- src/Interface.js | 76 ++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 61 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index fd5428f..dbeed09 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ arguments: - `xmlDoc` (XMLDocument) should be a markup fragment containing the MEI - - `target` (Element) should be an HTML element onto which the notation + - `target` (Element) should be an HTML or element onto which the notation will be drawn - `width` (Number) should be the width of the canvas in pixels. Defaults to 800 (optional) diff --git a/src/Interface.js b/src/Interface.js index db4fce6..ebc4dd8 100644 --- a/src/Interface.js +++ b/src/Interface.js @@ -2,42 +2,86 @@ * @class MEI2VF * @singleton */ -var MEI2VF = ( function(m2v, MeiLib, VF, $, undefined) { +var MEI2VF = (function(m2v, MeiLib, VF, $, undefined) { return { + /** + * enables or disables MEI2VF logging + * @method setLogging + * @param {Boolean} value True if logging should be enabled, false if not. Defaults to false. + */ setLogging : m2v.setLogging, + /** + * The methods in Converter can be used to manually address distinct + * processing steps and retrieve the created data. Can be used in + * addition or as a supplement to {@link render_notation} and + * {@link rendered_measures} + */ Converter : { - initConfig : function(c) { - return m2v.Converter.prototype.initConfig(c); + /** + * initializes the converter + * @method initConfig + * @param {Object} config The options passed to the converter. For a list, see + * {@link MEI2VF.Converter#defaults} + */ + initConfig : function(config) { + m2v.Converter.prototype.initConfig(config); }, - process : function(c) { - return m2v.Converter.prototype.process(c); + /** + * Processes the specified MEI document or document fragment. The generated + * objects can be processed further or drawn immediately to a canvas via + * {@link #draw}. + * @method process + * @param {XMLDocument} xmlDoc the XML document + */ + process : function(xmlDoc) { + m2v.Converter.prototype.process(xmlDoc); }, - draw : function(c) { - return m2v.Converter.prototype.draw(c); + /** + * Draws the processed data to a canvas + * @method draw + * @param ctx The canvas context + */ + draw : function(ctx) { + m2v.Converter.prototype.draw(ctx); }, + /** + * returns a 2d array of all Vex.Flow.Stave objects, arranged by + * [measure_n][staff_n] + * @method getAllVexMeasureStaffs + * @return {Vex.Flow.Stave[][]} see {@link MEI2VF.Converter#allVexMeasureStaffs} + */ getAllVexMeasureStaffs : function() { return m2v.Converter.prototype.getAllVexMeasureStaffs(); }, + /** + * Returns the width and the height of the area that contains all drawn + * staves as per the last processing. + * + * @method getStaffArea + * @return {Object} the width and height of the area that contains all staves. + * Properties: width, height + */ getStaffArea : function() { return m2v.Converter.prototype.getStaffArea(); } }, /** - * @property + * Contains all Vex.Flow.Stave objects created when calling {@link #render_notation}. + * Addressing scheme: [measure_n][staff_n] + * @property {Vex.Flow.Stave[][]} rendered_measures */ rendered_measures: null, /** - * Main rendering function. Uses the Converter's prototype as a - * singleton. No scaling; page layout information in the MEI code is ignored. + * Main rendering function. * @param {XMLDocument} xmlDoc The MEI XML Document - * @param {XMLElement} target An svg or canvas element - * @param {Number} width The width of the print space in pixels - * @param {Number} height The height of the print space in pixels + * @param {Element} target An svg or canvas element + * @param {Number} width The width of the print space in pixels. Defaults to 800 (optional) + * @param {Number} height The height of the print space in pixels. Defaults to 350 (optional) * @param {Number} backend Set to Vex.Flow.Renderer.Backends.RAPHAEL to * render to a Raphael context; if falsy, Vex.Flow.Renderer.Backends.CANVAS - * is set + * is set (optional) * @param {Object} options The options passed to the converter. For a list, see - * {@link MEI2VF.Converter MEI2VF.Converter} + * {@link MEI2VF.Converter#defaults} (optional) */ render_notation: function (xmlDoc, target, width, height, backend, options) { var ctx; @@ -61,5 +105,5 @@ var MEI2VF = ( function(m2v, MeiLib, VF, $, undefined) { } }; - + }(MEI2VF || {}, MeiLib, Vex.Flow, jQuery)); From 02cab2318238a8e6732e55ffe36be716e558be29 Mon Sep 17 00:00:00 2001 From: aerhard Date: Sat, 5 Jul 2014 07:57:19 +0200 Subject: [PATCH 6/6] renamed $children, updated Interface.js --- src/Converter.js | 18 +++++++++--------- src/Interface.js | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Converter.js b/src/Converter.js index 296420b..a1f0439 100644 --- a/src/Converter.js +++ b/src/Converter.js @@ -1046,9 +1046,9 @@ var MEI2VF = ( function(m2v, MeiLib, VF, $, undefined) { * @method processChord */ processChord : function(element, staff, staff_n) { - var me = this, i, j, hasDots, $children, keys = [], duration, durations = [], durAtt, xml_id, chord, chord_opts, atts; + var me = this, i, j, hasDots, children, keys = [], duration, durations = [], durAtt, xml_id, chord, chord_opts, atts; - $children = $(element).children(); + children = $(element).children(); atts = m2v.Util.attsToObj(element); durAtt = atts.dur; @@ -1061,16 +1061,16 @@ var MEI2VF = ( function(m2v, MeiLib, VF, $, undefined) { if (durAtt) { duration = me.translateDuration(+durAtt); } else { - for ( i = 0, j = $children.length; i < j; i += 1) { - durations.push(+$children[i].getAttribute('dur')); + for ( i = 0, j = children.length; i < j; i += 1) { + durations.push(+children[i].getAttribute('dur')); } duration = me.translateDuration(Math.max.apply(Math, durations)); } - for ( i = 0, j = $children.length; i < j; i += 1) { - keys.push(me.processAttsPitch($children[i])); - // dots.push(+$children[i].getAttribute('dots')); - if ($children[i].getAttribute('dots') === '1') + for ( i = 0, j = children.length; i < j; i += 1) { + keys.push(me.processAttsPitch(children[i])); + // dots.push(+children[i].getAttribute('dots')); + if (children[i].getAttribute('dots') === '1') hasDots = true; } @@ -1089,7 +1089,7 @@ var MEI2VF = ( function(m2v, MeiLib, VF, $, undefined) { var allNoteIndices = []; - $children.each(function(i) { + children.each(function(i) { me.processNoteInChord(i, this, element, chord); allNoteIndices.push(i); }); diff --git a/src/Interface.js b/src/Interface.js index ebc4dd8..ffac98a 100644 --- a/src/Interface.js +++ b/src/Interface.js @@ -72,7 +72,7 @@ var MEI2VF = (function(m2v, MeiLib, VF, $, undefined) { */ rendered_measures: null, /** - * Main rendering function. + * Main rendering function. * @param {XMLDocument} xmlDoc The MEI XML Document * @param {Element} target An svg or canvas element * @param {Number} width The width of the print space in pixels. Defaults to 800 (optional)