/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* MIDI file writer.
*
* @author Kara Kytle
* @author Jan Borgersen
*/
/**
* MIDI parser types
*/
private static final int types[] = {
};
/**
* new
*/
public int[] getMidiFileTypes() {
return localArray;
}
/**
* Obtains the file types that this provider can write from the
* sequence specified.
* @param sequence the sequence for which midi file type support
* is queried
* @return array of file types. If no file types are supported,
* returns an array of length 0.
*/
int typesArray[];
typesArray = new int[2];
} else {
typesArray = new int[1];
}
return typesArray;
}
return true;
}
}
return false;
}
int bytesRead = 0;
long bytesWritten = 0;
throw new IllegalArgumentException("Could not write MIDI file");
}
// First get the fileStream from this sequence
if (fileStream == null) {
throw new IllegalArgumentException("Could not write MIDI file");
}
buffer = new byte[bufferSize];
}
// Done....return bytesWritten
return (int) bytesWritten;
}
return bytesWritten;
}
//=================================================================================
int bytesBuilt = 0;
int headerLength = 14;
int length = 0;
int timeFormat;
float divtype;
// Determine the filetype to write
if( type==MIDI_TYPE_0 ) {
return null;
}
} else if( type==MIDI_TYPE_1 ) {
return null;
}
} else {
type = MIDI_TYPE_0;
type = MIDI_TYPE_1;
} else {
return null;
}
}
// Now build the file one track at a time
// Note that above we made sure that MIDI_TYPE_0 only happens
// if tracks.length==1
int trackCount = 0;
try {
trackCount++;
} catch (InvalidMidiDataException e) {
}
//bytesBuilt += trackStreams[i].getLength();
}
// Now seqence the track streams
if( trackCount == 1 ) {
} else if( trackCount > 1 ){
// fix for 5048381: NullPointerException when saving a MIDI sequence
// don't include failed track streams
if (trackStreams[i] != null) {
}
}
} else {
throw new IllegalArgumentException("invalid MIDI data in sequence");
}
// Now build the header...
hpos = new PipedOutputStream();
// Write the magic number
// Write the header length
// Write the filetype
if(type==MIDI_TYPE_0) {
} else {
// MIDI_TYPE_1
}
// Write the number of tracks
// Determine and write the timing format
} else {
// $$jb: 04.08.99: What to really do here?
return null;
}
// now construct an InputStream to become the FileStream
return fStream;
}
/**
* Returns ONE_BYTE, TWO_BYTE, SYSEX, META,
* ERROR, or IGNORE (i.e. invalid for a MIDI file)
*/
switch(byteValue) {
case 0xF0:
case 0xF7:
return SYSEX;
case 0xFF:
return META;
}
return IGNORE;
}
switch(byteValue & 0xF0) {
case 0x80:
case 0x90:
case 0xA0:
case 0xB0:
case 0xE0:
return TWO_BYTE;
case 0xC0:
case 0xD0:
return ONE_BYTE;
}
return ERROR;
}
int len = 1;
// first screen out leading zeros
// then write actual values
while (shift > 0) {
shift-=7;
len++;
}
return len;
}
private InputStream writeTrack( Track track, int type ) throws IOException, InvalidMidiDataException {
int bytesWritten = 0;
int lastBytesWritten = 0;
long currentTick = 0;
long deltaTick = 0;
long eventTick = 0;
int runningStatus = -1;
// -----------------------------
// Write each event in the track
// -----------------------------
for(int i=0; i<size; i++) {
int status;
int eventtype;
int metatype;
int length;
// get the tick
// $$jb: this gets easier if we change all system-wide time to delta ticks
// get the status byte
switch( eventtype ) {
case ONE_BYTE:
if(status!=runningStatus) {
}
break;
case TWO_BYTE:
if(status!=runningStatus) {
}
break;
case SYSEX:
// $$jb: 04.08.99: always write status for sysex
// $$jb: 10.18.99: we don't maintain length in
// the message data for SysEx (it is not transmitted
// over the line), so write the calculated length
// minus the status byte
// $$jb: 10.18.99: now write the rest of the
// message
break;
case META:
// $$jb: 10.18.99: getMessage() returns the
// entire valid midi message for a file,
// including the status byte and the var-length-int
// length value, so we can just write the data
// here. note that we must _always_ write the
// status byte, regardless of runningStatus.
break;
case IGNORE:
// ignore this event
break;
case ERROR:
// ignore this event
break;
default:
throw new InvalidMidiDataException("internal file writer error");
}
}
// ---------------------------------
// End write each event in the track
// ---------------------------------
// Build Track header now that we know length
bytesWritten += 8;
// Now sequence them
return fStream;
}
}