Giter Site home page Giter Site logo

newlandsvalley / elm-webmidi-ports Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 1.0 1.53 MB

Support for web-midi by means of Elm ports

License: BSD 3-Clause "New" or "Revised" License

Elm 92.46% HTML 5.15% Makefile 2.39%
web-midi soundfonts web-audio instrument

elm-webmidi-ports's Introduction

elm-webmidi-ports

Build Status

This is an Elm 0.18 pseudo-library for Web-MIDI. It started life as an almost direct translation from elm-webmidi (elm 0.16) which was deprecated a year or so ago because it made heavy use of signals which suddenly vanished from the language. The analogue of signals in Elm 0.18 is subscriptions which act through ports. However, one downside of ports is that their use precludes publication in the Elm package repository.

This version has one advantage over its predecessor - MIDI Event messages are now properly parsed using the elm-comidi parser which means that the full range of such messages is now supported.

The only processing that is done on the message stream is to recognise volume control messages and thus to save to state the current maximum volume. This allows programs that use the module to respond to the volume control as notes are played.

You will need to attach a MIDI device to your computer to see any effect from Web-MIDI. At the time of writing, Chrome has the best support. Recent versions of Opera and Firefox support it but playback seems unresponsive. Other browsers will fail to initialise or fail to respond (say) to key presses on a MIDI keyboard.

To build, run make and browse to webmidi.html

Testing

This project has been tested using an M-Audio KeystationMini32 keyboard.

Examples

cd to the examples directory to see the sample programs.

(Examples have a dependency on elm-soundfont-ports which uses native code and which consequently is debarred from publication on http://package.elm-lang.org/. As a workaround, the elm code is reproduced in the SoundFont of the examples.)

Basic

Basic.elm is functionally identical to WebMidi.elm. It simply illustrates how you might embed the WebMidi module inside a larger program (but in this case this program does nothing else).

Piano

Piano.elm allows you to plug in your MIDI keyboard or other MIDI device and play it as a piano. It works simply by loading the piano soundfont which is served as a local resource, initialising web-midi and requesting that any NoteOn events should be played through the soundfont.

Send

Send.elm allows you to send MIDI note on and off messages to any connected MIDI device.

Pick an Instrument

MidiInstrument.elm allows you to plug in your MIDI keyboard or other MIDI device and to choose the instrumental sound it makes. In this case, the soundfonts are loaded directly from Benjamin Gleitzman's github package of pre-rendered sound fonts. These may take a little longer to load.

To build, invoke compilemi.sh and browse to midiInstrument.html.

Suggestions for Further Work

This would be the basis of an ideal component for anyone wishing to write a web-audio synthesiser in elm which might respond to a larger selection of control messages.

Dependencies

  elm-lang/core 5.1.1
  elm-lang/html 2.0.0
  newlandsvalley/elm-comidi 3.0.0

Contributing

Travis CI enforces that all code is formatted with elm-format.

To do this:

  1. npm install -g elm-format
  2. make format

elm-webmidi-ports's People

Contributors

newlandsvalley avatar rhofour avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

rhofour

elm-webmidi-ports's Issues

FR: Support MIDI output

I'm going to get to work on this.

For the first version I'm thinking something similar to how inputs are currently handled where we don't differentiate between devices so any output will be sent to every device.

FR: Setup CI testing

This would just ensure the main package and the examples continue to build. If tests are eventually added this would have even more benefit.

Travis CI seems to be the popular option since it's well integrated and free for open source stuff. I'll eventually get around to looking at it.

Files aren't formatted with elm-format

Right now most of the Elm files are formatted with elm-format. Would you accept a PR to reform the Elm files?

I like autoformatters because they give me one less thing to think about when I'm writing code. However, they don't work well if everyone isn't on board as they'll otherwise clutter up unrelated changes and make the history harder to follow.

FR: Add unit tests

I haven't looked into how to test Elm with ports, but I don't suspect this will be too hard since the ports already make a good separation between this library and the web MIDI JS.

FR: Add the ability to distinguish between midi devices

I can probably write this, but I'm opening this to track it and hopefully get some input on how to implement this.

Input and output devices are already tracked and exposed to Elm, but right now you can't do anything with them.

For input:
I think the most straightforward thing would be to expose the ID of the midi device in the EncodedEvent and Event messages. That way clients can easily ignore it if they don't care, but they also have all the information if they want to use it. There might be a race if we receive a MIDI message followed by the device immediately disconnecting it's possible when a client sees the decoded event the attached device ID doesn't match up to any device. I don't think this is much of a problem though.

For output:
I think the simplest thing here would be to have two different send functions. One which sends to everything (like the existing one) and another which accepts a list of device ids.

Thoughts?

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.