1 /** @file simple_session_client.c
3 * @brief This simple client demonstrates the most basic features of JACK
4 * as they would be used by many applications.
5 * this version also adds session manager functionality.
14 #include <jack/jack.h>
15 #include <jack/types.h>
16 #include <jack/session.h>
18 jack_port_t
*input_port
;
19 jack_port_t
*output_port
;
20 jack_client_t
*client
;
25 * The process callback for this JACK application is called in a
26 * special realtime thread once for each audio cycle.
28 * This client does nothing more than copy data from its input
29 * port to its output port. It will exit when stopped by
30 * the user (e.g. using Ctrl-C on a unix-ish operating system)
33 process (jack_nframes_t nframes
, void *arg
)
35 jack_default_audio_sample_t
*in
, *out
;
37 in
= jack_port_get_buffer (input_port
, nframes
);
38 out
= jack_port_get_buffer (output_port
, nframes
);
40 sizeof (jack_default_audio_sample_t
) * nframes
);
46 session_callback (jack_session_event_t
*event
, void *arg
)
49 printf ("session notification\n");
50 printf ("path %s, uuid %s, type: %s\n", event
->session_dir
, event
->client_uuid
, event
->type
== JackSessionSave
? "save" : "quit");
53 snprintf (retval
, 100, "jack_simple_session_client %s", event
->client_uuid
);
54 event
->command_line
= strdup (retval
);
56 jack_session_reply( client
, event
);
58 if (event
->type
== JackSessionSaveAndQuit
) {
62 jack_session_event_free (event
);
66 * JACK calls this shutdown_callback if the server ever shuts down or
67 * decides to disconnect the client.
70 jack_shutdown (void *arg
)
76 main (int argc
, char *argv
[])
79 const char *client_name
= "simple";
82 /* open a client connection to the JACK server */
85 client
= jack_client_open (client_name
, JackNullOption
, &status
);
87 client
= jack_client_open (client_name
, JackSessionID
, &status
, argv
[1] );
90 fprintf (stderr
, "jack_client_open() failed, "
91 "status = 0x%2.0x\n", status
);
92 if (status
& JackServerFailed
) {
93 fprintf (stderr
, "Unable to connect to JACK server\n");
97 if (status
& JackServerStarted
) {
98 fprintf (stderr
, "JACK server started\n");
100 if (status
& JackNameNotUnique
) {
101 client_name
= jack_get_client_name(client
);
102 fprintf (stderr
, "unique name `%s' assigned\n", client_name
);
105 /* tell the JACK server to call `process()' whenever
106 there is work to be done.
109 jack_set_process_callback (client
, process
, 0);
111 /* tell the JACK server to call `jack_shutdown()' if
112 it ever shuts down, either entirely, or if it
113 just decides to stop calling us.
116 jack_on_shutdown (client
, jack_shutdown
, 0);
118 /* tell the JACK server to call `session_callback()' if
119 the session is saved.
122 jack_set_session_callback (client
, session_callback
, NULL
);
124 /* display the current sample rate.
127 printf ("engine sample rate: %" PRIu32
"\n",
128 jack_get_sample_rate (client
));
130 /* create two ports */
132 input_port
= jack_port_register (client
, "input",
133 JACK_DEFAULT_AUDIO_TYPE
,
135 output_port
= jack_port_register (client
, "output",
136 JACK_DEFAULT_AUDIO_TYPE
,
137 JackPortIsOutput
, 0);
139 if ((input_port
== NULL
) || (output_port
== NULL
)) {
140 fprintf(stderr
, "no more JACK ports available\n");
144 /* Tell the JACK server that we are ready to roll. Our
145 * process() callback will start running now. */
147 if (jack_activate (client
)) {
148 fprintf (stderr
, "cannot activate client");
152 /* Connect the ports. You can't do this before the client is
153 * activated, because we can't make connections to clients
154 * that aren't running. Note the confusing (but necessary)
155 * orientation of the driver backend ports: playback ports are
156 * "input" to the backend, and capture ports are "output" from
161 /* only do the autoconnect when not reloading from a session.
162 * in case of a session reload, the SM will restore our connections
167 ports
= jack_get_ports (client
, NULL
, NULL
,
168 JackPortIsPhysical
|JackPortIsOutput
);
170 fprintf(stderr
, "no physical capture ports\n");
174 if (jack_connect (client
, ports
[0], jack_port_name (input_port
))) {
175 fprintf (stderr
, "cannot connect input ports\n");
180 ports
= jack_get_ports (client
, NULL
, NULL
,
181 JackPortIsPhysical
|JackPortIsInput
);
183 fprintf(stderr
, "no physical playback ports\n");
187 if (jack_connect (client
, jack_port_name (output_port
), ports
[0])) {
188 fprintf (stderr
, "cannot connect output ports\n");
194 /* keep running until until we get a quit event */
200 jack_client_close (client
);