Exemplo n.º 1
0
        //private void UpdateOfftrackHistory(List<Offtrack> offtracks)
        //{
        //    if (SyncManager.Instance.Status == SyncManager.ConnectionStatus.Connected &&
        //        SyncManager.Instance.User != null)
        //    {
        //         Only host sends offtracks
        //        if (SyncManager.Instance.User.IsHost)
        //        {
        //            SyncManager.Instance.State.SetOfftrackHistory(this.Drivers);

        //             Send to server
        //            SyncManager.Instance.SendStateUpdate(SyncCommandHelper.UpdateOfftracks(offtracks));
        //        }
        //    }
        //}

        #endregion

        #endregion

        #region Events

        private void SdkOnSessionInfoUpdated(object sender, SdkWrapper.SessionInfoUpdatedEventArgs e)
        {
            _sessionInfo = e.SessionInfo;

            try
            {
                if (_mustUpdateSessionData)
                {
                    _sessionData.Update(e.SessionInfo);
                    _timeDelta             = new TimeDelta((float)_sessionData.Track.Length * 1000f, 20, 64);
                    _mustUpdateSessionData = false;

                    this.OnStaticInfoChanged();
                }

                App.Instance.Dispatcher.Invoke(() =>
                {
                    // Handle session info update
                    this.UpdateDriverlist(e.SessionInfo);

                    // Broadcast to windows
                    if (this.SessionInfoUpdated != null)
                    {
                        this.SessionInfoUpdated(sender, e);
                    }
                });
            }
            catch (Exception ex)
            {
                App.Instance.LogError("Updating session info.", ex);
            }
        }
        private static string timeDeltaToSmilString(TimeDelta time)
        {
            TimeSpan val = time.getTimeDeltaAsTimeSpan();

            return(String.Format(
                       "{0:00}:{1:00}:{2:00}.{3:000}",
                       val.Hours, val.Minutes % 60, val.Seconds % 60, val.Milliseconds % 1000));
        }
    protected override void OnClick()
    {
      var mapView = MapView.Active;
      if (mapView == null)
        return;

      var timeDelta = new TimeDelta(TimeModule.Settings.StepValue, (TimeUnit)TimeModule.Settings.StepUnit);
      mapView.Time = mapView.Time.Offset(timeDelta);
    }
Exemplo n.º 4
0
        public void CheckAudioDuration_SimpleMS()
        {
            ExternalAudioMedia audio = factory.Create <ExternalAudioMedia>();

            audio.ClipBegin = new Time(0);
            audio.ClipEnd   = new Time(1000);

            TimeDelta td = (TimeDelta)audio.Duration;

            Assert.AreEqual(1000, td.TimeDeltaAsMillisecondLong);
        }
        protected override void OnClick()
        {
            var mapView = MapView.Active;

            if (mapView == null)
            {
                return;
            }

            var timeDelta = new TimeDelta(TimeModule.Settings.StepValue * -1, (TimeUnit)TimeModule.Settings.StepUnit);

            mapView.Time = mapView.Time.Offset(timeDelta);
        }
Exemplo n.º 6
0
        public void StepMapTime()
        {
            //Get the active view
            MapView mapView = MapView.Active;

            if (mapView == null)
            {
                return;
            }

            //Step current map time forward by 1 month
            TimeDelta timeDelta = new TimeDelta(1, TimeUnit.Months);

            mapView.Time = mapView.Time.Offset(timeDelta);
        }
Exemplo n.º 7
0
        public void SplitVideoObjectCheckNewDuration_SimpleMS()
        {
            ExternalVideoMedia obj = factory.Create <ExternalVideoMedia>();

            obj.ClipBegin = new Time(0);
            obj.ClipEnd   = new Time(1000);

            AbstractVideoMedia new_obj = (AbstractVideoMedia)obj.Split(new Time(600));

            TimeDelta td_1 = obj.Duration;
            TimeDelta td_2 = new_obj.Duration;

            Assert.AreEqual(600, td_1.TimeDeltaAsMillisecondLong);
            Assert.AreEqual(400, td_2.TimeDeltaAsMillisecondLong);
        }
