npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ablaise/yamaha-eseq-converter

v1.1.0

Published

Yamaha E-Seq Converter is a ES6 JavaScript tool that helps to convert a midi file into the Yamaha's standard E-Seq format

Downloads

17

Readme

Yamaha E-Seq Converter

Yamaha E-Seq Converter is a ES6 JavaScript tool that helps to convert a midi file into the Yamaha's standard E-Seq format.

Focus

Because most midi files only use one channel, the primary goal of this library is to correctly assign notes to the left and right hands. As a result, the features of software like Smart Pianist can work properly.

| Before | After | |:-------------------------------------------:|:-----------------------------------------:| | Before editing | After editing |

Getting started

Provided midi files should not be in format 0 and should ideally have 2 tracks. If not, you will have to assign the tracks manually using the Midi class.

If a piano midi file has more than two tracks, the last two are usually the right and left hands.

Installation

npm install @ablaise/yamaha-eseq-converter

Events

Events are available and described on the table below.

| Name | Description | |:-------------:|:---------------------------------------------:| | EVENT_READY | Triggered when the midi file is loaded. | | EVENT_ID | Triggered when a message event is being read. |

Convert a piano midi file

Here is how you can use the library to convert your midi files. Change the code according to your needs.

import Midi from "@ablaise/yamaha-eseq-converter/lib/Midi";
import Utils from "@ablaise/yamaha-eseq-converter/lib/Utils";

const midi = new Midi({
    autorun: true,
    path: './path/to/file.mid',
    //buffer: new ArrayBuffer(...) // or "buffer" option if you prefer to work with ArrayBuffer
});

/**
 * Here is how you can handle a two-tracks midi file for piano.
 */
window.addEventListener(Midi.EVENT_ID, (event) => {
    const data = event.data;
    if (Utils.isChannelAssignable(data.id)) {
        let track = 0
        switch (data.index) {
            case 0:
                track = Midi.TRACKS.PIANO_LEFT_HAND;
                break;
            case 1:
                track = Midi.TRACKS.PIANO_RIGHT_HAND;
                break;
            default:
                console.warn('Unhandled channel.')
                break;
        }

        // update the byte ID with the expected channel
        data.dv.setUint8(data.offset, Utils.setChannel(data.id, track));
    }
});

/**
 * Downloads the output midi file.
 */
window.addEventListener(Midi.EVENT_READY, (event) => {
    const data = event.data;
    const header = data.context.getHeader();
    if (0 === header.getType()) {
        throw 'Invalid midi type.';
    }

    midi.download();
});

You can also use a callback instead of the EVENT_READY event.

import Midi from "@ablaise/yamaha-eseq-converter/lib/Midi";
import Utils from "@ablaise/yamaha-eseq-converter/lib/Utils";

const midi = new Midi({
    autorun: true,
    path: './path/to/file.mid',
    //buffer: new ArrayBuffer(...) // or "buffer" option if you prefer to work with ArrayBuffer
}, (data) => {
    const context = data.context;
    const header = context.getHeader();
    if (0 === header.getType()) {
        throw 'Invalid midi type.';
    }

    // ...
});

Running tests

Yamaha E-Seq Converter uses the Jest Javascript testing framework. You can run them using the following command.

npm run test

Final note

:construction: This tool is still experimental and was created to solve a specific problem. The midi file parser is not a hundred percent complete and may be incorrect in some cases, use it with caution.

What's next?

  • A demo website for batch conversion
  • Improving the midi parser and fixes
  • More events are coming soon
  • More tests are coming soon

Useful resources

Here are resources that helped me to understand the midi format.

  • https://moddingwiki.shikadi.net/wiki/MID_Format
  • http://midi.teragonaudio.com
  • http://www.ccarh.org/courses/253/handout/smf/
  • http://www.cs.uccs.edu/~cs525/midi/midi.html