View Javadoc

1   package net.sf.jack4j;
2   
3   /*
4   Copyright (C) 2008 Ondrej Par
5   
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU Lesser General Public License as published by
8   the Free Software Foundation; either version 2.1 of the License, or
9   (at your option) any later version.
10  
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  GNU Lesser General Public License for more details.
15  
16  You should have received a copy of the GNU Lesser General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  
20  */
21  
22  import java.util.EnumSet;
23  
24  /**
25   * Contains information about current state of Jack transport.
26   * 
27   * <p>
28   * The structure contains fields listed below. Note that some of the fields may
29   * be uninitialized; to obtain information about which fields have valid values,
30   * see {@link #getValidBits()} or {@link #getValidBitsSet()} methods.
31   * 
32   * <dl>
33   * <dt>usecs</dt>
34   * <dd>time in microseconds, monotonic, free-rolling counter</dd>
35   * <dt>frameRate</dt>
36   * <dd>current frame rate (per second)</dd>
37   * <dt>frame</dt>
38   * <dd>frame number; this field is always present</dd>
39   * <dt>validBits</dt>
40   * <dd>indicates which fields contain valid values, decode using
41   * {@link JackPositionBit}</dd>
42   * <dt>validBitsSet</dt>
43   * <dd>same as validBits, but decoded into more convenient EnumSet</dd>
44   * <dt>bar</dt>
45   * <dd>current bar</dd>
46   * <dt>beat</dt>
47   * <dd>current beat-within-bar</dd>
48   * <dt>tick</dt>
49   * <dd>current tick-within-beat</dd>
50   * <dt>barStartTick</dt>
51   * <dd></dd>
52   * <dt>beatsPerBar</dt>
53   * <dd>time signature "numerator"</dd>
54   * <dt>beatType</dt>
55   * <dd>time signature "denominator"</dd>
56   * <dt>ticksPerBeat</dt>
57   * <dd></dd>
58   * <dt>beatsPerMinute</dt>
59   * <dd></dd>
60   * <dt>frameTime</dt>
61   * <dd>current time in seconds</dd>
62   * <dt>nextTime</dt>
63   * <dd>next sequential frame_time (unless repositioned)</dd>
64   * <dt>bbtOffset</dt>
65   * <dd>bar-beat-tick offset (how many frames passed since the start of current
66   * tick)</dd>
67   * <dt>audioFramesPerVideoFrame</dt>
68   * <dd>number of audio frames per video frame</dd>
69   * <dt>videoOffset</dt>
70   * <dd>audio frame at which the first video frame in this cycle occurs</dd>
71   * </dl>
72   * 
73   * @author repa
74   * 
75   */
76  public class TransportPosition implements Cloneable {
77  
78  	static {
79  		JackBridge.initializeJackBridge();
80  	}
81  
82  	@SuppressWarnings("unused")
83  	private long positionHandle;
84  	private boolean deallocateWhenFinalized;
85  
86  	TransportPosition(long positionHandle, boolean deallocateWhenFinalized) {
87  		this.positionHandle = positionHandle;
88  		this.deallocateWhenFinalized = deallocateWhenFinalized;
89  	}
90  
91  	public TransportPosition() {
92  		this.positionHandle = allocateTransportPosition();
93  		this.deallocateWhenFinalized = true;
94  	}
95  
96  	@Override
97  	protected void finalize() throws Throwable {
98  		if (deallocateWhenFinalized) {
99  			deallocateTransportPosition(positionHandle);
100 		}
101 		super.finalize();
102 	}
103 
104 	/**
105 	 * @see java.lang.Object#clone()
106 	 */
107 	@Override
108 	protected TransportPosition clone() {
109 		TransportPosition that;
110 		try {
111 			that = (TransportPosition) super.clone();
112 		} catch (CloneNotSupportedException e) {
113 			// this never happens
114 			throw new RuntimeException(e);
115 		}
116 
117 		that.positionHandle = allocateCopyOfTransportPosition(positionHandle);
118 		that.deallocateWhenFinalized = true;
119 
120 		return that;
121 	}
122 
123 	/**
124 	 * @return the usecs
125 	 */
126 	public native long getUsecs();
127 
128 	/**
129 	 * @param usecs
130 	 *            the usecs to set
131 	 */
132 	public native void setUsecs(long usecs);
133 
134 	/**
135 	 * @return the frameRate
136 	 */
137 	public native int getFrameRate();
138 
139 	/**
140 	 * @param frameRate
141 	 *            the frameRate to set
142 	 */
143 	public native void setFrameRate(int frameRate);
144 
145 	/**
146 	 * @return the frame
147 	 */
148 	public native int getFrame();
149 
150 	/**
151 	 * @param frame
152 	 *            the frame to set
153 	 */
154 	public native void setFrame(int frame);
155 
156 	/**
157 	 * @return the validBits
158 	 */
159 	public native int getValidBits();
160 
161 	/**
162 	 * @param validBits
163 	 *            the validBits to set
164 	 */
165 	public native void setValidBits(int validBits);
166 
167 	/**
168 	 * @return the validBitsSet
169 	 */
170 	public EnumSet<JackPositionBit> getValidBitsSet() {
171 		return JackPositionBit.decode(getValidBits());
172 	}
173 
174 	/**
175 	 * @param validBitsSet
176 	 *            the validBitsSet to set
177 	 */
178 	public void setValidBitsSet(EnumSet<JackPositionBit> validBitsSet) {
179 		setValidBits(JackPositionBit.encode(validBitsSet));
180 	}
181 
182 	/**
183 	 * @return the bar
184 	 */
185 	public native int getBar();
186 
187 	/**
188 	 * @param bar
189 	 *            the bar to set
190 	 */
191 	public native void setBar(int bar);
192 
193 	/**
194 	 * @return the beat
195 	 */
196 	public native int getBeat();
197 
198 	/**
199 	 * @param beat
200 	 *            the beat to set
201 	 */
202 	public native void setBeat(int beat);
203 
204 	/**
205 	 * @return the tick
206 	 */
207 	public native int getTick();
208 
209 	/**
210 	 * @param tick
211 	 *            the tick to set
212 	 */
213 	public native void setTick(int tick);
214 
215 	/**
216 	 * @return the barStartTick
217 	 */
218 	public native double getBarStartTick();
219 
220 	/**
221 	 * @param barStartTick
222 	 *            the barStartTick to set
223 	 */
224 	public native void setBarStartTick(double barStartTick);
225 
226 	/**
227 	 * @return the beatsPerBar
228 	 */
229 	public native float getBeatsPerBar();
230 
231 	/**
232 	 * @param beatsPerBar
233 	 *            the beatsPerBar to set
234 	 */
235 	public native void setBeatsPerBar(float beatsPerBar);
236 
237 	/**
238 	 * @return the beatType
239 	 */
240 	public native float getBeatType();
241 
242 	/**
243 	 * @param beatType
244 	 *            the beatType to set
245 	 */
246 	public native void setBeatType(float beatType);
247 
248 	/**
249 	 * @return the ticks_per_beat
250 	 */
251 	public native double getTicksPerBeat();
252 
253 	/**
254 	 * @param ticks_per_beat
255 	 *            the ticks_per_beat to set
256 	 */
257 	public native void setTicksPerBeat(double ticks_per_beat);
258 
259 	/**
260 	 * @return the beats_per_minute
261 	 */
262 	public native double getBeatsPerMinute();
263 
264 	/**
265 	 * @param beats_per_minute
266 	 *            the beats_per_minute to set
267 	 */
268 	public native void setBeatsPerMinute(double beats_per_minute);
269 
270 	/**
271 	 * @return the frameTime
272 	 */
273 	public native double getFrameTime();
274 
275 	/**
276 	 * @param frameTime
277 	 *            the frameTime to set
278 	 */
279 	public native void setFrameTime(double frameTime);
280 
281 	/**
282 	 * @return the nextTime
283 	 */
284 	public native double getNextTime();
285 
286 	/**
287 	 * @param nextTime
288 	 *            the nextTime to set
289 	 */
290 	public native void setNextTime(double nextTime);
291 
292 	/**
293 	 * @return the bbtOffset
294 	 */
295 	public native int getBbtOffset();
296 
297 	/**
298 	 * @param bbtOffset
299 	 *            the bbtOffset to set
300 	 */
301 	public native void setBbtOffset(int bbtOffset);
302 
303 	/**
304 	 * @return the audioFramesPerVideoFrame
305 	 */
306 	public native float getAudioFramesPerVideoFrame();
307 
308 	/**
309 	 * @param audioFramesPerVideoFrame
310 	 *            the audioFramesPerVideoFrame to set
311 	 */
312 	public native void setAudioFramesPerVideoFrame(float audioFramesPerVideoFrame);
313 
314 	/**
315 	 * @return the videoOffset
316 	 */
317 	public native int getVideoOffset();
318 
319 	/**
320 	 * @param videoOffset
321 	 *            the videoOffset to set
322 	 */
323 	public native void setVideoOffset(int videoOffset);
324 
325 	private static native long allocateTransportPosition();
326 
327 	private static native long allocateCopyOfTransportPosition(long originalHandle);
328 
329 	private static native void deallocateTransportPosition(long positionHandle);
330 }