-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add react and redux, with audio context
- Loading branch information
1 parent
e2f222b
commit 562fdcf
Showing
140 changed files
with
976 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
language: node_js | ||
node_js: | ||
- 8 | ||
|
||
cache: | ||
yarn: true | ||
directories: | ||
- node_modules | ||
|
||
script: | ||
- yarn test | ||
- yarn build | ||
|
||
deploy: | ||
provider: pages | ||
skip_cleanup: true | ||
github_token: $GITHUB_TOKEN | ||
local_dir: build | ||
on: | ||
branch: master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | ||
<meta name="theme-color" content="#000000"> | ||
<!-- | ||
manifest.json provides metadata used when your web app is added to the | ||
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/ | ||
--> | ||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json"> | ||
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico"> | ||
<!-- | ||
Notice the use of %PUBLIC_URL% in the tags above. | ||
It will be replaced with the URL of the `public` folder during the build. | ||
Only files inside the `public` folder can be referenced from the HTML. | ||
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will | ||
work correctly both with client-side routing and a non-root public URL. | ||
Learn how to configure a non-root public URL by running `npm run build`. | ||
--> | ||
<title>Drumpad</title> | ||
</head> | ||
<body> | ||
<noscript> | ||
You need to enable JavaScript to run this app. | ||
</noscript> | ||
<div id="root"></div> | ||
<!-- | ||
This HTML file is a template. | ||
If you open it directly in the browser, you will see an empty page. | ||
You can add webfonts, meta tags, or analytics to this file. | ||
The build step will place the bundled scripts into the <body> tag. | ||
To begin the development, run `npm start` or `yarn start`. | ||
To create a production bundle, use `npm run build` or `yarn build`. | ||
--> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"short_name": "Drumpad", | ||
"name": "Drumpad", | ||
"icons": [ | ||
{ | ||
"src": "favicon.ico", | ||
"sizes": "192x192", | ||
"type": "image/png" | ||
} | ||
], | ||
"start_url": "./index.html", | ||
"display": "standalone", | ||
"theme_color": "#000000", | ||
"background_color": "#ffffff" | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import audioBufferService from '../services/audioBufferService' | ||
import * as fromAudioContext from '../reducers/audioContextReducer' | ||
import * as fromSamples from '../reducers/samplesReducer' | ||
import * as types from '../constants/actionTypes' | ||
|
||
const fetchSampleKit = () => (dispatch, getState) => { | ||
const fetchSampleKitRequest = () => ({ | ||
type: types.FETCH_SAMPLE_KIT_REQUEST, | ||
}) | ||
|
||
const fetchSampleKitSuccess = (payload) => ({ | ||
type: types.FETCH_SAMPLE_KIT_SUCCESS, | ||
payload, | ||
}) | ||
|
||
const fetchSampleKitFailure = (error) => ({ | ||
type: types.FETCH_SAMPLE_KIT_FAILURE, | ||
message: error.message || 'Something went wrong.', | ||
}) | ||
|
||
const context = fromAudioContext.getAudioContext(getState()) | ||
const defaultSampleKit = fromSamples.getAll(getState()) | ||
|
||
dispatch(fetchSampleKitRequest()) | ||
|
||
const sampleKit = defaultSampleKit | ||
.map(sample => { | ||
return audioBufferService | ||
.load(context, sample.url) | ||
.then(buffer => ({ | ||
...sample, | ||
buffer, | ||
start: audioBufferService.findStartGapDuration(buffer), | ||
})) | ||
}) | ||
|
||
return Promise.all(sampleKit) | ||
.then(payload => dispatch(fetchSampleKitSuccess(payload))) | ||
.catch(error => dispatch(fetchSampleKitFailure(error))) | ||
} | ||
|
||
const playSample = (id) => (dispatch, getState) => { | ||
const playSampleStart = (id) => ({ | ||
type: types.PLAY_SAMPLE_START, | ||
id, | ||
}) | ||
|
||
const playSampleStop = (id) => ({ | ||
type: types.PLAY_SAMPLE_STOP, | ||
id, | ||
}) | ||
|
||
const context = fromAudioContext.getAudioContext(getState()) | ||
const sample = fromSamples.getSample(getState(), id) | ||
|
||
dispatch(playSampleStart(id)) | ||
|
||
return audioBufferService.play(context, sample, () => { | ||
dispatch(playSampleStop(id)) | ||
}) | ||
} | ||
|
||
export default { | ||
fetchSampleKit, | ||
playSample, | ||
} | ||
|
||
export { | ||
fetchSampleKit, | ||
playSample, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import axios from 'axios' | ||
import httpAdapter from 'axios/lib/adapters/http' | ||
import nock from 'nock' | ||
import configureMockStore from 'redux-mock-store' | ||
import thunk from 'redux-thunk' | ||
import * as sampleKitActions from './sampleKitActions' | ||
import * as types from '../constants/actionTypes' | ||
import audioBufferService from '../services/audioBufferService' | ||
|
||
const host = 'http://localhost' | ||
|
||
const middlewares = [thunk] | ||
const mockStore = configureMockStore(middlewares) | ||
|
||
const sample = { id: 'sample', name: 'sample', url: '/sample-url', start: 0 } | ||
const state = { | ||
allIds: ['sample'], | ||
byId: { sample }, | ||
} | ||
|
||
const audioBuffer = { | ||
duration: 0.48036281179138324, | ||
length: 21184, | ||
numberOfChannels: 1, | ||
sampleRate: 44100, | ||
} | ||
|
||
// TODO: set this in a jest global setup | ||
axios.defaults.host = host | ||
axios.defaults.adapter = httpAdapter | ||
|
||
describe('sampleKitActions', () => { | ||
beforeEach(() => { | ||
audioBufferService.findStartGapDuration = jest.fn() | ||
.mockReturnValue(0) | ||
}) | ||
|
||
afterEach(nock.cleanAll) | ||
|
||
describe('fetchSamples', () => { | ||
it('success', async () => { | ||
audioBufferService.load = jest.fn() | ||
.mockReturnValue(Promise.resolve(audioBuffer)) | ||
|
||
nock(host) | ||
.get('/sample-url') | ||
.reply(200, { buffer: [] }) | ||
|
||
const payload = [{ ...sample, buffer: audioBuffer }] | ||
const store = mockStore({ samples: state }) | ||
const expectedActions = [ | ||
{ type: types.FETCH_SAMPLE_KIT_REQUEST }, | ||
{ type: types.FETCH_SAMPLE_KIT_SUCCESS, payload }, | ||
] | ||
|
||
await store.dispatch(sampleKitActions.fetchSampleKit()) | ||
|
||
expect(store.getActions()).toEqual(expectedActions) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.App { | ||
height: 100%; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React from 'react' | ||
import './App.css' | ||
|
||
import Drumpad from '../../containers/Drumpad' | ||
|
||
const App = () => ( | ||
<div className='App'> | ||
<Drumpad /> | ||
</div> | ||
) | ||
|
||
export default App |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import React from 'react' | ||
import { shallow } from 'enzyme' | ||
|
||
import App from './App' | ||
|
||
describe('App', () => { | ||
let component | ||
let props | ||
|
||
beforeEach(() => { | ||
props = {} | ||
component = shallow(<App {...props} />) | ||
}) | ||
|
||
it('renders', () => { | ||
// expect(component).toMatchSnapshot() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import App from './App' | ||
|
||
export default App |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
.Key { | ||
width: calc(33.3% - 6px); | ||
height: calc(33.3% - 6px); | ||
margin: 3px; | ||
border-radius: 5px; | ||
background-color: rgba(255,255,255,.5); | ||
transition: background-color .2s ease; | ||
} | ||
|
||
.Key::after { | ||
content: ''; | ||
display: block; | ||
width: 100%; | ||
height: 100%; | ||
background-image: radial-gradient(rgba(243,243,243,.8) 0%, transparent 100%); | ||
} | ||
|
||
.Key.isPlaying { | ||
background-color: #ff0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import './Key.css' | ||
|
||
const toggleClass = (isPlaying) => isPlaying ? 'Key isPlaying' : 'Key' | ||
|
||
const Key = ({ isPlaying, letter, sample, onClick }) => ( | ||
<div className={toggleClass(isPlaying)} onClick={(e) => onClick(e, sample)}> | ||
</div> | ||
) | ||
|
||
Key.propTypes = { | ||
sample: PropTypes.string.isRequired, | ||
onClick: PropTypes.func.isRequired, | ||
} | ||
|
||
export default Key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React from 'react' | ||
import { shallow } from 'enzyme' | ||
|
||
import Key from './Key' | ||
|
||
describe('Key', () => { | ||
let component, props | ||
|
||
beforeEach(() => { | ||
props = {} | ||
component = shallow(<Key {...props} />) | ||
}) | ||
|
||
it('should', () => { | ||
// expect(component).toMatchSnapshot() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Key from './Key.js' | ||
|
||
export default Key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import App from './App' | ||
import Key from './Key' | ||
|
||
export default { | ||
App, | ||
Key, | ||
} | ||
|
||
export { | ||
App, | ||
Key, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export const FETCH_SAMPLE_KIT_REQUEST = 'FETCH_SAMPLE_KIT_REQUEST' | ||
export const FETCH_SAMPLE_KIT_SUCCESS = 'FETCH_SAMPLE_KIT_SUCCESS' | ||
export const FETCH_SAMPLE_KIT_FAILURE = 'FETCH_SAMPLE_KIT_FAILURE' | ||
|
||
export const FETCH_SAMPLE_REQUEST = 'FETCH_SAMPLE_REQUEST' | ||
export const FETCH_SAMPLE_SUCCESS = 'FETCH_SAMPLE_SUCCESS' | ||
export const FETCH_SAMPLE_FAILURE = 'FETCH_SAMPLE_FAILURE' | ||
|
||
export const PLAY_SAMPLE_START = 'PLAY_SAMPLE_START' | ||
export const PLAY_SAMPLE_STOP = 'PLAY_SAMPLE_STOP' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const byId = (kit) => kit | ||
.reduce((samples, sample) => { | ||
samples[sample.id] = sample | ||
return samples | ||
},{}) | ||
|
||
const allIds = (kit) => kit.map(sample => sample.id) | ||
|
||
const defaultSampleKit = (kit) => ({ | ||
byId: byId(kit), | ||
allIds: allIds(kit), | ||
}) | ||
|
||
export default defaultSampleKit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const keys = [ | ||
{ letter: 't', sample: 'clap-808' }, | ||
{ letter: 'y', sample: 'cowbell-808' }, | ||
{ letter: 'u', sample: 'crash-808' }, | ||
{ letter: 'g', sample: 'hihat-808' }, | ||
{ letter: 'h', sample: 'kick-808' }, | ||
{ letter: 'j', sample: 'openhat-808' }, | ||
{ letter: 'b', sample: 'perc-808' }, | ||
{ letter: 'n', sample: 'snare-808' }, | ||
{ letter: 'm', sample: 'tom-808' }, | ||
] | ||
|
||
export default keys |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const kit808 = [ | ||
{ id: 'clap-808', name: 'Clap 808', url: '/clap-808.wav', kit: '808' }, | ||
{ id: 'cowbell-808', name: 'Cowbell 808', url: '/cowbell-808.wav', kit: '808' }, | ||
{ id: 'crash-808', name: 'Crash 808', url: '/crash-808.wav', kit: '808' }, | ||
{ id: 'hihat-808', name: 'Hihat 808', url: '/hihat-808.wav', kit: '808' }, | ||
{ id: 'kick-808', name: 'Kick 808', url: '/kick-808.wav', kit: '808' }, | ||
{ id: 'openhat-808', name: 'Openhat 808', url: '/openhat-808.wav', kit: '808' }, | ||
{ id: 'perc-808', name: 'Perc 808', url: '/perc-808.wav', kit: '808' }, | ||
{ id: 'snare-808', name: 'Snare 808', url: '/snare-808.wav', kit: '808' }, | ||
{ id: 'tom-808', name: 'Tom 808', url: '/tom-808.wav', kit: '808' }, | ||
] | ||
|
||
export default kit808 |
Oops, something went wrong.