Skip to content

Commit f1abd83

Browse files
committed
two options for all
two synths two bgs/interfaces two backgrounds
1 parent 8ff64ce commit f1abd83

File tree

5 files changed

+95
-19
lines changed

5 files changed

+95
-19
lines changed

app/index.js

+61-10
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ const start = require('./toneCenter').start
99
const duoSynth = require('./instruments/duoSynth');
1010
const tunedSynth = require('./instruments/tunedSynth');
1111

12+
const spacey = require('./grounds/spacey')
13+
const junkyard = require('./grounds/junkyard')
14+
15+
const grounds = {
16+
spacey,
17+
junkyard
18+
}
19+
1220
const views = {
1321
spaceCircle,
1422
coolBlobs
@@ -19,47 +27,81 @@ const instruments = {
1927
tunedSynth
2028
}
2129

30+
const state = {
31+
view: 'spaceCircle',
32+
synth: 'duoSynth',
33+
ground: ['spacey']
34+
}
35+
36+
// ids of room members
37+
const users = {}
38+
2239
// main synth memory
2340
const synthesizers = {};
2441

2542
// start with audio defaults
2643
start();
27-
tunedSynth(synthesizers)
28-
const drums = require('./grounds/spacey')
44+
instruments[state.synth](synthesizers)
45+
46+
grounds.spacey.start()
2947

3048
// view click handler
3149
$('#views a').on('click', function(e) {
32-
console.log(this);
50+
// update state
51+
state.view = this.id
3352
// update menu
3453
$('#views li').removeClass('active')
3554
$(this).parent().addClass('active')
3655
e.preventDefault()
3756
// reset socket listeners
38-
socket.removeAllListeners('serverDown');
39-
socket.removeAllListeners('serverDrag');
40-
socket.removeAllListeners('serverUp');
57+
socket.removeAllListeners('serverDrawDown');
58+
socket.removeAllListeners('serverDrawDrag');
59+
socket.removeAllListeners('serverDrawUp');
4160

4261
// reset and repopulate view
4362
project.clear();
44-
views[this.id]();
63+
views[state.view]();
64+
})
65+
66+
$('#grounds a').on('click', function(e) {
67+
e.preventDefault()
68+
var $parent = $(this).parent();
69+
// update state
70+
if ($(this).parent().hasClass('active')) {
71+
state.ground.splice(state.ground.indexOf(this.id))
72+
console.log('id', this.id, 'grounds', grounds[this.id]);
73+
grounds[this.id].stop();
74+
} else {
75+
state.ground.push(this.id)
76+
grounds[this.id].start();
77+
}
78+
$(this).parent().toggleClass('active')
4579

46-
// restart synth
47-
tunedSynth(synthesizers);
4880
})
4981

5082
// instrument click handler
5183
$('#instruments a').on('click', function(e) {
84+
// update state
85+
state.synth = this.id
5286
// update menu
5387
$('#instruments li').removeClass('active')
5488
$(this).parent().addClass('active')
5589
e.preventDefault()
90+
5691
// reset socket listeners
5792
socket.removeAllListeners('serverDown');
5893
socket.removeAllListeners('serverDrag');
5994
socket.removeAllListeners('serverUp');
6095

96+
// clear current synths
97+
clearSynths()
98+
socket.emit('synthChange', state.synth)
99+
})
100+
101+
socket.on('newSynth', (newSynth) => {
61102
// restart synth
62-
instruments[this.id](synthesizers)
103+
clearSynths();
104+
instruments[newSynth](synthesizers)
63105
})
64106

65107
// set up canvas
@@ -109,4 +151,13 @@ tool.onMouseUp =(event) => {
109151
y: event.point.y,
110152
}
111153
socket.emit('mouseUp', outEvent)
154+
}
155+
156+
function clearSynths() {
157+
Object.keys(synthesizers).forEach(id => {
158+
Object.keys(synthesizers[id]).forEach(synth => {
159+
synthesizers[id][synth].dispose()
160+
})
161+
synthesizers[id] = {}
162+
})
112163
}

app/views/coolBlobs.js

