|
|
Welcome to the Java Forums.
You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:
- have access to post topics
- communicate privately with other members (PM)
- not see advertisements between posts
- have the possibility to earn one of our surprises if you are an active member
- access many other special features that will be introduced later.
Registration is fast, simple and absolutely free so please, join our community today!
If you have any problems with the registration process or your account login, please contact us.
|
|

07-20-2008, 10:16 PM
|
|
Senior Member
|
|
Join Date: Dec 2007
Location: Spain
Posts: 342
|
|
|
midi bytes
I´d like to do some very bassic midi things:
How can one read and write a single midi byte in java?
|
|

07-20-2008, 10:28 PM
|
 |
Senior Member
|
|
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,225
|
|
|
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.
|
|

07-20-2008, 11:41 PM
|
|
Senior Member
|
|
Join Date: Dec 2007
Location: Spain
Posts: 342
|
|
|
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!
|
|

07-21-2008, 12:22 AM
|
|
Senior Member
|
|
Join Date: Dec 2007
Location: Spain
Posts: 342
|
|
|
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.
|
|

07-21-2008, 01:54 AM
|
 |
Senior Member
|
|
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,225
|
|
|
Sorry, I have no experience with sound generation hardware.
I just move data around.
|
|

07-21-2008, 04:28 AM
|
 |
Senior Member
|
|
Join Date: Jun 2008
Location: Southwest
Posts: 880
|
|
|
That's what sound is.
Originally Posted by Norm
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.
__________________
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. .
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
|
|

07-21-2008, 12:00 PM
|
|
Senior Member
|
|
Join Date: Dec 2007
Location: Spain
Posts: 342
|
|
|
Sure Norm,
for me music is music
for a programmer music is data?
|
|

07-21-2008, 12:37 PM
|
|
Senior Member
|
|
Join Date: Dec 2007
Location: Spain
Posts: 342
|
|
|
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();
|
|

07-21-2008, 01:14 PM
|
|
Senior Member
|
|
Join Date: Dec 2007
Location: Spain
Posts: 342
|
|
|
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);
}
|
|

07-21-2008, 02:34 PM
|
|
Senior Member
|
|
Join Date: Dec 2007
Location: Spain
Posts: 342
|
|
|
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();
|
|

07-21-2008, 05:48 PM
|
 |
Senior Member
|
|
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,225
|
|
|
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!!!
|
|

07-21-2008, 06:49 PM
|
|
Senior Member
|
|
Join Date: Dec 2007
Location: Spain
Posts: 342
|
|
|
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.
|
|

07-21-2008, 09:06 PM
|
 |
Senior Member
|
|
Join Date: Jun 2008
Location: Southwest
Posts: 880
|
|
|
music is data
Originally Posted by willemjav
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.
Originally Posted by willemjav
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.
Originally Posted by willemjav
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.
__________________
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. .
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
|
|

07-21-2008, 10:19 PM
|
|
Senior Member
|
|
Join Date: Dec 2007
Location: Spain
Posts: 342
|
|
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!
|
|

07-21-2008, 10:57 PM
|
|
Senior Member
|
|
Join Date: Dec 2007
Location: Spain
Posts: 342
|
|
here is some old stuff
JavaMidi_home
|
|

07-21-2008, 11:30 PM
|
 |
Senior Member
|
|
Join Date: Jun 2008
Location: Southwest
Posts: 880
|
|
|
here's the data packet
Originally Posted by Norm
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 )
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)
__________________
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. .
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
Last edited by Nicholas Jordan : 07-22-2008 at 02:45 AM.
Reason: add link
|
|

07-21-2008, 11:54 PM
|
|
Senior Member
|
|
Join Date: Dec 2007
Location: Spain
Posts: 342
|
|
|
no I haven´t nicholas
but I heard of thread killers
So for the moment no midi_in midi_out in java?
|
|

07-22-2008, 12:19 AM
|
 |
Senior Member
|
|
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,225
|
|
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.
|
|

07-22-2008, 12:28 AM
|
|
Senior Member
|
|
Join Date: Dec 2007
Location: Spain
Posts: 342
|
|
|
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
|
|

07-22-2008, 12:34 AM
|
|
Senior Member
|
|
Join Date: Dec 2007
Location: Spain
Posts: 342
|
|
|
I forgot to say norm old mac use OMS as midi driver, but the card has its own drivers.
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|