Hi. I am attempting to make a program that plays a midi file, like a sequencer would do, but also have the sequencer send off any NOTE_ON or NOTE_OFF messages to an external method. I have looked through the api and cannot find exactly what I am looking for. I was hoping someone on these forums could help.

I tried using the ControllerEventListener interface to read those messages, but it seems that it doesn't read NOTE_ON or NOTE_OFF messages. A MetaEventListener doesn't look like it would either.

This is what I came up with, but I'm not exactly sure how to implement it.

Although a transmitter claims to be able to send to "one or more Recievers", It just has a method to change Recievers, and not to add any.

I have thought of two options.
1. Open the source for the Transmitter class and have it send to an ArrayList of Recievers, instead of just one. (Not my first choice)
2. Add two transmitters or Recievers to the sequencer. (not sure how to do, as the only metohds are to return transmitters and recievers; not add any.)

I have been working on this for a while, and am getting tired of running into walls. Any help or comments would be appreciated. Thank you.

This java tutorial is helping me out some. I'll make sure and post any updates.

It's odd how writing a problem out can really help fix a problem. I found some code that does exactly what I want to do.

Transmitter   inPortTrans1, inPortTrans2;
        Receiver        synthRcvr;
        Receiver        seqRcvr;
        try 
        {
            inPortTrans1 = sequencer.getTransmitter();
            synthRcvr = new Drawer();
            inPortTrans1.setReceiver(synthRcvr);
            inPortTrans2 = sequencer.getTransmitter();
            seqRcvr = sequencer.getReceiver(); 
            inPortTrans2.setReceiver(seqRcvr);
        } 
        //sequencer has a midi file already read in. 


      // Drawer class
import javax.sound.midi.*;

public class Drawer implements Receiver
{
    public void close()
    {
        System.out.println("Do Nothing");
    }
    
    public void send(MidiMessage message, long timeStamp)
    {
        int status = message.getStatus();
        if (status == 144)
        {
            System.out.println(message.getLength());
            for (byte x : message.getMessage())
            {
                System.out.print(x + " ");
            }
            System.out.println("");
        }
    }
}

I still have to figure out which midi messages mean what, so I'm going to leave this thread as unanswered for now.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.