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.
15 #include <jack/jack.h>
16 #include <jack/types.h>
17 #include <jack/session.h>
19 jack_port_t
*input_port
;
20 jack_port_t
*output_port
;
21 jack_client_t
*client
;
26 * The process callback for this JACK application is called in a
27 * special realtime thread once for each audio cycle.
29 * This client does nothing more than copy data from its input
30 * port to its output port. It will exit when stopped by
31 * the user (e.g. using Ctrl-C on a unix-ish operating system)
34 process (jack_nframes_t nframes
, void *arg
)
36 jack_default_audio_sample_t
*in
, *out
;
38 in
= jack_port_get_buffer (input_port
, nframes
);
39 out
= jack_port_get_buffer (output_port
, nframes
);
41 sizeof (jack_default_audio_sample_t
) * nframes
);
47 session_callback (jack_session_event_t
*event
, void *arg
)
50 printf ("session notification\n");
51 printf ("path %s, uuid %s, type: %s\n", event
->session_dir
, event
->client_uuid
, event
->type
== JackSessionSave
? "save" : "quit");
54 snprintf (retval
, 100, "jack_simple_session_client %s", event
->client_uuid
);
55 event
->command_line
= strdup (retval
);
57 jack_session_reply( client
, event
);
59 if (event
->type
== JackSessionSaveAndQuit
) {
63 jack_session_event_free (event
);
67 * JACK calls this shutdown_callback if the server ever shuts down or
68 * decides to disconnect the client.
71 jack_shutdown (void *arg
)
77 main (int argc
, char *argv
[])
80 const char *client_name
= "simple";
83 /* open a client connection to the JACK server */
86 client
= jack_client_open (client_name
, JackNullOption
, &status
);
88 client
= jack_client_open (client_name
, JackSessionID
, &status
, argv
[1] );
91 fprintf (stderr
, "jack_client_open() failed, "
92 "status = 0x%2.0x\n", status
);
93 if (status
& JackServerFailed
) {
94 fprintf (stderr
, "Unable to connect to JACK server\n");
98 if (status
& JackServerStarted
) {
99 fprintf (stderr
, "JACK server started\n");
101 if (status
& JackNameNotUnique
) {
102 client_name
= jack_get_client_name(client
);
103 fprintf (stderr
, "unique name `%s' assigned\n", client_name
);
106 /* tell the JACK server to call `process()' whenever
107 there is work to be done.
110 jack_set_process_callback (client
, process
, 0);
112 /* tell the JACK server to call `jack_shutdown()' if
113 it ever shuts down, either entirely, or if it
114 just decides to stop calling us.
117 jack_on_shutdown (client
, jack_shutdown
, 0);
119 /* tell the JACK server to call `session_callback()' if
120 the session is saved.
123 jack_set_session_callback (client
, session_callback
, NULL
);
125 /* display the current sample rate.
128 printf ("engine sample rate: %" PRIu32
"\n",
129 jack_get_sample_rate (client
));
131 /* create two ports */
133 input_port
= jack_port_register (client
, "input",
134 JACK_DEFAULT_AUDIO_TYPE
,
136 output_port
= jack_port_register (client
, "output",
137 JACK_DEFAULT_AUDIO_TYPE
,
138 JackPortIsOutput
, 0);
140 if ((input_port
== NULL
) || (output_port
== NULL
)) {
141 fprintf(stderr
, "no more JACK ports available\n");
145 /* Tell the JACK server that we are ready to roll. Our
146 * process() callback will start running now. */
148 if (jack_activate (client
)) {
149 fprintf (stderr
, "cannot activate client");
153 /* Connect the ports. You can't do this before the client is
154 * activated, because we can't make connections to clients
155 * that aren't running. Note the confusing (but necessary)
156 * orientation of the driver backend ports: playback ports are
157 * "input" to the backend, and capture ports are "output" from
162 /* only do the autoconnect when not reloading from a session.
163 * in case of a session reload, the SM will restore our connections
168 ports
= jack_get_ports (client
, NULL
, NULL
,
169 JackPortIsPhysical
|JackPortIsOutput
);
171 fprintf(stderr
, "no physical capture ports\n");
175 if (jack_connect (client
, ports
[0], jack_port_name (input_port
))) {
176 fprintf (stderr
, "cannot connect input ports\n");
181 ports
= jack_get_ports (client
, NULL
, NULL
,
182 JackPortIsPhysical
|JackPortIsInput
);
184 fprintf(stderr
, "no physical playback ports\n");
188 if (jack_connect (client
, jack_port_name (output_port
), ports
[0])) {
189 fprintf (stderr
, "cannot connect output ports\n");
195 /* keep running until until we get a quit event */
204 jack_client_close (client
);