Exemplo n.º 1
0
        // default settings
        public static DrawerSettings Edo12()
        {
            var s = new DrawerSettings();

            //
            s.limitPrimeIndex = 2;                  // 5-limit
            //
            s.slopeOrigin     = new Rational(3, 2); // 5th
            s.slopeChainTurns = 2;
            //
#if DEBUG
            s.temperament = new[] {
                new Tempered {
                    rational = new Rational(81, 80), cents = 0
                },
            };
#endif
            //
            s.edGrids = new[] {
                new GridDrawer.EDGrid {
                    stepCount = 12, baseInterval = Rational.Two
                }
            };
            //
            return(s);
        }
Exemplo n.º 2
0
 // Serialization
 public static void Save(DrawerSettings s, XmlWriter w)
 {
     //
     w.WriteElementString("limitPrime", s.subgroup != null ? "" : Rationals.Utils.GetPrime(s.limitPrimeIndex).ToString());
     w.WriteElementString("subgroup", Rational.FormatRationals(s.subgroup, "."));
     w.WriteElementString("narrows", Rational.FormatRationals(s.narrows, "."));
     //
     w.WriteElementString("harmonicityName", s.harmonicityName);
     w.WriteElementString("rationalCountLimit", s.rationalCountLimit.ToString());
     //
     w.WriteElementString("slopeOrigin", s.slopeOrigin.FormatFraction());
     w.WriteElementString("slopeChainTurns", s.slopeChainTurns.ToString());
     //
     //w.WriteElementString("degreeCount", s.degreeCount.ToString());
     w.WriteElementString("degreeThreshold", s.degreeThreshold.ToString());
     //
     w.WriteElementString("selection", FormatIntervals(s.selection));
     if (s.temperament != null)
     {
         foreach (Tempered t in s.temperament)
         {
             w.WriteStartElement("temper");
             w.WriteAttributeString("rational", t.rational.FormatFraction());
             w.WriteAttributeString("cents", t.cents.ToString());
             w.WriteEndElement();
         }
     }
     w.WriteElementString("temperamentMeasure", s.temperamentMeasure.ToString());
     w.WriteElementString("edGrids", GridDrawer.EDGrid.Format(s.edGrids));
     w.WriteElementString("pointRadius", s.pointRadiusLinear.ToString());
 }
Exemplo n.º 3
0
 protected void ResetPreset()
 {
     // reset all preset components (viewport, drawer, sound)
     _drawerSettings = DrawerSettings.Reset();
     ResetPresetViewport();
     ResetPresetSoundSettings();
     //
     _currentPresetPath    = null;
     _currentPresetChanged = false;
 }
Exemplo n.º 4
0
        public static DrawerSettings Reset()
        {
            var s = DrawerSettings.Edo12();

            // Common settings
            s.rationalCountLimit = 500;
            s.pointRadiusLinear  = 0f;

            return(s);
        }
Exemplo n.º 5
0
        public MainWindow()
        {
            var assemblyName = System.Reflection.Assembly.GetExecutingAssembly().GetName();

            _windowTitlePrefix = "Rationals Explorer ";
#if DEBUG
            _windowTitlePrefix += assemblyName.Version.ToString();
#else
            _windowTitlePrefix += String.Format("{0}.{1}", assemblyName.Version.Major, assemblyName.Version.Minor);
#endif

            _viewport = new TD.Viewport3();

            _drawerSettings = DrawerSettings.Reset();

            _gridDrawer = new GridDrawer();

            // Initialize from Xaml
            AvaloniaXamlLoader.Load(this);

            _mainGrid = ExpectControl <Grid>(this, "mainGrid");

            _mainImageControl = ExpectControl <Image>(this, "mainImage");

            var mainImagePanel = ExpectControl <Control>(this, "mainImagePanel");
            mainImagePanel.GetObservable(Control.BoundsProperty).Subscribe(OnMainImageBoundsChanged);

            _menuPresetSave        = ExpectControl <Control>(this, "menuPresetSave");
            _menuPresetRecent      = ExpectControl <ItemsControl>(this, "menuPresetRecent");
            _menuPresetRecentItems = new Avalonia.Collections.AvaloniaList <MenuItem>();

            _textBoxSelectionInfo = ExpectControl <TextBox>(this, "textBoxSelectionInfo");

            // prepare rendering
            _eventRenderDoWork = new System.Threading.AutoResetEvent(false);
            //
            _threadRender      = new System.Threading.Thread(RenderThread);
            _threadRender.Name = "Render";
            _threadRender.Start();

            //
            FindDrawerSettingsControls(this);
            InitSoundEngines();

            LoadAppSettings();

            // Propagate some settings to Drawer
            _gridDrawer.SetSystemSettings(_systemSettings.drawerFont);
        }
