jdk/src/share/classes/javax/sound/midi/Sequence.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1999-2004 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.sound.midi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import com.sun.media.sound.MidiUtils;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * A <code>Sequence</code> is a data structure containing musical
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * information (often an entire song or composition) that can be played
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * back by a <code>{@link Sequencer}</code> object. Specifically, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * <code>Sequence</code> contains timing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * information and one or more tracks.  Each <code>{@link Track track}</code> consists of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * series of MIDI events (such as note-ons, note-offs, program changes, and meta-events).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * The sequence's timing information specifies the type of unit that is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * to time-stamp the events in the sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * A <code>Sequence</code> can be created from a MIDI file by reading the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * into an input stream and invoking one of the <code>getSequence</code> methods of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * {@link MidiSystem}.  A sequence can also be built from scratch by adding new
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <code>Tracks</code> to an empty <code>Sequence</code>, and adding
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <code>{@link MidiEvent}</code> objects to these <code>Tracks</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * @see Sequencer#setSequence(java.io.InputStream stream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * @see Sequencer#setSequence(Sequence sequence)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * @see Track#add(MidiEvent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * @see MidiFileFormat
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * @author Kara Kytle
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
public class Sequence {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    // Timing types
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * The tempo-based timing type, for which the resolution is expressed in pulses (ticks) per quarter note.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * @see #Sequence(float, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    public static final float PPQ                                                       = 0.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * The SMPTE-based timing type with 24 frames per second (resolution is expressed in ticks per frame).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * @see #Sequence(float, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    public static final float SMPTE_24                                          = 24.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * The SMPTE-based timing type with 25 frames per second (resolution is expressed in ticks per frame).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * @see #Sequence(float, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    public static final float SMPTE_25                                          = 25.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * The SMPTE-based timing type with 29.97 frames per second (resolution is expressed in ticks per frame).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * @see #Sequence(float, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    public static final float SMPTE_30DROP                                      = 29.97f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * The SMPTE-based timing type with 30 frames per second (resolution is expressed in ticks per frame).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * @see #Sequence(float, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    public static final float SMPTE_30                                          = 30.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    // Variables
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * The timing division type of the sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * @see #PPQ
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * @see #SMPTE_24
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * @see #SMPTE_25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * @see #SMPTE_30DROP
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * @see #SMPTE_30
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * @see #getDivisionType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    protected float divisionType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * The timing resolution of the sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @see #getResolution
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    protected int resolution;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * The MIDI tracks in this sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * @see #getTracks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    protected Vector<Track> tracks = new Vector<Track>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * Constructs a new MIDI sequence with the specified timing division
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * type and timing resolution.  The division type must be one of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * recognized MIDI timing types.  For tempo-based timing,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * <code>divisionType</code> is PPQ (pulses per quarter note) and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * the resolution is specified in ticks per beat.  For SMTPE timing,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * <code>divisionType</code> specifies the number of frames per
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * second and the resolution is specified in ticks per frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * The sequence will contain no initial tracks.  Tracks may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * added to or removed from the sequence using <code>{@link #createTrack}</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * and <code>{@link #deleteTrack}</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * @param divisionType the timing division type (PPQ or one of the SMPTE types)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * @param resolution the timing resolution
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * @throws InvalidMidiDataException if <code>divisionType</code> is not valid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * @see #PPQ
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * @see #SMPTE_24
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * @see #SMPTE_25
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * @see #SMPTE_30DROP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * @see #SMPTE_30
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @see #getDivisionType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * @see #getResolution
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * @see #getTracks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    public Sequence(float divisionType, int resolution) throws InvalidMidiDataException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        if (divisionType == PPQ)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            this.divisionType = PPQ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        else if (divisionType == SMPTE_24)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            this.divisionType = SMPTE_24;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        else if (divisionType == SMPTE_25)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            this.divisionType = SMPTE_25;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        else if (divisionType == SMPTE_30DROP)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            this.divisionType = SMPTE_30DROP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        else if (divisionType == SMPTE_30)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            this.divisionType = SMPTE_30;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        else throw new InvalidMidiDataException("Unsupported division type: " + divisionType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        this.resolution = resolution;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * Constructs a new MIDI sequence with the specified timing division
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * type, timing resolution, and number of tracks.  The division type must be one of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * recognized MIDI timing types.  For tempo-based timing,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * <code>divisionType</code> is PPQ (pulses per quarter note) and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * the resolution is specified in ticks per beat.  For SMTPE timing,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * <code>divisionType</code> specifies the number of frames per
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * second and the resolution is specified in ticks per frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * The sequence will be initialized with the number of tracks specified by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * <code>numTracks</code>. These tracks are initially empty (i.e.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * they contain only the meta-event End of Track).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * The tracks may be retrieved for editing using the <code>{@link #getTracks}</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * method.  Additional tracks may be added, or existing tracks removed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * using <code>{@link #createTrack}</code> and <code>{@link #deleteTrack}</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * @param divisionType the timing division type (PPQ or one of the SMPTE types)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * @param resolution the timing resolution
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * @param numTracks the initial number of tracks in the sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * @throws InvalidMidiDataException if <code>divisionType</code> is not valid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @see #PPQ
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * @see #SMPTE_24
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * @see #SMPTE_25
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * @see #SMPTE_30DROP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * @see #SMPTE_30
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * @see #getDivisionType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * @see #getResolution
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    public Sequence(float divisionType, int resolution, int numTracks) throws InvalidMidiDataException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        if (divisionType == PPQ)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            this.divisionType = PPQ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        else if (divisionType == SMPTE_24)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            this.divisionType = SMPTE_24;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        else if (divisionType == SMPTE_25)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            this.divisionType = SMPTE_25;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        else if (divisionType == SMPTE_30DROP)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            this.divisionType = SMPTE_30DROP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        else if (divisionType == SMPTE_30)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            this.divisionType = SMPTE_30;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        else throw new InvalidMidiDataException("Unsupported division type: " + divisionType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        this.resolution = resolution;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        for (int i = 0; i < numTracks; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            tracks.addElement(new Track());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * Obtains the timing division type for this sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * @return the division type (PPQ or one of the SMPTE types)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * @see #PPQ
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * @see #SMPTE_24
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * @see #SMPTE_25
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * @see #SMPTE_30DROP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * @see #SMPTE_30
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * @see #Sequence(float, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @see MidiFileFormat#getDivisionType()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    public float getDivisionType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        return divisionType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * Obtains the timing resolution for this sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * If the sequence's division type is PPQ, the resolution is specified in ticks per beat.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * For SMTPE timing, the resolution is specified in ticks per frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * @return the number of ticks per beat (PPQ) or per frame (SMPTE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * @see #getDivisionType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * @see #Sequence(float, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * @see MidiFileFormat#getResolution()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    public int getResolution() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        return resolution;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * Creates a new, initially empty track as part of this sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * The track initially contains the meta-event End of Track.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * The newly created track is returned.  All tracks in the sequence
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * may be retrieved using <code>{@link #getTracks}</code>.  Tracks may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * removed from the sequence using <code>{@link #deleteTrack}</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * @return the newly created track
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    public Track createTrack() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        Track track = new Track();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        tracks.addElement(track);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        return track;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * Removes the specified track from the sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * @param track the track to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * @return <code>true</code> if the track existed in the track and was removed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * otherwise <code>false</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * @see #createTrack
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * @see #getTracks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    public boolean deleteTrack(Track track) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        synchronized(tracks) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            return tracks.removeElement(track);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * Obtains an array containing all the tracks in this sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * If the sequence contains no tracks, an array of length 0 is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * @return the array of tracks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * @see #createTrack
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * @see #deleteTrack
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    public Track[] getTracks() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        return (Track[]) tracks.toArray(new Track[tracks.size()]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * Obtains the duration of this sequence, expressed in microseconds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * @return this sequence's duration in microseconds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    public long getMicrosecondLength() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        return com.sun.media.sound.MidiUtils.tick2microsecond(this, getTickLength(), null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * Obtains the duration of this sequence, expressed in MIDI ticks.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * @return this sequence's length in ticks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * @see #getMicrosecondLength
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    public long getTickLength() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        long length = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        synchronized(tracks) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            for(int i=0; i<tracks.size(); i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                long temp = ((Track)tracks.elementAt(i)).ticks();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                if( temp>length ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                    length = temp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            return length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * Obtains a list of patches referenced in this sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * This patch list may be used to load the required
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * <code>{@link Instrument}</code> objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * into a <code>{@link Synthesizer}</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * @return an array of <code>{@link Patch}</code> objects used in this sequence
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * @see Synthesizer#loadInstruments(Soundbank, Patch[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    public Patch[] getPatchList() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        // $$kk: 04.09.99: need to implement!!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        return new Patch[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
}