1 /*
2 * Copyright (c) 1999, 2006, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
194 // also, would it make sense to adjust the EOT's time
195 // to the last event, if the last non-EOT event is removed?
196 // Or: document that the ticks() length will not be reduced
197 // by deleting events (unless the EOT event is removed)
198 synchronized(eventsList) {
199 if (set.remove(event)) {
200 int i = eventsList.indexOf(event);
201 if (i >= 0) {
202 eventsList.remove(i);
203 return true;
204 }
205 }
206 }
207 return false;
208 }
209
210
211 /**
212 * Obtains the event at the specified index.
213 * @param index the location of the desired event in the event vector
214 * @throws <code>ArrayIndexOutOfBoundsException</code> if the
215 * specified index is negative or not less than the current size of
216 * this track.
217 * @see #size
218 */
219 public MidiEvent get(int index) throws ArrayIndexOutOfBoundsException {
220 try {
221 synchronized(eventsList) {
222 return (MidiEvent)eventsList.get(index);
223 }
224 } catch (IndexOutOfBoundsException ioobe) {
225 throw new ArrayIndexOutOfBoundsException(ioobe.getMessage());
226 }
227 }
228
229
230 /**
231 * Obtains the number of events in this track.
232 * @return the size of the track's event vector
233 */
234 public int size() {
235 synchronized(eventsList) {
236 return eventsList.size();
237 }
|
1 /*
2 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
194 // also, would it make sense to adjust the EOT's time
195 // to the last event, if the last non-EOT event is removed?
196 // Or: document that the ticks() length will not be reduced
197 // by deleting events (unless the EOT event is removed)
198 synchronized(eventsList) {
199 if (set.remove(event)) {
200 int i = eventsList.indexOf(event);
201 if (i >= 0) {
202 eventsList.remove(i);
203 return true;
204 }
205 }
206 }
207 return false;
208 }
209
210
211 /**
212 * Obtains the event at the specified index.
213 * @param index the location of the desired event in the event vector
214 * @throws ArrayIndexOutOfBoundsException if the
215 * specified index is negative or not less than the current size of
216 * this track.
217 * @see #size
218 * @return the event at the specified index
219 */
220 public MidiEvent get(int index) throws ArrayIndexOutOfBoundsException {
221 try {
222 synchronized(eventsList) {
223 return (MidiEvent)eventsList.get(index);
224 }
225 } catch (IndexOutOfBoundsException ioobe) {
226 throw new ArrayIndexOutOfBoundsException(ioobe.getMessage());
227 }
228 }
229
230
231 /**
232 * Obtains the number of events in this track.
233 * @return the size of the track's event vector
234 */
235 public int size() {
236 synchronized(eventsList) {
237 return eventsList.size();
238 }
|