-
Notifications
You must be signed in to change notification settings - Fork 9
/
code.js
67 lines (52 loc) · 1.4 KB
/
code.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
$(function() {
var dropzone = $("#dropzone")
dropzone.on("dragenter dragstart dragend dragleave dragover drag drop", function (e) {
e.preventDefault();
});
dropzone.on("dragenter", function() {
dropzone.addClass("hover")
})
dropzone.on("dragleave", function() {
dropzone.removeClass("hover")
})
dropzone.on("drop", function(e) {
dropzone.removeClass("hover")
var flasher = function(state) {
dropzone.toggleClass("flash", state)
}
flasher(true);
var fileNames = extractFilenames(e.originalEvent.dataTransfer.files)
setTimeout(function() {
flasher(false)
var cueSheet = filenamesToCue(fileNames);
$("#cuesheet").text(cueSheet);
}, 250)
})
})
function extractFilenames(fileList) {
return $.makeArray(fileList).map(function(file) {
return file.name
})
}
function filenamesToCue(fileNames) {
fileNames = fileNames.slice()
var firstFile = fileNames.shift()
var sheet = 'FILE "' + firstFile + '" BINARY\n\
TRACK 01 MODE2/2352\n\
INDEX 01 00:00:00\n\
';
var trackCounter = 2
fileNames.forEach(function(fileName) {
sheet += 'FILE "' + fileName + '" BINARY\n\
TRACK ' + padLeadingZero(trackCounter) + " AUDIO\n\
INDEX 00 00:00:00\n\
INDEX 01 00:02:00\n\
"
trackCounter++
})
return sheet;
}
function padLeadingZero(number) {
var padded = "0" + number;
return padded.substr(padded.length-2);
}