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 MidiSyncPlayer(MidiMusic music, IMidiTimeManager timeManager)
        {
            if (music == null)
            {
                throw new ArgumentNullException("music");
            }
            time_manager = timeManager;

            this.music = music;
            messages   = SmfTrackMerger.Merge(music).Tracks [0].Messages;
            state      = PlayerState.Stopped;
        }
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;
                }
            };
        }
Example #4
0
 public MidiPlayer(MidiMusic music, IMidiAccess access, IMidiTimeManager timeManager)
     : this(music, access.OpenOutputAsync(access.Outputs.First().Id).Result, timeManager)
 {
     should_dispose_output = true;
 }
Example #5
0
 public MidiPlayer(MidiMusic music, IMidiTimeManager timeManager)
     : this(music, MidiAccessManager.Empty, timeManager)
 {
 }
Example #6
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 #7
0
 public MidiPlayer(SmfMusic music, IMidiAccess access, IMidiTimeManager timeManager)
     : this(music, access.OpenOutputAsync (access.Outputs.First ().Id).Result, timeManager)
 {
     should_dispose_output = true;
 }
Example #8
0
 public MidiPlayer(SmfMusic music, IMidiTimeManager timeManager)
     : this(music, MidiAccessManager.Empty, timeManager)
 {
 }
Example #9
0
        public MidiSyncPlayer(SmfMusic music, IMidiTimeManager timeManager)
        {
            if (music == null)
                throw new ArgumentNullException ("music");
            time_manager = timeManager;

            this.music = music;
            messages = SmfTrackMerger.Merge (music).Tracks [0].Messages;
            state = PlayerState.Stopped;
        }