drum-machine | A simple Drum Machine with Create-react-app | Frontend Framework library
kandi X-RAY | drum-machine Summary
kandi X-RAY | drum-machine Summary
A simple Drum Machine with Create-react-app.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of drum-machine
drum-machine Key Features
drum-machine Examples and Code Snippets
Community Discussions
Trending Discussions on drum-machine
QUESTION
I created a React app based on Free Code Camp's Drum Machine project which works successfully on Code Pen and passes all tests found here https://codepen.io/kevin-orara/pen/RwKvjJz however when I transfer the code to Visual Studio it now fails 1 test. Yes the app appears to work and even compiled successfully. Now it is failing one test which is #6
When I press the trigger key associated with each .drum-pad, the audio clip contained in its child element should be triggered (e.g. pressing the Q key should trigger the drum pad which contains the string "Q", pressing the W key should trigger the drum pad which contains the string "W", etc.).
GitHub Repo here: https://github.com/korara78/drum-machine-fcc/tree/main/drum-machine-fcc
There are two things I noticed which seemed odd. First I had to add this code to the index.html file just to get the code to compile successfully. Being new to creating React apps I've only had to add 1 div id on index.html files thus far.
...ANSWER
Answered 2021-Jun-13 at 21:42QUESTION
I am building a drum machine and one of the challenges is to set up keyboard events to the pads displayed.
Please take a look at the code I wrote. There is no event triggered when I smashed the button on my keyboard. Is there anything wrong here? I did a little bit research and I found out that in most cases onKeyPress is bound to
?
...ANSWER
Answered 2021-May-26 at 09:27The issue you are running into here is related to how HTML and Javascript allows and handles input from the user. This is because a button input is not always in a 'focused' state read more here, and hence, Javascript is not receiving input events from the element as the button is not strictly receiving any.
The way to resolve this issue is realistically through CSS. The method most commonly used is using a standard text input field as shown below which is autofocused and maybe as a listener to always re-focus the element incase the user clicks outside of it.
QUESTION
I am trying to make a drum machine that will play a different sound when each button is pressed. I am using CodePen to make the project and I keep getting an object error when I try to use the DrumPad Component. Any help would be greatly appreciated. The relevant code is below.
Here is the link to my CodePen App: https://codepen.io/bbond766/pen/NWdLNog?editors=0010
...ANSWER
Answered 2021-May-21 at 02:43Change Your handleClick
method something like that
QUESTION
I am working on a Drum machine project where I am failing to pass a task. the task is:
When I press the trigger key associated with each .drum-pad, the audio clip contained in its child element should be triggered (e.g. pressing the Q key should trigger the drum pad which contains the string "Q", pressing the W key should trigger the drum pad which contains the string "W", etc.).
My code so far:
...ANSWER
Answered 2020-Dec-15 at 15:32The problem is this : in your handleKeyPress
handler, const audio = event.target.children[0];
does not target the audio
element.
I have used ref
to target the audio once user clicks on any of the keys mentioned in handleKeyPress
. Also whenever we use onKeyDown
synthetic event, we must use tabIndex={0}
. Try the below code :)
QUESTION
So I am doing a drum machine project on Freecodecamp, where I am failing this condition.
" When I click on a .drum-pad element, the audio clip contained in its child element should be triggered. " So how do I trigger child element(in this case the audio element,to play the audio) while clicking or pressing the parent element?
I wrote something like this
...ANSWER
Answered 2020-Dec-09 at 16:57You can get your audio element by searching the DOM and then call .play()
on it.
So your onClick
handler becomes:
QUESTION
I'm a newbie to React and currently building a drum-machine. I have wired up the drum-machine to play an audio contained inside its DrumPad child component.My problem is am failing make an id representing each audio display whenever its parent drum-pad div is clicked. I know I need to initialize state and then setState but I dont know how to implement it in my code.
here is my code
...ANSWER
Answered 2020-Oct-09 at 05:50for updating the state, you need to pass the function handleDisplay to DrumPad and call the handleDisplay inside handleClick, passing the required data as parameters.
QUESTION
I'm building a fcc-drum machine using React I get the following error when trying to map a data object:
Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
Check the render method of
App
.
Below is the data that I am trying to map along with my code:
...ANSWER
Answered 2020-Oct-06 at 03:22I would recommend taking a look at this question to find out more details about your error, but nevertheless, I've shared a working example below using functional components and fixing the missing key error mentioned by @DaniilLoban. The working example will print out the value of the letter
and id
keys from each object in your soundData array.
App.js
QUESTION
I am trying to play the audio onClick in react, however I got the error, I did check the ref, it is the audio element, I don't know what's wrong, any help will be much appreciated.
...ANSWER
Answered 2020-Sep-21 at 14:03current
is a property of your ref. You need to do
QUESTION
I created a Drum Machine with ReactJS, and I can't find a way to make the buttons look like clicked when I press the corresponding key. I found the following question on the site, but I can't make refs work with my code and I don't know why:
Apply button 'Active' styles on keypress in React
I also read that string refs are not advised against now, sow I really don't know how to approach this.
Here is the link to my app: https://codesandbox.io/s/github/AldanaBRZ/drum-machine
...ANSWER
Answered 2020-Jun-03 at 21:24While string refs are discouraged. You can still use refs by using React.createRef
ref: https://reactjs.org/docs/refs-and-the-dom.html
You don't have to use refs even, you can give them all unique ids since they are unique anyways, and then whenever a key is pressed, you can check do a if q is pressed, add pressed class to the q button
Adding and removing classes on an HTML element in JS can be achieved by the following:
You can use element.classList.add("pressed")
to achieve that. and element.classList.remove("pressed")
ref: https://developer.mozilla.org/en-US/docs/Web/API/Element/classList
QUESTION
On the Drum Machine challenge: https://www.freecodecamp.org/learn/front-end-libraries/front-end-libraries-projects/build-a-drum-machine
I have got the cdn script from FCC saying that all tests have passed, but when I try and press keys to run the function calling the audio clip to played, nothing happens - am I missing something here?
Keys Components
...ANSWER
Answered 2020-May-23 at 19:57You need to tell the browser to listen to an onKeydown event after the page has rendered, using the componentDidMount()
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install drum-machine
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page