Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CarlaDssiUtils.cpp 3.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Carla DSSI utils
  3. * Copyright (C) 2013-2014 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the doc/GPL.txt file.
  16. */
  17. #include "CarlaDssiUtils.hpp"
  18. #ifdef HAVE_JUCE
  19. # include "juce_core.h"
  20. #else
  21. # include <QtCore/QDir>
  22. # include <QtCore/QFileInfo>
  23. # include <QtCore/QStringList>
  24. #endif
  25. // -----------------------------------------------------------------------
  26. const char* find_dssi_ui(const char* const filename, const char* const label) noexcept
  27. {
  28. CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', nullptr);
  29. CARLA_SAFE_ASSERT_RETURN(label != nullptr && label[0] != '\0', nullptr);
  30. carla_debug("find_dssi_ui(\"%s\", \"%s\")", filename, label);
  31. try {
  32. #ifdef HAVE_JUCE
  33. using namespace juce;
  34. String guiFilename;
  35. String pluginDir(String(filename).upToLastOccurrenceOf(".", false, false));
  36. String checkLabel(label);
  37. String checkSName(File(pluginDir).getFileName());
  38. if (! checkLabel.endsWith("_")) checkLabel += "_";
  39. if (! checkSName.endsWith("_")) checkSName += "_";
  40. Array<File> results;
  41. for (int i=0, count=File(pluginDir).findChildFiles(results, File::findFiles|File::ignoreHiddenFiles, false); i < count; ++i)
  42. {
  43. const File& gui(results[i]);
  44. const String& guiShortName(gui.getFileName());
  45. if (guiShortName.startsWith(checkLabel) || guiShortName.startsWith(checkSName))
  46. {
  47. guiFilename = gui.getFullPathName();
  48. break;
  49. }
  50. }
  51. if (guiFilename.isEmpty())
  52. return nullptr;
  53. return carla_strdup(guiFilename.toRawUTF8());
  54. #else
  55. QString guiFilename;
  56. QString pluginDir(filename);
  57. pluginDir.resize(pluginDir.lastIndexOf("."));
  58. QString checkLabel(label);
  59. QString checkSName(QFileInfo(pluginDir).baseName());
  60. if (! checkLabel.endsWith("_")) checkLabel += "_";
  61. if (! checkSName.endsWith("_")) checkSName += "_";
  62. QStringList guiFiles(QDir(pluginDir).entryList());
  63. foreach (const QString& gui, guiFiles)
  64. {
  65. if (gui.startsWith(checkLabel) || gui.startsWith(checkSName))
  66. {
  67. QFileInfo finalname(pluginDir + QDir::separator() + gui);
  68. guiFilename = finalname.absoluteFilePath();
  69. break;
  70. }
  71. }
  72. if (guiFilename.isEmpty())
  73. return nullptr;
  74. return carla_strdup(guiFilename.toUtf8().constData());
  75. #endif
  76. } CARLA_SAFE_EXCEPTION_RETURN("find_dssi_ui", nullptr);
  77. }
  78. // -----------------------------------------------------------------------