Comments (5)
Hi @SeunghunSunmoonLee! Good question. The way I do this is to save the played notes during either onPlayNote or onStopNote (I use onStopNote).
For example,
class App extends React.Component {
state = {
recordedNotes: [],
}
playNote = (midiNumber, prevActiveNotes) => {
// ...whatever you're doing to actually play a sound for midiNumber
}
stopNote = (midiNumber, prevActiveNotes) => {
// ...whatever you're doing to stop playing sound for midiNumber
// react-piano actually gives you the notes that were being played (prevActiveNotes)
// right before stopNote occurs, so you can use this to record notes.
this.setState({
recordedNotes: recordedNotes.concat(prevActiveNotes),
});
}
render() {
<Piano
onPlayNote={this.playNote}
onStopNote={this.stopNote}
{...other props...}
/>
}
There's actually a bit more to this logic needed if you want to record chords correctly. I'm planning to create a comprehensive codesandbox soon that covers what you need to do to record and play back input. Hope this can help you get started though.
from react-piano.
Hi Kevin, thanks for the reply. I came up with saving midiNumber, timing as follow. But this is far from perfect since it misses many input data such as duration of the key, duration of the space between, intensity of the note played, activenotes played at the same time.
record(input) {
this.setState((state, props) => {
return {
recording: [...state.recording, input]
}
})
}
I have following two questions.
- How can I play array of midi numbers with time with web audio api or midi api or sound font player or react-piano?
- Is there a way to record using MediaStreamRecord
Currently my brain is battling with these resources. Helps appreciated!
references:
https://stackoverflow.com/questions/14418530/record-sounds-from-audiocontext-web-audio-api
https://developer.mozilla.org/en-US/docs/Web/API/MediaStream_Recording_API/Recording_a_media_element
https://github.com/higuma/web-audio-recorder-js/blob/master/lib/WebAudioRecorder.js
https://codepen.io/kulak-at/pen/oqbKpq
https://hackernoon.com/a-web-audio-experiment-666743e16679
from react-piano.
Sorry, I've been pretty busy and haven't had a chance to take a look at this - I'll be able to get back to you more in depth by the end of this weekend.
from react-piano.
@SeunghunSunmoonLee sorry for getting back to you later than expected. I had to actually do a new release (v3.1.0) to make the API more intuitively support recording/playback (so I recommend upgrading to v3.1.0 first).
I've written up a full featured demo of an app that uses soundfont-player for playback, and records notes that are played and allows you to then play the recorded notes back: https://codesandbox.io/s/l4jjvzmp47
The code is a little complex but it demonstrates how to record "events" that can be played back. Hope this helps.
from react-piano.
Did the demo app help? Going to close this issue for now but feel free to re-open and update this with any additional questions you have. Thanks!
from react-piano.
Related Issues (20)
- register keyboard events on custom dom nodes?
- When using two piano keyboards in two lines, on renderNoteLabel only labels on bottom keyboard will be turned of on
- What's the difference between playNote and onPlayNoteInput?
- npm install fails HOT 1
- The mousedown listener is placed on the whole document.
- Pressing down more than 4 keys at the same time is unreliable HOT 5
- activeNotes prop is not used to initialize state on first render
- Rounding of corners does not scale HOT 2
- Allow more key combination with event.code instead? HOT 1
- Separating the utilities from the UI HOT 4
- Internationalization issue (Y and Z) HOT 1
- How to sustain Active Notes on Mouse Over? HOT 3
- Does this or will this support a MIDI Keyboard? HOT 3
- Octave keyboard shortcut?
- How do I turn a key blue. I can play a sound by calling playNote but it doesn't color the key in the same way it is when I press down on it physically.
- mazzeka.com
- Disable Shortcut Labels
- on play / stop functions without pressing a button HOT 1
- how to display notes on keys HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-piano.