Add drum machine certification project
This commit is contained in:
parent
23a1b9c077
commit
bbbe8c0ff4
12 changed files with 29156 additions and 0 deletions
23
3-frontend-dev-libraries/3-drum-machine/.gitignore
vendored
Normal file
23
3-frontend-dev-libraries/3-drum-machine/.gitignore
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
/.pnp
|
||||
.pnp.js
|
||||
|
||||
# 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*
|
70
3-frontend-dev-libraries/3-drum-machine/README.md
Normal file
70
3-frontend-dev-libraries/3-drum-machine/README.md
Normal file
|
@ -0,0 +1,70 @@
|
|||
# Getting Started with Create React App
|
||||
|
||||
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
|
||||
|
||||
## Available Scripts
|
||||
|
||||
In the project directory, you can run:
|
||||
|
||||
### `npm start`
|
||||
|
||||
Runs the app in the development mode.\
|
||||
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
|
||||
|
||||
The page will reload when you make changes.\
|
||||
You may also see any lint errors in the console.
|
||||
|
||||
### `npm test`
|
||||
|
||||
Launches the test runner in the interactive watch mode.\
|
||||
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
|
||||
|
||||
### `npm run build`
|
||||
|
||||
Builds the app for production to the `build` folder.\
|
||||
It correctly bundles React in production mode and optimizes the build for the best performance.
|
||||
|
||||
The build is minified and the filenames include the hashes.\
|
||||
Your app is ready to be deployed!
|
||||
|
||||
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
|
||||
|
||||
### `npm run eject`
|
||||
|
||||
**Note: this is a one-way operation. Once you `eject`, you can't go back!**
|
||||
|
||||
If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
|
||||
|
||||
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.
|
||||
|
||||
You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.
|
||||
|
||||
## Learn More
|
||||
|
||||
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
|
||||
|
||||
To learn React, check out the [React documentation](https://reactjs.org/).
|
||||
|
||||
### Code Splitting
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
|
||||
|
||||
### Analyzing the Bundle Size
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
|
||||
|
||||
### Making a Progressive Web App
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
|
||||
|
||||
### Advanced Configuration
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
|
||||
|
||||
### Deployment
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
|
||||
|
||||
### `npm run build` fails to minify
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
|
28718
3-frontend-dev-libraries/3-drum-machine/package-lock.json
generated
Normal file
28718
3-frontend-dev-libraries/3-drum-machine/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
38
3-frontend-dev-libraries/3-drum-machine/package.json
Normal file
38
3-frontend-dev-libraries/3-drum-machine/package.json
Normal file
|
@ -0,0 +1,38 @@
|
|||
{
|
||||
"name": "3-drum-machine",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"homepage": "https://cherrykitten.github.io/freecodecamp-projects/3-frontend-dev-libraries/3-drum-machine/",
|
||||
"dependencies": {
|
||||
"@testing-library/jest-dom": "^5.16.5",
|
||||
"@testing-library/react": "^13.4.0",
|
||||
"@testing-library/user-event": "^13.5.0",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"react-scripts": "5.0.1"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "react-scripts start",
|
||||
"build": "react-scripts build",
|
||||
"test": "react-scripts test",
|
||||
"eject": "react-scripts eject"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": [
|
||||
"react-app",
|
||||
"react-app/jest"
|
||||
]
|
||||
},
|
||||
"browserslist": {
|
||||
"production": [
|
||||
">0.2%",
|
||||
"not dead",
|
||||
"not op_mini all"
|
||||
],
|
||||
"development": [
|
||||
"last 1 chrome version",
|
||||
"last 1 firefox version",
|
||||
"last 1 safari version"
|
||||
]
|
||||
}
|
||||
}
|
28
3-frontend-dev-libraries/3-drum-machine/public/index.html
Normal file
28
3-frontend-dev-libraries/3-drum-machine/public/index.html
Normal file
|
@ -0,0 +1,28 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="theme-color" content="#000000" />
|
||||
<meta
|
||||
name="description"
|
||||
content="Drum machine build for FreeCodeCamp"
|
||||
/>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.0/css/all.min.css" integrity="sha512-xh6O/CkQoPOWDdYTDqeRdPCVd1SpvCA9XXcUnZS2FmJNp1coAFzvtCN9BmamE+4aHK8yyUHUSCcJHgXloTyT2A==" crossorigin="anonymous" referrerpolicy="no-referrer" />
|
||||
<title>Drum Machine</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>
|
70
3-frontend-dev-libraries/3-drum-machine/src/App.css
Normal file
70
3-frontend-dev-libraries/3-drum-machine/src/App.css
Normal file
|
@ -0,0 +1,70 @@
|
|||
.App {
|
||||
background-color: #8db48e;
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
font-family: "Arial";
|
||||
font-weight: bold;
|
||||
}
|
||||
.App #drum-machine {
|
||||
background-color: #757070;
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 0.5fr;
|
||||
width: 920px;
|
||||
height: 480px;
|
||||
border-radius: 40px;
|
||||
border: 10px solid #4d724d;
|
||||
}
|
||||
.App #drum-machine #drumPads {
|
||||
grid-area: 1/1/2/2;
|
||||
display: grid;
|
||||
padding: 20px;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
grid-template-rows: repeat(3, 1fr);
|
||||
grid-column-gap: 20px;
|
||||
grid-row-gap: 20px;
|
||||
}
|
||||
.App #drum-machine #drumPads .drum-pad {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: #4d724d;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
cursor: pointer;
|
||||
background-image: linear-gradient(144deg, #AF40FF, #5B42F3 50%, #00DDEB);
|
||||
border: 0;
|
||||
border-radius: 40px;
|
||||
box-shadow: rgba(151, 65, 252, 0.2) 0 15px 30px -5px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.App #drum-machine #controls {
|
||||
grid-area: 1/2/2/3;
|
||||
display: grid;
|
||||
grid-template-rows: repeat(3, 1fr);
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
height: 100%;
|
||||
}
|
||||
.App #drum-machine #controls #display {
|
||||
background-color: #4d724d;
|
||||
display: flex;
|
||||
height: 75%;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
grid-area: 2/2/2/2;
|
||||
background-image: linear-gradient(144deg, #AF40FF, #5B42F3 50%, #00DDEB);
|
||||
border: 0;
|
||||
border-radius: 40px;
|
||||
box-shadow: rgba(151, 65, 252, 0.2) 0 15px 30px -5px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
@media screen and (max-width: 650px) {
|
||||
.app {
|
||||
transform: scale(0.5);
|
||||
}
|
||||
}
|
||||
|
||||
/*# sourceMappingURL=App.css.map */
|
1
3-frontend-dev-libraries/3-drum-machine/src/App.css.map
Normal file
1
3-frontend-dev-libraries/3-drum-machine/src/App.css.map
Normal file
|
@ -0,0 +1 @@
|
|||
{"version":3,"sourceRoot":"","sources":["App.scss"],"names":[],"mappings":"AAIA;EACE,kBALO;EAMP;EACA;EACA;EACA;EACA;EACA;EACA;;AAEA;EACE,kBAdK;EAeL;EACA;EACA;EACA;EACA;EAEA;;AAEA;EACE;EACA;EACA;EACA;EACA;EACA;EACA;;AAEA;EACE;EACA;EACA,kBAlCC;EAmCD;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;AAIJ;EACE;EACA;EACA;EACA;EACA;;AAEA;EACE,kBAvDC;EAwDD;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;AAMR;EACE;IACE","file":"App.css"}
|
48
3-frontend-dev-libraries/3-drum-machine/src/App.js
Normal file
48
3-frontend-dev-libraries/3-drum-machine/src/App.js
Normal file
|
@ -0,0 +1,48 @@
|
|||
import './App.css';
|
||||
import React from 'react';
|
||||
import {DrumPad, drumPads} from "./Components";
|
||||
|
||||
class App extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
volume: '50%',
|
||||
currentSound: '',
|
||||
}
|
||||
this.updateDisplay = this.updateDisplay.bind(this)
|
||||
}
|
||||
updateDisplay(soundID) {
|
||||
this.setState({
|
||||
currentSound: soundID,
|
||||
})
|
||||
|
||||
}
|
||||
render() {
|
||||
return (
|
||||
<div className="App">
|
||||
<div id={'drum-machine'}>
|
||||
<div id="drumPads">
|
||||
{drumPads.map((drumPad, i, arr) => (
|
||||
<DrumPad
|
||||
padKey={arr[i].key}
|
||||
soundID={arr[i].soundID}
|
||||
url={arr[i].url}
|
||||
updateDisplay={this.updateDisplay}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
<div>
|
||||
<div id={'controls'}>
|
||||
<div id={'display'}>
|
||||
{this.state.currentSound}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default App;
|
||||
|
78
3-frontend-dev-libraries/3-drum-machine/src/App.scss
Normal file
78
3-frontend-dev-libraries/3-drum-machine/src/App.scss
Normal file
|
@ -0,0 +1,78 @@
|
|||
$color1: #8db48e;
|
||||
$color2: #757070;
|
||||
$color3: #4d724d;
|
||||
|
||||
.App {
|
||||
background-color: $color1;
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
font-family: "Arial";
|
||||
font-weight: bold;
|
||||
|
||||
#drum-machine{
|
||||
background-color: $color2;
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 0.5fr;
|
||||
width: 920px;
|
||||
height: 480px;
|
||||
border-radius: 40px;
|
||||
|
||||
border: 10px solid $color3;
|
||||
|
||||
#drumPads{
|
||||
grid-area: 1 / 1 / 2 / 2;
|
||||
display: grid;
|
||||
padding: 20px;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
grid-template-rows: repeat(3, 1fr);
|
||||
grid-column-gap: 20px;
|
||||
grid-row-gap: 20px;
|
||||
|
||||
.drum-pad{
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: $color3;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
cursor: pointer;
|
||||
background-image: linear-gradient(144deg,#AF40FF, #5B42F3 50%,#00DDEB);
|
||||
border: 0;
|
||||
border-radius: 40px;
|
||||
box-shadow: rgba(151, 65, 252, 0.2) 0 15px 30px -5px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
}
|
||||
|
||||
#controls{
|
||||
grid-area: 1 / 2 / 2 / 3;
|
||||
display: grid;
|
||||
grid-template-rows: repeat(3, 1fr);
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
height: 100%;
|
||||
|
||||
#display{
|
||||
background-color: $color3;
|
||||
display: flex;
|
||||
height: 75%;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
grid-area: 2 / 2 / 2 / 2;
|
||||
background-image: linear-gradient(144deg,#AF40FF, #5B42F3 50%,#00DDEB);
|
||||
border: 0;
|
||||
border-radius: 40px;
|
||||
box-shadow: rgba(151, 65, 252, 0.2) 0 15px 30px -5px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (max-width: 650px) {
|
||||
.app {
|
||||
transform: scale(0.5);
|
||||
}
|
||||
}
|
57
3-frontend-dev-libraries/3-drum-machine/src/Components.js
Normal file
57
3-frontend-dev-libraries/3-drum-machine/src/Components.js
Normal file
|
@ -0,0 +1,57 @@
|
|||
import React from "react";
|
||||
|
||||
export const drumPads = [
|
||||
{key: 'Q', soundID: 'Heater-1', url: 'https://s3.amazonaws.com/freecodecamp/drums/Heater-1.mp3'},
|
||||
{key: 'W', soundID: 'Heater-2', url: 'https://s3.amazonaws.com/freecodecamp/drums/Heater-2.mp3'},
|
||||
{key: 'E', soundID: 'Heater-3', url: 'https://s3.amazonaws.com/freecodecamp/drums/Heater-3.mp3'},
|
||||
{key: 'A', soundID: 'Heater-4', url: 'https://s3.amazonaws.com/freecodecamp/drums/Heater-4_1.mp3'},
|
||||
{key: 'S', soundID: 'Clap', url: 'https://s3.amazonaws.com/freecodecamp/drums/Heater-6.mp3'},
|
||||
{key: 'D', soundID: 'Open-HH', url: 'https://s3.amazonaws.com/freecodecamp/drums/Dsc_Oh.mp3'},
|
||||
{key: 'Z', soundID: 'Kick-n-Hat', url: 'https://s3.amazonaws.com/freecodecamp/drums/Kick_n_Hat.mp3'},
|
||||
{key: 'X', soundID: 'Kick', url: 'https://s3.amazonaws.com/freecodecamp/drums/RP4_KICK_1.mp3'},
|
||||
{key: 'C', soundID: 'Closed-HH', url: 'https://s3.amazonaws.com/freecodecamp/drums/Cev_H2.mp3'},]
|
||||
|
||||
export class DrumPad extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
||||
this.playSound = this.playSound.bind(this);
|
||||
this.handleKeyPress = this.handleKeyPress.bind(this)
|
||||
}
|
||||
componentDidMount() {
|
||||
document.addEventListener('keydown', this.handleKeyPress);
|
||||
}
|
||||
componentWillUnmount() {
|
||||
document.removeEventListener('keydown', this.handleKeyPress);
|
||||
}
|
||||
|
||||
handleKeyPress(event) {
|
||||
if (event.key.toUpperCase() === this.props.padKey) {
|
||||
this.playSound()
|
||||
}
|
||||
}
|
||||
|
||||
playSound() {
|
||||
const sound = document.getElementById(this.props.padKey)
|
||||
sound.currentTime = 0;
|
||||
sound.play();
|
||||
this.props.updateDisplay(this.props.soundID.replace(/-/g, ' '));
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div
|
||||
className={'drum-pad'}
|
||||
id={this.props.soundID}
|
||||
onClick={this.playSound}
|
||||
>
|
||||
<audio
|
||||
src={this.props.url}
|
||||
id={this.props.padKey}
|
||||
className={'clip'}
|
||||
></audio>
|
||||
{this.props.padKey}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
13
3-frontend-dev-libraries/3-drum-machine/src/index.css
Normal file
13
3-frontend-dev-libraries/3-drum-machine/src/index.css
Normal file
|
@ -0,0 +1,13 @@
|
|||
body {
|
||||
margin: 0;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
|
||||
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
|
||||
sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
|
||||
monospace;
|
||||
}
|
12
3-frontend-dev-libraries/3-drum-machine/src/index.js
Normal file
12
3-frontend-dev-libraries/3-drum-machine/src/index.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
import React from 'react';
|
||||
import ReactDOM from 'react-dom/client';
|
||||
import './index.css';
|
||||
import App from './App';
|
||||
|
||||
const root = ReactDOM.createRoot(document.getElementById('root'));
|
||||
root.render(
|
||||
<React.StrictMode>
|
||||
<App/>
|
||||
|
||||
</React.StrictMode>
|
||||
);
|
Reference in a new issue