Exemplo n.º 8
0
        public override void Update(ConfigurationSection rootNode, API api)
        {
            Track track = ((SessionsModule)api.FindModule("Sessions")).Track;

            if (track == null)
            {
                return;
            }

            if (TimeDelta == null || track.Length != trackLength)
            {
                TimeDelta   = new TimeDelta(track.Length, deltaDistance, drivers);
                trackLength = track.Length;
            }

            TimeDelta.Update(api.CurrentTime, (float[])api.GetData("CarIdxLapDistPct"));
        }
        public void clear()
        {
            mTreeNodeSmilUris.Clear();
            mSmilFileNames.Clear();
            mTotalElapsedTime = new TimeDelta();
            mSmilWriter       = null;
            mAudioFileNames.Clear();
            mAudioMemoryStream = null;
            mLatestSmilIdNo    = 0;
            mPCMFormat         = null;
            DirectoryInfo di = new DirectoryInfo(getOutputFolder());

            if (!di.Exists)
            {
                di.Create();
            }
            foreach (FileSystemInfo fsi in di.GetFileSystemInfos())
            {
                fsi.Delete();
            }
        }
Exemplo n.º 10
0
    //public static IEnumerator WaitClockReady()
    //{
    //    while(!IsClockReady())
    //    {
    //        yield return 0;
    //    }
    //}
    /**
     * Adds information to this class so it can properly converge on a more precise idea of the actual server time.
     * @param	Time the client sent the request (in ms)
     * @param	Time the client received the response (in ms)
     * @param	Time the server sent the response (in ms)
     */
    private void AddTimeDelta(long clientSendTime, long clientReceiveTime, long serverTime)
    {
        //Debug.Log("AddTimeDelta()");
        //guess the latency
        int latency = (int) (clientReceiveTime - clientSendTime) / 2;

        long clientServerDelta = serverTime - clientReceiveTime;
        long timeSyncDelta = clientServerDelta + latency;
        TimeDelta delta = new TimeDelta(latency, timeSyncDelta);
        deltas.Add(delta);

        if (deltas.Count > maxDeltas)
        {
            deltas.RemoveAt(0);
        }
        Recalculate();
    }
