예제 #1
0
 public override void OnUpdate()
 {
     if (CurrentSample != null)
     {
         CurrentSample.OnUpdate();
     }
 }
예제 #2
0
        private async void DocumentationTextblock_ImageResolving(object sender, ImageResolvingEventArgs e)
        {
            var         deferral = e.GetDeferral();
            BitmapImage image    = null;

            // Determine if the link is not absolute, meaning it is relative.
            if (!Uri.TryCreate(e.Url, UriKind.Absolute, out Uri url))
            {
                url = new Uri(documentationPath + e.Url);
            }

            if (url.Scheme == "ms-appx")
            {
                image = new BitmapImage(url);
            }
            else
            {
                var imageStream = await CurrentSample.GetImageStream(url);

                if (imageStream != null)
                {
                    image = new BitmapImage();
                    await image.SetSourceAsync(imageStream);
                }
            }

            // Handle only if no exceptions occur.
            if (image != null)
            {
                e.Image   = image;
                e.Handled = true;
            }

            deferral.Complete();
        }
예제 #3
0
 public void EndRender()
 {
     if (CurrentSample != null)
     {
         CurrentSample.OnExit();
         CurrentSample = null;
     }
 }
        private async void InfoAreaPivot_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (InfoAreaPivot.SelectedItem != null)
            {
                if (DataContext is Sample sample)
                {
                    TrackingManager.TrackEvent("PropertyGrid", (InfoAreaPivot.SelectedItem as FrameworkElement)?.Name, sample.Name);
                }
            }

            if (CurrentSample == null)
            {
                return;
            }

            if (InfoAreaPivot.SelectedItem == PropertiesPivotItem)
            {
                // If we switch to the Properties Panel, we want to use a binded version of the Xaml Code.
                if (CurrentSample.HasXAMLCode)
                {
                    _lastRenderedProperties = true;

                    UpdateXamlRender(CurrentSample.BindedXamlCode);
                }

                return;
            }

            if (CurrentSample.HasXAMLCode && InfoAreaPivot.SelectedItem == XamlPivotItem && _lastRenderedProperties)
            {
                // Use this flag so we don't re-render the XAML tab if we're switching from tabs other than the properties one.
                _lastRenderedProperties = false;

                // If we switch to the Live Preview, then we want to use the Value based Text
                XamlCodeEditor.Text = CurrentSample.UpdatedXamlCode;

                UpdateXamlRender(CurrentSample.UpdatedXamlCode);
                await XamlCodeEditor.ResetPosition();

                XamlCodeEditor.Focus(FocusState.Programmatic);
                return;
            }

            if (CurrentSample.HasXAMLCode && InfoAreaPivot.SelectedItem == XamlReadOnlyPivotItem)
            {
                // Update Read-Only XAML tab on non-desktop devices to show changes to Properties
                XamlReadOnlyCodeRenderer.SetCode(CurrentSample.UpdatedXamlCode, "xaml");
            }

            if (CurrentSample.HasCSharpCode && InfoAreaPivot.SelectedItem == CSharpPivotItem)
            {
                var code = await CurrentSample.GetCSharpSourceAsync();

                CSharpCodeRenderer.SetCode(code, "c#");

                return;
            }
        }
예제 #5
0
        private void DoRead()
        {
            while (!stopped)
            {
                double value = ReadData();

                sampleCounter++;

                CurrentSample.Enqueue(value);
            }
        }
예제 #6
0
        public void BeginRenderSample(string sampleName)
        {
            if (AllSamples == null || !AllSamples.ContainsKey(sampleName))
            {
                return;
            }

            if (CurrentSample != null)
            {
                CurrentSample.OnExit();
            }

            CurrentSample = Activator.CreateInstance(AllSamples[sampleName]) as Sample;
            CurrentSample.OnInit();
        }
예제 #7
0
        private void BindSample()
        {
            List <double> loopLengths;

            if (CurrentSample == null)
            {
                txtSampleStartPosition.Seconds = 0;
                loopLengths             = BpmHelper.GetLoopLengths(Track.Bpm);
                cmbSampleLength.Seconds = 0;
                chkLoopSample.Checked   = false;
            }
            else
            {
                txtSampleStartPosition.Seconds = CurrentSample.Start;
                loopLengths             = BpmHelper.GetLoopLengths(CurrentSample.CalculateBpm(Track));
                cmbSampleLength.Seconds = CurrentSample.Length;
                chkLoopSample.Checked   = CurrentSample.IsLooped;
            }
            cmbSampleLength.PopulateItemsFromSecondsList(loopLengths);
        }
