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

Module API redesign #1852

Open
wants to merge 27 commits into
base: develop
Choose a base branch
from
Open

Module API redesign #1852

wants to merge 27 commits into from

Conversation

vlazzarini
Copy link
Member

Started working on consolidating and rationalising the module API (aka public functions in CSOUND).
First step was to consolidate the real FFT interface.

@vlazzarini
Copy link
Member Author

Some more work on this:

  • Removed unused functions
  • Consolidated some
  • Moved all OPDS-related functions out of the structure as inline: the rationale is twofold, first these do not depend on CSOUND but strictly operate on OPDS, secondly, they are minimal. We can add these without affecting the CSOUND structure.

@bramtayl
Copy link

bramtayl commented Mar 26, 2024

I like the renaming to make things easier to read/understand, maybe we should add deprecation messages though?

How much benefit is there from these public functions being part of the csound struct, instead of global functions? Global functions might be a bit easier to organize, and reduce the need for so much csound->. Is the idea that opcodes can swap out the functions for alternatives?

@vlazzarini
Copy link
Member Author

vlazzarini commented Mar 26, 2024

Anything that depends on CSOUND needs to be inside CSOUND otherwise external opcodes will not be able to use them. This is because external opcodes and other modules are loaded into a running instance and use its functionality without having to be linked to libcsound. Internal opcodes can access CSOUND entirely and all the public libcsound functions, but external modules/plugins cannot. The module API is for the benefit of external opcodes.

All opcodes in ../Opcodes should be external and all opcodes in ../OOps should be internal. Not all external are built as plugins because of the constraints of platforms we support. Code in 6.x drifted to accessing certain internal parts of the library because of this, but I am working on fixing this. We don't open the CSOUND structure because access then cannot be controlled and we are open to vulnerabilities. This has to be tightly controlled to avoid externals bringing the system down.

No need for deprecation messages at this point because version 7.0 does not have API compatibility with 6.x.

@bramtayl
Copy link

use its functionality without having to be linked to libcsound

Why are we avoiding linking plugins to libcsound though? Seems like it would be easier than having to carry around all these function definitions in the struct?

@vlazzarini
Copy link
Member Author

We are not avoiding anything.
This is how the system is designed, plugins are dynamically loaded modules, Csound loads them and resolves all symbols from inside. It is how a plugin system should work.

@bramtayl
Copy link

Hm, well, on my branch, I've started to move these out to global functions, and tests, including the plugin tests I've added, pass fine. bramtayl#29. I do link the plugins to libcsound though.

@kunstmusik
Copy link
Member

kunstmusik commented Mar 27, 2024 via email

@bramtayl
Copy link

sharing compiled plugins with other users

Hm, that doesn't seem like the best idea anyways?

problematic for linking issues on Windows

Can we add a test for that?

@kunstmusik
Copy link
Member

kunstmusik commented Mar 27, 2024 via email

@bramtayl
Copy link

I'm just looking for a way to trigger the issue, that's all. For example, github actions has several different OS versions to choose from: https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners/about-github-hosted-runners#standard-github-hosted-runners-for-public-repositories, we could just download the same plugin and try it on different versions.

Most of our users don't compile csound or plugins

Oh sure, of course users would want to download csound and the plugins all at once. I'm just skeptical of the wisdom of a user sharing a plugin with another user, especially because the two users could have totally different operating systems, c standard libraries, etc.

@vlazzarini
Copy link
Member Author

vlazzarini commented Mar 27, 2024

@bramtayl why don't you do a fork of Csound using your own ideas? Provided you keep to the licensing, it's Free software and you can do whatever you want with it.

We're happy for you to pursue your own design ideas, but for Csound 7.0. we are keeping to the library and API design we have put together since 2003.

@kunstmusik
Copy link
Member

kunstmusik commented Mar 27, 2024 via email

@bramtayl
Copy link

bramtayl commented Apr 22, 2024

why don't you do a fork of Csound using your own ideas?

Ok, I'll work on my on fork for now. As of #29 I've moved all public member functions from CSound to global functions, which means for the most part I can just use a forward declaration for the struct. The only remaining need for a second definition of the struct is for the C++ wrapper in plugin.h, but I'm working on dropping that too.

Compiling a plugin on Windows or Mac and distributing it to other users on those systems

I still don't understand why linking libcsound in plugins would cause a problems in these use cases. Any breadcrumbs you have to specific previous issues would be helpful.

@vlazzarini
Copy link
Member Author

Just to let you know that we will not be accepting any such changes in the Csound code structure, but of course you are welcome to fork and develop your own version.

@kunstmusik
Copy link
Member

@vlazzarini Could you update this PR with the latest from develop? Will review once this is building through GH actions.

@vlazzarini
Copy link
Member Author

will do

@vlazzarini
Copy link
Member Author

It's all merged now.

include/csoundCore.h Outdated Show resolved Hide resolved
Engine/fgens.c Outdated Show resolved Hide resolved
@@ -334,466 +303,476 @@ static inline const CS_TYPE *StringType(CSOUND *csound) {
}

static inline const CS_TYPE *AsigType(CSOUND *csound) {
return csound->asigType;
return csound->asigType;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious, why were these types added here as part of the API? Were these not accessible from csound_standard_types.h?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I added the option to build opcodes as plugins, I got undefined symbols for these. The best solution I could find was to make them available through the Csound struct. This was originally done in another PR.

@@ -186,59 +186,7 @@ int csoundSetReleaseLength(void *p, int n);
*/
MYFLT csoundSetReleaseLengthSeconds(void *p, MYFLT n);

/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These functions here look like they were previously a part of the API. Are there alternative ways now to for opcodes to access this information?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They don't seem to be used anywhere in the code and they are not public either. I don't know if we should add them to the module API. I tend to try and keep it to what is being used, at this stage I think we should know more or less what opcodes require. Happy to add it if you think it needs to be there.

@@ -1769,7 +1744,7 @@ static int gen30(FGDATA *ff, FUNC *ftp)
x[i] = FL(0.0);
x[1] = x[l1];
x[l1] = x[l1 + 1] = FL(0.0);
csound->InverseRealFFT(csound, x, l1);
csound->RealFFT(csound, csound->RealFFTSetup(csound,l1,FFT_FWD), x);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking here: the older code called csound->InverseRealFFT(), but this is now calling csound->RealFFT(). Is this correct?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, the interface is common to both directions, it gets set up differently. Just noted that it's FFT_INV, will fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants