Page 1 of 4 123 ... LastLast
Results 1 to 20 of 78

Thread: midi bytes

  1. #1
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default midi bytes

    I´d like to do some very bassic midi things:
    How can one read and write a single midi byte in java?

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,443
    Rep Power
    25

    Default

    What is a "single midi byte"?
    There are classes and methods in the io package that will read/write a byte at a time.
    Look in the API doc Index for readByte() & writeByte() for the different classes that will do that.

  3. #3
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default

    Norm,

    I am transforming a twenty year old pascal program into java code
    The old program sets a clock and sends midi numbers (int) to a midi port (it worked in pascal on an old atari)
    like this:

    procedure midi_instrument(kan, instr :integer);
    begin
    midi_out(240);
    midi_out(67);
    midi_out(117);
    midi_out(112);
    midi_out(64+kan-1);
    midi_out(instr-1);
    midi_out(247);
    end;
    The easiest way would be doing something similar.
    That would be writeByte() to a midi port?
    I am looking into the midi api stuff (e.e. setMessage();
    but it is hard get to the basics!

  4. #4
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default

    A more advanced approach (present in most midi related classes) would mean that I have to re-write 40 pages of code. The program sends the midi data to a old sound module (Yamaha fbo1) through a serial midi interface. There are also so-called midi exclusive data involved (producing 1/4 tones etc.). So I do need a kind of primitive "midi-machine-languages" approach. The clock will synchronize each byte by byte send to the module.

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,443
    Rep Power
    25

    Default

    Sorry, I have no experience with sound generation hardware.
    I just move data around.

  6. #6
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Red face That's what sound is.

    Quote Originally Posted by Norm View Post
    Sorry, I have no experience with sound generation hardware.
    I just move data around.
    Norm, there is an open source project called FLAC, which could really use some data moving around in Java. It is just moving data packets for the most part. There are some deeper, more skilled issues in calling the driver that actually converts the data to play on a machine but this is front line work in Java which could really use the skills of an experienced programmer.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  7. #7
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default

    Sure Norm,
    for me music is music
    for a programmer music is data?

  8. #8
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default

    so first step to get midi out would be

    try {
    midin = MidiSystem.getReceiver();
    midiout = MidiSystem.getTransmitter();
    }
    catch (MidiUnavailableException mue) {
    System.out.println(mue);
    }
    midiout.close();
    midin.close();

  9. #9
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default

    next step won´t work

    midiout = new ShortMessage();

    public static void midi_out (int md) {
    try {
    midiout.setMessage(md);
    } catch (InvalidMidiDataException ex) {
    ex.printStackTrace();
    System.out.println(ex);
    }

  10. #10
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default

    the above is changed in

    try {
    laadresource("citesresource.txt");
    } catch (IOException ex) {
    ex.printStackTrace();
    }

    try {
    m_in = MidiSystem.getReceiver();
    m_out = MidiSystem.getTransmitter();
    }
    catch (MidiUnavailableException mue) {
    System.out.println(mue);
    }
    System.out.println(m_out);
    m_out.close();
    m_in.close();

  11. #11
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,443
    Rep Power
    25

    Default

    For a programmer data is 8 bits/byte etc.
    The meaning of data depends on what program you feed it to.
    The same bits can be instructions to execute by a CPU to do some task or they can represent a graph or they can create sounds, or or or. It all depends on the hardward/software's usage of the data.

    Ultimately everything on a computer is data!!!

  12. #12
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default

    Norm,

    I am not a professional programmer and probably I do not express myself well. What I understand of the matter is that midi data is expressed in bytes, and each byte contains all/ most information to play a single tone. Of course midi is not audio data. Midi works similar as the old fashioned cards with small wholes that where used to make a mechanical organ play tunes (you see them a lot in Amsterdam). Each series of wholes/ byte would mean: play that instrument, with such, pitch and dynamics etc.

    I believe now days most midi is send in packages (a lot of bytes together). What I want to do is controlle the data transmission from the bottom part and send each data byte (which means a tone and sometimes something else) synchronized by a clock. The thing is I cannot figure out how to send a single midi number 0-256 to the midi out port of my mac book.

  13. #13
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Exclamation music is data

    Quote Originally Posted by willemjav View Post
    I am not a professional programmer and probably I do not express myself well. What I understand of the matter is that midi data is expressed in bytes, and each byte contains all/ most information to play a single tone.
    The base Java midi implementation runs at around eight kilohertz data rate, shipping bytes and so on to a port is a very low-level operation that has to be done by driver that is already written by professional programmer. Writing a compiler for midi is deeply involved in system issues that are not going to resolove with a fifteen line program written by shipping a few bytes to an i/o port. If you are a musician by nature, I suggest looking at some ready made tools available commercially.

    Quote Originally Posted by willemjav View Post
    Of course midi is not audio data. Midi works similar as the old fashioned cards with small wholes that where used to make a mechanical organ play tunes (you see them a lot in Amsterdam). Each series of wholes/ byte would mean: play that instrument, with such, pitch and dynamics etc.
    Try writing a wav / midi translator to start, you will find out there are a bunch of issues involved.

    Quote Originally Posted by willemjav View Post
    I believe now days most midi is send in packages (a lot of bytes together). What I want to do is control the data transmission from the bottom part and send each data byte (which means a tone and sometimes something else) synchronized by a clock. The thing is I cannot figure out how to send a single midi number 0-256 to the midi out port of my mac book.
    Norm, there are system issues that will not be apparent to this poster. Midi was originally written for eight bit data packets, with all the control information directly in the channel. The datastream has to be de-multiplexed and cleaned up, it is a very primitive format. Drivers exist in production that can do the work, but I see context switching at an enormous rate when they are used to drive the machine. Dedicated experimenter boards for the bench tech are recommended. There are plenty of people in Europe who are into this heavily, a brief search should find hundreds of them.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  14. #14
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default

    I might have to accept that with java/oo and all those wonderful issues of high level programming makes it impossible to send a single midi byte to a device. Nicholas by taken a quick glance at my old pascal code, WILLEM DRAGSTRA WEB SITE you’ll understand that, that is what I desperately need to make the Cités electronic music component of the cello and voice piece to sound again (should be performed in Holland in october).

    The program calculates midi numbers and sends them (one by one) out to the port.... that is all there and I know that is pretty primitive.... but the irony is that, that is hard to do with now-a-days java?
    Nicholas, maybe music is data, but for sure data is no music!

  15. #15
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default

    here is some old stuff
    JavaMidi_home

  16. #16
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default here's the data packet

    Quote Originally Posted by Norm View Post
    Sorry, I have no experience with sound generation hardware.
    I just move data around.
    ( note this code would be called in JNI, this is not Java code )
    Java Code:
    long MPGetMessageLength (unsigned char statusByte)
    {
                                              /* 8n 9n An Bn Cn Dn En */
        static const char ChannelLenTable[]  = { 3, 3, 3, 3, 2, 2, 3 };
    
                                              /* F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 FA FB FC FD FE FF */
        static const char SystemLenTable[]   = { 0, 2, 3, 2, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1 };  /* 0 for undefined (or unknown for F0) */
    Welcome to systems programming minus some java protections. Ever heard of a runaway pointer?

    Java Sound API: Java Sound Demo

    javax.sound.midi (Java 2 Platform SE 5.0)
    Last edited by Nicholas Jordan; 07-22-2008 at 12:45 AM. Reason: add link
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  17. #17
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default

    no I haven´t nicholas
    but I heard of thread killers
    So for the moment no midi_in midi_out in java?

  18. #18
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,443
    Rep Power
    25

    Default

    single ... byte to a device
    How is the device connect to the computer?
    How would you connect to that device from a java program?

    Given the above,
    In java you can use a write() method to write a single byte.

  19. #19
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default

    Modern midi devices are usb connected
    The old fashioned ones are the din-plugged (five pins) serial connectors.
    I would like to connect the device from a old mac G4 comp with a audio midi card (m audio delta) which has that old fashioned midi interface (the fbo module has no usb).
    the m_out = MidiSystem.getTransmitter(); might look for that card?

    thanks norm, thread is alive

  20. #20
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default

    I forgot to say norm old mac use OMS as midi driver, but the card has its own drivers.

Page 1 of 4 123 ... LastLast

Similar Threads

  1. DES algorithm (Read and Write bytes to file)
    By JoaoPe in forum Advanced Java
    Replies: 6
    Last Post: 07-29-2008, 03:46 PM
  2. Reading bytes from InputStream
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-25-2007, 07:51 PM
  3. how to know the number of bytes
    By gabriel in forum New To Java
    Replies: 2
    Last Post: 08-06-2007, 05:13 PM
  4. help with midi files
    By leonard in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 04:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •