Esempio n. 1
0
        unsafe public virtual void openOutput(int outputDevice, string outputDriverInfo, int bufferSize, int latency)
        {
            CsPortMidiApi.PortMidiStream stream;

            if (OpenOutput)
            {
                CsPortMidiApi.Pm_Close(output);
            }
            else
            {
                stream = new CsPortMidiApi.PortMidiStream();
                output = &stream;
            }
            if (trace)
            {
                Console.WriteLine("openOutput " + getDeviceName(outputDevice));
            }

            fixed(CsPortMidiApi.PortMidiStream **p = &output)
            {
                checkError(CsPortMidiApi.Pm_OpenOutput(p, outputDevice, outputDriverInfo, bufferSize, latency));
            }

            // if no exception, then increase count of open streams
            openCount++;
        }
Esempio n. 2
0
 unsafe public virtual void abort()
 {
     if (output == null)
     {
         return;                 // no effect if output not open
     }
     checkError(CsPortMidiApi.Pm_Abort(output));
 }
Esempio n. 3
0
 // WARNING: you must not call this if any devices are open
 public virtual void refreshDeviceLists()
 {
     if (openCount > 0)
     {
         throw new CsPortMidiException(pmStreamOpen, "RefreshDeviceLists called while stream is open");
     }
     checkError(CsPortMidiApi.Pm_Terminate());
     checkError(CsPortMidiApi.Pm_Initialize());
 }
Esempio n. 4
0
        protected internal bool trace = false;    // used to print midi msgs for debugging


        public CsPortMidi()
        {
            if (pmRefCount == 0)
            {
                pm = new CsPortMidiApi();
                pmRefCount++;
                checkError(CsPortMidiApi.Pm_Initialize());
            }
            buffer = new CsPortMidiApi.PmEvent();
        }
Esempio n. 5
0
 unsafe public virtual void closeOutput()
 {
     if (output == null)
     {
         return;                 // no effect if output not open
     }
     checkError(CsPortMidiApi.Pm_Close(output));
     output = null;
     openCount--;
 }
Esempio n. 6
0
 unsafe public virtual void writeShort(int @when, int msg)
 {
     if (output == null)
     {
         throw new CsPortMidiException(pmOutputNotOpen, "Output stream not open");
     }
     if (trace)
     {
         Console.WriteLine("writeShort: 0x" + msg.ToString("X8"));
     }
     checkError(CsPortMidiApi.Pm_WriteShort(output, @when, msg));
 }
Esempio n. 7
0
        unsafe public virtual bool getDeviceOutput(int i)
        {
            bool result;

            CsPortMidiApi.PmDeviceInfo *dev = (CsPortMidiApi.PmDeviceInfo *)CsPortMidiApi.Pm_GetDeviceInfo(i);
            if (dev == null)
            {
                result = false;
            }
            else
            {
                result = dev->output == 1 ? true : false;
            }
            return(result);
        }
Esempio n. 8
0
 unsafe public virtual void writeSysEx(int @when, sbyte[] msg)
 {
     if (output == null)
     {
         throw new CsPortMidiException(pmOutputNotOpen, "Output stream not open");
     }
     if (trace)
     {
         Console.Write("writeSysEx: ");
         for (int i = 0; i < msg.Length; i++)
         {
             Console.Write(msg[i].ToString("x"));
         }
         Console.Write("\n");
     }
     checkError(CsPortMidiApi.Pm_WriteSysEx(output, @when, msg));
 }
Esempio n. 9
0
 // Poll should be called by client to process input messages (if any)
 unsafe public virtual void poll()
 {
     if (input == null)
     {
         return;                 // does nothing until input is opened
     }
     while (true)
     {
         int rslt = CsPortMidiApi.Pm_Read(input, buffer);
         checkError(rslt);
         if (rslt == 0)
         {
             return;                     // no more messages
         }
         handleMidiIn(buffer);
     }
 }
Esempio n. 10
0
 internal virtual int checkError(int err)
 {
     // note that Pm_Read and Pm_Write return positive result values
     // which are not errors, so compare with >=
     if (err >= pm.pmNoError)
     {
         return(err);
     }
     if (err == pm.pmHostError)
     {
         throw new CsPortMidiException(err, CsPortMidiApi.Pm_GetHostErrorText());
     }
     else
     {
         throw new CsPortMidiException(err, CsPortMidiApi.Pm_GetErrorText(err));
     }
 }
Esempio n. 11
0
        unsafe public virtual string getDeviceName(int i)
        {
            string strName;

            CsPortMidiApi.PmDeviceInfo *dev = (CsPortMidiApi.PmDeviceInfo *)CsPortMidiApi.Pm_GetDeviceInfo(i);
            IntPtr pU = dev->name;

            if (pU == IntPtr.Zero)
            {
                strName = null;
            }
            else
            {
                strName = Marshal.PtrToStringAnsi(pU);
            }
            return(strName);
        }
Esempio n. 12
0
        // ******* QUERY DEVICE INFORMATION *********

        public virtual int countDevices()
        {
            return(checkError(CsPortMidiApi.Pm_CountDevices()));
        }
Esempio n. 13
0
 public virtual bool timeStarted()
 {
     return(CsPortMidiApi.Pt_TimeStarted());
 }
Esempio n. 14
0
 public virtual int timeGet()
 {
     return(CsPortMidiApi.Pt_Time());
 }
Esempio n. 15
0
 public virtual void timeStop()
 {
     checkError(CsPortMidiApi.Pt_TimeStop());
 }
Esempio n. 16
0
        // ******** ACCESS TO TIME ***********

        public virtual void timeStart(int resolution)
        {
            checkError(CsPortMidiApi.Pt_TimeStart(resolution));
        }