Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/Rearrange the clap a little bit #1415

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions clients/clap-first/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ project(scxt_clapfirst)
message(STATUS "Shortcircuit XT building clap-first wrappers")
set(name "Shortcircuit XT")
set(IMPL_TARGET ${PROJECT_NAME}_impl)
add_library(${IMPL_TARGET} STATIC clap-config.cpp
scxt-plugin/scxt-plugin.cpp)
add_library(${IMPL_TARGET} STATIC
scxt-plugin/clap-helpers-config.cpp
scxt-plugin/scxt-plugin.cpp
scxt-plugin/scxt-clap-entry-impl.cpp
)

target_link_libraries(${IMPL_TARGET} PUBLIC
clap_juce_shim_headers
Expand Down
93 changes: 1 addition & 92 deletions clients/clap-first/scxt-clap-entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,99 +25,8 @@
* https://github.com/surge-synthesizer/shortcircuit-xt
*/

/*
* This file provides the `clap_plugin_entry` entry point required in the DLL for all
* clap plugins. It also provides the basic functions for the resulting factory class
* which generates the plugin. In a single plugin case, this really is just plumbing
* through to expose polysynth::ConduitPolysynthConfig::getDescription() and create a polysynth
* plugin instance using the helper classes.
*
* For more information on this mechanism, see include/clap/entry.h
*/

#include <iostream>
#include <cmath>
#include <cstring>

#include <clap/clap.h>
#include <clap/plugin.h>
#include <clap/factory/plugin-factory.h>

#include "clapwrapper/vst3.h"
#include "clapwrapper/auv2.h"

namespace scxt::clap_first
{
namespace scxt_plugin
{
extern const clap_plugin_descriptor *getDescription();
extern const clap_plugin *makeSCXTPlugin(const clap_host *h);
} // namespace scxt_plugin

uint32_t clap_get_plugin_count(const clap_plugin_factory *f) { return 1; }
const clap_plugin_descriptor *clap_get_plugin_descriptor(const clap_plugin_factory *f, uint32_t w)
{
if (w == 0)
return scxt::clap_first::scxt_plugin::getDescription();

return nullptr;
}

static const clap_plugin *clap_create_plugin(const clap_plugin_factory *f, const clap_host *host,
const char *plugin_id)
{

if (strcmp(plugin_id, scxt::clap_first::scxt_plugin::getDescription()->id) == 0)
{
return scxt_plugin::makeSCXTPlugin(host);
}
return nullptr;
}

static bool clap_get_auv2_info(const clap_plugin_factory_as_auv2 *factory, uint32_t index,
clap_plugin_info_as_auv2_t *info)
{
auto desc = clap_get_plugin_descriptor(nullptr, index); // we don't use the factory above

auto plugin_id = desc->id;

info->au_type[0] = 0; // use the features to determine the type

if (strcmp(plugin_id, scxt::clap_first::scxt_plugin::getDescription()->id) == 0)
{
strncpy(info->au_subt, "ScXT", 5);
return true;
}

return false;
}

const struct clap_plugin_factory scxt_clap_factory = {
clap_get_plugin_count,
clap_get_plugin_descriptor,
clap_create_plugin,
};

const struct clap_plugin_factory_as_auv2 scxt_auv2_factory = {"SSTx", // manu
"Surge Synth Team", // manu name
clap_get_auv2_info};

static const void *get_factory(const char *factory_id)
{
if (!strcmp(factory_id, CLAP_PLUGIN_FACTORY_ID))
return &scxt_clap_factory;

if (!strcmp(factory_id, CLAP_PLUGIN_FACTORY_INFO_AUV2))
return &scxt_auv2_factory;

return nullptr;
}

// clap_init and clap_deinit are required to be fast, but we have nothing we need to do here
bool clap_init(const char *p) { return true; }
void clap_deinit() {}

} // namespace scxt::clap_first
#include "scxt-plugin/scxt-clap-entry-impl.h"

extern "C"
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
* https://github.com/surge-synthesizer/shortcircuit-xt
*/

#include "clap-config.h"
#include "clap/helpers/plugin.hxx"
#include "clap/helpers/host-proxy.hxx"
#include "clap-helpers-config.h"

#include <clap/helpers/plugin.hxx>
#include <clap/helpers/host-proxy.hxx>

namespace sxcf = scxt::clap_first;
namespace chlp = clap::helpers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
* https://github.com/surge-synthesizer/shortcircuit-xt
*/

#ifndef CLIENTS_CLAP_FIRST_CLAP_CONFIG_H
#define CLIENTS_CLAP_FIRST_CLAP_CONFIG_H
#ifndef CLIENTS_CLAP_FIRST_SCXT_PLUGIN_CLAP_HELPERS_CONFIG_H
#define CLIENTS_CLAP_FIRST_SCXT_PLUGIN_CLAP_HELPERS_CONFIG_H

#include <clap/helpers/plugin.hh>

Expand Down
112 changes: 112 additions & 0 deletions clients/clap-first/scxt-plugin/scxt-clap-entry-impl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* Shortcircuit XT - a Surge Synth Team product
*
* A fully featured creative sampler, available as a standalone
* and plugin for multiple platforms.
*
* Copyright 2019 - 2024, Various authors, as described in the github
* transaction log.
*
* ShortcircuitXT is released under the Gnu General Public Licence
* V3 or later (GPL-3.0-or-later). The license is found in the file
* "LICENSE" in the root of this repository or at
* https://www.gnu.org/licenses/gpl-3.0.en.html
*
* Individual sections of code which comprises ShortcircuitXT in this
* repository may also be used under an MIT license. Please see the
* section "Licensing" in "README.md" for details.
*
* ShortcircuitXT is inspired by, and shares code with, the
* commercial product Shortcircuit 1 and 2, released by VemberTech
* in the mid 2000s. The code for Shortcircuit 2 was opensourced in
* 2020 at the outset of this project.
*
* All source for ShortcircuitXT is available at
* https://github.com/surge-synthesizer/shortcircuit-xt
*/

#include "scxt-clap-entry-impl.h"

#include <iostream>
#include <cmath>
#include <cstring>

#include <clap/clap.h>
#include <clap/plugin.h>
#include <clap/factory/plugin-factory.h>

#include "clapwrapper/vst3.h"
#include "clapwrapper/auv2.h"

namespace scxt::clap_first
{
namespace scxt_plugin
{
extern const clap_plugin_descriptor *getDescription();
extern const clap_plugin *makeSCXTPlugin(const clap_host *h);
} // namespace scxt_plugin

uint32_t clap_get_plugin_count(const clap_plugin_factory *f) { return 1; }
const clap_plugin_descriptor *clap_get_plugin_descriptor(const clap_plugin_factory *f, uint32_t w)
{
if (w == 0)
return scxt::clap_first::scxt_plugin::getDescription();

return nullptr;
}

static const clap_plugin *clap_create_plugin(const clap_plugin_factory *f, const clap_host *host,
const char *plugin_id)
{

if (strcmp(plugin_id, scxt::clap_first::scxt_plugin::getDescription()->id) == 0)
{
return scxt_plugin::makeSCXTPlugin(host);
}
return nullptr;
}

static bool clap_get_auv2_info(const clap_plugin_factory_as_auv2 *factory, uint32_t index,
clap_plugin_info_as_auv2_t *info)
{
auto desc = clap_get_plugin_descriptor(nullptr, index); // we don't use the factory above

auto plugin_id = desc->id;

info->au_type[0] = 0; // use the features to determine the type

if (strcmp(plugin_id, scxt::clap_first::scxt_plugin::getDescription()->id) == 0)
{
strncpy(info->au_subt, "ScXT", 5);
return true;
}

return false;
}

const struct clap_plugin_factory scxt_clap_factory = {
clap_get_plugin_count,
clap_get_plugin_descriptor,
clap_create_plugin,
};

const struct clap_plugin_factory_as_auv2 scxt_auv2_factory = {"SSTx", // manu
"Surge Synth Team", // manu name
clap_get_auv2_info};

const void *get_factory(const char *factory_id)
{
if (!strcmp(factory_id, CLAP_PLUGIN_FACTORY_ID))
return &scxt_clap_factory;

if (!strcmp(factory_id, CLAP_PLUGIN_FACTORY_INFO_AUV2))
return &scxt_auv2_factory;

return nullptr;
}

// clap_init and clap_deinit are required to be fast, but we have nothing we need to do here
bool clap_init(const char *p) { return true; }
void clap_deinit() {}

} // namespace scxt::clap_first
39 changes: 39 additions & 0 deletions clients/clap-first/scxt-plugin/scxt-clap-entry-impl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Shortcircuit XT - a Surge Synth Team product
*
* A fully featured creative sampler, available as a standalone
* and plugin for multiple platforms.
*
* Copyright 2019 - 2024, Various authors, as described in the github
* transaction log.
*
* ShortcircuitXT is released under the Gnu General Public Licence
* V3 or later (GPL-3.0-or-later). The license is found in the file
* "LICENSE" in the root of this repository or at
* https://www.gnu.org/licenses/gpl-3.0.en.html
*
* Individual sections of code which comprises ShortcircuitXT in this
* repository may also be used under an MIT license. Please see the
* section "Licensing" in "README.md" for details.
*
* ShortcircuitXT is inspired by, and shares code with, the
* commercial product Shortcircuit 1 and 2, released by VemberTech
* in the mid 2000s. The code for Shortcircuit 2 was opensourced in
* 2020 at the outset of this project.
*
* All source for ShortcircuitXT is available at
* https://github.com/surge-synthesizer/shortcircuit-xt
*/

#ifndef CLIENTS_CLAP_FIRST_SCXT_PLUGIN_SCXT_CLAP_ENTRY_IMPL_H
#define CLIENTS_CLAP_FIRST_SCXT_PLUGIN_SCXT_CLAP_ENTRY_IMPL_H

namespace scxt::clap_first
{

const void *get_factory(const char *factory_id);
bool clap_init(const char *p);
void clap_deinit();

} // namespace scxt::clap_first
#endif // SCXT_PLUGIN_ENTRY_IMPL_H
2 changes: 1 addition & 1 deletion clients/clap-first/scxt-plugin/scxt-plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
#include "engine/engine.h"
#include "voice/voice.h"

#include "clap-config.h"
#include "clap-helpers-config.h"
#include "utils.h"

static_assert((int)scxt::voice::Voice::ExpressionIDs::VOLUME == (int)CLAP_NOTE_EXPRESSION_VOLUME);
Expand Down
Loading