Previous Next Package
Introduction to MIDICompose
Amountable and Ramp
We already know the interfaces 'Lengthable'
(MIDIObjects that have a length. eg: 'Note','Rest'...),
'Channelable' (for setting the MIDI-channel),
'MIDIVariables' and
'GMVariables'. In this lesson we will use a new
interface called 'Amountable'. An amountable
object always has a value that can be set, the 'amount'. There are some methods to handle
this amount: 'amount()' returns the value, 'setAmount(int)' sets the value, 'minAmount()'
the lowest possible value, 'maxAmount()' the highest and 'zeroAmount()' the default value
or the value with no effect. All amountable objects can be handled by this methods. We
will append a 'ControlChange' with VOLUME
to channel one and set it to minimum amount.
MyCompose.java (Version 18)
We can only hear the clarinet on channel two. Now we want to slowly fade in channel one.
We can append a lot of 'ControlChanges' with rising amounts. But there is a class that is
designed to do this work. It is called 'Ramp'. A
'Ramp' is a 'MIDIContainer' that can only
store 'Amountable'-objects. It starts with the current amount, ends with an end-amount. We
will append a 'Ramp' of 'ControlChange' to midi to generate a soft fade in of the oboe.
MyCompose.java (Version 19)
Now we replace the Volume-Controller by a 'Tempo'.
We do not have to change anything else, and have a tempo-fade-in now. Try to experiment
around with other amount-classes like 'PitchBend',
'ChannelPressure',
'CombinedControlChange' and
'MasterVolume'. You will probably have
problems using 'AfterTouch', because it only
effects notes at a certain pitch.
MyCompose.java (Version 20)
Finally we will create an envelope over the whole MIDI-file. We create a new class called
'Envelope' that is a 'MIDIContainer' existing
of several 'Ramp's. Each 'Ramp' is based on
'MasterVolume'. We build two constructors, one only with the parameter length, the other
one with three parameters for each fadein-, sustain- and fadeoutlength. Sustain is done by
appending a 'Rest'. We append an 'Envelope' to midi at
the end (after all melodies are appended). We can easily set length of 'Envelope' by
asking midi for its length ('midi.length()').
MyCompose.java (Version 21)
This was the last lesson. You should be able to work with
'MIDICompose' at your own now.
Previous Next Package