Skip to content

Commit 20b9319

Browse files
Keep part color
1 parent 803ce85 commit 20b9319

File tree

4 files changed

+30
-9
lines changed

4 files changed

+30
-9
lines changed

fcut.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ else
398398
contexts = httpContexts,
399399
}):next(function(webview)
400400
local httpServer = webview:getHttpServer()
401+
logger:info('FCut HTTP Server available at http://localhost:%s/', (select(2, httpServer:getAddress())))
401402
httpServer:createContext('/webview/(.*)', RestHttpHandler:new({
402403
['fullscreen(requestJson)?method=POST&Content-Type=application/json'] = function(exchange, fullscreen)
403404
webview:fullscreen(fullscreen == true);

htdocs/fcut-utils.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,3 +198,15 @@ function readFile(filename, asJson) {
198198
return response.text();
199199
});
200200
}
201+
202+
function hashString(s) {
203+
var h = 0;
204+
if (typeof s !== 'string') {
205+
s = '' + s;
206+
}
207+
for (var i = 0; i < s.length; i++) {
208+
h = ((h << 5) - h) + s.charCodeAt(i);
209+
h |= 0;
210+
}
211+
return h;
212+
}

htdocs/fcut.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ <h2>Fast FFmpeg Cutter (Preview)</h2>
7676
</div>
7777
<div id="navigation-bar" v-if="bars.nav" v-on:click="navigateOnClick($event, 'navigation-bar')" class="navigation-bar">
7878
<span v-for="(part, index) in parts" class="part" v-bind:style="{
79-
'background-color': hsvToRgb((index * 67) % 240 / 240, 0.8, partIndex === index ? 0.8 : 0.5),
79+
'background-color': hsvToRgb(part ? part.hue : 0, 0.8, partIndex === index ? 0.8 : 0.5),
8080
width: (Math.floor((part ? part.duration : 0) * 980 / duration) / 10) + '%'
8181
}"></span>
8282
<span v-bind:style="{ left: (Math.floor(time * 980 / duration) / 10 + 1) + '%' }" class="position"></span>

htdocs/fcut.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ var timeRegExp = /^frame=.*\stime=([0-9:.]+)\s/;
55
var DEFAULT_DESTINATION_FILENAME = 'fcut-out.mp4';
66
var DEFAULT_PROJECT_FILENAME = 'fcut-project.json';
77

8+
function updatePart(part) {
9+
if (typeof part === 'object') {
10+
var u = hashString(part.sourceId + (part.from | 0).toString(16));
11+
part.hue = Math.abs(u) % 240 / 240;
12+
}
13+
return part;
14+
}
15+
816
var vm = new Vue({
917
el: '#app',
1018
data: {
@@ -171,12 +179,12 @@ var vm = new Vue({
171179
addSource: function(sourceId, beforeIndex) {
172180
var info = this.sources[sourceId];
173181
var duration = Math.floor(parseFloat(info.format.duration) - 1.1);
174-
var part = {
182+
var part = updatePart({
175183
sourceId: sourceId,
176184
duration: duration,
177185
from: 0,
178186
to: duration
179-
};
187+
});
180188
if ((beforeIndex >= 0) && (beforeIndex < this.parts.length)) {
181189
this.parts.splice(beforeIndex, 0, part);
182190
} else {
@@ -313,12 +321,12 @@ var vm = new Vue({
313321
if (firstIndex >= 0) {
314322
var part1 = this.parts[firstIndex];
315323
var part2 = this.parts[firstIndex + 1];
316-
var part = {
324+
var part = updatePart({
317325
sourceId: part1.sourceId,
318326
duration: part1.duration + part2.duration,
319327
from: part1.from,
320328
to: part2.to
321-
};
329+
});
322330
this.parts.splice(firstIndex, 2, part);
323331
}
324332
},
@@ -327,18 +335,18 @@ var vm = new Vue({
327335
if (at && (at.relTime > 0) && (at.relTime < at.part.duration)) {
328336
var part = at.part;
329337
var splitTime = part.from + at.relTime;
330-
var part1 = {
338+
var part1 = updatePart({
331339
sourceId: part.sourceId,
332340
duration: at.relTime,
333341
from: part.from,
334342
to: splitTime
335-
};
336-
var part2 = {
343+
});
344+
var part2 = updatePart({
337345
sourceId: part.sourceId,
338346
duration: part.duration - at.relTime,
339347
from: splitTime,
340348
to: part.to
341-
};
349+
});
342350
this.partTime = this.time;
343351
this.partEndTime = this.time + part2.duration;
344352
this.parts.splice(at.index, 1, part1, part2);

0 commit comments

Comments
 (0)