617 } |
617 } |
618 |
618 |
619 Model.Annotation.prototype = new Model.Element(); |
619 Model.Annotation.prototype = new Model.Element(); |
620 |
620 |
621 Model.Annotation.prototype.setBegin = function(_beginMs) { |
621 Model.Annotation.prototype.setBegin = function(_beginMs) { |
622 this.begin.setMilliseconds(_beginMs); |
622 this.begin.setMilliseconds(Math.max(0,_beginMs)); |
623 } |
623 this.trigger("change-begin"); |
624 |
624 if (this.end < this.begin) { |
625 Model.Annotation.prototype.setEnd = function(_beginMs) { |
625 this.setEnd(this.begin); |
626 this.end.setMilliseconds(_beginMs); |
626 } |
|
627 } |
|
628 |
|
629 Model.Annotation.prototype.setEnd = function(_endMs) { |
|
630 this.end.setMilliseconds(Math.min(_endMs, this.getMedia().duration.milliseconds)); |
|
631 this.trigger("change-end"); |
|
632 if (this.end < this.begin) { |
|
633 this.setBegin(this.end); |
|
634 } |
|
635 } |
|
636 |
|
637 Model.Annotation.prototype.setDuration = function(_durMs) { |
|
638 this.setEnd(_durMs + this.begin.milliseconds); |
627 } |
639 } |
628 |
640 |
629 Model.Annotation.prototype.setMedia = function(_idRef) { |
641 Model.Annotation.prototype.setMedia = function(_idRef) { |
630 this.setReference("media", _idRef); |
642 this.setReference("media", _idRef); |
631 } |
643 } |
662 |
674 |
663 Model.MashedAnnotation = function(_mashup, _annotation) { |
675 Model.MashedAnnotation = function(_mashup, _annotation) { |
664 Model.Element.call(this, _mashup.id + "_" + _annotation.id, _annotation.source); |
676 Model.Element.call(this, _mashup.id + "_" + _annotation.id, _annotation.source); |
665 this.elementType = 'mashedAnnotation'; |
677 this.elementType = 'mashedAnnotation'; |
666 this.annotation = _annotation; |
678 this.annotation = _annotation; |
667 this.begin = new Model.Time(_mashup.duration); |
679 this.begin = new Model.Time(); |
668 this.end = new Model.Time(_mashup.duration + _annotation.getDuration()); |
680 this.end = new Model.Time(); |
|
681 this.duration = new Model.Time(); |
669 this.title = this.annotation.title; |
682 this.title = this.annotation.title; |
|
683 this.media_title = this.getMedia().title; |
670 this.description = this.annotation.description; |
684 this.description = this.annotation.description; |
671 this.color = this.annotation.color; |
685 this.color = this.annotation.color; |
672 var _this = this; |
686 var _this = this; |
673 this.on("click", function() { |
687 this.on("click", function() { |
674 _mashup.setCurrentTime(_this.begin); |
688 _mashup.setCurrentTime(_this.begin); |
693 return this.annotation.getTags().getTitles(); |
707 return this.annotation.getTags().getTitles(); |
694 } |
708 } |
695 |
709 |
696 Model.MashedAnnotation.prototype.getDuration = function() { |
710 Model.MashedAnnotation.prototype.getDuration = function() { |
697 return this.annotation.getDuration(); |
711 return this.annotation.getDuration(); |
|
712 } |
|
713 |
|
714 Model.MashedAnnotation.prototype.setBegin = function(_begin) { |
|
715 this.begin.setMilliseconds(_begin); |
|
716 this.duration.setMilliseconds(this.annotation.getDuration()); |
|
717 this.end.setMilliseconds(_begin + this.duration); |
698 } |
718 } |
699 |
719 |
700 /* */ |
720 /* */ |
701 |
721 |
702 Model.Mashup = function(_id, _source) { |
722 Model.Mashup = function(_id, _source) { |
703 Model.Playable.call(this, _id, _source); |
723 Model.Playable.call(this, _id, _source); |
704 this.elementType = 'mashup'; |
724 this.elementType = 'mashup'; |
705 this.duration = new Model.Time(); |
725 this.duration = new Model.Time(); |
706 this.segments = new Model.List(_source.directory); |
726 this.segments = new Model.List(_source.directory); |
707 this.medias = new Model.List(_source.directory); |
|
708 var _currentMedia = null; |
727 var _currentMedia = null; |
709 var _this = this; |
728 var _this = this; |
710 this.on("timeupdate", function(_time) { |
729 this.on("timeupdate", function(_time) { |
711 _this.getAnnotations().filter(function(_a) { |
730 _this.getAnnotations().filter(function(_a) { |
712 return (_a.end <= _time || _a.begin > _time) && _a.playing |
731 return (_a.end <= _time || _a.begin > _time) && _a.playing |
727 _m.trigger("enter"); |
746 _m.trigger("enter"); |
728 _currentMedia = _m; |
747 _currentMedia = _m; |
729 } |
748 } |
730 }); |
749 }); |
731 }); |
750 }); |
|
751 this._updateTimes = function() { |
|
752 _this.updateTimes(); |
|
753 } |
|
754 this.on("add-segments", this._updateTimes); |
|
755 this.on("remove-segments", this._updateTimes); |
732 } |
756 } |
733 |
757 |
734 Model.Mashup.prototype = new Model.Playable(); |
758 Model.Mashup.prototype = new Model.Playable(); |
735 |
759 |
736 Model.Mashup.prototype.addSegment = function(_annotation) { |
760 Model.Mashup.prototype.updateTimes = function() { |
737 var _mashedAnnotation = new Model.MashedAnnotation(this, _annotation); |
761 var _time = 0; |
738 this.duration.setMilliseconds(_mashedAnnotation.end); |
762 this.segments.forEach(function(_segment) { |
|
763 _segment.setBegin(_time); |
|
764 _time = _segment.end; |
|
765 }); |
|
766 this.duration.setMilliseconds(_time); |
|
767 } |
|
768 |
|
769 Model.Mashup.prototype.addSegment = function(_annotation, _defer) { |
|
770 var _mashedAnnotation = new Model.MashedAnnotation(this, _annotation), |
|
771 _defer = _defer || false; |
739 this.segments.push(_mashedAnnotation); |
772 this.segments.push(_mashedAnnotation); |
740 this.medias.push(_annotation.getMedia()); |
773 _annotation.on("change-begin", this._updateTimes); |
741 } |
774 _annotation.on("change-end", this._updateTimes); |
742 |
775 if (!_defer) { |
743 Model.Mashup.prototype.addSegmentById = function(_elId) { |
776 this.trigger("add-segments"); |
744 var _annotation = this.source.getElement(_elId); |
777 } |
|
778 } |
|
779 |
|
780 Model.Mashup.prototype.addSegmentById = function(_elId, _defer) { |
|
781 var _annotation = this.source.getElement(_elId), |
|
782 _defer = _defer || false; |
745 if (typeof _annotation !== "undefined") { |
783 if (typeof _annotation !== "undefined") { |
746 this.addSegment(_annotation); |
784 this.addSegment(_annotation, _defer); |
|
785 } |
|
786 } |
|
787 |
|
788 Model.Mashup.prototype.addSegments = function(_segments) { |
|
789 var _this = this; |
|
790 ns._(_segments).forEach(function(_segment) { |
|
791 _this.addSegment(_segment, true); |
|
792 }); |
|
793 this.trigger("add-segments"); |
|
794 } |
|
795 |
|
796 Model.Mashup.prototype.addSegmentsById = function(_segments) { |
|
797 var _this = this; |
|
798 ns._(_segments).forEach(function(_segment) { |
|
799 _this.addSegmentById(_segment, true); |
|
800 }); |
|
801 this.trigger("add-segments"); |
|
802 } |
|
803 |
|
804 Model.Mashup.prototype.removeSegment = function(_annotation, _defer) { |
|
805 var _defer = _defer || false; |
|
806 _annotation.off("change-begin", this._updateTimes); |
|
807 _annotation.off("change-end", this._updateTimes); |
|
808 this.segments.removeElement(_annotation); |
|
809 if (!_defer) { |
|
810 this.trigger("remove-segments"); |
|
811 } |
|
812 } |
|
813 |
|
814 Model.Mashup.prototype.removeSegmentById = function(_annId, _defer) { |
|
815 var _defer = _defer || false; |
|
816 var _annotation = this.source.getElementById(_annId); |
|
817 if (_annotation) { |
|
818 this.removeSegment(_annotation, _defer); |
|
819 } |
|
820 this.segments.removeElement(_annotation); |
|
821 if (!_defer) { |
|
822 this.trigger("remove-segments"); |
747 } |
823 } |
748 } |
824 } |
749 |
825 |
750 Model.Mashup.prototype.getAnnotations = function() { |
826 Model.Mashup.prototype.getAnnotations = function() { |
751 return this.segments; |
827 return this.segments; |
752 } |
828 } |
753 |
829 |
754 Model.Mashup.prototype.getMedias = function() { |
830 Model.Mashup.prototype.getMedias = function() { |
755 return this.medias; |
831 var medias = new Model.List(_source.directory); |
|
832 this.segments.each(function(_annotation) { |
|
833 medias.push(_annotation.getMedia()) |
|
834 }) |
|
835 return medias; |
756 } |
836 } |
757 |
837 |
758 Model.Mashup.prototype.getAnnotationsByTypeTitle = function(_title) { |
838 Model.Mashup.prototype.getAnnotationsByTypeTitle = function(_title) { |
759 var _annTypes = this.source.getAnnotationTypes().searchByTitle(_title).pluck("id"); |
839 var _annTypes = this.source.getAnnotationTypes().searchByTitle(_title).pluck("id"); |
760 if (_annTypes.length) { |
840 if (_annTypes.length) { |