235 changes: 187 additions & 48 deletions jack.h

Large diffs are not rendered by default.

24 changes: 17 additions & 7 deletions jslist.h
Expand Up @@ -3,7 +3,7 @@
Adaption to JACK, Copyright (C) 2002 Kai Vehmanen.
- replaced use of gtypes with normal ANSI C types
- glib's memery allocation routines replaced with
- glib's memory allocation routines replaced with
malloc/free calls
This program is free software; you can redistribute it and/or modify
Expand All @@ -26,6 +26,11 @@
#define __jack_jslist_h__

#include <stdlib.h>
#include <jack/systemdeps.h>

#ifdef sun
#define __inline__
#endif

typedef struct _JSList JSList;

Expand All @@ -42,9 +47,12 @@ jack_slist_alloc (void)
{
JSList *new_list;

new_list = malloc(sizeof(JSList));
new_list->data = NULL;
new_list->next = NULL;
new_list = (JSList*)malloc(sizeof(JSList));
if (new_list)
{
new_list->data = NULL;
new_list->next = NULL;
}

return new_list;
}
Expand All @@ -55,9 +63,11 @@ jack_slist_prepend (JSList* list, void* data)
{
JSList *new_list;

new_list = malloc(sizeof(JSList));
new_list->data = data;
new_list->next = list;
new_list = (JSList*)malloc(sizeof(JSList));
if (new_list) {
new_list->data = data;
new_list->next = list;
}

return new_list;
}
Expand Down
2 changes: 1 addition & 1 deletion midiport.h
Expand Up @@ -53,7 +53,7 @@ typedef struct _jack_midi_event
* @param port_buffer Port buffer from which to retrieve event.
* @return number of events inside @a port_buffer
*/
jack_nframes_t
uint32_t
jack_midi_get_event_count(void* port_buffer) JACK_OPTIONAL_WEAK_EXPORT;


Expand Down
316 changes: 316 additions & 0 deletions net.h
@@ -0,0 +1,316 @@
/*
Copyright (C) 2009-2010 Grame
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#ifndef __net_h__
#define __net_h__

#ifdef __cplusplus
extern "C"
{
#endif

#include <jack/systemdeps.h>
#include <jack/types.h>

#define DEFAULT_MULTICAST_IP "225.3.19.154"
#define DEFAULT_PORT 19000
#define DEFAULT_MTU 1500
#define MASTER_NAME_SIZE 256

#define SOCKET_ERROR -1

enum JackNetEncoder {

JackFloatEncoder = 0, // samples are transmitted as float
JackIntEncoder = 1, // samples are transmitted as 16 bits integer
JackCeltEncoder = 2, // samples are transmitted using CELT codec (http://www.celt-codec.org/)
};

typedef struct {

int audio_input; // from master or to slave (-1 to take master audio physical inputs)
int audio_output; // to master or from slave (-1 to take master audio physical outputs)
int midi_input; // from master or to slave (-1 to take master MIDI physical inputs)
int midi_output; // to master or from slave (-1 to take master MIDI physical outputs)
int mtu; // network Maximum Transmission Unit
int time_out; // in second, -1 means in infinite
int encoder; // encoder type (one of JackNetEncoder)
int kbps; // KB per second for CELT encoder
int latency; // network latency

} jack_slave_t;

typedef struct {

int audio_input; // master audio physical outputs (-1 to take slave wanted audio inputs)
int audio_output; // master audio physical inputs (-1 to take slave wanted audio outputs)
int midi_input; // master MIDI physical outputs (-1 to take slave wanted MIDI inputs)
int midi_output; // master MIDI physical inputs (-1 to take slave wanted MIDI outputs)
jack_nframes_t buffer_size; // mater buffer size
jack_nframes_t sample_rate; // mater sample rate
char master_name[MASTER_NAME_SIZE]; // master machine name

} jack_master_t;

/**
* jack_net_slave_t is an opaque type. You may only access it using the
* API provided.
*/
typedef struct _jack_net_slave jack_net_slave_t;

/**
* Open a network connection with the master machine.
* @param ip the multicast address of the master
* @param port the connection port
* @param request a connection request structure
* @param result a connection result structure
*
* @return Opaque net handle if successful or NULL in case of error.
*/
jack_net_slave_t* jack_net_slave_open(const char* ip, int port, const char* name, jack_slave_t* request, jack_master_t* result);

/**
* Close the network connection with the master machine.
* @param net the network connection to be closed
*
* @return 0 on success, otherwise a non-zero error code
*/
int jack_net_slave_close(jack_net_slave_t* net);

