0

I have been using Matlab for some time, but have just started using Octave. I am trying to read a midi file using the following code on my Windows machine:

javaaddpath('C:/Program Files/Java/jdk1.8.0_45/jre/lib/rt.jar');
midiFile = javaObject('java.io.File', file_name);
if ~midiFile.exists
    error('Unable to find file %s',file_name);
end

seq = javaObject('javax.sound.midi.MidiSystem.getSequence', midiFile);

But I am getting the following error:

error: [java] java.lang.ClassNotFoundException: javax.sound.midi.MidiSystem.getSequence

What am I doing wrong?

Thanks!

user1340654
  • 395
  • 2
  • 5
  • 16

1 Answers1

0

The function javaObject() is used to call a class constructor. However, getSequence() is a "normal" method of the javax.sound.midi.MidiSystem class.

octave> help javaObject 

 -- Built-in Function: JOBJ = javaObject (CLASSNAME)
 -- Built-in Function: JOBJ = javaObject (CLASSNAME, ARG1, ...)
     Create a Java object of class CLASSSNAME, by calling the class
     constructor with the arguments ARG1, ...

octave> man javaMethod 
 -- Built-in Function: RET = javaMethod (METHODNAME, OBJ)
 -- Built-in Function: RET = javaMethod (METHODNAME, OBJ, ARG1, ...)
     Invoke the method METHODNAME on the Java object OBJ with the
     arguments ARG1, ....

     For static methods, OBJ can be a string representing the fully
     qualified name of the corresponding class.

Note that typically, the second argument to javaMethod is an object, but can also be a string with the class name. Therefore, you need to do:

octave> midiFile = javaObject ("java.io.File", "Downloads/MIDI_sample.mid");
octave> seq = javaMethod ("getSequence", "javax.sound.midi.MidiSystem", midiFile )
seq =

<Java object: javax.sound.midi.Sequence>
carandraug
  • 12,938
  • 1
  • 26
  • 38