CsoundUnity 3.4.0
https://github.com/rorywalsh/CsoundUnity
CsoundUnityBridge.cs
Go to the documentation of this file.
1/*
2Copyright (C) 2015 Rory Walsh.
3
4This file is part of CsoundUnity: https://github.com/rorywalsh/CsoundUnity
5
6This interface would not have been possible without Richard Henninger's .NET interface to the Csound API.
7
8Contributors:
9
10Bernt Isak Wærstad
11Charles Berman
12Giovanni Bedetti
13Hector Centeno
14NPatch
15
16Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
17to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
18and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
19
20The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
21
22THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
24ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
25THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26*/
27
28using UnityEngine;
29using System;
30using System.Runtime.InteropServices;
31using csoundcsharp;
32using System.Collections.Generic;
33#if UNITY_EDITOR || UNITY_STANDALONE
34using MYFLT = System.Double;
35#elif UNITY_ANDROID || UNITY_IOS
36using MYFLT = System.Single;
37#endif
38
39/*
40 * CsoundUnityBridge class
41 */
43{
44 public IntPtr csound;
45 bool compiledOk = false;
46 Action onCsoundCreated;
47
48 private void SetEnvironmentSettings(List<EnvironmentSettings> environmentSettings)
49 {
50 if (environmentSettings == null || environmentSettings.Count == 0) return;
51 foreach (var env in environmentSettings)
52 {
53 if (env == null) continue;
54 var path = env.GetPath();
55 if (string.IsNullOrWhiteSpace(path)) continue;
56
57 switch (Application.platform)
58 {
59 case RuntimePlatform.OSXEditor:
60 case RuntimePlatform.OSXPlayer:
61 if (env.platform.Equals(SupportedPlatform.MacOS))
62 {
63 Debug.Log($"Setting {env.GetTypeString()} for MacOS to: {path}");
64 Csound6.NativeMethods.csoundSetGlobalEnv(env.GetTypeString(), path);
65 }
66 break;
67 case RuntimePlatform.WindowsPlayer:
68 case RuntimePlatform.WindowsEditor:
69 if (env.platform.Equals(SupportedPlatform.Windows))
70 {
71 Debug.Log($"Setting {env.GetTypeString()} for Windows to: {path}");
72 Csound6.NativeMethods.csoundSetGlobalEnv(env.GetTypeString(), path);
73 }
74 break;
75 case RuntimePlatform.Android:
76 if (env.platform.Equals(SupportedPlatform.Android))
77 {
78 Debug.Log($"Setting {env.GetTypeString()} for Android to: {path}");
79 Csound6.NativeMethods.csoundSetGlobalEnv(env.GetTypeString(), path);
80 //Debug.Log($"baseFolder: {env.baseFolder}");
81 if (env.baseFolder.Equals(EnvironmentPathOrigin.Plugins))
82 {
83 if (onCsoundCreated == null || onCsoundCreated.GetInvocationList().Length == 0)
84 {
85 onCsoundCreated += () =>
86 {
87 Debug.Log("Csound Force Loading Plugins!");
88 var loaded = Csound6.NativeMethods.csoundLoadPlugins(csound, path);
89 Debug.Log($"PLUGINS LOADED? {loaded}");
90 };
91 }
92 }
93 }
94 break;
95 case RuntimePlatform.IPhonePlayer:
96 if (env.platform.Equals(SupportedPlatform.iOS))
97 {
98 Debug.Log($"Setting {env.GetTypeString()} for iOS to: {path}");
99 Csound6.NativeMethods.csoundSetGlobalEnv(env.GetTypeString(), path);
100 }
101 break;
102 default:
103 break;
104 }
105 }
106 }
107
115 public CsoundUnityBridge(string csdFile, List<EnvironmentSettings> environmentSettings)
116 {
117 SetEnvironmentSettings(environmentSettings);
118
119 // KEEP THIS FOR REFERENCE ;)
120 //#if (UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN)
121 // Csound6.NativeMethods.csoundSetGlobalEnv("OPCODE6DIR64", csoundDir);
122 //#elif UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
123 // var opcodePath = Path.GetFullPath(Path.Combine(csoundDir, "CsoundLib64.bundle/Contents/MacOS"));
124 // //Debug.Log($"opcodePath {opcodePath} exists? " + Directory.Exists(opcodePath));
125 // Csound6.NativeMethods.csoundSetGlobalEnv("OPCODE6DIR64", opcodePath);
126 //#elif UNITY_ANDROID
127 // Csound6.NativeMethods.csoundSetGlobalEnv("OPCODE6DIR64", csoundDir);
128 //#endif
129
130 Csound6.NativeMethods.csoundInitialize(1);
131 csound = Csound6.NativeMethods.csoundCreate(System.IntPtr.Zero);
132 if (csound == null)
133 {
134 Debug.LogError("Couldn't create Csound!");
135 return;
136 }
137
138 Csound6.NativeMethods.csoundSetHostImplementedAudioIO(csound, 1, 0);
139 Csound6.NativeMethods.csoundCreateMessageBuffer(csound, 0);
140
141 Csound6.NativeMethods.csoundSetOption(csound, "-n");
142 Csound6.NativeMethods.csoundSetOption(csound, "-d");
143
144 var parms = GetParams();
145 parms.control_rate_override = AudioSettings.outputSampleRate;
146 parms.sample_rate_override = AudioSettings.outputSampleRate;
147 SetParams(parms);
148
149 onCsoundCreated?.Invoke();
150 onCsoundCreated = null;
151
152 int ret = Csound6.NativeMethods.csoundCompileCsdText(csound, csdFile);
153 Csound6.NativeMethods.csoundStart(csound);
154 //var res = PerformKsmps();
155 //Debug.Log($"PerformKsmps: {res}");
156 compiledOk = ret == 0 ? true : false;
157 //Debug.Log($"CsoundCompile: {compiledOk}");
158 }
159
160 #region Instantiation
161
162 public int LoadPlugins(string dir)
163 {
164 return Csound6.NativeMethods.csoundLoadPlugins(csound, dir);
165 }
166
167 #endregion
168 public int GetVersion()
169 {
170 return Csound6.NativeMethods.csoundGetVersion();
171 }
172
173 public int GetAPIVersion()
174 {
175 return Csound6.NativeMethods.csoundGetAPIVersion();
176 }
177
178 public void StopCsound()
179 {
180 Csound6.NativeMethods.csoundStop(csound);
181 }
182
183 public void OnApplicationQuit()
184 {
185 StopCsound();
186 //Csound6.NativeMethods.csoundCleanup(csound);
187 Csound6.NativeMethods.csoundDestroyMessageBuffer(csound);
188 Csound6.NativeMethods.csoundDestroy(csound);
189 }
190
191 public void Cleanup()
192 {
193 Csound6.NativeMethods.csoundCleanup(csound);
194 }
195
196 public void Reset()
197 {
198 Csound6.NativeMethods.csoundReset(csound);
199 }
200
202 {
203 return compiledOk;
204 }
205
206 public int CompileOrc(string orchStr)
207 {
208 return Csound6.NativeMethods.csoundCompileOrc(csound, orchStr);
209 }
210
211 public int PerformKsmps()
212 {
213 return Csound6.NativeMethods.csoundPerformKsmps(csound);
214 }
215
216 public MYFLT Get0dbfs()
217 {
218 return Csound6.NativeMethods.csoundGet0dBFS(csound);
219 }
220
222 {
223 return Csound6.NativeMethods.csoundGetCurrentTimeSamples(csound);
224 }
225
226 public void SendScoreEvent(string scoreEvent)
227 {
228 Csound6.NativeMethods.csoundInputMessage(csound, scoreEvent);
229 }
230
231 public void RewindScore()
232 {
233 Csound6.NativeMethods.csoundRewindScore(csound);
234 }
235
236 public void CsoundSetScoreOffsetSeconds(MYFLT value)
237 {
238 Csound6.NativeMethods.csoundSetScoreOffsetSeconds(csound, value);
239 }
240
241 public void SetChannel(string channel, MYFLT value)
242 {
243 Csound6.NativeMethods.csoundSetControlChannel(csound, channel, value);
244 }
245
246 public void SetStringChannel(string channel, string value)
247 {
248 Csound6.NativeMethods.csoundSetStringChannel(csound, channel, value);
249 }
250
251 public void SetAudioChannel(string name, MYFLT[] audio)
252 {
253 var bufsiz = GetKsmps();
254 var buffer = Marshal.AllocHGlobal(sizeof(MYFLT) * (int)bufsiz);
255 Marshal.Copy(audio, 0, buffer, (int)Math.Min(audio.Length, bufsiz));
256 Csound6.NativeMethods.csoundSetAudioChannel(csound, name, buffer);
257 Marshal.FreeHGlobal(buffer);
258 }
259
260 public MYFLT[] GetAudioChannel(string name)
261 {
262 var bufsiz = GetKsmps();
263 var buffer = Marshal.AllocHGlobal(sizeof(MYFLT) * (int)bufsiz);
264 MYFLT[] dest = new MYFLT[bufsiz];//include nchnls/nchnlss_i? no, not an output channel: just a single ksmps-sized buffer
265 Csound6.NativeMethods.csoundGetAudioChannel(csound, name, buffer);
266 Marshal.Copy(buffer, dest, 0, dest.Length);
267 Marshal.FreeHGlobal(buffer);
268 return dest;
269 }
270
274 public int TableLength(int table)
275 {
276 return Csound6.NativeMethods.csoundTableLength(csound, table);
277 }
278
282 public MYFLT GetTable(int table, int index)
283 {
284 return Csound6.NativeMethods.csoundTableGet(csound, table, index);
285 }
286
290 public void SetTable(int table, int index, MYFLT value)
291 {
292 Csound6.NativeMethods.csoundTableSet(csound, table, index, value);
293 }
294
298 public void TableCopyOut(int table, out MYFLT[] dest)
299 {
300 int len = Csound6.NativeMethods.csoundTableLength(csound, table);
301 if (len < 1)
302 {
303 dest = null;
304 return;
305 }
306
307 dest = new MYFLT[len];
308 IntPtr des = Marshal.AllocHGlobal(sizeof(MYFLT) * dest.Length);
309 Csound6.NativeMethods.csoundTableCopyOut(csound, table, des);
310 Marshal.Copy(des, dest, 0, len);
311 Marshal.FreeHGlobal(des);
312 }
313
317 public void TableCopyOutAsync(int table, out MYFLT[] dest)
318 {
319 int len = Csound6.NativeMethods.csoundTableLength(csound, table);
320 if (len < 1)
321 {
322 dest = null;
323 return;
324 }
325
326 dest = new MYFLT[len];
327 IntPtr des = Marshal.AllocHGlobal(sizeof(MYFLT) * dest.Length);
328 Csound6.NativeMethods.csoundTableCopyOutAsync(csound, table, des);
329 Marshal.Copy(des, dest, 0, len);
330 Marshal.FreeHGlobal(des);
331 }
332
337 public void TableCopyIn(int table, MYFLT[] source)
338 {
339 var len = Csound6.NativeMethods.csoundTableLength(csound, table);
340 if (len < 1 || len < source.Length) return;
341 IntPtr src = Marshal.AllocHGlobal(sizeof(MYFLT) * source.Length);
342 Marshal.Copy(source, 0, src, source.Length);
343 Csound6.NativeMethods.csoundTableCopyIn(csound, table, src);
344 Marshal.FreeHGlobal(src);
345 }
346
350 public void TableCopyInAsync(int table, MYFLT[] source)
351 {
352 var len = Csound6.NativeMethods.csoundTableLength(csound, table);
353 if (len < 1 || len < source.Length) return;
354 IntPtr src = Marshal.AllocHGlobal(sizeof(MYFLT) * source.Length);
355 Marshal.Copy(source, 0, src, source.Length);
356 Csound6.NativeMethods.csoundTableCopyInAsync(csound, table, src);
357 Marshal.FreeHGlobal(src);
358 }
359
364 public int GetTable(out MYFLT[] tableValues, int numTable)
365 {
366 int len = Csound6.NativeMethods.csoundTableLength(csound, numTable);
367 if (len < 1)
368 {
369 tableValues = null;
370 return -1;
371 }
372
373 IntPtr tablePtr = new IntPtr();
374 tableValues = new MYFLT[len];
375 int res = Csound6.NativeMethods.csoundGetTable(csound, out tablePtr, numTable);
376 if (res != -1)
377 Marshal.Copy(tablePtr, tableValues, 0, len);
378 else tableValues = null;
379 GCHandle gc = GCHandle.FromIntPtr(tablePtr);
380 gc.Free();
381 return res;
382 }
383
389 public int GetTableArgs(out MYFLT[] args, int index)
390 {
391 IntPtr addr = new IntPtr();
392 int len = Csound6.NativeMethods.csoundGetTableArgs(csound, out addr, index);
393 args = new MYFLT[len];
394 if (len != -1)
395 Marshal.Copy(addr, args, 0, len);
396 else args = null;
397 Marshal.FreeHGlobal(addr);
398 return len;
399 }
400
405 public int IsNamedGEN(int num)
406 {
407 return Csound6.NativeMethods.csoundIsNamedGEN(csound, num);
408 }
409
414 public void GetNamedGEN(int num, out string name, int len)
415 {
416 Csound6.NativeMethods.csoundGetNamedGEN(csound, num, out name, len);
417 }
418
422 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
423 private class NamedGenProxy
424 {
425 public IntPtr name;
426 public int genum;
427 public IntPtr next; //NAMEDGEN pointer used by csound as linked list, but not sure if we care
428 }
429
435 public IDictionary<string, int> GetNamedGens()
436 {
437 IDictionary<string, int> gens = new Dictionary<string, int>();
438 IntPtr pNAMEDGEN = Csound6.NativeMethods.csoundGetNamedGens(csound);
439 while (pNAMEDGEN != IntPtr.Zero)
440 {
441 NamedGenProxy namedGen = (NamedGenProxy)Marshal.PtrToStructure(pNAMEDGEN, typeof(NamedGenProxy));
442 gens.Add(Marshal.PtrToStringAnsi(namedGen.name), namedGen.genum);
443 pNAMEDGEN = namedGen.next;
444 }
445 return gens;
446 }
447
448 public MYFLT GetSr()
449 {
450 return Csound6.NativeMethods.csoundGetSr(csound);
451 }
452
453 public MYFLT GetKr()
454 {
455 return Csound6.NativeMethods.csoundGetKr(csound);
456 }
457
458 public uint GetKsmps()
459 {
460 return Csound6.NativeMethods.csoundGetKsmps(csound);
461 }
462
466 public MYFLT GetSpoutSample(int frame, int channel)
467 {
468 return Csound6.NativeMethods.csoundGetSpoutSample(csound, frame, channel);
469 }
470
471 public void AddSpinSample(int frame, int channel, MYFLT sample)
472 {
473 Csound6.NativeMethods.csoundAddSpinSample(csound, frame, channel, sample);
474 }
475
479 public void SetSpinSample(int frame, int channel, MYFLT sample)
480 {
481 Csound6.NativeMethods.csoundSetSpinSample(csound, frame, channel, sample);
482 }
483
487 public void ClearSpin()
488 {
489 Csound6.NativeMethods.csoundClearSpin(csound);
490 }
491
497 public MYFLT[] GetSpin()
498 {
499 var size = (Int32)Csound6.NativeMethods.csoundGetKsmps(csound) * (int)GetNchnlsInput();
500 var spin = new MYFLT[size];
501 var addr = Csound6.NativeMethods.csoundGetSpin(csound);
502 Marshal.Copy(addr, spin, 0, size);
503 return spin;
504 }
505
511 public MYFLT[] GetSpout()
512 {
513 var size = (Int32)Csound6.NativeMethods.csoundGetKsmps(csound) * (int)GetNchnls();
514 var spout = new MYFLT[size];
515 var addr = Csound6.NativeMethods.csoundGetSpout(csound);
516 Marshal.Copy(addr, spout, 0, size);
517 return spout;
518 }
519
523 public MYFLT GetChannel(string channel)
524 {
525 return Csound6.NativeMethods.csoundGetControlChannel(csound, channel, IntPtr.Zero);
526 }
527
531 public uint GetNchnlsInput()
532 {
533 return Csound6.NativeMethods.csoundGetNchnlsInput(csound);
534 }
535
539 public uint GetNchnls()
540 {
541 return Csound6.NativeMethods.csoundGetNchnlsInput(csound);
542 }
543
545 {
546 return Csound6.NativeMethods.csoundGetMessageCnt(csound);
547 }
548
549 public string GetCsoundMessage()
550 {
551 string message = GetMessageText(Csound6.NativeMethods.csoundGetFirstMessage(csound));
552 Csound6.NativeMethods.csoundPopFirstMessage(csound);
553 return message;
554 }
555
556 public static string GetMessageText(IntPtr message)
557 {
558 return CharPtr2String(message);
559 }
560
568 public IDictionary<string, IList<OpcodeArgumentTypes>> GetOpcodeList()
569 {
570 var opcodes = new SortedDictionary<string, IList<OpcodeArgumentTypes>>();
571 IntPtr ppOpcodeList = IntPtr.Zero;
572 int size = Csound6.NativeMethods.csoundNewOpcodeList(csound, out ppOpcodeList);
573 if ((ppOpcodeList != IntPtr.Zero) && (size >= 0))
574 {
575 int proxySize = Marshal.SizeOf(typeof(OpcodeListProxy));
576 for (int i = 0; i < size; i++)
577 {
578 OpcodeListProxy proxy = Marshal.PtrToStructure(ppOpcodeList + (i * proxySize), typeof(OpcodeListProxy)) as OpcodeListProxy;
579 string opname = Marshal.PtrToStringAnsi(proxy.opname);
581 {
582 outypes = Marshal.PtrToStringAnsi(proxy.outtypes),
583 intypes = Marshal.PtrToStringAnsi(proxy.intypes),
584 flags = proxy.flags
585 };
586 if (!opcodes.ContainsKey(opname))
587 {
588 IList<OpcodeArgumentTypes> types = new List<OpcodeArgumentTypes>();
589 types.Add(opcode);
590 opcodes.Add(opname, types);
591 }
592 else
593 {
594 opcodes[opname].Add(opcode);
595 }
596 }
597 Csound6.NativeMethods.csoundDisposeOpcodeList(csound, ppOpcodeList);
598 }
599 return opcodes;
600 }
601
609 public IDictionary<string, ChannelInfo> GetChannelList()
610 {
611 IDictionary<string, ChannelInfo> channels = new SortedDictionary<string, ChannelInfo>();
612
613 IntPtr ppChannels = IntPtr.Zero;
614 int size = Csound6.NativeMethods.csoundListChannels(csound, out ppChannels);
615 if ((size > 0) && (ppChannels != IntPtr.Zero))
616 {
617 int proxySize = Marshal.SizeOf(typeof(ChannelInfoProxy));
618 for (int i = 0; i < size; i++)
619 {
620 var proxy = Marshal.PtrToStructure(ppChannels + (i * proxySize), typeof(ChannelInfoProxy)) as ChannelInfoProxy;
621 string chanName = CharPtr2String(proxy.name);
622
623 ChannelInfo info = new ChannelInfo(chanName, (ChannelType)(proxy.type & 15), (ChannelDirection)(proxy.type >> 4));
624 var hintProxy = proxy.hints;
625 var hints = new ChannelHints((ChannelBehavior)hintProxy.behav, hintProxy.dflt, hintProxy.min, hintProxy.max)
626 {
627 x = hintProxy.x,
628 y = hintProxy.y,
629 height = hintProxy.height,
630 width = hintProxy.width,
631 attributes = CharPtr2String(proxy.name)
632 };
633 info.Hints = hints;
634 channels.Add(chanName, info);
635 }
636 Csound6.NativeMethods.csoundDeleteChannelList(csound, ppChannels);
637 }
638 return channels;
639 }
640
648 {
649 CSOUND_PARAMS oparms = new CSOUND_PARAMS();
650 Csound6.NativeMethods.csoundGetParams(csound, oparms);
651 return oparms;
652 }
653
663 public void SetParams(CSOUND_PARAMS parms)
664 {
665 Csound6.NativeMethods.csoundSetParams(csound, parms);
666 }
667
672 {
673 public string outypes;
674 public string intypes;
675 public int flags;
676 }
677
681 [StructLayout(LayoutKind.Sequential)]
682 private class OpcodeListProxy
683 {
684 public IntPtr opname;
685 public IntPtr outtypes;
686 public IntPtr intypes;
687 public int flags;
688 }
689
693 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
694 private class ChannelInfoProxy
695 {
696 [MarshalAs(UnmanagedType.AnsiBStr)]
697 public IntPtr name;
698 public int type;
699 [MarshalAs(UnmanagedType.Struct)]
700 public ChannelHintsProxy hints;
701 }
702
706 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
707 private struct ChannelHintsProxy
708 {
709 public ChannelHintsProxy(ChannelHints hints)
710 {
711 behav = (int)hints.behav;
712 dflt = hints.dflt; min = hints.min; max = hints.max;
713 x = hints.x; y = hints.y; height = hints.height; width = hints.width;
714 attributes = IntPtr.Zero;
715 }
716
717 public int behav;
718 public MYFLT dflt;
719 public MYFLT min;
720 public MYFLT max;
721 public int x;
722 public int y;
723 public int width;
724 public int height;
725 [MarshalAs(UnmanagedType.AnsiBStr)]
726 public IntPtr attributes;
727 }
728
729 public class ChannelInfo
730 {
731 public ChannelInfo(string _name, ChannelType _type, ChannelDirection _direction)
732 {
733 Name = _name;
734 Type = _type;
735 Direction = _direction;
736 }
737 public string Name;
741 };
742
746 public class ChannelHints
747 {
751 public ChannelHints() : this(ChannelBehavior.None, 0, 0, 0)
752 {
753 }
754
762 public ChannelHints(ChannelBehavior ibehav, MYFLT idflt, MYFLT imin, MYFLT imax)
763 {
764 behav = ibehav;
765 dflt = idflt;
766 min = imin;
767 max = imax;
768 x = 0;
769 y = 0;
770 width = 0;
771 height = 0;
772 attributes = null;
773 }
774
776 public MYFLT dflt;
777 public MYFLT min;
778 public MYFLT max;
779 public int x;
780 public int y;
781 public int width;
782 public int height;
783 public string attributes;
784 }
785
789 public enum ChannelBehavior
790 {
791 None = 0,
792 Integer = 1,
793 Linear = 2,
794 Exponential = 3
795 }
796
800 public enum ChannelType
801 {
802 None = 0, //error return type only, meaningless in input
803 Control = 1,
804 Audio = 2,
805 String = 3,
806 Pvs = 4,
807 Var = 5,
808 }
809
810 [Flags]
812 {
813 Input = 1,
814 Output = 2
815 }
816
817 [StructLayout(LayoutKind.Sequential)]
818 public class CSOUND_PARAMS
819 {
820 public int debug_mode; /* debug mode, 0 or 1 */
821 public int buffer_frames; /* number of frames in in/out buffers */
822 public int hardware_buffer_frames; /* ibid. hardware */
823 public int displays; /* graph displays, 0 or 1 */
824 public int ascii_graphs; /* use ASCII graphs, 0 or 1 */
825 public int postscript_graphs; /* use postscript graphs, 0 or 1 */
826 public int message_level; /* message printout control */
827 public int tempo; /* tempo (sets Beatmode) */
828 public int ring_bell; /* bell, 0 or 1 */
829 public int use_cscore; /* use cscore for processing */
830 public int terminate_on_midi; /* terminate performance at the end
831 of midifile, 0 or 1 */
832 public int heartbeat; /* print heart beat, 0 or 1 */
833 public int defer_gen01_load; /* defer GEN01 load, 0 or 1 */
834 public int midi_key; /* pfield to map midi key no */
835 public int midi_key_cps; /* pfield to map midi key no as cps */
836 public int midi_key_oct; /* pfield to map midi key no as oct */
837 public int midi_key_pch; /* pfield to map midi key no as pch */
838 public int midi_velocity; /* pfield to map midi velocity */
839 public int midi_velocity_amp; /* pfield to map midi velocity as amplitude */
840 public int no_default_paths; /* disable relative paths from files, 0 or 1 */
841 public int number_of_threads; /* number of threads for multicore performance */
842 public int syntax_check_only; /* do not compile, only check syntax */
843 public int csd_line_counts; /* csd line error reporting */
844 public int compute_weights; /* use calculated opcode weights for
845 multicore, 0 or 1 */
846 public int realtime_mode; /* use realtime priority mode, 0 or 1 */
847 public int sample_accurate; /* use sample-level score event accuracy */
848 public double sample_rate_override; /* overriding sample rate */
849 public double control_rate_override; /* overriding control rate */
850 public int nchnls_override; /* overriding number of out channels */
851 public int nchnls_i_override; /* overriding number of in channels */
852 public double e0dbfs_override; /* overriding 0dbfs */
853 public int daemon; /* daemon mode*/
854 public int ksmps_override; /* ksmps override */
855 public int FFT_library; /* fft_lib */
856 }
857
858
866 public string GetEnv(string key)
867 {
868 return CharPtr2String(Csound6.NativeMethods.csoundGetEnv(csound, key));
869 }
870
879 public int SetGlobalEnv(string name, string value)
880 {
881 return Csound6.NativeMethods.csoundSetGlobalEnv(name, value);
882 }
883
893 internal static String CharPtr2String(IntPtr pString)
894 {
895 return ((pString != null) && (pString != IntPtr.Zero)) ? Marshal.PtrToStringAnsi(pString) : string.Empty;
896 }
897}
SupportedPlatform
Definition: CsoundUnity.cs:254
EnvironmentPathOrigin
The base folder where to set the Environment Variables
Definition: CsoundUnity.cs:260
This structure holds the parameter hints for control channels.
ChannelHints(ChannelBehavior ibehav, MYFLT idflt, MYFLT imin, MYFLT imax)
Creates a channel hint initialized with the most common Control Channel values as provided.
ChannelHints()
Creates an empty hint by calling main constructor with all zeros
ChannelInfo(string _name, ChannelType _type, ChannelDirection _direction)
Defines a class to hold out and in types, and flags
int CompileOrc(string orchStr)
void SetTable(int table, int index, MYFLT value)
Sets the value of a slot in a function table. The table number and index are assumed to be valid.
int GetTable(out MYFLT[] tableValues, int numTable)
Stores values to function table 'tableNum' in tableValues, and returns the table length (not includin...
IDictionary< string, int > GetNamedGens()
Returns a Dictionary keyed by the names of all named table generators. Each name is paired with its i...
uint GetNchnls()
Get number of input channels
void SetSpinSample(int frame, int channel, MYFLT sample)
Set a sample from Csound's audio output buffer
IDictionary< string, IList< OpcodeArgumentTypes > > GetOpcodeList()
Returns a sorted Dictionary keyed by all opcodes which are active in the current instance of csound....
void GetNamedGEN(int num, out string name, int len)
Gets the GEN name from a number num, if this is a named GEN The final parameter is the max len of the...
MYFLT[] GetAudioChannel(string name)
int GetTableArgs(out MYFLT[] args, int index)
Stores the arguments used to generate function table 'tableNum' in args, and returns the number of ar...
void ClearSpin()
Clears the input buffer (spin).
uint GetNchnlsInput()
Get number of input channels
MYFLT GetTable(int table, int index)
Returns the value of a slot in a function table. The table number and index are assumed to be valid.
void SetAudioChannel(string name, MYFLT[] audio)
void TableCopyIn(int table, MYFLT[] source)
Copy the contents of an array source into a given function table The table number is assumed to be va...
void SendScoreEvent(string scoreEvent)
void SetParams(CSOUND_PARAMS parms)
Transfers the contents of the provided raw CSOUND_PARAMS object into csound's internal data structues...
void TableCopyOutAsync(int table, out MYFLT[] dest)
Asynchronous version of tableCopyOut()
void SetStringChannel(string channel, string value)
void AddSpinSample(int frame, int channel, MYFLT sample)
CSOUND_PARAMS GetParams()
Fills in a provided raw CSOUND_PARAMS object with csounds current parameter settings....
string GetEnv(string key)
Gets a string value from csound's environment values. Meaningful values include the contents of Windo...
int LoadPlugins(string dir)
IDictionary< string, ChannelInfo > GetChannelList()
Provides a dictionary of all currently defined channels resulting from compilation of an orchestra co...
MYFLT GetSpoutSample(int frame, int channel)
Get a sample from Csound's audio output buffer
CsoundUnityBridge(string csdFile, List< EnvironmentSettings > environmentSettings)
The CsoundUnityBridge constructor sets up the Csound Global Environment Variables set by the user....
MYFLT GetChannel(string channel)
Get a a control channel
void TableCopyInAsync(int table, MYFLT[] source)
Asynchronous version of csoundTableCopyIn()
int SetGlobalEnv(string name, string value)
Set the global value of environment variable 'name' to 'value', or delete variable if 'value' is NULL...
int IsNamedGEN(int num)
Checks if a given GEN number num is a named GEN if so, it returns the string length (excluding termin...
void CsoundSetScoreOffsetSeconds(MYFLT value)
void TableCopyOut(int table, out MYFLT[] dest)
Copy the contents of a function table into a supplied array dest The table number is assumed to be va...
void SetChannel(string channel, MYFLT value)
int TableLength(int table)
Returns the length of a function table (not including the guard point), or -1 if the table does not e...
MYFLT[] GetSpout()
Returns the Csound audio output working buffer (spout) as a MYFLT array. Enables external software to...
MYFLT[] GetSpin()
Returns the Csound audio input working buffer (spin) as a MYFLT array. Enables external software to w...
static string GetMessageText(IntPtr message)