gasman / jasmid Goto Github PK
View Code? Open in Web Editor NEWUNMAINTAINED. A MIDI file reader and synthesiser in Javascript
Home Page: http://matt.west.co.tt/music/jasmid-midi-synthesis-with-javascript-and-html5-audio/
License: Other
UNMAINTAINED. A MIDI file reader and synthesiser in Javascript
Home Page: http://matt.west.co.tt/music/jasmid-midi-synthesis-with-javascript-and-html5-audio/
License: Other
THIS PROJECT IS NO LONGER MAINTAINED. http://unmaintained.tech/ =============================================================== see jasmid.ts fork: https://github.com/pravdomil/jasmid.ts jasmid - A Javascript MIDI file reader and synthesiser Originally presented at BarCamp London 8, 13-14 November 2010 Instructions: Open index.html in browser. Turn up volume. Click on link. Sound output is via one of the following mechanisms, according to what your browser supports: * Mozilla Audio Data API <https://wiki.mozilla.org/Audio_Data_API> * Web Audio API <https://dvcs.w3.org/hg/audio/raw-file/tip/webaudio/specification.html> * a Flash fallback originally taken from dynamicaudio.js by Ben Firshman <https://github.com/bfirsh/dynamicaudio.js> and hacked around by me. The code: stream.js - helper library for reading a string as a stream of typed data midifile.js - parses the MIDI file format into a header and a list of tracks, each consisting of a list of event objects replayer.js - steps over the data structure generated by midifile.js and calls the appropriate operations on the synthesiser synth.js - audio synthesiser; generates waveforms according to tweakable parameters audio.js - passes the generated waveform to either the Audio Data API or the Flash fallback widget (da.swf) Limitations: * The only event types supported by replayer.js are note on, note off, tempo change and program change * There are currently only two instrument presets defined in synth.js - one for strings and a 'piano' one for everything else - and neither of them are particularly good (just a single volume-modulated sine wave). Matt Westcott <[email protected]> - @gasmanic - http://matt.west.co.tt/
Your README undersells this library.
Sound output is via the Mozilla Audio Data API, with a Flash fallback
but audio.js will use webkitAudio in Chromium, without falling back to Flash.
Hi,
I'm using jasmid along with MIDI.js to play some midi files inside the browser. I've ran into a strange issue. Playback deteriorates when I play a bit longer midi file on mobile CPUs (smartphones, tables). I'm trying with iPhone 5s, Nexus 5x, Nexus 7. These devices are not that bad generally.
It seem like it is influenced by the number of events a track inside midi file has. When I limit events to like 100 everything is great.
Any idea what might be the cause?
I wanna be able to get key signature of midi file. How do I do so?
IO.PrimitiveReader = function (data) {
var arr = Array.from(new Uint8Array(data));
var fn = {};
var position = 0;
fn.read = function (length) {
var result = arr.slice(position, position + length);
position += length;
return result;
};
/* read a big-endian 32-bit integer */
fn.readInt32 = function () {
var result = (
(arr[position] << 24)
+ (arr[position + 1] << 16)
+ (arr[position + 2] << 8)
+ arr[position + 3]);
position += 4;
return result;
}
/* read a big-endian 16-bit integer */
fn.readInt16 = function () {
var result = (
(arr[position] << 8)
+ arr[position + 1]);
position += 2;
return result;
}
/* read an 8-bit integer */
fn.readInt8 = function (signed) {
var result = arr[position];
if (signed && result > 127)
result -= 256;
position += 1;
return result;
}
fn.eof = function () {
return position >= arr.length;
}
fn.readVarInt = function () {
var result = 0;
while (true) {
var b = fn.readInt8();
if (b & 0x80) {
result += (b & 0x7f);
result <<= 7;
} else {
/* b is the last byte */
return result + b;
}
}
};
return fn;
};
I notice there is extra code in this project to avoid a dependency on jQuery. I can understand that at one level, but the reality is that when using jQuery there is more JS than there needs to be.
Is this still an objective of the project?
hi,
firstly, thanks for this nice framework.
i wanted to also display lyrics in devnagari(indian script) and found that currently it won't work as it is,
due to the x-user-defined charset. so i had to add some conversion code. i also tried another approach with a different version of loadRemote() in index.html, using the arrayBuffer type. then i had to change stream.js accordingly, which i have saved as stream1.js. i think this is a better approach, as to-from encoding conversions are reduced. the "b102_Bhairavi_*.mid file i have used is the test-file for unicode lyrics.
Of course we also need to read and propagate lyrics events in replayer, and i have done it using the handleMidiMetaEvent().
i have also added a stop button by calling the audioplayer.stop().it works, but i wonder if some other clean-up needs to be done.
have attached my change files to this issue.
regards,
manoj
Add more instruments from WebAudioFont
see example
https://surikov.github.io/webaudiofont/examples/midiplayer.html
300 drums + 1500 tone samples
This code
case 0x51:
event.subtype = 'setTempo';
if (length != 3) throw "Expected length for setTempo event is 3, got " + length;
event.microsecondsPerBeat = (
(stream.readInt8() << 16)
+ (stream.readInt8() << 8)
+ stream.readInt8()
)
return event;
will sometimes result in a microsecondsPerBeat
of zero which results in a beatsPerMinute
of Infinity
, and a secondsToGenerate
of 0, resulting in a perceived MIDI file length of 0.
Tried playing from the demos page, but got an error
navigator.appVersion - "5.0 (X11; CrOS x86_64 5978.80.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.119 Safari/537.36"
How to implement stop playback after playing MIDI file?
some way to loop would be nice
and jhohertz https://github.com/jhohertz/jasmid/tree/sidengine seem to have done lots of work on the jasmid
and this is perfect for 8 bit song in midi format :D
it would be a lot better if it's possible to loop though.
Hi!
I am trying to figure out how to build a project in which I need to play single notes. Those notes would be defined from javascript, say playNote("a") or playNote("g")
Could it be achieved using jasmid? What is the best approach to build it?
in synth.js, looks like A440 is used on midi number 57.
should it be
var frequency = 440 * Math.pow(2, (note-69)/12);
instead of
var frequency = 440 * Math.pow(2, (note-57)/12);
but according to http://www.phys.unsw.edu.au/jw/notes.html its number 69. Just wondering if this is intentional before submitting a pull request. but btw, awesome library! :)
Hi Matt,
Thanks for your effort to bring midi squencer/syth to web, I'm thinking to use jasmid in my project, however I find it can't play one of our midi correctly. but it do work with other sequencer without problem.
http://69.195.73.224/tcmm070000603.mid.
Can you kindly take a look?
Thanks,
Rick
Most midi files has tracks with instrument labelled in the trackName with the same track number. But some don't. Is the information stored somewhere? Also, is there a way to obtain the instrument code, where 1 corresponds to Acoustic Grand Piano, etc.?
when I click on the links nothing happens (Mac OS X 10.8.4). Sandbox seems to work but the midi player does not.
Thanks
noteoff appears well on chrome and firefox.but On IE I got "noteAftertouch",and the note also get disorted.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.