Esempio n. 1
0
 public int GetTimePositionInMillisecondsForTick(int ticks)
 {
     if (Format != 0)
     {
         return(SmfTrackMerger.Merge(this).GetTimePositionInMillisecondsForTick(ticks));
     }
     return(GetPlayTimeMillisecondsAtTick(Tracks [0].Messages, ticks, DeltaTimeSpec));
 }
Esempio n. 2
0
 public int GetTotalPlayTimeMilliseconds()
 {
     if (Format != 0)
     {
         return(SmfTrackMerger.Merge(this).GetTotalPlayTimeMilliseconds());
     }
     return(GetTotalPlayTimeMilliseconds(Tracks [0].Messages, DeltaTimeSpec));
 }
Esempio n. 3
0
 public int GetTotalTicks()
 {
     if (Format != 0)
     {
         return(SmfTrackMerger.Merge(this).GetTotalTicks());
     }
     return(Tracks [0].Messages.Sum(m => m.DeltaTime));
 }
Esempio n. 4
0
 public IEnumerable <MidiMessage> GetMetaEventsOfType(byte metaType)
 {
     if (Format != 0)
     {
         return(SmfTrackMerger.Merge(this).GetMetaEventsOfType(metaType));
     }
     return(GetMetaEventsOfType(tracks [0].Messages, metaType));
 }
Esempio n. 5
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;
        }
Esempio n. 6
0
        public MidiPlayer(MidiMusic music, IMidiOutput output, IMidiPlayerTimeManager timeManager)
        {
            if (music == null)
            {
                throw new ArgumentNullException("music");
            }
            if (output == null)
            {
                throw new ArgumentNullException("output");
            }
            if (timeManager == null)
            {
                throw new ArgumentNullException("timeManager");
            }

            this.music  = music;
            this.output = output;

            messages         = SmfTrackMerger.Merge(music).Tracks [0].Messages;
            player           = new MidiEventLooper(messages, timeManager, music.DeltaTimeSpec);
            player.Starting += () => {
                // all control reset on all channels.
                for (int i = 0; i < 16; i++)
                {
                    buffer [0] = (byte)(i + 0xB0);
                    buffer [1] = 0x79;
                    buffer [2] = 0;
                    output.Send(buffer, 0, 3, 0);
                }
            };
            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;
                }
            };
        }