Skip to content

Commit 4b8029d

Browse files
sound feeback for sliders
1 parent c960282 commit 4b8029d

9 files changed

Lines changed: 1090 additions & 6 deletions

File tree

File renamed without changes.
File renamed without changes.
File renamed without changes.

assets/sounds/1.wav

1.34 KB
Binary file not shown.

assets/sounds/2.wav

160 KB
Binary file not shown.

lib/actions.js

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,32 @@
11
'use babel';
22

3+
import path from 'path';
4+
import play from 'play';
5+
6+
let tickSound = path.resolve(__dirname, '../assets/sounds/1.wav');
7+
let tickSound2 = path.resolve(__dirname, '../assets/sounds/2.wav');
8+
9+
let lastValue = null;
10+
let lastTime = 0;
11+
let tick = (value, accent) => {
12+
13+
if (lastValue != value) {
14+
let now = Date.now();
15+
if (accent || now - lastTime > 50) {
16+
lastTime = now;
17+
lastValue = value;
18+
if (accent) {
19+
play.sound(tickSound);
20+
}
21+
else {
22+
play.sound(tickSound2);
23+
}
24+
}
25+
}
26+
27+
};
28+
29+
330
export default function actions(message) {
431

532
// console.log(message.data);
@@ -73,6 +100,7 @@ export default function actions(message) {
73100
this.addLine('position', function(node) {
74101
var position = !node ? 'relative' : node.value.split(' ')[0];
75102
px = px !== 0 ? px + 'px' : px;
103+
tick(position + ' ' + px, px === 0);
76104
return position + ' ' + px;
77105
});
78106

@@ -177,6 +205,7 @@ export default function actions(message) {
177205
var px = Math.round(message.data[2] / 127 * 66);
178206
if (px >= 65) { px = '100%'; }
179207
else if (px !== 0) { px = px + 'px'; }
208+
tick(px, (px === 0 || px === '100%'));
180209
this.addLine('size', function(node) { return px; });
181210

182211
}
@@ -206,6 +235,7 @@ export default function actions(message) {
206235
this.getFocusNode(function(node) {
207236
if (node && node.type === 'decl') {
208237
if (node.prop === 'margin' || node.prop === 'padding') {
238+
tick(px, (px === 0));
209239
this.addLine(node.prop, function() { return px; });
210240
}
211241
}
@@ -254,8 +284,9 @@ export default function actions(message) {
254284
font = node.value.split(' ');
255285
}
256286
font[font.length - 1] = px;
257-
258-
return font.join(' ');
287+
let result = font.join(' ');
288+
tick(result, (px === 0));
289+
return result;
259290
});
260291

261292
}
@@ -279,6 +310,7 @@ export default function actions(message) {
279310

280311
var sec = Math.round(Math.round(message.data[2] / 127 * 3 / 10 * 100) * 0.02 * 100) / 100;
281312
sec = sec !== 0 ? sec + 's' : sec;
313+
tick(sec, (sec === 0));
282314
this.addLine('transition', function(node) { return sec; });
283315

284316
}

0 commit comments

Comments
 (0)