Japanese

MDPW for JRuby

Install

Note

Sequence

Chord

Music piece

Visitor


Download
mdpw30.zip

Back

Install

Install JRuby(Ruby) if you have not installed yet. Download mdpw30.zip and extract it. You will find mdpw.jar. Add the jar file to your Java development environment. And in the jruby folder there is a mdpw.rb, the ruby library.
Top of this page| Next step

How to make a Note

The class Mn is for the note. The arguments of constructor are pitch(0-127), duration(positive double), velocity(0-127) and program number (0 - 127, 129) respectively.
require "mdpw"
n = Mn.new(60,1,32,1)


p = MidiFilePlayer.new
p.init('note.mid')
p.setTempo(120)
p.play(n)
p.end()

Top of this page| Next step

How to make a Sequence

You can make a sequnece of notes by Ms class. It inherits class "Array".
require "mdpw"
seq = Ms.new([Mn.new(60,1,64,1), Mn.new(62,1,64,1), Mn.new(64,1,64,1) ])

p = MidiFilePlayer.new
p.init('seq.mid')
p.setTempo(120)
p.play(seq)
p.end()

Top of this page| Next step

How to make a Chord

You can make a chord by Mc class. It inherits class "Array".
require "mdpw"
chord = Mc.new([Mn.new(60,1,64,1), Mn.new(64,1,64,1), Mn.new(67,1,64,1) ])

p = MidiFilePlayer.new
p.init('chord.mid')
p.setTempo(120)
p.play(chord)
p.end()

Top of this page| Next step

How to make a musical piece

You can make a musical piece by sequences and chords. Both can contain both. You can make a seqence as the melody, a sequence of chords as the accompaniment and a chord of those two.
require "mdpw"
seq = Ms.new([Mn.new(60,1,64,1), Mn.new(62,1,64,1), Mn.new(64,1,64,1) , Mn.new(65,1,-64,1) ])
chord = Mc.new([Mn.new(60,2,32,1), Mn.new(64,2,120,1), Mn.new(67,2,1,1)])

mp = Ms.new([seq, seq])
cp = Ms.new([chord, chord, chord, chord])
sample = Mc.new([mp , cp])

p = MidiFilePlayer.new
p.init('sample.mid')
p.setTempo(120)
p.play(sample)
p.end()


Top of this page| Next step

Visitor

This sample implements the "Crescendo" visitor. You can implement how to proccess the notes at the method "proccess". The first argument is the note to be proccessed and the second argument is the timing the note in the sequence.
require "mdpw"

class Crescendo < Visitor
  def initialize(d, sv, en)
    @duration = d
    @startv = sv
    @endv = en
  end
  def process(mn, d)
    mn.setVelocity((@endv - @startv)*d/@duration+@startv)
  end
end

seq = Ms.new([Mn.new(60,1,64,1), Mn.new(62,1,64,1), Mn.new(64,1,64,1) ])
v = Crescendo.new(seq.getDuration(), 32, 120)

seq.visit(v)

p = MidiFilePlayer.new
p.init('visitor.mid')
p.setTempo(120)
p.play(seq)
p.end()
Are you inspired? Enjoy Music Programing.
Top of this page