1 7 8 package javax.sound.midi; 9 10 import java.util.Vector ; 11 import com.sun.media.sound.MidiUtils; 12 13 14 38 public class Sequence { 39 40 41 43 47 public static final float PPQ = 0.0f; 48 49 53 public static final float SMPTE_24 = 24.0f; 54 55 59 public static final float SMPTE_25 = 25.0f; 60 61 65 public static final float SMPTE_30DROP = 29.97f; 66 67 71 public static final float SMPTE_30 = 30.0f; 72 73 74 76 85 protected float divisionType; 86 87 91 protected int resolution; 92 93 97 protected Vector <Track > tracks = new Vector <Track >(); 98 99 100 125 public Sequence(float divisionType, int resolution) throws InvalidMidiDataException { 126 127 if (divisionType == PPQ) 128 this.divisionType = PPQ; 129 else if (divisionType == SMPTE_24) 130 this.divisionType = SMPTE_24; 131 else if (divisionType == SMPTE_25) 132 this.divisionType = SMPTE_25; 133 else if (divisionType == SMPTE_30DROP) 134 this.divisionType = SMPTE_30DROP; 135 else if (divisionType == SMPTE_30) 136 this.divisionType = SMPTE_30; 137 else throw new InvalidMidiDataException ("Unsupported division type: " + divisionType); 138 139 this.resolution = resolution; 140 } 141 142 143 171 public Sequence(float divisionType, int resolution, int numTracks) throws InvalidMidiDataException { 172 173 if (divisionType == PPQ) 174 this.divisionType = PPQ; 175 else if (divisionType == SMPTE_24) 176 this.divisionType = SMPTE_24; 177 else if (divisionType == SMPTE_25) 178 this.divisionType = SMPTE_25; 179 else if (divisionType == SMPTE_30DROP) 180 this.divisionType = SMPTE_30DROP; 181 else if (divisionType == SMPTE_30) 182 this.divisionType = SMPTE_30; 183 else throw new InvalidMidiDataException ("Unsupported division type: " + divisionType); 184 185 this.resolution = resolution; 186 187 for (int i = 0; i < numTracks; i++) { 188 tracks.addElement(new Track ()); 189 } 190 } 191 192 193 205 public float getDivisionType() { 206 return divisionType; 207 } 208 209 210 220 public int getResolution() { 221 return resolution; 222 } 223 224 225 233 public Track createTrack() { 234 235 Track track = new Track (); 236 tracks.addElement(track); 237 238 return track; 239 } 240 241 242 251 public boolean deleteTrack(Track track) { 252 253 synchronized(tracks) { 254 255 return tracks.removeElement(track); 256 } 257 } 258 259 260 268 public Track [] getTracks() { 269 270 return (Track []) tracks.toArray(new Track [tracks.size()]); 271 } 272 273 274 278 public long getMicrosecondLength() { 279 280 return com.sun.media.sound.MidiUtils.tick2microsecond(this, getTickLength(), null); 281 } 282 283 284 291 public long getTickLength() { 292 293 long length = 0; 294 295 synchronized(tracks) { 296 297 for(int i=0; i<tracks.size(); i++ ) { 298 long temp = ((Track )tracks.elementAt(i)).ticks(); 299 if( temp>length ) { 300 length = temp; 301 } 302 } 303 return length; 304 } 305 } 306 307 308 318 public Patch [] getPatchList() { 319 320 return new Patch [0]; 322 } 323 } 324 | Popular Tags |