Browse Source

waveLeft/waveRight

Noah 8 years ago
parent
commit
b0b95531cc
4 changed files with 19 additions and 13 deletions
  1. 4 0
      THEMES.md
  2. 1 1
      package.json
  3. 8 6
      renderer/index.js
  4. 6 6
      renderer/patterns.js

+ 4 - 0
THEMES.md View File

63
 * `pattern` - What waveform shape to draw. Current options are `wave`, `bars`, `roundBars`, `pixel`, `bricks`, and `equalizer` (default: `wave`)
63
 * `pattern` - What waveform shape to draw. Current options are `wave`, `bars`, `roundBars`, `pixel`, `bricks`, and `equalizer` (default: `wave`)
64
 * `waveTop` - How many pixels from the top edge to start the waveform (default: `0`)
64
 * `waveTop` - How many pixels from the top edge to start the waveform (default: `0`)
65
 * `waveBottom` - How many pixels from the top edge to end the waveform (default: same as `height`)
65
 * `waveBottom` - How many pixels from the top edge to end the waveform (default: same as `height`)
66
+* `waveLeft` - How many pixels from the left edge to start the waveform (default: `0`)
67
+* `waveRight` - How many pixels from the right edge to start the waveform (default: same as `width`)
66
 * `waveColor` - A CSS color, what color the wave should be. The default is black.
68
 * `waveColor` - A CSS color, what color the wave should be. The default is black.
67
 
69
 
70
+Note that if you change `waveLeft` or `waveRight` to something other than full-width, you'll probably want to tweak `samplesPerFrame` too or else things will get pretty squished.
71
+
68
 ### Additional options
72
 ### Additional options
69
 
73
 
70
 * `name` - What name to show in the dropdown menu in the editor (the default is the key)
74
 * `name` - What name to show in the dropdown menu in the editor (the default is the key)

+ 1 - 1
package.json View File

1
 {
1
 {
2
   "name": "audiogram",
2
   "name": "audiogram",
3
-  "version": "0.9.2",
3
+  "version": "0.9.3",
4
   "description": "Turn audio into a shareable video.",
4
   "description": "Turn audio into a shareable video.",
5
   "main": "index.js",
5
   "main": "index.js",
6
   "scripts": {
6
   "scripts": {

+ 8 - 6
renderer/index.js View File

12
   renderer.context = context;
12
   renderer.context = context;
13
 
13
 
14
   renderer.update = function(options) {
14
   renderer.update = function(options) {
15
+
16
+    // TODO cleaner defaults
15
     options.backgroundColor = options.backgroundColor || "#fff";
17
     options.backgroundColor = options.backgroundColor || "#fff";
16
     options.waveColor = options.waveColor || options.foregroundColor || "#000";
18
     options.waveColor = options.waveColor || options.foregroundColor || "#000";
17
     options.captionColor = options.captionColor || options.foregroundColor || "#000";
19
     options.captionColor = options.captionColor || options.foregroundColor || "#000";
18
-    if (typeof options.waveTop !== "number") {
19
-      options.waveTop = 0;
20
-    }
21
-    if (typeof options.waveBottom !== "number") {
22
-      options.waveBottom = options.height;
23
-    }
20
+
21
+    if (typeof options.waveTop !== "number") options.waveTop = 0;
22
+    if (typeof options.waveBottom !== "number") options.waveBottom = options.height;
23
+    if (typeof options.waveLeft !== "number") options.waveLeft = 0;
24
+    if (typeof options.waveRight !== "number") options.waveRight = options.width;
25
+
24
     this.wrapText = textWrapper(context, options);
26
     this.wrapText = textWrapper(context, options);
25
     this.options = options;
27
     this.options = options;
26
     this.waveform = options.waveform || [sample.slice(0, options.samplesPerFrame)];
28
     this.waveform = options.waveform || [sample.slice(0, options.samplesPerFrame)];

+ 6 - 6
renderer/patterns.js View File

1
 var d3 = require("d3");
1
 var d3 = require("d3");
2
 
2
 
3
 module.exports = {
3
 module.exports = {
4
-  wave: curve(d3.curveCardinal.tension(0)),
4
+  wave: curve(d3.curveCardinal.tension(0.1)),
5
   pixel: curve(d3.curveStep),
5
   pixel: curve(d3.curveStep),
6
   roundBars: bars(true),
6
   roundBars: bars(true),
7
   bars: bars(),
7
   bars: bars(),
28
     var x = d3.scalePoint()
28
     var x = d3.scalePoint()
29
       .padding(0.1)
29
       .padding(0.1)
30
       .domain(d3.range(data.length))
30
       .domain(d3.range(data.length))
31
-      .rangeRound([0, options.width]);
31
+      .rangeRound([options.waveLeft, options.waveRight]);
32
 
32
 
33
     var height = d3.scaleLinear()
33
     var height = d3.scaleLinear()
34
       .domain([0, 1])
34
       .domain([0, 1])
46
 
46
 
47
     }).reverse();
47
     }).reverse();
48
 
48
 
49
-    top.unshift([0, baseline]);
50
-    top.push([options.width, baseline]);
49
+    top.unshift([options.waveLeft, baseline]);
50
+    top.push([options.waveRight, baseline]);
51
 
51
 
52
     // Fill waveform
52
     // Fill waveform
53
     context.beginPath();
53
     context.beginPath();
80
       .paddingInner(0.5)
80
       .paddingInner(0.5)
81
       .paddingOuter(0.01)
81
       .paddingOuter(0.01)
82
       .domain(d3.range(data.length))
82
       .domain(d3.range(data.length))
83
-      .rangeRound([0, options.width]);
83
+      .rangeRound([options.waveLeft, options.waveRight]);
84
 
84
 
85
     var height = d3.scaleLinear()
85
     var height = d3.scaleLinear()
86
       .domain([0, 1])
86
       .domain([0, 1])
119
       .paddingInner(0.1)
119
       .paddingInner(0.1)
120
       .paddingOuter(0.01)
120
       .paddingOuter(0.01)
121
       .domain(d3.range(data.length))
121
       .domain(d3.range(data.length))
122
-      .rangeRound([0, options.width]);
122
+      .rangeRound([options.waveLeft, options.waveRight]);
123
 
123
 
124
     var height = d3.scaleLinear()
124
     var height = d3.scaleLinear()
125
       .domain([0, 1])
125
       .domain([0, 1])