Giter Site home page Giter Site logo

gasman / jasmid Goto Github PK

View Code? Open in Web Editor NEW
414.0 19.0 90.0 129 KB

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

Ruby 1.06% JavaScript 72.00% ActionScript 11.59% HTML 15.35%

jasmid's Introduction

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/

jasmid's People

Contributors

gasman avatar luckyllama avatar paulmorris avatar pravdomil avatar signpostmarv avatar zz85 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

jasmid's Issues

How to play single notes

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?

Performance issues on mobile CPUs

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?

stream.js array buffer ajax

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;

};

Parsing tempo event results in invalid microsecondsPerBeat

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.

See mudcube/MIDI.js#134

event subtype error

noteoff appears well on chrome and firefox.but On IE I got "noteAftertouch",and the note also get disorted.

A440 == Midi Number 69?

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! :)

index.html

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

Why not using jQuery

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?

Lyrics with unicode, handling meta events and stopping

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

jasmid_fix.zip

Stop playback

How to implement stop playback after playing MIDI file?

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.