Esempio n. 1
0
 public static int GetTotalPlayTimeMilliseconds(IList <SmfMessage> messages, int deltaTimeSpec)
 {
     if (deltaTimeSpec < 0)
     {
         throw new NotSupportedException("non-tick based DeltaTime");
     }
     else
     {
         int tempo = SmfMetaType.DefaultTempo;
         int v     = 0;
         foreach (var m in messages)
         {
             v += (int)(tempo / 1000 * m.DeltaTime / deltaTimeSpec);
             if (m.Event.EventType == SmfEvent.Meta && m.Event.Msb == SmfMetaType.Tempo)
             {
                 tempo = SmfMetaType.GetTempo(m.Event.Data);
             }
         }
         return(v);
     }
 }
Esempio n. 2
0
        public virtual void HandleEvent(SmfMessage m)
        {
            if (m.DeltaTime != 0)
            {
                var ms = GetDeltaTimeInMilliseconds(m.DeltaTime);
                time_manager.AdvanceBy(ms);
            }
            if (m.Event.StatusByte == 0xFF)
            {
                if (m.Event.Msb == SmfMetaType.Tempo)
                {
                    current_tempo = SmfMetaType.GetTempo(m.Event.Data);
                }
                else if (m.Event.Msb == SmfMetaType.TimeSignature && m.Event.Data.Length == 4)
                {
                    Array.Copy(m.Event.Data, current_time_signature, 4);
                }
            }

            OnEvent(m.Event);
            PlayDeltaTime += m.DeltaTime;
        }