Skip to content

Commit

Permalink
Continue cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: falkTX <falktx@falktx.com>
  • Loading branch information
falkTX committed Apr 27, 2024
1 parent 4ab4e80 commit ad3b779
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 128 deletions.
16 changes: 8 additions & 8 deletions source/backend/plugin/CarlaPluginJSFX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ class CarlaPluginJSFX : public CarlaPlugin

bool getLabel(char* const strBuf) const noexcept override
{
std::strncpy(strBuf, fUnit.getFileId().toRawUTF8(), STR_MAX);
std::strncpy(strBuf, fUnit.getFileId(), STR_MAX);
return true;
}

Expand Down Expand Up @@ -960,7 +960,7 @@ class CarlaPluginJSFX : public CarlaPlugin
const File currentPath(splitPaths[i].toRawUTF8());
const File currentFile = currentPath.getChildFile(CharPointer_UTF8(label));
const CarlaJsfxUnit currentUnit(currentPath, currentFile);
if (File(currentUnit.getFilePath().toRawUTF8()).existsAsFile())
if (File(currentUnit.getFilePath()).existsAsFile())
fUnit = currentUnit;
}
}
Expand All @@ -977,12 +977,12 @@ class CarlaPluginJSFX : public CarlaPlugin
ysfx_config_u config(ysfx_config_new());
CARLA_SAFE_ASSERT_RETURN(config != nullptr, false);

const water::String rootPath = fUnit.getRootPath();
const water::String filePath = fUnit.getFilePath();
const CarlaString rootPath = fUnit.getRootPath();
const CarlaString filePath = fUnit.getFilePath();

ysfx_register_builtin_audio_formats(config.get());
ysfx_set_import_root(config.get(), rootPath.toRawUTF8());
ysfx_guess_file_roots(config.get(), filePath.toRawUTF8());
ysfx_set_import_root(config.get(), rootPath);
ysfx_guess_file_roots(config.get(), filePath);
ysfx_set_log_reporter(config.get(), &CarlaJsfxLogging::logAll);
ysfx_set_user_data(config.get(), (intptr_t)this);

Expand All @@ -993,7 +993,7 @@ class CarlaPluginJSFX : public CarlaPlugin
// get info

