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

How to automate startRecording and stopRecording #213

Closed
shivrajsa opened this issue Jul 26, 2017 · 7 comments
Closed

How to automate startRecording and stopRecording #213

shivrajsa opened this issue Jul 26, 2017 · 7 comments

Comments

@shivrajsa
Copy link

Please refer this issue #169
I want to record the sound made by MIDI.js as soon as it starts making sound

I am partially successful to achieve this. Means I have buttons to start and stop recording when MIDI.js is making sound please refer below gist

https://gist.github.com/shivrajsa/b4e4467a21420e74638b650a3c4b3bac

But I want it to be automatic i.e. recording should start automatically as soon as MIDI.js starts making sound and it should stop automatically when it stops. It should not require manual buttons to control recording.

Please guide to achieve this

@gleitz
Copy link

gleitz commented Jul 26, 2017

In the onsuccess of MIDI.loadPlugin you could call MIDI.startRecording. You could also call startRecording before the first note is played with MIDI.noteOn

@shivrajsa
Copy link
Author

@gleitz , main challenge is to automate stopRecording(), structure of my code is similar to

Function playMelody(....)
{
playNoteSequence1(arrayofnotes,arrayofdelay)
playNoteSequence2(arrayofnotes,arrayofdelay)
playNoteSequence3(arrayofnotes,arrayofdelay)
}

and I want to implement

Function playMelody(....)
{
playNoteSequence1(arrayofnotes,arrayofdelay)
playNoteSequence2(arrayofnotes,arrayofdelay)
playNoteSequence3(arrayofnotes,arrayofdelay)
MIDI.stopRecording();
}

I have implemented startRecording() in MIDI.noteOn() function in plugin.webaudio.js, here is the Gist

It seems stopRecording() is called before completion of playNoteSequence3(arrayofnotes,arrayofdelay), I think it is because of asynchronous execution of functions.

@gleitz
Copy link

gleitz commented Aug 17, 2017

You should put the stopRecording in the callback of playNoteSequence3, after calling the final noteOff

@shivrajsa
Copy link
Author

shivrajsa commented Aug 22, 2017

@gleitz , I provided incomplete information, sorry for that. Actually I want to execute stopRecording() after execution of all three function playNoteSequence1(arrayofnotes,arrayofdelay) playNoteSequence2(arrayofnotes,arrayofdelay) playNoteSequence3(arrayofnotes,arrayofdelay)

Because all these three functions execute asynchronously. Is there any way to achieve that.

Also I am thinking about calculating the time of whole melody based on tempo and schedule stopRecording() accordingly, but it will be little complex solution.

@shivrajsa
Copy link
Author

@gleitz , I am successful to implement stop recording by scheduling stopRecording() using setTimeout

@gleitz
Copy link

gleitz commented Aug 24, 2017

Awesome! Maybe you can post some sample code for others who might have this issue :)

@shivrajsa
Copy link
Author

I have array of delay for each note in miliseconds

var delayarray = [500,500,1000, . . . . .]

I add all these delay to calculate total time of melody, and call stopRecording() using setTimeout

setTimeout(MIDI.stopRecording,totaltime+1000)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants