expose per clip volume in edits

This commit is contained in:
j 2017-04-15 13:45:31 +02:00
parent 28f9a01d90
commit be34383f8c
6 changed files with 58 additions and 9 deletions

View file

@ -44,11 +44,11 @@ class Migration(migrations.Migration):
('created', models.DateTimeField(auto_now_add=True)), ('created', models.DateTimeField(auto_now_add=True)),
('modified', models.DateTimeField(auto_now=True)), ('modified', models.DateTimeField(auto_now=True)),
('name', models.CharField(max_length=255)), ('name', models.CharField(max_length=255)),
('status', models.CharField(default=b'private', max_length=20)), ('status', models.CharField(default='private', max_length=20)),
('description', models.TextField(default=b'')), ('description', models.TextField(default='')),
('rightslevel', models.IntegerField(db_index=True, default=0)), ('rightslevel', models.IntegerField(db_index=True, default=0)),
('query', oxdjango.fields.DictField(default={b'static': True})), ('query', oxdjango.fields.DictField(default={'static': True})),
('type', models.CharField(default=b'static', max_length=255)), ('type', models.CharField(default='static', max_length=255)),
('icon', models.ImageField(blank=True, default=None, null=True, upload_to=edit.models.get_icon_path)), ('icon', models.ImageField(blank=True, default=None, null=True, upload_to=edit.models.get_icon_path)),
('poster_frames', oxdjango.fields.TupleField(default=[], editable=False)), ('poster_frames', oxdjango.fields.TupleField(default=[], editable=False)),
('subscribed_users', models.ManyToManyField(related_name='subscribed_edits', to=settings.AUTH_USER_MODEL)), ('subscribed_users', models.ManyToManyField(related_name='subscribed_edits', to=settings.AUTH_USER_MODEL)),

View file

@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.4 on 2017-04-15 10:29
from __future__ import unicode_literals
from django.db import migrations, models
import oxdjango.fields
class Migration(migrations.Migration):
dependencies = [
('edit', '0002_auto_20160219_1537'),
]
operations = [
migrations.RenameField(
model_name='clip',
old_name='volume',
new_name='sortvolume',
),
migrations.AddField(
model_name='clip',
name='volume',
field=models.FloatField(default=1),
),
]

View file

@ -94,6 +94,8 @@ class Edit(models.Model):
or round(c.start, 3) >= round(duration, 3) \ or round(c.start, 3) >= round(duration, 3) \
or round(c.end, 3) > round(duration, 3): or round(c.end, 3) > round(duration, 3):
return False return False
if 'volume' in data:
c.volume = float(data['volume'])
c.save() c.save()
if index is not None: if index is not None:
ids.insert(index, c.id) ids.insert(index, c.id)
@ -427,11 +429,12 @@ class Clip(models.Model):
start = models.FloatField(default=0) start = models.FloatField(default=0)
end = models.FloatField(default=0) end = models.FloatField(default=0)
duration = models.FloatField(default=0) duration = models.FloatField(default=0)
volume = models.FloatField(default=1)
hue = models.FloatField(default=0) hue = models.FloatField(default=0)
saturation = models.FloatField(default=0) saturation = models.FloatField(default=0)
lightness = models.FloatField(default=0) lightness = models.FloatField(default=0)
volume = models.FloatField(default=0) sortvolume = models.FloatField(default=0)
sortvalue = models.CharField(max_length=1000, null=True, db_index=True) sortvalue = models.CharField(max_length=1000, null=True, db_index=True)
objects = managers.ClipManager() objects = managers.ClipManager()
@ -466,15 +469,16 @@ class Clip(models.Model):
if int(end*25) - int(start*25) > 0: if int(end*25) - int(start*25) > 0:
self.hue, self.saturation, self.lightness = extract.average_color( self.hue, self.saturation, self.lightness = extract.average_color(
self.item.timeline_prefix, self.start, self.end) self.item.timeline_prefix, self.start, self.end)
self.volume = extract.average_volume(self.item.timeline_prefix, self.start, self.end) self.sortvolume = extract.average_volume(self.item.timeline_prefix, self.start, self.end)
else: else:
self.hue = self.saturation = self.lightness = 0 self.hue = self.saturation = self.lightness = 0
self.volume = 0 self.sortvolume = 0
def json(self, user=None): def json(self, user=None):
data = { data = {
'id': self.get_id(), 'id': self.get_id(),
'index': self.index 'index': self.index,
'volume': self.volume,
} }
if self.annotation: if self.annotation:
data['annotation'] = self.annotation.public_id data['annotation'] = self.annotation.public_id

View file

@ -102,6 +102,7 @@ def editClip(request, data):
id: string, // clip id id: string, // clip id
in: float, // in point in seconds in: float, // in point in seconds
out: float // out point in seconds out: float // out point in seconds
volume: float // per clip volume (0-1)
} }
returns {} returns {}
see: addClips, orderClips, removeClips, sortClips see: addClips, orderClips, removeClips, sortClips
@ -118,6 +119,8 @@ def editClip(request, data):
clip.item = clip.annotation.item clip.item = clip.annotation.item
clip.annotation = None clip.annotation = None
setattr(clip, {'in': 'start', 'out': 'end'}.get(key), float(data[key])) setattr(clip, {'in': 'start', 'out': 'end'}.get(key), float(data[key]))
if 'volume' in data:
clip.volume = float(data['volume'])
if not clip.annotation: if not clip.annotation:
duration = clip.item.sort.duration duration = clip.item.sort.duration
if clip.start >= clip.end or clip.start >= duration or clip.end > duration: if clip.start >= clip.end or clip.start >= duration or clip.end > duration:
@ -183,6 +186,7 @@ def _order_clips(edit, sort):
'in': 'start', 'in': 'start',
'out': 'end', 'out': 'end',
'text': 'sortvalue', 'text': 'sortvalue',
'volume': 'sortvolume',
'item__sort__item': 'item__sort__public_id', 'item__sort__item': 'item__sort__public_id',
}.get(key, key) }.get(key, key)
order = '%s%s' % (operator, key) order = '%s%s' % (operator, key)

View file

@ -213,6 +213,18 @@ pandora.ui.editPanel = function(isEmbed) {
} }
pandora.api.get({id: clip.item, keys: ['duration']}, function(result) { pandora.api.get({id: clip.item, keys: ['duration']}, function(result) {
var clips; var clips;
//fixme include in history...
if (data.key == 'volume') {
pandora.api.editClip({
id: data.id,
volume: data.value
}, function(result) {
edit.clips[Ox.getIndexById(edit.clips, data.id)] = result.data;
Ox.Request.clearCache('sortClips');
sortClips(updateClips);
});
return;
}
if (data.key == 'out') { if (data.key == 'out') {
data.value = Math.min(data.value, result.data.duration); data.value = Math.min(data.value, result.data.duration);
} }

View file

@ -1197,6 +1197,9 @@ pandora.getClipVideos = function(clip, resolution) {
if (clip.id) { if (clip.id) {
item.id = clip.id; item.id = clip.id;
} }
if (Ox.isNumber(clip.volume)) {
item.volume = clip.volume;
}
if ( if (
currentTime <= start currentTime <= start
&& currentTime + clip.durations[i] > start && currentTime + clip.durations[i] > start