1 /* MidiFileWriter.java -- MIDI file writing services
2 Copyright (C) 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package javax
.sound
.midi
.spi
;
42 import java
.io
.IOException
;
43 import java
.io
.OutputStream
;
45 import javax
.sound
.midi
.Sequence
;
48 * MidiFileWriter provides MIDI file writing services.
50 * There are three types of Standard MIDI File (SMF) formats,
51 * represented by integers 0, 1, and 2.
53 * Type 0 files contain a single track and represents a single song
55 * Type 1 may contain multiple tracks for a single song performance.
56 * Type 2 may contain multiple tracks, each representing a
57 * separate song performance.
59 * See http://en.wikipedia.org/wiki/MIDI#MIDI_file_formats for more
62 * @author Anthony Green (green@redhat.com)
66 public abstract class MidiFileWriter
69 * Return the MIDI file types supported by this writer.
71 * @return the MIDI file types, or an empty array
73 public abstract int[] getMidiFileTypes();
76 * Return the MIDI file types supported by this writer for the
79 * @param sequence the sequence we'd like to write
80 * @return the MIDI file types, or an empty array
82 public abstract int[] getMidiFileTypes(Sequence sequence
);
85 * Returns true if this writer supports the given file type.
87 * @param fileType the file type we're asking about
88 * @return true if this writer supports fileType, false otherwise
90 public boolean isFileTypeSupported(int fileType
)
92 int types
[] = getMidiFileTypes();
93 for (int i
= types
.length
; i
> 0;)
95 if (types
[--i
] == fileType
)
102 * Returns true if this writer supports the given file type for the
105 * @param fileType the file type we're asking about
106 * @param sequence the sequence we'd like to write
107 * @return true if this writer supports fileType, false otherwise
109 public boolean isFileTypeSupported(int fileType
, Sequence sequence
)
111 int types
[] = getMidiFileTypes(sequence
);
112 for (int i
= types
.length
; i
> 0;)
114 if (types
[--i
] == fileType
)
121 * Write a sequence to a stream using the specified MIDI file type.
123 * @param in the sequence to write
124 * @param fileType the MIDI file type to use
125 * @param out the output stream to write to
126 * @return the number of byte written
127 * @throws IOException if an I/O exception happens
129 public abstract int write(Sequence in
, int fileType
, OutputStream out
)
133 * Write a sequence to a file using the specified MIDI file type.
135 * @param in the sequence to write
136 * @param fileType the MIDI file type to use
137 * @param out the file to write to
138 * @return the number of byte written
139 * @throws IOException if an I/O exception happens
141 public abstract int write(Sequence in
, int fileType
, File out
)