jdk/src/java.desktop/share/classes/javax/sound/midi/Sequence.java
author serb
Wed, 18 May 2016 20:40:17 +0300
changeset 38981 9521cb19e297
parent 26037 508779ce6619
child 40444 afabcfc2f3ef
permissions -rw-r--r--
8156169: Some sound tests rarely hangs because of incorrect synchronization Reviewed-by: prr, amenkov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
38981
9521cb19e297 8156169: Some sound tests rarely hangs because of incorrect synchronization
serb
parents: 26037
diff changeset
     2
 * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
2
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
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/**
26003
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
    31
 * A {@code Sequence} is a data structure containing musical information (often
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
    32
 * an entire song or composition) that can be played back by a {@link Sequencer}
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
    33
 * object. Specifically, the {@code Sequence} contains timing information and
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
    34
 * one or more tracks. Each {@link Track track} consists of a series of MIDI
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
    35
 * events (such as note-ons, note-offs, program changes, and meta-events). The
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
    36
 * sequence's timing information specifies the type of unit that is used to
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
    37
 * time-stamp the events in the sequence.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * <p>
26003
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
    39
 * A {@code Sequence} can be created from a MIDI file by reading the file into
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
    40
 * an input stream and invoking one of the {@code getSequence} methods of
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
    41
 * {@link MidiSystem}. A sequence can also be built from scratch by adding new
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
    42
 * {@code Tracks} to an empty {@code Sequence}, and adding {@link MidiEvent}
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
    43
 * objects to these {@code Tracks}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *
26003
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
    45
 * @author Kara Kytle
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * @see Sequencer#setSequence(java.io.InputStream stream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * @see Sequencer#setSequence(Sequence sequence)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * @see Track#add(MidiEvent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * @see MidiFileFormat
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
public class Sequence {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    // Timing types
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    /**
26003
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
    56
     * The tempo-based timing type, for which the resolution is expressed in
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
    57
     * pulses (ticks) per quarter note.
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
    58
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * @see #Sequence(float, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    public static final float PPQ                                                       = 0.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    /**
26003
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
    64
     * The SMPTE-based timing type with 24 frames per second (resolution is
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
    65
     * expressed in ticks per frame).
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
    66
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * @see #Sequence(float, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    public static final float SMPTE_24                                          = 24.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    /**
26003
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
    72
     * The SMPTE-based timing type with 25 frames per second (resolution is
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
    73
     * expressed in ticks per frame).
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
    74
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * @see #Sequence(float, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    public static final float SMPTE_25                                          = 25.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    /**
26003
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
    80
     * The SMPTE-based timing type with 29.97 frames per second (resolution is
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
    81
     * expressed in ticks per frame).
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
    82
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * @see #Sequence(float, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    public static final float SMPTE_30DROP                                      = 29.97f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    /**
26003
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
    88
     * The SMPTE-based timing type with 30 frames per second (resolution is
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
    89
     * expressed in ticks per frame).
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
    90
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * @see #Sequence(float, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    public static final float SMPTE_30                                          = 30.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    // Variables
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * The timing division type of the sequence.
26003
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
    99
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * @see #PPQ
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * @see #SMPTE_24
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * @see #SMPTE_25
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * @see #SMPTE_30DROP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * @see #SMPTE_30
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @see #getDivisionType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    protected float divisionType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * The timing resolution of the sequence.
26003
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   111
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * @see #getResolution
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    protected int resolution;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * The MIDI tracks in this sequence.
26003
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   118
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * @see #getTracks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    protected Vector<Track> tracks = new Vector<Track>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    /**
26003
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   124
     * Constructs a new MIDI sequence with the specified timing division type
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   125
     * and timing resolution. The division type must be one of the recognized
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   126
     * MIDI timing types. For tempo-based timing, {@code divisionType} is PPQ
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   127
     * (pulses per quarter note) and the resolution is specified in ticks per
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   128
     * beat. For SMTPE timing, {@code divisionType} specifies the number of
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   129
     * frames per second and the resolution is specified in ticks per frame. The
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   130
     * sequence will contain no initial tracks. Tracks may be added to or
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   131
     * removed from the sequence using {@link #createTrack} and
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   132
     * {@link #deleteTrack}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     *
26003
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   134
     * @param  divisionType the timing division type (PPQ or one of the SMPTE
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   135
     *         types)
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   136
     * @param  resolution the timing resolution
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   137
     * @throws InvalidMidiDataException if {@code divisionType} is not valid
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @see #PPQ
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * @see #SMPTE_24
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * @see #SMPTE_25
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * @see #SMPTE_30DROP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * @see #SMPTE_30
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @see #getDivisionType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * @see #getResolution
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @see #getTracks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    public Sequence(float divisionType, int resolution) throws InvalidMidiDataException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        if (divisionType == PPQ)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            this.divisionType = PPQ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        else if (divisionType == SMPTE_24)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            this.divisionType = SMPTE_24;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        else if (divisionType == SMPTE_25)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            this.divisionType = SMPTE_25;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        else if (divisionType == SMPTE_30DROP)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            this.divisionType = SMPTE_30DROP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        else if (divisionType == SMPTE_30)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            this.divisionType = SMPTE_30;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        else throw new InvalidMidiDataException("Unsupported division type: " + divisionType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        this.resolution = resolution;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    /**
26003
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   165
     * Constructs a new MIDI sequence with the specified timing division type,
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   166
     * timing resolution, and number of tracks. The division type must be one of
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   167
     * the recognized MIDI timing types. For tempo-based timing,
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   168
     * {@code divisionType} is PPQ (pulses per quarter note) and the resolution
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   169
     * is specified in ticks per beat. For SMTPE timing, {@code divisionType}
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   170
     * specifies the number of frames per second and the resolution is specified
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   171
     * in ticks per frame. The sequence will be initialized with the number of
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   172
     * tracks specified by {@code numTracks}. These tracks are initially empty
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   173
     * (i.e. they contain only the meta-event End of Track). The tracks may be
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   174
     * retrieved for editing using the {@link #getTracks} method. Additional
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   175
     * tracks may be added, or existing tracks removed, using
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   176
     * {@link #createTrack} and {@link #deleteTrack}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     *
26003
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   178
     * @param  divisionType the timing division type (PPQ or one of the SMPTE
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   179
     *         types)
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   180
     * @param  resolution the timing resolution
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   181
     * @param  numTracks the initial number of tracks in the sequence
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   182
     * @throws InvalidMidiDataException if {@code divisionType} is not valid
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * @see #PPQ
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * @see #SMPTE_24
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * @see #SMPTE_25
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * @see #SMPTE_30DROP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * @see #SMPTE_30
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * @see #getDivisionType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * @see #getResolution
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    public Sequence(float divisionType, int resolution, int numTracks) throws InvalidMidiDataException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        if (divisionType == PPQ)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            this.divisionType = PPQ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        else if (divisionType == SMPTE_24)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            this.divisionType = SMPTE_24;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        else if (divisionType == SMPTE_25)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            this.divisionType = SMPTE_25;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        else if (divisionType == SMPTE_30DROP)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            this.divisionType = SMPTE_30DROP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        else if (divisionType == SMPTE_30)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            this.divisionType = SMPTE_30;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        else throw new InvalidMidiDataException("Unsupported division type: " + divisionType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        this.resolution = resolution;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        for (int i = 0; i < numTracks; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            tracks.addElement(new Track());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * Obtains the timing division type for this sequence.
26003
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   214
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * @return the division type (PPQ or one of the SMPTE types)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * @see #PPQ
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * @see #SMPTE_24
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * @see #SMPTE_25
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * @see #SMPTE_30DROP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @see #SMPTE_30
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * @see #Sequence(float, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * @see MidiFileFormat#getDivisionType()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    public float getDivisionType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        return divisionType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    /**
26003
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   229
     * Obtains the timing resolution for this sequence. If the sequence's
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   230
     * division type is PPQ, the resolution is specified in ticks per beat. For
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   231
     * SMTPE timing, the resolution is specified in ticks per frame.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * @return the number of ticks per beat (PPQ) or per frame (SMPTE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * @see #getDivisionType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * @see #Sequence(float, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * @see MidiFileFormat#getResolution()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    public int getResolution() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        return resolution;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    /**
26003
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   243
     * Creates a new, initially empty track as part of this sequence. The track
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   244
     * initially contains the meta-event End of Track. The newly created track
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   245
     * is returned. All tracks in the sequence may be retrieved using
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   246
     * {@link #getTracks}. Tracks may be removed from the sequence using
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   247
     * {@link #deleteTrack}.
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   248
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * @return the newly created track
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    public Track createTrack() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        Track track = new Track();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        tracks.addElement(track);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        return track;
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
     *
26003
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   262
     * @param  track the track to remove
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   263
     * @return {@code true} if the track existed in the track and was removed,
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   264
     *         otherwise {@code false}
2
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) {
38981
9521cb19e297 8156169: Some sound tests rarely hangs because of incorrect synchronization
serb
parents: 26037
diff changeset
   269
        return tracks.removeElement(track);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    /**
26003
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   273
     * Obtains an array containing all the tracks in this sequence. If the
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   274
     * sequence contains no tracks, an array of length 0 is returned.
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   275
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * @return the array of tracks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * @see #createTrack
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * @see #deleteTrack
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    public Track[] getTracks() {
38981
9521cb19e297 8156169: Some sound tests rarely hangs because of incorrect synchronization
serb
parents: 26037
diff changeset
   281
        // Creation of the non-empty array will be synchronized inside toArray()
9521cb19e297 8156169: Some sound tests rarely hangs because of incorrect synchronization
serb
parents: 26037
diff changeset
   282
        return tracks.toArray(new Track[0]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * Obtains the duration of this sequence, expressed in microseconds.
26003
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   287
     *
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   288
     * @return this sequence's duration in microseconds
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    public long getMicrosecondLength() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        return com.sun.media.sound.MidiUtils.tick2microsecond(this, getTickLength(), null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * Obtains the duration of this sequence, expressed in MIDI ticks.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * @return this sequence's length in ticks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * @see #getMicrosecondLength
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    public long getTickLength() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        long length = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        synchronized(tracks) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            for(int i=0; i<tracks.size(); i++ ) {
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 5506
diff changeset
   308
                long temp = tracks.elementAt(i).ticks();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                if( temp>length ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                    length = temp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            return length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    /**
26003
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   318
     * Obtains a list of patches referenced in this sequence. This patch list
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   319
     * may be used to load the required {@link Instrument} objects into a
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   320
     * {@link Synthesizer}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     *
26003
d630c97424bd 8050852: Javadoc cleanup of javax.sound.midi package
serb
parents: 22584
diff changeset
   322
     * @return an array of {@link Patch} objects used in this sequence
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * @see Synthesizer#loadInstruments(Soundbank, Patch[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    public Patch[] getPatchList() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        // $$kk: 04.09.99: need to implement!!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        return new Patch[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
}