示例#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);
        }
示例#2
0
        public Form1()
        {
            InitializeComponent();
            IsMdiContainer = true;

            mMid    = new M_MidModel();
            cMid    = new C_MidControl();
            formCap = new MidiOutCaps();

            gridForm           = new PianoRoll();
            gridForm.MdiParent = this;
            //FormBorderStyle = FormBorderStyle.None;
            //WindowState = FormWindowState.Maximized;

            wGraph           = new WaveGraph();
            wGraph.MdiParent = this;

            num_midi_devices = M_MidModel.midiInGetNumDevs();
            if (num_midi_devices == 0)
            {
                //Console.Write("Please connect MIDI device and try again.\nPress any key...");
                //Console.ReadLine();
                //Environment.Exit(1);
            }
            else
            {
                handle      = new HMIDIIN();
                formDevices = new MIDIINCAPS[num_midi_devices];
            }
        }
示例#3
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;
        }
示例#4
0
 private void toolStripButton7_Click(object sender, EventArgs e)
 {
     C_MidControl.res = M_MidModel.midiOutGetDevCaps(0, ref formCap, (UInt32)Marshal.SizeOf(formCap));
     M_MidModel.midiInGetDevCaps(UIntPtr.Zero, out formDevices[0], (UInt32)Marshal.SizeOf(typeof(MIDIINCAPS)));
     device_ID = UIntPtr.Zero;
     M_MidModel.midiInOpen(out handle, device_ID, C_MidControl.callback, (UIntPtr)0);
     M_MidModel.midiInStart(handle);
     C_MidControl.res = M_MidModel.midiOutOpen(ref C_MidControl.ohandle, 0, null, 0, 0);
 }
示例#5
0
        private void toolStripButton5_Click(object sender, EventArgs e)
        {
            num_midi_devices = M_MidModel.midiInGetNumDevs();

            if (num_midi_devices == 0)
            {
                //Console.Write("Please connect MIDI device and try again.\nPress any key...");
                //Console.ReadLine();
                //Environment.Exit(1);
            }
            else
            {
                handle      = new HMIDIIN();
                formDevices = new MIDIINCAPS[num_midi_devices];
            }
        }
示例#6
0
 private void toolStripButton7_Click_1(object sender, EventArgs e)
 {
     M_MidModel.midiInStop(handle);
     M_MidModel.midiInClose(handle);
 }