Cabbage Logo
Back to Cabbage Site

Adding a set of standard Csound-based DSP Components to the next version of Csound Unitynts to

Hi!
First draft of presets available on the branch:

Use this link in the package manager:

https://github.com/rorywalsh/CsoundUnity.git#1632e230d95228268226dedec28524384a15f018

or better:

https://github.com/rorywalsh/CsoundUnity.git#feature/presets

Still WIP, not really documented, but I wanted to have some feedback before going on!
Let me know your thoughts!

EDIT: I think there is some issue with combo boxes yet :confused:

EDIT of EDIT: combo boxes should be fixed!

2 Likes

Hi!

Just got a chance to play with it a bit this morning, this is amazing! Combo boxes do look fixed on my end.

One thing that would be a nice addition would be the option to set a custom path to save the scriptable objects to help keep everything organized (as opposed to just saving them in the root of the assets folder.

Another thing that would be nice to have (and I have no idea how reasonable/feasible this is) would be if CsoundUnity could read a .snaps file generated by Cabbage and create CsoundUnityPreset assets based off that. But even without this this implementation is so much help, thank you so much!

1 Like

There seems to be an issue with building the Unity project when using the version of the package with the preset system - I’ve been getting these two errors when trying to build both for MacOS and Android

Edit: the image turned out too small but the errors say:

Library/PackageCache/com.csound.csoundunity@e484923571/Runtime/CsoundUnity.cs(1579,30): error CS0103: The name ‘UnityWebRequest’ does not exist in the current context

Library/PackageCache/com.csound.csoundunity@e484923571/Runtime/CsoundUnity.cs(1581,43): error CS0246: The type or namespace name ‘DownloadHandlerBuffer’ could not be found (are you missing a using directive or an assembly reference?)

Thanks for the tests and the suggestions, will fix the build issue soon (should be a missing reference in the asmdefs)

About the custom path, yes! I was thinking of adding it but I didn’t have enough time :wink:

About reading the snaps, it shouldn’t be too hard, they should be csv I think. The only thing I’m not sure is if they hold the channel name inside, if not it could be hard to “link” the channels.

I’ll have a look!

1 Like

The Cabbage snaps are in JSON format, and follow a simple channel:value structure. Should be easy to convert from one to the other. Great work @giovannibedetti

1 Like

Perfect!
I will add that in, hopefully while at the airport waiting for my flight back to Italy this saturday :wink:

Fix for the build issue pushed to feature/presets!

1 Like

ah yes it will be easy to import Cabbage snaps and also export them from Unity!

{
    "test": {
        "form": 0.0,
        "keyboard2": 60.0,
        "att": 0.009999999776482582,
        "dec": 0.4000000059604645,
        "sus": 0.699999988079071,
        "rel": 0.800000011920929,
        "filebutton8": 0.0,
        "filebutton9": 0.0
    }
}
2 Likes

@giovannibedetti can’t wait for new updates, thank you so much for working on this! One thing I just noticed is that button widgets don’t seem to be represented in the presets assets? They show up on the CsoundUnity component but the presets I’m creating doesn’t seem to contemplate channels associated with buttons.

EDIT: the issue I’ve been having with that is that for some instruments I’m using a button widget paired with a changed opcode to start/stop a continuous sound and it turns out that by changing the preset it unintentionally triggers/untriggers the instrument.

Ah yes that makes sense, since I set all the channels values!
let me add an exception for the buttons.
I will probably push an update to the branch today :wink:

EDIT: I pushed an update, not really tested, but it looks good!
Let me know how it goes

1 Like

Just got a chance to test it, the button exception is working beautifully! Also thanks so much for adding a path to save the preset files!

I just pushed an update to the presets branch, I think we’re getting there!
Now you can choose the save/load folder, and also json presets are listed to be loaded from the editor!
It needs some serious testing, let me know if you find any issue :wink:
Unfortunately I cannot add the support for Cabbage snaps easily, because Unity json deserialisation is very basic and it doesn’t work with the snaps json format where the keys are the name of the channels.
I have to parse the snaps :nerd_face:

That’s a shame. Is it worth looking into using a third party JSON package? Maybe not if you have already written a parser yourself?

I’m having a look but I’d like to avoid adding dependencies. I haven’t tried to write the parser yet, hopefully it won’t be too hard!

1 Like

Just sneaked some time to check this out - the option to select which folder to load form is super useful!

EDIT: Everything seems to be working fine with the ScriptableObject presets but the ones I saved as a JSON file don’t seem to serialize in the inspector under the Assignable Presets area.

JSONs are meant to be placed in folders that Unity doesn’t compile when built, so I am not checking for JSONs that are under the Assets folder. The exception is the StreamingAssets folder, that Unity doesn’t compile.
Have a look at https://github.com/rorywalsh/CsoundUnity/blob/6d7465dd3f2d941b6202c45e01a25b4051c028bd/Editor/CsoundUnityEditor.cs#L771
Does it make sense?
If not we can try and think of a solution, for sure there is still some work to be done, for example I haven’t tried with a “Resources” folder, that could require a custom loading (Resources.Load() => https://docs.unity3d.com/ScriptReference/Resources.Load.html)

Hi Giovanni, sorry for the delay! Ah gotcha - I don’t have much experience with JSON files so wasn’t aware of that, thanks for the explanation! I can see how using a “Resources” folder could be useful to streamline preset management by potentially allowing scriptable objects and JSON presets to live in the same path maybe?

Also, is there a way that JSON presets could be converted into scriptable object presets and vice-versa? Migrating SO between projects has always been messy in my experience, but with a JSON preset I can simply copy the file to another Unity project and it works right away (which would allow me to make a “preset pack” for an instrument and carry it from project to project). At the same time, SO offer more flexibility to edit them through the inspector and to load them with scripting (since I only need to call CsoundUnity.SetPreset() and pass in a SO as the argument), so it would be useful to convert the presets to SO after importing the JSON files. Not sure if this is too convoluted or if there’s a simpler solution to this conundrum tho

Hey!
So the latest push I made should allow placing SO and JSONs everywhere, it’s on the same preset branch!
To convert the JSON into a SO you could load the JSON first and then save it as a SO for now, but I will add a method to allow that (maybe a separate Editor Window, since there’s no point in doing this at runtime, also I think it could make the current CsoundUnity editor more confusing)
Hopefully I will have some time next week to look into this :wink:

1 Like

So it was very quick to add this since all the methods were there already :wink:
I decided to add a button for each preset to convert it to JSON or SO.
Not sure what it does to Global presets, but it’s a start :sweat_smile:
Same branch: https://github.com/rorywalsh/CsoundUnity.git#feature/presets
image

1 Like

I think it’s time I read up on Scriptable Objects. C# is becoming a distant memory to me :rofl: