From 6659fc9e96e6a1d7c74d1aa84afbac8bd10d33be Mon Sep 17 00:00:00 2001 From: futpib Date: Sat, 17 Nov 2018 15:35:02 +0300 Subject: [PATCH] Add shift mute hotkey --- components/graph/index.js | 47 +++++++++++++++++++++++++++++++----- components/hot-keys/index.js | 1 + selectors/index.js | 21 ++++++++++++++++ 3 files changed, 63 insertions(+), 6 deletions(-) diff --git a/components/graph/index.js b/components/graph/index.js index e20ff84..6c83e59 100644 --- a/components/graph/index.js +++ b/components/graph/index.js @@ -44,8 +44,14 @@ const { const { getPaiByTypeAndIndex, getDerivedMonitorSources, + getClientSinkInputs, getModuleSinkInputs, + + getClientSourceOutputs, + getModuleSourceOutputs, + + getSinkSinkInputs, } = require('../../selectors'); const { @@ -732,7 +738,7 @@ class Graph extends React.Component { pais.forEach(pai => this.toggleMute(pai, !allMuted)); } - toggleMute(pai, muted = !pai.muted) { + toggleMute(pai, muted = !pai.muted, shift = false) { if (pai.muted === muted) { return; } @@ -742,15 +748,30 @@ class Graph extends React.Component { } else if (pai.type === 'sourceOutput') { this.props.setSourceOutputMuteByIndex(pai.index, muted); } else if (pai.type === 'sink') { - this.props.setSinkMute(pai.index, muted); + if (shift) { + const sinkInputs = getSinkSinkInputs(pai)({ pulse: this.props }); + this.toggleAllMute(sinkInputs); + } else { + this.props.setSinkMute(pai.index, muted); + } } else if (pai.type === 'source') { this.props.setSourceMute(pai.index, muted); } else if (pai.type === 'client') { - const sinkInputs = getClientSinkInputs(pai)({ pulse: this.props }); - this.toggleAllMute(sinkInputs); + if (shift) { + const sourceOutputs = getClientSourceOutputs(pai)({ pulse: this.props }); + this.toggleAllMute(sourceOutputs); + } else { + 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); + if (shift) { + const sourceOutputs = getModuleSourceOutputs(pai)({ pulse: this.props }); + this.toggleAllMute(sourceOutputs); + } else { + const sinkInputs = getModuleSinkInputs(pai)({ pulse: this.props }); + this.toggleAllMute(sinkInputs); + } } } @@ -776,6 +797,20 @@ class Graph extends React.Component { this.toggleMute(pai); } + hotKeyShiftMute() { + if (!this.state.selected) { + return; + } + + const pai = dgoToPai.get(this.state.selected); + + if (!pai) { + return; + } + + this.toggleMute(pai, undefined, true); + } + _hotKeyVolume(direction) { if (!this.state.selected) { return; diff --git a/components/hot-keys/index.js b/components/hot-keys/index.js index 4bd0b64..303860f 100644 --- a/components/hot-keys/index.js +++ b/components/hot-keys/index.js @@ -28,6 +28,7 @@ const keyMap = { hotKeyVolumeUp: [ '*', '0' ], hotKeyMute: 'm', + hotKeyShiftMute: 'M', }; class MyHotKeys extends React.Component { diff --git a/selectors/index.js b/selectors/index.js index b8b4b4a..622de62 100644 --- a/selectors/index.js +++ b/selectors/index.js @@ -26,6 +26,21 @@ const getModuleSinkInputs = module => state => pickBy( state.pulse.infos.sinkInputs, ); +const getClientSourceOutputs = client => state => pickBy( + so => so.clientIndex === client.index, + state.pulse.infos.sourceOutputs, +); + +const getModuleSourceOutputs = module => state => pickBy( + so => so.moduleIndex === module.index, + state.pulse.infos.sourceOutputs, +); + +const getSinkSinkInputs = sink => state => pickBy( + si => si.sinkIndex === sink.index, + state.pulse.infos.sinkInputs, +); + const getDerivedMonitorSources = createSelector( state => state.pulse.infos.sources, sources => map(source => ({ @@ -39,6 +54,12 @@ const getDerivedMonitorSources = createSelector( module.exports = { getPaiByTypeAndIndex, getDerivedMonitorSources, + getClientSinkInputs, getModuleSinkInputs, + + getClientSourceOutputs, + getModuleSourceOutputs, + + getSinkSinkInputs, };