concrete subclasses

Hi

I have to edit a midi file. When I get the data byte[ ] from a MidiMessage and I edit it, I can't invoke the constructor MidiMessage(byte[ ]) because it's protected and "can be called only by concrete subclasses". So how can I rebuilt my sequence after editing it?

Thak you for your help

[312 byte] By [fedeeea] at [2007-11-26 18:42:23]
# 1
Just a guess: There is some kind of a factory method - of another class, or possibly the Midi class - which will return a new object.
bschauwejavaa at 2007-7-9 6:16:23 > top of Java-index,Java Essentials,Java Programming...
# 2
There is another method but it's protected http://java.sun.com/j2se/1.4.2/docs/api/javax/sound/midi/MidiMessage.htmlMaybe should I build a concrete subclass but I don't know how
fedeeea at 2007-7-9 6:16:23 > top of Java-index,Java Essentials,Java Programming...
# 3
MidiMessage is abstract, isn't it? What about one of its concrete subclasses, like SysexMessage? The MidiMessage you are tinkering with -- what class is it an instance of:String classname = myMidiMessage.getClass().getName();
DrLaszloJamfa at 2007-7-9 6:16:23 > top of Java-index,Java Essentials,Java Programming...
# 4

Thank you for your help but I'm not an expert java user and I didn't understand, sorry:

also the subclasses like SysexMessage and ShortMessage have protected constructors. Try to explain better:

If I write:

byte [] bla = MyMidiMessage.getMessage();

// edit the byte[]

now I'd like to do

AnotherMidiMessage = MidiMessage(editedbyte[]);

But I can't. Maybe I didn't understand the code you wrote.

fedeeea at 2007-7-9 6:16:23 > top of Java-index,Java Essentials,Java Programming...
# 5
So you want to create a new MidiMessage and stuff those bytes into it? Then as DrLJ said, create an instance of whichever subclass you need (that would be your decision) and call its setMessage() method.
DrClapa at 2007-7-9 6:16:23 > top of Java-index,Java Essentials,Java Programming...
# 6

1. MidiMessage is an abstract class. Do you know what that means? It means you can't create an instance of the class.

2. What class is you current midi message object an instance of? What does this print?

System.out.println(yourMidiMessage.getClass());

3. I don't know anything about midi, but I can read documentation. The class I mentioned, SysexMessage is not abstract and has a public constructor and public setMessage methods. Try using them and see if they work.

DrLaszloJamfa at 2007-7-9 6:16:23 > top of Java-index,Java Essentials,Java Programming...
# 7

Thank you all for the help, guys.

The message I want to edit is an instance of the MidiMessage class, not created by me but read from a file.

I tried with the ShortMessage constructor, since a "note on" message should belong to this class, but when I replace the original message with the one I bult the sequence becomes unreadable. Surely I'm doing something in the wrong way, but I don't know what. I'd need some code... Surely it's a simple thing to do if one knows how to....

Thank you again

P.s. by the way, I found the Messages in the file are instances of com.sun.media.sound.FastShortMessage and I can find no doc for that package, bt my editor says that class's not visible

fedeeea at 2007-7-9 6:16:23 > top of Java-index,Java Essentials,Java Programming...