/**
* Prototype for Process callback.
* @param nframes buffer size
* @param audio_input number of audio inputs
* @param audio_input_buffer an array of audio input buffers (from master)
* @param midi_input number of MIDI inputs
* @param midi_input_buffer an array of MIDI input buffers (from master)
* @param audio_output number of audio outputs
* @param audio_output_buffer an array of audio output buffers (to master)
* @param midi_output number of MIDI outputs
* @param midi_output_buffer an array of MIDI output buffers (to master)
* @param arg pointer to a client supplied structure supplied by jack_set_net_process_callback()
*
* @return zero on success, non-zero on error
*/
typedef int (* JackNetSlaveProcessCallback) (jack_nframes_t buffer_size,
int audio_input,
float** audio_input_buffer,
int midi_input,
void** midi_input_buffer,
int audio_output,
float** audio_output_buffer,
int midi_output,
void** midi_output_buffer,
void* data);

/**
* Set network process callback.
* @param net the network connection
* @param net_callback the process callback
* @param arg pointer to a client supplied structure
*
* @return 0 on success, otherwise a non-zero error code
*/
int jack_set_net_slave_process_callback(jack_net_slave_t * net, JackNetSlaveProcessCallback net_callback, void *arg);

/**
* Start processing thread, the net_callback will start to be called.
* @param net the network connection
*
* @return 0 on success, otherwise a non-zero error code
*/
int jack_net_slave_activate(jack_net_slave_t* net);

/**
* Stop processing thread.
* @param net the network connection
*
* @return 0 on success, otherwise a non-zero error code
*/
int jack_net_slave_deactivate(jack_net_slave_t* net);

/**
* Prototype for BufferSize callback.
* @param nframes buffer size
* @param arg pointer to a client supplied structure supplied by jack_set_net_buffer_size_callback()
*
* @return zero on success, non-zero on error
*/
typedef int (*JackNetSlaveBufferSizeCallback)(jack_nframes_t nframes, void *arg);

/**
* Prototype for SampleRate callback.
* @param nframes sample rate
* @param arg pointer to a client supplied structure supplied by jack_set_net_sample_rate_callback()
*
* @return zero on success, non-zero on error
*/
typedef int (*JackNetSlaveSampleRateCallback)(jack_nframes_t nframes, void *arg);

/**
* Set network buffer size callback.
* @param net the network connection
* @param bufsize_callback the buffer size callback
* @param arg pointer to a client supplied structure
*
* @return 0 on success, otherwise a non-zero error code
*/
int jack_set_net_slave_buffer_size_callback(jack_net_slave_t *net, JackNetSlaveBufferSizeCallback bufsize_callback, void *arg);

/**
* Set network sample rate callback.
* @param net the network connection
* @param samplerate_callback the sample rate callback
* @param arg pointer to a client supplied structure
*
* @return 0 on success, otherwise a non-zero error code
*/
int jack_set_net_slave_sample_rate_callback(jack_net_slave_t *net, JackNetSlaveSampleRateCallback samplerate_callback, void *arg);

/**
* Prototype for server Shutdown callback (if not set, the client will just restart, waiting for an available master again).
* @param arg pointer to a client supplied structure supplied by jack_set_net_shutdown_callback()
*/
typedef void (*JackNetSlaveShutdownCallback)(void* data);

/**
* Set network shutdown callback.
* @param net the network connection
* @param shutdown_callback the shutdown callback
* @param arg pointer to a client supplied structure
*
* @return 0 on success, otherwise a non-zero error code
*/
int jack_set_net_slave_shutdown_callback(jack_net_slave_t *net, JackNetSlaveShutdownCallback shutdown_callback, void *arg);

/**
* jack_net_master_t is an opaque type, you may only access it using the API provided.
*/
typedef struct _jack_net_master jack_net_master_t;

/**
* Open a network connection with the slave machine.
* @param ip the multicast address of the master
* @param port the connection port
* @param request a connection request structure
* @param result a connection result structure
*
* @return Opaque net handle if successful or NULL in case of error.
*/
jack_net_master_t* jack_net_master_open(const char* ip, int port, const char* name, jack_master_t* request, jack_slave_t* result);

/**
* Close the network connection with the slave machine.
* @param net the network connection to be closed
*
* @return 0 on success, otherwise a non-zero error code
*/
int jack_net_master_close(jack_net_master_t* net);

/**
* Receive sync and data from the network.
* @param net the network connection
* @param audio_input number of audio inputs
* @param audio_input_buffer an array of audio input buffers
* @param midi_input number of MIDI inputs
* @param midi_input_buffer an array of MIDI input buffers
*
* @return zero on success, non-zero on error
*/
int jack_net_master_recv(jack_net_master_t* net, int audio_input, float** audio_input_buffer, int midi_input, void** midi_input_buffer);

/**
* Send sync and data to the network.
* @param net the network connection
* @param audio_output number of audio outputs
* @param audio_output_buffer an array of audio output buffers
* @param midi_output number of MIDI ouputs
* @param midi_output_buffer an array of MIDI output buffers
*
* @return zero on success, non-zero on error
*/
int jack_net_master_send(jack_net_master_t* net, int audio_output, float** audio_output_buffer, int midi_output, void** midi_output_buffer);