Exemplo n.º 6
0
 private void SavePreset(XmlWriter w)
 {
     // drawer
     w.WriteStartElement("drawer");
     DrawerSettings.Save(_drawerSettings, w);
     w.WriteEndElement();
     // viewport
     w.WriteStartElement("viewport");
     SavePresetViewport(w);
     w.WriteEndElement();
     // Sound settings
     w.WriteStartElement("sound");
     WriteSoundSettings(w, _soundSettings);
     w.WriteEndElement();
 }
Exemplo n.º 7
0
        private void UpdateDrawerFully()
        {
            DrawerSettings s = _drawerSettings;

            // subgroup
            _gridDrawer.SetSubgroup(s.limitPrimeIndex, s.subgroup, s.narrows);
            // generation
            _gridDrawer.SetGeneration(s.harmonicityName, s.rationalCountLimit);
            // temperament
            _gridDrawer.SetTemperamentMeasure(s.temperamentMeasure);
            _gridDrawer.SetTemperament(s.temperament);
            // degrees
            _gridDrawer.SetDegrees(s.degreeThreshold);
            // slope
            _gridDrawer.SetSlope(s.slopeOrigin, s.slopeChainTurns);
            // view
            _gridDrawer.SetEDGrids(s.edGrids);
            _gridDrawer.SetSelection(s.selection);
            _gridDrawer.SetPointRadius(s.pointRadiusLinear);
        }
Exemplo n.º 8
0
 private void SetWindowLayout(string locationValue)
 {
     if (locationValue == null)
     {
         return;
     }
     int[] ns = DrawerSettings.ParseIntegers(locationValue);
     if (ns == null || ns.Length != 6)
     {
         return;
     }
     // propagate
     this.WindowState = (WindowState)ns[0];
     if (this.WindowState == WindowState.Normal)
     {
         this.WindowStartupLocation = WindowStartupLocation.Manual;
         this.Position   = new PixelPoint(ns[1], ns[2]);
         this.ClientSize = new Size(ns[3], ns[4]);
     }
     _mainGrid.ColumnDefinitions[0].Width = new GridLength(ns[5]);
 }
Exemplo n.º 9
0
        // Read settings from controls - used on saving Preset
        protected DrawerSettings GetSettingsFromControls()
        {
            DrawerSettings s = new DrawerSettings {
            };

            // subgroup
            if (!String.IsNullOrWhiteSpace(textBoxSubgroup.Text))
            {
                string[] subgroupText = DS.SplitSubgroupText(textBoxSubgroup.Text);
                s.subgroup = Rational.ParseRationals(subgroupText[0]);
                s.narrows  = Rational.ParseRationals(subgroupText[1]);
                s.narrows  = NarrowUtils.ValidateNarrows(s.narrows);
            }
            // base & prime limit
            if (s.subgroup == null)
            {
                s.limitPrimeIndex = (int)upDownLimit.Value;
            }
            // generation
            s.harmonicityName    = (string)comboBoxDistance.SelectedItem;
            s.rationalCountLimit = (int)upDownCountLimit.Value;
            // temperament
            s.temperament        = _temperamentControls.GetTemperament();
            s.temperamentMeasure = (float)sliderTemperament.Value * 0.01f;
            // slope
            s.slopeOrigin     = Rational.Parse(textBoxSlopeOrigin.Text);
            s.slopeChainTurns = (float)upDownChainTurns.Value;
            // degrees
            //s.degreeCount = (int)upDownDegreeCount.Value;
            s.degreeThreshold = (float)upDownDegreeThreshold.Value;
            // selection
            s.selection = DS.ParseIntervals(textBoxSelection.Text);
            // grids
            s.edGrids = GridDrawer.EDGrid.Parse(textBoxEDGrids.Text);

            return(s);
        }
