Giter Site home page Giter Site logo

erhabor-fona / midi_util Goto Github PK

View Code? Open in Web Editor NEW

This project forked from eghosa-osayande/midi_util

0.0 1.0 0.0 79 KB

a pure dart library that allows one to write multi-track Musical Instrument Digital Interface (MIDI) files from within dart programs

License: Apache License 2.0

Dart 11.23% CSS 2.76% HTML 86.02%

midi_util's Introduction

midi_util

Inspired by the python library -MIDIUtil written by Mark Conway Wirt, midi_util is a pure dart library that allows one to create MIDI files (Musical Instrument Digital Interface) within a dart program with minimum fuss, and supports both format 1 and 2 files. Due to the large documentation as well as the organic growth of the MIDI files specifications, midi_util has been made to effectively implement aspects of this specifications that are commonly used and are in high demand. The midi_util package is properly structured to give anyone with a good understanding of the MIDI file format, and demonstrates a good understanding of object oriented programming with dart the ability to extend the library -Henc all of these makes this package easy to understand

import 'dart:io';

import 'package:midi_util/midi_util.dart';

void main() {
  List notes = [60, 62, 64, 65, 67, 69, 71, 72]; //  # MIDI note number
  var track = 0;
  var channel = 0;
  var time = 0; //    # In beats
  var duration = 0.5; //    # In beats
  var tempo = 60; //   # In BPM
  var volume = 100; //  # 0-127, as per the MIDI standard

  MIDIFile myMIDI = MIDIFile(numTracks: 2);
  myMIDI.addTempo(
    track: track,
    time: time,
    tempo: tempo,
  );
  myMIDI.addKeySignature(
      track: track,
      time: time,
      no_of_accidentals: 0,
      accidental_mode: AccidentalMode.MAJOR,
      accidental_type: AccidentalType.SHARPS);

  List.generate(notes.length, (i) {
    myMIDI.addNote(
        track: track,
        channel: channel,
        pitch: notes[i],
        time: time + i,
        duration: duration,
        volume: 100);
  });

  var outputFile = File('c_scale.mid');
  myMIDI.writeFile(outputFile);
}

There are several additional event types that can be added and there are various options available for creating the MIDIFile object, but the above is sufficient to begin using the library and creating note sequences. The above code is found in machine-readable form in the examples directory. A detailed class reference and documentation describing how to extend the library is provided in the documentation directory.

midi_util's People

Contributors

eghosa-osayande avatar erhabor-fona avatar

Watchers

James Cloos 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.