synthing

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

commit 5fb08c2709963dbb3246dc0a76f781ba1f56aed0
parent 87569ec4ff9e35a6e4893e1b8fa78164e529d308
Author: Massimo Siboldi <mdsiboldi@gmail.com>
Date:   Sun, 18 Mar 2018 12:48:06 -0700

Beats stay forever

Diffstat:
Msrc/App/index.js | 2++
Msrc/WaveManager/index.js | 3+--
Msrc/consts.js | 3++-
Msrc/store.js | 40++++++++++++++--------------------------
4 files changed, 19 insertions(+), 29 deletions(-)

diff --git a/src/App/index.js b/src/App/index.js @@ -8,6 +8,7 @@ import Param from '../Param/'; import Wheel from '../Wheel/'; import Help from '../Help/'; import Keybindings from '../Keybindings/'; +import WaveTable from '../WaveTable/'; import './App.css'; import '../iconfont/style.css'; import consts from '../consts.js'; @@ -99,6 +100,7 @@ class App extends Component { activated={idx === this.props.editingToneIdx} tone={this.props.tones[idx]} beat={this.props.beat} + numBeats={this.props.numBeats} toggleMute={() => { this.props.setToneProperty(idx, 'mute', !this.props.tones[idx].mute); }} diff --git a/src/WaveManager/index.js b/src/WaveManager/index.js @@ -57,8 +57,7 @@ export default class WaveManager extends Component { waveform={this.props.tone.waveform.slice()} /> </div> - - {this.props.tone.beats.map((val, idx) => { + {this.props.tone.beats.slice(0, this.props.numBeats).map((val, idx) => { return ( <CheckBox class={this.props.beat === idx ? 'beat' : ''} diff --git a/src/consts.js b/src/consts.js @@ -24,5 +24,6 @@ export default { ], initialWave: new Array(BUF_SIZE) .fill(0) - .map((val, i) => Math.sin(i / BUF_SIZE * Math.PI * 2)) + .map((val, i) => Math.sin(i / BUF_SIZE * Math.PI * 2)), + MAX_BEATS: 16 } diff --git a/src/store.js b/src/store.js @@ -3,13 +3,21 @@ import thunk from 'redux-thunk'; import consts from './consts.js'; import helpers from './helpers.js'; -const numBeats = 4; +const toneShape = { + active: false, + waveform: consts.initialWave, + mix: 0.7, + mute: false, + solo: false, + beats: helpers.boolArray.create(consts.MAX_BEATS) +}; + const initialState = { volume: 0.7, bpm: 120, beat: 0, playing: false, - numBeats, + numBeats: consts.MAX_BEATS, editingToneIdx: 0, helpOpen: false, adsr: { @@ -18,24 +26,12 @@ const initialState = { sustain: 0.4, release: 1 }, - tones: [{ + tones: [Object.assign({}, toneShape, { active: true, - waveform: consts.initialWave.slice(), - mix: 0.7, - mute: false, - solo: false, - beats: helpers.boolArray.update(helpers.boolArray.create(numBeats), 0, true) - }], + beats: helpers.boolArray.update(helpers.boolArray.create(consts.MAX_BEATS), 0, true) + })], }; -const newTone = { - active: false, - waveform: consts.initialWave.slice(), - mix: 0.7, - mute: false, - solo: false, - beats: helpers.boolArray.create(numBeats) -}; const adsrReducer = (state, action) => { const updates = {}; @@ -69,7 +65,7 @@ const tonesReducer = (state = [], action) => { return helpers.immObjArray.add( state, idx, - Object.assign({}, newTone, newToneProps) + Object.assign({}, toneShape, newToneProps) ); case 'SET_TONE_PROPERTY': // idx: required @@ -85,14 +81,6 @@ const tonesReducer = (state = [], action) => { case 'DELETE_TONE': // idx: required return helpers.immObjArray.remove(state, action.idx); - case 'SET_GLOBAL_NUM_BEATS': - // TODO save beats and just change the view, instead of deleting them - return state.map((val, idx) => { - let ret = Object.assign({}, val, { - beats: helpers.boolArray.setLength(val.beats, action.value) - }); - return ret; - }); default: return state; }