예제 #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="s"></param>
        public override void RunSample(Sample s)
        {
            if (CurrentSample != null) //
            {
                CurrentSample.Shutdown();
                CurrentSample  = null;
                IsSamplePaused = false; // don't pause next sample
                                        // create dummy scene and modify controls
                CreateDummyScene();
                this.TrayManager.ShowBackdrop("SdkTrays/Bands");
                this.TrayManager.ShowAll();
                ((Button)this.TrayManager.GetWidget("StartStop")).Caption = "Start Sample";
            }
            if (s != null) // sample starting
            {
                ((Button)this.TrayManager.GetWidget("StartStop")).Caption = "Stop Sample";
                this.TrayManager.ShowBackdrop("SdkTrays/Shade");
                this.TrayManager.HideAll();
                DestroyDummyScene();

                try
                {
                    base.RunSample(s);
                }
                catch (Exception ex) // if failed to start, show error and fall back to menu
                {
                    s.Shutdown();
                    CreateDummyScene();
                    this.TrayManager.ShowBackdrop("SdkTrays/Bands");
                    this.TrayManager.ShowAll();
                    ((Button)this.TrayManager.GetWidget("StartStop")).Caption = "Start Sample";

                    this.TrayManager.ShowOkDialog("Error!", ex.ToString() + "\nSource " + ToString());
                }
            }
        }
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            if (e.Parameter is Sample sample)
            {
                CurrentSample = sample;
            }

            if (CurrentSample != null)
            {
                // UNO TODO
                // The controls may be loaded when set directly to their parent
                // so the datacontext of the renderer needs to be set early.
                await SetSampleDataContext();

                if (CurrentSample.HasType)
                {
                    try
                    {
                        SamplePage            = Activator.CreateInstance(CurrentSample.PageType) as Page;
                        SampleContent.Content = SamplePage;

                        // Some samples use the OnNavigatedTo and OnNavigatedFrom
                        // Can't use Frame here because some samples depend on the current Frame
                        MethodInfo method = CurrentSample.PageType.GetMethod(
                            "OnNavigatedTo",
                            BindingFlags.Instance | BindingFlags.NonPublic);

                        if (method != null)
                        {
                            method.Invoke(SamplePage, new object[] { e });
                        }
                    }
                    catch (Exception ex)
                    {
                        ExceptionNotification.Show("Sample Page failed to load: " + ex.Message);
                    }

                    if (SamplePage != null)
                    {
                        SamplePage.Loaded += SamplePage_Loaded;

                        // UNO TODO
                        if (SamplePage.IsLoaded)
                        {
                            SamplePage_Loaded(SamplePage, new RoutedEventArgs());
                        }
                    }
                }
                else if (!CurrentSample.HasXAMLCode)
                {
                    _onlyDocumentation = true;
                }

                async Task SetSampleDataContext()
                {
                    InfoAreaPivot.Items.Clear();

                    // Load Sample Properties before we load sample (if we haven't before)
                    await CurrentSample.PreparePropertyDescriptorAsync();

                    // We only have properties on examples with live XAML
                    var propertyDesc = CurrentSample.PropertyDescriptor;

                    DataContext = CurrentSample;

                    if (propertyDesc != null)
                    {
                        _xamlRenderer.DataContext = propertyDesc.Expando;
                    }

                    if (propertyDesc?.Options.Count > 0)
                    {
                        InfoAreaPivot.Items.Add(PropertiesPivotItem);
                    }

                    // Uno todo (Adding a pivot item does not refresh SelectedItem)
                    UpdateXamlRender(CurrentSample.BindedXamlCode);
                }

                if (CurrentSample.HasXAMLCode)
                {
#if !HAS_UNO
                    if (AnalyticsInfo.VersionInfo.GetDeviceFormFactor() != DeviceFormFactor.Desktop || CurrentSample.DisableXamlEditorRendering)
#endif
                    {
                        // Only makes sense (and works) for now to show Live Xaml on Desktop, so fallback to old system here otherwise.
                        XamlReadOnlyCodeRenderer.SetCode(CurrentSample.UpdatedXamlCode, "xaml");

                        InfoAreaPivot.Items.Add(XamlReadOnlyPivotItem);
                    }
#if !HAS_UNO
                    else
                    {
                        XamlCodeEditor.Text = CurrentSample.UpdatedXamlCode;

                        InfoAreaPivot.Items.Add(XamlPivotItem);

                        _xamlCodeRendererSupported = true;
                    }
#endif

                    InfoAreaPivot.SelectedIndex = 0;
                }

                if (CurrentSample.HasCSharpCode)
                {
                    var code = await CurrentSample.GetCSharpSourceAsync();

                    CSharpCodeRenderer.SetCode(code, "c#");
                    InfoAreaPivot.Items.Add(CSharpPivotItem);
                }

                if (CurrentSample.HasDocumentation)
                {
                    var contents = await CurrentSample.GetDocumentationAsync();

                    if (!string.IsNullOrWhiteSpace(contents))
                    {
                        DocumentationTextBlock.Text = contents;
                        InfoAreaPivot.Items.Add(DocumentationPivotItem);
                    }
                }

                // Hide the GitHub button if there isn't a CodeUrl.
                if (string.IsNullOrEmpty(CurrentSample.CodeUrl))
                {
                    GithubButton.Visibility = Visibility.Collapsed;
                }
                else
                {
                    GithubButton.Visibility = Visibility.Visible;
                }

                if (InfoAreaPivot.Items.Count == 0)
                {
                    SidePaneState = PaneState.None;
                }
                else
                {
                    SidePaneState = _onlyDocumentation ? PaneState.Full : PaneState.Normal;
                }

                Shell.Current.SetAppTitle($"{CurrentSample.CategoryName} > {CurrentSample.Name}");
            }
            else
            {
                ExceptionNotification.Show("Sample does not exist");
            }

            if (!CanChangePaneState)
            {
                SampleTitleBar.Children.Remove(NarrowInfoButton);
            }

            if (e.NavigationMode != NavigationMode.Back)
            {
                var nop = Samples.PushRecentSample(CurrentSample);
            }
        }
