From 810c77cc85a1f18303f2386f3f4bc0b595d2f474 Mon Sep 17 00:00:00 2001 From: futpib Date: Wed, 21 Nov 2018 02:09:10 +0300 Subject: [PATCH] Mute shortcut modifiers --- components/graph/index.js | 57 ++++++++++++++++++------------------ components/hot-keys/index.js | 8 +++-- 2 files changed, 35 insertions(+), 30 deletions(-) diff --git a/components/graph/index.js b/components/graph/index.js index 7872d6a..e82c544 100644 --- a/components/graph/index.js +++ b/components/graph/index.js @@ -820,10 +820,14 @@ class Graph extends React.Component { this._requestedIcons.add(icon); } - onBackgroundMouseDown() { - this.setState({ - contexted: backgroundSymbol, - }); + onBackgroundMouseDown(event) { + if (event.button === 1) { + this.toggleAllMute(this.props.infos.sinks); + } else if (event.button === 2) { + this.setState({ + contexted: backgroundSymbol, + }); + } } onSelectNode(selected) { @@ -920,7 +924,7 @@ class Graph extends React.Component { pais.forEach(pai => this.toggleMute(pai, !allMuted)); } - toggleMute(pai, muted = !pai.muted, shift = false) { + toggleMute(pai, muted = !pai.muted, sourceBiased = false) { if (pai.muted === muted) { return; } @@ -930,7 +934,7 @@ class Graph extends React.Component { } else if (pai.type === 'sourceOutput') { this.props.setSourceOutputMuteByIndex(pai.index, muted); } else if (pai.type === 'sink') { - if (shift) { + if (sourceBiased) { const sinkInputs = getSinkSinkInputs(pai)({ pulse: this.props }); this.toggleAllMute(sinkInputs); } else { @@ -939,7 +943,7 @@ class Graph extends React.Component { } else if (pai.type === 'source') { this.props.setSourceMute(pai.index, muted); } else if (pai.type === 'client') { - if (shift) { + if (sourceBiased) { const sourceOutputs = getClientSourceOutputs(pai)({ pulse: this.props }); this.toggleAllMute(sourceOutputs); } else { @@ -947,7 +951,7 @@ class Graph extends React.Component { this.toggleAllMute(sinkInputs); } } else if (pai.type === 'module') { - if (shift) { + if (sourceBiased) { const sourceOutputs = getModuleSourceOutputs(pai)({ pulse: this.props }); this.toggleAllMute(sourceOutputs); } else { @@ -1046,10 +1050,23 @@ class Graph extends React.Component { }); } - hotKeyMute() { + hotKeyMute({ shiftKey: sourceBiased, ctrlKey: all }) { if (!this.state.selected) { - const defaultSink = getDefaultSinkPai({ pulse: this.props }); - this.toggleMute(defaultSink); + if (sourceBiased) { + if (all) { + this.toggleAllMute(this.props.infos.sources); + } else { + const defaultSource = getDefaultSourcePai({ pulse: this.props }); + this.toggleMute(defaultSource); + } + } else { + if (all) { // eslint-disable-line no-lonely-if + this.toggleAllMute(this.props.infos.sinks); + } else { + const defaultSink = getDefaultSinkPai({ pulse: this.props }); + this.toggleMute(defaultSink); + } + } return; } @@ -1059,23 +1076,7 @@ class Graph extends React.Component { return; } - this.toggleMute(pai); - } - - hotKeyShiftMute() { - if (!this.state.selected) { - const defaultSource = getDefaultSourcePai({ pulse: this.props }); - this.toggleMute(defaultSource); - return; - } - - const pai = dgoToPai.get(this.state.selected); - - if (!pai) { - return; - } - - this.toggleMute(pai, undefined, true); + this.toggleMute(pai, undefined, sourceBiased); } _hotKeyVolume(direction) { diff --git a/components/hot-keys/index.js b/components/hot-keys/index.js index a11c23d..0a7686d 100644 --- a/components/hot-keys/index.js +++ b/components/hot-keys/index.js @@ -29,8 +29,12 @@ const keyMap = { hotKeyVolumeDown: [ '/', '9' ], hotKeyVolumeUp: [ '*', '0' ], - hotKeyMute: 'space', - hotKeyShiftMute: 'shift+space', + hotKeyMute: [ + 'space', + 'shift+space', + 'ctrl+space', + 'ctrl+shift+space', + ], hotKeySetAsDefault: 'f',