button basher - 2010-11-30

Hi there,

Thought I'd give scripteffect a wurl, and prototype a midi plugin I've been thinking about. I am attempting to detect Note off events, and have been unable to successfully get this to work, I've attached a picture of my test setup in EnergyXt.

It can pass through a note off midi message:
plugin.send(sm,timeStamp);
but not detect
if (command==javax.sound.midi.ShortMessage.NOTE_OFF)

Any ideas?
bb

import org.jvaptools.scripteffect.*;
org.jvaptools.VstPluginImpl plugin;
public void init(org.jvaptools.VstPluginImpl owner) {
  this.plugin=owner; 
  // Set Volume to 1
  scale=1.0f;
  this.plugin.setParameter("a","0.5");
  //short nMidi[] = new short[12];
}
public void close() {}
float scale;
public void onMidiEvent(javax.sound.midi.MidiMessage message, long timeStamp) {
    // If message of type ShortMessage
    
    if(message instanceof javax.sound.midi.ShortMessage ){
        javax.sound.midi.ShortMessage sm=(javax.sound.midi.ShortMessage)message;
        int command=sm.getCommand();
        int velocity=sm.getData2();
        int channel = sm.getChannel();
        int note = sm.getData1();
        int noteInOctave = (note%12);
        int octave = ((note-noteInOctave)/12);
        
        //unable to get this bit working as predicted
            plugin.setParameter("b",Float.toString((float) command));
            
            //never gets here: unable to detect note_off
            if (command==javax.sound.midi.ShortMessage.NOTE_OFF){//0x80 - noteoff
                plugin.setParameter("a","10.0");
            }
            
            //yet output a noteoff message no problem?
            try{        
                sm.setMessage(command,sm.getChannel(),sm.getData1(),velocity);
                plugin.send(sm,timeStamp);
            } catch(javax.sound.midi.InvalidMidiDataException e){}
        //---------
    }
}
public void processReplacing(vstmain plugin,float a,float b,float c,float d,float[][] inputs, float[][] outputs, int sampleFrames)
{ 
// Save parameter a as midi message volume
scale=a;
float[] out1 = outputs[0];
float[] out2 = outputs[1];
float[] in1 = inputs[0];
float[] in2 = inputs[1];
for (int i = 0; i < sampleFrames; i++) {
out1[i] = in1[i];
out2[i] = in2[i];
} }