Code Monkey home page Code Monkey logo

midi.js's Introduction

midi.js

a library for writing MIDI files, reading MIDI files, and representing MIDI files as an intermediary JSON structure. nothing more, nothing less.

including

simply add a script tag to your page linking to the midi.js built script. this will expose a global MIDI object.

using

to read files

midi.js accepts a binary string as it's input. the example below shows how to parse a midi file selected from a file type input.

onFileChange = (fileInput) ->
  files = fileInput.files
  reader = new FileReader()

  reader.onload = (load_e) ->
    midi = new MIDI(load_e.target.result)
    console.log midi

  reader.readAsBinaryString(files[0])

to write files

instead of accepting a binary string, the MIDI constructor can also accept predefined header and track objects. additionally, any MIDI file can call write to return the encoded contents of the midi.

header =
  formatType: 0
  trackCount: 1
  ticksPerBeat: 96

track1 = [
  new MIDI.Events.TrackName(''),
  new MIDI.Events.TimeSignature(4, 4, 36, 8),
  new MIDI.Events.NoteOn(65, 100),
  new MIDI.Events.NoteOff(65, 64, 24),
  new MIDI.Events.NoteOn(70, 100, 168),
  new MIDI.Events.NoteOff(70, 64, 24),
  new MIDI.Events.EndOfTrack()]

midi = new MIDI(header, [track1])
console.log(midi.write())

compiling, developing

two primary Gruntfile tasks are exposed for purposes of developement.

build - will compile coffeescript files, and build the requirejs distributed packages default - will run build, and setup a watcher to rebuild on file changes

midi.js's People

Stargazers

Steve Schow avatar Michael Anthony avatar rchk avatar

Watchers

Nic Luciano avatar James Cloos avatar Michael Anthony avatar  avatar

Forkers

beng

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.