Skip to content

Commit

Permalink
Work on tagging and annotations
Browse files Browse the repository at this point in the history
modified:   Gemfile
modified:   Gemfile.lock
modified:   app/assets/javascripts/application.js
	-- added moment js gem

modified:   app/assets/javascripts/angular/controllers/annotation_viewer.js
	-- added option to constructor so it can transform resource objects (ensuresconsistent data)

modified:   app/assets/javascripts/angular/controllers/listen.js
modified:   app/assets/javascripts/angular/directives/directives.js
	-- general work

modified:   app/assets/templates/listen.html
modified:   app/assets/javascripts/angular/filters/filters.js
	-- created a filter for using momentjs in angular expressions

modified:   app/assets/stylesheets/partials/_annotation_viewer.css.scss
	-- fixed overflow bug

modified:   lib/assets/javascripts/jquery.drawabox.js

new file:   vendor/bin/shntool-3.0.10/shntool.exe
	-- great tool for cutting wav files
  • Loading branch information
atruskie committed Feb 5, 2013
1 parent c67af6d commit 68f0675
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 24 deletions.
43 changes: 31 additions & 12 deletions app/assets/javascripts/angular/controllers/annotation_viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,20 @@ function AnnotationViewerCtrl($scope, $element, $attrs, $transclude) {
};




// updated in directive
$scope.model.converters = $scope.model.converters || {};


}

function Annotation(localId, audioRecordingId) {
function Annotation(localIdOrResource, audioRecordingId) {

var localId = typeof(localIdOrResource) === "number" ? localIdOrResource : undefined;
var resource;
if (localIdOrResource instanceof Object && localIdOrResource.constructor.name == "Resource") {
resource = localIdOrResource;
}

if (!(this instanceof Annotation))
throw new Error("Constructor called as a function");

Expand All @@ -43,17 +48,31 @@ function Annotation(localId, audioRecordingId) {
this.__temporaryId__ = localId || Number.Unique();
this._selected = false;

this.audioRecordingId = audioRecordingId;
if (localId) {
this.audioRecordingId = audioRecordingId;

this.createdAt = now;
this.updatedAt = now;

this.endTimeSeconds = 0.0;
this.highFrequencyHertz = 0.0;
this.isReference = false;
this.lowFrequencyHertz = 0.0;
this.startTimeSeconds = 0.0;
this.audioEventTags = [];
}

if (resource) {
angular.extend(this, resource);

this.createdAt = now;
this.updatedAt = now;
this.createdAt = new Date(this.createdAt);
this.updatedAt = new Date(this.updatedAt);

this.endTimeSeconds = 0.0;
this.highFrequencyHertz = 0.0;
this.isReference = false;
this.lowFrequencyHertz = 0.0;
this.startTimeSeconds = 0.0;
this.audioEventTags = [];
this.endTimeSeconds = parseFloat(this.endTimeSeconds);
this.highFrequencyHertz = parseFloat(this.highFrequencyHertz);
this.lowFrequencyHertz = parseFloat(this.lowFrequencyHertz);
this.startTimeSeconds = parseFloat(this.startTimeSeconds);
}
}

AnnotationViewerCtrl.$inject = ['$scope', '$element', '$attrs', '$transclude'];
18 changes: 12 additions & 6 deletions app/assets/javascripts/angular/controllers/listen.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,8 @@ function ListenCtrl($scope, $resource, $routeParams, Media, AudioEvent, Tag) {


for (var index = 0; index < $scope.model.audioEvents.length; index++) {
// give local Ids
$scope.model.audioEvents[index].__temporaryId__ = Number.Unique;

// give other properties
$scope.model.audioEvents[index]._selected = false;
// transform
$scope.model.audioEvents[index] = new Annotation($scope.model.audioEvents[index]);
}
},
function audioEventQueryFailure() {
Expand All @@ -95,7 +92,9 @@ function ListenCtrl($scope, $resource, $routeParams, Media, AudioEvent, Tag) {


// download all the tags and store them in Tag service cache
Tag.query({}, {}, function(){}, undefined);
Tag.query({}, {}, function(){

}, undefined);

$scope.model.limits = {
timeMin: 0.0,
Expand All @@ -105,6 +104,13 @@ function ListenCtrl($scope, $resource, $routeParams, Media, AudioEvent, Tag) {
};


$scope.startOffset = function() {
return moment($scope.media.model.original.recordedDate).add({seconds: $scope.media.model.startOffset});
};
$scope.endOffset = function() {
return moment($scope.media.model.original.recordedDate).add({seconds: $scope.media.model.endOffset});
};

$scope.clearSelected = function() {
//$scope.model.selectedAudioEvents.length = 0;

Expand Down
14 changes: 9 additions & 5 deletions app/assets/javascripts/angular/directives/directives.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,16 +199,17 @@
* @param scope
*/
function resizeOrMove(audioEvent, box, scope) {
var boxId = parseInt(box.id);

if (audioEvent.__temporaryId__ === box.id) {
if (audioEvent.__temporaryId__ === boxId) {
audioEvent.startTimeSeconds = scope.model.converters.pixelsToSeconds(box.left || 0);
audioEvent.highFrequencyHertz = scope.model.converters.pixelsToHertz(box.top || 0);

audioEvent.endTimeSeconds = audioEvent.startTimeSeconds + scope.model.converters.pixelsToSeconds(box.width || 0);
audioEvent.lowFrequencyHertz = audioEvent.highFrequencyHertz + scope.model.converters.pixelsToHertz(box.height || 0);
}
else {
console.error("Box ids do not match on resizing or move event", audioEvent.__temporaryId__, box.id);
console.error("Box ids do not match on resizing or move event", audioEvent.__temporaryId__, boxId);
}
}

Expand All @@ -226,7 +227,7 @@

function create(simpleBox, audioRecordingId, scope) {

var audioEvent = new Annotation(simpleBox.id, audioRecordingId);
var audioEvent = new Annotation(parseInt(simpleBox.id), audioRecordingId);

resizeOrMove(audioEvent, simpleBox, scope);
touchUpdatedField(audioEvent);
Expand Down Expand Up @@ -503,9 +504,8 @@

}


element.bind('click', updateModel);
// element.bind('change', updateModel);
// element.bind('change', updateModel);

// forward binding (from model to element)
ctrl.$render = function () {
Expand All @@ -519,6 +519,10 @@
};

attr.$observe('value', ctrl.$render);


// lastly cache any new items
// library[attr.name].push([scope, ctrl]);
}
}
});
Expand Down
19 changes: 19 additions & 0 deletions app/assets/javascripts/angular/filters/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,23 @@
}
});