// Experimental Adapter API

/**
* jack_adapter_t is an opaque type, you may only access it using the API provided.
*/
typedef struct _jack_adapter jack_adapter_t;

/**
* Create an adapter.
* @param input number of audio inputs
* @param output of audio outputs
* @param host_buffer_size the host buffer size in frames
* @param host_sample_rate the host buffer sample rate
* @param adapted_buffer_size the adapted buffer size in frames
* @param adapted_sample_rate the adapted buffer sample rate
*
* @return 0 on success, otherwise a non-zero error code
*/
jack_adapter_t* jack_create_adapter(int input, int output,
jack_nframes_t host_buffer_size,
jack_nframes_t host_sample_rate,
jack_nframes_t adapted_buffer_size,
jack_nframes_t adapted_sample_rate);

/**
* Destroy an adapter.
* @param adapter the adapter to be destroyed
*
* @return 0 on success, otherwise a non-zero error code
*/
int jack_destroy_adapter(jack_adapter_t* adapter);

/**
* Flush internal state of an adapter.
* @param adapter the adapter to be flushed
*
* @return 0 on success, otherwise a non-zero error code
*/
void jack_flush_adapter(jack_adapter_t* adapter);

/**
* Push input to and pull output from adapter ringbuffer.
* @param adapter the adapter
* @param input an array of audio input buffers
* @param output an array of audio ouput buffers
* @param frames number of frames
*
* @return 0 on success, otherwise a non-zero error code
*/
int jack_adapter_push_and_pull(jack_adapter_t* adapter, float** input, float** output, unsigned int frames);

/**
* Pull input to and push output from adapter ringbuffer.
* @param adapter the adapter
* @param input an array of audio input buffers
* @param output an array of audio ouput buffers
* @param frames number of frames
*
* @return 0 on success, otherwise a non-zero error code
*/
int jack_adapter_pull_and_push(jack_adapter_t* adapter, float** input, float** output, unsigned int frames);

#ifdef __cplusplus
}
#endif

#endif /* __net_h__ */
10 changes: 10 additions & 0 deletions ringbuffer.h
Expand Up @@ -194,6 +194,16 @@ int jack_ringbuffer_mlock(jack_ringbuffer_t *rb);
*/
void jack_ringbuffer_reset(jack_ringbuffer_t *rb);

/**
* Reset the internal "available" size, and read and write pointers, making an empty buffer.
*
* This is not thread safe.
*
* @param rb a pointer to the ringbuffer structure.
* @param sz the new size, that must be less than allocated size.
*/
void jack_ringbuffer_reset_size (jack_ringbuffer_t * rb, size_t sz);

/**
* Write data into the ringbuffer.
*
Expand Down
26 changes: 15 additions & 11 deletions session.h
Expand Up @@ -37,7 +37,7 @@ extern "C" {
/**
* Session event type.
*
* if a client cant save templates, i might just do a normal save.
* If a client cant save templates, i might just do a normal save.
*
* There is no "quit without saving" event because a client might refuse to
* quit when it has unsaved data, but other clients may have already quit.
Expand Down Expand Up @@ -190,17 +190,19 @@ int jack_session_reply (jack_client_t *client,


/**
* free memory used by a jack_session_event_t
* this also frees the memory used by the command_line pointer.
* if its non NULL.
* Free memory used by a jack_session_event_t.
*
* This also frees the memory used by the command_line pointer, if its non NULL.
*/
void jack_session_event_free (jack_session_event_t *event) JACK_WEAK_EXPORT;


/**
* get the assigned uuid for client.
* safe to call from callback and all other threads.
* memory needs to be freed.
* Get the assigned uuid for client.
* Safe to call from callback and all other threads.
*
* The caller is responsible for calling jack_free(3) on any non-NULL
* returned value.
*/
char *jack_client_get_uuid (jack_client_t *client) JACK_WEAK_EXPORT;

