git-svn-id: svn+ssh://jackaudio.org/trunk/jack@3113 0c269be4-1314-0410-8aa9-9f06e86f4224tags/0.115.6
@@ -1,6 +1,7 @@ | |||||
MAINTAINERCLEANFILES = Makefile.in | MAINTAINERCLEANFILES = Makefile.in | ||||
bin_PROGRAMS = jack_simple_client \ | bin_PROGRAMS = jack_simple_client \ | ||||
jack_transport_client \ | |||||
jack_impulse_grabber \ | jack_impulse_grabber \ | ||||
jack_metro \ | jack_metro \ | ||||
jack_showtime \ | jack_showtime \ | ||||
@@ -17,27 +18,31 @@ AM_CXXFLAGS = -I.. $(JACK_CFLAGS) $(sndfile_cflags) | |||||
jack_simple_client_SOURCES = simple_client.c | jack_simple_client_SOURCES = simple_client.c | ||||
jack_simple_client_LDFLAGS = @OS_LDFLAGS@ | jack_simple_client_LDFLAGS = @OS_LDFLAGS@ | ||||
jack_simple_client_LDADD = ../libjack/libjack.la | |||||
jack_simple_client_LDADD = $(top_builddir)/libjack/libjack.la | |||||
jack_transport_client_SOURCES = transport_client.c | |||||
jack_transport_client_LDFLAGS = @OS_LDFLAGS@ | |||||
jack_transport_client_LDADD = $(top_builddir)/libjack/libjack.la | |||||
jack_metro_SOURCES = metro.c | jack_metro_SOURCES = metro.c | ||||
jack_metro_LDFLAGS = @OS_LDFLAGS@ | jack_metro_LDFLAGS = @OS_LDFLAGS@ | ||||
jack_metro_LDADD = ../libjack/libjack.la | |||||
jack_metro_LDADD = $(top_builddir)/libjack/libjack.la | |||||
jack_showtime_SOURCES = showtime.c | jack_showtime_SOURCES = showtime.c | ||||
jack_showtime_LDFLAGS = @OS_LDFLAGS@ | jack_showtime_LDFLAGS = @OS_LDFLAGS@ | ||||
jack_showtime_LDADD = ../libjack/libjack.la | |||||
jack_showtime_LDADD = $(top_builddir)/libjack/libjack.la | |||||
jack_impulse_grabber_SOURCES = impulse_grabber.c | jack_impulse_grabber_SOURCES = impulse_grabber.c | ||||
jack_impulse_grabber_LDFLAGS = @OS_LDFLAGS@ | jack_impulse_grabber_LDFLAGS = @OS_LDFLAGS@ | ||||
jack_impulse_grabber_LDADD = ../libjack/libjack.la | |||||
jack_impulse_grabber_LDADD = $(top_builddir)/libjack/libjack.la | |||||
jack_midiseq_SOURCES = midiseq.c | jack_midiseq_SOURCES = midiseq.c | ||||
jack_midiseq_LDFLAGS = @OS_LDFLAGS@ | jack_midiseq_LDFLAGS = @OS_LDFLAGS@ | ||||
jack_midiseq_LDADD = ../libjack/libjack.la | |||||
jack_midiseq_LDADD = $(top_builddir)/libjack/libjack.la | |||||
jack_midisine_SOURCES = midisine.c | jack_midisine_SOURCES = midisine.c | ||||
jack_midisine_LDFLAGS = @OS_LDFLAGS@ | jack_midisine_LDFLAGS = @OS_LDFLAGS@ | ||||
jack_midisine_LDADD = ../libjack/libjack.la | |||||
jack_midisine_LDADD = $(top_builddir)/libjack/libjack.la | |||||
# | # | ||||
# sample in-process client(s) | # sample in-process client(s) | ||||
@@ -1,6 +1,6 @@ | |||||
/** @file simple_client.c | /** @file simple_client.c | ||||
* | * | ||||
* @brief This simple client demonstrates the basic features of JACK | |||||
* @brief This simple client demonstrates the most basic features of JACK | |||||
* as they would be used by many applications. | * as they would be used by many applications. | ||||
*/ | */ | ||||
@@ -16,41 +16,23 @@ jack_port_t *input_port; | |||||
jack_port_t *output_port; | jack_port_t *output_port; | ||||
jack_client_t *client; | jack_client_t *client; | ||||
/* a simple state machine for this client */ | |||||
volatile enum { | |||||
Init, | |||||
Run, | |||||
Exit | |||||
} client_state = Init; | |||||
/** | /** | ||||
* The process callback for this JACK application is called in a | * The process callback for this JACK application is called in a | ||||
* special realtime thread once for each audio cycle. | * special realtime thread once for each audio cycle. | ||||
* | * | ||||
* This client follows a simple rule: when the JACK transport is | |||||
* running, copy the input port to the output. When it stops, exit. | |||||
* This client does nothing more than copy data from its input | |||||
* port to its output port. It will exit when stopped by | |||||
* the user (e.g. using Ctrl-C on a unix-ish operating system) | |||||
*/ | */ | ||||
int | int | ||||
process (jack_nframes_t nframes, void *arg) | process (jack_nframes_t nframes, void *arg) | ||||
{ | { | ||||
jack_default_audio_sample_t *in, *out; | jack_default_audio_sample_t *in, *out; | ||||
jack_transport_state_t ts = jack_transport_query(client, NULL); | |||||
if (ts == JackTransportRolling) { | |||||
if (client_state == Init) | |||||
client_state = Run; | |||||
in = jack_port_get_buffer (input_port, nframes); | |||||
out = jack_port_get_buffer (output_port, nframes); | |||||
memcpy (out, in, | |||||
sizeof (jack_default_audio_sample_t) * nframes); | |||||
} else if (ts == JackTransportStopped) { | |||||
if (client_state == Run) | |||||
client_state = Exit; | |||||
} | |||||
in = jack_port_get_buffer (input_port, nframes); | |||||
out = jack_port_get_buffer (output_port, nframes); | |||||
memcpy (out, in, | |||||
sizeof (jack_default_audio_sample_t) * nframes); | |||||
return 0; | return 0; | ||||
} | } | ||||
@@ -69,26 +51,11 @@ int | |||||
main (int argc, char *argv[]) | main (int argc, char *argv[]) | ||||
{ | { | ||||
const char **ports; | const char **ports; | ||||
const char *client_name; | |||||
const char *client_name = "simple"; | |||||
const char *server_name = NULL; | const char *server_name = NULL; | ||||
jack_options_t options = JackNullOption; | jack_options_t options = JackNullOption; | ||||
jack_status_t status; | jack_status_t status; | ||||
if (argc >= 2) { /* client name specified? */ | |||||
client_name = argv[1]; | |||||
if (argc >= 3) { /* server name specified? */ | |||||
server_name = argv[2]; | |||||
options |= JackServerName; | |||||
} | |||||
} else { /* use basename of argv[0] */ | |||||
client_name = strrchr(argv[0], '/'); | |||||
if (client_name == 0) { | |||||
client_name = argv[0]; | |||||
} else { | |||||
client_name++; | |||||
} | |||||
} | |||||
/* open a client connection to the JACK server */ | /* open a client connection to the JACK server */ | ||||
client = jack_client_open (client_name, options, &status, server_name); | client = jack_client_open (client_name, options, &status, server_name); | ||||
@@ -183,11 +150,14 @@ main (int argc, char *argv[]) | |||||
free (ports); | free (ports); | ||||
/* keep running until the transport stops */ | |||||
/* keep running until stopped by the user */ | |||||
while (client_state != Exit) { | |||||
sleep (1); | |||||
} | |||||
sleep (-1); | |||||
/* this is never reached but if the program | |||||
had some other way to exit besides being killed, | |||||
they would be important to call. | |||||
*/ | |||||
jack_client_close (client); | jack_client_close (client); | ||||
exit (0); | exit (0); | ||||
@@ -0,0 +1,197 @@ | |||||
/** @file transport_client.c | |||||
* | |||||
* @brief This client demonstrates very simple use of the JACK | |||||
* transport API. Compare it with the simple_client example, | |||||
* which is even simpler. It also demonstrates taking a client | |||||
* name and optionally server name from the command line, rather | |||||
* than hard-coding either of these names. | |||||
*/ | |||||
#include <stdio.h> | |||||
#include <errno.h> | |||||
#include <unistd.h> | |||||
#include <stdlib.h> | |||||
#include <string.h> | |||||
#include <jack/jack.h> | |||||
jack_port_t *input_port; | |||||
jack_port_t *output_port; | |||||
jack_client_t *client; | |||||
/* a simple state machine for this client */ | |||||
volatile enum { | |||||
Init, | |||||
Run, | |||||
Exit | |||||
} client_state = Init; | |||||
/** | |||||
* The process callback for this JACK application is called in a | |||||
* special realtime thread once for each audio cycle. | |||||
* | |||||
* This client follows a simple rule: when the JACK transport is | |||||
* running, copy the input port to the output. When it stops, exit. | |||||
*/ | |||||
int | |||||
process (jack_nframes_t nframes, void *arg) | |||||
{ | |||||
jack_default_audio_sample_t *in, *out; | |||||
jack_transport_state_t ts = jack_transport_query(client, NULL); | |||||
if (ts == JackTransportRolling) { | |||||
if (client_state == Init) | |||||
client_state = Run; | |||||
in = jack_port_get_buffer (input_port, nframes); | |||||
out = jack_port_get_buffer (output_port, nframes); | |||||
memcpy (out, in, | |||||
sizeof (jack_default_audio_sample_t) * nframes); | |||||
} else if (ts == JackTransportStopped) { | |||||
if (client_state == Run) | |||||
client_state = Exit; | |||||
} | |||||
return 0; | |||||
} | |||||
/** | |||||
* JACK calls this shutdown_callback if the server ever shuts down or | |||||
* decides to disconnect the client. | |||||
*/ | |||||
void | |||||
jack_shutdown (void *arg) | |||||
{ | |||||
exit (1); | |||||
} | |||||
int | |||||
main (int argc, char *argv[]) | |||||
{ | |||||
const char **ports; | |||||
const char *client_name; | |||||
const char *server_name = NULL; | |||||
jack_options_t options = JackNullOption; | |||||
jack_status_t status; | |||||
if (argc >= 2) { /* client name specified? */ | |||||
client_name = argv[1]; | |||||
if (argc >= 3) { /* server name specified? */ | |||||
server_name = argv[2]; | |||||
options |= JackServerName; | |||||
} | |||||
} else { /* use basename of argv[0] */ | |||||
client_name = strrchr(argv[0], '/'); | |||||
if (client_name == 0) { | |||||
client_name = argv[0]; | |||||
} else { | |||||
client_name++; | |||||
} | |||||
} | |||||
/* open a client connection to the JACK server */ | |||||
client = jack_client_open (client_name, options, &status, server_name); | |||||
if (client == NULL) { | |||||
fprintf (stderr, "jack_client_open() failed, " | |||||
"status = 0x%2.0x\n", status); | |||||
if (status & JackServerFailed) { | |||||
fprintf (stderr, "Unable to connect to JACK server\n"); | |||||
} | |||||
exit (1); | |||||
} | |||||
if (status & JackServerStarted) { | |||||
fprintf (stderr, "JACK server started\n"); | |||||
} | |||||
if (status & JackNameNotUnique) { | |||||
client_name = jack_get_client_name(client); | |||||
fprintf (stderr, "unique name `%s' assigned\n", client_name); | |||||
} | |||||
/* tell the JACK server to call `process()' whenever | |||||
there is work to be done. | |||||
*/ | |||||
jack_set_process_callback (client, process, 0); | |||||
/* tell the JACK server to call `jack_shutdown()' if | |||||
it ever shuts down, either entirely, or if it | |||||
just decides to stop calling us. | |||||
*/ | |||||
jack_on_shutdown (client, jack_shutdown, 0); | |||||
/* display the current sample rate. | |||||
*/ | |||||
printf ("engine sample rate: %" PRIu32 "\n", | |||||
jack_get_sample_rate (client)); | |||||
/* create two ports */ | |||||
input_port = jack_port_register (client, "input", | |||||
JACK_DEFAULT_AUDIO_TYPE, | |||||
JackPortIsInput, 0); | |||||
output_port = jack_port_register (client, "output", | |||||
JACK_DEFAULT_AUDIO_TYPE, | |||||
JackPortIsOutput, 0); | |||||
if ((input_port == NULL) || (output_port == NULL)) { | |||||
fprintf(stderr, "no more JACK ports available\n"); | |||||
exit (1); | |||||
} | |||||
/* Tell the JACK server that we are ready to roll. Our | |||||
* process() callback will start running now. */ | |||||
if (jack_activate (client)) { | |||||
fprintf (stderr, "cannot activate client"); | |||||
exit (1); | |||||
} | |||||
/* Connect the ports. You can't do this before the client is | |||||
* activated, because we can't make connections to clients | |||||
* that aren't running. Note the confusing (but necessary) | |||||
* orientation of the driver backend ports: playback ports are | |||||
* "input" to the backend, and capture ports are "output" from | |||||
* it. | |||||
*/ | |||||
ports = jack_get_ports (client, NULL, NULL, | |||||
JackPortIsPhysical|JackPortIsOutput); | |||||
if (ports == NULL) { | |||||
fprintf(stderr, "no physical capture ports\n"); | |||||
exit (1); | |||||
} | |||||
if (jack_connect (client, ports[0], jack_port_name (input_port))) { | |||||
fprintf (stderr, "cannot connect input ports\n"); | |||||
} | |||||
free (ports); | |||||
ports = jack_get_ports (client, NULL, NULL, | |||||
JackPortIsPhysical|JackPortIsInput); | |||||
if (ports == NULL) { | |||||
fprintf(stderr, "no physical playback ports\n"); | |||||
exit (1); | |||||
} | |||||
if (jack_connect (client, jack_port_name (output_port), ports[0])) { | |||||
fprintf (stderr, "cannot connect output ports\n"); | |||||
} | |||||
free (ports); | |||||
/* keep running until the transport stops */ | |||||
while (client_state != Exit) { | |||||
sleep (1); | |||||
} | |||||
jack_client_close (client); | |||||
exit (0); | |||||
} |