Esempio n. 1
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            C_MidControl.res = M_MidModel.midiOutGetDevCaps(0, ref formCap, (UInt32)Marshal.SizeOf(formCap));
            C_MidControl.res = M_MidModel.midiOutOpen(ref C_MidControl.ohandle, 0, null, 0, 0);

            var prevTimestamp = -250;

            for (int i = 0; i < noteDict.Count; i++)
            {
                if (!noteDict[i].IsDisposed)
                {
                    byte[] data = new byte[4];
                    data[0] = 0x90;
                    data[1] = noteDict[i].noteLevel;
                    data[2] = 127;

                    uint msg = BitConverter.ToUInt32(data, 0);
                    C_MidControl.res = M_MidModel.midiOutShortMsg(C_MidControl.ohandle, (int)msg);
                    var sleepTimestamp = noteDict[i].noteTimeStamp - prevTimestamp;
                    Thread.Sleep(sleepTimestamp);
                    prevTimestamp = noteDict[i].noteTimeStamp;
                }
            }
            C_MidControl.res = M_MidModel.midiOutClose(C_MidControl.ohandle);
        }
Esempio n. 2
0
        public static void callback(HMIDIIN hMidiIn, M_MidModel.MidiInMessage wMsg, UIntPtr dwInstance, UIntPtr dwParam1, UIntPtr dwParam2)
        {
            if (wMsg.ToString() == "MIM_OPEN")
            {
                // Console.WriteLine("MIDI connection opened successfully");
            }
            else if (wMsg.ToString() == "MIM_DATA")
            {
                byte[] data     = new byte[4];
                int    highword = unchecked ((short)(long)dwParam1);
                int    lowword  = unchecked ((short)((long)dwParam1 >> 16));
                // unchecked : 오버플로 검사 안함

                data[0] = 0x90;
                data[1] = (byte)(highword >> 8);
                data[2] = (byte)(lowword & 0xff);
                uint msg = BitConverter.ToUInt32(data, 0);

                res = M_MidModel.midiOutShortMsg(ohandle, (int)msg);

                UIntPtr timestamp = dwParam2;
                //Console.WriteLine(String.Format("{0} :\n\tNote Index: {1}\n\tNote Velocity: {2}\n\tTimestamp: {3}", wMsg, data[1], data[2], timestamp));
            }
            return;
        }