Exemplo n.º 10
0
        private void LoadPreset(XmlReader r)
        {
            // read preset from App Settings or saved preset xml
            while (r.Read())
            {
                if (r.NodeType == XmlNodeType.Element)
                {
                    switch (r.Name)
                    {
                    case "drawer":
                        _drawerSettings = DrawerSettings.Load(r.ReadSubtree());
                        break;

                    case "viewport":
                        LoadPresetViewport(r.ReadSubtree());
                        break;

                    case "sound":
                        _soundSettings = ReadSoundSettings(r.ReadSubtree());
                        break;
                    }
                }
            }
        }
Exemplo n.º 11
0
        // Set settings to controls
        protected void SetSettingsToControls()
        {
            DrawerSettings s = _drawerSettings;

            _settingInternally = true;
            // base
            upDownLimit.Value    = s.limitPrimeIndex;
            textBoxSubgroup.Text = DS.FormatSubgroup(s.subgroup, s.narrows);
            // temperament
            _temperamentControls.SetTemperament(s.temperament);
            sliderTemperament.Value = (int)Math.Round(s.temperamentMeasure * 100);
            // slope
            textBoxSlopeOrigin.Text = s.slopeOrigin.FormatFraction();
            upDownChainTurns.Value  = s.slopeChainTurns;
            // degrees
            //upDownDegreeCount.Value = s.degreeCount;
            upDownDegreeThreshold.Value = s.degreeThreshold;
            // selection
            textBoxSelection.Text = DS.FormatIntervals(s.selection);
            // grids
            textBoxEDGrids.Text = GridDrawer.EDGrid.Format(s.edGrids);
            // drawing
            if (!String.IsNullOrEmpty(s.harmonicityName))
            {
                comboBoxDistance.SelectedItem = s.harmonicityName;
            }
            upDownCountLimit.Value = s.rationalCountLimit;
            //

            //if (s.temperament != null) {
            //    UpdateTemperamentRowsAfterValidation(); // validate temperament
            //}
            // -- ValidateControlsByDrawer() will be called later

            _settingInternally = false;
        }
Exemplo n.º 12
0
        public static DrawerSettings Load(XmlReader r)
        {
            var s  = new DrawerSettings {
            };
            var ts = new List <Tempered>();

            while (r.Read())
            {
                if (r.NodeType == XmlNodeType.Element)
                {
                    switch (r.Name)
                    {
                    case "limitPrime": {
                        Rational limitPrime = Rational.Parse(r.ReadElementContentAsString());     // allow to be a rational
                        if (!limitPrime.IsDefault())
                        {
                            s.limitPrimeIndex = limitPrime.GetHighPrimeIndex();
                        }
                        break;
                    }

                    case "subgroup": {
                        s.subgroup = Rational.ParseRationals(r.ReadElementContentAsString());
                        break;
                    }

                    case "narrows": {
                        s.narrows = Rational.ParseRationals(r.ReadElementContentAsString());
                        s.narrows = NarrowUtils.ValidateNarrows(s.narrows);
                        break;
                    }

                    //
                    case "harmonicityName":     s.harmonicityName = r.ReadElementContentAsString();   break;

                    case "rationalCountLimit":  s.rationalCountLimit = r.ReadElementContentAsInt();      break;

                    //
                    case "slopeOrigin":         s.slopeOrigin = Rational.Parse(r.ReadElementContentAsString()); break;

                    case "slopeChainTurns":     s.slopeChainTurns = r.ReadElementContentAsFloat();    break;

                    //
                    //case "degreeCount":         s.degreeCount        = r.ReadElementContentAsInt();      break;
                    case "degreeThreshold":     s.degreeThreshold = r.ReadElementContentAsFloat();    break;

                    //
                    case "selection":           s.selection = ParseIntervals(r.ReadElementContentAsString()); break;

                    case "temper": {
                        var t = new Tempered {
                        };
                        t.rational = Rational.Parse(r.GetAttribute("rational"));
                        float.TryParse(r.GetAttribute("cents"), out t.cents);
                        ts.Add(t);
                        break;
                    }

                    case "temperamentMeasure":  s.temperamentMeasure = r.ReadElementContentAsFloat();    break;

                    case "edGrids":             s.edGrids = GridDrawer.EDGrid.Parse(r.ReadElementContentAsString()); break;

                    case "pointRadius":         s.pointRadiusLinear = r.ReadElementContentAsFloat();    break;
                    }
                }
            }
            if (ts.Count > 0)
            {
                s.temperament = ts.ToArray();
            }
            return(s);
        }