예제 #10
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            if (e.Parameter is Sample sample)
            {
                CurrentSample = sample;
            }

            if (CurrentSample != null)
            {
                if (!string.IsNullOrWhiteSpace(CurrentSample.Type))
                {
                    try
                    {
                        var pageInstance = Activator.CreateInstance(CurrentSample.PageType);
                        SampleContent.Content = pageInstance;
                    }
                    catch
                    {
                        ExceptionNotification.Show("Sample Page failed to load.");
                    }

                    if (SamplePage != null)
                    {
                        SamplePage.Loaded += SamplePage_Loaded;
                    }
                }
                else
                {
                    _onlyDocumentation = true;
                }

                DataContext = CurrentSample;

                await Samples.PushRecentSample(CurrentSample);

                var propertyDesc = CurrentSample.PropertyDescriptor;

                InfoAreaPivot.Items.Clear();

                if (propertyDesc != null)
                {
                    _xamlRenderer.DataContext = propertyDesc.Expando;
                }

                if (propertyDesc != null && propertyDesc.Options.Count > 0)
                {
                    InfoAreaPivot.Items.Add(PropertiesPivotItem);
                }

                if (CurrentSample.HasXAMLCode)
                {
                    if (AnalyticsInfo.VersionInfo.GetDeviceFormFactor() != DeviceFormFactor.Desktop || CurrentSample.DisableXamlEditorRendering)
                    {
                        // Only makes sense (and works) for now to show Live Xaml on Desktop, so fallback to old system here otherwise.
                        XamlReadOnlyCodeRenderer.SetCode(CurrentSample.UpdatedXamlCode, "xaml");

                        InfoAreaPivot.Items.Add(XamlReadOnlyPivotItem);
                    }
                    else
                    {
                        XamlCodeEditor.Text = CurrentSample.UpdatedXamlCode;

                        InfoAreaPivot.Items.Add(XamlPivotItem);

                        _xamlCodeRendererSupported = true;
                    }

                    InfoAreaPivot.SelectedIndex = 0;
                }

                if (CurrentSample.HasCSharpCode)
                {
                    var code = await CurrentSample.GetCSharpSourceAsync();

                    CSharpCodeRenderer.SetCode(code, "c#");
                    InfoAreaPivot.Items.Add(CSharpPivotItem);
                }

                if (CurrentSample.HasJavaScriptCode)
                {
                    var code = await CurrentSample.GetJavaScriptSourceAsync();

                    JavaScriptCodeRenderer.SetCode(code, "js");
                    InfoAreaPivot.Items.Add(JavaScriptPivotItem);
                }

                if (CurrentSample.HasDocumentation)
                {
#pragma warning disable SA1008 // Opening parenthesis must be spaced correctly
                    var(contents, path) = await CurrentSample.GetDocumentationAsync();

#pragma warning restore SA1008 // Opening parenthesis must be spaced correctly
                    documentationPath = path;
                    if (!string.IsNullOrWhiteSpace(contents))
                    {
                        DocumentationTextblock.Text = contents;
                        InfoAreaPivot.Items.Add(DocumentationPivotItem);
                    }
                }

                // Hide the Github button if there isn't a CodeUrl.
                if (string.IsNullOrEmpty(CurrentSample.CodeUrl))
                {
                    GithubButton.Visibility = Visibility.Collapsed;
                }

                if (InfoAreaPivot.Items.Count == 0)
                {
                    SidePaneState     = PaneState.None;
                    _hasDocumentation = false;
                }
                else
                {
                    SidePaneState = _onlyDocumentation ? PaneState.Full : PaneState.Normal;
                }

                Shell.Current.SetAppTitle($"{CurrentSample.CategoryName} > {CurrentSample.Name}");
            }
            else
            {
                ExceptionNotification.Show("Sample does not exist");
            }

            if (!CanChangePaneState)
            {
                SampleTitleBar.Children.Remove(NarrowInfoButton);
                PaneStates.States.Clear();
                WindowStates.States.Clear();
            }
        }
