Keyboard handling in plugins

Sure, would be happy to take a look!

These are the implementations of a function that returns the name of the currently running executable, one for each platform:

[code] String getCurrentExecutableName() throw();

#if JUCE_WINDOWS

// see: http://www.oroboro.com/rafael/docserv.php/article/news/entry/52/num_entries/1
String getCurrentExecutableName() throw()
{
    WCHAR buf[MAX_PATH] = { '\0' };

    if ( !GetModuleFileNameW( NULL, buf, MAX_PATH ))
    {
        return String::empty;
    }
    return String(buf);
}

#elif JUCE_MAC

// see: http://www.oroboro.com/rafael/docserv.php/article/news/entry/52/num_entries/1

String getCurrentExecutableName() throw()
{
    char str[2*MAXPATHLEN] = {'\0'};

    unsigned int size = 2*MAXPATHLEN;
    if ( _NSGetExecutablePath( str, &size ))
    {
        return String::empty;
    }

    return String(str, size);
}

#elif JUCE_LINUX

// see: http://www.oroboro.com/rafael/docserv.php/article/news/entry/52/num_entries/1

String getCurrentExecutableName() throw()
{
    char buf[1024] = { '\0' };

    s32 len;
    if (( len = readlink( "/proc/self/exe", buf, sizeof( buf ) - 1 )) == -1 )
    {
        return String::empty;
    }
    buf[len] = '\0';

    return String(buf);
}

#else
#error unsupported OS
#endif
[/code]

The following is the code that tries to guess the host, given the executable name obtained above.

The detecting part is different for mac and PC because some of the hosts have different executable names in the two platfrom.
I’ve left to be implemented the Linux part because I have no need to support that platform currently, but contributions are welcome.

    enum HostType
    {
        host_Undetected,
        host_AbletonLive6,
        host_AbletonLive7,
        host_AbletonLive8,
        host_AbletonLiveGeneric,
        host_DigidesignProTools,
        host_CakewalkSonar8,
        host_CakewalkSonarGeneric,
        host_Reaper,
        host_MackieTracktion3,
        host_MackieTracktionGeneric,
        host_SteinbergCubase4,
        host_SteinbergCubase5,
        host_SteinbergCubaseGeneric,
        host_AppleLogic,
        host_Unknown,
    };

    HostType detectHost () throw ()
    {
        String currentExecutableFullPath (getCurrentExecutableName ());
        String currentExecutableFileName (File (currentExecutableFullPath).getFileName ());

#if JUCE_MAC

        if (currentExecutableFullPath.containsIgnoreCase (T("Live 6.")))
        {
            return host_AbletonLive6;
        }
        else if (currentExecutableFullPath.containsIgnoreCase (T("Live 7.")))
        {
            return host_AbletonLive7;
        }
        else if (currentExecutableFullPath.containsIgnoreCase (T("Live 8.")))
        {
            return host_AbletonLive8;
        }
        else if (currentExecutableFileName.containsIgnoreCase (T("Live")))
        {
            return host_AbletonLiveGeneric;
        }
        else if (currentExecutableFileName.containsIgnoreCase (T("Pro Tools")))
        {
            return host_DigidesignProTools;
        }
        else if (currentExecutableFileName.containsIgnoreCase (T("Cubase 4")))
        {
            return host_SteinbergCubase4;
        }
        else if (currentExecutableFileName.containsIgnoreCase (T("Cubase 5")))
        {
            return host_SteinbergCubase5;
        }
        else if (currentExecutableFileName.contains (T("Logic")))
        {
            return host_AppleLogic;
        }
        else
        {
            return host_Unknown;
        }

#elif JUCE_WINDOWS

        if (currentExecutableFileName.containsIgnoreCase (T("Live 6.")))
        {
            return host_AbletonLive6;
        }
        else if (currentExecutableFileName.containsIgnoreCase (T("Live 7.")))
        {
            return host_AbletonLive7;
        }
        else if (currentExecutableFileName.containsIgnoreCase (T("Live 8.")))
        {
            return host_AbletonLive8;
        }
        else if (currentExecutableFileName.containsIgnoreCase (T("Live ")))
        {
            return host_AbletonLiveGeneric;
        }
        else if (currentExecutableFileName.containsIgnoreCase (T("ProTools")))
        {
            return host_DigidesignProTools;
        }
        else if (currentExecutableFullPath.containsIgnoreCase (T("SONAR 8")))
        {
            return host_CakewalkSonar8;
        }
        else if (currentExecutableFileName.containsIgnoreCase (T("SONAR")))
        {
            return host_CakewalkSonarGeneric;
        }
        else if (currentExecutableFileName.containsIgnoreCase (T("reaper")))
        {
            return host_Reaper;
        }
        else if (currentExecutableFullPath.containsIgnoreCase (T("Tracktion 3")))
        {
            return host_MackieTracktion3;
        }
        else if (currentExecutableFileName.containsIgnoreCase (T("Tracktion")))
        {
            return host_MackieTracktionGeneric;
        }
        else if (currentExecutableFileName.containsIgnoreCase (T("Cubase4")))
        {
            return host_SteinbergCubase4;
        }
        else if (currentExecutableFileName.containsIgnoreCase (T("Cubase5")))
        {
            return host_SteinbergCubase5;
        }
        else if (currentExecutableFileName.containsIgnoreCase (T("Cubase")))
        {
            return host_SteinbergCubaseGeneric;
        }
        else
        {
            return host_Unknown;
        }

#else
#error Unsupported OS
#endif
    }

Nicely done! Thanks, I’ll see if I can slot that into the framework somewhere.

Ok, I’ve checked in a jucified version of that, as juce_PluginHostType.h - you might want to take a quick look, as I’ve not actually tested it!