/**
* moment js adapters
*
* requires momentjs
*/
bawfs.filter('moment', function() {
return function(input, method) {

if (input) {
var restOfArguments = Array.prototype.slice.call(arguments, 2, arguments.length)

var m = moment(input);
return m[method].apply(m, restOfArguments);

}

}
});

})();
1 change: 1 addition & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
//= require jquery_ujs
// require jquery.ui.all // disabled because slow
// require jquery.ui.datepicker // disabled because slow
//= require moment
//= require angular.js
//= require angular-resource.js
//= require angular-ui.js
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ baw-annotation-viewer {
position: absolute;
top: 0;
left: 0;
overflow: hidden;

// debug
@if $DEBUG { background-color: rgba(255,0,0,0.15) ;}
Expand Down
14 changes: 13 additions & 1 deletion app/assets/templates/listen.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ <h1>Listen</h1>
<p>Listen and annotate.</p>

<h3>Spectrogram</h3>
<p>
Date: {{model.media.original.recordedDate | moment:"format":"dddd, MMMM Do YYYY, HH:mm:ss ZZ"}}
</p>
<baw-annotation-viewer model="model"></baw-annotation-viewer>
<p>
<span>Date: {{model.media.original.recordedDate}}</span>
<span>Date: {{model.media.original.recordedDate}}</span>
</p>

<h3>Audio Controls</h3>
<audio id="main-player" ng-audio="model.audioElement" controls>
Expand Down Expand Up @@ -74,6 +81,7 @@ <h3>Annotations</h3>
<thead>
<tr>
<th>Selected</th>
<th>Jump to</th>
<th>Annotation ID</th>
<th>Audio Recording</th>
<th>Created At</th>
Expand All @@ -91,7 +99,11 @@ <h3>Annotations</h3>
<tr ng-repeat="ae in model.audioEvents">
<td>
<!--<input type="radio" ng-checked="ae._selected" ng-model="ae._selected" name="selectionRadioGroup" >-->
<input type="radio" baw-checked ng-model="ae._selected" name="selectionRadioGroup" >
<input type="radio" baw-checked ng-model="ae._selected" name="selectionRadioGroup" >
SELECTED:{{ae._selected}}
</td>
<td>
<!-- TODO -->
</td>
<td colspan="{{ae.id && 1 || 2}}">
{{ae.id}}
Expand Down
1 change: 1 addition & 0 deletions lib/assets/javascripts/jquery.drawabox.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@
stop: function (event, ui) { contextData.options.boxResized($newBox); }
});
$newBox.draggable({
containment: 'parent',
drag: function (event, ui) { contextData.options.boxMoving($newBox); },
stop: function (event, ui) { contextData.options.boxMoved($newBox); }
});
Expand Down
Binary file added vendor/bin/shntool-3.0.10/shntool.exe
Binary file not shown.

0 comments on commit 68f0675

Please sign in to comment.