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.nio.Buffer;
23  import java.nio.ByteBuffer;
24  
25  /**
26   * Port registered by {@link JackClient}.
27   * 
28   * @author repa
29   * 
30   */
31  public class JackLocalPort extends JackPort {
32  
33  	static {
34  		JackBridge.initializeJackBridge();
35  	}
36  
37  	private JackClient client;
38  	@SuppressWarnings("unused")
39  	private long clientHandle = 0;
40  	@SuppressWarnings("unused")
41  	private ByteBuffer cachedByteBuffer = null;
42  
43  	JackLocalPort(long portHandle, JackClient client) {
44  		super(portHandle);
45  		this.client = client;
46  		this.clientHandle = client.getClientHandle();
47  	}
48  
49  	/**
50  	 * Returns the client that owns this port.
51  	 */
52  	public JackClient getClient() {
53  		return client;
54  	}
55  
56  	/**
57  	 * Sets short name of this port.
58  	 */
59  	public void setPortName(String portName) throws JackException {
60  		synchronized (client) {
61  			setPortNameInternal(portName);
62  			client.localPortNameChanged(this, portName);
63  		}
64  	}
65  
66  	private native void setPortNameInternal(String portName) throws JackException;
67  
68  	/**
69  	 * Sets port alias.
70  	 * 
71  	 * <p>
72  	 * The port can have at most 2 aliases.
73  	 */
74  	public native void setPortAlias(String alias) throws JackException;
75  
76  	/**
77  	 * Removes port alias.
78  	 */
79  	public native void unsetPortAlias(String alias) throws JackException;
80  
81  	/**
82  	 * Returns all aliases set for this port.
83  	 */
84  	public native String[] getPortAliases() throws JackException;
85  
86  	/**
87  	 * Returns number of connections to or from port.
88  	 */
89  	public native int connected() throws JackException;
90  
91  	/**
92  	 * Returns true if the port is directly connected to port with specified
93  	 * name.
94  	 */
95  	public native boolean connectedTo(String portName) throws JackException;
96  
97  	/**
98  	 * Returns full port names of to which this port is connected.
99  	 * 
100 	 * <p>
101 	 * If the port is not connected, returns null.
102 	 */
103 	public native String[] getConnections() throws JackException;
104 
105 	/**
106 	 * Returns pointer to the memory area associated with the specified port.
107 	 * 
108 	 * <p>
109 	 * The pointer is not very useful in Java, but can be used for some JNI
110 	 * calls.
111 	 * 
112 	 * <p>
113 	 * <b>This method can only be called during {@link JackClient#process(int)}
114 	 * callback, and only by the thread that invoked the callback. The returned
115 	 * value is valid only during that callback.</b>
116 	 * 
117 	 * @param bufferSize
118 	 *            the value passed in <code>bufferSize</code> parameter to
119 	 *            {@link JackClient#process(int)}
120 	 * @return native pointer, converted to long @
121 	 */
122 	public native long getBufferPointer(int bufferSize) throws JackException;
123 
124 	/**
125 	 * Returns ByteBuffer that contains the memory area associated with the
126 	 * specified port.
127 	 * 
128 	 * <p>
129 	 * <b>This method can only be called during {@link JackClient#process(int)}
130 	 * callback, and only by the thread that invoked the callback. The returned
131 	 * value is valid only during that callback.</b>
132 	 * 
133 	 * <p>
134 	 * The caller is responsible for calling {@link Buffer#clear()} on the
135 	 * returned value before the buffer is used. Otherwise, <b>the buffer
136 	 * position, limit, and mark may be set to random value</b>. The buffer
137 	 * capacity is always set to the buffer size multiplied by
138 	 * <code>Float.SIZE / 8</code>.
139 	 * 
140 	 * @param bufferSize
141 	 *            the value passed in <code>bufferSize</code> parameter to
142 	 *            {@link JackClient#process(int)}
143 	 * @return port buffer, wrapped into ByteBuffer object
144 	 */
145 	public native ByteBuffer getByteBuffer(int bufferSize) throws JackException;
146 
147 	/**
148 	 * Ties this (output) port to given input port.
149 	 * 
150 	 * <p>
151 	 * The sourcePort must be owned by the same client as this port, and it must
152 	 * be an input port.
153 	 * 
154 	 * <p>
155 	 * This port must be an output port.
156 	 */
157 	public native void tie(JackLocalPort sourcePort) throws JackException;
158 
159 	/**
160 	 * Undoes the effect of {@link #tie(JackLocalPort)}.
161 	 */
162 	public native void untie() throws JackException;
163 }