Fix: Use proper JACK client name

Currently, if I build a JUCE static and link my plugins to it, all JACK client names will be “JuceJack”.
This is bad, so I’ve changed the code to register the JACK client name as the application name.

Patch below

[code]— a/source/src/native/linux/juce_linux_JackAudio.cpp
+++ b/source/src/native/linux/juce_linux_JackAudio.cpp
@@ -112,6 +112,15 @@ namespace
#define JUCE_JACK_CLIENT_NAME “JuceJack”
#endif

+static const char* getJackClientName()
+{

  • String jackClientName = JUCEApplication::getInstance()->getApplicationName();
  • if (jackClientName.isEmpty())
  •  jackClientName = String(JUCE_JACK_CLIENT_NAME);
    
  • return jackClientName.toUTF8();
    +}

//==============================================================================
class JackAudioIODevice : public AudioIODevice
{
@@ -130,7 +139,7 @@ public:
jassert (deviceName.isNotEmpty());

     jack_status_t status;
  •    client = JUCE_NAMESPACE::jack_client_open (JUCE_JACK_CLIENT_NAME, JackNoStartServer, &status);
    
  •    client = JUCE_NAMESPACE::jack_client_open (getJackClientName(), JackNoStartServer, &status);
    
       if (client == 0)
       {
    

@@ -495,7 +504,7 @@ public:
String clientName (ports[j]);
clientName = clientName.upToFirstOccurrenceOf (":", false, false);

  •                if (clientName != String (JUCE_JACK_CLIENT_NAME)
    
  •                if (clientName != String (getJackClientName())
                        && ! inputNames.contains (clientName))
                   {
                       inputNames.add (clientName);
    

@@ -519,7 +528,7 @@ public:
String clientName (ports[j]);
clientName = clientName.upToFirstOccurrenceOf (":", false, false);

  •                if (clientName != String (JUCE_JACK_CLIENT_NAME)
    
  •                if (clientName != String (getJackClientName())
                        && ! outputNames.contains (clientName))
                   {
                       outputNames.add (clientName);
    

[/code]

Feel free to implement it.
The only flaw is that JACK can crash when using non-ascii client names.

The idea is that you should set JUCE_JACK_CLIENT_NAME to whatever string you want.

I guess I could change it so that if the user doesn’t define that macro explicitly, then it could the name of their app, but I can’t do it like you suggest, or it’d break any existing code where people have set the macro.

BTW your function is returning a pointer to a string that goes out of scope when the function returns.

[quote=“jules”]The idea is that you should set JUCE_JACK_CLIENT_NAME to whatever string you want.

I guess I could change it so that if the user doesn’t define that macro explicitly, then it could the name of their app, but I can’t do it like you suggest, or it’d break any existing code where people have set the macro.

BTW your function is returning a pointer to a string that goes out of scope when the function returns.[/quote]

Well, I need a way to make my plugins share the same static lib and still have different JACK client names.
AFAIK, this is not possible with the current code.

The patch for now is just a suggestion (just to see if it would compile and work).
In my own code I’ll just use:

everytime I need to know the app name.

That should be ok, right?
(I got no crashes so far)

So why not just leave the file alone and do:

#define JUCE_JACK_CLIENT_NAME (JUCEApplication::getInstance()->getApplicationName().toUTF8())

?

[quote=“jules”]So why not just leave the file alone and do:

#define JUCE_JACK_CLIENT_NAME (JUCEApplication::getInstance()->getApplicationName().toUTF8())

?[/quote]

ah, you caught me…

I’ll use that from now on, thanks!

By the way, this is not related to JACK, but the the ALSA midi in/out created by juce is always named “JUCE Midi Input” and “JUCE Midi Output” it would be nice to also use the application name there – right now I’m just patching the juce sources to insert my own application name.

Ok, I should probably add some similar macros for those.