{
if (! ysfx_load_file(fEffect, filePath.toRawUTF8(), 0))
if (! ysfx_load_file(fEffect, filePath, 0))
{
pData->engine->setLastError("Failed to load JSFX");
return false;
Expand Down Expand Up @@ -1021,7 +1021,7 @@ class CarlaPluginJSFX : public CarlaPlugin
pData->name = carla_strdup(ysfx_get_name(fEffect));
}

pData->filename = carla_strdup(filePath.toRawUTF8());
pData->filename = filePath.dup();

// ---------------------------------------------------------------
// register client
Expand Down
14 changes: 7 additions & 7 deletions source/backend/utils/CachedPlugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -627,17 +627,17 @@ static const CarlaCachedPluginInfo* get_cached_plugin_jsfx(const CB::CarlaJsfxUn

ysfx_config_u config(ysfx_config_new());

const water::String rootPath = unit.getRootPath();
const water::String filePath = unit.getFilePath();
const CarlaString rootPath = unit.getRootPath();
const CarlaString filePath = unit.getFilePath();

ysfx_register_builtin_audio_formats(config.get());
ysfx_set_import_root(config.get(), rootPath.toRawUTF8());
ysfx_guess_file_roots(config.get(), filePath.toRawUTF8());
ysfx_set_import_root(config.get(), rootPath);
ysfx_guess_file_roots(config.get(), filePath);
ysfx_set_log_reporter(config.get(), &CB::CarlaJsfxLogging::logErrorsOnly);

ysfx_u effect(ysfx_new(config.get()));

if (! ysfx_load_file(effect.get(), filePath.toRawUTF8(), 0))
if (! ysfx_load_file(effect.get(), filePath, 0))
{
info.valid = false;
return &info;
Expand All @@ -654,11 +654,11 @@ static const CarlaCachedPluginInfo* get_cached_plugin_jsfx(const CB::CarlaJsfxUn
}

static CarlaString name, label, maker;
label = unit.getFileId().toRawUTF8();
label = unit.getFileId();
name = ysfx_get_name(effect.get());
maker = ysfx_get_author(effect.get());

info.valid = true;
info.valid = true;

info.category = CB::CarlaJsfxCategories::getFromEffect(effect.get());

Expand Down
15 changes: 0 additions & 15 deletions source/modules/water/files/DirectoryIterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
*/

#include "DirectoryIterator.h"
#include "../text/StringArray.h"

namespace water {

Expand Down Expand Up @@ -146,18 +145,4 @@ const File& DirectoryIterator::getFile() const
return currentFile;
}

float DirectoryIterator::getEstimatedProgress() const
{
if (totalNumFiles < 0)
totalNumFiles = File (path.toRawUTF8()).getNumberOfChildFiles (File::findFilesAndDirectories);

if (totalNumFiles <= 0)
return 0.0f;

const float detailedIndex = (subIterator != nullptr) ? index + subIterator->getEstimatedProgress()
: (float) index;

return detailedIndex / totalNumFiles;
}

}
12 changes: 2 additions & 10 deletions source/modules/water/files/DirectoryIterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This file is part of the Water library.
Copyright (c) 2016 ROLI Ltd.
Copyright (C) 2017-2022 Filipe Coelho <falktx@falktx.com>
Copyright (C) 2017-2024 Filipe Coelho <falktx@falktx.com>
Permission is granted to use this software under the terms of the ISC license
http://www.isc.org/downloads/software-support-policy/isc-license/
Expand Down Expand Up @@ -109,13 +109,6 @@ class DirectoryIterator
*/
const File& getFile() const;

/** Returns a guess of how far through the search the iterator has got.
@returns a value 0.0 to 1.0 to show the progress, although this won't be
very accurate.
*/
float getEstimatedProgress() const;

private:
//==============================================================================
class NativeIterator
Expand All @@ -124,8 +117,7 @@ class DirectoryIterator
NativeIterator (const File& directory, const String& wildCard);
~NativeIterator();

bool next (String& filenameFound,
bool* isDirectory, int64* fileSize, bool* isReadOnly);
bool next (String& filenameFound, bool* isDirectory, int64* fileSize, bool* isReadOnly);

class Pimpl;

Expand Down
14 changes: 7 additions & 7 deletions source/modules/water/files/File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ String File::parseAbsolutePath (const String& p)
// Check if path is valid under Wine
String testpath ("Z:" + path);

if (File(testpath).exists())
if (File(testpath.toRawUTF8()).exists())
{
path = testpath;
}
Expand Down Expand Up @@ -181,7 +181,7 @@ String File::parseAbsolutePath (const String& p)
*/
carla_safe_assert(path.toRawUTF8(), __FILE__, __LINE__);

return File::getCurrentWorkingDirectory().getChildFile (path).getFullPathName();
return File::getCurrentWorkingDirectory().getChildFile (path.toRawUTF8()).getFullPathName();
}
#else
// Mac or Linux..
Expand Down Expand Up @@ -424,7 +424,7 @@ File File::getChildFile (const char* const relativePath) const

#ifdef CARLA_OS_WIN
if (r.indexOf ((water_uchar) '/') >= 0)
return getChildFile (String (r).replaceCharacter ('/', '\\'));
return getChildFile (String (r).replaceCharacter ('/', '\\').toRawUTF8());
#endif

String path (fullPath);
Expand Down Expand Up @@ -992,7 +992,7 @@ namespace WindowsFileHelpers
CHAR apath [MAX_PATH + 256];

if (WideCharToMultiByte (CP_UTF8, 0, wpath, -1, apath, numElementsInArray (apath), nullptr, nullptr))
return File (String (apath));
return File (apath);
}

return File();
Expand All @@ -1006,7 +1006,7 @@ namespace WindowsFileHelpers
GetModuleFileNameW (moduleHandle, wdest, (DWORD) numElementsInArray (wdest));

if (WideCharToMultiByte (CP_UTF8, 0, wdest, -1, adest, numElementsInArray (adest), nullptr, nullptr))
return File (String (adest));
return File (adest);

return File();
}
Expand Down Expand Up @@ -1120,7 +1120,7 @@ File File::getCurrentWorkingDirectory()
GetCurrentDirectoryW ((DWORD) numElementsInArray (wdest), wdest);

if (WideCharToMultiByte (CP_UTF8, 0, wdest, -1, adest, numElementsInArray (adest), nullptr, nullptr))
return File (String (adest));
return File (adest);

return File();
}
Expand Down Expand Up @@ -1153,7 +1153,7 @@ File File::getSpecialLocation (const SpecialLocationType type)
GetTempPathW ((DWORD) numElementsInArray (wdest), wdest);

if (WideCharToMultiByte (CP_UTF8, 0, wdest, -1, adest, numElementsInArray (adest), nullptr, nullptr))
return File (String (adest));
return File (adest);

return File();
}
Expand Down
59 changes: 27 additions & 32 deletions source/utils/CarlaJsfxUtils.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Carla JSFX utils
* Copyright (C) 2021 Jean Pierre Cimalando
* Copyright (C) 2021-2022 Filipe Coelho <falktx@falktx.com>
* Copyright (C) 2021-2024 Filipe Coelho <falktx@falktx.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
Expand All @@ -19,21 +19,16 @@
#ifndef CARLA_JSFX_UTILS_HPP_INCLUDED
#define CARLA_JSFX_UTILS_HPP_INCLUDED

#include "CarlaDefines.h"
#include "CarlaBackend.h"
#include "CarlaUtils.hpp"
#include "CarlaJuceUtils.hpp"
#include "CarlaString.hpp"

