| 1 | /* |
| 2 | Copyright (C) 2002 Paul Davis |
| 3 | Copyright (C) 2003 Jack O'Quin |
| 4 | |
| 5 | This program is free software; you can redistribute it and/or modify |
| 6 | it under the terms of the GNU Lesser General Public License as published by |
| 7 | the Free Software Foundation; either version 2.1 of the License, or |
| 8 | (at your option) any later version. |
| 9 | |
| 10 | This program is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | GNU Lesser General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU Lesser General Public License |
| 16 | along with this program; if not, write to the Free Software |
| 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | |
| 19 | */ |
| 20 | |
| 21 | #ifndef __jack_transport_h__ |
| 22 | #define __jack_transport_h__ |
| 23 | |
| 24 | #ifdef __cplusplus |
| 25 | extern "C" { |
| 26 | #endif |
| 27 | |
| 28 | #include <jack/types.h> |
| 29 | #include <jack/weakmacros.h> |
| 30 | |
| 31 | /** |
| 32 | * @defgroup TransportControl Transport and Timebase control |
| 33 | * @{ |
| 34 | */ |
| 35 | |
| 36 | /** |
| 37 | * Called by the timebase master to release itself from that |
| 38 | * responsibility. |
| 39 | * |
| 40 | * If the timebase master releases the timebase or leaves the JACK |
| 41 | * graph for any reason, the JACK engine takes over at the start of |
| 42 | * the next process cycle. The transport state does not change. If |
| 43 | * rolling, it continues to play, with frame numbers as the only |
| 44 | * available position information. |
| 45 | * |
| 46 | * @see jack_set_timebase_callback |
| 47 | * |
| 48 | * @param client the JACK client structure. |
| 49 | * |
| 50 | * @return 0 on success, otherwise a non-zero error code. |
| 51 | */ |
| 52 | int jack_release_timebase (jack_client_t *client) JACK_OPTIONAL_WEAK_EXPORT; |
| 53 | |
| 54 | /** |
| 55 | * Register (or unregister) as a slow-sync client, one that cannot |
| 56 | * respond immediately to transport position changes. |
| 57 | * |
| 58 | * The @a sync_callback will be invoked at the first available |
| 59 | * opportunity after its registration is complete. If the client is |
| 60 | * currently active this will be the following process cycle, |
| 61 | * otherwise it will be the first cycle after calling jack_activate(). |
| 62 | * After that, it runs according to the ::JackSyncCallback rules. |
| 63 | * Clients that don't set a @a sync_callback are assumed to be ready |
| 64 | * immediately any time the transport wants to start. |
| 65 | * |
| 66 | * @param client the JACK client structure. |
| 67 | * @param sync_callback is a realtime function that returns TRUE when |
| 68 | * the client is ready. Setting @a sync_callback to NULL declares that |
| 69 | * this client no longer requires slow-sync processing. |
| 70 | * @param arg an argument for the @a sync_callback function. |
| 71 | * |
| 72 | * @return 0 on success, otherwise a non-zero error code. |
| 73 | */ |
| 74 | int jack_set_sync_callback (jack_client_t *client, |
| 75 | JackSyncCallback sync_callback, |
| 76 | void *arg) JACK_OPTIONAL_WEAK_EXPORT; |
| 77 | |
| 78 | /** |
| 79 | * Set the timeout value for slow-sync clients. |
| 80 | * |
| 81 | * This timeout prevents unresponsive slow-sync clients from |
| 82 | * completely halting the transport mechanism. The default is two |
| 83 | * seconds. When the timeout expires, the transport starts rolling, |
| 84 | * even if some slow-sync clients are still unready. The @a |
| 85 | * sync_callbacks of these clients continue being invoked, giving them |
| 86 | * a chance to catch up. |
| 87 | * |
| 88 | * @see jack_set_sync_callback |
| 89 | * |
| 90 | * @param client the JACK client structure. |
| 91 | * @param timeout is delay (in microseconds) before the timeout expires. |
| 92 | * |
| 93 | * @return 0 on success, otherwise a non-zero error code. |
| 94 | */ |
| 95 | int jack_set_sync_timeout (jack_client_t *client, |
| 96 | jack_time_t timeout) JACK_OPTIONAL_WEAK_EXPORT; |
| 97 | |
| 98 | /** |
| 99 | * Register as timebase master for the JACK subsystem. |
| 100 | * |
| 101 | * The timebase master registers a callback that updates extended |
| 102 | * position information such as beats or timecode whenever necessary. |
| 103 | * Without this extended information, there is no need for this |
| 104 | * function. |
| 105 | * |
| 106 | * There is never more than one master at a time. When a new client |
| 107 | * takes over, the former @a timebase_callback is no longer called. |
| 108 | * Taking over the timebase may be done conditionally, so it fails if |
| 109 | * there was a master already. |
| 110 | * |
| 111 | * @param client the JACK client structure. |
| 112 | * @param conditional non-zero for a conditional request. |
| 113 | * @param timebase_callback is a realtime function that returns |
| 114 | * position information. |
| 115 | * @param arg an argument for the @a timebase_callback function. |
| 116 | * |
| 117 | * @return |
| 118 | * - 0 on success; |
| 119 | * - EBUSY if a conditional request fails because there was already a |
| 120 | * timebase master; |
| 121 | * - other non-zero error code. |
| 122 | */ |
| 123 | int jack_set_timebase_callback (jack_client_t *client, |
| 124 | int conditional, |
| 125 | JackTimebaseCallback timebase_callback, |
| 126 | void *arg) JACK_OPTIONAL_WEAK_EXPORT; |
| 127 | |
| 128 | /** |
| 129 | * Reposition the transport to a new frame number. |
| 130 | * |
| 131 | * May be called at any time by any client. The new position takes |
| 132 | * effect in two process cycles. If there are slow-sync clients and |
| 133 | * the transport is already rolling, it will enter the |
| 134 | * ::JackTransportStarting state and begin invoking their @a |
| 135 | * sync_callbacks until ready. This function is realtime-safe. |
| 136 | * |
| 137 | * @see jack_transport_reposition, jack_set_sync_callback |
| 138 | * |
| 139 | * @param client the JACK client structure. |
| 140 | * @param frame frame number of new transport position. |
| 141 | * |
| 142 | * @return 0 if valid request, non-zero otherwise. |
| 143 | */ |
| 144 | int jack_transport_locate (jack_client_t *client, |
| 145 | jack_nframes_t frame) JACK_OPTIONAL_WEAK_EXPORT; |
| 146 | |
| 147 | /** |
| 148 | * Query the current transport state and position. |
| 149 | * |
| 150 | * This function is realtime-safe, and can be called from any thread. |
| 151 | * If called from the process thread, @a pos corresponds to the first |
| 152 | * frame of the current cycle and the state returned is valid for the |
| 153 | * entire cycle. |
| 154 | * |
| 155 | * @param client the JACK client structure. |
| 156 | * @param pos pointer to structure for returning current transport |
| 157 | * position; @a pos->valid will show which fields contain valid data. |
| 158 | * If @a pos is NULL, do not return position information. |
| 159 | * |
| 160 | * @return Current transport state. |
| 161 | */ |
| 162 | jack_transport_state_t jack_transport_query (const jack_client_t *client, |
| 163 | jack_position_t *pos) JACK_OPTIONAL_WEAK_EXPORT; |
| 164 | |
| 165 | /** |
| 166 | * Return an estimate of the current transport frame, |
| 167 | * including any time elapsed since the last transport |
| 168 | * positional update. |
| 169 | * |
| 170 | * @param client the JACK client structure |
| 171 | */ |
| 172 | jack_nframes_t jack_get_current_transport_frame (const jack_client_t *client) JACK_OPTIONAL_WEAK_EXPORT; |
| 173 | |
| 174 | /** |
| 175 | * Request a new transport position. |
| 176 | * |
| 177 | * May be called at any time by any client. The new position takes |
| 178 | * effect in two process cycles. If there are slow-sync clients and |
| 179 | * the transport is already rolling, it will enter the |
| 180 | * ::JackTransportStarting state and begin invoking their @a |
| 181 | * sync_callbacks until ready. This function is realtime-safe. |
| 182 | * |
| 183 | * @see jack_transport_locate, jack_set_sync_callback |
| 184 | * |
| 185 | * @param client the JACK client structure. |
| 186 | * @param pos requested new transport position. |
| 187 | * |
| 188 | * @return 0 if valid request, EINVAL if position structure rejected. |
| 189 | */ |
| 190 | int jack_transport_reposition (jack_client_t *client, |
| 191 | const jack_position_t *pos) JACK_OPTIONAL_WEAK_EXPORT; |
| 192 | |
| 193 | /** |
| 194 | * Start the JACK transport rolling. |
| 195 | * |
| 196 | * Any client can make this request at any time. It takes effect no |
| 197 | * sooner than the next process cycle, perhaps later if there are |
| 198 | * slow-sync clients. This function is realtime-safe. |
| 199 | * |
| 200 | * @see jack_set_sync_callback |
| 201 | * |
| 202 | * @param client the JACK client structure. |
| 203 | */ |
| 204 | void jack_transport_start (jack_client_t *client) JACK_OPTIONAL_WEAK_EXPORT; |
| 205 | |
| 206 | /** |
| 207 | * Stop the JACK transport. |
| 208 | * |
| 209 | * Any client can make this request at any time. It takes effect on |
| 210 | * the next process cycle. This function is realtime-safe. |
| 211 | * |
| 212 | * @param client the JACK client structure. |
| 213 | */ |
| 214 | void jack_transport_stop (jack_client_t *client) JACK_OPTIONAL_WEAK_EXPORT; |
| 215 | |
| 216 | /** |
| 217 | * Gets the current transport info structure (deprecated). |
| 218 | * |
| 219 | * @param client the JACK client structure. |
| 220 | * @param tinfo current transport info structure. The "valid" field |
| 221 | * describes which fields contain valid data. |
| 222 | * |
| 223 | * @deprecated This is for compatibility with the earlier transport |
| 224 | * interface. Use jack_transport_query(), instead. |
| 225 | * |
| 226 | * @pre Must be called from the process thread. |
| 227 | */ |
| 228 | void jack_get_transport_info (jack_client_t *client, |
| 229 | jack_transport_info_t *tinfo) JACK_OPTIONAL_WEAK_EXPORT; |
| 230 | |
| 231 | /** |
| 232 | * Set the transport info structure (deprecated). |
| 233 | * |
| 234 | * @deprecated This function still exists for compatibility with the |
| 235 | * earlier transport interface, but it does nothing. Instead, define |
| 236 | * a ::JackTimebaseCallback. |
| 237 | */ |
| 238 | void jack_set_transport_info (jack_client_t *client, |
| 239 | jack_transport_info_t *tinfo) JACK_OPTIONAL_WEAK_EXPORT; |
| 240 | |
| 241 | /**@}*/ |
| 242 | |
| 243 | #ifdef __cplusplus |
| 244 | } |
| 245 | #endif |
| 246 | |
| 247 | #endif /* __jack_transport_h__ */ |