Giter VIP home page Giter VIP logo

midi-eye's Introduction

MIDI EYE

MIDI input event listener for Ruby

Install

gem install midi-eye

or using Bundler, add this to your Gemfile

gem "midi-eye"

Usage

require 'midi-eye'

The following is an example that takes any note messages received from a unimidi input, transposes them up one octave and then sends them to an output

First, pick some MIDI IO ports

@input = UniMIDI::Input.gets
@output = UniMIDI::Output.gets

Then create a listener for the input port

transpose = MIDIEye::Listener.new(@input)

You can bind an event to the listener using Listener#listen_for

The listener will try to positively match the parameters you pass in to the properties of the messages it receives.

In this example, we specify that the listener listens for note on/off messages, which are identifiable by their class.

transpose.listen_for(:class => [MIDIMessage::NoteOn, MIDIMessage::NoteOff]) do |event|

  # raise the note value by an octave
  event[:message].note += 12

  # send the altered note message to the output you chose earlier
  @output.puts(event[:message])

end

There is also the option of leaving out the parameters altogether and including using conditional if/unless/case/etc statements in the callback.

You can bind as many events to a listener as you wish by repeatedly calling Listener#listen_for

Once all the events are bound, start the listener

transpose.run

A listener can also be run in a background thread by passing in :background => true.

transpose.run(:background => true)

transpose.join # join the background thread later

Documentation

Author

License

Apache 2.0, See the file LICENSE

Copyright (c) 2011-2017 Ari Russo

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.