Rename a pipe method, add docs
[carla.git] / source / utils / CarlaDssiUtils.cpp
blob77ceffb7d789cfc9f6f56f71e29e412c52cf4d84
1 /*
2 * Carla DSSI utils
3 * Copyright (C) 2013-2018 Filipe Coelho <falktx@falktx.com>
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.
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.
15 * For a full copy of the GNU General Public License see the doc/GPL.txt file.
18 #include "CarlaDssiUtils.hpp"
20 #include "water/files/File.h"
22 // --------------------------------------------------------------------------------------------------------------------
24 const char* find_dssi_ui(const char* const filename, const char* const label) noexcept
26 CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', nullptr);
27 CARLA_SAFE_ASSERT_RETURN(label != nullptr && label[0] != '\0', nullptr);
28 carla_debug("find_dssi_ui(\"%s\", \"%s\")", filename, label);
30 try {
31 water::String guiFilename;
32 water::String pluginDir(water::String(filename).upToLastOccurrenceOf(".", false, false));
34 water::String checkLabel(label);
35 water::String checkSName(water::File(pluginDir).getFileName());
37 if (checkSName.endsWithIgnoreCase("dssi"))
39 checkSName = checkSName.dropLastCharacters(4);
41 if (checkSName.endsWithChar('-'))
42 checkSName = checkSName.dropLastCharacters(1);
45 if (! checkLabel.endsWithChar('_')) checkLabel += "_";
46 if (! checkSName.endsWithChar('_')) checkSName += "_";
48 std::vector<water::File> results;
50 if (const uint count = water::File(pluginDir).findChildFiles(results,
51 water::File::findFiles|water::File::ignoreHiddenFiles,
52 false))
54 for (uint i=0; i<count; ++i)
56 const water::File& gui(results[i]);
57 const water::String& guiShortName(gui.getFileName());
59 if (guiShortName.startsWith(checkLabel) || guiShortName.startsWith(checkSName))
61 guiFilename = gui.getFullPathName();
62 break;
67 if (guiFilename.isEmpty())
68 return nullptr;
70 return carla_strdup(guiFilename.toRawUTF8());
72 } CARLA_SAFE_EXCEPTION_RETURN("find_dssi_ui", nullptr);
75 // --------------------------------------------------------------------------------------------------------------------