Giter Site home page Giter Site logo

drkzrg / yamaha-eseq-converter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ablaise/yamaha-eseq-converter

0.0 0.0 0.0 294 KB

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

License: MIT License

JavaScript 100.00%

yamaha-eseq-converter's Introduction

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

๐Ÿšง 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.

yamaha-eseq-converter's People

Contributors

ablaise avatar

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.