Skip to content

Commit 17076fe

Browse files
committed
basic functionality of one room
1 parent 462f538 commit 17076fe

File tree

3 files changed

+20
-36
lines changed

3 files changed

+20
-36
lines changed

app/index.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,16 @@ function changeFrequency(id, direction, frequency) {
1818
synthesizers[id][direction].frequency.value = frequency
1919
}
2020

21+
function changeAmplitude(id, amplitude) {
22+
// var newAmp = amplitude * -3
23+
// console.log('newAmp:', newAmp);
24+
// synthesizers[id].x.volume.value = newAmp;
25+
// synthesizers[id].y.volume.value = newAmp;
26+
}
27+
2128
function attack(id) {
2229
synthesizers[id].x.triggerAttack(synthesizers[id].x.frequency.value)
23-
synthesizers[id].y.triggerAttack(synthesizers[id].y.frequency.value)
30+
synthesizers[id].y.triggerAttack(synthesizers[id].x.frequency.value * 1.5)
2431
}
2532

2633
function release(id) {
@@ -35,8 +42,8 @@ socket.on('connect', () => {
3542

3643
socket.on('populateSynths', (ids) => {
3744
ids.forEach(id => {
38-
let newXSynth1 = new Tone.Synth().chain(reverb)
39-
let newYSynth2 = new Tone.Synth().chain(reverb)
45+
let newXSynth1 = new Tone.DuoSynth({harmonicity: 1.5}).chain(reverb)
46+
let newYSynth2 = new Tone.DuoSynth({harmonicity: 1.5}).chain(reverb)
4047
newXSynth1.volume.value = -12;
4148
newYSynth2.volume.value = -12;
4249
synthesizers[id] = {
@@ -48,13 +55,17 @@ socket.on('populateSynths', (ids) => {
4855

4956
socket.on('mouseDown', (event) => {
5057
changeFrequency(event.id, 'x', event.x)
51-
changeFrequency(event.id, 'y', event.y)
58+
changeFrequency(event.id, 'y', event.x * 1.5)
5259
attack(event.id)
5360
})
5461

5562
socket.on('mouseDrag', (event) => {
63+
// console.log(event);
64+
let amplitude = Math.abs(event.delta[1]) + Math.abs(event.delta[2])
65+
changeAmplitude(event.id, amplitude)
66+
5667
changeFrequency(event.id, 'x', event.x)
57-
changeFrequency(event.id, 'y', event.y)
68+
changeFrequency(event.id, 'y', event.x * 1.5)
5869
})
5970

6071
socket.on('mouseUp', (event) => {

public/js/ui.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ for (var i = 0; i < count; i++) {
5959
placedSymbol.scale(i / count);
6060
placedSymbol.direction = 2 * Math.PI * Math.random()
6161
}
62-
console.log(view.size);
6362

6463
// The onFrame function is called up to 60 times a second:
6564
function onFrame(event) {
@@ -128,15 +127,6 @@ socket.on('mouseDown', function(event) {
128127
})
129128

130129
function onMouseDrag(event) {
131-
// var step = event.delta / 2;
132-
// step.angle += 90;
133-
134-
// var top = event.middlePoint + step;
135-
// var bottom = event.middlePoint - step;
136-
137-
// path.add(top);
138-
// path.insert(0, bottom);
139-
// path.smooth();
140130
var outEvent = {
141131
id: socket.id,
142132
x: event.point.x,

server/index.js

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ const volleyball = require('volleyball')
66

77
const express = require('express');
88
const app = express();
9-
109
const socketio = require('socket.io');
10+
const chalk = require('chalk')
1111

1212
server.on('request', app);
1313

@@ -29,8 +29,8 @@ app.use(express.static(path.join(__dirname, '../public')));
2929
app.use(volleyball)
3030

3131
io.on('connection', socket => {
32-
console.log('New client connection');
33-
console.log(socket.id);
32+
console.log(chalk.blue('New client connection'));
33+
console.log(chalk.blue(socket.id));
3434

3535
// join room on create (room name is passed from client)
3636
socket.on('create', room => {
@@ -43,28 +43,13 @@ io.on('connection', socket => {
4343
// dispatch the current synths (including self)
4444
io.to(room).emit('populateSynths', memory[room])
4545

46-
// on 'draw' add to memory and draw to others in room
47-
// socket.to(room).on('draw', (...payload) => {
48-
// memory[room].push(payload);
49-
// io.to(room).emit('otherDrawing', ...payload)
50-
// })
5146

5247
// on 'draw' add to memory and draw to others in room
5348
socket.to(room).on('mouseDown', (inEvent) => {
54-
// const event = {
55-
// id: socket.id,
56-
// x: inEvent.x,
57-
// y: inEvent.y
58-
// }
5949
io.to(room).emit('mouseDown', inEvent)
6050
})
6151

6252
socket.to(room).on('mouseDrag', (inEvent) => {
63-
// const event = {
64-
// id: socket.id,
65-
// x: inEvent.x,
66-
// y: inEvent.y
67-
// }
6853
io.to(room).emit('mouseDrag', inEvent)
6954
})
7055

@@ -75,11 +60,9 @@ io.on('connection', socket => {
7560
// log on disconnect
7661
socket.on('disconnect', () => {
7762
socket.leave(room);
78-
console.log('before', memory[room]);
63+
console.log(chalk.yellow(`leaving: ${socket.id}`))
7964
let deleteIndex = memory[room].indexOf(socket.id)
8065
if (deleteIndex !== -1) memory[room].splice(deleteIndex)
81-
console.log('after', memory[room]);
82-
console.log('disconnect :()');
8366
});
8467
})
8568
});

0 commit comments

Comments
 (0)