[jmsl] QuarterTone MidiScoreInstrument save problem

jmsl at music.columbia.edu jmsl at music.columbia.edu
Tue Jan 8 08:05:30 EST 2008


...actually there is a third way. Put it in a jar file and put the jar 
file in jmsl_plugins
Thanks
Nick D


jmsl at music.columbia.edu wrote:
> Hi Peter
>
> I encounter no errors running this from Eclipse, nor saving the score 
> manually using the JMSL Score menu, nor loading it back using the JMSL 
> Score menu. So you are right it is a problem with paths...
>
> Are you running it from Eclipse or are you executing 
> run_jmsl_score.command under OSX, then loading the score using the 
> JMSL Score menu?
>
> If the latter, then you can add your instrument's .class file to the 
> classpath one of two ways, without altering the run_jmsl_score.command 
> file:
> 1) Put it in a jar file and put the jar file in the JMSL_v103/lib 
> directory (the lib directory is scanned for jars)
> ...OR...
> 2) make the folder hierarchy 
> com/petermcculloch/megalo/QuarterToneTwoChannelMidiInstrument.class 
> and move that into jmsl_plugins. (the jmsl_plugins folder is added to 
> the classpath)
>
> I think the jmsl_plugins folder is a better place for it because then 
> it will show up in JMSL Score's hierarchical instrument plug-in menu
>
> Let me know if this works for you!
>
> Thanks
> Nick
>
>
> jmsl at music.columbia.edu wrote:
>> Thanks Nick,
>>
>> I've made the changes, but I'm still getting the following error on 
>> save.  I've tried putting the classfile into the nested folders in 
>> the lib folder where jmsl.jar lives, but it doesn't find it either.  
>> I also added two test classloaders in the main method, one using 
>> Class.classForName() and one using JMSLClassLoader.load.  The first 
>> one works fine, but the second one gives me a 
>> ClassNotFoundException.  Do I need to add the class to JMSL's path?
>>
>> thanks,
>> Peter McCulloch
>>
>>
>> Save instrument
>> java.lang.ClassNotFoundException: 
>> com/petermcculloch/megalo/QuarterToneTwoChannelMidiInstrument
>>     at java.lang.Class.forName0(Native Method)
>>     at java.lang.Class.forName(Class.java:164)
>>     at 
>> com.softsynth.jmsl.util.JMSLClassLoader.load(JMSLClassLoader.java)
>>     at 
>> com.softsynth.jmsl.util.BeanInspector.setClassName(BeanInspector.java)
>>     at 
>> com.softsynth.jmsl.util.SimpleXMLSaver.<init>(SimpleXMLSaver.java)
>>     at 
>> com.softsynth.jmsl.score.ScoreFrame.handleSaveIns(ScoreFrame.java)
>>     at 
>> com.softsynth.jmsl.score.ScoreFrame.actionPerformed(ScoreFrame.java)
>>     at java.awt.MenuItem.processActionEvent(MenuItem.java:597)
>>     at java.awt.MenuItem.processEvent(MenuItem.java:556)
>>     at java.awt.MenuComponent.dispatchEventImpl(MenuComponent.java:298)
>>     at java.awt.MenuComponent.dispatchEvent(MenuComponent.java:286)
>>     at java.awt.EventQueue.dispatchEvent(EventQueue.java:466)
>>     at 
>> java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:269) 
>>
>>     at 
>> java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190) 
>>
>>     at 
>> java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:184)
>>     at 
>> java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:176)
>>     at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
>> JMSLClassLoader, Class.forName( 
>> com.petermcculloch.megalo.QuarterToneTwoChannelMidiInstrument) 
>> failed, trying System classloader
>>
>>
>> Here's the code:
>>
>> package com.petermcculloch.megalo;
>>
>> import java.awt.event.WindowAdapter;
>> import java.awt.event.WindowEvent;
>>
>> import com.softsynth.jmsl.DimensionNameSpace;
>> import com.softsynth.jmsl.Interpreter;
>> import com.softsynth.jmsl.JMSL;
>> import com.softsynth.jmsl.MusicDevice;
>> import com.softsynth.jmsl.midi.MidiIO;
>> import com.softsynth.jmsl.midi.MidiInstrument;
>> import com.softsynth.jmsl.score.Note;
>> import com.softsynth.jmsl.score.NoteFactory;
>> import com.softsynth.jmsl.score.Score;
>> import com.softsynth.jmsl.score.ScoreFrame;
>> import com.softsynth.jmsl.score.midi.MidiScoreInstrument;
>> import com.softsynth.jmsl.util.AttributeBuildable;
>> import com.softsynth.jmsl.util.JMSLClassLoader;
>>
>> public class QuarterToneTwoChannelMidiInstrument extends 
>> MidiScoreInstrument implements
>>         AttributeBuildable {
>>
>>     private static final MidiIO MIDI = JMSL.midi;
>>     MidiInstrument ins1, ins2;
>>
>>     public QuarterToneTwoChannelMidiInstrument() {
>>         this(1);
>>     }
>>
>>     public QuarterToneTwoChannelMidiInstrument(int channel1) {
>>         super(channel1);
>>         ins1 = new MidiInstrument(channel1);
>>         ins2 = new MidiInstrument(channel1 + 1);
>>     }
>>
>>     /**
>>      *
>>      */
>>     public void buildFromAttributes() {
>>         System.out.println("Got here, buildFromAttributes()");
>>         super.buildFromAttributes();
>>         MIDI.bendPitch(getChannel(), MidiIO.PITCH_BEND_CENTER);
>>         MIDI.bendPitch(getChannel2(), MidiIO.PITCH_BEND_CENTER + 2048);
>>         System.out.println("Pitch Bend " + MIDI.PITCH_BEND + 
>> "\t\tPitch Bend Center"
>>                 + MIDI.PITCH_BEND_CENTER);
>>         // Set both channels to full volume
>>         MIDI.control(getChannel(), MIDI.MIDI_VOLUME_CONTROL_INDEX, 127);
>>         MIDI.control(getChannel2(), MIDI.MIDI_VOLUME_CONTROL_INDEX, 
>> 127);
>>
>>     }
>>
>>     @Override
>>     public String getName() {
>>         return "Quarter-Tone MIDI Instrument (2 Ch.)";
>>     }
>>
>>     @Override
>>     public double play(double playtime, double timestretch, double[] 
>> dim) {
>>         double pitch = dim[1];
>>         double roundedPitch = Math.round(pitch * 2) * 0.5;
>>         double[] scaledVelDim = dim;
>>         scaledVelDim[2] = dim[2] * 127.;
>>
>>         if (roundedPitch - Math.floor(roundedPitch) == 0) {
>>             return ins1.play(playtime, timestretch, scaledVelDim);
>>         } else {
>>             return ins2.play(playtime, timestretch, scaledVelDim);
>>         }
>>     }
>>
>>     @Override
>>     public int getProgram() {
>>         return ins1.getProgram();
>>     }
>>
>>     @Override
>>     public void setProgram(int program) {
>>         ins1.setProgram(program);
>>         ins2.setProgram(program);
>>     }
>>
>>     @Override
>>     public Interpreter getInterpreter() {
>>         return ins1.getInterpreter();
>>     }
>>
>>     @Override
>>     public void setInterpreter(Interpreter interpreter) {
>>         if ((ins1 != null) && (ins2 != null)) {
>>             ins1.setInterpreter(interpreter);
>>             ins2.setInterpreter(interpreter);
>>         }
>>         super.setInterpreter(interpreter);
>>     }
>>
>>     @Override
>>     public DimensionNameSpace getDimensionNameSpace() {
>>         return ins1.getDimensionNameSpace();
>>     }
>>
>>     @Override
>>     public void setDimensionNameSpace(DimensionNameSpace dns) {
>>         if ((ins1 != null) && (ins2 != null)) {
>>             ins1.setDimensionNameSpace(dns);
>>             ins2.setDimensionNameSpace(dns);
>>         }
>>         super.setDimensionNameSpace(dns);
>>     }
>>
>>     @Override
>>     public double update(double playtime, double timestretch, 
>> double[] dim) {
>>         double pitch = dim[1];
>>         double roundedPitch = Math.round(pitch * 2) * 0.5;
>>         double[] scaledVelDim = dim;
>>         scaledVelDim[2] = dim[2] * 127.;
>>
>>         if (roundedPitch - Math.floor(roundedPitch) == 0) {
>>             return ins1.update(playtime, timestretch, scaledVelDim);
>>         } else {
>>             return ins2.update(playtime, timestretch, scaledVelDim);
>>         }
>>     }
>>
>>     public MidiInstrument getIns1() {
>>         return ins1;
>>     }
>>
>>     public void setIns1(MidiInstrument ins1) {
>>         this.ins1 = ins1;
>>     }
>>
>>     public MidiInstrument getIns2() {
>>         return ins2;
>>     }
>>
>>     public void setIns2(MidiInstrument ins2) {
>>         this.ins2 = ins2;
>>     }
>>
>>     @Override
>>     public double getTransposition() {
>>         return ins1.getTransposition();
>>     }
>>
>>     @Override
>>     public void setTransposition(double transposition) {
>>         ins1.setTransposition(transposition);
>>         ins2.setTransposition(transposition);
>>     }
>>
>>     @Override
>>     public int getNumOutputs() {
>>         return 2;
>>     }
>>
>>     @Override
>>     public int getChannel() {
>>         return ins1.getChannel();
>>     }
>>
>>     @Override
>>     public void setChannel(int channel) {
>>         ins1.setChannel(channel);
>>         if (channel + 1 == 10) {
>>             ins2.setChannel(11);
>>         } else {
>>             ins2.setChannel(channel + 1);
>>         }
>>     }
>>
>>     public int getChannel2() {
>>         if (ins1.getChannel() + 1 != 10) {
>>             return ins1.getChannel() + 1;
>>         } else {
>>             return 11;
>>         }
>>     }
>>
>>     @Override
>>     public double close(double time) throws InterruptedException {
>>         ins1.close(time);
>>         return ins2.close(time);
>>     }
>>
>>     @Override
>>     public double open(double time) throws InterruptedException {
>>         ins1.open(time);
>>         return ins2.open(time);
>>     }
>>
>>     @Override
>>     public Object getOutput() {
>>         return ins1.getOutput();
>>     }
>>
>>     @Override
>>     public Object getOutput(int outNum) {
>>         System.out.println("******OutNumber:\t" + outNum);
>>         if (outNum == 0) {
>>             return ins1.getOutput();
>>         } else {
>>             return ins2.getOutput();
>>         }
>>     }
>>
>>     @Override
>>     public void setMusicDevice(MusicDevice device) {
>>         super.setMusicDevice(device);
>>         if ((ins1 != null) && (ins2 != null)) {
>>             ins1.setMusicDevice(device);
>>             ins2.setMusicDevice(device);
>>         }
>>     }
>>
>>     @Override
>>     public void setMixerClassName(String mixerClassName) {
>>         if ((ins1 != null) && (ins2 != null)) {
>>             ins1.setMixerClassName(mixerClassName);
>>             ins2.setMixerClassName(mixerClassName);
>>         }
>>         super.setMixerClassName(mixerClassName);
>>     }
>>
>>     public static void main(String args[]) {
>>         // plays a quarter-tone scale, and then a chord to 
>> demonstrate playback.
>>
>>         ScoreFrame frame = new ScoreFrame();
>>
>>         Score score = new Score(1);
>>         score.addMeasures(10, 3, 4);
>>
>>         for (double x = 0.; x < 12.; x = x + 0.5) {
>>             // System.out.println(x + 60.);
>>             Note n = NoteFactory.makeNote(0.25, x + 60., 1, 0.25);
>>             score.addNote(n);
>>             if (x % 2. != 1.5) {
>>                 n.setBeamedOut(true);
>>             }
>>         }
>>
>>         for (int i = 0; i < 6; i++) {
>>             Note n = NoteFactory.makeNote(0.5, 60., 1., 0.5);
>>             score.addNote(n);
>>             n.addInterval(64.);
>>             n.addInterval(67);
>>             n.addInterval(72.5);
>>             if (i % 4 != 1) {
>>                 n.setBeamedOut(true);
>>             }
>>
>>         }
>>
>>         frame.addScore(score);
>>
>>         QuarterToneTwoChannelMidiInstrument dc = new 
>> QuarterToneTwoChannelMidiInstrument();
>>         dc.setChannel(1);
>>         dc.getMusicDevice().open();
>>         dc.buildFromAttributes();
>>
>>         frame.addInstrument(dc);
>>
>>         // This works fine!
>>         try {
>>             Class testClass = 
>> Class.forName(QuarterToneTwoChannelMidiInstrument.class
>>                     .getCanonicalName());
>>         } catch (ClassNotFoundException e1) {
>>             System.out.println("Error with System class loader");
>>             e1.printStackTrace();
>>         }
>>
>>         try {
>>             Class testClass2 = 
>> JMSLClassLoader.load(QuarterToneTwoChannelMidiInstrument.class
>>                     .getCanonicalName());
>>         } catch (ClassNotFoundException e1) {
>>             System.out.println("Error with JMSLClassLoader");
>>             e1.printStackTrace();
>>         }
>>
>>         frame.addWindowListener(new WindowAdapter() {
>>             public void windowClosing(WindowEvent e) {
>>                 JMSL.closeMusicDevices(); // be nice!
>>                 System.exit(0);
>>             }
>>         });
>>
>>         frame.pack();
>>         frame.setVisible(true);
>>
>>     }
>>
>> }
>>
>> _______________________________________________
>> jmsl mailing list
>> jmsl at music.columbia.edu
>> http://music.columbia.edu/mailman/listinfo/jmsl
> _______________________________________________
> jmsl mailing list
> jmsl at music.columbia.edu
> http://music.columbia.edu/mailman/listinfo/jmsl


More information about the jmsl mailing list