Exemplo n.º 11
0
        private void parseSmil(string fullSmilPath)
        {
            Presentation presentation = m_Project.GetPresentation(0);

            string dirPath = Path.GetDirectoryName(m_Book_FilePath);

            XmlDocument smilXmlDoc = readXmlDocument(fullSmilPath);

            XmlNodeList listOfAudioNodes = smilXmlDoc.GetElementsByTagName("audio");

            if (listOfAudioNodes != null)
            {
                foreach (XmlNode audioNode in listOfAudioNodes)
                {
                    XmlAttributeCollection attributeCol = audioNode.Attributes;

                    if (attributeCol != null)
                    {
                        XmlNode attrAudioSrc = attributeCol.GetNamedItem("src");
                        if (attrAudioSrc != null && !String.IsNullOrEmpty(attrAudioSrc.Value))
                        {
                            XmlNode parent = audioNode.ParentNode;
                            if (parent != null && parent.Name == "a")
                            {
                                parent = parent.ParentNode;
                            }

                            if (parent != null)
                            {
                                XmlNodeList listOfAudioPeers = parent.ChildNodes;
                                foreach (XmlNode peerNode in listOfAudioPeers)
                                {
                                    if (peerNode.NodeType == XmlNodeType.Element && peerNode.Name == "text")
                                    {
                                        XmlAttributeCollection peerAttrs = peerNode.Attributes;

                                        if (peerAttrs != null)
                                        {
                                            XmlNode attrTextSrc = peerAttrs.GetNamedItem("src");
                                            if (attrTextSrc != null && !String.IsNullOrEmpty(attrTextSrc.Value))
                                            {
                                                int index = attrTextSrc.Value.LastIndexOf('#');
                                                if (index < (attrTextSrc.Value.Length - 1))
                                                {
                                                    string        dtbookFragmentId = attrTextSrc.Value.Substring(index + 1);
                                                    core.TreeNode tNode            = getTreeNodeWithXmlElementId(dtbookFragmentId);
                                                    if (tNode != null)
                                                    {
                                                        AbstractAudioMedia existingAudioMedia = tNode.GetAudioMedia();
                                                        if (existingAudioMedia != null)
                                                        {
                                                            //Ignore.
                                                            //System.Diagnostics.Debug.Fail("TreeNode already has media ??");
                                                        }

                                                        XmlNode attrClipBegin = attributeCol.GetNamedItem("clipBegin");
                                                        XmlNode attrClipEnd   = attributeCol.GetNamedItem("clipEnd");

                                                        Media media = null;
                                                        if (attrAudioSrc.Value.EndsWith("wav"))
                                                        {
                                                            string fullWavPath = Path.Combine(dirPath,
                                                                                              attrAudioSrc.Value);

                                                            PCMDataInfo pcmInfo   = null;
                                                            Stream      wavStream = null;
                                                            try
                                                            {
                                                                wavStream = File.Open(fullWavPath, FileMode.Open,
                                                                                      FileAccess.Read, FileShare.Read);
                                                                pcmInfo = PCMDataInfo.ParseRiffWaveHeader(wavStream);
                                                                presentation.MediaDataManager.DefaultPCMFormat = pcmInfo.Copy();
                                                                TimeDelta duration = new TimeDelta(pcmInfo.Duration);

                                                                Time clipB = Time.Zero;
                                                                Time clipE = Time.MaxValue;

                                                                if (attrClipBegin != null &&
                                                                    !string.IsNullOrEmpty(attrClipBegin.Value))
                                                                {
                                                                    clipB = new Time(TimeSpan.Parse(attrClipBegin.Value));
                                                                }
                                                                if (attrClipEnd != null &&
                                                                    !string.IsNullOrEmpty(attrClipEnd.Value))
                                                                {
                                                                    clipE = new Time(TimeSpan.Parse(attrClipEnd.Value));
                                                                }
                                                                if (!clipB.IsEqualTo(Time.Zero) || !clipE.IsEqualTo(Time.MaxValue))
                                                                {
                                                                    duration = clipE.GetTimeDelta(clipB);
                                                                }
                                                                long byteOffset = 0;
                                                                if (!clipB.IsEqualTo(Time.Zero))
                                                                {
                                                                    byteOffset = pcmInfo.GetByteForTime(clipB);
                                                                }
                                                                if (byteOffset > 0)
                                                                {
                                                                    wavStream.Seek(byteOffset, SeekOrigin.Current);
                                                                }

                                                                presentation.MediaDataFactory.DefaultAudioMediaDataType =
                                                                    typeof(WavAudioMediaData);

                                                                WavAudioMediaData mediaData =
                                                                    (WavAudioMediaData)
                                                                    presentation.MediaDataFactory.CreateAudioMediaData();
                                                                mediaData.InsertAudioData(wavStream, Time.Zero, duration);

                                                                media = presentation.MediaFactory.CreateManagedAudioMedia();
                                                                ((ManagedAudioMedia)media).AudioMediaData = mediaData;
                                                            }
                                                            finally
                                                            {
                                                                if (wavStream != null)
                                                                {
                                                                    wavStream.Close();
                                                                }
                                                            }
                                                        }
                                                        else
                                                        {
                                                            media = presentation.MediaFactory.CreateExternalAudioMedia();
                                                            ((ExternalAudioMedia)media).Src = attrAudioSrc.Value;
                                                            if (attrClipBegin != null &&
                                                                !string.IsNullOrEmpty(attrClipBegin.Value))
                                                            {
                                                                ((ExternalAudioMedia)media).ClipBegin =
                                                                    new Time(TimeSpan.Parse(attrClipBegin.Value));
                                                            }
                                                            if (attrClipEnd != null &&
                                                                !string.IsNullOrEmpty(attrClipEnd.Value))
                                                            {
                                                                ((ExternalAudioMedia)media).ClipEnd =
                                                                    new Time(TimeSpan.Parse(attrClipEnd.Value));
                                                            }
                                                        }

                                                        ChannelsProperty chProp = tNode.GetProperty <ChannelsProperty>();
                                                        if (chProp == null)
                                                        {
                                                            chProp =
                                                                presentation.PropertyFactory.CreateChannelsProperty();
                                                            tNode.AddProperty(chProp);
                                                        }
                                                        chProp.SetMedia(m_audioChannel, media);
                                                        break; // scan peers to audio node
                                                    }
                                                    else
                                                    {
                                                        System.Diagnostics.Debug.Fail("XmlProperty with ID not found ??");
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 12
0
 public override void Reset()
 {
     TimeDelta = null;
 }
Exemplo n.º 13
0
 public TimeDeltaModule() : base("TimeDelta")
 {
     TimeDelta   = null;
     trackLength = -1F;
 }
Exemplo n.º 14
0
        //private void UpdateOfftrackHistory(List<Offtrack> offtracks)
        //{
        //    if (SyncManager.Instance.Status == SyncManager.ConnectionStatus.Connected &&
        //        SyncManager.Instance.User != null)
        //    {
        //         Only host sends offtracks
        //        if (SyncManager.Instance.User.IsHost)
        //        {
        //            SyncManager.Instance.State.SetOfftrackHistory(this.Drivers);

        //             Send to server
        //            SyncManager.Instance.SendStateUpdate(SyncCommandHelper.UpdateOfftracks(offtracks));
        //        }
        //    }
        //}

        #endregion

        #endregion

        #region Events

        private void SdkOnSessionInfoUpdated(object sender, SdkWrapper.SessionInfoUpdatedEventArgs e)
        {
            _sessionInfo = e.SessionInfo;
            
            try
            {
                if (_mustUpdateSessionData)
                {
                    _sessionData.Update(e.SessionInfo);
                    _timeDelta = new TimeDelta((float)_sessionData.Track.Length * 1000f, 20, 64);
                    _mustUpdateSessionData = false;

                    this.OnStaticInfoChanged();
                }

                App.Instance.Dispatcher.Invoke(() =>
                {
                    // Handle session info update
                    this.UpdateDriverlist(e.SessionInfo);

                    // Broadcast to windows
                    if (this.SessionInfoUpdated != null)
                    {
                        this.SessionInfoUpdated(sender, e);
                    }

                });
            }
            catch (Exception ex)
            {
                App.Instance.LogError("Updating session info.", ex);
            }
        }
        public bool preVisit(TreeNode node)
        {
            XmlWriter curWr;

            if (getLevelNodeNavigator().isIncluded(node))
            {
                curWr = getNextSmilWriter();
            }
            else
            {
                curWr = getSmilWriter();
            }
            curWr.WriteStartElement("seq", SMIL_NS);
            curWr.WriteAttributeString("id", getNextSmilId());
            properties.channel.ChannelsProperty chProp
                = node.getProperty(typeof(properties.channel.ChannelsProperty)) as properties.channel.ChannelsProperty;
            if (chProp != null)
            {
                media.IMedia audChMedia = chProp.getMedia(getAudioChannel());
                List <media.data.audio.AudioMediaData> audioMediaData = new List <urakawa.media.data.audio.AudioMediaData>();
                if (audChMedia is media.data.ManagedAudioMedia)
                {
                    audioMediaData.Add(((media.data.ManagedAudioMedia)audChMedia).getMediaData());
                }
                else if (audChMedia is media.SequenceMedia)
                {
                    audioMediaData.AddRange(getAudioMediaDataFromSequenceMedia((media.SequenceMedia)audChMedia));
                }
                if (audioMediaData.Count > 0)
                {
                    curWr.WriteStartElement("par", SMIL_NS);
                    if (audioMediaData.Count > 1)
                    {
                        curWr.WriteStartElement("seq", SMIL_NS);
                    }
                    foreach (media.data.audio.AudioMediaData amd in audioMediaData)
                    {
                        TimeDelta clipBegin = getElapsenInCurrentAudio();
                        if (getCurrentPCMFormat() == null)
                        {
                            mPCMFormat = new urakawa.media.data.audio.PCMFormatInfo(amd.getPCMFormat());
                        }
                        else if (!getCurrentPCMFormat().ValueEquals(amd.getPCMFormat()))
                        {
                            throw new exception.InvalidDataFormatException(
                                      "Can not export since the PCM format differs within a single destination file");
                        }
                        copyData(amd.getAudioData(), getAudioStream(), (uint)amd.getPCMLength());
                        TimeDelta clipEnd = getElapsenInCurrentAudio();
                        curWr.WriteStartElement("audio", SMIL_NS);
                        curWr.WriteAttributeString("src", getCurrentAudioFileName());
                        curWr.WriteAttributeString("clipBegin", timeDeltaToSmilString(clipBegin));
                        curWr.WriteAttributeString("clipEnd", timeDeltaToSmilString(clipEnd));
                    }
                    if (audioMediaData.Count > 1)
                    {
                        curWr.WriteEndElement();
                    }
                    curWr.WriteEndElement();
                }
            }
            return(true);
        }
Exemplo n.º 16
0
        public void initialize()
        {
            sdk = new iRacingSDK();
            sdk.Startup();

            // check connection
            if (sdk.IsConnected())
            {
                String yaml = sdk.GetSessionInfo();

                // caridx
                Int32 start = yaml.IndexOf("DriverCarIdx: ") + "DriverCarIdx: ".Length;
                Int32 end = yaml.IndexOf("\n", start);
                carIdx = Int32.Parse(yaml.Substring(start, end - start));

                // carname
                start = yaml.IndexOf("CarIdx: " + carIdx.ToString(), start);
                start = yaml.IndexOf("CarPath: ", start) + "CarPath: ".Length;
                end = yaml.IndexOf("\n", start);
                if (start < 0)
                    carname = "unknown";
                else
                    carname = yaml.Substring(start, end - start);

                // track name
                start = yaml.IndexOf("TrackName: ") + "TrackName: ".Length;
                end = yaml.IndexOf("\n", start);
                if (start < 0)
                    trackname = "unknown";
                else
                    trackname = yaml.Substring(start, end - start);

                // track length
                start = yaml.IndexOf("TrackLength: ") + "TrackLength: ".Length;
                end = yaml.IndexOf("km\n", start);
                String dbg = yaml.Substring(start, end - start);
                trackLength = (Int32)(Single.Parse(yaml.Substring(start, end - start)) * 1000);

                // session types
                RegexOptions options = RegexOptions.IgnoreCase | RegexOptions.Compiled;
                MatchCollection sessionNums, sessionTypes;
                Regex optionRegex = new Regex(@"SessionNum: (\d+)", options);

                // Get matches of pattern in yaml
                sessionNums = optionRegex.Matches(yaml);

                optionRegex = new Regex(@"SessionType: (\w+)", options);
                sessionTypes = optionRegex.Matches(yaml);

                Int32 currentSessionNum = (Int32)sdk.GetData("SessionNum");

                // Iterate matches
                for (Int32 ctr = 0; ctr < Math.Min(sessionNums.Count, sessionTypes.Count); ctr++)
                {
                    if (Int32.Parse(sessionNums[ctr].Value.Substring(12)) == currentSessionNum)
                    {
                        switch (sessionTypes[ctr].Value.Substring(13).Trim())
                        {
                            case "Practice":
                                sessiontype = iRacing.SessionTypes.practice;
                                break;
                            case "Qualify":
                                sessiontype = iRacing.SessionTypes.qualify;
                                break;
                            case "Race":
                                sessiontype = iRacing.SessionTypes.race;
                                break;
                            default:
                                sessiontype = iRacing.SessionTypes.invalid;
                                break;
                        }
                    }
                }

                // reset laptimes
                lapStartTime = (Double)sdk.GetData("ReplaySessionTime");
                lapTimeValid = false;

                // fuel consumption, last 5 lap rolling
                fuelcons = new Single[fuelconslaps];
                fuelconsPtr = 0;

                // init timedelta
                timedelta = new TimeDelta(trackLength);
                timedelta.SaveBestLap(carIdx);
                LoadBestLap();

                init = true;
            }
            else // retry next tick
            {
                init = false;
            }
        }