Exemplo n.º 1
0
 public ChannelHintsProxy(ChannelHints hints)
 {
     behav      = (int)hints.behav;
     dflt       = hints.dflt; min = hints.min; max = hints.max;
     x          = hints.x; y = hints.y; height = hints.height; width = hints.width;
     attributes = IntPtr.Zero;
 }
Exemplo n.º 2
0
    /// <summary>
    /// Legacy channel access method.  Should be avoided in favor of csound 6's new thread-safe
    /// access methods as used in subclasses.
    /// Used internally by Get/SetValueDirect methods in subclasses ideally called from
    /// within the same thread between calls to PerformKsmps or PerformBuffer.
    /// If used between different threads (not recommended - use threadsafe property "Value" instead),
    /// you should acquire and use a lock (see GetLock method) to arbitrate potential race conditions.
    /// </summary>
    /// <returns>a pointer to unmanaged memory where the channel's data begins</returns>
    //internal IntPtr GetChannelPointer()
    //{

    //        int flags = (sizeof(int)) + (int)(((uint)Direction) << 4);
    //        CsoundStatus result = Csound6Net.Int2StatusEnum(NativeMethods.csoundGetChannelPtr(csound, out m_pChannel, Name, flags));
    //        if (((int)result) < 0) throw new Csound6NetException(Csound6NetException.ChannelAccessFailed, Name, result);
    //    }

    //    return m_pChannel;
    //}

    /// <summary>
    /// Provides a dictionary of all currently defined channels resulting from compilation of an orchestra
    /// containing channel definitions.
    /// Entries, keyed by name, are polymorphically assigned to their correct data type: control, audio, string, pvc.
    /// Used by the Csound6SoftwareBus class to initialize its contents.
    /// </summary>
    /// <returns>a dictionary of all currently defined channels keyed by their name to its ChannelInfo</returns>
    public IDictionary <string, ChannelInfo> GetChannelList()
    {
        IDictionary <string, ChannelInfo> channels = new SortedDictionary <string, ChannelInfo>();
        IntPtr ppChannels = IntPtr.Zero;
        int    size       = Csound6.NativeMethods.csoundListChannels(csound, out ppChannels);

        if ((ppChannels != IntPtr.Zero) && (size >= 0))
        {
            int proxySize = Marshal.SizeOf(typeof(ChannelInfoProxy));
            for (int i = 0; i < size; i++)
            {
                var         proxy     = Marshal.PtrToStructure(ppChannels + (i * proxySize), typeof(ChannelInfoProxy)) as ChannelInfoProxy;
                string      chanName  = Marshal.PtrToStringAnsi(proxy.name);
                ChannelInfo info      = new ChannelInfo(chanName, (ChannelType)(proxy.type & 15), (ChannelDirection)(proxy.type >> 4));
                var         hintProxy = proxy.hints;
                var         hints     = new ChannelHints((ChannelBehavior)hintProxy.behav, hintProxy.dflt, hintProxy.min, hintProxy.max)
                {
                    x          = hintProxy.x,
                    y          = hintProxy.y,
                    height     = hintProxy.height,
                    width      = hintProxy.width,
                    attributes = (hintProxy.attributes != IntPtr.Zero) ? Marshal.PtrToStringAnsi(hintProxy.attributes) : null
                };
                info.Hints = hints;
                channels.Add(chanName, info);
            }
            Csound6.NativeMethods.csoundDeleteChannelList(csound, ppChannels);
        }

        return(channels);
    }