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

In case there's interest, I'm developing a cython csound wrapper: cycsound #25

Open
shakfu opened this issue Jun 22, 2024 · 10 comments
Open

Comments

@shakfu
Copy link

shakfu commented Jun 22, 2024

Hi, In case this is useful somehow, I started work on a cython wrapper for the csound.h api a little while ago called cycsound.

It's still early stage, but so far it wraps a small subset of the api with audio output. It compiles (dynamic linking) on macOS, windows, and linux, with full static linking on macOS, which means it can currently generate a self-contained 2MB python wheel for macOS (which was my initial driver to start this project).

Reading the excellent ctcsound.py source has been enormously helpful and I've been using it as a development guide.

I'll keep chipping away... it helps me to learn csound, but any feedback would be welcome (-:

@fggp
Copy link
Collaborator

fggp commented Jun 22, 2024 via email

@shakfu
Copy link
Author

shakfu commented Jun 22, 2024

@fggp Thanks for the heads up...

I'll keep an eye out for changes in the api...

@shakfu
Copy link
Author

shakfu commented Jun 25, 2024

@fggp It's not clear to me where changes in the api are occurring. Is there some branch somewhere where this is happening?

@fggp
Copy link
Collaborator

fggp commented Jun 25, 2024 via email

@shakfu
Copy link
Author

shakfu commented Jun 25, 2024

@fggp Thanks for the info about the new api. Will check it out. 👍

@shakfu
Copy link
Author

shakfu commented Jun 28, 2024

@fggp The new api is a lot shorter than the old one:

#ifndef CSOUND_H
#define CSOUND_H

//Instantiation
PUBLIC int 	csoundInitialize (int flags)
PUBLIC CSOUND*  csoundCreate (void *hostData) 
PUBLIC void 	csoundDestroy (CSOUND *) 

// Performance
// One compilation function that does everything
// For example, we could potentially use "argc" as a code
// > 0 - argc/argv as main() command-line parameters
// 0 - start csound as a daemon with no code, ignore argv
// -1 - argv[0] is an orchestra string (csoundCompileStr)
// -2 - argv[0] is a complete csound   (csoundCompileCsdText)
// First call to csoundCompile() also starts Csound so we remove csoundStart()
// async defines async operation
// NB - interface with double pointers may not be ideal for non C/C++
PUBLIC int  csoundCompile (CSOUND *, int argc, const char **argv, int async);
PUBLIC int  csoundPerformKsmps (CSOUND *);

// Realtime Audio
// this is now effectively -n since there is no access to buffer, only to spin.
// we need a better name I think
PUBLIC void csoundSetHostImplementedAudioIO(CSOUND *, int state);
// access to spin/spout (no need to give individual sample access)
PUBLIC MYFLT *csoundGetSpin (CSOUND *);
PUBLIC MYFLT *csoundGetSpout (CSOUND *csound);

// no audio IO callbacks - that's only available in the module API now.
// MIDI callbacks can be set with a single new function
typedef struct {
  int(*open)(CSOUND *, void **userData, const char *devName, int mode); // MIDI open callback (mode=CS_MIDI_IN, CS_MIDI_OUT)
  int(*read)(CSOUND *, void *userData, unsigned char *buf, int nBytes);
  int(*write)(CSOUND *, void *userData, unsigned char *buf, int nBytes);
  int(*close)(CSOUND *, void *userData);
} CS_MIDI_CALLBACKS;
PUBLIC void csoundSetMIDICallbacks(CSOUND *, CS_MIDI_CALLBACKS *);
 
// Messages
PUBLIC void 	   csoundCreateMessageBuffer (CSOUND *csound, int toStdOut)
PUBLIC const char *csoundGetFirstMessage (CSOUND *csound)
PUBLIC void 	   csoundPopFirstMessage (CSOUND *csound)
PUBLIC int 	       csoundGetMessageCnt (CSOUND *csound)
void PUBLIC 	   csoundDestroyMessageBuffer (CSOUND *csound)

// Channels
PUBLIC int csoundListChannels(CSOUND *, controlChannelInfo_t **lst);
PUBLIC void csoundDeleteChannelList(CSOUND *, controlChannelInfo_t *lst);
// basic types
PUBLIC MYFLT csoundGetControlChannel(CSOUND *csound, const char *name, int *err);
PUBLIC void csoundSetControlChannel(CSOUND *csound, const char *name, MYFLT val);
PUBLIC void csoundGetAudioChannel(CSOUND *csound, const char *name, MYFLT *samples);
PUBLIC void csoundSetAudioChannel(CSOUND *csound, const char *name, MYFLT *samples);
PUBLIC void csoundGetStringChannel(CSOUND *csound, const char *name, char *string);
PUBLIC  void csoundSetStringChannel(CSOUND *csound, const char *name, char *string);
// generic data access (e.g. for other types, structs, etc)
PUBLIC int csoundGetChannelPtr(CSOUND *, MYFLT **p, const char *name, int type);
PUBLIC int csoundGetChannelDatasize(CSOUND *csound, const char *name);

// events:
// async selects asynchronous operation
// new function - replaces csoundInputMessage
PUBLIC void  csoundEventString (CSOUND *, const char *message, int async);
// new function - replaces csoundScoreEvent
// type 0 - instrument instance     CS_INSTR_EVENT
// type 1 - functiob table instance CS_TABLE_EVENT
PUBLIC void  csoundEvent (CSOUND *, int type, MYFLT *params, int async);

//Tables
PUBLIC int 	csoundTableLength (CSOUND *, int table);
PUBLIC void csoundTableCopyIn (CSOUND *csound, int table, MYFLT *src);
PUBLIC void csoundTableCopyOut (CSOUND *csound, int table, MYFLT *dest);

//Opcodes - adapted for new internals
PUBLIC int 	csoundAppendOpcode (CSOUND *, const char *opname, int dsblksiz, int flags,
                                    const char *outypes, const char *intypes, int(*init)(CSOUND *, void *),
                                    int(*perf)(CSOUND *, void *), int(*deinit)(CSOUND *, void *));

//Threading and concurrency

#endif  /* CSOUND_H */

@fggp
Copy link
Collaborator

fggp commented Jun 28, 2024 via email

@shakfu
Copy link
Author

shakfu commented Jun 30, 2024

@fggp wrote

In the attachment you can read some proposals.

I'm sorry but I did not see any attachment.

@fggp
Copy link
Collaborator

fggp commented Jun 30, 2024 via email

@shakfu
Copy link
Author

shakfu commented Jun 30, 2024

Thanks for the summary. I completely agree with its contents.

This is good news since it looks like the csound7 api is really mostly a subset of the csound6 api.

I might as well continue my earlier work then.

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

No branches or pull requests

2 participants