-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrenderer.js
79 lines (62 loc) · 2.23 KB
/
renderer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// This file is required by the index.html file and will
// be executed in the renderer process for that window.
// All of the Node.js APIs are available in this process.
import React from 'react'
import ReactDOM from 'react-dom'
import { HashRouter as Router, Route, Link, Switch } from "react-router-dom";
import 'grommet/scss/vanilla/index.scss';
import Landing from './components/landing/Landing';
import Project from './components/project/Project';
import { createStore, applyMiddleware } from 'redux';
import { Provider } from 'react-redux';
import { projectReducer } from './reducers/project';
import { ipcRenderer } from 'electron';
import {IPC_WRITE_REQUEST} from './actions/ipcActions';
const ipcMiddleware = store => next => action => {
if(action.type.startsWith('IPC_REQUEST')) {
ipcRenderer.send(action.type, action);
}
return next(action);
};
import { playNote, metronomeBeat } from './actions/play';
import { playTonejsNote, setTimeCallback } from './tonejs/play';
const musicMiddlware = store => next => action => {
var nextResult = next(action);
var {notesToPlay} = store.getState();
if(notesToPlay && notesToPlay.length > 0) {
for(var n of notesToPlay) {
playTonejsNote(n.value, n.length, 0);
}
store.dispatch(playNote());
}
return nextResult;
}
const store = new createStore(projectReducer, applyMiddleware(ipcMiddleware, musicMiddlware));
setTimeCallback(() => store.dispatch(metronomeBeat()), '8n')
var oldEmit = ipcRenderer.emit;
ipcRenderer.emit = (e, s, d) => {
if(e.startsWith('IPC_RESPONSE') && d) {
store.dispatch(d);
}
oldEmit.apply(ipcRenderer, [e, s, d]);
}
ipcRenderer.on(IPC_WRITE_REQUEST, (e, d) => {
const {measures, timeSignature} = store.getState();
d = {...d, measures, timeSignature};
store.dispatch(d);
});
class App extends React.Component {
render () {
return (
<Provider store={store}>
<Router>
<Switch>
<Route exact path="/" component={Landing} />
<Route path="/project" component={Project} />
</Switch>
</Router>
</Provider>
)
}
}
ReactDOM.render(<App/>,document.getElementById('app'))