Exemple #1
0
        private void BarAdded(Core.Model.Bar bar)
        {
            var track = TrackHeaders.GetChildren <UI.Track>().SingleOrDefault(t => t.Model == bar.Track);

            var row    = Grid.GetRow(track);
            var column = bar.Track.Bars.IndexOf(bar);

            while (BarGrid.ColumnDefinitions.Count <= column)
            {
                BarGrid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(Constants.BarWidth)
                });
            }

            var ui = new UI.Bar(bar, track);

            ui.Selected += (s, b) =>
            {
                SelectedBar?.Deselect();
                SelectedBar = ui;
            };
            bar.Updated += (s, fullUpdate) =>
            {
                ui.FullUpdate = fullUpdate;
                UpdateBars.Enqueue(ui);
            };
            Grid.SetRow(ui, row);
            Grid.SetColumn(ui, column);

            BarGrid.Children.Add(ui);

            AddLog("Bar added");
        }
Exemple #2
0
        /// <summary>
        /// OnReceive is our Callback that gets called by the .NET socket class when new data arrives on the socket
        /// </summary>
        /// <param name="asyn"></param>
        private void OnReceive(IAsyncResult asyn)
        {
            // first verify we received data from the correct socket.  This check isn't really necessary in this example since we
            // only have a single socket but if we had multiple sockets, we could use this check to use the same callback to recieve data from
            // multiple sockets
            if (asyn.AsyncState.ToString().Equals("Derivative"))
            {
                // read data from the socket.
                int iReceivedBytes = 0;
                iReceivedBytes = m_sockDerivative.EndReceive(asyn);
                // set our flag back to true so we can call begin receive again
                m_bDerivativeNeedBeginReceive = true;
                // in this example, we will convert to a string for ease of use.
                string sData = Encoding.ASCII.GetString(m_szDerivativeSocketBuffer, 0, iReceivedBytes);

                // When data is read from the socket, you can get multiple messages at a time and there is no guarantee
                // that the last message you receive will be complete.  It is possible that only half a message will be read
                // this time and you will receive the 2nd half of the message at the next call to OnReceive.
                // As a result, we need to save off any incomplete messages while processing the data and add them to the beginning
                // of the data next time.
                sData = m_sDerivativeIncompleteRecord + sData;
                // clear our incomplete record string so it doesn't get processed next time too.
                m_sDerivativeIncompleteRecord = "";

                // now we loop through the data breaking it appart into messages.  Each message on this port is terminated
                // with a newline character ("\n")
                string sLine       = "";
                int    iNewLinePos = -1;
                while (sData.Length > 0)
                {
                    iNewLinePos = sData.IndexOf("\n");
                    if (iNewLinePos > 0)
                    {
                        sLine = sData.Substring(0, iNewLinePos);
                        //UpdateListview(sLine);
                        dout(sLine.Trim());
                        // move on to the next message.  This isn't very efficient but it is simple (which is the focus of this example).
                        sData = sData.Substring(sLine.Length + 1);
                        if (sLine.StartsWith(string.Format("{0},BH,", this.RequestID)) || sLine.StartsWith(string.Format("{0},BC,", this.RequestID)))
                        {
                            UpdateBars?.Invoke(new BarUpdateIQ(sLine));
                        }
                    }
                    else
                    {
                        // we get here when there are no more newline characters in the data.
                        // save off the rest of message for processing the next batch of data.
                        m_sDerivativeIncompleteRecord = sData;
                        sData = "";
                    }
                }

                // call wait for data to notify the socket that we are ready to receive another callback
                WaitForData("Derivative");
            }
        }
Exemple #3
0
        public MainPage()
        {
            this.InitializeComponent();

            SetStatus("Initialising ...");

            App.Current.UnhandledException += (s, e) => AddLog(e.Message);

            Background            = Constants.ApplicationBackgroundBrush;
            StatusBar.Background  = Constants.StatusBarBackgroundBrush;
            StatusBar.BorderBrush = Constants.StatusBarBorderBrush;
            ConsoleRow.Height     = new GridLength(0);

            InitialiseKeyboardAccelerators();
            CreateSong();

            Timer          = new System.Timers.Timer(100);
            Timer.Elapsed += (s, e) =>
            {
                while (UpdateBars.Any())
                {
                    UpdateBars.TryDequeue(out UI.Bar bar);
                    UI.Utilities.CallUI(() => bar?.Update());
                }

                if (UpdatePosition)
                {
                    UI.Utilities.CallUI(() => Position.Text = Song.GetTime().ToTimeString());
                    UpdatePosition = false;
                }
            };
            Timer.Start();

            Audio        = new UwpAudio();
            Audio.Ready += (s, e) => OnAudioReady();
        }