#include "water/files/File.h"
#include "water/text/String.h"

#ifdef YSFX_API
# error YSFX_API is not private
#endif
#include "ysfx/include/ysfx.h"

#include <memory>

CARLA_BACKEND_START_NAMESPACE

// --------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -76,7 +71,7 @@ struct CarlaJsfxLogging

struct CarlaJsfxCategories
{
static PluginCategory getFromEffect(ysfx_t* effect)
static PluginCategory getFromEffect(ysfx_t* const effect)
{
PluginCategory category = PLUGIN_CATEGORY_OTHER;

Expand All @@ -88,8 +83,8 @@ struct CarlaJsfxCategories

for (uint32_t i=0; i<tagCount && category == PLUGIN_CATEGORY_OTHER; ++i)
{
water::CharPointer_UTF8 tag(tags[i]);
PluginCategory current = getFromTag(tag);
PluginCategory current = getFromTag(tags[i]);

if (current != PLUGIN_CATEGORY_NONE)
category = current;
}
Expand All @@ -98,30 +93,30 @@ struct CarlaJsfxCategories
return category;
}

static PluginCategory getFromTag(const water::CharPointer_UTF8 tag)
static PluginCategory getFromTag(const char* const tag)
{
if (tag.compareIgnoreCase(water::CharPointer_UTF8("synthesis")) == 0)
if (carla_strcasecmp(tag, "synthesis") == 0)
return PLUGIN_CATEGORY_SYNTH;

if (tag.compareIgnoreCase(water::CharPointer_UTF8("delay")) == 0)
if (carla_strcasecmp(tag, "delay") == 0)
return PLUGIN_CATEGORY_DELAY;

if (tag.compareIgnoreCase(water::CharPointer_UTF8("equalizer")) == 0)
if (carla_strcasecmp(tag, "equalizer") == 0)
return PLUGIN_CATEGORY_EQ;

if (tag.compareIgnoreCase(water::CharPointer_UTF8("filter")) == 0)
if (carla_strcasecmp(tag, "filter") == 0)
return PLUGIN_CATEGORY_FILTER;

if (tag.compareIgnoreCase(water::CharPointer_UTF8("distortion")) == 0)
if (carla_strcasecmp(tag, "distortion") == 0)
return PLUGIN_CATEGORY_DISTORTION;

if (tag.compareIgnoreCase(water::CharPointer_UTF8("dynamics")) == 0)
if (carla_strcasecmp(tag, "dynamics") == 0)
return PLUGIN_CATEGORY_DYNAMICS;

if (tag.compareIgnoreCase(water::CharPointer_UTF8("modulation")) == 0)
if (carla_strcasecmp(tag, "modulation") == 0)
return PLUGIN_CATEGORY_MODULATOR;

if (tag.compareIgnoreCase(water::CharPointer_UTF8("utility")) == 0)
if (carla_strcasecmp(tag, "utility") == 0)
return PLUGIN_CATEGORY_UTILITY;

return PLUGIN_CATEGORY_NONE;
Expand All @@ -132,12 +127,12 @@ struct CarlaJsfxCategories

class CarlaJsfxUnit
{
static water::String createFileId(const water::File& rootPath, const water::File& filePath)
static CarlaString createFileId(const water::File& rootPath, const water::File& filePath)
{
water::String fileId(filePath.getRelativePathFrom(rootPath));
#ifdef CARLA_OS_WIN
fileId.replaceCharacter('\\', '/');
#endif
CarlaString fileId(filePath.getRelativePathFrom(rootPath).toRawUTF8());
#ifdef CARLA_OS_WIN
fileId.replace('\\', '/');
#endif
return fileId;
}

Expand All @@ -149,33 +144,33 @@ class CarlaJsfxUnit

CarlaJsfxUnit(const water::File& rootPath, const water::File& filePath)
: fFileId(createFileId(rootPath, filePath)),
fFilePath(rootPath.getChildFile(fFileId.toRawUTF8()).getFullPathName()),
fRootPath(rootPath.getFullPathName()) {}
fFilePath(rootPath.getChildFile(fFileId).getFullPathName().toRawUTF8()),
fRootPath(rootPath.getFullPathName().toRawUTF8()) {}

explicit operator bool() const noexcept
{
return fFileId.isNotEmpty();
}

const water::String& getFileId() const noexcept
const CarlaString& getFileId() const noexcept
{
return fFileId;
}

const water::String& getFilePath() const noexcept
const CarlaString& getFilePath() const noexcept
{
return fFilePath;
}

const water::String& getRootPath() const noexcept
const CarlaString& getRootPath() const noexcept
{
return fRootPath;
}

private:
water::String fFileId;
water::String fFilePath;
water::String fRootPath;
CarlaString fFileId;
CarlaString fFilePath;
CarlaString fRootPath;
};

// --------------------------------------------------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit ad3b779

Please sign in to comment.