question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Play different instruments in a flexible way

See original GitHub issue

I’d like to play several midi-files after one another, like sort of a playlist. According to the midi-file I’d like to get all its instruments to play. Sofar I only achieve that like this:

var player;
var instruments;

window.onload = function () {
    MIDI.loadPlugin({
        soundfontUrl: './soundfont/',
        onsuccess: function () {
            player = MIDI.Player;
            player.timeWrap = 1;
            player.loadFile('test.mid', function () {
                instruments = player.getFileInstruments();
                for (var i = 0; i < instruments.length; i++) {
                    MIDI.programChange(i, MIDI.GM.byName[instruments[i]].number);
                }
                player.start();
            });
        }
    });
};

However they either seem to play on the wrong channel or somehow the wrong soundfont is assigned. So for example, the clarinet plays the piano’s melody. I couldn’t figure out how to solve that problem.

I’d be really happy about some advice or ideas 😃

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
hmoffattcommented, Nov 26, 2017

On 26/11/17 21:37, Owwwl9 wrote:

instruments = player.getFileInstruments(); for (var i = 0; i < instruments.length; i++) { MIDI.programChange(i, MIDI.GM.byName[instruments[i]].number); }

Don’t do this, it’s completely wrong. getFileInstruments just gives you a list of instruments that are used in the file, so that you can load the appropriate sound fonts.

The MIDI file itself will set the program (instrument) on the appropriate channel. There is no need for you to make any calls to MIDI.programChange yourself.

0reactions
page200commented, Dec 27, 2022

Same problem. Has anyone found a solution? Or any example of MIDI.js playing MIDI files with the correct instruments apart from piano?

The commented-out line is probably not the only bug, as discussed in issue #268

Read more comments on GitHub >

github_iconTop Results From Across the Web

Flexible Instrumentation Series - Alfred Music
As seen in the video below, Alfred/Belwin FLEX options provide opportunities for making music with like-instrument or mixed-instrument ensembles. Most grade .5– ...
Read more >
What is the most flexible musical instrument in terms of all ...
And thank you for asking, my opinions are handpan played along with (in no particular order) didgeridoo, cello, harp, flute, double bass, voice,...
Read more >
Flexatone - Wikipedia
The flexatone or fleximetal is a modern percussion instrument (an indirectly struck idiophone) consisting of a small flexible metal sheet suspended in a ......
Read more >
How to learn multiple Instruments (Benefits and Practice ...
... during the Lockdown I want to share my experience of learning multiple instruments with you. ... Your browser can't play this video....
Read more >
String Ensemble Flexible Instrumentation | Sheet music at JW ...
These 25 trios can be played with any combination of string instruments. Ideal for classroom, recital, or festival use with difficulty ranges from...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found