Git Product home page Git Product logo

mudcube / midi.js Goto Github PK

View Code? Open in Web Editor NEW
3.8K 3.8K 642.0 10.16 MB

:musical_keyboard: Making life easy to create a MIDI-app on the web. Includes a library to program synesthesia into your app for memory recognition or for creating trippy effects. Convert soundfonts for Guitar, Bass, Drums, ect. into code that can be read by the browser. Supports multiple simultaneous instruments and perfect timing.

Home Page: http://mudcu.be/midi-js/

License: MIT License

JavaScript 68.48% CSS 1.02% Ruby 1.36% HTML 29.14%

midi.js's People

Contributors

0xfe avatar adrianholovaty avatar bsstoner avatar bzwheeler avatar earslap avatar joncom avatar kusog avatar mscuthbert avatar mudcube avatar odyssomay avatar pete-otaqui avatar ragamroll avatar shama avatar sinkswim avatar tails avatar toddpress avatar ucarion avatar v-fedorov avatar zorbash avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

midi.js's Issues

MIDI.js does not work on IE9 (5.7% of users affected)

I've tested MIDI.js on IE9 and received the following errors:

SCRIPT438: Object doesn't support property or method 'defineProperty'
WebMIDIAPI.js, line 415 character 5

SCRIPT438: Object doesn't support property or method 'map'
LoadPlugin.js, line 30 character 2

Popping sound in Firefox w/ WebAudioAPI

Firefox creates popping sounds, especially when many notes are played quickly. This may have to do with linearRampToValueAtTime using up too much resources. Any ideas / thoughts for fixes?

Too many AudioContext created - max 4

It seems that the code is not deleting the AudioContext objects, so once you play enough midi files, it reaches the max and cannot create any more.

We probably need a way to clean up resources when the file is done playing.

iOS compatible

Hi!

Thanks for your amazing code! It's simply awesome!

Can be used on iOS?

Best Regards,
Roberto

playback slows down when MIDI tab is in background

I'm having this issue in Chrome 32, OSX 10.8 - I'm using the MIDI Plugin, but not the Player, to play sounds by calling noteOn via javascript in a setInterval loop.
When the browser tab is in its own window, or is the visible tab in a window with multiple tabs, the playback is correct. When I put the tab in the background, playback slows down.
On the demo apps this doesn't happen so this may be something with how I have my javascript programmed.

Example here:
http://midi.backtrace.us/minimalism.html
When the window first loads, it plays at a steady tempo around 6 or 8 notes per second. If you open a new browser tab, playback slows down and the notes bunch up and play in clusters about once per second.

.stopAllNotes does not work

It's not clear how to stop MIDIJS all the notes scheduled to play later. The stopAllNotes method is undefined, always undefined, it also doesn't work if it gets called via MIDI.AudioTag.

Obsolete reference to 'playback-title' in Player.js

Player.js has the line

document.getElementById("playback-title").innerHTML = title.replace(".mid","");

which causes problems when loading MIDI from a file / URL. This seems to be obsolete because playback-title isn't referenced anywhere else.

chrome: "audio resources unavailable for AudioContext construction"

using the basic demo and playing a note over and over again, Chrome throws this error:
"Uncaught SyntaxError: audio resources unavailable for AudioContext construction"

as seen on here:
http://stanford.edu/~c0chran/cgi-bin/midi-default/

if I put a try block around the new audio context that is generated in plugin.js, it doesn't throw the error:
try {
MIDI.Player.ctx = ctx = new AudioContext();
} catch(err) {}

however, the rendering of the audio is much slower on chrome than on Firefox, such that you could only play a note about once every 2 seconds.when the try block is removed, the audio can play more rapidly but then the error is thrown after 5-6 plays.

is there no having one without the other?

Use with NPM + Browserify?

Greetings,

This is an impressive thing here, but I find it to be confusing almost completely unportable.

Please consider using NPM, and perhaps browserify, to make it truly modular and portable. It much easier to manage and organize code with those tools (which are becoming industry standards in Javascript).

Many thanks,

Anyway to download the generated music?

Is there any way to download the generated music, that's created by noteOn() and noteOff() calls?

I tried taking the audio tag's src (which is a data URI) and assigning it to an anchor tag. Opening that in a new browser tab doesn't play any sound.

about size of generated soundfont

