synthing

a waveform sequencing synth on the web
Log | Files | Refs | Submodules

commit ffeadc2d9b4cee98aa35b6e351240226600f829b
parent 55a3186095cfa3ed10dd6289745f32cb8402b0fa
Author: Massimo Siboldi <mdsiboldi@gmail.com>
Date:   Sun, 11 Mar 2018 22:50:13 -0700

Add editingToneIdx to redux because it was left out for some reason

Diffstat:
Msrc/App/index.js | 27++++++++++++---------------
Msrc/index.js | 9+++++----
Msrc/store.js | 6+++++-
3 files changed, 22 insertions(+), 20 deletions(-)

diff --git a/src/App/index.js b/src/App/index.js @@ -83,11 +83,10 @@ class App extends Component { solo: false, beats: boolArray.update(boolArray.create(4), 0, true) }], - editingToneIdx: 0 } } - editingWaveform = () => this.state.tones[this.state.editingToneIdx].waveform + editingWaveform = () => this.state.tones[this.props.editingToneIdx].waveform activeTones = () => { let hasSolo = false; @@ -132,7 +131,7 @@ class App extends Component { ); } - updateTone = (idx = this.state.editingToneIdx, opts) => { + updateTone = (idx = this.props.editingToneIdx, opts) => { this.setState({ tones: immObjArray.update(this.state.tones, idx, opts) }); @@ -140,16 +139,14 @@ class App extends Component { removeTone = (idx) => { const tones = immObjArray.remove(this.state.tones, idx); - this.setState({ - tones, - editingToneIdx: Math.min( - this.state.editingToneIdx, - tones.length - 1 - ) - }); + this.setState({ tones }); + this.props.setEditingToneIdx(Math.min( + this.props.editingToneIdx, + tones.length - 1 + )); } - changeEditingTone = (i) => this.setState({editingToneIdx: i}) + changeEditingTone = (i) => this.props.set({editingToneIdx: i}) addTone = ( waveform = initialWave.slice(), @@ -197,16 +194,16 @@ class App extends Component { const tones = this.state.tones.map((form, idx) => { return ( <WaveManager - activate={this.changeEditingTone.bind(this, idx)} + activate={this.props.setEditingToneIdx.bind(null, idx)} remove={this.removeTone.bind(this, idx)} duplicate={() => { let pleaseActivate = false; - if (this.state.editingToneIdx === idx) { + if (this.props.editingToneIdx === idx) { pleaseActivate = true; } this.addTone(this.state.tones[idx].waveform.slice(), idx + 1, pleaseActivate); }} - activated={idx === this.state.editingToneIdx} + activated={idx === this.props.editingToneIdx} tone={this.state.tones[idx]} beat={this.props.beat} toggleMute={() => { @@ -250,7 +247,7 @@ class App extends Component { mouseData={this.state.mouseData} waveform={this.editingWaveform()} updateWaveform={(waveform) => { - this.updateTone(this.state.editingToneIdx, {waveform}); + this.updateTone(this.props.editingToneIdx, {waveform}); }} ></WaveEditor> <div class="global-controls"> diff --git a/src/index.js b/src/index.js @@ -7,10 +7,11 @@ import { Provider, connect } from 'preact-redux'; import { store } from './store.js'; const ConnectedApp = connect(state => Object.assign({}, state.global, {adsr: state.adsr}), { - setVolume: (newVal) => ({type: 'SET_GLOBAL_VOLUME', value: newVal}), - setBpm: (newVal) => ({type: 'SET_GLOBAL_BPM', value: newVal}), - setBeat: (newVal) => ({type: 'SET_GLOBAL_BEAT', value: newVal}), - setNumBeats: (newVal) => ({type: 'SET_GLOBAL_NUM_BEATS', value: newVal}), + setVolume: (value) => ({type: 'SET_GLOBAL_VOLUME', value}), + setBpm: (value) => ({type: 'SET_GLOBAL_BPM', value}), + setBeat: (value) => ({type: 'SET_GLOBAL_BEAT', value}), + setNumBeats: (value) => ({type: 'SET_GLOBAL_NUM_BEATS', value}), + setEditingToneIdx: (value) => ({type: 'SET_EDITING_TONE_IDX', value}), startMetro: () => (dispatch, getState) => { const tickMetro = {type: 'TICK_METRO'}; const startMetro = {type: 'START_METRO'}; diff --git a/src/store.js b/src/store.js @@ -8,7 +8,8 @@ const initialState = { bpm: 120, beat: 0, playing: false, - numBeats: 4 + numBeats: 4, + editingToneIdx: 0 }, adsr: { attack: 0.3, @@ -59,6 +60,9 @@ const globalReducer = (state, action) => { updates.playing = false; updates.beat = 0; break; + case 'SET_EDITING_TONE_IDX': + updates.editingToneIdx = action.value; + break; default: break; }