001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package javax.sound.midi;
019:
020: import java.util.Vector;
021:
022: import org.apache.harmony.sound.internal.nls.Messages;
023:
024: public class Sequence {
025: public static final float PPQ = 0.0f;
026:
027: public static final float SMPTE_24 = 24.0f;
028:
029: public static final float SMPTE_25 = 25.0f;
030:
031: public static final float SMPTE_30 = 30.0f;
032:
033: public static final float SMPTE_30DROP = 29.969999313354492f;
034:
035: protected float divisionType;
036:
037: protected int resolution;
038:
039: protected Vector<Track> tracks;
040:
041: private Vector<Patch> patches;
042:
043: public Sequence(float divisionType, int resolution)
044: throws InvalidMidiDataException {
045: if (divisionType != Sequence.PPQ
046: && divisionType != Sequence.SMPTE_24
047: && divisionType != Sequence.SMPTE_25
048: && divisionType != Sequence.SMPTE_30
049: && divisionType != Sequence.SMPTE_30DROP) {
050: // sound.0B=Unsupported division type: {0}
051: throw new InvalidMidiDataException(Messages.getString(
052: "sound.0B", divisionType)); //$NON-NLS-1$
053: }
054: this .divisionType = divisionType;
055: this .resolution = resolution;
056: this .tracks = new Vector<Track>();
057: this .patches = new Vector<Patch>();
058:
059: }
060:
061: public Sequence(float divisionType, int resolution, int numTracks)
062: throws InvalidMidiDataException {
063: if (divisionType != Sequence.PPQ
064: && divisionType != Sequence.SMPTE_24
065: && divisionType != Sequence.SMPTE_25
066: && divisionType != Sequence.SMPTE_30
067: && divisionType != Sequence.SMPTE_30DROP) {
068: // sound.0B=Unsupported division type: {0}
069: throw new InvalidMidiDataException(Messages.getString(
070: "sound.0B", divisionType)); //$NON-NLS-1$
071: }
072: this .divisionType = divisionType;
073: this .resolution = resolution;
074: this .patches = new Vector<Patch>();
075: this .tracks = new Vector<Track>();
076: if (numTracks > 0) {
077: for (int i = 0; i < numTracks; i++) {
078: tracks.add(new Track());
079: }
080: }
081: }
082:
083: public Track createTrack() {
084: /*
085: * new Tracks accrue to the end of vector
086: */
087: Track tr = new Track();
088: tracks.add(tr);
089: return tr;
090: }
091:
092: public boolean deleteTrack(Track track) {
093: return tracks.remove(track);
094: }
095:
096: public float getDivisionType() {
097: return divisionType;
098: }
099:
100: public long getMicrosecondLength() {
101: float divisionType;
102: if (this .divisionType == 0.0f) {
103: divisionType = 2;
104: } else {
105: divisionType = this .divisionType;
106: }
107: return (long) (1000000.0 * getTickLength() / (divisionType
108: * this .resolution * 1.0f));
109: }
110:
111: public Patch[] getPatchList() {
112: //FIXME
113: /*
114: * I don't understand how to works this method, and so
115: * I simply return an empty array. 'patches' initializes
116: * in the constructor as empty vector
117: */
118: Patch[] patch = new Patch[patches.size()];
119: patches.toArray(patch);
120: return patch;
121: }
122:
123: public int getResolution() {
124: return resolution;
125: }
126:
127: public long getTickLength() {
128: /*
129: * this method return the biggest value of tick of
130: * all tracks contain in the Sequence
131: */
132: long maxTick = 0;
133: for (int i = 0; i < tracks.size(); i++) {
134: if (maxTick < tracks.get(i).ticks()) {
135: maxTick = tracks.get(i).ticks();
136: }
137: }
138: return maxTick;
139: }
140:
141: public Track[] getTracks() {
142: Track[] track = new Track[tracks.size()];
143: tracks.toArray(track);
144: return track;
145: }
146:
147: }
|