Cabbage Logo
Back to Cabbage Site

Writing a plugin for Csound

Rory,

I’ve wanted to learn the internals of Csound for some time, now. But I absolutely despise C++. I’ve also wanted to learn how to embed Lua in another program, more than just the simple projects I’ve done so far. Yeah, I know, probably not the best first project. But that’s the goal.

Actually, the ultimate goal is to write a tool that would allow my bounding box library to be used to build something graphically. I know that that sort of task would require more complex data structures than what Csound can offer, and I know Lua.

Also, because this plugin would specifically be generating code that would only work with Cabbage, I figured I might as start with you. I’ve read through the basics on Csound, and I’ve got knowledge of embedding Lua, I’ve also looked through what they did with Python. I’ve been looking for the luaCsnd library code, but I’m guessing that’s a deprecated project.

Anyway, I was playing around with ChatGPT, and asked it to write at function that would divide a bounding box into smaller boxes, and while it wasn’t perfect Lua code, it did help me to consolidate several of my functions into one, and with a slight variation, I got rid of 3 more. So the bounding box library when from 43 opcodes, down to 11 or so. Plus, plus I rethought the create library, and that’s now the builder library, and only has maybe 300 lines (most of them comments).

Probably already said to much, so thanks…

Mike

A second related question… As part of my prototype, I want to create an image where I’ll be drawing the bounding boxes. I’ve only been trying to learn svg for a couple days, all I really need to do is a bunch of rects. I can learn more as I go.

My question is would it be possible to create an svg element with a name so that I could reference and access it after is rendered. Also, can I use the mouse to select elements? Can an element be edited/deleted once added? Or do I need to keep a rendering list separately?

You did say the svg implementation is a subset, right? Is there a list of available elements?

Mike

(answered my own second question…)

So just to clarify. Each image can only have one svgElement? Also, if that is true, I would need to “pre-create” each of these image/bboxes, and put them off-screen. I curious about the performance of creating a bunch of the images, and what limits are there.

Lucky for you Csound is written in C :stuck_out_tongue_winking_eye:

I think the luaCsnd is deprecated / not maintained, but there is a more recent project I think. I’ll take a look…

This is still being maintained afaik:


Johann hangs out on the Csound discord server if you need to ask any questions.

I’ve only looked at a couple things, and maybe it was just the names of the files that threw me off… Just plain Ansi C? That’s cool!

And thanks for the heads up on the Lua. I’ll have to wait until I get a Linux machine. Apple seems to require all the Linux package maintainers to remain current on the os, so I’m to far back to use home brew or what ever is the other…

1 Like