JMSL Tutorial: Plug-ins

JMSL has powerful tools that scan the CLASSPATH for plug-in classes the user can create. For example, when JScore is used as a standalone (by running ScoreFrame), and it is launched with a folder named "jmsl_plugins" in its classpath, it will automatically scan the classes it finds there. Classes it finds are sorted out into the following groups and made available in menus:

UnaryCopyBufferTransforms Operate on the Notes in the CopyBuffer, result is pasted into the score.
BinaryCopyBufferTransforms Operate on the Notes in the AuxCopyBuffer1 and AuxCopyBuffer2, result is pasted into the score.
JSyn Circuits that implement UnitVoice. These are used to build JSynUnitVoiceInstrument and can be programmed by hand or using Syntona.
JSyn UnitVoices that implement UnitSink. These are used to build a signal processing JSynUnitVoiceInstrument
Instruments Can be added to Orchestra.
NotePropertyTransforms Operate on selected Notes "in place".
ScoreOperator Perform arbitrary operation on a Score

When you or a third party developer creates a subclass of one of the categories above, you must drag that class along with its directory structure into your jmsl_plugins folder. ScoreFrame will find it. This means if the class is in a package named "acme", then you must drag the "acme" folder and the .class file inside it, into the jmsl_plugins folder


IMPORTANT: a class must implement com.softsynth.jmsl.JMSLPlugin. This is an interface with no methods. It is simply there to distinguish classes the developer wants to show up as a plugin from classes to be excluded.

The full source code for a JMSL Plugin is shown below.
package com.punosmusic.jmsl.plugins;

import java.util.Enumeration;

import com.softsynth.jmsl.*;
import com.softsynth.jmsl.score.Note;
import com.softsynth.jmsl.score.NoteFactory;
import com.softsynth.jmsl.score.NotePropertiesTransform;
import com.softsynth.jmsl.score.Score;
import com.softsynth.jmsl.score.SelectionBuffer;

/**
 * For JScore. Just blort out some 12 tone row pitches and keep rhythms the same
 * 
 * @author Nick Didkovsky, copyright 2000 Nick Didkovsky, all rights reserved
 */
public class SerialTransform extends NotePropertiesTransform implements JMSLPlugin {

    MusicShape row;

    public SerialTransform() {
        setName("Serial Transform");
        row = new MusicShape(1);
        for (int i = 0; i < 12; i++) {
            row.add(60 + i);
        }
    }

    public void operate(Score score, SelectionBuffer selectionBuffer) {
        System.out.println("SerialTransform by Nick Didkovsky, (c) 2006 Nick Didkovsky, all rights reserved");
        row.scramble(0, row.size() - 1, 0);
        int kount = 0;
        for (Enumeration e = selectionBuffer.elements(); e.hasMoreElements();) {
            Note note = (Note) e.nextElement();
            if (!note.isRest()) {
                double pitch = row.get(kount % row.size(), 0);
                kount++;
                pitch += 12 * JMSLRandom.choose(3);
                note.setPitchData(pitch);
                // Use NoteFactory to recalculate staff level, accidental, and
                // stem direction
                NoteFactory.setLevelPitch(note, note.getPitchData());
                if (note.isChord() || note.isInterval()) {
                    Note.resortChord(note);
                }
            }
        }
    }

    public static final String copyright = "copyright (C) 2000 Nick Didkovsky, all rights reserved";
}

  (C) Nick Didkovsky and Phil Burk, All Rights Reserved
  JMSL is based upon HMSL (C) Phil Burk, Larry Polansky and David Rosenboom.