From c415c76f92c338bb32c17c2b8883040f4e5ad551 Mon Sep 17 00:00:00 2001 From: futpib Date: Fri, 16 Nov 2018 20:50:52 +0300 Subject: [PATCH] Mute all client/module outputs --- components/graph/index.js | 48 ++++++++++++++++++++++++++++++++------- selectors/index.js | 13 +++++++++++ store/index.js | 2 +- 3 files changed, 54 insertions(+), 9 deletions(-) diff --git a/components/graph/index.js b/components/graph/index.js index 61619e0..d47788b 100644 --- a/components/graph/index.js +++ b/components/graph/index.js @@ -9,6 +9,8 @@ const { merge, repeat, defaultTo, + prop, + all, } = require('ramda'); const React = require('react'); @@ -29,6 +31,8 @@ const { const { getPaiByTypeAndIndex, getDerivedMonitorSources, + getClientSinkInputs, + getModuleSinkInputs, } = require('../../selectors'); const { @@ -545,10 +549,16 @@ class Graph extends React.Component { onNodeMouseDown(event, data) { const pai = dgoToPai.get(data); if (pai && event.button === 1) { - if (pai.type === 'sink') { - this.props.setSinkMute(pai.index, !pai.muted); - } else if (pai.type === 'source') { - this.props.setSourceMute(pai.index, !pai.muted); + if (pai.type === 'sink' || + pai.type === 'source' + ) { + this.toggleMute(pai); + } else if (pai.type === 'client') { + const sinkInputs = getClientSinkInputs(pai)({ pulse: this.props }); + this.toggleAllMute(sinkInputs); + } else if (pai.type === 'module') { + const sinkInputs = getModuleSinkInputs(pai)({ pulse: this.props }); + this.toggleAllMute(sinkInputs); } } } @@ -579,14 +589,36 @@ class Graph extends React.Component { onEdgeMouseDown(event, data) { const pai = dgoToPai.get(data); if (pai && event.button === 1) { - if (pai.type === 'sinkInput') { - this.props.setSinkInputMuteByIndex(pai.index, !pai.muted); - } else if (pai.type === 'sourceOutput') { - this.props.setSourceOutputMuteByIndex(pai.index, !pai.muted); + if (pai.type === 'sinkInput' || + pai.type === 'sourceOutput' + ) { + this.toggleMute(pai); } } } + toggleAllMute(pais) { + pais = values(pais); + const allMuted = all(prop('muted'), pais); + pais.forEach(pai => this.toggleMute(pai, !allMuted)); + } + + toggleMute(pai, muted = !pai.muted) { + if (pai.muted === muted) { + return; + } + + if (pai.type === 'sinkInput') { + this.props.setSinkInputMuteByIndex(pai.index, muted); + } else if (pai.type === 'sourceOutput') { + this.props.setSourceOutputMuteByIndex(pai.index, muted); + } else if (pai.type === 'sink') { + this.props.setSinkMute(pai.index, muted); + } else if (pai.type === 'source') { + this.props.setSourceMute(pai.index, muted); + } + } + render() { let edges = map(paoToEdge, flatten(map(values, [ this.props.objects.sinkInputs, diff --git a/selectors/index.js b/selectors/index.js index d75e761..b8b4b4a 100644 --- a/selectors/index.js +++ b/selectors/index.js @@ -5,6 +5,7 @@ const { path, filter, indexBy, + pickBy, } = require('ramda'); const { createSelector } = require('reselect'); @@ -15,6 +16,16 @@ const storeKeyByType = map(prop('key'), indexBy(prop('type'), things)); const getPaiByTypeAndIndex = (type, index) => state => path([ storeKeyByType[type], index ], state.pulse.infos); +const getClientSinkInputs = client => state => pickBy( + si => si.clientIndex === client.index, + state.pulse.infos.sinkInputs, +); + +const getModuleSinkInputs = module => state => pickBy( + si => si.moduleIndex === module.index, + state.pulse.infos.sinkInputs, +); + const getDerivedMonitorSources = createSelector( state => state.pulse.infos.sources, sources => map(source => ({ @@ -28,4 +39,6 @@ const getDerivedMonitorSources = createSelector( module.exports = { getPaiByTypeAndIndex, getDerivedMonitorSources, + getClientSinkInputs, + getModuleSinkInputs, }; diff --git a/store/index.js b/store/index.js index 71ba6b8..9fcf26d 100644 --- a/store/index.js +++ b/store/index.js @@ -37,7 +37,7 @@ module.exports = (state = initialState) => { state, composeWithDevTools({ realtime: dev, - hostname: 'localhost', port: 8000, + // hostname: 'localhost', port: 8000, })(applyMiddleware(...middlewares)), );