예제 #11
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            if (e.Parameter is Sample sample)
            {
                CurrentSample = sample;
            }

            if (CurrentSample != null)
            {
                if (!string.IsNullOrWhiteSpace(CurrentSample.Type))
                {
                    try
                    {
                        var pageInstance = Activator.CreateInstance(CurrentSample.PageType);
                        SampleContent.Content = pageInstance;

                        // Some samples use the OnNavigatedTo and OnNavigatedFrom
                        // Can't use Frame here because some samples depend on the current Frame
                        MethodInfo method = CurrentSample.PageType.GetMethod(
                            "OnNavigatedTo",
                            BindingFlags.Instance | BindingFlags.NonPublic);

                        if (method != null)
                        {
                            method.Invoke(pageInstance, new object[] { e });
                        }
                    }
                    catch
                    {
                        ExceptionNotification.Show("Sample Page failed to load.");
                    }

                    if (SamplePage != null)
                    {
                        SamplePage.Loaded += SamplePage_Loaded;
                    }
                }
                else
                {
                    _onlyDocumentation = true;
                }

                InfoAreaPivot.Items.Clear();

                if (CurrentSample.HasXAMLCode)
                {
                    // Load Sample Properties before we load sample (if we haven't before)
                    await CurrentSample.PreparePropertyDescriptorAsync();

                    // We only have properties on examples with live XAML
                    var propertyDesc = CurrentSample.PropertyDescriptor;

                    if (propertyDesc != null)
                    {
                        _xamlRenderer.DataContext = propertyDesc.Expando;
                    }

                    if (propertyDesc?.Options.Count > 0)
                    {
                        InfoAreaPivot.Items.Add(PropertiesPivotItem);
                    }

                    if (AnalyticsInfo.VersionInfo.GetDeviceFormFactor() != DeviceFormFactor.Desktop || CurrentSample.DisableXamlEditorRendering)
                    {
                        // Only makes sense (and works) for now to show Live Xaml on Desktop, so fallback to old system here otherwise.
                        XamlReadOnlyCodeRenderer.SetCode(CurrentSample.UpdatedXamlCode, "xaml");

                        InfoAreaPivot.Items.Add(XamlReadOnlyPivotItem);
                    }
                    else
                    {
                        XamlCodeEditor.Text = CurrentSample.UpdatedXamlCode;

                        InfoAreaPivot.Items.Add(XamlPivotItem);

                        _xamlCodeRendererSupported = true;
                    }

                    InfoAreaPivot.SelectedIndex = 0;
                }

                if (CurrentSample.HasCSharpCode)
                {
                    var code = await CurrentSample.GetCSharpSourceAsync();

                    CSharpCodeRenderer.SetCode(code, "c#");
                    InfoAreaPivot.Items.Add(CSharpPivotItem);
                }

                if (CurrentSample.HasDocumentation)
                {
#pragma warning disable SA1008 // Opening parenthesis must be spaced correctly
                    var(contents, path) = await CurrentSample.GetDocumentationAsync();

#pragma warning restore SA1008 // Opening parenthesis must be spaced correctly
                    documentationPath = path;
                    if (!string.IsNullOrWhiteSpace(contents))
                    {
                        DocumentationTextBlock.Text = contents;
                        InfoAreaPivot.Items.Add(DocumentationPivotItem);
                    }
                }

                // Hide the GitHub button if there isn't a CodeUrl.
                if (string.IsNullOrEmpty(CurrentSample.CodeUrl))
                {
                    GithubButton.Visibility = Visibility.Collapsed;
                }
                else
                {
                    GithubButton.Visibility = Visibility.Visible;
                }

                DataContext = CurrentSample;

                if (InfoAreaPivot.Items.Count == 0)
                {
                    SidePaneState = PaneState.None;
                }
                else
                {
                    SidePaneState = _onlyDocumentation ? PaneState.Full : PaneState.Normal;
                }

                Shell.Current.SetAppTitle($"{CurrentSample.CategoryName} > {CurrentSample.Name}");
            }
            else
            {
                ExceptionNotification.Show("Sample does not exist");
            }

            if (!CanChangePaneState)
            {
                SampleTitleBar.Children.Remove(NarrowInfoButton);
            }

            if (e.NavigationMode != NavigationMode.Back)
            {
                var nop = Samples.PushRecentSample(CurrentSample);
            }
        }
