Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor to React and Redux #2

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# http://editorconfig.org

# top-most EditorConfig file
root = true

[*]
charset = utf-8
end_of_line = lf
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
insert_final_newline = true
20 changes: 20 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
# See https://help.github.com/ignore-files/ for more about ignoring files.

# dependencies
/node_modules

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
20 changes: 20 additions & 0 deletions .travis.yml
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# drumpad

[![Build Status](https://travis-ci.org/iagodahlem/drumpad.svg?branch=master)](https://travis-ci.org/iagodahlem/drumpad)

Playing with JavaScript and Web Audio API.

## License
Expand Down
112 changes: 0 additions & 112 deletions index.html

This file was deleted.

25 changes: 21 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,30 @@
"name": "drumpad",
"repository": "https://github.com/iagodahlem/drumpad.git",
"author": "Iago Dahlem Lorensini <iagodahlemlorensini@gmail.com>",
"homepage": "https://iagodahlem.github.io/drumpad",
"license": "MIT",
"scripts": {
"start": "live-server --port=8080 --host=localhost --open=./index.html",
"build": "htmlmin --nojsmin -o index.html index.html"
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"dependencies": {
"axios": "^0.16.2",
"keycode": "^2.1.9",
"prop-types": "^15.5.10",
"react": "^15.6.1",
"react-dom": "^15.6.1",
"react-redux": "^5.0.6",
"react-scripts": "1.0.12",
"redux": "^3.7.2",
"redux-thunk": "^2.2.0"
},
"devDependencies": {
"htmlmin": "0.0.7",
"live-server": "1.1.0"
"enzyme": "^2.9.1",
"nock": "^9.0.21",
"react-test-renderer": "^15.6.2",
"redux-logger": "^3.0.6",
"redux-mock-store": "^1.3.0"
}
}
Binary file added public/favicon.ico
Binary file not shown.
40 changes: 40 additions & 0 deletions public/index.html
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>
15 changes: 15 additions & 0 deletions public/manifest.json
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 added public/samples/clap-808.wav
Binary file not shown.
File renamed without changes.
Binary file added public/samples/clap-crushed.wav
Binary file not shown.
Binary file added public/samples/clap-fat.wav
Binary file not shown.
Binary file added public/samples/clap-slapper.wav
Binary file not shown.
Binary file added public/samples/clap-tape.wav
Binary file not shown.
Binary file added public/samples/cowbell-808.wav
Binary file not shown.
Binary file added public/samples/crash-808.wav
Binary file not shown.
Binary file added public/samples/crash-acoustic.wav
Binary file not shown.
Binary file added public/samples/crash-noise.wav
Binary file not shown.
Binary file added public/samples/crash-tape.wav
Binary file not shown.
Binary file added public/samples/hihat-808.wav
Binary file not shown.
Binary file added public/samples/hihat-acoustic01.wav
Binary file not shown.
File renamed without changes.
Binary file added public/samples/hihat-analog.wav
Binary file not shown.
Binary file added public/samples/hihat-digital.wav
Binary file not shown.
Binary file added public/samples/hihat-dist01.wav
Binary file not shown.
Binary file added public/samples/hihat-dist02.wav
Binary file not shown.
Binary file added public/samples/hihat-electro.wav
Binary file not shown.
Binary file added public/samples/hihat-plain.wav
Binary file not shown.
Binary file added public/samples/hihat-reso.wav
Binary file not shown.
Binary file added public/samples/hihat-ring.wav
Binary file not shown.
File renamed without changes.
Binary file added public/samples/kick-acoustic01.wav
Binary file not shown.
Binary file added public/samples/kick-acoustic02.wav
Binary file not shown.
Binary file added public/samples/kick-big.wav
Binary file not shown.
Binary file added public/samples/kick-classic.wav
Binary file not shown.
Binary file added public/samples/kick-cultivator.wav
Binary file not shown.
Binary file added public/samples/kick-deep.wav
Binary file not shown.
Binary file added public/samples/kick-dry.wav
Binary file not shown.
Binary file added public/samples/kick-electro01.wav
Binary file not shown.
Binary file added public/samples/kick-electro02.wav
Binary file not shown.
Binary file added public/samples/kick-floppy.wav
Binary file not shown.
Binary file added public/samples/kick-gritty.wav
Binary file not shown.
Binary file added public/samples/kick-heavy.wav
Binary file not shown.
Binary file added public/samples/kick-newwave.wav
Binary file not shown.
Binary file added public/samples/kick-oldschool.wav
Binary file not shown.
Binary file added public/samples/kick-plain.wav
Binary file not shown.
Binary file added public/samples/kick-slapback.wav
Binary file not shown.
Binary file added public/samples/kick-softy.wav
Binary file not shown.
Binary file added public/samples/kick-stomp.wav
Binary file not shown.
Binary file added public/samples/kick-tape.wav
Binary file not shown.
Binary file added public/samples/kick-thump.wav
Binary file not shown.
Binary file added public/samples/kick-tight.wav
Binary file not shown.
Binary file added public/samples/kick-tron.wav
Binary file not shown.
File renamed without changes.
Binary file added public/samples/kick-vinyl02.wav
Binary file not shown.
Binary file added public/samples/kick-zapper.wav
Binary file not shown.
Binary file added public/samples/openhat-808.wav
Binary file not shown.
File renamed without changes.
Binary file added public/samples/openhat-analog.wav
Binary file not shown.
Binary file added public/samples/openhat-slick.wav
Binary file not shown.
Binary file added public/samples/openhat-tight.wav
Binary file not shown.
File renamed without changes.
Binary file added public/samples/perc-chirpy.wav
Binary file not shown.
Binary file added public/samples/perc-hollow.wav
Binary file not shown.
Binary file added public/samples/perc-laser.wav
Binary file not shown.
Binary file added public/samples/perc-metal.wav
Binary file not shown.
Binary file added public/samples/perc-nasty.wav
Binary file not shown.
Binary file added public/samples/perc-short.wav
Binary file not shown.
Binary file added public/samples/perc-tambo.wav
Binary file not shown.
Binary file added public/samples/perc-tribal.wav
Binary file not shown.
Binary file added public/samples/perc-weirdo.wav
Binary file not shown.
Binary file added public/samples/ride-acoustic01.wav
Binary file not shown.
File renamed without changes.
Binary file added public/samples/shaker-analog.wav
Binary file not shown.
Binary file added public/samples/shaker-shuffle.wav
Binary file not shown.
Binary file added public/samples/shaker-suckup.wav
Binary file not shown.
File renamed without changes.
Binary file added public/samples/snare-acoustic01.wav
Binary file not shown.
Binary file added public/samples/snare-acoustic02.wav
Binary file not shown.
Binary file added public/samples/snare-analog.wav
Binary file not shown.
Binary file added public/samples/snare-big.wav
Binary file not shown.
Binary file added public/samples/snare-block.wav
Binary file not shown.
Binary file added public/samples/snare-brute.wav
Binary file not shown.
Binary file added public/samples/snare-dist01.wav
Binary file not shown.
Binary file added public/samples/snare-dist02.wav
Binary file not shown.
Binary file added public/samples/snare-dist03.wav
Binary file not shown.
Binary file added public/samples/snare-electro.wav
Binary file not shown.
Binary file added public/samples/snare-lofi01.wav
Binary file not shown.
Binary file added public/samples/snare-lofi02.wav
Binary file not shown.
Binary file added public/samples/snare-modular.wav
Binary file not shown.
Binary file added public/samples/snare-noise.wav
Binary file not shown.
Binary file added public/samples/snare-pinch.wav
Binary file not shown.
Binary file added public/samples/snare-punch.wav
Binary file not shown.
Binary file added public/samples/snare-smasher.wav
Binary file not shown.
Binary file added public/samples/snare-sumo.wav
Binary file not shown.
Binary file added public/samples/snare-tape.wav
Binary file not shown.
Binary file added public/samples/snare-vinyl01.wav
Binary file not shown.
Binary file added public/samples/snare-vinyl02.wav
Binary file not shown.
Binary file added public/samples/tom-808.wav
Binary file not shown.
File renamed without changes.
Binary file added public/samples/tom-acoustic02.wav
Binary file not shown.
Binary file added public/samples/tom-analog.wav
Binary file not shown.
Binary file added public/samples/tom-chiptune.wav
Binary file not shown.
Binary file added public/samples/tom-fm.wav
Binary file not shown.
Binary file added public/samples/tom-lofi.wav
Binary file not shown.
Binary file added public/samples/tom-rototom.wav
Binary file not shown.
Binary file added public/samples/tom-short.wav
Binary file not shown.
71 changes: 71 additions & 0 deletions src/actions/sampleKitActions.js
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,
}
Loading