Created
September 19, 2009 22:28
-
-
Save Visuelle-Musik/189613 to your computer and use it in GitHub Desktop.
MIDI I/O with JRuby, ruby-processing example 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# === MIDI-Notes to solresol-colours in RubyProcessing. Example for the use of JRmidi, very basic Midi-Implementation for JRuby, especially for use with ruby-processing === | |
# --- ruby-processing see: http://wiki.github.com/jashkenas/ruby-processing / solresol is a universal language, where words can be put out as musical notes, colours or other --- | |
# --- solresol see: http://en.wikipedia.org/wiki/Solresol --- | |
# Notes have to come as MIDI-note-events from MIDI-in, and are for demonstration purposes redirected to two other output ports as well, adopt your MIDI-ports below! | |
MIDI_PORT_IN = 0 # your MIDI-input where notes will be mapped to coulors | |
MIDI_PORT_OUT_DAW_IN = 12 # the ports are numberes from 0 to n in the java-sound-API, this is a virtual in port of my "Digital Audio Wortstation", where this output is sent to | |
MIDI_PORT_OUT_SYNTH = 9 # in my configuration this is the synth as provided by the operating-system | |
require "jr_midi" # class JRmidi for basic MIDI I/O in JRuby... | |
class Sketch < Processing::App | |
load_library :opengl | |
include_package "processing.opengl" | |
def setup | |
@daw = JRmidi.new(self, :daw, :in_port => MIDI_PORT_IN, :out_port => MIDI_PORT_OUT_DAW_IN, :verbose => true) | |
@synth = JRmidi.new(self, :synth, :out_port => MIDI_PORT_OUT_SYNTH, :verbose => true) | |
library_loaded?(:opengl) ? render_mode(OPENGL) : render_mode(P3D) | |
hint(DISABLE_OPENGL_2X_SMOOTH); # save performance ? | |
hint(DISABLE_DEPTH_TEST); # save performance ? | |
no_stroke | |
frameRate(30); # default is 60, set to 25 for monitors with 75 Hz, for instance... | |
@s_col = Array.new | |
@s_col[0] = @s_col[1] = 0xFFE30000 # do-red (C , C#) | |
@s_col[2] = @s_col[3] = 0xFFEA621F # re-orange (D, D#) | |
@s_col[4] = 0xFFEDED00 # mi-yellow (E) | |
@s_col[5] = @s_col[6] = 0xFF00AA00 # fa-green (F, F#) | |
@s_col[7] = @s_col[8] = 0xFF00AAAA # sol-turquoise (G, G#) | |
@s_col[9] = @s_col[10] = 0xFF0000CC # la-blue (A, A#[Bb]) | |
@s_col[11] = 0xFF6D398B # si-purple (B) | |
@cur_col = 0xFF000000 # black | |
end | |
def draw | |
fill(@cur_col) # colour as set by setup(), note_on() or note_off() | |
rect(0, 0, 1024, 768) | |
end | |
def note_on(channel, note, velocity ) | |
@daw.send_note_on( channel, note, velocity ) | |
@synth.send_note_on( channel, note, velocity ) | |
@cur_col = @s_col[note % 12] | |
end | |
def note_off(channel, note, velocity ) | |
@daw.send_note_off( channel, note, velocity ) | |
@synth.send_note_off( channel, note, velocity ) | |
@cur_col = 0xFF000000 # black | |
end | |
end | |
Sketch.new(:width => 1024, :height => 768, :title => "processing-ruby: MIDI to solresol-colours") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment