]> git.parisson.com Git - telemeta.git/commitdiff
added markers functionality, marker edit panels and synchronization with the rule...
authorriccardo <riccardo@parisson.com>
Fri, 28 Jan 2011 17:39:39 +0000 (18:39 +0100)
committerriccardo <riccardo@parisson.com>
Fri, 28 Jan 2011 17:39:39 +0000 (18:39 +0100)
telemeta/htdocs/timeside/src/controller.js
telemeta/htdocs/timeside/src/marker.js
telemeta/htdocs/timeside/src/markermap.js
telemeta/htdocs/timeside/src/player.js
telemeta/templates/telemeta_default/mediaitem_detail.html

index ba0870be22f94bf675dbb41083bd6ae94bedc06b..7de3a121ddb7f91b8a58084311c31d6a5d29afb0 100644 (file)
@@ -7,23 +7,25 @@
 
 TimeSide(function($N) {
 
-$N.Class.create("Controller", $N.Core, {
-
-    initialize: function($super, cfg) {
-        $super();
-        this.configure(cfg, {
-            player: null,
-            soundProvider: null,
-            map: null
-        });
-        if (this.cfg.player && !$N.isInstanceOf(this.cfg.player, 'Player')) {
-            this.cfg.player = new $N.Player(this.cfg.player);
-        }
-        this._setupPlayer();
-    },
+    $N.Class.create("Controller", $N.Core, {
+
+        initialize: function($super, cfg) {
+            $super();
+            this.configure(cfg, {
+                player: null,
+                soundProvider: null,
+                map: null,
+                markersDiv: document.getElementById("markers_div_id")
+            });
+            if (this.cfg.player && !$N.isInstanceOf(this.cfg.player, 'Player')) {
+                this.cfg.player = new $N.Player(this.cfg.player);
+            }
+            this._setupPlayer();
+        },
 
-    _setupPlayer: function() {
-        this.cfg.player
+        _setupPlayer: function() {
+            this.attach(this.updateMarkersDiv);
+            this.cfg.player
             .setSoundProvider(this.cfg.soundProvider)
             .setMarkerMap(this.cfg.map)
             .observe('play', $N.attachFunction(this.cfg.soundProvider, this.cfg.soundProvider.play))
@@ -31,27 +33,116 @@ $N.Class.create("Controller", $N.Core, {
             .observe('move', this.attach(this._onMove))
             .observe('markeradd', this.attach(this._onMarkerAdd))
             .observe('markermove', this.attach(this._onMarkerMove))
+            .observe('markeradd2',this.attach(this._onMarkerAdd2))
             .draw();
-    },
+            
+        },
 
-    _onMove: function(e, data) {
-        this.cfg.soundProvider.seek(data.offset);
-    },
+        _onMarkerAdd2: function(e,data){
+            if (this.cfg.map) {
+                alert(this.cfg.map._toString());
+            }
+        },
 
-    _onMarkerMove: function(e, data) {
-        if (this.cfg.map) {
-            this.cfg.map.move(this.cfg.map.byId(data.id), data.offset);
-        }
-    },
+        _onMove: function(e, data) {
+            this.cfg.soundProvider.seek(data.offset);
+        },
+
+
+        updateMarkersDiv: function(nonNullMarkersMap, selectedMarkOffset){
+            var div = this.cfg.markersDiv;
+            var m = nonNullMarkersMap.markers;
+            var l = m.length;
+            if(div){
+                var d = new Date();
+                var textWithFocus;
+                div.style.display = "block";
+                var doc = document;
+                var divChildren = div.childNodes;
+                var round = Math.round;
+                for(var i=0; i<l; i++){
+                    var marker = m[i];
+                    var subdiv, text;
+                    if(divChildren.length<=i){
+                        //create new div
+                        subdiv = doc.createElement('div');
+                        var header = doc.createElement('div');
+                        //creating marker, see marker.js
+                        //would be better not to copy this code but to
+                        //reference it.
+                        var label = doc.createElement('span');
+                        label.style.cssText = "color:#fff;background-color:#009;width: '2ex';textAlign: 'center';font-family: 'monospace'";
+                        //label.setAttribute("class", $N.cssPrefix + this.cfg.className);
+                        label.innerHTML = (i+1);
+                        header.appendChild(label);
+                        var timeSpan = doc.createElement('span');
+                        timeSpan.style.cssText="margin-left:1ex";
+                        header.appendChild(timeSpan);
+                        subdiv.appendChild(header);
 
-    _onMarkerAdd: function(e, data) {
-        if (this.cfg.map) {
-            this.cfg.map.add(data.offset, 'marker at ' + data.offset);
+                        text = doc.createElement('textarea');
+                        text.style.cssText="margin:0;padding:0;width:100%";
+
+                        var ok = doc.createElement('a');
+                        ok.setAttribute("href","#");
+                        ok.innerHTML = "OK";
+                        subdiv.appendChild(text);
+                        subdiv.appendChild(ok);
+                        subdiv.style.cssText="margin-bottom:1em;margin-top:1ex";
+                        div.appendChild(subdiv);
+                    }else{
+                        subdiv = divChildren[i];
+                        text = subdiv.childNodes[1];
+                        header = subdiv.childNodes[0];
+                    }
+                    var timeStr = this.formatMarkerOffset(marker.offset);
+                    
+                    header.childNodes[1].innerHTML = timeStr;
+                    //updating text
+                    text.innerHTML = marker.desc;
+                    if(selectedMarkOffset==marker.offset){
+                        textWithFocus = text;
+                    }
+                }
+                if(textWithFocus){
+                    textWithFocus.focus();
+                }
+            }
+        },
+
+        formatMarkerOffset: function(markerOffset){
+            //marker offset is in float format second.decimalPart
+            var hours = parseInt(markerOffset/(60*24));
+            markerOffset-=hours*(60*24);
+            var minutes = parseInt(markerOffset/(60));
+            markerOffset-=minutes*(60);
+            var seconds = parseInt(markerOffset);
+            markerOffset-=seconds;
+            var msec = Math.round(markerOffset*100); //show only centiseconds
+            //(use 1000* to show milliseconds)
+            var format = (hours<10 ? "0"+hours : hours )+":"+
+            (minutes<10 ? "0"+minutes : minutes )+":"+
+            (seconds<10 ? "0"+seconds : seconds )+"."+
+            msec;
+            return format;
+        },
+        _onMarkerMove: function(e, data) {
+            if (this.cfg.map) {
+                this.cfg.map.move(this.cfg.map.byId(data.id), data.offset);
+                this.updateMarkersDiv(this.cfg.map, data.offset);
+            }
+        },
+
+        _onMarkerAdd: function(e, data) {
+            if (this.cfg.map) {
+                //this.cfg.map.add(data.offset, 'marker at ' + data.offset);
+                this.cfg.map.add(data.offset, '');
+                this.updateMarkersDiv(this.cfg.map, data.offset);
+            }
         }
-    }
 
-});
+    });
 
-$N.notifyScriptLoad();
+    $N.notifyScriptLoad();
 
 });
index 32f74430edc95117b0f84f1758b8c13d9d28b292..c6759162d2686633a2c993c53b2f7bba87899854 100644 (file)
@@ -211,6 +211,11 @@ $N.Class.create("Marker", $N.Core, {
         $J(document).mouseup(this.attachWithEvent(this._onMouseUp));
     }
 
+//    _toString: function() {
+//        return "<marker id="+id+" position="+position+" description=\""+
+//            +description+"\"/>";
+//    }
+
 
 });
 
index 543fb2e5cdfe7bcb78567d3b1deb61afc29f4e67..29ade71f94437cacaf690b2717d17c9615c7fc84 100644 (file)
@@ -114,7 +114,20 @@ $N.Class.create("MarkerMap", $N.Core, {
 
     each: function(callback) {
         $J(this.markers).each(callback);
+    },
+
+    _toString: function() {
+        var s = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<telemeta>\n<markers>";
+        for (var i in this.markers) {
+                marker = this.markers[i];
+            s+="\n\t"; //+marker._toString();
+            s+="<marker id="+marker.id+" position="+marker.offset+" description=\""+
+            +marker.desc+"\"/>"
+        }
+        s+="\n</markers>\n</telemeta>";
+        return s;
     }
+
 });
 
 $N.notifyScriptLoad();
index 04df2f62293ae0f220d364b5e536c6e65961f5a2..a43baec312e1a00f178dd39a0aa416357210ebfe 100644 (file)
@@ -18,7 +18,8 @@ $N.Class.create("Player", $N.Core, {
         },
         'div.control': {
             'div.layout': {
-                'div.playback': ['a.play', 'a.pause', 'a.rewind', 'a.forward', 'a.set-marker']
+                'div.playback': ['a.play', 'a.pause', 'a.rewind', 'a.forward', 'a.set-marker', 'a.set-marker2']
+                //,'input.textMarker']
             }
         }/*,
         'div.marker-control': ['a.set-marker']*/
@@ -28,7 +29,9 @@ $N.Class.create("Player", $N.Core, {
         pause: 'Pause',
         rewind: 'Rewind',
         forward: 'Forward',
-        'set-marker': 'Set marker'
+        'set-marker': 'Set marker',
+        'set-marker2': 'Set marker2'
+        //,'text-marker' : 'textmarker'
     },
     elements: {},
     ruler: null,
@@ -93,11 +96,13 @@ $N.Class.create("Player", $N.Core, {
         // IE apparently doesn't send the second mousedown on double click:
         var jump = $J.browser.msie ? 'mousedown dblclick' : 'mousedown';
         this.elements.rewind.attr('href', '#').bind(jump, this.attach(this._onRewind))
-            .click(function() {return false; });
+            .click(function() {return false;});
         this.elements.forward.attr('href', '#').bind(jump, this.attach(this._onForward))
-            .click(function() {return false; });
+            .click(function() {return false;});
         this.elements.pause.attr('href', '#').bind('click', this.attach(this._onPause));
         this.elements.play.attr('href', '#').bind('click', this.attach(this._onPlay));
+        
+        //assigning title string to all anchors???????
         this.elements.control.find('a').add(this.elements.setMarker)
             .attr('href', '#')
             .each(function(i, a){
@@ -108,7 +113,12 @@ $N.Class.create("Player", $N.Core, {
             
         //this.elements.markerControl.find('a').attr('href', '#');
         if (this.map) {
+            //configureMarkersDiv();
             this.elements.setMarker.bind('click', this.attach(this._onSetMarker));
+            this.elements.setMarker2.bind('click', this.attach(this._onSetMarker2));
+            //this.elements.textMarker.attr('type', 'text');
+            //this.elements.textMarker.bind('click', this.attach(this._onSetMarker2));
+          
         } else {
             this.elements.setMarker.remove();
         }
@@ -133,6 +143,13 @@ $N.Class.create("Player", $N.Core, {
         //this.container.resize(this.attach(this.resize)); // Can loop ?
     },
 
+    _onSetMarker2: function() {
+        if (this.map) {
+            this.fire('markeradd2', {offset: this.soundProvider.getPosition()});
+        }
+        return false;
+    },
+
     resize: function(overrideHeight) {
         this.debug("resizing");
         var height;
index 4133495e49bebe9f10a41139178e3b6b377d74dc..44cc3460449cd2db817fdb300cea9e968d677d6c 100644 (file)
@@ -61,6 +61,7 @@ load_player({{ item.approx_duration.as_seconds }});
         </div>\r
         </div>\r
 \r
+        <div class="markers_div" id="markers_div_id"></div>\r
         <div class="item_visualization">\r
             <form id="visualizer_id_form" method="get" action="#">\r
                 <!--\r
@@ -86,7 +87,7 @@ load_player({{ item.approx_duration.as_seconds }});
               <td>Property</td>\r
               <td>Value</td>\r
               <td>Unit</td>\r
-             <tr>\r
+             </tr>\r
             {% for analyser in analysers %}\r
              <tr class="analyzer-line">\r
               <td>\r
@@ -115,7 +116,6 @@ load_player({{ item.approx_duration.as_seconds }});
         </form>\r
 -->\r
         </div>\r
-\r
         {% if audio_export_enabled %}\r
         <div class="exporter">\r
             <p>{% trans "Download:" %}\r