Skip to content

Commit 255e661

Browse files
Activity on apparent tactile motion: display ideal duration/SOA on value change
1 parent 9de1eab commit 255e661

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

index.html

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -433,15 +433,19 @@ <h2>Study</h2>
433433
<section>
434434
<h2>Activity</h2>
435435
<p>Explore the effects of parameters</p>
436-
<div width="20Opx">
436+
437437
<canvas nx="dial" id="intensity1" label="Intensity" min="0" max="1" height="100" width="100"></canvas>
438438
<canvas nx="dial" id="duration1" label="Duration" min="0.01" max="1000" height="100" width="100"></canvas>
439439
<canvas nx="dial" id="soa1" label="SOA" min="0" max="1000" height="100" width="100"></canvas>
440440
<canvas nx="button" id="bang1" label="Trigger" height="100" width="100"></canvas>
441-
<canvas nx="envelope" id="envelopeLeft1" label="Envelope (left)" height="100" width="100"></canvas>
442-
<canvas nx="envelope" id="envelopeRight1" label="Envelope (right)" height="100" width="100"></canvas>
441+
<br/>
442+
<canvas nx="envelope" id="envelopeLeft1" label="Envelope (left)" height="100" width="200"></canvas>
443+
<canvas nx="envelope" id="envelopeRight1" label="Envelope (right)" height="100" width="200"></canvas>
444+
<br/>
445+
<canvas nx="dial" id="idealDuration1" label="Ideal duration" min="0.01" max="1000" height="100" width="100"></canvas>
446+
<canvas nx="dial" id="idealSoa1" label="Ideal SOA" min="0" max="1000" height="100" width="100"></canvas>
443447
<!--<canvas nx="toggle" id="svgToggle1" label="Toggle SVG"></canvas>-->
444-
</div>
448+
445449
<div id="pdPatch1" class="pdPatch"></div>
446450
<script>
447451
Pd.start();

js/webaudiohaptics.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ function addActivity1(patchUrl, pdPatchId, suffix) {
6565

6666
function addActivity(patchUrl, pdPatchId, suffix) {
6767

68+
console.log('addActivity', patchUrl, pdPatchId, suffix)
69+
6870
var defaultIntensity = 0.3;
6971
var defaultDuration = 100;
7072
var maxDuration = 2000;
@@ -79,6 +81,9 @@ function addActivity(patchUrl, pdPatchId, suffix) {
7981
var envelopeLeft = nx.widgets['envelopeLeft' + suffix];
8082
var envelopeRight = nx.widgets['envelopeRight' + suffix];
8183
var svgToggle = nx.widgets['svgToggle' + suffix];
84+
var idealDuration = nx.widgets['idealDuration' + suffix];
85+
var idealSoa = nx.widgets['idealSoa' + suffix];
86+
console.log(nx.widgets)
8287

8388
if (intensity) {
8489
intensity.on('value', function(data) {
@@ -88,14 +93,29 @@ function addActivity(patchUrl, pdPatchId, suffix) {
8893
}
8994
if (duration) {
9095
duration.on('value', function(data) {
91-
//console.log('duration', data)
92-
Pd.send('duration', [data])
96+
Pd.send('duration', [data]);
97+
if (idealSoa) {
98+
// SOA = 0.28 * duration + 60.7
99+
var idealSoaVal = 0.28 * data + 60.7
100+
//console.log('idealSoa', idealSoaVal)
101+
idealSoa.set({
102+
value: idealSoaVal
103+
})
104+
}
93105
})
94106
}
95107
if (soa) {
96108
soa.on('value', function(data) {
97109
//console.log('soa', data)
98110
Pd.send('soa', [data])
111+
if (idealDuration) {
112+
// SOA = 0.28 * duration + 60.7
113+
var idealDurationVal = (data - 60.7)/0.28;
114+
//console.log('idealDuration', idealDurationVal)
115+
idealDuration.set({
116+
value: idealDurationVal
117+
})
118+
}
99119
})
100120
}
101121
if (bang) {
@@ -203,6 +223,12 @@ function addActivity(patchUrl, pdPatchId, suffix) {
203223
soa.set({
204224
value: defaultSOA
205225
})
226+
idealDuration.set({
227+
value: defaultDuration
228+
})
229+
idealSoa.set({
230+
value: defaultSOA
231+
})
206232

207233
envelopeLeft.set({
208234
points: [{

0 commit comments

Comments
 (0)