4141#include < errno.h> // for EEXIST
4242
4343#ifdef APF_JACKCLIENT_DEBUG
44- #include < iostream>
4544#include < jack/statistics.h> // for jack_get_xrun_delayed_usecs()
4645#define APF_JACKCLIENT_DEBUG_MSG (str ) \
4746 do { std::cout << " apf::JackClient: " << str << std::endl; } while (false )
@@ -126,6 +125,7 @@ class JackClient
126125 // / @see jack_activate()
127126 bool activate () const
128127 {
128+ APF_JACKCLIENT_DEBUG_MSG (" Activating JACK client." );
129129 if (!_client || jack_activate (_client)) return false ;
130130
131131 this ->connect_pending_connections ();
@@ -233,6 +233,7 @@ class JackClient
233233 << still_pending_connections.size ());
234234
235235 _pending_connections.swap (still_pending_connections);
236+
236237 return _pending_connections.empty ();
237238 }
238239
@@ -352,15 +353,10 @@ class JackClient
352353 // / JACK shutdown callback.
353354 // / By default, this is throwing a jack_error exception. If you don't like
354355 // / this, you can overwrite this function in your derived class.
355- // / @param code status code, see JackInfoShutdownCallback
356- // / @param reason a string describing the shutdown reason
357- // / @see JackInfoShutdownCallback and jack_on_info_shutdown()
358- // / @note There is also JackShutdownCallback and jack_on_shutdown(), but
359- // / this one is more useful.
360- virtual void jack_shutdown_callback (jack_status_t code, const char * reason)
356+ // / @see There is also JackShutdownCallback and jack_on_shutdown()
357+ virtual void jack_shutdown_callback ()
361358 {
362- (void )code; // avoid "unused parameter" warning
363- throw jack_error (" JACK shutdown! Reason: " + std::string (reason));
359+ throw jack_error (" JACK shutdown!" );
364360 }
365361
366362 // / JACK sample rate callback.
@@ -408,10 +404,9 @@ class JackClient
408404 return static_cast <JackClient*>(arg)->jack_sync_callback (state, pos);
409405 }
410406
411- static void _jack_shutdown_callback (jack_status_t code
412- , const char * reason, void * arg)
407+ static void _jack_shutdown_callback (void * arg)
413408 {
414- static_cast <JackClient*>(arg)->jack_shutdown_callback (code, reason );
409+ static_cast <JackClient*>(arg)->jack_shutdown_callback ();
415410 }
416411
417412 static int _jack_sample_rate_callback (nframes_t sr, void * arg)
@@ -436,8 +431,11 @@ class JackClient
436431 , const std::string& destination
437432 , _pending_connections_t & pending_connections) const
438433 {
434+ APF_JACKCLIENT_DEBUG_MSG (" Connection: " << source << " -> " << destination);
439435 if (_client == nullptr ) return false ;
440436 int success = jack_connect (_client, source.c_str (), destination.c_str ());
437+ APF_JACKCLIENT_DEBUG_MSG (" Connection returned: " << success);
438+
441439 switch (success)
442440 {
443441 case 0 :
@@ -504,6 +502,14 @@ JackClient::JackClient(const std::string& name
504502 _client = jack_client_open (name.c_str (), options, &status);
505503 if (!_client) throw jack_error (status);
506504
505+ if (status & JackServerStarted) {
506+ APF_JACKCLIENT_DEBUG_MSG (" Server started." );
507+ }
508+ if (status & JackNameNotUnique) {
509+ _client_name = jack_get_client_name (_client);
510+ APF_JACKCLIENT_DEBUG_MSG (" Unique name assigned: " << _client_name);
511+ }
512+
507513 if (options & JackUseExactName)
508514 {
509515 assert (_client_name == jack_get_client_name (_client));
@@ -525,15 +531,15 @@ JackClient::JackClient(const std::string& name
525531 }
526532
527533 // TODO: separate option to disable sync callback?
528-
529534 if (jack_set_sync_callback (_client, _jack_sync_callback, this ))
530535 {
531536 throw jack_error (" Could not set sync callback function for '"
532537 + _client_name + " '!" );
533538 }
534539 }
535-
536- jack_on_info_shutdown (_client, _jack_shutdown_callback, this );
540+ // jack_on_info_shutdown CAUSES ISSUES ON WINDOWS
541+ // Using jack_on_shutdown instead
542+ jack_on_shutdown (_client, _jack_shutdown_callback, this );
537543
538544 if (jack_set_xrun_callback (_client, _jack_xrun_callback, this ))
539545 {
0 commit comments