Actuallly, I’m looking for this kind of thing https://chuck.stanford.edu/chunity/documentation/#chuckeventlistener which I used in this project https://youtu.be/OM_B1s9WCVQ It was some time ago so I’m trying to remember how it was done) and apply to Csound.
Generally what it does it listens to Chuck and wait for an message from it. Then it fires function you need. And I used delegates (Action) to send this signal to function in other objects. The reason I stopped to make it like this, guys from Chuck do not want to work on mobile support or I didn’t find a right branch of code. They are welcoming any efforts on subject but I am not a programmer, unfortunately.
Spaceship project is made with UE4 Quartz which provides accurate tick events in music timing but I don’t like size of the build) and lack of WebGL support. So I am stuck in finding universal platform as you see) Hopefully I do something with CSound.
CsoundUnity Package (UPM) development
I’m sure it can be done with Csound, it will just take some thought. So Chuck would send event that would trigger events in the game? You can do this with CsoundUnity also. Simple place some kind of channel listener in your C# script. Whenever a channel changes in Csound, it can trigger the appropriate response in Unity. I’m not sure if the invalue/outvalue
callbacks are supported in CsoundUnity, they are another potential solution.
@doudar41 if I understood what you’re trying to achieve you could create a variable in the Csound code, which will act as a trigger, and set its value on a channel with chnset.
On Unity, use CsoundUnity.GetChannel to get its value, and check for changes.
You can then reset it with CsoundUnity.SetChannel.
Maybe I could add a sample about how to use triggers, there are plenty of ways to achieve the same result!
But feel free to ask and post your code attempts!
I suggest you to open a new thread since this is holding too much information, (outdated in some cases)
Another note: we don’t support WebGL (and we won’t in the close future) since we cannot use OnAudioFilterRead there (with that function we fill the samples of the AudioSource), so we need to find a workaround, which doesn’t look very easy to find.
@rorywalsh I think we discussed about this briefly in the past, do you have any idea on how we could make it work?
Also I could implement csoundSetInputChannelCallback and csoundSetOutputChannelCallback, they could be very handy in this scenario!
I think yes, It looks like good idea, thanks. I struggle with understanding referencing in csound or better to say overall syntax) Hopefully I will figure it out and show some results soon)
@rorywalsh
I did some progress which I want to share with you. https://youtu.be/rPdnRSIi9FM
As you see I did some progress on rhythmic movements.
I used scriptable objects and events in it so cabbage file looks like this
https://github.com/doudar41/csoundShip/blob/60f7329d47d8a868993dae52a76cfe38f2473767/ShipRhythmMaker
I used as you advised Rory’s Sequencer. But I took only one table which is like 16th notes of one bar.
Result of counting through these notes I sent to Unity by chnset. Where I check in Update kind of OnValueChange function and call unity event once per changing. There are some weird things going on ) but mostly it works.
Nice. So you’re happy that it will do the job?
Not yet)) There some strange things. I stuck on spawning perfabs that connect to this event. But hopefully I’ll manage it, at least this is a good start.
@doudar41 on this branch https://github.com/rorywalsh/CsoundUnity.git#channelCallbacks the first implementation of csoundSetInputChannelCallback, csoundSetOutputChannelCallback, csoundRegisterSenseEventCallback and csoundSetYieldCallback.
Still WIP, but would be nice having some feedback.
Known issues: the callback cannot be added again after removing them, or Unity will hang and you’ll have to force close it.
Removing the callback doesn’t correctly clear the callback from the heap.
Notice that there is no way of clearing the callbacks with a Csound API method yet (see: https://github.com/csound/csound/issues/1595)
Btw you can use them like this:
CsoundUnity csound;
CsoundUnityBridge.ChannelEventHandler InputChannelHandler;
// Start is called before the first frame update
void Start()
{
csound = GetComponent<CsoundUnity>();
InputChannelHandler = new CsoundUnityBridge.ChannelEventHandler((sender, args) =>
{
Debug.Log($"{sender}, Name: {args.Name}, Type: {args.Type}, Value: {args.Value}, Direction: {args.Direction}");
});
csound.AddInputChannelCallback(InputChannelHandler);
}
The above callback will be invoked everytime an “invalue” opcode is used in Csound.
You can test it with this csd example:
<CsoundSynthesizer>
<CsOptions>
</CsOptions>
<CsInstruments>
;run this example in CsoundQt, a Csound editor that provides widgets
;make the Widgets-panel visible, by clicking the Widgets symbol in the menu or pressing (Alt+1).
sr = 48000
ksmps = 64
nchnls = 2
0dbfs = 1
; written by Andres Cabrera
instr 1
kfreq invalue "freq" ; Quotes are needed here
asig oscil 0.1, kfreq, 1
outs asig, asig
endin
</CsInstruments>
<CsScore>
f 1 0 1024 10 1 ;sine
i 1 0 300 ;play for 300 seconds
e
</CsScore>
</CsoundSynthesizer>
Great, I’ll test it. I cancelled my work for Russian media and now little bit busy of finding something new) because it was my essencial income. But I’ll test it definitely. Thank you. I had some improvement I wanted to share and discuss with you but still think that callback should be better way. So it better I test it.
I’m sorry to hear that, hopefully better times will come.
I’m very curious to see your improvements, feel free to open a new thread showcasing your work!
I just wanted to point out that those callbacks will be probably removed in Csound 7, see Victor’s comment here: https://github.com/csound/csound/issues/1595#issuecomment-1053581096, so I’m not sure it is a good idea to add those methods to the CsoundUnity master.
Yeah, I was also following that thread. Seems like adding it now might lead to some frustration down the road when Csound 7 becomes mainstream. @doudar41, if you can manage to get it to work with basic polling, then I’d stick with that.
In the process of adding VU Meters to the CsoundUnity Editor
Little downside: we now see the Script field because I have to draw the default editor inspector to have the VUMeters drawn
But I think they are very useful while developing, I found myself gathering the volume from Csound too many times, so in the next release (3.3.0) I think you will find the VUMeters
Now you’re spoiling us!