LMMS
Loading...
Searching...
No Matches
CarlaDssiUtils.cpp
Go to the documentation of this file.
1/*
2 * Carla DSSI utils
3 * Copyright (C) 2013-2018 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
18#include "CarlaDssiUtils.hpp"
19
20#include "water/files/File.h"
21
22// --------------------------------------------------------------------------------------------------------------------
23
24const char* find_dssi_ui(const char* const filename, const char* const label) noexcept
25{
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);
29
30 try {
31 water::String guiFilename;
32 water::String pluginDir(water::String(filename).upToLastOccurrenceOf(".", false, false));
33
34 water::String checkLabel(label);
35 water::String checkSName(water::File(pluginDir).getFileName());
36
37 if (checkSName.endsWithIgnoreCase("dssi"))
38 {
39 checkSName = checkSName.dropLastCharacters(4);
40
41 if (checkSName.endsWithChar('-'))
42 checkSName = checkSName.dropLastCharacters(1);
43 }
44
45 if (! checkLabel.endsWithChar('_')) checkLabel += "_";
46 if (! checkSName.endsWithChar('_')) checkSName += "_";
47
48 std::vector<water::File> results;
49
50 if (const uint count = water::File(pluginDir).findChildFiles(results,
52 false))
53 {
54 for (uint i=0; i<count; ++i)
55 {
56 const water::File& gui(results[i]);
57 const water::String& guiShortName(gui.getFileName());
58
59 if (guiShortName.startsWith(checkLabel) || guiShortName.startsWith(checkSName))
60 {
61 guiFilename = gui.getFullPathName();
62 break;
63 }
64 }
65 }
66
67 if (guiFilename.isEmpty())
68 return nullptr;
69
70 return carla_strdup(guiFilename.toRawUTF8());
71
72 } CARLA_SAFE_EXCEPTION_RETURN("find_dssi_ui", nullptr);
73}
74
75// --------------------------------------------------------------------------------------------------------------------
#define CARLA_SAFE_EXCEPTION_RETURN(msg, ret)
Definition CarlaDefines.h:231
#define CARLA_SAFE_ASSERT_RETURN(cond, ret)
Definition CarlaDefines.h:190
unsigned int uint
Definition CarlaDefines.h:327
const char * find_dssi_ui(const char *const filename, const char *const label) noexcept
Definition CarlaDssiUtils.cpp:24
Definition File.h:50
@ findFiles
Definition File.h:462
@ ignoreHiddenFiles
Definition File.h:464
Definition String.h:48
bool endsWithIgnoreCase(StringRef text) const noexcept
Definition String.cpp:1313
bool endsWithChar(water_uchar character) const noexcept
Definition String.cpp:1284
String dropLastCharacters(int numberToDrop) const
Definition String.cpp:1429
const char * toRawUTF8() const
Definition String.cpp:1925
bool startsWith(StringRef text) const noexcept
Definition String.cpp:1266
bool isEmpty() const noexcept
Definition String.h:238
register unsigned i
Definition inflate.c:1575
static char filename[]
Definition features.c:5
GUI::ui_handle_t gui
Definition main.cpp:50
_WDL_CSTRING_PREFIX void INT_PTR count
Definition wdlcstring.h:263