Explorar o código

Merge remote-tracking branch 'origin/standalone' into develop

# Conflicts:
#	demo/demo.js
Matthias %!s(int64=8) %!d(string=hai) anos
pai
achega
6bc38542e1
Modificáronse 8 ficheiros con 68 adicións e 37 borrados
  1. 17 13
      Gruntfile.js
  2. 15 14
      demo/demo.js
  3. 1 1
      demo/index.html
  4. 0 7
      demo/inject.ts
  5. 1 1
      karma.conf.js
  6. 1 0
      package.json
  7. 32 1
      src/OSMD/OSMD.ts
  8. 1 0
      typings.json

+ 17 - 13
Gruntfile.js

@@ -31,25 +31,29 @@ module.exports = function (grunt) {
         // Browserify
         browserify: {
             dist: {
-                src: [].concat(typings, src),
+                src: ['src/OSMD/OSMD.ts'],
                 dest: '<%= outputDir.build %>/osmd.js',
                 options: {
-                    banner: "<%= banner %>"
+                    banner: "<%= banner %>",
+                    browserifyOptions: {
+                        standalone: 'opensheetmusicdisplay'
+                    }
                 }
             },
-            demo: {
-                src: [].concat(typings, src, ['demo/inject.ts']),
-                dest: '<%= outputDir.build %>/demo/osmd-demo.js',
+            debug: {
+                src: ['src/OSMD/OSMD.ts'],
+                dest: '<%= outputDir.build %>/osmd-debug.js',
                 options: {
                     banner: "<%= banner %>",
                     browserifyOptions: {
-                        debug: true
+                        debug: true,
+                        standalone: 'opensheetmusicdisplay'                        
                     }
                 }
             },
-            debug: {
+            test: {
                 src: [].concat(typings, src, test),
-                dest: '<%= outputDir.build %>/osmd-debug.js',
+                dest: '<%= outputDir.build %>/osmd-test.js',
                 options: {
                     banner: "<%= banner %>",
                     browserifyOptions: {
@@ -69,8 +73,7 @@ module.exports = function (grunt) {
                 },
                 banner: banner,
                 mangle: true,
-                mangleProperties: true,
-                preserveComments: 'all'
+                mangleProperties: true
             },
             bundle: {
                 files: {
@@ -158,7 +161,8 @@ module.exports = function (grunt) {
             demo: {
                 files: [
                     { src: ['*'], dest: '<%= outputDir.build %>/demo/sheets/', cwd: './test/data/', expand: true },
-                    { src: ['*.js', '*.css', '*.html'], cwd: './demo/', expand: true, dest: '<%= outputDir.build %>/demo/' }
+                    { src: ['*.js', '*.css', '*.html'], cwd: './demo/', expand: true, dest: '<%= outputDir.build %>/demo/' },
+                    { src: ['osmd-debug.js'], cwd: './build/', expand: true, dest: '<%= outputDir.build %>/demo/' }
                 ]
             }
         },
@@ -198,8 +202,8 @@ module.exports = function (grunt) {
     grunt.registerTask('docs',        'Builds class documentation to /build/docs',   ['typedoc']);
 
     // Build tasks
-    grunt.registerTask('build:demo',  'Builds the demo.',                            ['browserify:demo', 'copy:demo']);
-    grunt.registerTask('build:test',  'Builds the tests',                            ['browserify:debug']);
+    grunt.registerTask('build:demo',  'Builds the demo.',                            ['browserify:debug', 'copy:demo']);
+    grunt.registerTask('build:test',  'Builds the tests',                            ['browserify:test']);
     grunt.registerTask('build:dist',  'Builds for distribution on npm and Bower.',   ['browserify:dist', 'uglify', 'ts']);
 
     // Tests

+ 15 - 14
demo/demo.js

@@ -1,10 +1,9 @@
 /*jslint browser:true */
 (function () {
     "use strict";
-    // The MusicSheet object
-    var sheet,
+    var OSMD;
     // The folder of the demo files
-        folder = "sheets/",
+    var folder = "sheets/",
     // The available demos
         demos = {
             "M. Clementi - Sonatina Op.36 No.1 Pt.1": "MuzioClementi_SonatinaOpus36No1_Part1",
@@ -78,8 +77,9 @@
             scale();
         };
 
-        // Create sheet object and canvas
-        sheet = new window.OSMD(canvas);
+        // Create OSMD object and canvas
+        OSMD = new opensheetmusicdisplay.OSMD(canvas);
+        OSMD.setLogLevel('info');
         document.body.appendChild(canvas);
 
         // Set resize event handler
@@ -91,7 +91,7 @@
                 var width = document.body.clientWidth;
                 canvas.width = width;
                 try {
-                sheet.render();
+                OSMD.render();
                 } catch (e) {}
                 enable();
             }
@@ -100,21 +100,22 @@
         window.addEventListener("keydown", function(e) {
             var event = window.event ? window.event : e;
             if (event.keyCode === 39) {
-                sheet.cursor.next();
+                OSMD.cursor.next();
             }
         });
         nextCursorBtn.addEventListener("click", function() {
-            sheet.cursor.next();
+            OSMD.cursor.next();
         });
         hideCursorBtn.addEventListener("click", function() {
-            sheet.cursor.hide();
+            OSMD.cursor.hide();
         });
         showCursorBtn.addEventListener("click", function() {
-            sheet.cursor.show();
+            OSMD.cursor.show();
         });
     }
 
     function Resize(startCallback, endCallback) {
+
       var rtime;
       var timeout = false;
       var delta = 200;
@@ -149,9 +150,9 @@
             str = folder + select.value + ".xml";
         }
         zoom = 1.0;
-        sheet.load(str).then(
+        OSMD.load(str).then(
             function() {
-                return sheet.render();
+                return OSMD.render();
             },
             function(e) {
                 error("Error reading sheet: " + e);
@@ -183,8 +184,8 @@
     function scale() {
         disable();
         window.setTimeout(function(){
-            sheet.zoom = zoom;
-            sheet.render();
+            OSMD.zoom = zoom;
+            OSMD.render();
             enable();
         }, 0);
     }

+ 1 - 1
demo/index.html

@@ -8,7 +8,7 @@
     <meta name="author" content="OpenSheetMusicDisplay contributors">
 
     <!-- Include opensheetmusicdisplay -->
-    <script src="osmd-demo.js"></script>
+    <script src="osmd-debug.js"></script>
 
     <!-- Include code and styles for this demo -->
     <script src="demo.js"></script>

+ 0 - 7
demo/inject.ts

@@ -1,7 +0,0 @@
-import { OSMD } from "./../src/OSMD/OSMD";
-
-/* This file injects OSMD in the window object.
- * !!! HANDLE WITH CARE !!!
- */
-
-(window as any).OSMD = OSMD;

+ 1 - 1
karma.conf.js

@@ -15,7 +15,7 @@ module.exports = function (config) {
         exclude: [],
 
         files: [{
-            pattern: 'build/osmd-debug.js'
+            pattern: 'build/osmd-test.js'
         }, {
             pattern: 'src/**/*.ts',
             included: false

+ 1 - 0
package.json

@@ -41,6 +41,7 @@
   "dependencies": {
     "es6-promise": "^3.2.1",
     "jszip": "^3.0.0",
+    "loglevel": "^1.4.1",
     "shortid": "^2.2.6",
     "typescript-collections": "^1.1.2",
     "vexflow": "^1.2.53"

+ 32 - 1
src/OSMD/OSMD.ts

@@ -12,6 +12,7 @@ import {AJAX} from "./AJAX";
 import {Logging} from "../Common/Logging";
 import {Fraction} from "../Common/DataObjects/Fraction";
 import {OutlineAndFillStyleEnum} from "../MusicalScore/Graphical/DrawingEnums";
+import * as log from "loglevel";
 
 export class OSMD {
     /**
@@ -83,7 +84,7 @@ export class OSMD {
                 let parser: DOMParser = new DOMParser();
                 content = parser.parseFromString(str, "text/xml");
             } else if (str.length < 2083) {
-                // Assume now 'str' is a URL
+                // Assume now "str" is a URL
                 // Retrieve the file at the given URL
                 return AJAX.ajax(str).then(
                     (s: string) => { return self.load(s); },
@@ -113,6 +114,7 @@ export class OSMD {
         this.sheet = reader.createMusicSheet(score, "Unknown path");
         this.graphic = new GraphicalMusicSheet(this.sheet, calc);
         this.cursor.init(this.sheet.MusicPartManager, this.graphic);
+        log.info(`Loaded sheet ${this.sheet.TitleString} successfully.`);
         return Promise.resolve({});
     }
 
@@ -154,6 +156,35 @@ export class OSMD {
     }
 
     /**
+     * Sets the logging level for this OSMD instance. By default, this is set to `warn`.
+     *
+     * @param: content can be `trace`, `debug`, `info`, `warn` or `error`.
+     */
+    public setLogLevel(level: string): void {
+        switch (level) {
+            case "trace":
+                log.setDefaultLevel(LogLevel.TRACE);
+                break;
+            case "debug":
+                log.setDefaultLevel(LogLevel.DEBUG);
+                break;
+            case "info":
+                log.setDefaultLevel(LogLevel.INFO);
+                break;
+            case "warn":
+                log.setDefaultLevel(LogLevel.WARN);
+                break;
+            case "error":
+                log.setDefaultLevel(LogLevel.ERROR);
+                break;
+            default:
+                log.warn(`Could not set log level to ${level}. Using warn instead.`);
+                log.setDefaultLevel(LogLevel.WARN);
+                break;
+        }
+    }
+
+    /**
      * Initialize this object to default values
      * FIXME: Probably unnecessary
      */

+ 1 - 0
typings.json

@@ -1,6 +1,7 @@
 {
   "globalDependencies": {
     "chai": "registry:dt/chai#3.4.0+20160317120654",
+    "loglevel": "registry:dt/loglevel#1.4.0+20160412141402",
     "mocha": "registry:dt/mocha#2.2.5+20160317120654",
     "shortid": "registry:dt/shortid#0.0.0+20160316155526"
   },