Expand Down Expand Up @@ -243,6 +245,9 @@ void jack_session_commands_free (jack_session_command_t *cmds) JACK_WEAK_EXPORT;
* Get the session ID for a client name.
*
* The session manager needs this to reassociate a client name to the session_id.
*
* The caller is responsible for calling jack_free(3) on any non-NULL
* returned value.
*/
char *jack_get_uuid_for_client_name (jack_client_t *client,
const char *client_name) JACK_WEAK_EXPORT;
Expand All @@ -252,6 +257,9 @@ char *jack_get_uuid_for_client_name (jack_client_t *client,
*
* In order to snapshot the graph connections, the session manager needs to map
* session_ids to client names.
*
* The caller is responsible for calling jack_free(3) on any non-NULL
* returned value.
*/
char *jack_get_client_name_by_uuid (jack_client_t *client,
const char *client_uuid ) JACK_WEAK_EXPORT;
Expand Down Expand Up @@ -279,10 +287,6 @@ jack_reserve_client_name (jack_client_t *client,
int
jack_client_has_session_callback (jack_client_t *client, const char *client_name) JACK_WEAK_EXPORT;

/**
* @}
*/

#ifdef __cplusplus
}
#endif
Expand Down
123 changes: 123 additions & 0 deletions systemdeps.h
@@ -0,0 +1,123 @@
/*
Copyright (C) 2004-2012 Grame
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#ifndef __jack_systemdeps_h__
#define __jack_systemdeps_h__

#ifndef POST_PACKED_STRUCTURE

#ifdef __GNUC__
/* POST_PACKED_STRUCTURE needs to be a macro which
expands into a compiler directive. The directive must
tell the compiler to arrange the preceding structure
declaration so that it is packed on byte-boundaries rather
than use the natural alignment of the processor and/or
compiler.
*/

#define PRE_PACKED_STRUCTURE
#define POST_PACKED_STRUCTURE __attribute__((__packed__))

#else

#ifdef _MSC_VER
#define PRE_PACKED_STRUCTURE1 __pragma(pack(push,1))
#define PRE_PACKED_STRUCTURE PRE_PACKED_STRUCTURE1
/* PRE_PACKED_STRUCTURE needs to be a macro which
expands into a compiler directive. The directive must
tell the compiler to arrange the following structure
declaration so that it is packed on byte-boundaries rather
than use the natural alignment of the processor and/or
compiler.
*/
#define POST_PACKED_STRUCTURE ;__pragma(pack(pop))
/* and POST_PACKED_STRUCTURE needs to be a macro which
restores the packing to its previous setting */
#else
#define PRE_PACKED_STRUCTURE
#define POST_PACKED_STRUCTURE
#endif

#endif

#endif

#if defined(WIN32) && !defined(__CYGWIN__) && !defined(GNU_WIN32)

#include <windows.h>

#ifdef _MSC_VER /* Microsoft compiler */
#define __inline__ inline
#if (!defined(int8_t) && !defined(_STDINT_H))
#define __int8_t_defined
typedef char int8_t;
typedef unsigned char uint8_t;
typedef short int16_t;
typedef unsigned short uint16_t;
typedef long int32_t;
typedef unsigned long uint32_t;
typedef LONGLONG int64_t;
typedef ULONGLONG uint64_t;
#endif
#elif __MINGW32__ /* MINGW */
#include <stdint.h>
#include <sys/types.h>
#else /* other compilers ...*/
#include <inttypes.h>
#include <pthread.h>
#include <sys/types.h>
#endif

#if !defined(_PTHREAD_H) && !defined(PTHREAD_WIN32)
/**
* to make jack API independent of different thread implementations,
* we define jack_native_thread_t to HANDLE here.
*/
typedef HANDLE jack_native_thread_t;
#else
#ifdef PTHREAD_WIN32 // Added by JE - 10-10-2011
#include <ptw32/pthread.h> // Makes sure we #include the ptw32 version !
#endif
/**
* to make jack API independent of different thread implementations,
* we define jack_native_thread_t to pthread_t here.
*/
typedef pthread_t jack_native_thread_t;
#endif

#endif // WIN32 && !__CYGWIN__ && !GNU_WIN32 */

#if defined(__APPLE__) || defined(__linux__) || defined(__sun__) || defined(sun) || defined(__unix__) || defined(__CYGWIN__) || defined(GNU_WIN32)

#if defined(__CYGWIN__) || defined(GNU_WIN32)
#include <stdint.h>
#endif
#include <inttypes.h>
#include <pthread.h>
#include <sys/types.h>

/**
* to make jack API independent of different thread implementations,
* we define jack_native_thread_t to pthread_t here.
*/
typedef pthread_t jack_native_thread_t;

#endif /* __APPLE__ || __linux__ || __sun__ || sun */

#endif
31 changes: 27 additions & 4 deletions thread.h
Expand Up @@ -25,9 +25,8 @@ extern "C"
{
#endif

#include <pthread.h>
#include <jack/systemdeps.h>
#include <jack/weakmacros.h>
#include <jack/types.h>

/* use 512KB stack per thread - the default is way too high to be feasible
* with mlockall() on many systems */
Expand Down Expand Up @@ -105,10 +104,30 @@ int jack_client_create_thread (jack_client_t* client,
*/
int jack_drop_real_time_scheduling (jack_native_thread_t thread) JACK_OPTIONAL_WEAK_EXPORT;

typedef int (*jack_thread_creator_t)(jack_native_thread_t*,
/**
* Stop the thread, waiting for the thread handler to terminate.
*
* @param thread POSIX thread ID.
*
* @returns 0, if successful; otherwise an error number.
*/
int jack_client_stop_thread(jack_client_t* client, jack_native_thread_t thread) JACK_OPTIONAL_WEAK_EXPORT;

/**
* Kill the thread.
*
* @param thread POSIX thread ID.
*
* @returns 0, if successful; otherwise an error number.
*/
int jack_client_kill_thread(jack_client_t* client, jack_native_thread_t thread) JACK_OPTIONAL_WEAK_EXPORT;

#ifndef WIN32

typedef int (*jack_thread_creator_t)(pthread_t*,
const pthread_attr_t*,
void* (*function)(void*),
void* arg) JACK_OPTIONAL_WEAK_EXPORT;
void* arg);
/**
* This function can be used in very very specialized cases
* where it is necessary that client threads created by JACK
Expand All @@ -123,11 +142,15 @@ typedef int (*jack_thread_creator_t)(jack_native_thread_t*,
* that all threads that might call win32 functions are known
* to Wine.
*
* Set it to NULL to restore thread creation function.
*
* @param creator a function that creates a new thread
*
*/
void jack_set_thread_creator (jack_thread_creator_t creator) JACK_OPTIONAL_WEAK_EXPORT;

#endif

/* @} */

#ifdef __cplusplus
Expand Down
43 changes: 12 additions & 31 deletions transport.h
Expand Up @@ -28,21 +28,6 @@ extern "C" {
#include <jack/types.h>
#include <jack/weakmacros.h>

#ifndef POST_PACKED_STRUCTURE
#ifdef __GNUC__
/* POST_PACKED_STRUCTURE needs to be a macro which
expands into a compiler directive. The directive must
tell the compiler to arrange the preceding structure
declaration so that it is packed on byte-boundaries rather
than use the natural alignment of the processor and/or
compiler.
*/
#define POST_PACKED_STRUCTURE __attribute__((__packed__))
#else
/* Add other things here for non-gcc platforms */
#endif
#endif

/**
* @defgroup TransportControl Transport and Timebase control
* @{
Expand All @@ -67,7 +52,7 @@ extern "C" {
int jack_release_timebase (jack_client_t *client) JACK_OPTIONAL_WEAK_EXPORT;

/**
* Register (or unregister) as a @ref slowsyncclients "slow-sync client", that cannot
* Register (or unregister) as a slow-sync client, one that cannot
* respond immediately to transport position changes.
*
* The @a sync_callback will be invoked at the first available
Expand All @@ -91,7 +76,7 @@ int jack_set_sync_callback (jack_client_t *client,
void *arg) JACK_OPTIONAL_WEAK_EXPORT;

/**
* Set the timeout value for @ref slowsyncclients "slow-sync clients".
* Set the timeout value for slow-sync clients.
*
* This timeout prevents unresponsive slow-sync clients from
* completely halting the transport mechanism. The default is two
Expand Down Expand Up @@ -123,8 +108,6 @@ int jack_set_sync_timeout (jack_client_t *client,
* Taking over the timebase may be done conditionally, so it fails if
* there was a master already.
*
* The method may be called whether the client has been activated or not.
*
* @param client the JACK client structure.
* @param conditional non-zero for a conditional request.
* @param timebase_callback is a realtime function that returns
Expand All @@ -146,9 +129,9 @@ int jack_set_timebase_callback (jack_client_t *client,
* Reposition the transport to a new frame number.
*
* May be called at any time by any client. The new position takes
* effect in two process cycles. If there are @ref slowsyncclients
* "slow-sync clients" and the transport is already rolling, it will
* enter the ::JackTransportStarting state and begin invoking their @a
* effect in two process cycles. If there are slow-sync clients and
* the transport is already rolling, it will enter the
* ::JackTransportStarting state and begin invoking their @a
* sync_callbacks until ready. This function is realtime-safe.
*
* @see jack_transport_reposition, jack_set_sync_callback
Expand Down Expand Up @@ -192,17 +175,15 @@ jack_nframes_t jack_get_current_transport_frame (const jack_client_t *client) JA
* Request a new transport position.
*
* May be called at any time by any client. The new position takes
* effect in two process cycles. If there are @ref slowsyncclients
* "slow-sync clients" and the transport is already rolling, it will
* enter the ::JackTransportStarting state and begin invoking their @a
* effect in two process cycles. If there are slow-sync clients and
* the transport is already rolling, it will enter the
* ::JackTransportStarting state and begin invoking their @a
* sync_callbacks until ready. This function is realtime-safe.
*
* @see jack_transport_locate, jack_set_sync_callback
*
* @param client the JACK client structure.
* @param pos requested new transport position. Fill pos->valid to specify
* which fields should be taken into account. If you mark a set of fields
* as valid, you are expected to fill them all.
* @param pos requested new transport position.
*
* @return 0 if valid request, EINVAL if position structure rejected.
*/
Expand All @@ -214,7 +195,7 @@ int jack_transport_reposition (jack_client_t *client,
*
* Any client can make this request at any time. It takes effect no
* sooner than the next process cycle, perhaps later if there are
* @ref slowsyncclients "slow-sync clients". This function is realtime-safe.
* slow-sync clients. This function is realtime-safe.
*
* @see jack_set_sync_callback
*
Expand Down Expand Up @@ -245,7 +226,7 @@ void jack_transport_stop (jack_client_t *client) JACK_OPTIONAL_WEAK_EXPORT;
* @pre Must be called from the process thread.
*/
void jack_get_transport_info (jack_client_t *client,
jack_transport_info_t *tinfo) JACK_OPTIONAL_WEAK_DEPRECATED_EXPORT;
jack_transport_info_t *tinfo) JACK_OPTIONAL_WEAK_EXPORT;

/**
* Set the transport info structure (deprecated).
Expand All @@ -255,7 +236,7 @@ void jack_get_transport_info (jack_client_t *client,
* a ::JackTimebaseCallback.
*/
void jack_set_transport_info (jack_client_t *client,
jack_transport_info_t *tinfo) JACK_OPTIONAL_WEAK_DEPRECATED_EXPORT;
jack_transport_info_t *tinfo) JACK_OPTIONAL_WEAK_EXPORT;

/*@}*/

Expand Down
170 changes: 63 additions & 107 deletions types.h
Expand Up @@ -21,8 +21,7 @@
#ifndef __jack_types_h__
#define __jack_types_h__

#include <inttypes.h>
#include <pthread.h>
#include <jack/systemdeps.h>

typedef int32_t jack_shmsize_t;

Expand Down Expand Up @@ -74,12 +73,7 @@ typedef struct _jack_client jack_client_t;
*/
typedef uint32_t jack_port_id_t;

/**
* to make jack API independent of different thread implementations,
* we define jack_native_thread_t to pthread_t here.
* (all platforms that jack1 runs on, have pthread)
*/
typedef pthread_t jack_native_thread_t;
typedef uint32_t jack_port_type_id_t;

/**
* @ref jack_options_t bits
Expand Down Expand Up @@ -215,7 +209,7 @@ enum JackStatus {
JackBackendError = 0x800,

/**
* Client is being shutdown against its will
* Client zombified failure
*/
JackClientZombie = 0x1000
};
Expand Down Expand Up @@ -266,6 +260,7 @@ typedef void (*JackLatencyCallback)(jack_latency_callback_mode_t mode, void *arg
/**
* the new latency API operates on Ranges.
*/
PRE_PACKED_STRUCTURE
struct _jack_latency_range
{
/**
Expand All @@ -276,7 +271,7 @@ struct _jack_latency_range
* maximum latency
*/
jack_nframes_t max;
};
} POST_PACKED_STRUCTURE;

typedef struct _jack_latency_range jack_latency_range_t;

Expand All @@ -288,12 +283,19 @@ typedef struct _jack_latency_range jack_latency_range_t;
* @pre nframes == pow(2,x)
*
* @param nframes number of frames to process
* @param arg pointer to a client supplied data
* @param arg pointer to a client supplied structure
*
* @return zero on success, non-zero on error
*/
typedef int (*JackProcessCallback)(jack_nframes_t nframes, void *arg);

/**
* Prototype for the client thread routine called
* by the engine when the client is inserted in the graph.
*
* @param arg pointer to a client supplied structure
*
*/
typedef void *(*JackThreadCallback)(void* arg);

/**
Expand All @@ -314,7 +316,7 @@ typedef void (*JackThreadInitCallback)(void *arg);
* Prototype for the client supplied function that is called
* whenever the processing graph is reordered.
*
* @param arg pointer to a client supplied data
* @param arg pointer to a client supplied structure
*
* @return zero on success, non-zero on error
*/
Expand All @@ -326,7 +328,7 @@ typedef int (*JackGraphOrderCallback)(void *arg);
*
* @see jack_get_xrun_delayed_usecs()
*
* @param arg pointer to a client supplied data
* @param arg pointer to a client supplied structure
*
* @return zero on success, non-zero on error
*/
Expand All @@ -353,7 +355,7 @@ typedef int (*JackBufferSizeCallback)(jack_nframes_t nframes, void *arg);
* when the engine sample rate changes.
*
* @param nframes new engine sample rate
* @param arg pointer to a client supplied data
* @param arg pointer to a client supplied structure
*
* @return zero on success, non-zero on error
*/
Expand All @@ -377,13 +379,13 @@ typedef void (*JackPortRegistrationCallback)(jack_port_id_t port, int register,
* @param name a null-terminated string containing the client name
* @param register non-zero if the client is being registered,
* zero if the client is being unregistered
* @param arg pointer to a client supplied data
* @param arg pointer to a client supplied structure
*/
typedef void (*JackClientRegistrationCallback)(const char* name, int register, void *arg);

/**
* Prototype for the client supplied function that is called
* whenever a client is registered or unregistered.
* whenever a port is connected or disconnected.
*
* @param a one of two ports connected or disconnected
* @param b one of two ports connected or disconnected
Expand All @@ -393,6 +395,18 @@ typedef void (*JackClientRegistrationCallback)(const char* name, int register, v
*/
typedef void (*JackPortConnectCallback)(jack_port_id_t a, jack_port_id_t b, int connect, void* arg);

/**
* Prototype for the client supplied function that is called
* whenever the port name has been changed.
*
* @param port the port that has been renamed
* @param new_name the new name
* @param arg pointer to a client supplied structure
*
* @return zero on success, non-zero on error
*/
typedef int (*JackPortRenameCallback)(jack_port_id_t port, const char* old_name, const char* new_name, void *arg);

/**
* Prototype for the client supplied function that is called
* whenever jackd starts or stops freewheeling.
Expand Down Expand Up @@ -423,16 +437,16 @@ typedef void (*JackShutdownCallback)(void *arg);
* to release client ressources. Warning: jack_client_close() cannot be
* safely used inside the shutdown callback and has to be called outside of
* the callback context.
*
* @param code a shutdown code
* @param code a status word, formed by OR-ing together the relevant @ref JackStatus bits.
* @param reason a string describing the shutdown reason (backend failure, server crash... etc...)
* @param arg pointer to a client supplied structure
*/
typedef void (*JackInfoShutdownCallback)(jack_status_t code, const char* reason, void *arg);

/**
* Used for the type argument of jack_port_register() for default
* audio and midi ports.
* audio ports and midi ports.
*/
#define JACK_DEFAULT_AUDIO_TYPE "32 bit float mono audio"
#define JACK_DEFAULT_MIDI_TYPE "8 bit raw midi"
Expand All @@ -445,7 +459,7 @@ typedef void (*JackInfoShutdownCallback)(jack_status_t code, const char* reason,
typedef float jack_default_audio_sample_t;

/**
* A port has a set of flags that are formed by OR-ing together the
* A port has a set of flags that are formed by AND-ing together the
* desired values from the list below. The flags "JackPortIsInput" and
* "JackPortIsOutput" are mutually exclusive and it is an error to use
* them both.
Expand Down Expand Up @@ -511,7 +525,8 @@ typedef enum {
JackTransportStopped = 0, /**< Transport halted */
JackTransportRolling = 1, /**< Transport playing */
JackTransportLooping = 2, /**< For OLD_TRANSPORT, now ignored */
JackTransportStarting = 3 /**< Waiting for sync ready */
JackTransportStarting = 3, /**< Waiting for sync ready */
JackTransportNetStarting = 4, /**< Waiting for sync ready on the network*/

} jack_transport_state_t;

Expand All @@ -530,101 +545,45 @@ typedef enum {
} jack_position_bits_t;

/** all valid position bits */
#define JACK_POSITION_MASK (JackPositionBBT|JackPositionTimecode|JackBBTFrameOffset|JackAudioVideoRatio|JackVideoFrameOffset)
#define JACK_POSITION_MASK (JackPositionBBT|JackPositionTimecode)
#define EXTENDED_TIME_INFO

/**
* Struct for transport position information.
*/
typedef struct {
PRE_PACKED_STRUCTURE
struct _jack_position {

/*@{*/
/** @name Server-set fields
* these cannot be set from clients; the server sets them */
/* these four cannot be set from clients: the server sets them */
jack_unique_t unique_1; /**< unique ID */
jack_time_t usecs;
/**< microsecond timestamp that is guaranteed to be
monotonic, but not neccessarily
linear.
The absolute value is
implementation-dependent (i.e. it
could be wall-clock, time since
jack started, uptime, etc). */
/**< monotonic, free-rolling */
jack_nframes_t frame_rate;
/**< current frame rate, in frames per second */
/*}@*/

/*@{*/
/** @name Mandatory fields
*/
/**< current frame rate (per second) */
jack_nframes_t frame;
/**< frame number, always present/required.
/**< frame number, always present */

This is the frame number on the
transport timeline, which is not
the same as what @ref
jack_frame_time returns. */
jack_position_bits_t valid;
/**< which other fields are valid, as a
bitmask constructed from values in
\ref jack_position_bits_t */
/*}@*/

/*@{*/
/** @name JackPositionBBT fields
* Bar:Beat.Tick-related information.
*
* Applications that support
* JackPositionBBT are encouraged to also fill the JackBBTFrameOffset
*/
/**< which other fields are valid */

/* JackPositionBBT fields: */
int32_t bar;
/**< current bar
Should be >0: the first bar is
bar '1'. */
/**< current bar */
int32_t beat;
/**< current beat-within-bar
Should be >0 and <=beats_per_bar:
the first beat is beat '1'. */
/**< current beat-within-bar */
int32_t tick;
/**< current tick-within-beat
Should be >0 and <=ticks_per_beat:
the first tick is tick '0'. */
/**< current tick-within-beat */
double bar_start_tick;
/**< number of ticks that have elapsed
between frame 0 and the first beat
of the current measure. */

float beats_per_bar;
/**< time signature "numerator" */
float beat_type;
/**< time signature "denominator" */
double ticks_per_beat;
/**< number of ticks within a bar.
Usually a moderately large integer
with many denominators, such as
1920.0 */
double beats_per_minute;
/**< BPM, quantized to block size. This
means when the tempo is not constant
within this block, the BPM value should
adapted to compensate for this. This
is different from most fields in this
struct, which specify the value at
the beginning of the block rather
than an average.*/
/*}@*/

/*@{*/
/** @name JackPositionTimecode fields
* EXPERIMENTAL: could change */

/* JackPositionTimecode fields: (EXPERIMENTAL: could change) */
double frame_time; /**< current time in seconds */
double next_time; /**< next sequential frame_time
(unless repositioned) */
/*}@*/

/*@{*/
/* JackBBTFrameOffset fields: */
jack_nframes_t bbt_offset; /**< frame offset for the BBT fields
(the given bar, beat, and tick
Expand All @@ -640,11 +599,9 @@ typedef struct {
the BBT time refers to a frame that
many frames before the start of the
cycle. */
/*}@*/

/*@{*/
/* JACK video positional data
* EXPERIMENTAL: could change */
/* JACK video positional data (experimental) */

float audio_frames_per_video_frame; /**< number of audio frames
per video frame. Should be assumed
zero if JackAudioVideoRatio is not
Expand All @@ -658,27 +615,26 @@ typedef struct {
is not set. If JackVideoFrameOffset is
set, but the value is zero, there is
no video frame within this cycle. */
/*}@*/

/*@{*/
/** @name Other fields */
/* For binary compatibility, new fields should be allocated from
* this padding area with new valid bits controlling access, so
* the existing structure size and offsets are preserved. */
int32_t padding[7];
/*}@*/

/* When (unique_1 == unique_2) the contents are consistent. */
jack_unique_t unique_2; /**< unique ID */

} POST_PACKED_STRUCTURE jack_position_t;
} POST_PACKED_STRUCTURE;

typedef struct _jack_position jack_position_t;

/**
* Prototype for the @a sync_callback defined by @ref slowsyncclients
* "slow-sync clients". When the client is active, this callback is
* invoked just before process() in the same thread. This occurs once
* after registration, then subsequently whenever some client requests
* a new position, or the transport enters the ::JackTransportStarting
* state. This realtime function must not wait.
* Prototype for the @a sync_callback defined by slow-sync clients.
* When the client is active, this callback is invoked just before
* process() in the same thread. This occurs once after registration,
* then subsequently whenever some client requests a new position, or
* the transport enters the ::JackTransportStarting state. This
* realtime function must not wait.
*
* The transport @a state will be:
*
Expand Down
2 changes: 1 addition & 1 deletion weakjack.h
Expand Up @@ -21,7 +21,7 @@
#define __weakjack_h__

/**
* @defgroup WeakLinkage managing support for newer/older versions of JACK
* @defgroup WeakLinkage Managing support for newer/older versions of JACK
* @{ One challenge faced by developers is that of taking
* advantage of new features introduced in new versions
* of [ JACK ] while still supporting older versions of
Expand Down
31 changes: 30 additions & 1 deletion weakmacros.h
Expand Up @@ -46,12 +46,31 @@
the symbol it used with. For this to work full may
require linker arguments in the client as well.
*/
#define JACK_WEAK_EXPORT __attribute__((WEAK_ATTRIBUTE))

#ifdef WIN32
/*
Not working with __declspec(dllexport) so normal linking
Linking with JackWeakAPI.cpp will be the preferred way.
*/
#define JACK_WEAK_EXPORT
#else
#define JACK_WEAK_EXPORT __attribute__((WEAK_ATTRIBUTE))
#endif

#else
/* Add other things here for non-gcc platforms */

#ifdef WIN32
#define JACK_WEAK_EXPORT
#endif

#endif
#endif

#ifndef JACK_WEAK_EXPORT
#define JACK_WEAK_EXPORT
#endif

#ifndef JACK_OPTIONAL_WEAK_EXPORT
#define JACK_OPTIONAL_WEAK_EXPORT
#endif
Expand All @@ -61,7 +80,17 @@
#define JACK_OPTIONAL_WEAK_DEPRECATED_EXPORT __attribute__((__deprecated__))
#else
/* Add other things here for non-gcc platforms */

#ifdef WIN32
#define JACK_OPTIONAL_WEAK_DEPRECATED_EXPORT
#endif

#endif /* __GNUC__ */

#ifndef JACK_OPTIONAL_WEAK_DEPRECATED_EXPORT
#define JACK_OPTIONAL_WEAK_DEPRECATED_EXPORT
#endif

#endif

#endif /* __weakmacros_h__ */