[jmsl] Rest toggle - cool!
jmsl at music.columbia.edu
jmsl at music.columbia.edu
Thu Mar 19 07:41:11 EDT 2009
Hi Peter
Here's source for RestToggle Transform...
Nick
package com.softsynth.jmsl.score.transforms;
import java.util.Enumeration;
import java.util.Hashtable;
import com.softsynth.jmsl.score.*;
/**
* Toggle a note between rest and pitch
*
* @author Nick Didkovsky, copyright 2000 Nick Didkovsky, all rights
reserved
*
*/
public class RestToggleTransform extends NotePropertiesTransform {
Hashtable oldValues = new Hashtable();
public RestToggleTransform() {
setName("Rest Toggle");
}
/**
* If a note is NOT a rest, make it a rest. If it IS a rest, make it
middle C. If it is a rest
* which used to be a note, then change it back to the original
pitch. A Note is made into a
* rest by setting its pitch data to 0, followed by
NoteFactory.updateFromPitch(note);
*
*/
public void operate(Score score, SelectionBuffer selectionBuffer) {
for (Enumeration e = selectionBuffer.elements();
e.hasMoreElements();) {
Note note = (Note) e.nextElement();
if (note.isRest()) {
double pitch = NoteFactory.MIDDLE_C;
if (oldValues.containsKey(note)) {
pitch = ((Double) oldValues.get(note)).doubleValue();
}
note.setPitchData(pitch);
note.setVelData(0.5);
} else {
oldValues.put(note, new Double(note.getPitchData()));
note.setPitchData(0);
}
NoteFactory.updateFromPitch(note);
}
score.setDirty(true);
}
public static final String copyright = "copyright (C) 2000 Nick
Didkovsky, all rights reserved";
}
jmsl at music.columbia.edu wrote:
> Hi Nick,
>
> I was poking around with the newish release of JMSL and discovered the
> RestToggleTransform. It works great (on chords too!), but I'm unclear
> as to how it's working.
>
> From what I can tell, the pitch data is being changed, but how is the
> old pitch data being stored? Even if I go off and transform some
> other notes, I can still come back and switch around the old notes.
>
> The notes don't have a userBean added to them, and the dns changes the
> pitch data to 0. to make rests. Making changes to the note, such as
> changing duration or inserting notes in front of it (or adding
> intervals) doesn't prevent it from working.
>
> The only thing that makes it forget its pitch is if you change a note
> to a rest, copy the rest, and paste it. Then the rest is restored as
> middle C (as would happen with notes that were initially entered as
> rests).
>
> In any case, I was just curious how you did this and wondering if I
> was missing something obvious. It's definitely a great addition to
> the JMSL toolkit!
>
> thanks,
> Peter McCulloch
> _______________________________________________
> jmsl mailing list
> jmsl at music.columbia.edu
> http://music.columbia.edu/mailman/listinfo/jmsl
More information about the jmsl
mailing list