surikov / webaudiofont

Use full GM set of musical instruments to play MIDI and single sounds or effects. Support for reverberation and equaliser. No plugins, no Flash. Pure HTML5 implementation compatible with desktop and mobile browser. See live examples.
https://surikov.github.io/webaudiofont/
GNU General Public License v3.0
891 stars 92 forks source link

I would like to load and play four midi simultaneously. #29

Closed sdoherty0 closed 5 years ago

sdoherty0 commented 5 years ago

I have found a way to do it in riffshare, by changing the file loader function, but I cannot find a way to load four midi files in webaudiofont and then play them simultaneously with gain nodes to alter their respective volumes. Do you have an example of loading from multiple simultaneous midi files? Thanks.

surikov commented 5 years ago

You can load and play any number of midi simultaneously. You can send all notes from all midi's into single Gain node.

Please be more specific.

Place link to your code here if you need review.

sdoherty0 commented 5 years ago

I have done this in your riffshare app by allowing the storeTracks object to keep adding tracks to it from multiple file loads by changing the openSong function to handle all files passed to it . However, I have not seen a code example or snippet of how to load multiple midi files in webaudiofont. What I have seen is javascript sf2 loads, or a single midi file loader, but I do not know how to load the individual midis and pass them to gain nodes and then play them all at the same time. Do you have an example of this?

surikov commented 5 years ago

No.

sdoherty0 commented 5 years ago

Could you show me a snippet of how I could do it? Your riffshare is awesome, I just don't need all of the visuals, but I'm amazed at its ability to handle so much complexity.

surikov commented 5 years ago

Invoke loading function twice and store notes in two arrays. Send notes from both arrays to single output in the same time.

This is very easy.

sdoherty0 commented 5 years ago

Thank you for your patience. I am looking at the midiplayer.html example, and I do not see how to do what you are describing because i don't see where it is being sent to an output. It is calling sendNotes, which calls player.queueWaveTable, and I don't see how to do that with two things. Again, thank you for your patience.

surikov commented 5 years ago
function sendNotes(firstSong, secondSong ...
  for (var t = 0; t < firstSong.tracks.length; t++) {
    var track = firstSong.tracks[t];
    for (var i = 0; i < track.notes.length; i++) {
      ...
    }
  for (var t = 0; t < secondSong.tracks.length; t++) {
    var track = secondSong.tracks[t];
    for (var i = 0; i < track.notes.length; i++) {
      ...
    }
sdoherty0 commented 5 years ago

That did it! Thank you so much.

sdoherty0 commented 5 years ago

How can I change the tempo? Thanks again,your library has solved a problem I have been facing for a long time.

On Wed, Feb 6, 2019, 1:46 PM Srgy Surkv notifications@github.com wrote:

function sendNotes(firstSong, secondSong ...

for (var t = 0; t < firstSong.tracks.length; t++) {

var track = firstSong.tracks[t];

for (var i = 0; i < track.notes.length; i++) {

  ...

}

for (var t = 0; t < secondSong.tracks.length; t++) {

var track = secondSong.tracks[t];

for (var i = 0; i < track.notes.length; i++) {

  ...

}

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/surikov/webaudiofont/issues/29#issuecomment-461139698, or mute the thread https://github.com/notifications/unsubscribe-auth/AtB-QPBArrizZdO4TO01ydFC5MQK5lMdks5vKyLzgaJpZM4akbTu .

surikov commented 5 years ago

search closed issues for same question