Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rutgers!ames!cit-vax!rgoodman From: rgoodman@cit-vax.Caltech.Edu (Ron Carl Goodman) Newsgroups: comp.sys.atari.st Subject: Re: reading from the midi port Message-ID: <2087@cit-vax.Caltech.Edu> Date: Thu, 19-Mar-87 19:32:47 EST Article-I.D.: cit-vax.2087 Posted: Thu Mar 19 19:32:47 1987 Date-Received: Sat, 21-Mar-87 07:30:33 EST References: <14085@cca.CCA.COM> Reply-To: rgoodman@cit-vax.UUCP (Ron Carl Goodman) Organization: California Institute of Technology Lines: 42 In article <14085@cca.CCA.COM> you write: >... >grabs midi data a byte at a time and stuffs it into an array...when the >array reaches a length of 78 it is displayed on the screen and a new >string starts getting written. My problem is that I hook up a sequencer >to my ST and start it putting out midi data and start running my program. >My program always displays 4 or 5 lines of midi data then exits the program. >My program is basically built with a big 'while' loop which says >'while data is at the midi in port do blah blah blah'. The problem is really that your ST is a fast computer! When your sequencer is plopping out data, your ST reads it in. At first, before your program is going, the data is stored in the 128 byte midi buffer. As you read the data, more is being placed in the buffer, but the sequencer does not spew out data as fast as the ST reads the data. So your buffer is eventually depleted. When the ST catches up (based on when you ran the program in relation to turning on the sequencer) your ST will make a request for data and there will be none waiting. A fraction of a second later, some will be waiting, but its too late... your while loop has fallen through. One solution is to use something that checks the port N times before deciding that no more data is truly there (to be sure that no more is coming). N can be found experimentally. 300 is plenty. This kind of method is sort of icky, because N may not work when this program is run on a different computer. Another solution is to call a system timer with a delay of like 1/10 of a second and check again before determining no data is left. By the way, you might wonder how this method works, since the time between two notes could actually be far more than 1/10th of a second. Sequencers put out timing signals as part of the MIDI code (I think 247) at a constant rate to solve that problem. Unfortunately, there is no standard END_OF_ SEQUENCE marker. Ron Goodman -- rgoodman@cit-vax.caltech.edu _______ _________ _________ | rgoodman@cit-vax.bitnet / \#/ \#/ | Pasadena rgoodman@cit-vax.uucp |alifornia |nstitute |echnology | California \_______ ___/#\___ of | | U. S. A.