Inheritance: IDisposable, IMidiPlayerStatus
Example #1
0
        public MidiPlayer(MidiMusic music, IMidiOutput output, IMidiTimeManager timeManager)
        {
            if (music == null)
            {
                throw new ArgumentNullException("music");
            }
            if (output == null)
            {
                throw new ArgumentNullException("output");
            }
            if (timeManager == null)
            {
                throw new ArgumentNullException("timeManager");
            }

            this.output = output;

            player         = new MidiSyncPlayer(music, timeManager);
            EventReceived += (m) => {
                switch (m.EventType)
                {
                case MidiEvent.NoteOn:
                case MidiEvent.NoteOff:
                    if (channel_mask != null && channel_mask [m.Channel])
                    {
                        return;                         // ignore messages for the masked channel.
                    }
                    goto default;

                case MidiEvent.SysEx1:
                case MidiEvent.SysEx2:
                    if (buffer.Length <= m.Data.Length)
                    {
                        buffer = new byte [buffer.Length * 2];
                    }
                    buffer [0] = m.StatusByte;
                    Array.Copy(m.Data, 0, buffer, 1, m.Data.Length);
                    output.Send(buffer, 0, m.Data.Length + 1, 0);
                    break;

                case MidiEvent.Meta:
                    // do nothing.
                    break;

                default:
                    var size = MidiEvent.FixedDataSize(m.StatusByte);
                    buffer [0] = m.StatusByte;
                    buffer [1] = m.Msb;
                    buffer [2] = m.Lsb;
                    output.Send(buffer, 0, size + 1, 0);
                    break;
                }
            };
        }
Example #2
0
        public MidiPlayer(SmfMusic music, IMidiOutput output, IMidiTimeManager timeManager)
        {
            if (music == null)
            {
                throw new ArgumentNullException("music");
            }
            if (output == null)
            {
                throw new ArgumentNullException("output");
            }
            if (timeManager == null)
            {
                throw new ArgumentNullException("timeManager");
            }

            this.output = output;

            player         = new MidiSyncPlayer(music, timeManager);
            EventReceived += (m) => {
                switch (m.EventType)
                {
                case SmfEvent.SysEx1:
                case SmfEvent.SysEx2:
                    if (buffer.Length <= m.Data.Length)
                    {
                        buffer = new byte [buffer.Length * 2];
                    }
                    buffer [0] = m.StatusByte;
                    Array.Copy(m.Data, 0, buffer, 1, m.Data.Length);
                    output.SendAsync(buffer, 0, m.Data.Length + 1, 0);
                    break;

                case SmfEvent.Meta:
                    // do nothing.
                    break;

                default:
                    var size = SmfEvent.FixedDataSize(m.StatusByte);
                    buffer [0] = m.StatusByte;
                    buffer [1] = m.Msb;
                    buffer [2] = m.Lsb;
                    output.SendAsync(buffer, 0, size + 1, 0);
                    break;
                }
            };
        }
Example #3
0
        public MidiPlayer(SmfMusic music, IMidiOutput output, IMidiTimeManager timeManager)
        {
            if (music == null)
                throw new ArgumentNullException ("music");
            if (output == null)
                throw new ArgumentNullException ("output");
            if (timeManager == null)
                throw new ArgumentNullException ("timeManager");

            this.output = output;

            player = new MidiSyncPlayer (music, timeManager);
            EventReceived += (m) => {
                switch (m.EventType) {
                case SmfEvent.SysEx1:
                case SmfEvent.SysEx2:
                    if (buffer.Length <= m.Data.Length)
                        buffer = new byte [buffer.Length * 2];
                    buffer [0] = m.StatusByte;
                    Array.Copy (m.Data, 0, buffer, 1, m.Data.Length);
                    output.SendAsync (buffer, 0, m.Data.Length + 1, 0);
                    break;
                case SmfEvent.Meta:
                    // do nothing.
                    break;
                default:
                    var size = SmfEvent.FixedDataSize (m.StatusByte);
                    buffer [0] = m.StatusByte;
                    buffer [1] = m.Msb;
                    buffer [2] = m.Lsb;
                    output.SendAsync (buffer, 0, size + 1, 0);
                    break;
                }
            };
        }