예제 #12
0
 private void StopPlayback()
 {
     CurrentSample.StopPlayback();
 }
        private bool UpdateData()
        {
            if (wfMode == WaveForm.Wav)
            {
                const uint ActualSampleRate = BAUDRATE / 10;
                WaveReader wr;
                try
                {
                    wr = new WaveReader(WavFile);
                }
                catch
                {
                    return(false);
                }
                if (!wr.IsWave)
                {
                    return(false);
                }

                int    TotalFrame      = wr.GetTotalFrame();
                uint   FileSampleRate  = wr.GetInfo().SampleRate;
                double SampleRateRatio = (double)FileSampleRate / ActualSampleRate;
                SignalData = new byte[(int)Math.Ceiling(TotalFrame / SampleRateRatio + 1)];

                byte[] CurrentSample;
                double FrameIndex = 0.0;    // float cannot provide needed precision
                int    i          = 0;
                do
                {
                    CurrentSample = wr.GetSampleAt(Convert.ToInt32(FrameIndex));
                    SignalData[i] = (byte)(CurrentSample[CurrentSample.Count() - 1] ^ (byte)0x80);
                    FrameIndex   += SampleRateRatio;
                    i++;
                } while (FrameIndex < TotalFrame);

                wr.Close();

                return(true);
            }
            else
            {
                byte Max, Min;
                uint Length;
                if (!byte.TryParse(txtPeak.Text, out Max) || !byte.TryParse(txtGrov.Text, out Min) ||
                    !uint.TryParse(txtSamp.Text, out Length))
                {
                    return(false);
                }
                if (Min > Max || Length == 0)
                {
                    return(false);
                }
                SignalData = new byte[Length];
                Single NormalizedT;
                for (int i = 0; i < Length; i++)
                {
                    NormalizedT = (Single)i / (Single)Length;
                    switch (wfMode)
                    {
                    case WaveForm.Sqr:
                        SignalData[i] = (NormalizedT >= 0.5) ? Max : Min;
                        break;

                    case WaveForm.Saw:
                        SignalData[i] = (byte)((Max - Min) * NormalizedT + Min);
                        break;

                    case WaveForm.Tri:
                        if (NormalizedT < 0.5)
                        {
                            SignalData[i] = (byte)((Max - Min) * NormalizedT * 2 + Min);
                        }
                        else
                        {
                            SignalData[i] = (byte)((Max - Min) * (1 - NormalizedT) * 2 + Min);
                        }
                        break;

                    case WaveForm.Sin:
                        SignalData[i] = (byte)(Math.Sin(NormalizedT * Math.PI * 2) * (Max - Min) * 0.5 + (Max + Min) * 0.5);
                        break;
                    }
                }
                return(true);
            }
        }