Hi,
I use soundfont_builder.rb and FluidR3_GM.sf2(download from fluidsynth sourceforge site,114M), it works perfect on my win7(no error or warning msg).but i found the generated soundfont js file size is smaller than soundfonts in git. for example,acoustic_grand_piano-mp3.js in git is 1402 KB,but my acoustic_grand_piano-mp3.js is only 88KB.
my question is why? is it because my generated soundfonts not completely? or because the sample soundfonts generated from a more high-quality sound bank?

i really wants a "high-quality" guitar soundfonts(i like the sample acoustic_grand_piano-mp3.js) ,any sugguestion?
thanks!

loading Soundfont

If soundfont never loads (the rainbow star never goes away), am I having an issue with a particular file or is my question too open ended?

source links in demo-MIDIPlayer.html are broken

Most of the links to .js files don't work, for example

<a href="./js/MIDI.loadPlugin.js">MIDI.loadPlugin.js</a>:

That file is now ./js/MIDI/LoadPlugin.js. Similarly ./js/Color.js now at ./js/Color/SpaceW3.js, etc.

(The links in the online version of the code at http://mudcu.be/midi-js/ work but only because it is older code that links to older versions of the .js files in the original locations.)

Firefox and Opera issues

MIDI.js works great on Chrome, but when run on Firefox and Opera there is a lot of echo and some notes won't play, or they are cut off right after they start playing. Wondering if there is a better soundfont out there to circumvent the loud echo which is not present when played with Chrome. I am using acoustic_grand_piano-ogg.js.

Can't detect when instrument is ready to play

Hi,
Im trying to detect the moment when the instrumens are completely loaded, could somebody please give some hint about it? I've tried many different things, but i can't find a point in which the plugin is ready to sound

Thanks in advance,

Noise and glitches on Opera and IE10

There are noises and glitches on Opera and IE10. This issue is more noticeable on Opera than IE10, but evident in both. This becomes especially noticeable when notes are played one after another at a higher tempo. It is more noticeable when the volume is turned up to max on the machine, but exists at all volumes.

Opera is used by 1.8% of world users and IE10 is used by 0.9% of world users, but in the months to come IE10 usage will grow massively.

Any way to load sound fonts on demand?

is there any way to have the MIDI Plugin load, start playing with a single sound font, and then load other sound fonts in the background or via user action while music is playing?

Small Question about chordOn

Hi guys, great job!!!!

im not able to get the chordOn working. NoteOn works fine, but im not sure what should i send to the parameter "chord" of chordOn. Here is my code:

            MIDI.noteOn(channel, notes, velocity, delay);
            MIDI.noteOff(channel, notes, delay + 2.75)

where notes is an array of integers containing the midi notes (that called one by one with noteOn works).

Could you please help me? Im currently simulating chords by playing many noteOn statements and would like to use it right.

Thanks in advance!!!

Detky

MIDI.noteOn() cuts note off abruptly after three seconds.

MIDI.noteOn() plays note for three seconds, and then cuts it off abruptly.
The note should be allowed to decay gradually to silence, and should not be cut off, unless turned off by MIDI.noteOff(). The time that it takes for the note to decay to silence should be a function of the input velocity, naturally.

Can't load instruments from external sites.

Instrument files are pretty big and better served via CDNs.

This is currently not possible because they are loaded via XMLHttpRequest which disallows cross-domain requests. Can this be changed to use the "script" tag?

Thanks!

Play MIDI with multiple instruments

Is it possible to bind different instruments to each channel in multichannel MIDI? For example if I've got a midi file with guitar and drums and soundfonts for each instrument. How could I play this midi in this way? Should i hack jasmid or MIDI.js and add instruments support for each midi channel?

Thanks.

MIDI.noteOff does not seem to work reliably.

It seems that, on Chrome, noteOff leaves the note off forever. (I'm not sure about other browsers.)

This is what my code does on every note play:

duration = note.getTicks().value() / (@tpm/60);
MIDI.noteOn(0, midi_note, 127, 0);
MIDI.noteOff(0, midi_note, duration);

duration is usually a value between 0 and 2, midi_note is a valid note value. The noteOn part works fine -- the noteOff switches off notes, but future noteOn calls to the same note don't work.

Suggestion for how to add reverb?

Does anyone have a suggestion for a way to add reverb to the output? Is there a reverb.js hiding somewhere? I don't know if its too processor intensive to do in a browser, seems like it should be possible for simple reverb.

polymer.js compatibility issue in safari and firefox

I'm currently working with MIDI.js and polymer.js in a project
it's working great together in chrome but not in safari and firefox

I know polymer is in pre alpha, but maybe you care...

thanks

MIDI.js rocks

First note not played

Hi,
It seems that the first note of a loaded file is not played.
When debugging, I found that the first noteOn event of the data array has a length of "0". By length, I mean data[n][1] (see Player.js; Line:226). So queuedTime remains inferior to currentTime, and the event pushing is skipped. I didn't investigate any further to suggest a fix.
The issue can be reproduced also by the first file on "http://mudcu.be/midi-js/"
Regards

Provide loading process feedback

Hallo Michael,

i'm trying to set the flag USE_XHR to true to get some loading progress feedback to build an animation, but i'm getting always an error on the following line:

MIDI.Soundfont[instrumentId] = JSON.parse(response.responseText);

JSON reports invalid character by parsing. I'm loading standard instruments from "midi-js-soundfonts" that works fine when USE_XHR is set to false.

Do you have an idea of what could be the reason?

Thanks for your help and your great job!

Android support

I'm using MIDI.js for my web-app WatchAndRepeat.com

Works great on desktop Chrome, Safari, and iPad.
Also works but not as smoothly on IE10 or Firefox.
TERRIBLE on Android tablets.

I'm willing to pay someone $$$ to work on midi.js and get it working smoothly on Android tablets and IE10 for PC's. I will provide the devices to you if you live in the NYC metro area. Email me at [email protected] to discuss further.

sf2-piano.sh - Loading bult soundfont-ogg.js results in JS error

The soundfont-generator shell script exports a invalid -ogg.js. File seems to be alright but something is going wrong when parsed.

It throws :
Uncaught SyntaxError: Unexpected token :
on line 2 : soundfont-ogg.js

Steps:
1 Clone MIDI repo
2 cd MIDI.js/soundfont-generator/shell
3 ./sf2-piano
4 Observe building into build path
5 Swap paths in basic-example.html with build path
6 Load basic-example.html in Chrome
7 Observe JS error :Uncaught SyntaxError: Unexpected token : line:2 :soundfont-ogg.js

The demo files are not playing from the zip download

Hi,

This is a really amazing library but I facing some challenges in getting it to work.

I am really new to this stuff and have downloaded the source zip files twice.

The last time I downloaded the code zip, the demo files were playing when opened in chrome but they are not playing now. The colorful circles keeps going around and the soundfonts are never downloaded. The only message displayed is "Web Audio API...".

I happen to have the old zip and opening the the demo's from the old zip still works - the events and b64 midi plays when the demo files are opened in chrome.

In both cases the files are on my local machine and are not hosted on any server

So, do I need to make some changes that will get the latest version of demos playing?

Thanks for the help in advance.

Shantanu

Loading midi files from URL's

Seems when you load a midi file from a URL it fails due to DOM Exception 5 - this is down to the attempt to convert from ASCII to binary.

Not sure you need to? Commenting out the line got the midi files playing?

fetch.onreadystatechange = function () {
    if (this.readyState === 4 && this.status === 200) {
        var t = this.responseText || "";
        var ff = [];
        var mx = t.length;
        var scc = String.fromCharCode;
        for (var z = 0; z < mx; z++) {
            ff[z] = scc(t.charCodeAt(z) & 255);
        }
        console.log(ff.join(""));

        var data = ff.join("");

        //var data = window.atob(ff.join(""));
        root.currentData = data;
        root.loadMidiFile();
        if (callback) callback(data);
    }
};
fetch.send();

Multiple instruments don't work in safari.

I had consoled audiobuffers and found some weird loading behavior in case of multiple instruments.And as a result of which multiple instruments are not working for safari.

changing instrument string value not registering with plugin.js

in demo-Basic.html, changing the instrument from:
instrument: "acoustic_grand_piano",
to:
instrument: "acoustic_guitar_steel",

does not work, as plugin.js still tries to process the default value of '0' for the grand piano. maybe the acoustic_guitar_steel naming convention just isn't supported, but if I just manually set instrument to 25 (acoustic_guirar_steel) in Plugin.js, it works fine:

var playChannel = function (channel, note) {
    if (!MIDI.channels[channel]) return;
    var instrument = 25;

Documentation on Player.loadFile

It took me forever to figure out that Player.loadFile can take in a link to a midi file or a base64 string.

I might commit the documentation myself.

ruby soundfont_buidler not generating files

I installed all the necessary dependencies and am using this GM soundbank: http://musescore.org/en/handbook/soundfont

when I run soundfont_builder I get the following output:

...
Hit return to begin.

Generating audio for: Acoustic Guitar (steel)(acoustic_guitar_steel)
Generating: A0
Running: /usr/local/bin/fluidsynth -C 1 -R 1 -g 0.5 -F ../../soundfont/acoustic_guitar_steel-mp3/A0.wav ./FluidR3_GM.sf2 ../../soundfont/temp.midi
Running: /usr/local/bin/oggenc -m 32 -M 64 ../../soundfont/acoustic_guitar_steel-mp3/A0.wav
Enabling bitrate management engine
ERROR: Input file "../../soundfont/acoustic_guitar_steel-mp3/A0.wav" is not a supported format
Running: /usr/local/bin/lame -v -b 8 -B 32 ../../soundfont/acoustic_guitar_steel-mp3/A0.wav
Warning: unsupported audio format
Updating JS files...
soundfont_builder.rb:154:in read': No such file or directory - ../../soundfont/acoustic_guitar_steel-mp3/A0.ogg (Errno::ENOENT) from soundfont_builder.rb:154:inbase64js'
from soundfont_builder.rb:179:in block in generate_audio' from soundfont_builder.rb:169:inupto'
from soundfont_builder.rb:169:in generate_audio' from soundfont_builder.rb:191:inblock in

'
from soundfont_builder.rb:191:in each' from soundfont_builder.rb:191:in'

Latency of 700ms for MIDI.loadPlugin is bad for user experience

I used the code below to measure how long it takes for MIDI.loadPlugin to call its callback on my MacBook Air and it came out to be 700ms. On other machines I have witnessed this delay to be as bad as 4 seconds, which is terrible for user experience.

I am wondering if there is a way to optimize this method so that it won't take longer than 100ms on the MacBook Air.

$(document).ready(function() {
/* Load the MIDI Player*/
debug((new Date()).getMilliseconds());
MIDI.loadPlugin({
soundfontUrl: "./soundfont/",
instrument: "acoustic_grand_piano",
callback: function() {
debug((new Date()).getMilliseconds());
}
});
});

[soundfont-generator] Syntax errors when executing soundfont_builder.rb

Hello,
I'm trying to get all the samples of FluidR3_GM.sf2 in js files so I installed all the dependencies and tried to execut soundfont_builder.rb but I get some syntax errors :

soundfont_builder.rb:114: odd number list for Hash
return { key: reverse_notes[note],
^
soundfont_builder.rb:114: syntax error, unexpected ':', expecting '}'
return { key: reverse_notes[note],
^
soundfont_builder.rb:115: syntax error, unexpected ':', expecting '='
octave: octave }
^
soundfont_builder.rb:205: syntax error, unexpected $end, expecting kEND

Did I do something wrong ?

Safari on iPad fails to play multiple tracks

I'm unable to here sound when playing the latest version of your code on the iPad. However, the demo site version works.

I've also noticed that the demo site code base works on the iPad, but won't play multi-track midi files properly. No sound is played, even though on my demo site http://kusogmusic.azurewebsites.net/home/contact the notes fall for both tracks. It seems that it is trying to play. If you want to see that, pick the Cyrstallize Duet. The duet song is the same instrument for both tracks, so I wonder if it is not the same issue as you outlined with multiple instruments in another issue.

On my windows 8.1 desktop, it works fine with IE11, Chrome, Opera, and FireFox.

Triggering Drum Sounds?

Hello.

I've been looking for a place to leave questions relating to midi.js but haven't found one. If this isn't the proper place, please let me know where would be a good place to post..

My question is:

I'm trying to get a just a drum sound to trigger but it is not working. I can get other notes to trigger from "acoustic_grand_piano" but not from just "synth_drum".

I think midi note 35 should relate to the "Acoustic Bass Drum".

Using sample from the demo-Basic.html

window.onload = function () {
MIDI.loadPlugin({
soundfontUrl: "./soundfont/",
instrument: "synth_drum",
callback: function() {
var delay = 0; // play one note every quarter second
var note = 35; // the MIDI note
var velocity = 127; // how hard the note hits
// play the note
MIDI.setVolume(0, 127);
MIDI.noteOn(0, note, velocity, delay);
MIDI.noteOff(0, note, delay + 0.75);
}
});
};

A song with bug :I

There is a song in the list paused for 5 minutes with the same key playing, I should have known the song name awhile back now I totally forget which is it the song sorry โŒ

Volume should be channel independant

Hello,

Thank you MIDIjs which is a good and simple to use library.

MIDI.plugin.js setVolume function should be channel specific.
It already accept channel as an argument but does nothing with this.
I guess a good way to solve this would be to use a masterVolume and an array of volume by channel.

This functionnality could be very usefull to start produce mixing table using js ;)
Bye

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.