+18-5
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ module.exports = function() {
5959
var symbols = [symbol1, symbol2, symbol3, symbol4]
6060

6161
for (var i = 0; i < count; i++) {
62-
// The center position is a random point in the view
63-
var center = new Point((view.size.width * -1 + view.size.width * ((i % 4) / 4)) + (view.size.width / 8), Math.random() * view.size.height);
62+
// The center position is in one of four columns
63+
let column = ((i % 4) / 4)
64+
var center = new Point((view.size.width * -1 + view.size.width * column) + (view.size.width / 8), Math.random() * view.size.height);
6465
var placedSymbol = symbols[Math.floor(Math.random() * 4)].place(center);
6566
placedSymbol.speed = Math.random() * 4 - 2;
6667
}
@@ -73,9 +74,21 @@ module.exports = function() {
7374
}
7475
}
7576

77+
view.onResize = (event) => {
78+
console.log(event);
79+
for (var i = 0; i < count; i++) {
80+
var item = project.activeLayer.children[i]
81+
// if(i < 5) console.log('before', item.position.x);
82+
let column = item.position.x / view.size.width + 1
83+
// if (i < 5) console.log(column);
84+
item.position.x += (event.delta.width * column)
85+
// if (i < 5) console.log('after', item.position.x);
86+
}
87+
}
88+
7689
// Space Circle Path:
7790

78-
socket.on('serverDown', function(event) {
91+
socket.on('serverDrawDown', function(event) {
7992
var circlePath = new Path.Circle({
8093
center: [event.x, event.y],
8194
radius: 20,
@@ -93,7 +106,7 @@ module.exports = function() {
93106
}, 300);
94107
})
95108

96-
socket.on('serverDrag', function(event) {
109+
socket.on('serverDrawDrag', function(event) {
97110
var last = paths[event.id].past[paths[event.id].past.length - 1]
98111
var circlePath = new Path.Circle({
99112
center: [event.x, event.y],
@@ -107,7 +120,7 @@ module.exports = function() {
107120
}, 300)
108121
});
109122

110-
socket.on('serverUp', function() {
123+
socket.on('serverDrawUp', function() {
111124

112125
})
113126

app/views/spaceCircle.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ module.exports = function() {
5959

6060

6161
// create drawing events
62-
socket.on('serverDown', function(event) {
62+
socket.on('serverDrawDown', function(event) {
6363
var shadow = new Path();
6464
var path = new Path();
6565
path.fillColor = {
@@ -90,7 +90,7 @@ module.exports = function() {
9090
};
9191
})
9292

93-
socket.on('serverDrag', function(event) {
93+
socket.on('serverDrawDrag', function(event) {
9494
var middlePoint = new Point(event.middlePoint[1], event.middlePoint[2])
9595
var step = new Point(event.delta[1] / 2, event.delta[2] / 2)
9696
step.angle += 90;
@@ -114,7 +114,7 @@ module.exports = function() {
114114

115115
})
116116

117-
socket.on('serverUp', function(event) {
117+
socket.on('serverDrawUp', function(event) {
118118
var current = paths[event.id].currentPath.path;
119119
var shadow = paths[event.id].currentPath.shadow;
120120
current.add(new Point(event.x, event.y));

public/css/style.css

+5
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,9 @@ body, html { height:100%; }
1313
canvas[resize] {
1414
width: 100%;
1515
height: 100%;
16+
}
17+
18+
.navbar-nav {
19+
margin-left:30px;
20+
margin-right:30px;
1621
}

server/index.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,21 @@ io.on('connection', socket => {
5151
// on 'draw' add to memory and draw to others in room
5252
socket.to(room).on('mouseDown', (inEvent) => {
5353
io.to(room).emit('serverDown', inEvent)
54+
io.to(room).emit('serverDrawDown', inEvent)
5455
})
5556

5657
socket.to(room).on('mouseDrag', (inEvent) => {
5758
io.to(room).emit('serverDrag', inEvent)
59+
io.to(room).emit('serverDrawDrag', inEvent)
5860
})
5961

6062
socket.to(room).on('mouseUp', (event) => {
61-
io.to(room).emit('serverUp', event)
63+
io.to(room).emit('serverUp', event)
64+
io.to(room).emit('serverDrawUp', event)
65+
})
66+
67+
socket.to(room).on('synthChange', (event) => {
68+
io.to(room).emit('newSynth', event)
6269
})
6370

6471
// log on disconnect

0 commit comments

Comments
 (0)