Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New audio player - Review of iss127 #135

Merged
merged 74 commits into from
Apr 18, 2018
Merged
Show file tree
Hide file tree
Changes from 69 commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
8530865
Add optional parameters Freesound api query
xavierfav Jan 24, 2018
03c9648
Add command and task refresh sound extra_data
xavierfav Jan 25, 2018
ab7fa63
Add audio annotator lib files
lorenzo-romanelli Jan 25, 2018
0d64447
Add optional parameters Freesound api query
xavierfav Jan 24, 2018
96d24da
Add command and task refresh sound extra_data
xavierfav Jan 25, 2018
9ce935b
Merge remote-tracking branch 'origin/iss123' into iss127
xavierfav Jan 25, 2018
9cbe00e
Merge branch 'iss127' of github.com:MTG/freesound-datasets into iss127
xavierfav Jan 25, 2018
08d95b2
Clean audio annotator unused files
xavierfav Jan 25, 2018
f74cf0a
Move audio annotator files, inignore lib/
xavierfav Jan 25, 2018
1495332
Add wavesurfer player WIP
xavierfav Jan 25, 2018
147fcf5
Add optional parameters Freesound api query
xavierfav Jan 24, 2018
cf510c5
Add command and task refresh sound extra_data
xavierfav Jan 25, 2018
7e5da79
Add audio annotator lib files
lorenzo-romanelli Jan 25, 2018
21c768c
Clean audio annotator unused files
xavierfav Jan 25, 2018
4df5cb7
Move audio annotator files, inignore lib/
xavierfav Jan 25, 2018
7b74d89
Add wavesurfer player WIP
xavierfav Jan 25, 2018
836d6d3
Add images sound extra data
xavierfav Jan 30, 2018
9f1250b
Fix conflict
xavierfav Jan 30, 2018
e97667d
Work on audio player WIP
lorenzo-romanelli Jan 30, 2018
c2a4c6b
Add graph num contributions per day
xavierfav Jan 17, 2018
a244f05
Add cumulative contributions
xavierfav Jan 17, 2018
70c40f2
Add monitor graph ground truth
xavierfav Jan 18, 2018
f603d30
Change header graph
xavierfav Jan 18, 2018
2a090b2
Switch graphs to Highstock
xavierfav Jan 19, 2018
ccbb40f
Add management command extract votes #126
xavierfav Jan 22, 2018
4bf99ca
Fix file path extract votes
xavierfav Jan 22, 2018
fbc93bc
Fix new line js
xavierfav Jan 22, 2018
159dd1b
Fix size FSD button on small screen
xavierfav Jan 23, 2018
37e48cb
Add optional parameters Freesound api query
xavierfav Jan 24, 2018
965f256
Add command and task refresh sound extra_data
xavierfav Jan 25, 2018
6b1d4f4
Fix bug GT graph order dates
xavierfav Jan 25, 2018
d99466d
Add audio annotator lib files
lorenzo-romanelli Jan 25, 2018
0272704
Clean audio annotator unused files
xavierfav Jan 25, 2018
dcf2159
Move audio annotator files, inignore lib/
xavierfav Jan 25, 2018
b870d46
Add wavesurfer player WIP
xavierfav Jan 25, 2018
34f3b4f
Add gitignore files
xavierfav Jan 30, 2018
1d1895c
Add audio annotator lib files
lorenzo-romanelli Jan 25, 2018
d735dea
Clean audio annotator unused files
xavierfav Jan 25, 2018
31b2e61
Move audio annotator files, inignore lib/
xavierfav Jan 25, 2018
a658f18
Add images sound extra data
xavierfav Jan 30, 2018
6379e66
Work on audio player WIP
lorenzo-romanelli Jan 30, 2018
d601439
Merge branch 'iss127' of https://github.com/MTG/freesound-datasets in…
lorenzo-romanelli Mar 19, 2018
8c36e78
Merge branch 'master' into iss127
lorenzo-romanelli Mar 19, 2018
276130e
Add FreeSound spectrogram URL when monitoring a category
lorenzo-romanelli Mar 21, 2018
03f45ae
Add FreeSound images as background for audio player
lorenzo-romanelli Mar 21, 2018
13dc3bd
Prevent wavesurfer from drawing waveforms
lorenzo-romanelli Mar 23, 2018
c1fe52c
Add basic player interface
lorenzo-romanelli Mar 23, 2018
1b900c3
Refactorized player code into own JS prototype
lorenzo-romanelli Mar 23, 2018
c3098e9
Finish refactoring player JS
lorenzo-romanelli Mar 26, 2018
c6d5f3b
Finish refactoring player JS
lorenzo-romanelli Mar 26, 2018
62e0500
Add stop all functionality for the player
lorenzo-romanelli Mar 26, 2018
2256e2c
Add basic player timer
lorenzo-romanelli Mar 26, 2018
9df6a6b
Finish player v0.1
lorenzo-romanelli Mar 28, 2018
67cc1fd
Add hover effect on playbar
lorenzo-romanelli Mar 28, 2018
974710d
Change color of the progress bar and fix secondsToString function
lorenzo-romanelli Mar 30, 2018
6259f47
Fix player and canvas sizes
lorenzo-romanelli Mar 30, 2018
63bb430
Add loader while loading the player
lorenzo-romanelli Mar 31, 2018
ee4172c
Add players wherever needed, with the possibility to change size
lorenzo-romanelli Apr 4, 2018
fc36e9d
Add random number to the player id to avoid conflicts between players…
lorenzo-romanelli Apr 5, 2018
b2b72eb
Fix too many AudioContexts bug
lorenzo-romanelli Apr 5, 2018
74afc99
Add unique ID to players (replaces random ID)
lorenzo-romanelli Apr 5, 2018
02d3d1c
Fix bug when playing sounds loaded over ajax that wouldn't stop sound…
lorenzo-romanelli Apr 5, 2018
e310849
Use UUID4 to identify instances of the player
lorenzo-romanelli Apr 10, 2018
3049857
Move <script> inclusion in separate templatetag, to avoid unnecessary…
lorenzo-romanelli Apr 12, 2018
fe0e9c8
Refactor player css without using flexboxes (should fix bug in FSD ho…
lorenzo-romanelli Apr 13, 2018
2af81e4
Use 'Math.floor' instead of 'seconds.toFixed' for timer
lorenzo-romanelli Apr 13, 2018
bc9d961
Build cleaner interface for sound validation
lorenzo-romanelli Apr 13, 2018
026568f
Stop player in FSD homepage when scrolling happens. Hide timer. Refac…
lorenzo-romanelli Apr 16, 2018
a8b1728
Add WaveSurfer overrides in pleyer.js to avoid drawing waveform
lorenzo-romanelli Apr 16, 2018
ada0523
Clean code. Fix annotator interface bug. Minor other fixes.
lorenzo-romanelli Apr 18, 2018
fbadade
Destroy players when popups are closed
lorenzo-romanelli Apr 18, 2018
c27a84e
Fix player.destroy() bug
lorenzo-romanelli Apr 18, 2018
31d9ffa
Update picture of the interface on annotation instructions
lorenzo-romanelli Apr 18, 2018
7082110
Destroy player only if loaded
lorenzo-romanelli Apr 18, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
Expand Down
13 changes: 13 additions & 0 deletions datasets/management/commands/refresh_sound_extra_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from django.core.management.base import BaseCommand
from datasets.tasks import refresh_sound_extra_data


class Command(BaseCommand):
help = 'Refresh the extra_data field in Sound model' \


def add_arguments(self, parser):
pass

def handle(self, *args, **options):
refresh_sound_extra_data()
50 changes: 50 additions & 0 deletions datasets/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,56 @@ class Sound(models.Model):
def get_candidate_annotations(self, dataset):
return CandidateAnnotation.objects.filter(sound_dataset__in=self.sounddataset_set.filter(dataset=dataset))

def get_image_url(self, img_type, size):
img_types = ['spectrogram', 'waveform']
sizes = ['M', 'L']
if img_type not in img_types:
return '#'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Raising an exception here would make more sense.

if size not in sizes:
return '#'
url_parts = self.extra_data['previews'].split('previews')
prefix = url_parts[0]
freesound_id_pref = url_parts[1].split('/')[1]
user_id = url_parts[1].split('_')[-1].split('-')[0]
params = {
'prefix': prefix,
'freesound_id_pref': freesound_id_pref,
'freesound_id': self.freesound_id,
'user_id': user_id,
'size': size
}
if img_type == 'spectrogram':
img_url = self.build_spectrogram_url(params)
elif img_type == 'waveform':
img_url = self.build_waveform_url(params)
return img_url

def build_spectrogram_url(self, params):
prefix = params['prefix']
freesound_id_pref = params['freesound_id_pref']
freesound_id = params['freesound_id']
user_id = params['user_id']
size = params['size']
spec_url = "{0}displays/{1}/{2}_{3}_spec_{4}.jpg".format(prefix,
freesound_id_pref,
freesound_id,
user_id,
size)
return spec_url

def build_waveform_url(self, params):
prefix = params['prefix']
freesound_id_pref = params['freesound_id_pref']
freesound_id = params['freesound_id']
user_id = params['user_id']
size = params['size']
wave_url = "{0}displays/{1}/{2}_{3}_wave_{4}.png".format(prefix,
freesound_id_pref,
freesound_id,
user_id,
size)
return wave_url

def __str__(self):
return 'Sound {0} (freesound {1})'.format(self.id, self.freesound_id)

Expand Down
13 changes: 13 additions & 0 deletions datasets/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,16 @@ def refresh_sound_deleted_state():
sound.deleted_in_freesound = True
sound.save()
logger.info('Finished refreshing freesound sound deleted state')


@shared_task
def refresh_sound_extra_data():
logger.info('Start refreshing freesound sound extra data')
sound_ids = Sound.objects.all().values_list('freesound_id', flat=True)
results = query_freesound_by_id(sound_ids, fields="id,name,analysis,images", descriptors="lowlevel.average_loudness")
with transaction.atomic():
for freesound_sound in results:
sound = Sound.objects.get(freesound_id=freesound_sound.id)
sound.extra_data.update(freesound_sound.as_dict())
sound.save()
logger.info('Finished refreshing freesound sound extra data')
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
{% extends "base.html" %}
{% load staticfiles %}
{% load dataset_templatetags %}
{% load general_templatetags %}
{% block title %}Validate category {{ node.name }}{% endblock title %}
{% block extra_head %}
{% load_sound_player_files %}
{% endblock %}

{% block page_js %}
<script type="text/javascript">
function submitForm(){
Expand Down Expand Up @@ -209,22 +214,26 @@ <h2>Is <div class="ui big label">{{ node.name }}</div> present in the following
<div class="card" id="row_annotation_{{ forloop.counter0 }}">
{% with annotation.sound_dataset.sound.freesound_id as fsid %}
<div class="content">
<div class="right floated meta"><a href="javascript:void(0);" onclick="openFreesoundSoundPage('{{ fsid }}', '{{ forloop.counter0 }}');">
<div class="header">
#{{ forloop.counter }}
<div class="right floated meta"><a href="javascript:void(0);" onclick="openFreesoundSoundPage('{{ fsid }}', '{{ forloop.counter0 }}');">
see in <img class="ui image" style="width: 80px;" src="{% static 'img/freesound_logo_color.png' %}"></a></div>
<div class="header">#{{ forloop.counter }}</div>

</div>
<div class="description">
<div class="ui grid">
<div class="eight wide column">
{{ fsid| fs_embed | safe }}
<div class="ui container center aligned">
{% sound_player dataset fsid "medium" %}
</div>
<div class="eight wide column vote_card_form">
{{ form.vote }}
{{ form.annotation_id }}
{{ form.visited_sound }}
<div class="ui grid">
<div class="centered row">
<div class="eight wide column vote_card_form">
{{ form.vote }}
{{ form.annotation_id }}
{{ form.visited_sound }}
</div>
</div>
</div>
</div>

</div>
</div>
{% endwith %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
{% extends "base.html" %}
{% load staticfiles %}
{% load dataset_templatetags %}
{% load general_templatetags %}
{% block title %}Validate category {{ node.name }}{% endblock title %}
{% block extra_head %}
{% load_sound_player_files %}
{% endblock %}

{% block page_js %}
<script type="text/javascript">
function submitForm(){
Expand Down Expand Up @@ -184,22 +189,24 @@ <h2>Is <div class="ui big label">{{ node.name }}</div> present in the following
<div class="card" id="row_annotation_{{ forloop.counter0 }}">
{% with annotation.sound_dataset.sound.freesound_id as fsid %}
<div class="content">
<div class="right floated meta"><a href="javascript:void(0);" onclick="openFreesoundSoundPage('{{ fsid }}', '{{ forloop.counter0 }}');">
<div class="header">
#{{ forloop.counter }}
<div class="right floated meta"><a href="javascript:void(0);" onclick="openFreesoundSoundPage('{{ fsid }}', '{{ forloop.counter0 }}');">
see in <img class="ui image" style="width: 80px;" src="{% static 'img/freesound_logo_color.png' %}"></a></div>
<div class="header">#{{ forloop.counter }}</div>

</div>
<div class="description">
<div class="ui container center aligned">
{% sound_player dataset fsid "medium" %}
</div>
<div class="ui grid">
<div class="eight wide column">
{{ fsid| fs_embed | safe }}
</div>
<div class="eight wide column vote_card_form">
{{ form.vote }}
{{ form.annotation_id }}
{{ form.visited_sound }}
<div class="centered row">
<div class="sixteen wide column vote_card_form">
{{ form.vote }}
{{ form.annotation_id }}
{{ form.visited_sound }}
</div>
</div>
</div>

</div>
</div>
{% endwith %}
Expand Down
11 changes: 10 additions & 1 deletion datasets/templates/datasets/dataset.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
{% load dataset_templatetags %}
{% load general_templatetags %}
{% block title %}{{dataset.short_name|upper}}{% endblock title %}
{% block extra_head %}
{% load_sound_player_files %}
{% endblock %}

{% block page_js %}

<script type="text/javascript">
Expand Down Expand Up @@ -102,6 +106,10 @@
var translate_value = translate_values[counter];
examples_container.css({"transform": "translateX(" + translate_value + "px)"});
counter = (counter < 9) ? counter + 1 : 0;
// stop currently playing sound
if (window.activePlayer) {
window.activePlayer.stop();
}
}
}, 3000)

Expand Down Expand Up @@ -153,7 +161,8 @@ <h3 class="ui header">{{ dataset.short_name|upper }}: a dataset of everyday soun
<div>
{% for sound in node.valid_examples|slice:"2" %}
<span>
{{ sound| fs_embed | safe }}
{% sound_player dataset sound "mini" %}
{# {{ sound| fs_embed | safe }}#}
</span>
{% endfor %}
</div>
Expand Down
13 changes: 13 additions & 0 deletions datasets/templates/datasets/include_player_resources.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% load staticfiles %}

{% block extra_head %}
<link rel="stylesheet" type="text/css" href="{% static "audio-annotator/css/player.css" %}"/>
<!--script src="{% static "audio-annotator/js/lib/materialize.min.js" %}" type="text/javascript"></script-->
<script src="{% static "audio-annotator/js/lib/wavesurfer.min.js" %}" type="text/javascript"></script>
<!--script src="{% static "audio-annotator/js/lib/wavesurfer.spectrogram.min.js" %}" type="text/javascript"></script-->
<!--script src="{% static "audio-annotator/js/colormap/colormap.min.js" %}" type="text/javascript"></script-->
<!--script src="{% static "audio-annotator/js/src/annotation_stages.js" %}" type="text/javascript"></script-->
<!--script src="{% static "audio-annotator/js/src/hidden_image.js" %}" type="text/javascript"></script-->
<!--script src="{% static "audio-annotator/js/src/components.js" %}" type="text/javascript"></script-->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clear commented script here

<script src="{% static "audio-annotator/js/src/player.js" %}" type="text/javascript"></script>
{% endblock %}
26 changes: 26 additions & 0 deletions datasets/templates/datasets/player.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{% load general_templatetags %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think loading the general template tags here is not needed


<div class="player_container">

<div class="soundplayer {{ player_size }}" id="s{{ freesound_id }}_{{ player_id }}">
<div class="ui active dimmer">
<div class="ui loader"></div>
</div>
<div class="wavesurfer"></div>
<div class="playbar"></div>
</div>

<script type="text/javascript">
var playerOptions = {
size: "{{ player_size }}",
player_id: "{{ player_id }}",
freesound_id: "{{ freesound_id }}",
sound_url: "{{ sound_url }}",
waveform_url: "{{ waveform_url }}",
spectrogram_url: "{{ spectrogram_url }}",
};

var player = new Player(playerOptions)
</script>

</div>
6 changes: 5 additions & 1 deletion datasets/templates/datasets/taxonomy_node.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% extends "base.html" %}
{% load staticfiles %}
{% load dataset_templatetags %}
{% load general_templatetags %}
{% block title %}{{ node.name }}{% endblock title %}

{% block content %}
Expand Down Expand Up @@ -30,7 +31,10 @@ <h2>Audio samples with candidate annotations for <div class="ui huge label">{{ n
<tbody>
{% for sound in sounds %}
<tr>
<td>{{ sound.freesound_id | fs_embed | safe }}</td>
<td>
{# {{ sound.freesound_id | fs_embed | safe }}#}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clear commented code

{% sound_player dataset sound.freesound_id "small" %}
</td>
<td><a href="http://freesound.org/s/{{ sound.freesound_id }}" target="_blank">http://freesound.org/s/{{ sound.freesound_id }}</a></td>
<td>{{ sound.num_PP }}</td>
<td>{{ sound.num_PNP }}</td>
Expand Down
12 changes: 10 additions & 2 deletions datasets/templates/datasets/taxonomy_node_info.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
{% load staticfiles %}
{% load dataset_templatetags %}
{% load general_templatetags %}
{% block extra_head %}
{% load_sound_player_files %}
{% endblock %}

{% block page_js %}
<script type="text/javascript">
var popupLoading = '<div style="height:310px; width:730px" class="ui loading segment">Loading</div>';
Expand All @@ -12,7 +18,8 @@
var popup = this
var ajax_url = el.getAttribute('ajax_url')
$.ajax({
url: ajax_url
url: ajax_url,
cache: true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this "cache: true" really needed in the end?
There are other part of the code where there are this sort of AJAX requests for pop-ups.
I never saw problems with not caching some code, and since we finally send the lib files in the HTML template that includes the player, it is I guess not a problem anymore?

Anyway, I don't say to remove it. Just want to understand if this would be needed in other cases.

}).done(function(result) {
popup.html(result);
el.setAttribute("data-html", result);
Expand Down Expand Up @@ -91,7 +98,8 @@
<tr><td>Examples</td>
<td>
{% for fsid in node.freesound_examples %}
{{ fsid| fs_embed | safe }}
{# {{ fsid| fs_embed | safe }}#}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clear

{% sound_player dataset fsid "small" %}
{% endfor %}
</td>
</tr>
Expand Down
4 changes: 3 additions & 1 deletion datasets/templates/datasets/taxonomy_node_mini_info.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{% load dataset_templatetags %}
{% load general_templatetags %}

<table class="ui unstackable table bottom attached" width="100%" style="margin-bottom:7px;">
<tbody>
<td>Hierarchy</td>
Expand Down Expand Up @@ -32,7 +34,7 @@
<tr><td>Examples</td>
<td>
{% for fsid in node.freesound_examples %}
{{ fsid| fs_embed | safe }}
{% sound_player dataset fsid "small" %}
{% endfor %}
</td>
</tr>
Expand Down
6 changes: 5 additions & 1 deletion datasets/templates/datasets/taxonomy_node_small_info.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{% load staticfiles %}
{% load dataset_templatetags %}
{% load general_templatetags %}

{% block page_js %}
<script type="text/javascript">
var popupLoading = '<div style="height:310px; width:730px" class="ui loading segment">Loading</div>';
Expand Down Expand Up @@ -67,7 +70,8 @@
<tr><td>Examples</td>
<td>
{% for fsid in node.freesound_examples %}
{{ fsid| fs_embed | safe }}
{% sound_player dataset fsid "small" %}
{# {{ fsid| fs_embed | safe }}#}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clear

{% endfor %}
</td>
</tr>
Expand Down
22 changes: 22 additions & 0 deletions datasets/templatetags/general_templatetags.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django import template
from django.core import urlresolvers
from uuid import uuid4
import datetime
import time

Expand Down Expand Up @@ -48,3 +49,24 @@ def timestamp_to_datetime(value):
@register.filter()
def multiply(value, arg):
return value*arg


@register.inclusion_tag('datasets/include_player_resources.html')
def load_sound_player_files():
return


@register.inclusion_tag('datasets/player.html')
def sound_player(dataset, freesound_sound_id, player_size):
sound = dataset.sounds.get(freesound_id=freesound_sound_id)
sound_url = sound.extra_data['previews']
spec_size = 'M' if player_size in ("mini", "small") else 'L'
spectrogram_url = sound.get_image_url('spectrogram', spec_size)
waveform_url = sound.get_image_url('waveform', 'M')
return {'sound_url': sound_url,
'freesound_id': freesound_sound_id,
'spectrogram_url': spectrogram_url,
'waveform_url': waveform_url,
'player_size': player_size,
'player_id': uuid4()
}
Loading