Browse Source

Mostly working

Noah 7 years ago
parent
commit
b2daddf441
4 changed files with 27 additions and 34 deletions
  1. 9 8
      audiogram/index.js
  2. 6 7
      bin/worker
  3. 6 9
      client/index.js
  4. 6 10
      server/render.js

+ 9 - 8
audiogram/index.js View File

@@ -19,6 +19,7 @@ function Audiogram(id) {
19 19
 
20 20
   // File locations to use
21 21
   this.dir = path.join(serverSettings.workingDirectory, this.id);
22
+
22 23
   this.audioPath = path.join(this.dir, "audio");
23 24
   this.videoPath = path.join(this.dir, "video.mp4");
24 25
   this.frameDir = path.join(this.dir, "frames");
@@ -40,11 +41,11 @@ Audiogram.prototype.getDuration = function(cb) {
40 41
       return cb(err);
41 42
     }
42 43
 
43
-    if (self.settings.maxDuration && self.settings.maxDuration < duration) {
44
-      cb("Exceeds max duration of " + self.settings.maxDuration + "s");
44
+    if (self.settings.theme.maxDuration && self.settings.theme.maxDuration < duration) {
45
+      cb("Exceeds max duration of " + self.settings.theme.maxDuration + "s");
45 46
     }
46 47
 
47
-    self.set("numFrames", self.numFrames = Math.floor(duration * self.settings.framesPerSecond));
48
+    self.set("numFrames", self.numFrames = Math.floor(duration * self.settings.theme.framesPerSecond));
48 49
 
49 50
     cb(null);
50 51
 
@@ -61,7 +62,7 @@ Audiogram.prototype.getWaveform = function(cb) {
61 62
 
62 63
   getWaveform(this.audioPath, {
63 64
     numFrames: this.numFrames,
64
-    samplesPerFrame: this.settings.samplesPerFrame
65
+    samplesPerFrame: this.settings.theme.samplesPerFrame
65 66
   }, function(err, waveform){
66 67
 
67 68
     return cb(err, self.waveform = waveform);
@@ -104,7 +105,7 @@ Audiogram.prototype.drawFrames = function(cb) {
104 105
 
105 106
   this.status("renderer");
106 107
 
107
-  initializeCanvas(this.settings, function(err, renderer){
108
+  initializeCanvas(this.settings.theme, function(err, renderer){
108 109
 
109 110
     if (err) {
110 111
       return cb(err);
@@ -113,8 +114,8 @@ Audiogram.prototype.drawFrames = function(cb) {
113 114
     self.status("frames");
114 115
 
115 116
     drawFrames(renderer, {
116
-      width: self.settings.width,
117
-      height: self.settings.height,
117
+      width: self.settings.theme.width,
118
+      height: self.settings.theme.height,
118 119
       numFrames: self.numFrames,
119 120
       frameDir: self.frameDir,
120 121
       caption: self.settings.caption,
@@ -137,7 +138,7 @@ Audiogram.prototype.combineFrames = function(cb) {
137 138
     framePath: path.join(this.frameDir, "%06d.png"),
138 139
     audioPath: this.audioPath,
139 140
     videoPath: this.videoPath,
140
-    framesPerSecond: this.settings.framesPerSecond
141
+    framesPerSecond: this.settings.theme.framesPerSecond
141 142
   }, cb);
142 143
 
143 144
 };

+ 6 - 7
bin/worker View File

@@ -10,15 +10,15 @@ pluckJob();
10 10
 
11 11
 function pluckJob(){
12 12
 
13
-  transports.getJob(function(err, settings){
13
+  transports.getJob(function(err, job){
14 14
 
15 15
     if (err) {
16 16
       throw err;
17 17
     }
18 18
 
19
-    if (settings) {
19
+    if (job) {
20 20
 
21
-      return render(settings);
21
+      return render(job);
22 22
 
23 23
     }
24 24
 
@@ -28,12 +28,11 @@ function pluckJob(){
28 28
 
29 29
 }
30 30
 
31
-function render(settings) {
31
+function render(job) {
32 32
 
33
-  var audiogram = new Audiogram(settings.id);
33
+  var audiogram = new Audiogram(job.id);
34 34
 
35
-  // TODO rename to theme
36
-  audiogram.settings = settings;
35
+  audiogram.settings = job;
37 36
 
38 37
   audiogram.render(function(err){
39 38
 

+ 6 - 9
client/index.js View File

@@ -45,16 +45,13 @@ function submitted() {
45 45
 
46 46
   var formData = new FormData();
47 47
 
48
-  var settings = $.extend({}, theme, {
49
-    caption: caption,
50
-    start: selection.start,
51
-    end: selection.end
52
-  });
53
-
54
-  delete settings.backgroundImageFile;
55
-
56 48
   formData.append("audio", file);
57
-  formData.append("settings", JSON.stringify(settings));
49
+  if (selection.start || selection.end) {
50
+    formData.append("start", selection.start);
51
+    formData.append("end", selection.end);
52
+  }
53
+  formData.append("theme", JSON.stringify($.extend({}, theme, { backgroundImageFile: null })));
54
+  formData.append("caption", caption);
58 55
 
59 56
   setClass("loading");
60 57
   d3.select("#loading-message").text("Uploading audio...");

+ 6 - 10
server/render.js View File

@@ -9,7 +9,7 @@ function validate(req, res, next) {
9 9
 
10 10
   try {
11 11
 
12
-    req.body.settings = JSON.parse(req.body.settings);
12
+    req.body.theme = JSON.parse(req.body.theme);
13 13
 
14 14
   } catch(e) {
15 15
 
@@ -22,12 +22,12 @@ function validate(req, res, next) {
22 22
   }
23 23
 
24 24
   // Start at the beginning, or specified time
25
-  if (req.body.settings.start) {
26
-    req.body.settings.start = +req.body.settings.start;
25
+  if (req.body.start) {
26
+    req.body.start = +req.body.start;
27 27
   }
28 28
 
29
-  if (req.body.settings.end) {
30
-    req.body.settings.end = +req.body.settings.end;
29
+  if (req.body.end) {
30
+    req.body.end = +req.body.end;
31 31
   }
32 32
 
33 33
   return next();
@@ -45,11 +45,7 @@ function route(req, res) {
45 45
     }
46 46
 
47 47
     // Queue up the job with a timestamp
48
-    transports.addJob({
49
-      created: (new Date()).getTime(),
50
-      settings: req.body.settings,
51
-      caption: req.body.caption
52
-    });
48
+    transports.addJob(_.extend({ id: id, created: (new Date()).getTime() }, req.body));
53 49
 
54 50
     res.json({ id: id });
55 51